aboutsummaryrefslogtreecommitdiff
path: root/editors/sed.c
diff options
context:
space:
mode:
authorDenis Vlasenko <vda.linux@googlemail.com>2007-01-29 23:44:38 +0000
committerDenis Vlasenko <vda.linux@googlemail.com>2007-01-29 23:44:38 +0000
commit9356b5022cf151df878a65002e9359ac8074576d (patch)
treefd26dfda4720cb3c8158d531c01c91fe276b9145 /editors/sed.c
parent322661d025626d7a92482fec232d29f4450dd4b0 (diff)
downloadbusybox-w32-9356b5022cf151df878a65002e9359ac8074576d.tar.gz
busybox-w32-9356b5022cf151df878a65002e9359ac8074576d.tar.bz2
busybox-w32-9356b5022cf151df878a65002e9359ac8074576d.zip
preparatory patch for -Wwrite-strings #7: sed
remaining: shell (rather scary mess in msh.c)
Diffstat (limited to 'editors/sed.c')
-rw-r--r--editors/sed.c29
1 files changed, 16 insertions, 13 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 70b36095f..c0ad3c4d5 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -235,9 +235,9 @@ static int index_of_next_unescaped_regexp_delim(int delimiter, const char *str)
235/* 235/*
236 * Returns the index of the third delimiter 236 * Returns the index of the third delimiter
237 */ 237 */
238static int parse_regex_delim(char *cmdstr, char **match, char **replace) 238static int parse_regex_delim(const char *cmdstr, char **match, char **replace)
239{ 239{
240 char *cmdstr_ptr = cmdstr; 240 const char *cmdstr_ptr = cmdstr;
241 char delimiter; 241 char delimiter;
242 int idx = 0; 242 int idx = 0;
243 243
@@ -291,26 +291,30 @@ static int get_address(const char *my_str, int *linenum, regex_t ** regex)
291} 291}
292 292
293/* Grab a filename. Whitespace at start is skipped, then goes to EOL. */ 293/* Grab a filename. Whitespace at start is skipped, then goes to EOL. */
294static int parse_file_cmd(sed_cmd_t *sed_cmd, char *filecmdstr, char **retval) 294static int parse_file_cmd(sed_cmd_t *sed_cmd, const char *filecmdstr, char **retval)
295{ 295{
296 int start = 0, idx, hack = 0; 296 int start = 0, idx, hack = 0;
297 297
298 /* Skip whitespace, then grab filename to end of line */ 298 /* Skip whitespace, then grab filename to end of line */
299 while (isspace(filecmdstr[start])) start++; 299 while (isspace(filecmdstr[start]))
300 start++;
300 idx = start; 301 idx = start;
301 while (filecmdstr[idx] && filecmdstr[idx] != '\n') idx++; 302 while (filecmdstr[idx] && filecmdstr[idx] != '\n')
303 idx++;
302 304
303 /* If lines glued together, put backslash back. */ 305 /* If lines glued together, put backslash back. */
304 if (filecmdstr[idx] == '\n') hack = 1; 306 if (filecmdstr[idx] == '\n')
307 hack = 1;
305 if (idx == start) 308 if (idx == start)
306 bb_error_msg_and_die("empty filename"); 309 bb_error_msg_and_die("empty filename");
307 *retval = xstrndup(filecmdstr+start, idx-start+hack+1); 310 *retval = xstrndup(filecmdstr+start, idx-start+hack+1);
308 if (hack) (*retval)[idx] = '\\'; 311 if (hack)
312 (*retval)[idx] = '\\';
309 313
310 return idx; 314 return idx;
311} 315}
312 316
313static int parse_subst_cmd(sed_cmd_t *sed_cmd, char *substr) 317static int parse_subst_cmd(sed_cmd_t *sed_cmd, const char *substr)
314{ 318{
315 int cflags = bbg.regex_type; 319 int cflags = bbg.regex_type;
316 char *match; 320 char *match;
@@ -337,9 +341,9 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, char *substr)
337 if (isdigit(substr[idx])) { 341 if (isdigit(substr[idx])) {
338 if (match[0] != '^') { 342 if (match[0] != '^') {
339 /* Match 0 treated as all, multiple matches we take the last one. */ 343 /* Match 0 treated as all, multiple matches we take the last one. */
340 char *pos = substr + idx; 344 const char *pos = substr + idx;
341 /* FIXME: error check? */ 345/* FIXME: error check? */
342 sed_cmd->which_match = (unsigned short)strtol(substr+idx, &pos, 10); 346 sed_cmd->which_match = (unsigned short)strtol(substr+idx, (char**) &pos, 10);
343 idx = pos - substr; 347 idx = pos - substr;
344 } 348 }
345 continue; 349 continue;
@@ -361,7 +365,6 @@ static int parse_subst_cmd(sed_cmd_t *sed_cmd, char *substr)
361 { 365 {
362 char *temp; 366 char *temp;
363 idx += parse_file_cmd(sed_cmd, substr+idx, &temp); 367 idx += parse_file_cmd(sed_cmd, substr+idx, &temp);
364
365 break; 368 break;
366 } 369 }
367 /* Ignore case (gnu exension) */ 370 /* Ignore case (gnu exension) */
@@ -395,7 +398,7 @@ out:
395/* 398/*
396 * Process the commands arguments 399 * Process the commands arguments
397 */ 400 */
398static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr) 401static const char *parse_cmd_args(sed_cmd_t *sed_cmd, const char *cmdstr)
399{ 402{
400 /* handle (s)ubstitution command */ 403 /* handle (s)ubstitution command */
401 if (sed_cmd->cmd == 's') 404 if (sed_cmd->cmd == 's')