diff options
Diffstat (limited to 'editors')
-rw-r--r-- | editors/Config.src (renamed from editors/Config.in) | 22 | ||||
-rw-r--r-- | editors/Kbuild.src (renamed from editors/Kbuild) | 0 | ||||
-rw-r--r-- | editors/sed.c | 43 |
3 files changed, 39 insertions, 26 deletions
diff --git a/editors/Config.in b/editors/Config.src index 5f9566f0a..6cf21919c 100644 --- a/editors/Config.in +++ b/editors/Config.src | |||
@@ -7,14 +7,14 @@ menu "Editors" | |||
7 | 7 | ||
8 | config AWK | 8 | config AWK |
9 | bool "awk" | 9 | bool "awk" |
10 | default n | 10 | default y |
11 | help | 11 | help |
12 | Awk is used as a pattern scanning and processing language. This is | 12 | Awk is used as a pattern scanning and processing language. This is |
13 | the BusyBox implementation of that programming language. | 13 | the BusyBox implementation of that programming language. |
14 | 14 | ||
15 | config FEATURE_AWK_LIBM | 15 | config FEATURE_AWK_LIBM |
16 | bool "Enable math functions (requires libm)" | 16 | bool "Enable math functions (requires libm)" |
17 | default n | 17 | default y |
18 | depends on AWK | 18 | depends on AWK |
19 | help | 19 | help |
20 | Enable math functions of the Awk programming language. | 20 | Enable math functions of the Awk programming language. |
@@ -22,14 +22,14 @@ config FEATURE_AWK_LIBM | |||
22 | 22 | ||
23 | config CMP | 23 | config CMP |
24 | bool "cmp" | 24 | bool "cmp" |
25 | default n | 25 | default y |
26 | help | 26 | help |
27 | cmp is used to compare two files and returns the result | 27 | cmp is used to compare two files and returns the result |
28 | to standard output. | 28 | to standard output. |
29 | 29 | ||
30 | config DIFF | 30 | config DIFF |
31 | bool "diff" | 31 | bool "diff" |
32 | default n | 32 | default y |
33 | help | 33 | help |
34 | diff compares two files or directories and outputs the | 34 | diff compares two files or directories and outputs the |
35 | differences between them in a form that can be given to | 35 | differences between them in a form that can be given to |
@@ -37,7 +37,7 @@ config DIFF | |||
37 | 37 | ||
38 | config FEATURE_DIFF_LONG_OPTIONS | 38 | config FEATURE_DIFF_LONG_OPTIONS |
39 | bool "Enable long options" | 39 | bool "Enable long options" |
40 | default n | 40 | default y |
41 | depends on DIFF && LONG_OPTS | 41 | depends on DIFF && LONG_OPTS |
42 | help | 42 | help |
43 | Enable use of long options. | 43 | Enable use of long options. |
@@ -52,7 +52,7 @@ config FEATURE_DIFF_DIR | |||
52 | 52 | ||
53 | config ED | 53 | config ED |
54 | bool "ed" | 54 | bool "ed" |
55 | default n | 55 | default y |
56 | help | 56 | help |
57 | The original 1970's Unix text editor, from the days of teletypes. | 57 | The original 1970's Unix text editor, from the days of teletypes. |
58 | Small, simple, evil. Part of SUSv3. If you're not already using | 58 | Small, simple, evil. Part of SUSv3. If you're not already using |
@@ -60,20 +60,20 @@ config ED | |||
60 | 60 | ||
61 | config PATCH | 61 | config PATCH |
62 | bool "patch" | 62 | bool "patch" |
63 | default n | 63 | default y |
64 | help | 64 | help |
65 | Apply a unified diff formatted patch. | 65 | Apply a unified diff formatted patch. |
66 | 66 | ||
67 | config SED | 67 | config SED |
68 | bool "sed" | 68 | bool "sed" |
69 | default n | 69 | default y |
70 | help | 70 | help |
71 | sed is used to perform text transformations on a file | 71 | sed is used to perform text transformations on a file |
72 | or input from a pipeline. | 72 | or input from a pipeline. |
73 | 73 | ||
74 | config VI | 74 | config VI |
75 | bool "vi" | 75 | bool "vi" |
76 | default n | 76 | default y |
77 | help | 77 | help |
78 | 'vi' is a text editor. More specifically, it is the One True | 78 | 'vi' is a text editor. More specifically, it is the One True |
79 | text editor <grin>. It does, however, have a rather steep | 79 | text editor <grin>. It does, however, have a rather steep |
@@ -91,7 +91,7 @@ config FEATURE_VI_MAX_LEN | |||
91 | 91 | ||
92 | config FEATURE_VI_8BIT | 92 | config FEATURE_VI_8BIT |
93 | bool "Allow vi to display 8-bit chars (otherwise shows dots)" | 93 | bool "Allow vi to display 8-bit chars (otherwise shows dots)" |
94 | default y | 94 | default n |
95 | depends on VI | 95 | depends on VI |
96 | help | 96 | help |
97 | If your terminal can display characters with high bit set, | 97 | If your terminal can display characters with high bit set, |
@@ -170,7 +170,7 @@ config FEATURE_VI_WIN_RESIZE | |||
170 | 170 | ||
171 | config FEATURE_VI_ASK_TERMINAL | 171 | config FEATURE_VI_ASK_TERMINAL |
172 | bool "Use 'tell me cursor position' ESC sequence to measure window" | 172 | bool "Use 'tell me cursor position' ESC sequence to measure window" |
173 | default n | 173 | default y |
174 | depends on VI | 174 | depends on VI |
175 | help | 175 | help |
176 | If terminal size can't be retrieved and $LINES/$COLUMNS are not set, | 176 | If terminal size can't be retrieved and $LINES/$COLUMNS are not set, |
diff --git a/editors/Kbuild b/editors/Kbuild.src index 76302aa76..76302aa76 100644 --- a/editors/Kbuild +++ b/editors/Kbuild.src | |||
diff --git a/editors/sed.c b/editors/sed.c index 4bd6e0168..a5ef400fc 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -119,10 +119,10 @@ struct globals { | |||
119 | } pipeline; | 119 | } pipeline; |
120 | } FIX_ALIASING; | 120 | } FIX_ALIASING; |
121 | #define G (*(struct globals*)&bb_common_bufsiz1) | 121 | #define G (*(struct globals*)&bb_common_bufsiz1) |
122 | void BUG_sed_globals_too_big(void); | 122 | struct BUG_G_too_big { |
123 | char BUG_G_too_big[sizeof(G) <= COMMON_BUFSIZE ? 1 : -1]; | ||
124 | }; | ||
123 | #define INIT_G() do { \ | 125 | #define INIT_G() do { \ |
124 | if (sizeof(struct globals) > COMMON_BUFSIZE) \ | ||
125 | BUG_sed_globals_too_big(); \ | ||
126 | G.sed_cmd_tail = &G.sed_cmd_head; \ | 126 | G.sed_cmd_tail = &G.sed_cmd_head; \ |
127 | } while (0) | 127 | } while (0) |
128 | 128 | ||
@@ -385,7 +385,8 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) | |||
385 | break; | 385 | break; |
386 | /* Comment */ | 386 | /* Comment */ |
387 | case '#': | 387 | case '#': |
388 | while (substr[++idx]) /*skip all*/; | 388 | // while (substr[++idx]) continue; |
389 | idx += strlen(substr + idx); // same | ||
389 | /* Fall through */ | 390 | /* Fall through */ |
390 | /* End of command */ | 391 | /* End of command */ |
391 | case ';': | 392 | case ';': |
@@ -395,7 +396,7 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr) | |||
395 | bb_error_msg_and_die("bad option in substitution expression"); | 396 | bb_error_msg_and_die("bad option in substitution expression"); |
396 | } | 397 | } |
397 | } | 398 | } |
398 | out: | 399 | out: |
399 | /* compile the match string into a regex */ | 400 | /* compile the match string into a regex */ |
400 | if (*match != '\0') { | 401 | if (*match != '\0') { |
401 | /* If match is empty, we use last regex used at runtime */ | 402 | /* If match is empty, we use last regex used at runtime */ |
@@ -896,13 +897,32 @@ static void process_files(void) | |||
896 | 897 | ||
897 | /* Determine if this command matches this line: */ | 898 | /* Determine if this command matches this line: */ |
898 | 899 | ||
900 | //bb_error_msg("match1:%d", sed_cmd->in_match); | ||
901 | //bb_error_msg("match2:%d", (!sed_cmd->beg_line && !sed_cmd->end_line | ||
902 | // && !sed_cmd->beg_match && !sed_cmd->end_match)); | ||
903 | //bb_error_msg("match3:%d", (sed_cmd->beg_line > 0 | ||
904 | // && (sed_cmd->end_line || sed_cmd->end_match | ||
905 | // ? (sed_cmd->beg_line <= linenum) | ||
906 | // : (sed_cmd->beg_line == linenum) | ||
907 | // ) | ||
908 | // ) | ||
909 | //bb_error_msg("match4:%d", (beg_match(sed_cmd, pattern_space))); | ||
910 | //bb_error_msg("match5:%d", (sed_cmd->beg_line == -1 && next_line == NULL)); | ||
911 | |||
899 | /* Are we continuing a previous multi-line match? */ | 912 | /* Are we continuing a previous multi-line match? */ |
900 | sed_cmd->in_match = sed_cmd->in_match | 913 | sed_cmd->in_match = sed_cmd->in_match |
901 | /* Or is no range necessary? */ | 914 | /* Or is no range necessary? */ |
902 | || (!sed_cmd->beg_line && !sed_cmd->end_line | 915 | || (!sed_cmd->beg_line && !sed_cmd->end_line |
903 | && !sed_cmd->beg_match && !sed_cmd->end_match) | 916 | && !sed_cmd->beg_match && !sed_cmd->end_match) |
904 | /* Or did we match the start of a numerical range? */ | 917 | /* Or did we match the start of a numerical range? */ |
905 | || (sed_cmd->beg_line > 0 && (sed_cmd->beg_line <= linenum)) | 918 | || (sed_cmd->beg_line > 0 |
919 | && (sed_cmd->end_line || sed_cmd->end_match | ||
920 | /* note: even if end is numeric and is < linenum too, | ||
921 | * GNU sed matches! We match too */ | ||
922 | ? (sed_cmd->beg_line <= linenum) /* N,end */ | ||
923 | : (sed_cmd->beg_line == linenum) /* N */ | ||
924 | ) | ||
925 | ) | ||
906 | /* Or does this line match our begin address regex? */ | 926 | /* Or does this line match our begin address regex? */ |
907 | || (beg_match(sed_cmd, pattern_space)) | 927 | || (beg_match(sed_cmd, pattern_space)) |
908 | /* Or did we match last line of input? */ | 928 | /* Or did we match last line of input? */ |
@@ -976,7 +996,6 @@ static void process_files(void) | |||
976 | case 'P': | 996 | case 'P': |
977 | { | 997 | { |
978 | char *tmp = strchr(pattern_space, '\n'); | 998 | char *tmp = strchr(pattern_space, '\n'); |
979 | |||
980 | if (tmp) { | 999 | if (tmp) { |
981 | *tmp = '\0'; | 1000 | *tmp = '\0'; |
982 | /* TODO: explain why '\n' below */ | 1001 | /* TODO: explain why '\n' below */ |
@@ -999,11 +1018,8 @@ static void process_files(void) | |||
999 | case 'D': | 1018 | case 'D': |
1000 | { | 1019 | { |
1001 | char *tmp = strchr(pattern_space, '\n'); | 1020 | char *tmp = strchr(pattern_space, '\n'); |
1002 | |||
1003 | if (tmp) { | 1021 | if (tmp) { |
1004 | tmp = xstrdup(tmp+1); | 1022 | overlapping_strcpy(pattern_space, tmp + 1); |
1005 | free(pattern_space); | ||
1006 | pattern_space = tmp; | ||
1007 | goto restart; | 1023 | goto restart; |
1008 | } | 1024 | } |
1009 | } | 1025 | } |
@@ -1048,7 +1064,6 @@ static void process_files(void) | |||
1048 | case 'r': | 1064 | case 'r': |
1049 | { | 1065 | { |
1050 | FILE *rfile; | 1066 | FILE *rfile; |
1051 | |||
1052 | rfile = fopen_for_read(sed_cmd->string); | 1067 | rfile = fopen_for_read(sed_cmd->string); |
1053 | if (rfile) { | 1068 | if (rfile) { |
1054 | char *line; | 1069 | char *line; |
@@ -1097,12 +1112,11 @@ static void process_files(void) | |||
1097 | int len; | 1112 | int len; |
1098 | /* If no next line, jump to end of script and exit. */ | 1113 | /* If no next line, jump to end of script and exit. */ |
1099 | if (next_line == NULL) { | 1114 | if (next_line == NULL) { |
1100 | /* Jump to end of script and exit */ | ||
1101 | free(next_line); | 1115 | free(next_line); |
1102 | next_line = NULL; | 1116 | next_line = NULL; |
1103 | goto discard_line; | 1117 | goto discard_line; |
1104 | /* append next_line, read new next_line. */ | ||
1105 | } | 1118 | } |
1119 | /* Append next_line, read new next_line. */ | ||
1106 | len = strlen(pattern_space); | 1120 | len = strlen(pattern_space); |
1107 | pattern_space = xrealloc(pattern_space, len + strlen(next_line) + 2); | 1121 | pattern_space = xrealloc(pattern_space, len + strlen(next_line) + 2); |
1108 | pattern_space[len] = '\n'; | 1122 | pattern_space[len] = '\n'; |
@@ -1131,7 +1145,6 @@ static void process_files(void) | |||
1131 | case 'y': | 1145 | case 'y': |
1132 | { | 1146 | { |
1133 | int i, j; | 1147 | int i, j; |
1134 | |||
1135 | for (i = 0; pattern_space[i]; i++) { | 1148 | for (i = 0; pattern_space[i]; i++) { |
1136 | for (j = 0; sed_cmd->string[j]; j += 2) { | 1149 | for (j = 0; sed_cmd->string[j]; j += 2) { |
1137 | if (pattern_space[i] == sed_cmd->string[j]) { | 1150 | if (pattern_space[i] == sed_cmd->string[j]) { |