aboutsummaryrefslogtreecommitdiff
path: root/editors
diff options
context:
space:
mode:
Diffstat (limited to 'editors')
-rw-r--r--editors/sed.c14
1 files changed, 9 insertions, 5 deletions
diff --git a/editors/sed.c b/editors/sed.c
index f75fceea5..0f5cab2b7 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -173,7 +173,7 @@ static void cleanup_outname(void)
173 if (G.outname) unlink(G.outname); 173 if (G.outname) unlink(G.outname);
174} 174}
175 175
176/* strdup, replacing "\n" with '\n', and "\delimiter" with 'delimiter' */ 176/* strcpy, replacing "\from" with 'to'. If to is NUL, replacing "\any" with 'any' */
177 177
178static void parse_escapes(char *dest, const char *string, int len, char from, char to) 178static void parse_escapes(char *dest, const char *string, int len, char from, char to)
179{ 179{
@@ -188,9 +188,10 @@ static void parse_escapes(char *dest, const char *string, int len, char from, ch
188 } 188 }
189 *dest++ = string[i++]; 189 *dest++ = string[i++];
190 } 190 }
191 /* TODO: is it safe wrt a string with trailing '\\' ? */
191 *dest++ = string[i++]; 192 *dest++ = string[i++];
192 } 193 }
193 *dest = 0; 194 *dest = '\0';
194} 195}
195 196
196static char *copy_parsing_escapes(const char *string, int len) 197static char *copy_parsing_escapes(const char *string, int len)
@@ -198,6 +199,8 @@ static char *copy_parsing_escapes(const char *string, int len)
198 char *dest = xmalloc(len + 1); 199 char *dest = xmalloc(len + 1);
199 200
200 parse_escapes(dest, string, len, 'n', '\n'); 201 parse_escapes(dest, string, len, 'n', '\n');
202 /* GNU sed also recognizes \t */
203 parse_escapes(dest, dest, strlen(dest), 't', '\t');
201 return dest; 204 return dest;
202} 205}
203 206
@@ -205,7 +208,7 @@ static char *copy_parsing_escapes(const char *string, int len)
205/* 208/*
206 * index_of_next_unescaped_regexp_delim - walks left to right through a string 209 * index_of_next_unescaped_regexp_delim - walks left to right through a string
207 * beginning at a specified index and returns the index of the next regular 210 * beginning at a specified index and returns the index of the next regular
208 * expression delimiter (typically a forward * slash ('/')) not preceded by 211 * expression delimiter (typically a forward slash ('/')) not preceded by
209 * a backslash ('\'). A negative delimiter disables square bracket checking. 212 * a backslash ('\'). A negative delimiter disables square bracket checking.
210 */ 213 */
211static int index_of_next_unescaped_regexp_delim(int delimiter, const char *str) 214static int index_of_next_unescaped_regexp_delim(int delimiter, const char *str)
@@ -425,7 +428,8 @@ static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
425 break; 428 break;
426 } 429 }
427 sed_cmd->string = xstrdup(cmdstr); 430 sed_cmd->string = xstrdup(cmdstr);
428 parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), 0, 0); 431 /* "\anychar" -> "anychar" */
432 parse_escapes(sed_cmd->string, sed_cmd->string, strlen(cmdstr), '\0', '\0');
429 cmdstr += strlen(cmdstr); 433 cmdstr += strlen(cmdstr);
430 /* handle file cmds: (r)ead */ 434 /* handle file cmds: (r)ead */
431 } else if (strchr("rw", sed_cmd->cmd)) { 435 } else if (strchr("rw", sed_cmd->cmd)) {
@@ -1337,7 +1341,7 @@ int sed_main(int argc, char **argv)
1337 // FIXME: error check / message? 1341 // FIXME: error check / message?
1338 rename(G.outname, argv[i]); 1342 rename(G.outname, argv[i]);
1339 free(G.outname); 1343 free(G.outname);
1340 G.outname = 0; 1344 G.outname = NULL;
1341 } 1345 }
1342 if (G.input_file_count > G.current_input_file) 1346 if (G.input_file_count > G.current_input_file)
1343 process_files(); 1347 process_files();