diff options
author | Rob Landley <rob@landley.net> | 2005-11-20 07:44:35 +0000 |
---|---|---|
committer | Rob Landley <rob@landley.net> | 2005-11-20 07:44:35 +0000 |
commit | fae1dc86203c0e9f66b726495815b6fdea30b5ed (patch) | |
tree | a6105bb6469cd06a31e344e76a54e42643d87130 /editors | |
parent | 4ee2eee2fcd6da772abb572c92cfa231517ae65c (diff) | |
download | busybox-w32-fae1dc86203c0e9f66b726495815b6fdea30b5ed.tar.gz busybox-w32-fae1dc86203c0e9f66b726495815b6fdea30b5ed.tar.bz2 busybox-w32-fae1dc86203c0e9f66b726495815b6fdea30b5ed.zip |
Support # comments after s/// option list.
Diffstat (limited to 'editors')
-rw-r--r-- | editors/sed.c | 46 |
1 files changed, 14 insertions, 32 deletions
diff --git a/editors/sed.c b/editors/sed.c index ce4c42733..2f6fc174c 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
@@ -8,20 +8,7 @@ | |||
8 | * Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au> | 8 | * Copyright (C) 2003 by Glenn McGrath <bug1@iinet.net.au> |
9 | * Copyright (C) 2003,2004 by Rob Landley <rob@landley.net> | 9 | * Copyright (C) 2003,2004 by Rob Landley <rob@landley.net> |
10 | * | 10 | * |
11 | * This program is free software; you can redistribute it and/or modify | 11 | * Licensed under GPLv2 or later, see file LICENSE in this tarball for details. |
12 | * it under the terms of the GNU General Public License as published by | ||
13 | * the Free Software Foundation; either version 2 of the License, or | ||
14 | * (at your option) any later version. | ||
15 | * | ||
16 | * This program is distributed in the hope that it will be useful, | ||
17 | * but WITHOUT ANY WARRANTY; without even the implied warranty of | ||
18 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU | ||
19 | * General Public License for more details. | ||
20 | * | ||
21 | * You should have received a copy of the GNU General Public License | ||
22 | * along with this program; if not, write to the Free Software | ||
23 | * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | ||
24 | * | ||
25 | */ | 12 | */ |
26 | 13 | ||
27 | /* Code overview. | 14 | /* Code overview. |
@@ -35,7 +22,7 @@ | |||
35 | (sed_cmd_head/sed_cmd_tail). | 22 | (sed_cmd_head/sed_cmd_tail). |
36 | 23 | ||
37 | add_input_file() adds a FILE * to the list of input files. We need to | 24 | add_input_file() adds a FILE * to the list of input files. We need to |
38 | know them all ahead of time to find the last line for the $ match. | 25 | know all input sources ahead of time to find the last line for the $ match. |
39 | 26 | ||
40 | process_files() does actual sedding, reading data lines from each input FILE * | 27 | process_files() does actual sedding, reading data lines from each input FILE * |
41 | (which could be stdin) and applying the sed command list (sed_cmd_head) to | 28 | (which could be stdin) and applying the sed command list (sed_cmd_head) to |
@@ -63,16 +50,8 @@ | |||
63 | default to the whole pattern space if no specific address match was | 50 | default to the whole pattern space if no specific address match was |
64 | requested.) | 51 | requested.) |
65 | 52 | ||
66 | Unsupported features: | ||
67 | |||
68 | - most GNU extensions | ||
69 | - and more. | ||
70 | |||
71 | Todo: | 53 | Todo: |
72 | |||
73 | - Create a wrapper around regex to make libc's regex conform with sed | 54 | - Create a wrapper around regex to make libc's regex conform with sed |
74 | - Fix bugs | ||
75 | |||
76 | 55 | ||
77 | Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html | 56 | Reference http://www.opengroup.org/onlinepubs/007904975/utilities/sed.html |
78 | */ | 57 | */ |
@@ -209,7 +188,7 @@ static void parse_escapes(char *dest, const char *string, int len, char from, ch | |||
209 | *dest=0; | 188 | *dest=0; |
210 | } | 189 | } |
211 | 190 | ||
212 | static char *copy_parsing_slashn(const char *string, int len) | 191 | static char *copy_parsing_escapes(const char *string, int len) |
213 | { | 192 | { |
214 | char *dest=xmalloc(len+1); | 193 | char *dest=xmalloc(len+1); |
215 | 194 | ||
@@ -270,7 +249,7 @@ static int parse_regex_delim(const char *cmdstr, char **match, char **replace) | |||
270 | if (idx == -1) { | 249 | if (idx == -1) { |
271 | bb_error_msg_and_die(bad_format_in_subst); | 250 | bb_error_msg_and_die(bad_format_in_subst); |
272 | } | 251 | } |
273 | *match = copy_parsing_slashn(cmdstr_ptr, idx); | 252 | *match = copy_parsing_escapes(cmdstr_ptr, idx); |
274 | 253 | ||
275 | /* save the replacement string */ | 254 | /* save the replacement string */ |
276 | cmdstr_ptr += idx + 1; | 255 | cmdstr_ptr += idx + 1; |
@@ -278,7 +257,7 @@ static int parse_regex_delim(const char *cmdstr, char **match, char **replace) | |||
278 | if (idx == -1) { | 257 | if (idx == -1) { |
279 | bb_error_msg_and_die(bad_format_in_subst); | 258 | bb_error_msg_and_die(bad_format_in_subst); |
280 | } | 259 | } |
281 | *replace = copy_parsing_slashn(cmdstr_ptr, idx); | 260 | *replace = copy_parsing_escapes(cmdstr_ptr, idx); |
282 | 261 | ||
283 | return ((cmdstr_ptr - cmdstr) + idx); | 262 | return ((cmdstr_ptr - cmdstr) + idx); |
284 | } | 263 | } |
@@ -307,7 +286,7 @@ static int get_address(char *my_str, int *linenum, regex_t ** regex) | |||
307 | if (next == -1) | 286 | if (next == -1) |
308 | bb_error_msg_and_die("unterminated match expression"); | 287 | bb_error_msg_and_die("unterminated match expression"); |
309 | 288 | ||
310 | temp=copy_parsing_slashn(pos,next); | 289 | temp=copy_parsing_escapes(pos,next); |
311 | *regex = (regex_t *) xmalloc(sizeof(regex_t)); | 290 | *regex = (regex_t *) xmalloc(sizeof(regex_t)); |
312 | xregcomp(*regex, temp, regex_type|REG_NEWLINE); | 291 | xregcomp(*regex, temp, regex_type|REG_NEWLINE); |
313 | free(temp); | 292 | free(temp); |
@@ -380,6 +359,7 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, char *substr) | |||
380 | case 'p': | 359 | case 'p': |
381 | sed_cmd->sub_p = 1; | 360 | sed_cmd->sub_p = 1; |
382 | break; | 361 | break; |
362 | /* Write to file */ | ||
383 | case 'w': | 363 | case 'w': |
384 | { | 364 | { |
385 | char *temp; | 365 | char *temp; |
@@ -391,6 +371,11 @@ static int parse_subst_cmd(sed_cmd_t * const sed_cmd, char *substr) | |||
391 | case 'I': | 371 | case 'I': |
392 | cflags |= REG_ICASE; | 372 | cflags |= REG_ICASE; |
393 | break; | 373 | break; |
374 | /* Comment */ | ||
375 | case '#': | ||
376 | while(substr[++idx]); | ||
377 | /* Fall through */ | ||
378 | /* End of command */ | ||
394 | case ';': | 379 | case ';': |
395 | case '}': | 380 | case '}': |
396 | goto out; | 381 | goto out; |
@@ -1128,13 +1113,11 @@ extern int sed_main(int argc, char **argv) | |||
1128 | bb_perror_msg_and_die("atexit"); | 1113 | bb_perror_msg_and_die("atexit"); |
1129 | #endif | 1114 | #endif |
1130 | 1115 | ||
1131 | #define LIE_TO_AUTOCONF | 1116 | /* Lie to autoconf when it starts asking stupid questions. */ |
1132 | #ifdef LIE_TO_AUTOCONF | ||
1133 | if(argc==2 && !strcmp(argv[1],"--version")) { | 1117 | if(argc==2 && !strcmp(argv[1],"--version")) { |
1134 | printf("This is not GNU sed version 4.0\n"); | 1118 | printf("This is not GNU sed version 4.0\n"); |
1135 | exit(0); | 1119 | exit(0); |
1136 | } | 1120 | } |
1137 | #endif | ||
1138 | 1121 | ||
1139 | /* do normal option parsing */ | 1122 | /* do normal option parsing */ |
1140 | while ((opt = getopt(argc, argv, "irne:f:")) > 0) { | 1123 | while ((opt = getopt(argc, argv, "irne:f:")) > 0) { |
@@ -1160,8 +1143,7 @@ extern int sed_main(int argc, char **argv) | |||
1160 | 1143 | ||
1161 | cmdfile = bb_xfopen(optarg, "r"); | 1144 | cmdfile = bb_xfopen(optarg, "r"); |
1162 | 1145 | ||
1163 | while ((line = bb_get_chomped_line_from_file(cmdfile)) | 1146 | while ((line = bb_get_chomped_line_from_file(cmdfile)) != NULL) { |
1164 | != NULL) { | ||
1165 | add_cmd(line); | 1147 | add_cmd(line); |
1166 | getpat=0; | 1148 | getpat=0; |
1167 | free(line); | 1149 | free(line); |