aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorRobert Griebl <griebl@gmx.de>2002-06-11 23:43:27 +0000
committerRobert Griebl <griebl@gmx.de>2002-06-11 23:43:27 +0000
commit47abc49c4ae7fb219f6ecafc36a3aea972468acb (patch)
tree121535d1e1ec269b110256a60d4ce709c8da664d
parent3ad88ccf2de2ed7c415f5d998235d7cf135c0b23 (diff)
downloadbusybox-w32-47abc49c4ae7fb219f6ecafc36a3aea972468acb.tar.gz
busybox-w32-47abc49c4ae7fb219f6ecafc36a3aea972468acb.tar.bz2
busybox-w32-47abc49c4ae7fb219f6ecafc36a3aea972468acb.zip
Patch from Simon Krahnke:
I wrote a patch for busybox for our company's (www.lisa.de) private use. [...] To sed it adds the '!'-inversion of addresses.
-rw-r--r--editors/sed.c39
1 files changed, 28 insertions, 11 deletions
diff --git a/editors/sed.c b/editors/sed.c
index 5edcd482b..93faf00c2 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -96,6 +96,9 @@ struct sed_cmd {
96 96
97 /* the command */ 97 /* the command */
98 char cmd; /* p,d,s (add more at your leisure :-) */ 98 char cmd; /* p,d,s (add more at your leisure :-) */
99
100 /* inversion flag */
101 int invert; /* the '!' after the address */
99}; 102};
100 103
101/* globals */ 104/* globals */
@@ -405,6 +408,17 @@ static char *parse_cmd_str(struct sed_cmd * const sed_cmd, const char *const cmd
405 while (isspace(cmdstr[idx])) 408 while (isspace(cmdstr[idx]))
406 idx++; 409 idx++;
407 410
411 /* there my be the inversion flag between part2 and part3 */
412 sed_cmd->invert = 0;
413 if (cmdstr[idx] == '!') {
414 sed_cmd->invert = 1;
415 idx++;
416
417 /* skip whitespace before the command */
418 while (isspace(cmdstr[idx]))
419 idx++;
420 }
421
408 /* last part (mandatory) will be a command */ 422 /* last part (mandatory) will be a command */
409 if (cmdstr[idx] == '\0') 423 if (cmdstr[idx] == '\0')
410 error_msg_and_die("missing command"); 424 error_msg_and_die("missing command");
@@ -642,12 +656,12 @@ static void process_file(FILE *file)
642 /* for every line, go through all the commands */ 656 /* for every line, go through all the commands */
643 for (i = 0; i < ncmds; i++) { 657 for (i = 0; i < ncmds; i++) {
644 struct sed_cmd *sed_cmd = &sed_cmds[i]; 658 struct sed_cmd *sed_cmd = &sed_cmds[i];
645 659 int deleted = 0;
646 660
647 /* 661 /*
648 * entry point into sedding... 662 * entry point into sedding...
649 */ 663 */
650 if ( 664 int matched = (
651 /* no range necessary */ 665 /* no range necessary */
652 (sed_cmd->beg_line == 0 && sed_cmd->end_line == 0 && 666 (sed_cmd->beg_line == 0 && sed_cmd->end_line == 0 &&
653 sed_cmd->beg_match == NULL && 667 sed_cmd->beg_match == NULL &&
@@ -658,8 +672,9 @@ static void process_file(FILE *file)
658 (sed_cmd->beg_match && (regexec(sed_cmd->beg_match, line, 0, NULL, 0) == 0)) || 672 (sed_cmd->beg_match && (regexec(sed_cmd->beg_match, line, 0, NULL, 0) == 0)) ||
659 /* we are currently within the beginning & ending address range */ 673 /* we are currently within the beginning & ending address range */
660 still_in_range 674 still_in_range
661 ) { 675 );
662 int deleted = 0; 676
677 if (sed_cmd->invert ^ matched) {
663 678
664 /* 679 /*
665 * actual sedding 680 * actual sedding
@@ -746,13 +761,15 @@ static void process_file(FILE *file)
746 /* else if we couldn't open the output file, 761 /* else if we couldn't open the output file,
747 * no biggie, just don't print anything */ 762 * no biggie, just don't print anything */
748 altered++; 763 altered++;
749 } 764 }
750 break; 765 break;
751 } 766 }
767 }
752 768
753 /* 769 /*
754 * exit point from sedding... 770 * exit point from sedding...
755 */ 771 */
772 if (matched) {
756 if ( 773 if (
757 /* this is a single-address command or... */ 774 /* this is a single-address command or... */
758 (sed_cmd->end_line == 0 && sed_cmd->end_match == NULL) || ( 775 (sed_cmd->end_line == 0 && sed_cmd->end_match == NULL) || (
@@ -774,10 +791,10 @@ static void process_file(FILE *file)
774 else { 791 else {
775 still_in_range = 1; 792 still_in_range = 1;
776 } 793 }
777
778 if (deleted)
779 break;
780 } 794 }
795
796 if (deleted)
797 break;
781 } 798 }
782 799
783 /* we will print the line unless we were told to be quiet or if the 800 /* we will print the line unless we were told to be quiet or if the