Remove unused optarg variable
[oweals/busybox.git] / sed.c
diff --git a/sed.c b/sed.c
index e0351c3b80f6ae3029b68a4450467728a26dbc4d..897c290d5cf73ce6b23420ab856ebe798787aad4 100644 (file)
--- a/sed.c
+++ b/sed.c
@@ -154,6 +154,9 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *line, rege
 {
        char *my_str = strdup(str);
        int idx = 0;
+       char olddelimiter;
+       olddelimiter = sed_cmd->delimiter;
+       sed_cmd->delimiter = '/';
 
        if (isdigit(my_str[idx])) {
                do {
@@ -182,6 +185,7 @@ static int get_address(struct sed_cmd *sed_cmd, const char *str, int *line, rege
        }
 
        free(my_str);
+       sed_cmd->delimiter = olddelimiter;
        return idx;
 }
 
@@ -436,8 +440,7 @@ static void load_cmd_file(char *filename)
                }
                /* eat trailing newline (if any) --if I don't do this, edit commands
                 * (aic) will print an extra newline */
-               if (line[strlen(line)-1] == '\n')
-                       line[strlen(line)-1] = 0;
+               chomp(line);
                add_cmd_str(line);
                free(line);
        }
@@ -619,9 +622,10 @@ static void process_file(FILE *file)
                        if (sed_cmds[i].beg_match && sed_cmds[i].end_match) {
                                if (still_in_range || regexec(sed_cmds[i].beg_match, line, 0, NULL, 0) == 0) {
                                        line_altered += do_sed_command(&sed_cmds[i], line);
-                                       still_in_range = 1; 
-                                       if (regexec(sed_cmds[i].end_match, line, 0, NULL, 0) == 0)
+                                       if (still_in_range && regexec(sed_cmds[i].end_match, line, 0, NULL, 0) == 0)
                                                still_in_range = 0;
+                                       else
+                                               still_in_range = 1;
                                }
                        }
 
@@ -671,11 +675,8 @@ extern int sed_main(int argc, char **argv)
 #endif
 
        /* do normal option parsing */
-       while ((opt = getopt(argc, argv, "hne:f:")) > 0) {
+       while ((opt = getopt(argc, argv, "ne:f:")) > 0) {
                switch (opt) {
-                       case 'h':
-                               usage(sed_usage);
-                               break;
                        case 'n':
                                be_quiet++;
                                break;
@@ -685,6 +686,8 @@ extern int sed_main(int argc, char **argv)
                        case 'f': 
                                load_cmd_file(optarg);
                                break;
+                       default:
+                               show_usage();
                }
        }
 
@@ -692,7 +695,7 @@ extern int sed_main(int argc, char **argv)
         * argv[optind] should be the pattern. no pattern, no worky */
        if (ncmds == 0) {
                if (argv[optind] == NULL)
-                       usage(sed_usage);
+                       show_usage();
                else {
                        add_cmd_str(argv[optind]);
                        optind++;