Some more patchelttes from Larry Doolittle.
[oweals/busybox.git] / sed.c
diff --git a/sed.c b/sed.c
index 156ad3adaa30774168811ab780609e52a75ebb3a..47fb63712066a5f1a8e02133d7b9f8bbe06006f5 100644 (file)
--- a/sed.c
+++ b/sed.c
@@ -181,7 +181,7 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *line, rege
                        error_msg_and_die("unterminated match expression");
                my_str[idx] = '\0';
                *regex = (regex_t *)xmalloc(sizeof(regex_t));
-               xregcomp(*regex, my_str+1, 0);
+               xregcomp(*regex, my_str+1, REG_NEWLINE);
                idx++; /* so it points to the next character after the last '/' */
        }
        else {
@@ -577,9 +577,7 @@ static int do_subst_command(const struct sed_cmd *sed_cmd, const char *line)
                        break;
        }
 
-       /* if there's anything left of the line, print it */
-       if (*hackline)
-               fputs(hackline, stdout);
+       puts(hackline);
 
        /* cleanup */
        free(regmatch);
@@ -594,7 +592,7 @@ static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
        switch (sed_cmd->cmd) {
 
                case 'p':
-                       fputs(line, stdout);
+                       puts(line);
                        break;
 
                case 'd':
@@ -619,7 +617,7 @@ static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
                         *    flag exists in the first place.
                         */
 
-                       /* if the user specified that they didn't want anything printed (i.e. a -n
+                       /* if the user specified that they didn't want anything printed (i.e., a -n
                         * flag and no 'p' flag after the s///), then there's really no point doing
                         * anything here. */
                        if (be_quiet && !sed_cmd->sub_p)
@@ -637,7 +635,7 @@ static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
                        break;
 
                case 'a':
-                       fputs(line, stdout);
+                       puts(line);
                        fputs(sed_cmd->editline, stdout);
                        altered++;
                        break;
@@ -653,7 +651,7 @@ static int do_sed_command(const struct sed_cmd *sed_cmd, const char *line)
 
                case 'r': {
                        FILE *file;
-                       fputs(line, stdout);
+                       puts(line);
                        file = fopen(sed_cmd->filename, "r");
                        if (file)
                                print_file(file);
@@ -677,6 +675,7 @@ static void process_file(FILE *file)
        /* go through every line in the file */
        while ((line = get_line_from_file(file)) != NULL) {
 
+               chomp(line);
                linenum++;
                line_altered = 0;
 
@@ -723,7 +722,7 @@ static void process_file(FILE *file)
                 * line was altered (via a 'd'elete or 's'ubstitution), in which case
                 * the altered line was already printed */
                if (!be_quiet && !line_altered)
-                       fputs(line, stdout);
+                       puts(line);
 
                free(line);
        }