aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorGlenn L McGrath <bug1@ihug.co.nz>2003-04-07 12:24:44 +0000
committerGlenn L McGrath <bug1@ihug.co.nz>2003-04-07 12:24:44 +0000
commitc6adada1584df76a85ed08ba7bbfa9a8c3302f99 (patch)
tree4a8950326054d14ba1fd9f114321b6ab9e4a7e9a
parent4957fc7a931a6c310b19f8ba7e2c75fe418e95e5 (diff)
downloadbusybox-w32-c6adada1584df76a85ed08ba7bbfa9a8c3302f99.tar.gz
busybox-w32-c6adada1584df76a85ed08ba7bbfa9a8c3302f99.tar.bz2
busybox-w32-c6adada1584df76a85ed08ba7bbfa9a8c3302f99.zip
Rename "line" to pattern_space to be more descriptive and closer to the POSIX description
-rw-r--r--editors/sed.c66
1 files changed, 32 insertions, 34 deletions
diff --git a/editors/sed.c b/editors/sed.c
index c03924917..834f06638 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -773,14 +773,14 @@ static sed_cmd_t *branch_to(const char *label)
773 773
774static void process_file(FILE *file) 774static void process_file(FILE *file)
775{ 775{
776 char *line; 776 char *pattern_space; /* Posix requires it be able to hold at least 8192 bytes */
777 static int linenum = 0; /* GNU sed does not restart counting lines at EOF */ 777 static int linenum = 0; /* GNU sed does not restart counting lines at EOF */
778 unsigned int still_in_range = 0; 778 unsigned int still_in_range = 0;
779 int altered; 779 int altered;
780 int force_print; 780 int force_print;
781 781
782 line = bb_get_chomped_line_from_file(file); 782 pattern_space = bb_get_chomped_line_from_file(file);
783 if (line == NULL) { 783 if (pattern_space == NULL) {
784 return; 784 return;
785 } 785 }
786 786
@@ -812,7 +812,7 @@ static void process_file(FILE *file)
812 /* this line number is the first address we're looking for */ 812 /* this line number is the first address we're looking for */
813 (sed_cmd->beg_line && (sed_cmd->beg_line == linenum)) || 813 (sed_cmd->beg_line && (sed_cmd->beg_line == linenum)) ||
814 /* this line matches our first address regex */ 814 /* this line matches our first address regex */
815 (sed_cmd->beg_match && (regexec(sed_cmd->beg_match, line, 0, NULL, 0) == 0)) || 815 (sed_cmd->beg_match && (regexec(sed_cmd->beg_match, pattern_space, 0, NULL, 0) == 0)) ||
816 /* we are currently within the beginning & ending address range */ 816 /* we are currently within the beginning & ending address range */
817 still_in_range || ((sed_cmd->beg_line == -1) && (next_line == NULL)) 817 still_in_range || ((sed_cmd->beg_line == -1) && (next_line == NULL))
818 ); 818 );
@@ -827,13 +827,13 @@ static void process_file(FILE *file)
827 printf("%d\n", linenum); 827 printf("%d\n", linenum);
828 break; 828 break;
829 case 'P': { /* Write the current pattern space upto the first newline */ 829 case 'P': { /* Write the current pattern space upto the first newline */
830 char *tmp = strchr(line, '\n'); 830 char *tmp = strchr(pattern_space, '\n');
831 if (tmp) { 831 if (tmp) {
832 *tmp = '\0'; 832 *tmp = '\0';
833 } 833 }
834 } 834 }
835 case 'p': /* Write the current pattern space to output */ 835 case 'p': /* Write the current pattern space to output */
836 puts(line); 836 puts(pattern_space);
837 break; 837 break;
838 case 'd': 838 case 'd':
839 altered++; 839 altered++;
@@ -850,8 +850,8 @@ static void process_file(FILE *file)
850 * substitution 850 * substitution
851 * 851 *
852 * s///p ONLY = always print successful substitutions, even if 852 * s///p ONLY = always print successful substitutions, even if
853 * the line is going to be printed anyway (line will be printed 853 * the pattern_space is going to be printed anyway (pattern_space
854 * twice). 854 * will be printed twice).
855 * 855 *
856 * -n AND s///p = print ONLY a successful substitution ONE TIME; 856 * -n AND s///p = print ONLY a successful substitution ONE TIME;
857 * no other lines are printed - this is the reason why the 'p' 857 * no other lines are printed - this is the reason why the 'p'
@@ -862,24 +862,24 @@ static void process_file(FILE *file)
862 /* HACK: escape newlines twice so regex can match them */ 862 /* HACK: escape newlines twice so regex can match them */
863 { 863 {
864 int offset = 0; 864 int offset = 0;
865 while(strchr(line + offset, '\n') != NULL) { 865 while(strchr(pattern_space + offset, '\n') != NULL) {
866 char *tmp; 866 char *tmp;
867 line = xrealloc(line, strlen(line) + 2); 867 pattern_space = xrealloc(pattern_space, strlen(pattern_space) + 2);
868 tmp = strchr(line + offset, '\n'); 868 tmp = strchr(pattern_space + offset, '\n');
869 memmove(tmp + 1, tmp, strlen(tmp) + 1); 869 memmove(tmp + 1, tmp, strlen(tmp) + 1);
870 tmp[0] = '\\'; 870 tmp[0] = '\\';
871 tmp[1] = 'n'; 871 tmp[1] = 'n';
872 offset = tmp - line + 2; 872 offset = tmp - pattern_space + 2;
873 } 873 }
874 } 874 }
875#endif 875#endif
876 /* we print the line once, unless we were told to be quiet */ 876 /* we print the pattern_space once, unless we were told to be quiet */
877 substituted = do_subst_command(sed_cmd, &line); 877 substituted = do_subst_command(sed_cmd, &pattern_space);
878 878
879#ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE 879#ifdef CONFIG_FEATURE_SED_EMBEDED_NEWLINE
880 /* undo HACK: escape newlines twice so regex can match them */ 880 /* undo HACK: escape newlines twice so regex can match them */
881 { 881 {
882 char *tmp = line; 882 char *tmp = pattern_space;
883 883
884 while((tmp = strstr(tmp, "\\n")) != NULL) { 884 while((tmp = strstr(tmp, "\\n")) != NULL) {
885 memmove(tmp, tmp + 1, strlen(tmp + 1) + 1); 885 memmove(tmp, tmp + 1, strlen(tmp + 1) + 1);
@@ -895,11 +895,11 @@ static void process_file(FILE *file)
895 /* we also print the line if we were given the 'p' flag 895 /* we also print the line if we were given the 'p' flag
896 * (this is quite possibly the second printing) */ 896 * (this is quite possibly the second printing) */
897 if ((sed_cmd->sub_p) && altered) { 897 if ((sed_cmd->sub_p) && altered) {
898 puts(line); 898 puts(pattern_space);
899 } 899 }
900 break; 900 break;
901 case 'a': 901 case 'a':
902 puts(line); 902 puts(pattern_space);
903 fputs(sed_cmd->editline, stdout); 903 fputs(sed_cmd->editline, stdout);
904 altered++; 904 altered++;
905 break; 905 break;
@@ -913,7 +913,7 @@ static void process_file(FILE *file)
913 if ((sed_cmd->end_match == NULL && sed_cmd->end_line == 0) 913 if ((sed_cmd->end_match == NULL && sed_cmd->end_line == 0)
914 /* multi-address case */ 914 /* multi-address case */
915 /* - matching text */ 915 /* - matching text */
916 || (sed_cmd->end_match && (regexec(sed_cmd->end_match, line, 0, NULL, 0) == 0)) 916 || (sed_cmd->end_match && (regexec(sed_cmd->end_match, pattern_space, 0, NULL, 0) == 0))
917 /* - matching line numbers */ 917 /* - matching line numbers */
918 || (sed_cmd->end_line > 0 && sed_cmd->end_line == linenum)) 918 || (sed_cmd->end_line > 0 && sed_cmd->end_line == linenum))
919 { 919 {
@@ -925,7 +925,7 @@ static void process_file(FILE *file)
925 925
926 case 'r': { 926 case 'r': {
927 FILE *outfile; 927 FILE *outfile;
928 puts(line); 928 puts(pattern_space);
929 outfile = fopen(sed_cmd->filename, "r"); 929 outfile = fopen(sed_cmd->filename, "r");
930 if (outfile) 930 if (outfile)
931 bb_xprint_and_close_file(outfile); 931 bb_xprint_and_close_file(outfile);
@@ -941,16 +941,16 @@ static void process_file(FILE *file)
941 next_line = NULL; 941 next_line = NULL;
942 break; 942 break;
943 case 'n': /* Read next line from input */ 943 case 'n': /* Read next line from input */
944 free(line); 944 free(pattern_space);
945 line = next_line; 945 pattern_space = next_line;
946 next_line = bb_get_chomped_line_from_file(file); 946 next_line = bb_get_chomped_line_from_file(file);
947 linenum++; 947 linenum++;
948 break; 948 break;
949 case 'N': /* Append the next line to the current line */ 949 case 'N': /* Append the next line to the current line */
950 if (next_line) { 950 if (next_line) {
951 line = realloc(line, strlen(line) + strlen(next_line) + 2); 951 pattern_space = realloc(pattern_space, strlen(pattern_space) + strlen(next_line) + 2);
952 strcat(line, "\n"); 952 strcat(pattern_space, "\n");
953 strcat(line, next_line); 953 strcat(pattern_space, next_line);
954 next_line = bb_get_chomped_line_from_file(file); 954 next_line = bb_get_chomped_line_from_file(file);
955 linenum++; 955 linenum++;
956 } 956 }
@@ -965,18 +965,16 @@ static void process_file(FILE *file)
965 break; 965 break;
966 case 'y': { 966 case 'y': {
967 int i; 967 int i;
968 for (i = 0; line[i] != 0; i++) { 968 for (i = 0; pattern_space[i] != 0; i++) {
969 int j; 969 int j;
970 for (j = 0; sed_cmd->translate[j] ;j += 2) { 970 for (j = 0; sed_cmd->translate[j] ;j += 2) {
971 if (line[i] == sed_cmd->translate[j]) { 971 if (pattern_space[i] == sed_cmd->translate[j]) {
972 line[i] = sed_cmd->translate[j + 1]; 972 pattern_space[i] = sed_cmd->translate[j + 1];
973 } 973 }
974 } 974 }
975 } 975 }
976 } 976 }
977 break; 977 break;
978// case ':':
979// break;
980 } 978 }
981 } 979 }
982 980
@@ -993,7 +991,7 @@ static void process_file(FILE *file)
993 /* this line number is the last address we're looking for or... */ 991 /* this line number is the last address we're looking for or... */
994 (sed_cmd->end_line && (sed_cmd->end_line == linenum)) || 992 (sed_cmd->end_line && (sed_cmd->end_line == linenum)) ||
995 /* this line matches our last address regex */ 993 /* this line matches our last address regex */
996 (sed_cmd->end_match && (regexec(sed_cmd->end_match, line, 0, NULL, 0) == 0)) 994 (sed_cmd->end_match && (regexec(sed_cmd->end_match, pattern_space, 0, NULL, 0) == 0))
997 ) 995 )
998 ) 996 )
999 ) { 997 ) {
@@ -1015,11 +1013,11 @@ static void process_file(FILE *file)
1015 * line was altered (via a 'd'elete or 's'ubstitution), in which case 1013 * line was altered (via a 'd'elete or 's'ubstitution), in which case
1016 * the altered line was already printed */ 1014 * the altered line was already printed */
1017 if ((!be_quiet && !altered) || force_print){ 1015 if ((!be_quiet && !altered) || force_print){
1018 puts(line); 1016 puts(pattern_space);
1019 } 1017 }
1020 free(line); 1018 free(pattern_space);
1021 line = next_line; 1019 pattern_space = next_line;
1022 } while (line); 1020 } while (pattern_space);
1023} 1021}
1024 1022
1025extern int sed_main(int argc, char **argv) 1023extern int sed_main(int argc, char **argv)