00001 /*
00002 * This program is free software; you can redistribute it and/or modify
00003 * it under the terms of the GNU General Public License as published by
00004 * the Free Software Foundation; either version 2 of the License, or
00005 * (at your option) any later version.
00006 *
00007 * This program is distributed in the hope that it will be useful,
00008 * but WITHOUT ANY WARRANTY; without even the implied warranty of
00009 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
00010 * GNU General Public License for more details.
00011 *
00012 * You should have received a copy of the GNU General Public License
00013 * along with this program; if not, write to the Free Software
00014 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
00015 *
00016 * (c)Copyright 2006 Hewlett-Packard Development Company, LP.
00017 *
00018 */
00019
00020 #ifndef _C_COMMANDLINE_H_
00021 #define _C_COMMANDLINE_H_
00022
00023 #include "Utils.hpp"
00024
00025 template <class T_TIndexCommand>
00026 class C_CommandLine {
00027
00028 public:
00029 // public types used for command line description
00030 enum T_option_type { // option type
00031 E_OT_MANDATORY, // option is mandatory
00032 E_OT_OPTIONAL } ; // or a default value exists
00033
00034 enum T_value_type { // option value type
00035 E_VT_INTEGER, // an integer is expected for a value of the option
00036 E_VT_OCTET_HEXA, // an octet in hexa
00037 E_VT_STRING } ; // everything
00038
00039 typedef struct _command_option { // option description
00040 T_TIndexCommand index ;
00041 char *name ; // name of the option
00042 T_option_type option_type ; // type of the option
00043 int nb_values ; // number of values expected for the option
00044 T_value_type *values_types ; // types of the value(s) of the option
00045 char *param_comment ; // parameters description
00046 char *comments ; // general comments
00047 } T_command_option ;
00048
00049 typedef struct _command_line { // command line description
00050 int nb_options ; // number of options
00051 T_TIndexCommand help_index ; // index of the help option
00052 T_command_option *command_options ; // description of all the options
00053 } T_command_line ;
00054
00055 public:
00056 // public methods
00057 int startAnalyzeCommandLine (int argc,
00058 char **argv,
00059 T_command_line *) ; // starts analyzing command line
00060 void usage (void) ; // write command syntax to stderr and exit program
00061
00062 C_CommandLine () ;
00063 virtual ~C_CommandLine () ;
00064
00065 virtual bool set_data (T_TIndexCommand, char**) = 0 ;
00066
00067
00068 private:
00069 // private fields
00070 char *f_programName ; // executing process name (first argument)
00071 T_command_line *f_command_description ; // command line description
00072 bool *f_option_flags ; // table of the detected options
00073 bool f_noHelpIndex ; // no help option defined
00074 int f_internalHelpCode ;
00075
00076 // private methods
00077 void AnalyzeCommandLine (int argc, char **argv); // starts analyzing command line
00078 int SearchForOption (char *pattern) ; // options pattern matching
00079 bool VerifyMandatoryArgs () ; // command line arguments verification
00080 bool VerifyOptionValues (int opt, int idx, char **argv); // option values verification
00081 int SearchForOption (T_TIndexCommand idxCmd) ; // options code matching
00082
00083 int integer_ok (char *name); // option format integer verif
00084 int octet_hexa_ok (char *name); // option format hexa verif
00085
00086
00087
00088 } ; /* C_CommandLine */
00089
00090 #endif // _C_COMMANDLINE_H_
00091
00092
00093
00094
00095
00096
00097
00098
00099
00100
00101
1.2.14 written by Dimitri van Heesch,
© 1997-2002