summaryrefslogtreecommitdiffstats
path: root/package/busybox/busybox-1.12.0-grep.patch
blob: 1ac1d9fc965f5e72a01d610b50603d61f372bf1d (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
73
74
75
76
77
78
--- busybox-1.12.0/findutils/grep.c	Sat Aug  9 18:14:59 2008
+++ busybox-1.12.0-grep/findutils/grep.c	Fri Sep 19 23:33:15 2008
@@ -87,7 +87,11 @@
 
 struct globals {
 	int max_matches;
+#if !ENABLE_EXTRA_COMPAT
 	int reflags;
+#else
+	RE_TRANSLATE_TYPE case_fold; /* RE_TRANSLATE_TYPE is [[un]signed] char* */
+#endif
 	smalluint invert_search;
 	smalluint print_filename;
 	smalluint open_errors;
@@ -110,7 +114,19 @@
 	}; \
 } while (0)
 #define max_matches       (G.max_matches         )
+#if !ENABLE_EXTRA_COMPAT
 #define reflags           (G.reflags             )
+#else
+#define case_fold         (G.case_fold           )
+/* http://www.delorie.com/gnu/docs/regex/regex_46.html */
+#define reflags           re_syntax_options
+#undef REG_NOSUB
+#undef REG_EXTENDED
+#undef REG_ICASE
+#define REG_NOSUB    bug:is:here /* should not be used */
+#define REG_EXTENDED RE_SYNTAX_EGREP
+#define REG_ICASE    bug:is:here /* should not be used */
+#endif
 #define invert_search     (G.invert_search       )
 #define print_filename    (G.print_filename      )
 #define open_errors       (G.open_errors         )
@@ -240,6 +256,7 @@
 					xregcomp(&gl->compiled_regex, gl->pattern, reflags);
 #else
 					memset(&gl->compiled_regex, 0, sizeof(gl->compiled_regex));
+					gl->compiled_regex.translate = case_fold; /* for -i */
 					if (re_compile_pattern(gl->pattern, strlen(gl->pattern), &gl->compiled_regex))
 						bb_error_msg_and_die("bad regex '%s'", gl->pattern);
 #endif
@@ -532,17 +549,34 @@
 	if (ENABLE_FEATURE_GREP_FGREP_ALIAS && applet_name[0] == 'f')
 		option_mask32 |= OPT_F;
 
+#if !ENABLE_EXTRA_COMPAT
 	if (!(option_mask32 & (OPT_o | OPT_w)))
 		reflags = REG_NOSUB;
+#endif
 
 	if (ENABLE_FEATURE_GREP_EGREP_ALIAS
 	 && (applet_name[0] == 'e' || (option_mask32 & OPT_E))
 	) {
 		reflags |= REG_EXTENDED;
 	}
+#if ENABLE_EXTRA_COMPAT
+	else {
+		reflags = RE_SYNTAX_GREP;
+	}
+#endif
 
-	if (option_mask32 & OPT_i)
+	if (option_mask32 & OPT_i) {
+#if !ENABLE_EXTRA_COMPAT
 		reflags |= REG_ICASE;
+#else
+		int i;
+		case_fold = xmalloc(256);
+		for (i = 0; i < 256; i++)
+			case_fold[i] = (unsigned char)i;
+		for (i = 'a'; i <= 'z'; i++)
+			case_fold[i] = (unsigned char)(i - ('a' - 'A'));
+#endif
+	}
 
 	argv += optind;
 	argc -= optind;