FFSM++  1.1.0
French Forest Sector Model ++
AnyOption Class Reference

#include <anyoption.h>

Public Member Functions

 AnyOption ()
 
 AnyOption (int maxoptions)
 
 AnyOption (int maxoptions, int maxcharoptions)
 
 ~AnyOption ()
 
void setCommandPrefixChar (char _prefix)
 
void setCommandLongPrefix (char *_prefix)
 
void setFileCommentChar (char _comment)
 
void setFileDelimiterChar (char _delimiter)
 
void useCommandArgs (int _argc, char **_argv)
 
void useFiileName (const char *_filename)
 
void noPOSIX ()
 
void setVerbose ()
 
void setOption (const char *opt_string)
 
void setOption (char opt_char)
 
void setOption (const char *opt_string, char opt_char)
 
void setFlag (const char *opt_string)
 
void setFlag (char opt_char)
 
void setFlag (const char *opt_string, char opt_char)
 
void setCommandOption (const char *opt_string)
 
void setCommandOption (char opt_char)
 
void setCommandOption (const char *opt_string, char opt_char)
 
void setCommandFlag (const char *opt_string)
 
void setCommandFlag (char opt_char)
 
void setCommandFlag (const char *opt_string, char opt_char)
 
void setFileOption (const char *opt_string)
 
void setFileOption (char opt_char)
 
void setFileOption (const char *opt_string, char opt_char)
 
void setFileFlag (const char *opt_string)
 
void setFileFlag (char opt_char)
 
void setFileFlag (const char *opt_string, char opt_char)
 
void processOptions ()
 
void processCommandArgs ()
 
void processCommandArgs (int max_args)
 
bool processFile ()
 
void processCommandArgs (int _argc, char **_argv)
 
void processCommandArgs (int _argc, char **_argv, int max_args)
 
bool processFile (const char *_filename)
 
char * getValue (const char *_option)
 
bool getFlag (const char *_option)
 
char * getValue (char _optchar)
 
bool getFlag (char _optchar)
 
void printUsage ()
 
void printAutoUsage ()
 
void addUsage (const char *line)
 
void printHelp ()
 
void autoUsagePrint (bool flag)
 
int getArgc ()
 
char * getArgv (int index)
 
bool hasOptions ()
 

Private Member Functions

void init ()
 
void init (int maxopt, int maxcharopt)
 
bool alloc ()
 
void cleanup ()
 
bool valueStoreOK ()
 
bool doubleOptStorage ()
 
bool doubleCharStorage ()
 
bool doubleUsageStorage ()
 
bool setValue (const char *option, char *value)
 
bool setFlagOn (const char *option)
 
bool setValue (char optchar, char *value)
 
bool setFlagOn (char optchar)
 
void addOption (const char *option, int type)
 
void addOption (char optchar, int type)
 
void addOptionError (const char *opt)
 
void addOptionError (char opt)
 
bool findFlag (char *value)
 
void addUsageError (const char *line)
 
bool CommandSet ()
 
bool FileSet ()
 
bool POSIX ()
 
char parsePOSIX (char *arg)
 
int parseGNU (char *arg)
 
bool matchChar (char c)
 
int matchOpt (char *opt)
 
char * readFile ()
 
char * readFile (const char *fname)
 
bool consumeFile (char *buffer)
 
void processLine (char *theline, int length)
 
char * chomp (char *str)
 
void valuePairs (char *type, char *value)
 
void justValue (char *value)
 
void printVerbose (const char *msg)
 
void printVerbose (char *msg)
 
void printVerbose (char ch)
 
void printVerbose ()
 

Private Attributes

int argc
 
char ** argv
 
const char * filename
 
char * appname
 
int * new_argv
 
int new_argc
 
int max_legal_args
 
int max_options
 
const char ** options
 
int * optiontype
 
int * optionindex
 
int option_counter
 
int max_char_options
 
char * optionchars
 
int * optchartype
 
int * optcharindex
 
int optchar_counter
 
char ** values
 
int g_value_counter
 
const char ** usage
 
int max_usage_lines
 
int usage_lines
 
bool command_set
 
bool file_set
 
bool mem_allocated
 
bool posix_style
 
bool verbose
 
bool print_usage
 
bool print_help
 
char opt_prefix_char
 
char long_opt_prefix [MAX_LONG_PREFIX_LENGTH+1]
 
char file_delimiter_char
 
char file_comment_char
 
char equalsign
 
char comment
 
char delimiter
 
char endofline
 
char whitespace
 
char nullterminate
 
bool set
 
bool once
 
bool hasoptions
 
bool autousage
 

Detailed Description

Definition at line 32 of file anyoption.h.

Constructor & Destructor Documentation

AnyOption ( )

Definition at line 65 of file anyoption.cpp.

66 {
67  init();
68 }
void init()
Definition: anyoption.cpp:87

Here is the call graph for this function:

AnyOption ( int  maxoptions)

Definition at line 70 of file anyoption.cpp.

71 {
72  init( maxopt , maxopt );
73 }
void init()
Definition: anyoption.cpp:87

Here is the call graph for this function:

AnyOption ( int  maxoptions,
int  maxcharoptions 
)

Definition at line 75 of file anyoption.cpp.

76 {
77  init( maxopt , maxcharopt );
78 }
void init()
Definition: anyoption.cpp:87

Here is the call graph for this function:

~AnyOption ( )

Definition at line 80 of file anyoption.cpp.

81 {
82  if( mem_allocated )
83  cleanup();
84 }
bool mem_allocated
Definition: anyoption.h:198
void cleanup()
Definition: anyoption.cpp:253

Here is the call graph for this function:

Member Function Documentation

void addOption ( const char *  option,
int  type 
)
private

Definition at line 521 of file anyoption.cpp.

Referenced by setCommandFlag(), setCommandOption(), setFileFlag(), setFileOption(), setFlag(), and setOption().

522 {
523  if( option_counter >= max_options ){
524  if( doubleOptStorage() == false ){
525  addOptionError( opt );
526  return;
527  }
528  }
529  options[ option_counter ] = opt ;
530  optiontype[ option_counter ] = type ;
532  option_counter++;
533 }
int * optiontype
Definition: anyoption.h:176
int option_counter
Definition: anyoption.h:178
int g_value_counter
Definition: anyoption.h:189
const char ** options
Definition: anyoption.h:175
bool doubleOptStorage()
Definition: anyoption.cpp:194
int max_options
Definition: anyoption.h:174
int * optionindex
Definition: anyoption.h:177
void addOptionError(const char *opt)
Definition: anyoption.cpp:560

Here is the call graph for this function:

Here is the caller graph for this function:

void addOption ( char  optchar,
int  type 
)
private

Definition at line 536 of file anyoption.cpp.

537 {
538  if( !POSIX() ){
539  printVerbose("Ignoring the option character \"");
540  printVerbose( opt );
541  printVerbose( "\" ( POSIX options are turned off )" );
542  printVerbose();
543  return;
544  }
545 
546 
548  if( doubleCharStorage() == false ){
549  addOptionError( opt );
550  return;
551  }
552  }
553  optionchars[ optchar_counter ] = opt ;
554  optchartype[ optchar_counter ] = type ;
556  optchar_counter++;
557 }
int * optcharindex
Definition: anyoption.h:184
int optchar_counter
Definition: anyoption.h:185
void printVerbose()
Definition: anyoption.cpp:329
int max_char_options
Definition: anyoption.h:181
int g_value_counter
Definition: anyoption.h:189
int * optchartype
Definition: anyoption.h:183
char * optionchars
Definition: anyoption.h:182
bool doubleCharStorage()
Definition: anyoption.cpp:215
void addOptionError(const char *opt)
Definition: anyoption.cpp:560
bool POSIX()
Definition: anyoption.cpp:316

Here is the call graph for this function:

void addOptionError ( const char *  opt)
private

Definition at line 560 of file anyoption.cpp.

Referenced by addOption().

561 {
562  cout << endl ;
563  cout << "OPTIONS ERROR : Failed allocating extra memory " << endl ;
564  cout << "While adding the option : \""<< opt << "\"" << endl;
565  cout << "Exiting." << endl ;
566  cout << endl ;
567  exit(0);
568 }

Here is the caller graph for this function:

void addOptionError ( char  opt)
private

Definition at line 571 of file anyoption.cpp.

572 {
573  cout << endl ;
574  cout << "OPTIONS ERROR : Failed allocating extra memory " << endl ;
575  cout << "While adding the option: \""<< opt << "\"" << endl;
576  cout << "Exiting." << endl ;
577  cout << endl ;
578  exit(0);
579 }
void addUsage ( const char *  line)

Definition at line 1153 of file anyoption.cpp.

Referenced by main().

1154 {
1155  if( usage_lines >= max_usage_lines ){
1156  if( doubleUsageStorage() == false ){
1157  addUsageError( line );
1158  exit(1);
1159  }
1160  }
1161  usage[ usage_lines ] = line ;
1162  usage_lines++;
1163 }
const char ** usage
Definition: anyoption.h:192
bool doubleUsageStorage()
Definition: anyoption.cpp:238
void addUsageError(const char *line)
Definition: anyoption.cpp:1166
int usage_lines
Definition: anyoption.h:194
int max_usage_lines
Definition: anyoption.h:193

Here is the call graph for this function:

Here is the caller graph for this function:

void addUsageError ( const char *  line)
private

Definition at line 1166 of file anyoption.cpp.

Referenced by addUsage().

1167 {
1168  cout << endl ;
1169  cout << "OPTIONS ERROR : Failed allocating extra memory " << endl ;
1170  cout << "While adding the usage/help : \""<< line << "\"" << endl;
1171  cout << "Exiting." << endl ;
1172  cout << endl ;
1173  exit(0);
1174 
1175 }

Here is the caller graph for this function:

bool alloc ( )
private

Definition at line 143 of file anyoption.cpp.

Referenced by init().

144 {
145  int i = 0 ;
146  int size = 0 ;
147 
148  if( mem_allocated )
149  return true;
150 
151  size = (max_options+1) * sizeof(const char*);
152  options = (const char**)malloc( size );
153  optiontype = (int*) malloc( (max_options+1)*sizeof(int) );
154  optionindex = (int*) malloc( (max_options+1)*sizeof(int) );
155  if( options == NULL || optiontype == NULL || optionindex == NULL )
156  return false;
157  else
158  mem_allocated = true;
159  for( i = 0 ; i < max_options ; i++ ){
160  options[i] = NULL;
161  optiontype[i] = 0 ;
162  optionindex[i] = -1 ;
163  }
164  optionchars = (char*) malloc( (max_char_options+1)*sizeof(char) );
165  optchartype = (int*) malloc( (max_char_options+1)*sizeof(int) );
166  optcharindex = (int*) malloc( (max_char_options+1)*sizeof(int) );
167  if( optionchars == NULL ||
168  optchartype == NULL ||
169  optcharindex == NULL )
170  {
171  mem_allocated = false;
172  return false;
173  }
174  for( i = 0 ; i < max_char_options ; i++ ){
175  optionchars[i] = '0';
176  optchartype[i] = 0 ;
177  optcharindex[i] = -1 ;
178  }
179 
180  size = (max_usage_lines+1) * sizeof(const char*) ;
181  usage = (const char**) malloc( size );
182 
183  if( usage == NULL ){
184  mem_allocated = false;
185  return false;
186  }
187  for( i = 0 ; i < max_usage_lines ; i++ )
188  usage[i] = NULL;
189 
190  return true;
191 }
int * optcharindex
Definition: anyoption.h:184
int * optiontype
Definition: anyoption.h:176
const char ** usage
Definition: anyoption.h:192
int max_char_options
Definition: anyoption.h:181
const char ** options
Definition: anyoption.h:175
bool mem_allocated
Definition: anyoption.h:198
int * optchartype
Definition: anyoption.h:183
int max_options
Definition: anyoption.h:174
char * optionchars
Definition: anyoption.h:182
int max_usage_lines
Definition: anyoption.h:193
int * optionindex
Definition: anyoption.h:177

Here is the caller graph for this function:

void autoUsagePrint ( bool  flag)

Definition at line 362 of file anyoption.cpp.

363 {
364  autousage = _autousage;
365 }
bool autousage
Definition: anyoption.h:219
char * chomp ( char *  str)
private

Definition at line 1053 of file anyoption.cpp.

Referenced by justValue(), and valuePairs().

1054 {
1055  while( *str == whitespace )
1056  str++;
1057  char *end = str+strlen(str)-1;
1058  while( *end == whitespace )
1059  end--;
1060  *(end+1) = nullterminate;
1061  return str;
1062 }
char whitespace
Definition: anyoption.h:212
char nullterminate
Definition: anyoption.h:213

Here is the caller graph for this function:

void cleanup ( )
private

Definition at line 253 of file anyoption.cpp.

Referenced by ~AnyOption().

254 {
255  free (options);
256  free (optiontype);
257  free (optionindex);
258  free (optionchars);
259  free (optchartype);
260  free (optcharindex);
261  free (usage);
262  if( values != NULL )
263  free (values);
264  if( new_argv != NULL )
265  free (new_argv);
266 }
int * optcharindex
Definition: anyoption.h:184
int * optiontype
Definition: anyoption.h:176
const char ** usage
Definition: anyoption.h:192
int * new_argv
Definition: anyoption.h:168
const char ** options
Definition: anyoption.h:175
char ** values
Definition: anyoption.h:188
int * optchartype
Definition: anyoption.h:183
char * optionchars
Definition: anyoption.h:182
int * optionindex
Definition: anyoption.h:177

Here is the caller graph for this function:

bool CommandSet ( )
private

Definition at line 298 of file anyoption.cpp.

Referenced by processCommandArgs().

299 {
300  return( command_set );
301 }
bool command_set
Definition: anyoption.h:196

Here is the caller graph for this function:

bool consumeFile ( char *  buffer)
private

Definition at line 971 of file anyoption.cpp.

Referenced by processFile().

972 {
973 
974  if( buffer == NULL )
975  return false;
976 
977  char *cursor = buffer;/* preserve the ptr */
978  char *pline = NULL ;
979  int linelength = 0;
980  bool newline = true;
981  for( unsigned int i = 0 ; i < strlen( buffer ) ; i++ ){
982  if( *cursor == endofline ) { /* end of line */
983  if( pline != NULL ) /* valid line */
984  processLine( pline, linelength );
985  pline = NULL;
986  newline = true;
987  }else if( newline ){ /* start of line */
988  newline = false;
989  if( (*cursor != comment ) ){ /* not a comment */
990  pline = cursor ;
991  linelength = 0 ;
992  }
993  }
994  cursor++; /* keep moving */
995  linelength++;
996  }
997  free (buffer);
998  return true;
999 }
void processLine(char *theline, int length)
Definition: anyoption.cpp:1023
char endofline
Definition: anyoption.h:211
char comment
Definition: anyoption.h:209

Here is the call graph for this function:

Here is the caller graph for this function:

bool doubleCharStorage ( )
private

Definition at line 215 of file anyoption.cpp.

Referenced by addOption().

216 {
217  optionchars = (char*) realloc( optionchars,
218  ((2*max_char_options)+1)*sizeof(char) );
219  optchartype = (int*) realloc( optchartype,
220  ((2*max_char_options)+1)*sizeof(int) );
221  optcharindex = (int*) realloc( optcharindex,
222  ((2*max_char_options)+1)*sizeof(int) );
223  if( optionchars == NULL ||
224  optchartype == NULL ||
225  optcharindex == NULL )
226  return false;
227  /* init new storage */
228  for( int i = max_char_options ; i < 2*max_char_options ; i++ ){
229  optionchars[i] = '0';
230  optchartype[i] = 0 ;
231  optcharindex[i] = -1 ;
232  }
233  max_char_options = 2 * max_char_options;
234  return true;
235 }
int * optcharindex
Definition: anyoption.h:184
int max_char_options
Definition: anyoption.h:181
int * optchartype
Definition: anyoption.h:183
char * optionchars
Definition: anyoption.h:182

Here is the caller graph for this function:

bool doubleOptStorage ( )
private

Definition at line 194 of file anyoption.cpp.

Referenced by addOption().

195 {
196  options = (const char**)realloc( options,
197  ((2*max_options)+1) * sizeof( const char*) );
198  optiontype = (int*) realloc( optiontype ,
199  ((2 * max_options)+1)* sizeof(int) );
200  optionindex = (int*) realloc( optionindex,
201  ((2 * max_options)+1) * sizeof(int) );
202  if( options == NULL || optiontype == NULL || optionindex == NULL )
203  return false;
204  /* init new storage */
205  for( int i = max_options ; i < 2*max_options ; i++ ){
206  options[i] = NULL;
207  optiontype[i] = 0 ;
208  optionindex[i] = -1 ;
209  }
210  max_options = 2 * max_options ;
211  return true;
212 }
int * optiontype
Definition: anyoption.h:176
const char ** options
Definition: anyoption.h:175
int max_options
Definition: anyoption.h:174
int * optionindex
Definition: anyoption.h:177

Here is the caller graph for this function:

bool doubleUsageStorage ( )
private

Definition at line 238 of file anyoption.cpp.

Referenced by addUsage().

239 {
240  usage = (const char**)realloc( usage,
241  ((2*max_usage_lines)+1) * sizeof( const char*) );
242  if ( usage == NULL )
243  return false;
244  for( int i = max_usage_lines ; i < 2*max_usage_lines ; i++ )
245  usage[i] = NULL;
246  max_usage_lines = 2 * max_usage_lines ;
247  return true;
248 
249 }
const char ** usage
Definition: anyoption.h:192
int max_usage_lines
Definition: anyoption.h:193

Here is the caller graph for this function:

bool FileSet ( )
private

Definition at line 304 of file anyoption.cpp.

Referenced by processFile().

305 {
306  return( file_set );
307 }
bool file_set
Definition: anyoption.h:197

Here is the caller graph for this function:

bool findFlag ( char *  value)
private

Definition at line 829 of file anyoption.cpp.

Referenced by getFlag().

830 {
831  if( val == NULL )
832  return false;
833 
834  if( strcmp( TRUE_FLAG , val ) == 0 )
835  return true;
836 
837  return false;
838 }
#define TRUE_FLAG
Definition: anyoption.h:28

Here is the caller graph for this function:

int getArgc ( )

Definition at line 905 of file anyoption.cpp.

Referenced by main().

906 {
907  return new_argc;
908 }
int new_argc
Definition: anyoption.h:169

Here is the caller graph for this function:

char * getArgv ( int  index)

Definition at line 911 of file anyoption.cpp.

912 {
913  if( index < new_argc ){
914  return ( argv[ new_argv[ index ] ] );
915  }
916  return NULL;
917 }
int new_argc
Definition: anyoption.h:169
char ** argv
Definition: anyoption.h:164
int * new_argv
Definition: anyoption.h:168
bool getFlag ( const char *  _option)

Definition at line 793 of file anyoption.cpp.

Referenced by main().

794 {
795  if( !valueStoreOK() )
796  return false;
797  for( int i = 0 ; i < option_counter ; i++ ){
798  if( strcmp( options[i], option ) == 0 )
799  return findFlag( values[ optionindex[i] ] );
800  }
801  return false;
802 }
bool valueStoreOK()
Definition: anyoption.cpp:761
int option_counter
Definition: anyoption.h:178
bool findFlag(char *value)
Definition: anyoption.cpp:829
const char ** options
Definition: anyoption.h:175
char ** values
Definition: anyoption.h:188
int * optionindex
Definition: anyoption.h:177

Here is the call graph for this function:

Here is the caller graph for this function:

bool getFlag ( char  _optchar)

Definition at line 817 of file anyoption.cpp.

818 {
819  if( !valueStoreOK() )
820  return false;
821  for( int i = 0 ; i < optchar_counter ; i++ ){
822  if( optionchars[i] == option )
823  return findFlag( values[ optcharindex[i] ] ) ;
824  }
825  return false;
826 }
int * optcharindex
Definition: anyoption.h:184
bool valueStoreOK()
Definition: anyoption.cpp:761
int optchar_counter
Definition: anyoption.h:185
bool findFlag(char *value)
Definition: anyoption.cpp:829
char ** values
Definition: anyoption.h:188
char * optionchars
Definition: anyoption.h:182

Here is the call graph for this function:

char * getValue ( const char *  _option)

Definition at line 780 of file anyoption.cpp.

Referenced by main().

781 {
782  if( !valueStoreOK() )
783  return NULL;
784 
785  for( int i = 0 ; i < option_counter ; i++ ){
786  if( strcmp( options[i], option ) == 0 )
787  return values[ optionindex[i] ];
788  }
789  return NULL;
790 }
bool valueStoreOK()
Definition: anyoption.cpp:761
int option_counter
Definition: anyoption.h:178
const char ** options
Definition: anyoption.h:175
char ** values
Definition: anyoption.h:188
int * optionindex
Definition: anyoption.h:177

Here is the call graph for this function:

Here is the caller graph for this function:

char * getValue ( char  _optchar)

Definition at line 805 of file anyoption.cpp.

806 {
807  if( !valueStoreOK() )
808  return NULL;
809  for( int i = 0 ; i < optchar_counter ; i++ ){
810  if( optionchars[i] == option )
811  return values[ optcharindex[i] ];
812  }
813  return NULL;
814 }
int * optcharindex
Definition: anyoption.h:184
bool valueStoreOK()
Definition: anyoption.cpp:761
int optchar_counter
Definition: anyoption.h:185
char ** values
Definition: anyoption.h:188
char * optionchars
Definition: anyoption.h:182

Here is the call graph for this function:

bool hasOptions ( )

Definition at line 356 of file anyoption.cpp.

357 {
358  return hasoptions;
359 }
bool hasoptions
Definition: anyoption.h:218
void init ( )
private

Definition at line 87 of file anyoption.cpp.

Referenced by AnyOption().

88 {
90 }
#define DEFAULT_MAXOPTS
Definition: anyoption.h:22
void init()
Definition: anyoption.cpp:87

Here is the caller graph for this function:

void init ( int  maxopt,
int  maxcharopt 
)
private

Definition at line 93 of file anyoption.cpp.

94 {
95 
96  max_options = maxopt;
97  max_char_options = maxcharopt;
99  usage_lines = 0 ;
100  argc = 0;
101  argv = NULL;
102  posix_style = true;
103  verbose = false;
104  filename = NULL;
105  appname = NULL;
106  option_counter = 0;
107  optchar_counter = 0;
108  new_argv = NULL;
109  new_argc = 0 ;
110  max_legal_args = 0 ;
111  command_set = false;
112  file_set = false;
113  values = NULL;
114  g_value_counter = 0;
115  mem_allocated = false;
116  command_set = false;
117  file_set = false;
118  opt_prefix_char = '-';
119  file_delimiter_char = ':';
120  file_comment_char = '#';
121  equalsign = '=';
122  comment = '#' ;
123  delimiter = ':' ;
124  endofline = '\n';
125  whitespace = ' ' ;
126  nullterminate = '\0';
127  set = false;
128  once = true;
129  hasoptions = false;
130  autousage = false;
131 
132  strcpy( long_opt_prefix , "--" );
133 
134  if( alloc() == false ){
135  cout << endl << "OPTIONS ERROR : Failed allocating memory" ;
136  cout << endl ;
137  cout << "Exiting." << endl ;
138  exit (0);
139  }
140 }
bool hasoptions
Definition: anyoption.h:218
bool alloc()
Definition: anyoption.cpp:143
char opt_prefix_char
Definition: anyoption.h:204
#define DEFAULT_MAXUSAGE
Definition: anyoption.h:25
int new_argc
Definition: anyoption.h:169
char delimiter
Definition: anyoption.h:210
char ** argv
Definition: anyoption.h:164
char whitespace
Definition: anyoption.h:212
char file_delimiter_char
Definition: anyoption.h:206
int optchar_counter
Definition: anyoption.h:185
bool command_set
Definition: anyoption.h:196
int option_counter
Definition: anyoption.h:178
char equalsign
Definition: anyoption.h:208
char nullterminate
Definition: anyoption.h:213
bool once
Definition: anyoption.h:216
char file_comment_char
Definition: anyoption.h:207
int max_char_options
Definition: anyoption.h:181
bool autousage
Definition: anyoption.h:219
int g_value_counter
Definition: anyoption.h:189
int max_legal_args
Definition: anyoption.h:170
const char * filename
Definition: anyoption.h:165
char endofline
Definition: anyoption.h:211
int * new_argv
Definition: anyoption.h:168
bool verbose
Definition: anyoption.h:200
bool posix_style
Definition: anyoption.h:199
bool file_set
Definition: anyoption.h:197
int argc
Definition: anyoption.h:163
bool mem_allocated
Definition: anyoption.h:198
int usage_lines
Definition: anyoption.h:194
char ** values
Definition: anyoption.h:188
int max_options
Definition: anyoption.h:174
char comment
Definition: anyoption.h:209
int max_usage_lines
Definition: anyoption.h:193
char * appname
Definition: anyoption.h:166
char long_opt_prefix[MAX_LONG_PREFIX_LENGTH+1]
Definition: anyoption.h:205

Here is the call graph for this function:

void justValue ( char *  value)
private

Definition at line 1096 of file anyoption.cpp.

Referenced by processLine().

1097 {
1098 
1099  if ( strlen(chomp(type)) == 1 ){ /* this is a char option */
1100  for( int i = 0 ; i < optchar_counter ; i++ ){
1101  if( optionchars[i] == type[0] ){ /* match */
1102  if( optchartype[i] == COMMON_FLAG ||
1103  optchartype[i] == FILE_FLAG )
1104  {
1105  setFlagOn( type[0] );
1106  return;
1107  }
1108  }
1109  }
1110  }
1111  /* if no char options matched */
1112  for( int i = 0 ; i < option_counter ; i++ ){
1113  if( strcmp( options[i], type ) == 0 ){ /* match */
1114  if( optiontype[i] == COMMON_FLAG ||
1115  optiontype[i] == FILE_FLAG )
1116  {
1117  setFlagOn( type );
1118  return;
1119  }
1120  }
1121  }
1122  printVerbose( "Unknown option in resourcefile : " );
1123  printVerbose( type );
1124  printVerbose( );
1125 }
char * chomp(char *str)
Definition: anyoption.cpp:1053
int * optiontype
Definition: anyoption.h:176
bool setFlagOn(const char *option)
Definition: anyoption.cpp:859
int optchar_counter
Definition: anyoption.h:185
int option_counter
Definition: anyoption.h:178
void printVerbose()
Definition: anyoption.cpp:329
const char ** options
Definition: anyoption.h:175
#define FILE_FLAG
Definition: anyoption.h:14
#define COMMON_FLAG
Definition: anyoption.h:12
int * optchartype
Definition: anyoption.h:183
char * optionchars
Definition: anyoption.h:182

Here is the call graph for this function:

Here is the caller graph for this function:

bool matchChar ( char  c)
private

Definition at line 738 of file anyoption.cpp.

Referenced by parsePOSIX().

739 {
740  for( int i = 0 ; i < optchar_counter ; i++ ){
741  if( optionchars[i] == c ) { /* found match */
742  if(optchartype[i] == COMMON_OPT ||
743  optchartype[i] == COMMAND_OPT )
744  { /* an option store and stop scanning */
745  return true;
746  }else if( optchartype[i] == COMMON_FLAG ||
747  optchartype[i] == COMMAND_FLAG ) { /* a flag store and keep scanning */
748  setFlagOn( c );
749  return false;
750  }
751  }
752  }
753  printVerbose( "Unknown command argument option : " );
754  printVerbose( c ) ;
755  printVerbose( );
756  printAutoUsage();
757  return false;
758 }
bool setFlagOn(const char *option)
Definition: anyoption.cpp:859
void printAutoUsage()
Definition: anyoption.cpp:1133
#define COMMON_OPT
Definition: anyoption.h:9
int optchar_counter
Definition: anyoption.h:185
void printVerbose()
Definition: anyoption.cpp:329
#define COMMAND_FLAG
Definition: anyoption.h:13
#define COMMON_FLAG
Definition: anyoption.h:12
int * optchartype
Definition: anyoption.h:183
char * optionchars
Definition: anyoption.h:182
#define COMMAND_OPT
Definition: anyoption.h:10

Here is the call graph for this function:

Here is the caller graph for this function:

int matchOpt ( char *  opt)
private

Definition at line 715 of file anyoption.cpp.

Referenced by parseGNU().

716 {
717  for( int i = 0 ; i < option_counter ; i++ ){
718  if( strcmp( options[i], opt ) == 0 ){
719  if( optiontype[i] == COMMON_OPT ||
720  optiontype[i] == COMMAND_OPT )
721  { /* found option return index */
722  return i;
723  }else if( optiontype[i] == COMMON_FLAG ||
724  optiontype[i] == COMMAND_FLAG )
725  { /* found flag, set it */
726  setFlagOn( opt );
727  return -1;
728  }
729  }
730  }
731  printVerbose( "Unknown command argument option : " );
732  printVerbose( opt ) ;
733  printVerbose( );
734  printAutoUsage();
735  return -1;
736 }
int * optiontype
Definition: anyoption.h:176
bool setFlagOn(const char *option)
Definition: anyoption.cpp:859
void printAutoUsage()
Definition: anyoption.cpp:1133
#define COMMON_OPT
Definition: anyoption.h:9
int option_counter
Definition: anyoption.h:178
void printVerbose()
Definition: anyoption.cpp:329
#define COMMAND_FLAG
Definition: anyoption.h:13
const char ** options
Definition: anyoption.h:175
#define COMMON_FLAG
Definition: anyoption.h:12
#define COMMAND_OPT
Definition: anyoption.h:10

Here is the call graph for this function:

Here is the caller graph for this function:

void noPOSIX ( )

Definition at line 310 of file anyoption.cpp.

311 {
312  posix_style = false;
313 }
bool posix_style
Definition: anyoption.h:199
int parseGNU ( char *  arg)
private

Definition at line 680 of file anyoption.cpp.

Referenced by processCommandArgs().

681 {
682  int split_at = 0;
683  /* if has a '=' sign get value */
684  for( unsigned int i = 0 ; i < strlen(arg) ; i++ ){
685  if(arg[i] == equalsign ){
686  split_at = i ; /* store index */
687  i = strlen(arg); /* get out of loop */
688  }
689  }
690  if( split_at > 0 ){ /* it is an option value pair */
691  char* tmp = (char*) malloc( (split_at+1)*sizeof(char) );
692  for( int i = 0 ; i < split_at ; i++ )
693  tmp[i] = arg[i];
694  tmp[split_at] = '\0';
695 
696  if ( matchOpt( tmp ) >= 0 ){
697  setValue( options[matchOpt(tmp)] , arg+split_at+1 );
698  free (tmp);
699  }else{
700  printVerbose( "Unknown command argument option : " );
701  printVerbose( arg );
702  printVerbose( );
703  printAutoUsage();
704  free (tmp);
705  return -1;
706  }
707  }else{ /* regular options with no '=' sign */
708  return matchOpt(arg);
709  }
710  return -1;
711 }
int matchOpt(char *opt)
Definition: anyoption.cpp:715
void printAutoUsage()
Definition: anyoption.cpp:1133
char equalsign
Definition: anyoption.h:208
void printVerbose()
Definition: anyoption.cpp:329
const char ** options
Definition: anyoption.h:175
bool setValue(const char *option, char *value)
Definition: anyoption.cpp:844

Here is the call graph for this function:

Here is the caller graph for this function:

char parsePOSIX ( char *  arg)
private

Definition at line 653 of file anyoption.cpp.

Referenced by processCommandArgs().

654 {
655 
656  for( unsigned int i = 0 ; i < strlen(arg) ; i++ ){
657  char ch = arg[i] ;
658  if( matchChar(ch) ) { /* keep matching flags till an option */
659  /*if last char argv[++i] is the value */
660  if( i == strlen(arg)-1 ){
661  return ch;
662  }else{/* else the rest of arg is the value */
663  i++; /* skip any '=' and ' ' */
664  while( arg[i] == whitespace
665  || arg[i] == equalsign )
666  i++;
667  setValue( ch , arg+i );
668  return '0';
669  }
670  }
671  }
672  printVerbose( "Unknown command argument option : " );
673  printVerbose( arg );
674  printVerbose( );
675  printAutoUsage();
676  return '0';
677 }
char whitespace
Definition: anyoption.h:212
void printAutoUsage()
Definition: anyoption.cpp:1133
char equalsign
Definition: anyoption.h:208
void printVerbose()
Definition: anyoption.cpp:329
bool matchChar(char c)
Definition: anyoption.cpp:738
bool setValue(const char *option, char *value)
Definition: anyoption.cpp:844

Here is the call graph for this function:

Here is the caller graph for this function:

bool POSIX ( )
private

Definition at line 316 of file anyoption.cpp.

Referenced by addOption(), and processCommandArgs().

317 {
318  return posix_style;
319 }
bool posix_style
Definition: anyoption.h:199

Here is the caller graph for this function:

void printAutoUsage ( )

Definition at line 1133 of file anyoption.cpp.

Referenced by matchChar(), matchOpt(), parseGNU(), parsePOSIX(), and processCommandArgs().

1134 {
1135  if( autousage ) printUsage();
1136 }
bool autousage
Definition: anyoption.h:219
void printUsage()
Definition: anyoption.cpp:1139

Here is the call graph for this function:

Here is the caller graph for this function:

void printHelp ( )
void printUsage ( )

Definition at line 1139 of file anyoption.cpp.

Referenced by main(), and printAutoUsage().

1140 {
1141 
1142  if( once ) {
1143  once = false ;
1144  cout << endl ;
1145  for( int i = 0 ; i < usage_lines ; i++ )
1146  cout << usage[i] << endl ;
1147  cout << endl ;
1148  }
1149 }
const char ** usage
Definition: anyoption.h:192
bool once
Definition: anyoption.h:216
int usage_lines
Definition: anyoption.h:194

Here is the caller graph for this function:

void printVerbose ( const char *  msg)
private

Definition at line 335 of file anyoption.cpp.

336 {
337  if( verbose )
338  cout << msg ;
339 }
bool verbose
Definition: anyoption.h:200
void printVerbose ( char *  msg)
private

Definition at line 342 of file anyoption.cpp.

343 {
344  if( verbose )
345  cout << msg ;
346 }
bool verbose
Definition: anyoption.h:200
void printVerbose ( char  ch)
private

Definition at line 349 of file anyoption.cpp.

350 {
351  if( verbose )
352  cout << ch ;
353 }
bool verbose
Definition: anyoption.h:200
void printVerbose ( )
private

Definition at line 329 of file anyoption.cpp.

Referenced by addOption(), justValue(), matchChar(), matchOpt(), parseGNU(), parsePOSIX(), processCommandArgs(), and valuePairs().

330 {
331  if( verbose )
332  cout << endl ;
333 }
bool verbose
Definition: anyoption.h:200

Here is the caller graph for this function:

void processCommandArgs ( )

Definition at line 610 of file anyoption.cpp.

Referenced by main(), and processCommandArgs().

611 {
612  if( ! ( valueStoreOK() && CommandSet() ) )
613  return;
614 
615  if( max_legal_args == 0 )
617  new_argv = (int*) malloc( (max_legal_args+1) * sizeof(int) );
618  for( int i = 1 ; i < argc ; i++ ){/* ignore first argv */
619  if( argv[i][0] == long_opt_prefix[0] &&
620  argv[i][1] == long_opt_prefix[1] ) { /* long GNU option */
621  int match_at = parseGNU( argv[i]+2 ); /* skip -- */
622  if( match_at >= 0 && i < argc-1 ) /* found match */
623  setValue( options[match_at] , argv[++i] );
624  }else if( argv[i][0] == opt_prefix_char ) { /* POSIX char */
625  if( POSIX() ){
626  char ch = parsePOSIX( argv[i]+1 );/* skip - */
627  if( ch != '0' && i < argc-1 ) /* matching char */
628  setValue( ch , argv[++i] );
629  } else { /* treat it as GNU option with a - */
630  int match_at = parseGNU( argv[i]+1 ); /* skip - */
631  if( match_at >= 0 && i < argc-1 ) /* found match */
632  setValue( options[match_at] , argv[++i] );
633  }
634  }else { /* not option but an argument keep index */
635  if( new_argc < max_legal_args ){
636  new_argv[ new_argc ] = i ;
637  new_argc++;
638  }else{ /* ignore extra arguments */
639  printVerbose( "Ignoring extra argument: " );
640  printVerbose( argv[i] );
641  printVerbose( );
642  printAutoUsage();
643  }
644  printVerbose( "Unknown command argument option : " );
645  printVerbose( argv[i] );
646  printVerbose( );
647  printAutoUsage();
648  }
649  }
650 }
char opt_prefix_char
Definition: anyoption.h:204
int new_argc
Definition: anyoption.h:169
char ** argv
Definition: anyoption.h:164
void printAutoUsage()
Definition: anyoption.cpp:1133
bool valueStoreOK()
Definition: anyoption.cpp:761
char parsePOSIX(char *arg)
Definition: anyoption.cpp:653
void printVerbose()
Definition: anyoption.cpp:329
int max_legal_args
Definition: anyoption.h:170
int * new_argv
Definition: anyoption.h:168
int argc
Definition: anyoption.h:163
const char ** options
Definition: anyoption.h:175
bool setValue(const char *option, char *value)
Definition: anyoption.cpp:844
int parseGNU(char *arg)
Definition: anyoption.cpp:680
bool CommandSet()
Definition: anyoption.cpp:298
char long_opt_prefix[MAX_LONG_PREFIX_LENGTH+1]
Definition: anyoption.h:205
bool POSIX()
Definition: anyoption.cpp:316

Here is the call graph for this function:

Here is the caller graph for this function:

void processCommandArgs ( int  max_args)

Definition at line 589 of file anyoption.cpp.

590 {
591  max_legal_args = max_args;
593 }
int max_legal_args
Definition: anyoption.h:170
void processCommandArgs()
Definition: anyoption.cpp:610

Here is the call graph for this function:

void processCommandArgs ( int  _argc,
char **  _argv 
)

Definition at line 603 of file anyoption.cpp.

604 {
605  useCommandArgs( _argc, _argv );
607 }
void useCommandArgs(int _argc, char **_argv)
Definition: anyoption.cpp:368
void processCommandArgs()
Definition: anyoption.cpp:610

Here is the call graph for this function:

void processCommandArgs ( int  _argc,
char **  _argv,
int  max_args 
)

Definition at line 596 of file anyoption.cpp.

597 {
598  max_legal_args = max_args;
599  processCommandArgs( _argc, _argv );
600 }
int max_legal_args
Definition: anyoption.h:170
void processCommandArgs()
Definition: anyoption.cpp:610

Here is the call graph for this function:

bool processFile ( )

Definition at line 922 of file anyoption.cpp.

Referenced by processFile().

923 {
924  if( ! (valueStoreOK() && FileSet()) )
925  return false;
926  return ( consumeFile(readFile()) );
927 }
bool consumeFile(char *buffer)
Definition: anyoption.cpp:971
bool valueStoreOK()
Definition: anyoption.cpp:761
bool FileSet()
Definition: anyoption.cpp:304
char * readFile()
Definition: anyoption.cpp:937

Here is the call graph for this function:

Here is the caller graph for this function:

bool processFile ( const char *  _filename)

Definition at line 930 of file anyoption.cpp.

931 {
933  return ( processFile() );
934 }
void useFiileName(const char *_filename)
Definition: anyoption.cpp:378
const char * filename
Definition: anyoption.h:165
bool processFile()
Definition: anyoption.cpp:922

Here is the call graph for this function:

void processLine ( char *  theline,
int  length 
)
private

Definition at line 1023 of file anyoption.cpp.

Referenced by consumeFile().

1024 {
1025  bool found = false;
1026  char *pline = (char*) malloc( (length+1)*sizeof(char) );
1027  for( int i = 0 ; i < length ; i ++ )
1028  pline[i]= *(theline++);
1029  pline[length] = nullterminate;
1030  char *cursor = pline ; /* preserve the ptr */
1031  if( *cursor == delimiter || *(cursor+length-1) == delimiter ){
1032  justValue( pline );/* line with start/end delimiter */
1033  }else{
1034  for( int i = 1 ; i < length-1 && !found ; i++){/* delimiter */
1035  if( *cursor == delimiter ){
1036  *(cursor-1) = nullterminate; /* two strings */
1037  found = true;
1038  valuePairs( pline , cursor+1 );
1039  }
1040  cursor++;
1041  }
1042  cursor++;
1043  if( !found ) /* not a pair */
1044  justValue( pline );
1045  }
1046  free (pline);
1047 }
char delimiter
Definition: anyoption.h:210
char nullterminate
Definition: anyoption.h:213
void justValue(char *value)
Definition: anyoption.cpp:1096
void valuePairs(char *type, char *value)
Definition: anyoption.cpp:1065

Here is the call graph for this function:

Here is the caller graph for this function:

void processOptions ( )

Definition at line 582 of file anyoption.cpp.

583 {
584  if( ! valueStoreOK() )
585  return;
586 }
bool valueStoreOK()
Definition: anyoption.cpp:761

Here is the call graph for this function:

char * readFile ( )
private

Definition at line 937 of file anyoption.cpp.

Referenced by processFile().

938 {
939  return ( readFile(filename) );
940 }
const char * filename
Definition: anyoption.h:165
char * readFile()
Definition: anyoption.cpp:937

Here is the caller graph for this function:

char * readFile ( const char *  fname)
private

Definition at line 947 of file anyoption.cpp.

948 {
949  int length;
950  char *buffer;
951  ifstream is;
952  is.open ( fname , ifstream::in );
953  if( ! is.good() ){
954  is.close();
955  return NULL;
956  }
957  is.seekg (0, ios::end);
958  length = is.tellg();
959  is.seekg (0, ios::beg);
960  buffer = (char*) malloc(length*sizeof(char));
961  is.read (buffer,length);
962  is.close();
963  return buffer;
964 }
void setCommandFlag ( const char *  opt_string)

Definition at line 411 of file anyoption.cpp.

412 {
413  addOption( opt , COMMAND_FLAG );
414  g_value_counter++;
415 }
int g_value_counter
Definition: anyoption.h:189
#define COMMAND_FLAG
Definition: anyoption.h:13
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setCommandFlag ( char  opt_char)

Definition at line 418 of file anyoption.cpp.

419 {
420  addOption( opt , COMMAND_FLAG );
421  g_value_counter++;
422 }
int g_value_counter
Definition: anyoption.h:189
#define COMMAND_FLAG
Definition: anyoption.h:13
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setCommandFlag ( const char *  opt_string,
char  opt_char 
)

Definition at line 425 of file anyoption.cpp.

426 {
427  addOption( opt , COMMAND_FLAG );
428  addOption( optchar , COMMAND_FLAG );
429  g_value_counter++;
430 }
int g_value_counter
Definition: anyoption.h:189
#define COMMAND_FLAG
Definition: anyoption.h:13
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setCommandLongPrefix ( char *  _prefix)

Definition at line 275 of file anyoption.cpp.

276 {
277  if( strlen( _prefix ) > MAX_LONG_PREFIX_LENGTH ){
278  *( _prefix + MAX_LONG_PREFIX_LENGTH ) = '\0';
279  }
280 
281  strcpy (long_opt_prefix, _prefix);
282 }
#define MAX_LONG_PREFIX_LENGTH
Definition: anyoption.h:23
char long_opt_prefix[MAX_LONG_PREFIX_LENGTH+1]
Definition: anyoption.h:205
void setCommandOption ( const char *  opt_string)

Definition at line 389 of file anyoption.cpp.

390 {
391  addOption( opt , COMMAND_OPT );
392  g_value_counter++;
393 }
int g_value_counter
Definition: anyoption.h:189
#define COMMAND_OPT
Definition: anyoption.h:10
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setCommandOption ( char  opt_char)

Definition at line 396 of file anyoption.cpp.

397 {
398  addOption( opt , COMMAND_OPT );
399  g_value_counter++;
400 }
int g_value_counter
Definition: anyoption.h:189
#define COMMAND_OPT
Definition: anyoption.h:10
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setCommandOption ( const char *  opt_string,
char  opt_char 
)

Definition at line 403 of file anyoption.cpp.

404 {
405  addOption( opt , COMMAND_OPT );
406  addOption( optchar , COMMAND_OPT );
407  g_value_counter++;
408 }
int g_value_counter
Definition: anyoption.h:189
#define COMMAND_OPT
Definition: anyoption.h:10
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setCommandPrefixChar ( char  _prefix)

Definition at line 269 of file anyoption.cpp.

270 {
271  opt_prefix_char = _prefix;
272 }
char opt_prefix_char
Definition: anyoption.h:204
void setFileCommentChar ( char  _comment)

Definition at line 285 of file anyoption.cpp.

286 {
287  file_delimiter_char = _comment;
288 }
char file_delimiter_char
Definition: anyoption.h:206
void setFileDelimiterChar ( char  _delimiter)

Definition at line 292 of file anyoption.cpp.

293 {
294  file_comment_char = _delimiter ;
295 }
char file_comment_char
Definition: anyoption.h:207
void setFileFlag ( const char *  opt_string)

Definition at line 455 of file anyoption.cpp.

456 {
457  addOption( opt , FILE_FLAG );
458  g_value_counter++;
459 }
int g_value_counter
Definition: anyoption.h:189
#define FILE_FLAG
Definition: anyoption.h:14
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setFileFlag ( char  opt_char)

Definition at line 462 of file anyoption.cpp.

463 {
464  addOption( opt , FILE_FLAG );
465  g_value_counter++;
466 }
int g_value_counter
Definition: anyoption.h:189
#define FILE_FLAG
Definition: anyoption.h:14
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setFileFlag ( const char *  opt_string,
char  opt_char 
)

Definition at line 469 of file anyoption.cpp.

470 {
471  addOption( opt , FILE_FLAG );
472  addOption( optchar , FILE_FLAG );
473  g_value_counter++;
474 }
int g_value_counter
Definition: anyoption.h:189
#define FILE_FLAG
Definition: anyoption.h:14
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setFileOption ( const char *  opt_string)

Definition at line 433 of file anyoption.cpp.

434 {
435  addOption( opt , FILE_OPT );
436  g_value_counter++;
437 }
int g_value_counter
Definition: anyoption.h:189
void addOption(const char *option, int type)
Definition: anyoption.cpp:521
#define FILE_OPT
Definition: anyoption.h:11

Here is the call graph for this function:

void setFileOption ( char  opt_char)

Definition at line 440 of file anyoption.cpp.

441 {
442  addOption( opt , FILE_OPT );
443  g_value_counter++;
444 }
int g_value_counter
Definition: anyoption.h:189
void addOption(const char *option, int type)
Definition: anyoption.cpp:521
#define FILE_OPT
Definition: anyoption.h:11

Here is the call graph for this function:

void setFileOption ( const char *  opt_string,
char  opt_char 
)

Definition at line 447 of file anyoption.cpp.

448 {
449  addOption( opt , FILE_OPT );
450  addOption( optchar, FILE_OPT );
451  g_value_counter++;
452 }
int g_value_counter
Definition: anyoption.h:189
void addOption(const char *option, int type)
Definition: anyoption.cpp:521
#define FILE_OPT
Definition: anyoption.h:11

Here is the call graph for this function:

void setFlag ( const char *  opt_string)

Definition at line 499 of file anyoption.cpp.

Referenced by main().

500 {
501  addOption( opt , COMMON_FLAG );
502  g_value_counter++;
503 }
int g_value_counter
Definition: anyoption.h:189
#define COMMON_FLAG
Definition: anyoption.h:12
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

Here is the caller graph for this function:

void setFlag ( char  opt_char)

Definition at line 506 of file anyoption.cpp.

507 {
508  addOption( opt , COMMON_FLAG );
509  g_value_counter++;
510 }
int g_value_counter
Definition: anyoption.h:189
#define COMMON_FLAG
Definition: anyoption.h:12
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setFlag ( const char *  opt_string,
char  opt_char 
)

Definition at line 513 of file anyoption.cpp.

514 {
515  addOption( opt , COMMON_FLAG );
516  addOption( optchar , COMMON_FLAG );
517  g_value_counter++;
518 }
int g_value_counter
Definition: anyoption.h:189
#define COMMON_FLAG
Definition: anyoption.h:12
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

bool setFlagOn ( const char *  option)
private

Definition at line 859 of file anyoption.cpp.

Referenced by justValue(), matchChar(), and matchOpt().

860 {
861  if( !valueStoreOK() )
862  return false;
863  for( int i = 0 ; i < option_counter ; i++ ){
864  if( strcmp( options[i], option ) == 0 ){
865  values[ optionindex[i] ] = (char*) malloc((strlen(TRUE_FLAG)+1)*sizeof(char));
866  strcpy( values[ optionindex[i] ] , TRUE_FLAG );
867  return true;
868  }
869  }
870  return false;
871 }
bool valueStoreOK()
Definition: anyoption.cpp:761
int option_counter
Definition: anyoption.h:178
#define TRUE_FLAG
Definition: anyoption.h:28
const char ** options
Definition: anyoption.h:175
char ** values
Definition: anyoption.h:188
int * optionindex
Definition: anyoption.h:177

Here is the call graph for this function:

Here is the caller graph for this function:

bool setFlagOn ( char  optchar)
private

Definition at line 889 of file anyoption.cpp.

890 {
891  if( !valueStoreOK() )
892  return false;
893  for( int i = 0 ; i < optchar_counter ; i++ ){
894  if( optionchars[i] == option ){
895  values[ optcharindex[i] ] = (char*) malloc((strlen(TRUE_FLAG)+1)*sizeof(char));
896  strcpy( values[ optcharindex[i] ] , TRUE_FLAG );
897  return true;
898  }
899  }
900  return false;
901 }
int * optcharindex
Definition: anyoption.h:184
bool valueStoreOK()
Definition: anyoption.cpp:761
int optchar_counter
Definition: anyoption.h:185
#define TRUE_FLAG
Definition: anyoption.h:28
char ** values
Definition: anyoption.h:188
char * optionchars
Definition: anyoption.h:182

Here is the call graph for this function:

void setOption ( const char *  opt_string)

Definition at line 477 of file anyoption.cpp.

Referenced by main().

478 {
479  addOption( opt , COMMON_OPT );
480  g_value_counter++;
481 }
#define COMMON_OPT
Definition: anyoption.h:9
int g_value_counter
Definition: anyoption.h:189
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

Here is the caller graph for this function:

void setOption ( char  opt_char)

Definition at line 484 of file anyoption.cpp.

485 {
486  addOption( opt , COMMON_OPT );
487  g_value_counter++;
488 }
#define COMMON_OPT
Definition: anyoption.h:9
int g_value_counter
Definition: anyoption.h:189
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

void setOption ( const char *  opt_string,
char  opt_char 
)

Definition at line 491 of file anyoption.cpp.

492 {
493  addOption( opt , COMMON_OPT );
494  addOption( optchar , COMMON_OPT );
495  g_value_counter++;
496 }
#define COMMON_OPT
Definition: anyoption.h:9
int g_value_counter
Definition: anyoption.h:189
void addOption(const char *option, int type)
Definition: anyoption.cpp:521

Here is the call graph for this function:

bool setValue ( const char *  option,
char *  value 
)
private

Definition at line 844 of file anyoption.cpp.

Referenced by parseGNU(), parsePOSIX(), processCommandArgs(), and valuePairs().

845 {
846  if( !valueStoreOK() )
847  return false;
848  for( int i = 0 ; i < option_counter ; i++ ){
849  if( strcmp( options[i], option ) == 0 ){
850  values[ optionindex[i] ] = (char*) malloc((strlen(value)+1)*sizeof(char));
851  strcpy( values[ optionindex[i] ], value );
852  return true;
853  }
854  }
855  return false;
856 }
bool valueStoreOK()
Definition: anyoption.cpp:761
int option_counter
Definition: anyoption.h:178
const char ** options
Definition: anyoption.h:175
char ** values
Definition: anyoption.h:188
int * optionindex
Definition: anyoption.h:177

Here is the call graph for this function:

Here is the caller graph for this function:

bool setValue ( char  optchar,
char *  value 
)
private

Definition at line 874 of file anyoption.cpp.

875 {
876  if( !valueStoreOK() )
877  return false;
878  for( int i = 0 ; i < optchar_counter ; i++ ){
879  if( optionchars[i] == option ){
880  values[ optcharindex[i] ] = (char*) malloc((strlen(value)+1)*sizeof(char));
881  strcpy( values[ optcharindex[i] ], value );
882  return true;
883  }
884  }
885  return false;
886 }
int * optcharindex
Definition: anyoption.h:184
bool valueStoreOK()
Definition: anyoption.cpp:761
int optchar_counter
Definition: anyoption.h:185
char ** values
Definition: anyoption.h:188
char * optionchars
Definition: anyoption.h:182

Here is the call graph for this function:

void setVerbose ( )

Definition at line 323 of file anyoption.cpp.

324 {
325  verbose = true ;
326 }
bool verbose
Definition: anyoption.h:200
void useCommandArgs ( int  _argc,
char **  _argv 
)

Definition at line 368 of file anyoption.cpp.

Referenced by processCommandArgs().

369 {
370  argc = _argc;
371  argv = _argv;
372  command_set = true;
373  appname = argv[0];
374  if(argc > 1) hasoptions = true;
375 }
bool hasoptions
Definition: anyoption.h:218
char ** argv
Definition: anyoption.h:164
bool command_set
Definition: anyoption.h:196
int argc
Definition: anyoption.h:163
char * appname
Definition: anyoption.h:166

Here is the caller graph for this function:

void useFiileName ( const char *  _filename)

Definition at line 378 of file anyoption.cpp.

Referenced by processFile().

379 {
380  filename = _filename;
381  file_set = true;
382 }
const char * filename
Definition: anyoption.h:165
bool file_set
Definition: anyoption.h:197

Here is the caller graph for this function:

void valuePairs ( char *  type,
char *  value 
)
private

Definition at line 1065 of file anyoption.cpp.

Referenced by processLine().

1066 {
1067  if ( strlen(chomp(type)) == 1 ){ /* this is a char option */
1068  for( int i = 0 ; i < optchar_counter ; i++ ){
1069  if( optionchars[i] == type[0] ){ /* match */
1070  if( optchartype[i] == COMMON_OPT ||
1071  optchartype[i] == FILE_OPT )
1072  {
1073  setValue( type[0] , chomp(value) );
1074  return;
1075  }
1076  }
1077  }
1078  }
1079  /* if no char options matched */
1080  for( int i = 0 ; i < option_counter ; i++ ){
1081  if( strcmp( options[i], type ) == 0 ){ /* match */
1082  if( optiontype[i] == COMMON_OPT ||
1083  optiontype[i] == FILE_OPT )
1084  {
1085  setValue( type , chomp(value) );
1086  return;
1087  }
1088  }
1089  }
1090  printVerbose( "Unknown option in resourcefile : " );
1091  printVerbose( type );
1092  printVerbose( );
1093 }
char * chomp(char *str)
Definition: anyoption.cpp:1053
int * optiontype
Definition: anyoption.h:176
#define COMMON_OPT
Definition: anyoption.h:9
int optchar_counter
Definition: anyoption.h:185
int option_counter
Definition: anyoption.h:178
void printVerbose()
Definition: anyoption.cpp:329
const char ** options
Definition: anyoption.h:175
int * optchartype
Definition: anyoption.h:183
bool setValue(const char *option, char *value)
Definition: anyoption.cpp:844
char * optionchars
Definition: anyoption.h:182
#define FILE_OPT
Definition: anyoption.h:11

Here is the call graph for this function:

Here is the caller graph for this function:

bool valueStoreOK ( )
private

Definition at line 761 of file anyoption.cpp.

Referenced by getFlag(), getValue(), processCommandArgs(), processFile(), processOptions(), setFlagOn(), and setValue().

762 {
763  int size= 0;
764  if( !set ){
765  if( g_value_counter > 0 ){
766  size = g_value_counter * sizeof(char*);
767  values = (char**)malloc( size );
768  for( int i = 0 ; i < g_value_counter ; i++)
769  values[i] = NULL;
770  set = true;
771  }
772  }
773  return set;
774 }
int g_value_counter
Definition: anyoption.h:189
char ** values
Definition: anyoption.h:188

Here is the caller graph for this function:

Member Data Documentation

char* appname
private

Definition at line 166 of file anyoption.h.

Referenced by init(), and useCommandArgs().

int argc
private

Definition at line 163 of file anyoption.h.

Referenced by init(), processCommandArgs(), and useCommandArgs().

char** argv
private

Definition at line 164 of file anyoption.h.

Referenced by getArgv(), init(), processCommandArgs(), and useCommandArgs().

bool autousage
private

Definition at line 219 of file anyoption.h.

Referenced by autoUsagePrint(), init(), and printAutoUsage().

bool command_set
private

Definition at line 196 of file anyoption.h.

Referenced by CommandSet(), init(), and useCommandArgs().

char comment
private

Definition at line 209 of file anyoption.h.

Referenced by consumeFile(), and init().

char delimiter
private

Definition at line 210 of file anyoption.h.

Referenced by init(), and processLine().

char endofline
private

Definition at line 211 of file anyoption.h.

Referenced by consumeFile(), and init().

char equalsign
private

Definition at line 208 of file anyoption.h.

Referenced by init(), parseGNU(), and parsePOSIX().

char file_comment_char
private

Definition at line 207 of file anyoption.h.

Referenced by init(), and setFileDelimiterChar().

char file_delimiter_char
private

Definition at line 206 of file anyoption.h.

Referenced by init(), and setFileCommentChar().

bool file_set
private

Definition at line 197 of file anyoption.h.

Referenced by FileSet(), init(), and useFiileName().

const char* filename
private

Definition at line 165 of file anyoption.h.

Referenced by init(), readFile(), and useFiileName().

int g_value_counter
private
bool hasoptions
private

Definition at line 218 of file anyoption.h.

Referenced by hasOptions(), init(), and useCommandArgs().

char long_opt_prefix[MAX_LONG_PREFIX_LENGTH+1]
private

Definition at line 205 of file anyoption.h.

Referenced by init(), processCommandArgs(), and setCommandLongPrefix().

int max_char_options
private

Definition at line 181 of file anyoption.h.

Referenced by addOption(), alloc(), doubleCharStorage(), and init().

int max_legal_args
private

Definition at line 170 of file anyoption.h.

Referenced by init(), and processCommandArgs().

int max_options
private

Definition at line 174 of file anyoption.h.

Referenced by addOption(), alloc(), doubleOptStorage(), and init().

int max_usage_lines
private

Definition at line 193 of file anyoption.h.

Referenced by addUsage(), alloc(), doubleUsageStorage(), and init().

bool mem_allocated
private

Definition at line 198 of file anyoption.h.

Referenced by alloc(), init(), and ~AnyOption().

int new_argc
private

Definition at line 169 of file anyoption.h.

Referenced by getArgc(), getArgv(), init(), and processCommandArgs().

int* new_argv
private

Definition at line 168 of file anyoption.h.

Referenced by cleanup(), getArgv(), init(), and processCommandArgs().

char nullterminate
private

Definition at line 213 of file anyoption.h.

Referenced by chomp(), init(), and processLine().

bool once
private

Definition at line 216 of file anyoption.h.

Referenced by init(), and printUsage().

char opt_prefix_char
private

Definition at line 204 of file anyoption.h.

Referenced by init(), processCommandArgs(), and setCommandPrefixChar().

int optchar_counter
private
int* optcharindex
private
int* optchartype
private

Definition at line 183 of file anyoption.h.

Referenced by addOption(), alloc(), cleanup(), doubleCharStorage(), justValue(), matchChar(), and valuePairs().

int option_counter
private
char* optionchars
private
int* optionindex
private
int* optiontype
private

Definition at line 176 of file anyoption.h.

Referenced by addOption(), alloc(), cleanup(), doubleOptStorage(), justValue(), matchOpt(), and valuePairs().

bool posix_style
private

Definition at line 199 of file anyoption.h.

Referenced by init(), noPOSIX(), and POSIX().

bool print_help
private

Definition at line 202 of file anyoption.h.

bool print_usage
private

Definition at line 201 of file anyoption.h.

bool set
private

Definition at line 215 of file anyoption.h.

const char** usage
private

Definition at line 192 of file anyoption.h.

Referenced by addUsage(), alloc(), cleanup(), doubleUsageStorage(), and printUsage().

int usage_lines
private

Definition at line 194 of file anyoption.h.

Referenced by addUsage(), init(), and printUsage().

char** values
private

Definition at line 188 of file anyoption.h.

Referenced by cleanup(), getFlag(), getValue(), init(), setFlagOn(), setValue(), and valueStoreOK().

bool verbose
private

Definition at line 200 of file anyoption.h.

Referenced by init(), printVerbose(), and setVerbose().

char whitespace
private

Definition at line 212 of file anyoption.h.

Referenced by chomp(), init(), and parsePOSIX().


The documentation for this class was generated from the following files: