#include <stdlib.h>
#include <stdio.h>
#include "getopt.h"
#include "args.h"
#if 0
parser_options options =
{
{
0,
1,
1,
1,
1
},
0,
0
};
#endif
static
boolean quote_strings = FALSE;
static
boolean convert_numbers = TRUE;
static
boolean expand_macros = TRUE;
static
boolean paste_strings = TRUE;
static
boolean collapse_whitespace = TRUE;
static
boolean check_only = FALSE;
static
boolean dump_ast = FALSE;
static
boolean whole_file = FALSE;
struct
option option_table[] =
{
{
"check"
, 0, &check_only, 1 },
{
"noquotes"
, 0, "e_strings, 0 },
{
"quote"
, 0, "e_strings, 1 },
{
"convert"
, 0, &convert_numbers, 1 },
{
"noconvert"
, 0, &convert_numbers, 0 },
{
"expand"
, 0, &expand_macros, 1 },
{
"noexpand"
, 0, &expand_macros, 0 },
{
"paste"
, 0, &paste_strings, 1 },
{
"nopaste"
, 0, &paste_strings, 0 },
{
"collapse"
, 0, &collapse_whitespace, 1 },
{
"nocollapse"
, 0, &collapse_whitespace, 0 },
{
"dump"
, 0, &dump_ast, 1 },
{
"nodump"
, 0, &dump_ast, 0 },
{
"wholefile"
, 0, &whole_file, 1 },
{ NULL, 0, 0, 0 }
};
parser_options *parse_args (
int
argc,
char
**argv)
{
int
c;
parser_options *options;
while
(1)
{
c = getopt_long_only (argc, argv,
""
, option_table, NULL);
if
(c == -1)
break
;
switch
(c)
{
case
':'
:
case
'?'
:
fprintf
(stderr,
"%s: error in command-line\n"
, argv[0]);
exit
(1);
break
;
}
}
options = (parser_options *)
malloc
(
sizeof
(parser_options));
options->string_opts = 0;
options->string_opts |= (convert_numbers ? BTO_CONVERT : 0);
options->string_opts |= (expand_macros ? BTO_EXPAND : 0);
options->string_opts |= (paste_strings ? BTO_PASTE : 0);
options->string_opts |= (collapse_whitespace ? BTO_COLLAPSE : 0);
options->other_opts = 0;
options->quote_strings = quote_strings;
options->check_only = check_only;
options->dump_ast = dump_ast;
options->whole_file = whole_file;
return
options;
}