43 #include "EST_String.h"
44 #include "EST_io_aux.h"
45 #include "EST_Token.h"
46 #include "EST_cutils.h"
47 #include "EST_TList.h"
48 #include "EST_string_aux.h"
49 #include "EST_cmd_line.h"
50 #include "EST_Pathname.h"
51 #include "EST_Features.h"
56 static int valid_option(
const EST_Option &option,
const char *arg,
58 static void standard_options(
int argc,
char **argv,
const EST_String &usage);
62 static void output_man_options(
const EST_String &usage);
63 static void output_sgml_options(
const EST_String &usage);
64 static void output_sgml_synopsis(
char **argv,
const EST_String &usage);
71 if ((al.
val(
"-N", 0) !=
"true") &&
72 ((envname = getenv(
"IA_OP_FILE")) != 0))
73 if (op.
load(getenv(
"IA_OP_FILE")) != read_ok)
77 if (al.
val(
"-c", 0) !=
"")
78 if (op.
load(al.
val(
"-c")) != read_ok)
82 override_lib_ops(op, al);
84 if (al.
val(
"-ops", 0) ==
"true")
98 int parse_command_line(
int argc,
112 standard_options(argc,argv,usage);
116 est_progname = argv[0];
117 parse_usage(argv[0],usage,options,al);
119 for (i=1; i < argc; i++)
123 else if (streq(argv[i],
"-"))
125 else if (!valid_option(options,argv[i],arg))
128 EST_String(
": Unknown option \"")+argv[i]+
"\"\n");
132 if (options.
val(arg) ==
"true")
134 else if (options.
val(arg) ==
"<int>")
144 arg+
"\" not an int\n");
147 else if ((options.
val(arg) ==
"<float>") ||
148 (options.
val(arg) ==
"<double>"))
152 EST_String(
": missing float argument for \"")+
158 arg+
"\" not a float\n");
161 else if (options.
val(arg) ==
"<string>")
165 EST_String(
": missing string argument for \"")+
170 else if (options.
val(arg) ==
"<ofile>")
174 EST_String(
": missing ifile argument for \"")+
177 if (writable_file(argv[i]) == TRUE)
181 EST_String(
": output file not accessible \"")+
184 else if (options.
val(arg) ==
"<ifile>")
188 EST_String(
": missing ifile argument for \"")+
191 if (readable_file(argv[i]) == TRUE)
199 else if (options.
val(arg) ==
"<star>")
208 options.
val(argv[i])+
"\" (misparsed usage string)\n");
213 if (files.length() == 0)
219 static int valid_option(
const EST_Option &options,
const char *arg,
227 for (p = options.
list.head(); p != 0; p = p->next())
229 if (options.
key(p) == arg)
234 else if ((options.
val(p) ==
"<star>") &&
237 sarg = options.
key(p);
264 if ((ts.
peek().string() ==
"<string>") ||
265 (ts.
peek().string() ==
"<float>") ||
266 (ts.
peek().string() ==
"<double>") ||
267 (ts.
peek().string() ==
"<ifile>") ||
268 (ts.
peek().string() ==
"<ofile>") ||
269 (ts.
peek().string() ==
"<int>"))
272 if (ts.
peek().string() ==
"{")
278 EST_String(
": malformed default value for \"")+
279 t.string()+
"\" (missing closing brace)\n");
286 options.
add_item(t.string(),
"true");
294 cerr << progname << message;
295 cerr <<
"Type -h for help on options.\n";
299 static void standard_options(
int argc,
char **argv,
const EST_String &usage)
304 for (i=1; i < argc; i++)
306 if (streq(argv[i],
"-man_options"))
308 output_man_options(usage);
311 if (streq(argv[i],
"-sgml_options"))
313 output_sgml_options(usage);
316 if (streq(argv[i],
"-sgml_synopsis"))
318 output_sgml_synopsis(argv, usage);
321 if ((streq(argv[i],
"-h")) ||
322 (streq(argv[i],
"-help")) ||
323 (streq(argv[i],
"-?")) ||
324 (streq(argv[i],
"--help")))
327 cout <<
"Usage: " << full.filename() <<
" " << usage << endl;
330 if (((streq(argv[i],
"-version")) ||
331 (streq(argv[i],
"--version")))&&
334 cout << argv[0] <<
": " << est_name <<
" v" << est_tools_version << endl;
342 static void output_man_options(
const EST_String &usage)
346 int in_options = FALSE;
359 fprintf(stdout,
"\n.TP 8\n.BI \"%s \" ",(
const char *)t.string());
360 if ((ts.
peek().string() ==
"<string>") ||
361 (ts.
peek().string() ==
"<float>") ||
362 (ts.
peek().string() ==
"<double>") ||
363 (ts.
peek().string() ==
"<int>"))
364 fprintf(stdout,
"%s",(
const char *)ts.
get().string());
365 if ((ts.
peek().string() ==
"{"))
368 fprintf(stdout,
" \" {%s}\"",(
const char *)ts.
get().string());
372 fprintf(stdout,
"\n");
378 fprintf(stdout,
"\n");
379 fprintf(stdout,
"%s ",(
const char *)t.string());
383 fprintf(stdout,
"\n");
388 static void output_sgml_options(
const EST_String &usage)
393 int in_options = FALSE;
400 fprintf(stdout,
"<variablelist>\n");
409 fprintf(stdout,
"\n</PARA></LISTITEM>\n</varlistentry>\n\n");
410 fprintf(stdout,
"<varlistentry><term>%s</term>\n<LISTITEM><PARA>\n", (
const char *)t.string());
411 if ((ts.
peek().string() ==
"<string>") ||
412 (ts.
peek().string() ==
"<float>") ||
413 (ts.
peek().string() ==
"<ifile>") ||
414 (ts.
peek().string() ==
"<ofile>") ||
415 (ts.
peek().string() ==
"<double>") ||
416 (ts.
peek().string() ==
"<int>"))
418 atype = ts.
get().string();
421 fprintf(stdout,
"<replaceable>%s</replaceable>\n",
422 (
const char *) atype);
424 if ((ts.
peek().string() ==
"{"))
427 fprintf(stdout,
" \" {%s}\"",(
const char *)ts.
get().string());
431 fprintf(stdout,
"\n");
437 fprintf(stdout,
"\n");
438 fprintf(stdout,
"%s ",(
const char *)t.string());
442 fprintf(stdout,
"</PARA></LISTITEM>\n</varlistentry>\n</variablelist>\n");
446 static void output_sgml_synopsis(
char **argv,
const EST_String &usage)
451 int in_options = FALSE;
460 fprintf(stdout,
"<cmdsynopsis><command>%s</command>",
461 (
const char *)full.filename());
463 fprintf(stdout,
"%s",(
const char *)ts.
get_upto_eoln().string());
472 fprintf(stdout,
"</arg>\n");
473 fprintf(stdout,
"<arg>%s ", (
const char *)t.string());
474 if ((ts.
peek().string() ==
"<string>") ||
475 (ts.
peek().string() ==
"<float>") ||
476 (ts.
peek().string() ==
"<ifile>") ||
477 (ts.
peek().string() ==
"<ofile>") ||
478 (ts.
peek().string() ==
"<double>") ||
479 (ts.
peek().string() ==
"<int>"))
481 atype = ts.
get().string();
484 fprintf(stdout,
"<replaceable>%s</replaceable>",
485 (
const char *) atype);
487 if ((ts.
peek().string() ==
"{"))
490 fprintf(stdout,
" \" {%s}\"",(
const char *)ts.
get().string());
496 fprintf(stdout,
"</arg>\n</cmdsynopsis>\n");
504 "-o <ofile> output file" +
505 "-otype <string> output file type\n";
512 op.
set(option, al.
val(arg));