summaryrefslogtreecommitdiffstats
path: root/package/busybox/patches/360-awk_multi_f.patch
blob: ab753c125a5a94e48beec66feded7dee3ab093b1 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
Index: busybox-1.7.2/editors/awk.c
===================================================================
--- busybox-1.7.2.orig/editors/awk.c	2007-10-30 15:34:59.000000000 -0500
+++ busybox-1.7.2/editors/awk.c	2007-10-30 15:35:03.000000000 -0500
@@ -2757,6 +2757,7 @@
 {
 	unsigned opt;
 	char *opt_F, *opt_W;
+	llist_t *opt_f = NULL;
 	llist_t *opt_v = NULL;
 	int i, j, flen;
 	var *v;
@@ -2816,8 +2817,8 @@
 			*s1 = '=';
 		}
 	}
-	opt_complementary = "v::";
-	opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &g_progname, &opt_W);
+	opt_complementary = "v::f::";
+	opt = getopt32(argv, "F:v:f:W:", &opt_F, &opt_v, &opt_f, &opt_W);
 	argv += optind;
 	argc -= optind;
 	if (opt & 0x1)
@@ -2826,25 +2827,31 @@
 		if (!is_assignment(llist_pop(&opt_v)))
 			bb_show_usage();
 	}
-	if (opt & 0x4) { // -f
-		char *s = s; /* die, gcc, die */
-		FILE *from_file = afopen(g_progname, "r");
-		/* one byte is reserved for some trick in next_token */
-		if (fseek(from_file, 0, SEEK_END) == 0) {
-			flen = ftell(from_file);
-			s = xmalloc(flen + 4);
-			fseek(from_file, 0, SEEK_SET);
-			i = 1 + fread(s + 1, 1, flen, from_file);
-		} else {
-			for (i = j = 1; j > 0; i += j) {
-				s = xrealloc(s, i + 4096);
-				j = fread(s + i, 1, 4094, from_file);
+	if (opt_f != NULL) { // -f
+		while (opt_f != NULL) {
+			char *s = NULL;
+			FILE *from_file;
+
+			g_progname = opt_f->data;
+			from_file = afopen(g_progname, "r");
+			/* one byte is reserved for some trick in next_token */
+			if (fseek(from_file, 0, SEEK_END) == 0) {
+				flen = ftell(from_file);
+				s = xmalloc(flen + 4);
+				fseek(from_file, 0, SEEK_SET);
+				i = 1 + fread(s + 1, 1, flen, from_file);
+			} else {
+				for (i = j = 1; j > 0; i += j) {
+					s = xrealloc(s, i + 4096);
+					j = fread(s + i, 1, 4094, from_file);
+				}
 			}
+			s[i] = '\0';
+			fclose(from_file);
+			parse_program(s + 1);
+			free(s);
+			opt_f = opt_f->link;
 		}
-		s[i] = '\0';
-		fclose(from_file);
-		parse_program(s + 1);
-		free(s);
 	} else { // no -f: take program from 1st parameter
 		if (!argc)
 			bb_show_usage();