nis-util
1.0.D108
|
00001 // 00002 // nis-util - NIS Administration Utilities 00003 // Copyright (C) 2001, 2008, 2009, 2011, 2012 Peter Miller 00004 // 00005 // This program is free software; you can redistribute it and/or modify 00006 // it under the terms of the GNU General Public License as published by 00007 // the Free Software Foundation; either version 2 of the License, or (at 00008 // your option) any later version. 00009 // 00010 // This program is distributed in the hope that it will be useful, 00011 // but WITHOUT ANY WARRANTY; without even the implied warranty of 00012 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU 00013 // General Public License for more details. 00014 // 00015 // You should have received a copy of the GNU General Public License 00016 // along with this program. If not, see <http://www.gnu.org/licenses/>. 00017 // 00018 00019 #ifndef LIB_ARGLEX_H 00020 #define LIB_ARGLEX_H 00021 00022 #include <list> 00023 00024 #include <lib/arglex/source.h> 00025 00026 #define ARGLEX_END_MARKER {0,0} 00027 00033 class arglex 00034 { 00035 public: 00039 virtual ~arglex(); 00040 00051 arglex(int argc, char **argv); 00052 00053 enum 00054 { 00055 token_configuration_file, 00056 token_eoln, 00057 token_group_name_maximum, 00058 token_help, 00059 token_license, 00060 token_number, 00061 token_option, 00062 token_page_length, 00063 token_page_width, 00064 token_passwd_name_maximum, 00065 token_stdio, 00066 token_string, 00067 token_tracing, 00068 token_verbose, 00069 token_verbose_not, 00070 token_version, 00071 token_warning, 00072 token_warning_not, 00073 token_MAX 00074 }; 00075 00086 int token_first(void); 00087 00098 int token_next(void); 00099 00104 int token_cur(void) const { return token; } 00105 00113 rcstring get_string_value(void) const { return value_string; } 00114 00120 long get_integer_value(void) const { return value_number; } 00121 00127 const source_location &get_source_location(void) const; 00128 00138 const char *token_name(int num) const; 00139 00147 void usage(void) const; 00148 00156 void bad_argument(void) const; 00157 00163 void generic_argument(void); 00164 00177 static bool compare(const char *formal, const char *actual); 00178 00185 void check_stdin_references(void); 00186 00193 void check_stdout_references(void); 00194 00201 rcstring get_filename_or_stdin(void); 00202 00208 void get_filename_or_stdin(rcstring &fnvar); 00209 00216 rcstring get_filename_or_stdout(void); 00217 00223 void get_filename_or_stdout(rcstring &fnvar); 00224 00225 protected: 00226 struct table_t 00227 { 00228 const char *name; 00229 int token; 00230 }; 00231 00244 void table_set(const table_t *tp); 00245 00253 void usage_tail_set(const char *text); 00254 00255 private: 00260 void help(const char *name = 0) const; 00261 00266 void version(void) const; 00267 00272 void license(void) const; 00273 00274 typedef std::list<arglex_source::pointer> sources_t; 00275 00281 sources_t sources; 00282 00291 int token; 00292 00298 source_location token_locn; 00299 00308 rcstring value_string; 00309 00319 long value_number; 00320 00321 typedef std::list<const table_t *> tables_t; 00322 00328 tables_t tables; 00329 00336 const char *usage_tail_; 00337 00343 const char *usage_tail_get(void) const; 00344 00351 int number_of_stdin_references; 00352 00359 int number_of_stdout_references; 00360 00368 void push_arg_back(const char *text); 00369 00374 arglex(); 00375 00383 arglex(const arglex &rhs); 00384 00392 arglex &operator=(const arglex &rhs); 00393 }; 00394 00395 // vim: set ts=8 sw=4 et : 00396 #endif // LIB_ARGLEX_H