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