This commit is contained in:
hyung-hwan 2008-07-26 09:01:27 +00:00
parent 3a8e597e03
commit 3aa1251661
2 changed files with 27 additions and 10 deletions

View File

@ -1052,27 +1052,35 @@ static int handle_args (int argc, ase_char_t* argv[], struct awk_src_io* src_io)
{ ASE_T("pablock"), ASE_OPT_OPTIONAL, ASE_NULL, 0 }, { ASE_T("pablock"), ASE_OPT_OPTIONAL, ASE_NULL, 0 },
{ ASE_T("help"), ASE_OPT_NONE, ASE_NULL, ASE_T('h')}, { ASE_T("help"), ASE_OPT_NONE, ASE_NULL, ASE_T('h')},
{ ASE_T("main"), ASE_OPT_REQUIRED, ASE_NULL, ASE_T('m')} { ASE_T("main"), ASE_OPT_REQUIRED, ASE_NULL, ASE_T('m') },
{ ASE_T("file"), ASE_OPT_REQUIRED, ASE_NULL, ASE_T('f') },
{ ASE_T("field-separator"), ASE_OPT_REQUIRED, ASE_NULL, ASE_T('F') },
{ ASE_T("assign"), ASE_OPT_REQUIRED, ASE_NULL, ASE_T('v') }
}; };
static ase_opt_t opt = static ase_opt_t opt =
{ {
ASE_T("hf:m:i:"), ASE_T("hm:f:F:v:"),
lng lng
}; };
ase_printf (ASE_T("111111111111111111\n"));
while ((c = ase_getopt (argc, argv, &opt)) != ASE_CHAR_EOF) while ((c = ase_getopt (argc, argv, &opt)) != ASE_CHAR_EOF)
{ {
switch (c) switch (c)
{ {
case 0:
ase_printf (ASE_T("%d\n"), opt.lngind);
break;
case ASE_T('h'): case ASE_T('h'):
print_usage (argv[0]); print_usage (argv[0]);
return -1; return -1;
case ASE_T('f'): case ASE_T('f'):
ase_printf (ASE_T("ffffffffffff\n"));
src_io->input_file = opt.arg; src_io->input_file = opt.arg;
break; break;
@ -1086,11 +1094,20 @@ ase_printf (ASE_T("111111111111111111\n"));
print_usage (argv[0]); print_usage (argv[0]);
return -1; return -1;
case 0: default:
break; return -1;
} }
} }
if (src_io->input_file == ASE_NULL)
{
/* the first is the source code... */
}
else
{
/* the remainings are data file names */
}
if (opt.ind < argc) if (opt.ind < argc)
{ {
ase_printf (ASE_T("Error: redundant argument - %s\n"), argv[opt.ind]); ase_printf (ASE_T("Error: redundant argument - %s\n"), argv[opt.ind]);
@ -1098,7 +1115,6 @@ ase_printf (ASE_T("111111111111111111\n"));
return -1; return -1;
} }
ase_printf (ASE_T("1xx11111111111111111\n"));
return 0; return 0;
} }

View File

@ -1,5 +1,5 @@
/* /*
* $Id: getopt.c 287 2008-07-24 14:08:37Z baconevi $ * $Id: getopt.c 288 2008-07-25 15:01:27Z baconevi $
* *
* {License} * {License}
*/ */
@ -135,15 +135,16 @@ ase_cint_t ase_getopt (int argc, ase_char_t* const* argv, ase_opt_t* opt)
if (opt->ind == 0) opt->ind = 1; if (opt->ind == 0) opt->ind = 1;
//again: //again:
if (opt->ind > argc || !argv[opt->ind] || if (opt->ind >= argc /*|| !argv[opt->ind] */||
argv[opt->ind][0] != ASE_T('-') || argv[opt->ind][0] != ASE_T('-') ||
argv[opt->ind][1] == ASE_T('\0')) return -1; argv[opt->ind][1] == ASE_T('\0')) return ASE_CHAR_EOF;
if (argv[opt->ind][1] == ASE_T('-') && if (argv[opt->ind][1] == ASE_T('-') &&
argv[opt->ind][2] == ASE_T('\0')) argv[opt->ind][2] == ASE_T('\0'))
{ {
/* -- */
++opt->ind; ++opt->ind;
return -1; return ASE_CHAR_EOF;
} }
// TODO: how to handle when lng is off? is this correct? // TODO: how to handle when lng is off? is this correct?