awk: getopt_ulflags'isation
This commit is contained in:
parent
750fc6d7bb
commit
099efbf99e
@ -2605,6 +2605,8 @@ static rstream *next_input_file(void)
|
|||||||
|
|
||||||
int awk_main(int argc, char **argv)
|
int awk_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
unsigned long opt;
|
||||||
|
char *opt_F, *opt_v, *opt_W;
|
||||||
char *s, *s1;
|
char *s, *s1;
|
||||||
int i, j, c, flen;
|
int i, j, c, flen;
|
||||||
var *v;
|
var *v;
|
||||||
@ -2660,18 +2662,12 @@ keep_going:
|
|||||||
free(s);
|
free(s);
|
||||||
}
|
}
|
||||||
|
|
||||||
while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
|
opt = bb_getopt_ulflags(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
|
||||||
switch (c) {
|
if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
|
||||||
case 'F':
|
if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
|
||||||
setvar_s(V[FS], optarg);
|
if (opt & 0x4) { // -f
|
||||||
break;
|
|
||||||
case 'v':
|
|
||||||
if (! is_assignment(optarg))
|
|
||||||
bb_show_usage();
|
|
||||||
break;
|
|
||||||
case 'f':
|
|
||||||
from_file = TRUE;
|
from_file = TRUE;
|
||||||
F = afopen(programname = optarg, "r");
|
F = afopen(programname, "r");
|
||||||
s = NULL;
|
s = NULL;
|
||||||
/* one byte is reserved for some trick in next_token */
|
/* one byte is reserved for some trick in next_token */
|
||||||
if (fseek(F, 0, SEEK_END) == 0) {
|
if (fseek(F, 0, SEEK_END) == 0) {
|
||||||
@ -2689,20 +2685,14 @@ keep_going:
|
|||||||
fclose(F);
|
fclose(F);
|
||||||
parse_program(s+1);
|
parse_program(s+1);
|
||||||
free(s);
|
free(s);
|
||||||
break;
|
|
||||||
case 'W':
|
|
||||||
bb_error_msg("Warning: unrecognized option '-W %s' ignored", optarg);
|
|
||||||
break;
|
|
||||||
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
if (opt & 0x8) // -W
|
||||||
|
bb_error_msg("Warning: unrecognized option '-W %s' ignored", opt_W);
|
||||||
|
|
||||||
if (!from_file) {
|
if (!from_file) {
|
||||||
if (argc == optind)
|
if (argc == optind)
|
||||||
bb_show_usage();
|
bb_show_usage();
|
||||||
programname="cmd. line";
|
programname = "cmd. line";
|
||||||
parse_program(argv[optind++]);
|
parse_program(argv[optind++]);
|
||||||
|
|
||||||
}
|
}
|
||||||
|
Loading…
Reference in New Issue
Block a user