18 #ifndef __utlCommandLineParser_h 19 #define __utlCommandLineParser_h 43 #define utl_usage(usage) utl::utlOption((char*)NULL,(unsigned int)argc,(char**)argv,(char*)NULL,(char*)usage) 49 #define utl_help(str) utl::utlOption((char*)NULL,(unsigned int)argc,(char**)argv,str,(char*)NULL) 58 #define utl_option(name,defaut,usage) utl::utlOption((char*)name,(unsigned int)argc,(char**)argv,defaut,(char*)usage) 65 #define utl_showdoc(argu) if (utl_option(argu,(const char *)NULL,0)) return 0; 72 utlOption(
const char *
const name,
const unsigned int argc,
char **argv,
const char *
const defaut,
const char *
const usage=NULL)
74 static bool first=
true, visu=
false;
75 const char *res = NULL;
79 visu =
utlOption(
"-h",argc,argv,(
const char*)NULL)!=NULL;
80 visu |=
utlOption(
"-help",argc,argv,(
char*)NULL)!=NULL;
81 visu |=
utlOption(
"--help",argc,argv,(
char*)NULL)!=NULL;
89 std::string argv0Str(argv[0]);
90 unsigned found = argv0Str.find_last_of(
"/\\");
92 std::fprintf(stderr,
" : %s",usage);
93 std::fprintf(stderr,
" (%s, %s)\n\n",__DATE__,__TIME__);
96 std::fprintf(stderr,
"%s\n",defaut);
103 while (k<argc && strcmp(argv[k],name))
105 res=(k++==argc?defaut:(k==argc?argv[--k]:argv[k]));
117 utlOption(
const char *
const name,
const unsigned int argc,
char **argv,
const bool defaut,
const char *
const usage=NULL)
119 const char *s =
utlOption(name,argc,argv,(
const char*)NULL);
120 const bool res = s?(strcmp(s,
"false") && strcmp(s,
"FALSE") && strcmp(s,
"off") && strcmp(s,
"OFF") && strcmp(s,
"0")):defaut;
121 utlOption(name,0,NULL,res?
"true":
"false",usage);
126 utlOption(
const char *
const name,
const unsigned int argc,
char **argv,
const int defaut,
const char *
const usage=NULL)
128 const char *s =
utlOption(name,argc,argv,(
const char*)NULL);
129 const int res = s?atoi(s):defaut;
131 std::sprintf(tmp,
"%d",res);
137 utlOption(
const char *
const name,
const unsigned int argc,
char **argv,
const char defaut,
const char *
const usage=NULL)
139 const char *s =
utlOption(name,argc,argv,(
const char*)NULL);
140 const char res = s?s[0]:defaut;
149 utlOption(
const char *
const name,
const unsigned int argc,
char **argv,
const double defaut,
const char *
const usage=NULL)
151 const char *s =
utlOption(name,argc,argv,(
const char*)NULL);
152 const double res = s?atof(s):defaut;
154 std::sprintf(tmp,
"%g",res);
std::string GetColoredString(const std::string &str, const int color)
const char * utlOption(const char *const name, const unsigned int argc, char **argv, const char *const defaut, const char *const usage=NULL)