aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-09-14 06:01:14 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-09-14 06:01:14 +0000
commitf4523562b615b8b2cfc8bcc7a962b4d0f5cb9168 (patch)
tree292257e3ebb8632bd292bf8a663c005aa36d1c0b
parent8aac05bfe5ffdbc4c9591d7d5b486c0af0769a7a (diff)
downloadbusybox-w32-f4523562b615b8b2cfc8bcc7a962b4d0f5cb9168.tar.gz
busybox-w32-f4523562b615b8b2cfc8bcc7a962b4d0f5cb9168.tar.bz2
busybox-w32-f4523562b615b8b2cfc8bcc7a962b4d0f5cb9168.zip
Fix branching commands.
If a label isnt specified, jump to end of script, not the last command in the script. Print an error and exit if you try and jump to a non-existant label Works for the following testcase # cat strings a b c d e f g # cat strings | ./busybox sed -n '/d/b;p' a b c e f g
-rw-r--r--editors/sed.c31
1 files changed, 18 insertions, 13 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 7174288a2..aa3ce024e 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -475,9 +475,11 @@ static char *parse_cmd_str(sed_cmd_t * sed_cmd, char *cmdstr)
475 int length; 475 int length;
476 476
477 cmdstr += strspn(cmdstr, " "); 477 cmdstr += strspn(cmdstr, " ");
478 length = strcspn(cmdstr, "; \n"); 478 length = strcspn(cmdstr, semicolon_whitespace);
479 sed_cmd->label = strndup(cmdstr, length); 479 if (length) {
480 cmdstr += length; 480 sed_cmd->label = strndup(cmdstr, length);
481 cmdstr += length;
482 }
481 } 483 }
482 /* translation command */ 484 /* translation command */
483 else if (sed_cmd->cmd == 'y') { 485 else if (sed_cmd->cmd == 'y') {
@@ -771,13 +773,11 @@ static sed_cmd_t *branch_to(const char *label)
771 sed_cmd_t *sed_cmd; 773 sed_cmd_t *sed_cmd;
772 774
773 for (sed_cmd = sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) { 775 for (sed_cmd = sed_cmd_head.next; sed_cmd; sed_cmd = sed_cmd->next) {
774 if ((sed_cmd->label) && (strcmp(sed_cmd->label, label) == 0)) { 776 if ((sed_cmd->cmd == ':') && (sed_cmd->label) && (strcmp(sed_cmd->label, label) == 0)) {
775 break; 777 return (sed_cmd);
776 } 778 }
777 } 779 }
778 780 bb_error_msg_and_die("Can't find label for jump to `%s'", label);
779 /* If no match returns last command */
780 return (sed_cmd);
781} 781}
782 782
783static void process_file(FILE * file) 783static void process_file(FILE * file)
@@ -998,12 +998,17 @@ static void process_file(FILE * file)
998 linenum++; 998 linenum++;
999 } 999 }
1000 break; 1000 break;
1001 case 'b':
1002 sed_cmd = branch_to(sed_cmd->label);
1003 break;
1004 case 't': 1001 case 't':
1005 if (substituted) { 1002 if (substituted)
1006 sed_cmd = branch_to(sed_cmd->label); 1003 /* Fall through */
1004 case 'b':
1005 {
1006 if (sed_cmd->label == NULL) {
1007 /* Jump to end of script */
1008 deleted = 1;
1009 } else {
1010 sed_cmd = branch_to(sed_cmd->label);
1011 }
1007 } 1012 }
1008 break; 1013 break;
1009 case 'y':{ 1014 case 'y':{