aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-08 05:21:02 +0000
committerbug1 <bug1@69ca8d6d-28ef-0310-b511-8ec308f3f277>2003-03-08 05:21:02 +0000
commit7728ad43614187172155ab898a46cfe55195ba02 (patch)
tree35bcd897ffb6e41d7e89a2531a86d4ac5a383e2d
parent74dd0dbabb7c8778468a183aeaf9490908eaffb4 (diff)
downloadbusybox-w32-7728ad43614187172155ab898a46cfe55195ba02.tar.gz
busybox-w32-7728ad43614187172155ab898a46cfe55195ba02.tar.bz2
busybox-w32-7728ad43614187172155ab898a46cfe55195ba02.zip
Fix matching for the $ address (last line)
git-svn-id: svn://busybox.net/trunk/busybox@6719 69ca8d6d-28ef-0310-b511-8ec308f3f277
-rw-r--r--editors/sed.c22
1 files changed, 16 insertions, 6 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 4ab721982..08c56a06d 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -399,8 +399,8 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd
399 * part1 part2 part3 399 * part1 part2 part3
400 */ 400 */
401 401
402 /* first part (if present) is an address: either a number or a /regex/ */ 402 /* first part (if present) is an address: either a '$', a number or a /regex/ */
403 if (isdigit(cmdstr[idx]) || cmdstr[idx] == '/' || ( cmdstr[idx] == '\\' && cmdstr[idx+1] != '\\')) 403 if ((cmdstr[idx] == '$') || (isdigit(cmdstr[idx])) || (cmdstr[idx] == '/') || ((cmdstr[idx] == '\\') && (cmdstr[idx+1] != '\\')))
404 idx = get_address(sed_cmd, cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match); 404 idx = get_address(sed_cmd, cmdstr, &sed_cmd->beg_line, &sed_cmd->beg_match);
405 405
406 /* second part (if present) will begin with a comma */ 406 /* second part (if present) will begin with a comma */
@@ -645,14 +645,23 @@ static int do_subst_command(const struct sed_cmd *sed_cmd, char **line)
645 645
646static void process_file(FILE *file) 646static void process_file(FILE *file)
647{ 647{
648 char *line = NULL; 648 char *line;
649 static int linenum = 0; /* GNU sed does not restart counting lines at EOF */ 649 static int linenum = 0; /* GNU sed does not restart counting lines at EOF */
650 unsigned int still_in_range = 0; 650 unsigned int still_in_range = 0;
651 int altered; 651 int altered;
652 int i; 652 int i;
653 653
654 line = get_line_from_file(file);
655 if (line == NULL) {
656 return;
657 }
658
654 /* go through every line in the file */ 659 /* go through every line in the file */
655 while ((line = get_line_from_file(file)) != NULL) { 660 do {
661 char *next_line;
662
663 /* Read one line in advance so we can act on the last line, the '$' address */
664 next_line = get_line_from_file(file);
656 665
657 chomp(line); 666 chomp(line);
658 linenum++; 667 linenum++;
@@ -676,7 +685,7 @@ static void process_file(FILE *file)
676 /* this line matches our first address regex */ 685 /* this line matches our first address regex */
677 (sed_cmd->beg_match && (regexec(sed_cmd->beg_match, line, 0, NULL, 0) == 0)) || 686 (sed_cmd->beg_match && (regexec(sed_cmd->beg_match, line, 0, NULL, 0) == 0)) ||
678 /* we are currently within the beginning & ending address range */ 687 /* we are currently within the beginning & ending address range */
679 still_in_range 688 still_in_range || ((sed_cmd->beg_line == -1) && (next_line == NULL))
680 ); 689 );
681 690
682 if (sed_cmd->invert ^ matched) { 691 if (sed_cmd->invert ^ matched) {
@@ -811,7 +820,8 @@ static void process_file(FILE *file)
811 puts(line); 820 puts(line);
812 821
813 free(line); 822 free(line);
814 } 823 line = next_line;
824 } while (line);
815} 825}
816 826
817extern int sed_main(int argc, char **argv) 827extern int sed_main(int argc, char **argv)