- reuse strings and messages. Saves about 600B
[oweals/busybox.git] / editors / sed.c
index 893931153afbda027ccff84d7c0f0f862168c398..219a44008bc982cd141607ca2692baaeb0f611b2 100644 (file)
@@ -134,7 +134,7 @@ void sed_free_and_close_stuff(void)
 {
        sed_cmd_t *sed_cmd = bbg.sed_cmd_head.next;
 
-       llist_free_contents(bbg.append_head);
+       llist_free(bbg.append_head, free);
 
        while (sed_cmd) {
                sed_cmd_t *sed_cmd_next = sed_cmd->next;
@@ -449,7 +449,7 @@ static char *parse_cmd_args(sed_cmd_t *sed_cmd, char *cmdstr)
                parse_escapes(match,match,strlen(match),i,i);
                parse_escapes(replace,replace,strlen(replace),i,i);
 
-               sed_cmd->string = xcalloc(1, (strlen(match) + 1) * 2);
+               sed_cmd->string = xzalloc((strlen(match) + 1) * 2);
                for (i = 0; match[i] && replace[i]; i++) {
                        sed_cmd->string[i * 2] = match[i];
                        sed_cmd->string[(i * 2) + 1] = replace[i];
@@ -481,7 +481,7 @@ static void add_cmd(char *cmdstr)
                cmdstr = bb_xasprintf("%s\n%s", bbg.add_cmd_line, cmdstr);
                free(bbg.add_cmd_line);
                bbg.add_cmd_line = cmdstr;
-       } else bbg.add_cmd_line=NULL;
+       }
 
        /* If this line ends with backslash, request next line. */
        temp=strlen(cmdstr);
@@ -513,7 +513,7 @@ static void add_cmd(char *cmdstr)
                 *            part1 part2  part3
                 */
 
-               sed_cmd = xcalloc(1, sizeof(sed_cmd_t));
+               sed_cmd = xzalloc(sizeof(sed_cmd_t));
 
                /* first part (if present) is an address: either a '$', a number or a /regex/ */
                cmdstr += get_address(cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
@@ -683,7 +683,7 @@ static sed_cmd_t *branch_to(const char *label)
 
 static void append(char *s)
 {
-       bbg.append_head = llist_add_to_end(bbg.append_head, bb_xstrdup(s));
+       llist_add_to_end(&bbg.append_head, bb_xstrdup(s));
 }
 
 static void flush_append(void)
@@ -737,8 +737,8 @@ static int puts_maybe_newline(char *s, FILE *file, int missing_newline, int no_n
        if(!no_newline) fputc('\n',file);
 
     if(ferror(file)) {
-               fprintf(stderr,"Write failed.\n");
-               exit(4);  /* It's what gnu sed exits with... */
+               bb_default_error_retval = 4;  /* It's what gnu sed exits with... */
+               bb_error_msg_and_die(bb_msg_write_error);
        }
 
        return no_newline;
@@ -1166,7 +1166,7 @@ int sed_main(int argc, char **argv)
         * files were specified or '-' was specified, take input from stdin.
         * Otherwise, we process all the files specified. */
        if (argv[optind] == NULL) {
-               if(bbg.in_place) bb_error_msg_and_die("Filename required for -i");
+               if(bbg.in_place) bb_error_msg_and_die(bb_msg_requires_arg, "-i");
                add_input_file(stdin);
                process_files();
        } else {