aboutsummaryrefslogtreecommitdiff
path: root/editors/awk.c
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/awk.c
parent750fc6d7bb6dc4c57399696e5e05c75c6cdd4aa5 (diff)
downloadbusybox-w32-099efbf99e2cedfb1d0edf10c9447297554cf584.tar.gz
busybox-w32-099efbf99e2cedfb1d0edf10c9447297554cf584.tar.bz2
busybox-w32-099efbf99e2cedfb1d0edf10c9447297554cf584.zip
awk: getopt_ulflags'isation
Diffstat (limited to 'editors/awk.c')
-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)
2605 2605
2606int awk_main(int argc, char **argv) 2606int awk_main(int argc, char **argv)
2607{ 2607{
2608 unsigned long opt;
2609 char *opt_F, *opt_v, *opt_W;
2608 char *s, *s1; 2610 char *s, *s1;
2609 int i, j, c, flen; 2611 int i, j, c, flen;
2610 var *v; 2612 var *v;
@@ -2660,49 +2662,37 @@ keep_going:
2660 free(s); 2662 free(s);
2661 } 2663 }
2662 2664
2663 while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) { 2665 opt = bb_getopt_ulflags(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
2664 switch (c) { 2666 if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
2665 case 'F': 2667 if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
2666 setvar_s(V[FS], optarg); 2668 if (opt & 0x4) { // -f
2667 break; 2669 from_file = TRUE;
2668 case 'v': 2670 F = afopen(programname, "r");
2669 if (! is_assignment(optarg)) 2671 s = NULL;
2670 bb_show_usage(); 2672 /* one byte is reserved for some trick in next_token */
2671 break; 2673 if (fseek(F, 0, SEEK_END) == 0) {
2672 case 'f': 2674 flen = ftell(F);
2673 from_file = TRUE; 2675 s = (char *)xmalloc(flen+4);
2674 F = afopen(programname = optarg, "r"); 2676 fseek(F, 0, SEEK_SET);
2675 s = NULL; 2677 i = 1 + fread(s+1, 1, flen, F);
2676 /* one byte is reserved for some trick in next_token */ 2678 } else {
2677 if (fseek(F, 0, SEEK_END) == 0) { 2679 for (i=j=1; j>0; i+=j) {
2678 flen = ftell(F); 2680 s = (char *)xrealloc(s, i+4096);
2679 s = (char *)xmalloc(flen+4); 2681 j = fread(s+i, 1, 4094, F);
2680 fseek(F, 0, SEEK_SET); 2682 }
2681 i = 1 + fread(s+1, 1, flen, F);
2682 } else {
2683 for (i=j=1; j>0; i+=j) {
2684 s = (char *)xrealloc(s, i+4096);
2685 j = fread(s+i, 1, 4094, F);
2686 }
2687 }
2688 s[i] = '\0';
2689 fclose(F);
2690 parse_program(s+1);
2691 free(s);
2692 break;
2693 case 'W':
2694 bb_error_msg("Warning: unrecognized option '-W %s' ignored", optarg);
2695 break;
2696
2697 default:
2698 bb_show_usage();
2699 } 2683 }
2684 s[i] = '\0';
2685 fclose(F);
2686 parse_program(s+1);
2687 free(s);
2700 } 2688 }
2689 if (opt & 0x8) // -W
2690 bb_error_msg("Warning: unrecognized option '-W %s' ignored", opt_W);
2701 2691
2702 if (!from_file) { 2692 if (!from_file) {
2703 if (argc == optind) 2693 if (argc == optind)
2704 bb_show_usage(); 2694 bb_show_usage();
2705 programname="cmd. line"; 2695 programname = "cmd. line";
2706 parse_program(argv[optind++]); 2696 parse_program(argv[optind++]);
2707 2697
2708 } 2698 }