diff options
| author | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-10 04:12:35 +0000 |
|---|---|---|
| committer | bug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 2003-03-10 04:12:35 +0000 |
| commit | eb0908cc088d21707c1deaf4cb3f370fdf34c5bd (patch) | |
| tree | b500f91385dd1a1cfcbdf2361a8ebe067d2e70ad | |
| parent | ffe0cc856f12a39f44959e828544c51a8ddd1fb4 (diff) | |
| download | busybox-w32-eb0908cc088d21707c1deaf4cb3f370fdf34c5bd.tar.gz busybox-w32-eb0908cc088d21707c1deaf4cb3f370fdf34c5bd.tar.bz2 busybox-w32-eb0908cc088d21707c1deaf4cb3f370fdf34c5bd.zip | |
fix n, add N, P
git-svn-id: svn://busybox.net/trunk/busybox@6729 69ca8d6d-28ef-0310-b511-8ec308f3f277
| -rw-r--r-- | editors/sed.c | 27 |
1 files changed, 22 insertions, 5 deletions
diff --git a/editors/sed.c b/editors/sed.c index 5b08c8ee1..e1242671e 100644 --- a/editors/sed.c +++ b/editors/sed.c | |||
| @@ -382,7 +382,7 @@ static char *parse_cmd_str(sed_cmd_t * const sed_cmd, char *cmdstr) | |||
| 382 | { | 382 | { |
| 383 | /* if it was a single-letter command that takes no arguments (such as 'p' | 383 | /* if it was a single-letter command that takes no arguments (such as 'p' |
| 384 | * or 'd') all we need to do is increment the index past that command */ | 384 | * or 'd') all we need to do is increment the index past that command */ |
| 385 | if (strchr("npqd=", sed_cmd->cmd)) { | 385 | if (strchr("nNpPqd=", sed_cmd->cmd)) { |
| 386 | cmdstr++; | 386 | cmdstr++; |
| 387 | } | 387 | } |
| 388 | /* handle (s)ubstitution command */ | 388 | /* handle (s)ubstitution command */ |
| @@ -680,6 +680,7 @@ static void process_file(FILE *file) | |||
| 680 | if (line == NULL) { | 680 | if (line == NULL) { |
| 681 | return; | 681 | return; |
| 682 | } | 682 | } |
| 683 | chomp(line); | ||
| 683 | 684 | ||
| 684 | /* go through every line in the file */ | 685 | /* go through every line in the file */ |
| 685 | do { | 686 | do { |
| @@ -688,7 +689,7 @@ static void process_file(FILE *file) | |||
| 688 | /* Read one line in advance so we can act on the last line, the '$' address */ | 689 | /* Read one line in advance so we can act on the last line, the '$' address */ |
| 689 | next_line = get_line_from_file(file); | 690 | next_line = get_line_from_file(file); |
| 690 | 691 | ||
| 691 | chomp(line); | 692 | chomp(next_line); |
| 692 | linenum++; | 693 | linenum++; |
| 693 | altered = 0; | 694 | altered = 0; |
| 694 | 695 | ||
| @@ -722,10 +723,15 @@ static void process_file(FILE *file) | |||
| 722 | case '=': | 723 | case '=': |
| 723 | printf("%d\n", linenum); | 724 | printf("%d\n", linenum); |
| 724 | break; | 725 | break; |
| 725 | case 'p': | 726 | case 'P': { /* Write the current pattern space upto the first newline */ |
| 727 | char *tmp = strchr(line, '\n'); | ||
| 728 | if (tmp) { | ||
| 729 | *tmp = '\0'; | ||
| 730 | } | ||
| 731 | } | ||
| 732 | case 'p': /* Write the current pattern space to output */ | ||
| 726 | puts(line); | 733 | puts(line); |
| 727 | break; | 734 | break; |
| 728 | |||
| 729 | case 'd': | 735 | case 'd': |
| 730 | altered++; | 736 | altered++; |
| 731 | deleted = 1; | 737 | deleted = 1; |
| @@ -808,8 +814,19 @@ static void process_file(FILE *file) | |||
| 808 | free(line); | 814 | free(line); |
| 809 | return; | 815 | return; |
| 810 | case 'n': /* Read next line from input */ | 816 | case 'n': /* Read next line from input */ |
| 811 | i = ncmds; | 817 | free(line); |
| 818 | line = next_line; | ||
| 819 | next_line = get_line_from_file(file); | ||
| 820 | chomp(next_line); | ||
| 821 | linenum++; | ||
| 812 | break; | 822 | break; |
| 823 | case 'N': /* Append the next line to the current line */ | ||
| 824 | line = realloc(line, strlen(line) + strlen(next_line) + 2); | ||
| 825 | strcat(line, "\n"); | ||
| 826 | strcat(line, next_line); | ||
| 827 | next_line = get_line_from_file(file); | ||
| 828 | chomp(next_line); | ||
| 829 | linenum++; | ||
| 813 | } | 830 | } |
| 814 | } | 831 | } |
| 815 | 832 | ||
