Added more essential NAS modules for NSLU2, NAS100d and DSMG600RevA profiles
[openwrt.git] / package / busybox / patches / 400-revert_awk_getopt.patch
1 Index: busybox-1.4.2/editors/awk.c
2 ===================================================================
3 --- busybox-1.4.2.orig/editors/awk.c 2007-06-15 23:43:26.460690280 +0200
4 +++ busybox-1.4.2/editors/awk.c 2007-06-15 23:45:26.283474448 +0200
5 @@ -2639,14 +2639,13 @@
6
7 int awk_main(int argc, char **argv)
8 {
9 - unsigned opt;
10 - char *opt_F, *opt_v, *opt_W;
11 int i, j, flen;
12 var *v;
13 var tv;
14 char **envp;
15 char *vnames = (char *)vNames; /* cheat */
16 char *vvalues = (char *)vValues;
17 + int c;
18
19 /* Undo busybox.c, or else strtod may eat ','! This breaks parsing:
20 * $1,$2 == '$1,' '$2', NOT '$1' ',' '$2' */
21 @@ -2694,40 +2693,56 @@
22 free(s);
23 }
24
25 - opt = getopt32(argc, argv, "F:v:f:W:", &opt_F, &opt_v, &programname, &opt_W);
26 - argv += optind;
27 - argc -= optind;
28 - if (opt & 0x1) setvar_s(V[FS], opt_F); // -F
29 - if (opt & 0x2) if (!is_assignment(opt_v)) bb_show_usage(); // -v
30 - if (opt & 0x4) { // -f
31 - char *s = s; /* die, gcc, die */
32 - FILE *from_file = afopen(programname, "r");
33 - /* one byte is reserved for some trick in next_token */
34 - if (fseek(from_file, 0, SEEK_END) == 0) {
35 - flen = ftell(from_file);
36 - s = xmalloc(flen + 4);
37 - fseek(from_file, 0, SEEK_SET);
38 - i = 1 + fread(s + 1, 1, flen, from_file);
39 - } else {
40 - for (i = j = 1; j > 0; i += j) {
41 - s = xrealloc(s, i + 4096);
42 - j = fread(s + i, 1, 4094, from_file);
43 + programname = NULL;
44 + while((c = getopt(argc, argv, "F:v:f:W:")) != EOF) {
45 + switch (c) {
46 + case 'F':
47 + setvar_s(V[FS], optarg);
48 + break;
49 + case 'v':
50 + if (! is_assignment(optarg))
51 + bb_show_usage();
52 + break;
53 + case 'f': {
54 + FILE *F = afopen(programname = optarg, "r");
55 + char *s = NULL;
56 + /* one byte is reserved for some trick in next_token */
57 + if (fseek(F, 0, SEEK_END) == 0) {
58 + flen = ftell(F);
59 + s = (char *)xmalloc(flen+4);
60 + fseek(F, 0, SEEK_SET);
61 + i = 1 + fread(s+1, 1, flen, F);
62 + } else {
63 + for (i=j=1; j>0; i+=j) {
64 + s = (char *)xrealloc(s, i+4096);
65 + j = fread(s+i, 1, 4094, F);
66 + }
67 + }
68 + s[i] = '\0';
69 + fclose(F);
70 + parse_program(s+1);
71 + free(s);
72 + break;
73 }
74 + case 'W':
75 + bb_error_msg("Warning: unrecognized option '-W %s' ignored\n", optarg);
76 + break;
77 +
78 + default:
79 + bb_show_usage();
80 }
81 - s[i] = '\0';
82 - fclose(from_file);
83 - parse_program(s + 1);
84 - free(s);
85 - } else { // no -f: take program from 1st parameter
86 + }
87 + argc -= optind;
88 + argv += optind;
89 +
90 + if (!programname) {
91 if (!argc)
92 bb_show_usage();
93 programname = "cmd. line";
94 parse_program(*argv++);
95 argc--;
96 }
97 - if (opt & 0x8) // -W
98 - bb_error_msg("warning: unrecognized option '-W %s' ignored", opt_W);
99 -
100 +
101 /* fill in ARGV array */
102 setvar_i(V[ARGC], argc + 1);
103 setari_u(V[ARGV], 0, "awk");
This page took 0.043894 seconds and 5 git commands to generate.