summaryrefslogtreecommitdiffhomepage
path: root/editors
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2006-09-22 09:02:30 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2006-09-22 09:02:30 +0000
commit099efbf99e2cedfb1d0edf10c9447297554cf584 (patch)
tree16e05b44895348c8c53a73e07f452396d5ec2fff /editors
parent750fc6d7bb6dc4c57399696e5e05c75c6cdd4aa5 (diff)
awk: getopt_ulflags'isation
Diffstat (limited to 'editors')
-rw-r--r--editors/awk.c64
1 files changed, 27 insertions, 37 deletions
diff --git a/editors/awk.c b/editors/awk.c
index 6e81aa8f4..c934fe0df 100644
--- a/editors/awk.c
+++ b/editors/awk.c
@@ -2605,6 +2605,8 @@ static rstream *next_input_file(void)
int awk_main(int argc, char **argv)
{
+ unsigned long opt;
+ char *opt_F, *opt_v, *opt_W;
char *s, *s1;
int i, j, c, flen;
var *v;
@@ -2660,49 +2662,37 @@ keep_going:
free(s);
}
- while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
- switch (c) {
- case 'F':
- setvar_s(V[FS], optarg);
- break;
- case 'v':
- if (! is_assignment(optarg))
- bb_show_usage();
- break;
- case 'f':
- from_file = TRUE;
- F = afopen(programname = optarg, "r");
- s = NULL;
- /* one byte is reserved for some trick in next_token */
- if (fseek(F, 0, SEEK_END) == 0) {
- flen = ftell(F);
- s = (char *)xmalloc(flen+4);
- fseek(F, 0, SEEK_SET);
- i = 1 + fread(s+1, 1, flen, F);
- } else {
- for (i=j=1; j>0; i+=j) {
- s = (char *)xrealloc(s, i+4096);
- j = fread(s+i, 1, 4094, F);
- }
- }
- s[i] = '\0';
- fclose(F);
- parse_program(s+1);
- free(s);
- break;
- case 'W':
- bb_error_msg("Warning: unrecognized option '-W %s' ignored", optarg);
- break;
-
- default:
- bb_show_usage();
+ opt = bb_getopt_ulflags(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
+ if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
+ if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
+ if (opt & 0x4) { // -f
+ from_file = TRUE;
+ F = afopen(programname, "r");
+ s = NULL;
+ /* one byte is reserved for some trick in next_token */
+ if (fseek(F, 0, SEEK_END) == 0) {
+ flen = ftell(F);
+ s = (char *)xmalloc(flen+4);
+ fseek(F, 0, SEEK_SET);
+ i = 1 + fread(s+1, 1, flen, F);
+ } else {
+ for (i=j=1; j>0; i+=j) {
+ s = (char *)xrealloc(s, i+4096);
+ j = fread(s+i, 1, 4094, F);
+ }
}
+ s[i] = '\0';
+ fclose(F);
+ parse_program(s+1);
+ free(s);
}
+ if (opt & 0x8) // -W
+ bb_error_msg("Warning: unrecognized option '-W %s' ignored", opt_W);
if (!from_file) {
if (argc == optind)
bb_show_usage();
- programname="cmd. line";
+ programname = "cmd. line";
parse_program(argv[optind++]);
}