sed: getopt_ulflags'isation
This commit is contained in:
parent
8514fc5681
commit
750fc6d7bb
@ -1086,7 +1086,9 @@ static void add_cmd_block(char *cmdstr)
|
|||||||
|
|
||||||
int sed_main(int argc, char **argv)
|
int sed_main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
int status = EXIT_SUCCESS, opt, getpat = 1;
|
unsigned long opt;
|
||||||
|
char *opt_e, *opt_f;
|
||||||
|
int status = EXIT_SUCCESS, getpat = 1;
|
||||||
|
|
||||||
bbg.sed_cmd_tail=&bbg.sed_cmd_head;
|
bbg.sed_cmd_tail=&bbg.sed_cmd_head;
|
||||||
|
|
||||||
@ -1100,41 +1102,27 @@ int sed_main(int argc, char **argv)
|
|||||||
}
|
}
|
||||||
|
|
||||||
/* do normal option parsing */
|
/* do normal option parsing */
|
||||||
while ((opt = getopt(argc, argv, "irne:f:")) > 0) {
|
opt = bb_getopt_ulflags(argc, argv, "irne:f:", &opt_e, &opt_f);
|
||||||
switch (opt) {
|
if (opt & 0x1) { // -i
|
||||||
case 'i':
|
bbg.in_place++;
|
||||||
bbg.in_place++;
|
atexit(cleanup_outname);
|
||||||
atexit(cleanup_outname);
|
}
|
||||||
break;
|
if (opt & 0x2) bbg.regex_type|=REG_EXTENDED; // -r
|
||||||
case 'r':
|
if (opt & 0x4) bbg.be_quiet++; // -n
|
||||||
bbg.regex_type|=REG_EXTENDED;
|
if (opt & 0x8) { // -e
|
||||||
break;
|
add_cmd_block(opt_e);
|
||||||
case 'n':
|
getpat=0;
|
||||||
bbg.be_quiet++;
|
}
|
||||||
break;
|
if (opt & 0x10) { // -f
|
||||||
case 'e':
|
FILE *cmdfile;
|
||||||
add_cmd_block(optarg);
|
char *line;
|
||||||
|
cmdfile = xfopen(opt_f, "r");
|
||||||
|
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
|
||||||
|
add_cmd(line);
|
||||||
getpat=0;
|
getpat=0;
|
||||||
break;
|
free(line);
|
||||||
case 'f':
|
|
||||||
{
|
|
||||||
FILE *cmdfile;
|
|
||||||
char *line;
|
|
||||||
|
|
||||||
cmdfile = xfopen(optarg, "r");
|
|
||||||
|
|
||||||
while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) {
|
|
||||||
add_cmd(line);
|
|
||||||
getpat=0;
|
|
||||||
free(line);
|
|
||||||
}
|
|
||||||
xprint_and_close_file(cmdfile);
|
|
||||||
|
|
||||||
break;
|
|
||||||
}
|
|
||||||
default:
|
|
||||||
bb_show_usage();
|
|
||||||
}
|
}
|
||||||
|
xprint_and_close_file(cmdfile);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* if we didn't get a pattern from -e or -f, use argv[optind] */
|
/* if we didn't get a pattern from -e or -f, use argv[optind] */
|
||||||
|
Loading…
Reference in New Issue
Block a user