aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorEric Andersen <andersen@codepoet.org>1999-10-29 06:50:17 +0000
committerEric Andersen <andersen@codepoet.org>1999-10-29 06:50:17 +0000
commit24d8e7d787aa1940030a1beaabdd4388588ca512 (patch)
tree2da0e6ade947ff1a5a77d3911015781a457df458
parentc1525e84dd6a3ac8252ce10e6ae605bd37d60797 (diff)
downloadbusybox-w32-24d8e7d787aa1940030a1beaabdd4388588ca512.tar.gz
busybox-w32-24d8e7d787aa1940030a1beaabdd4388588ca512.tar.bz2
busybox-w32-24d8e7d787aa1940030a1beaabdd4388588ca512.zip
Stuf
-rw-r--r--editors/sed.c6
-rw-r--r--sed.c6
-rw-r--r--utility.c86
3 files changed, 53 insertions, 45 deletions
diff --git a/editors/sed.c b/editors/sed.c
index a3e635d3a..0df53a7f8 100644
--- a/editors/sed.c
+++ b/editors/sed.c
@@ -126,7 +126,6 @@ extern int sed_main (int argc, char **argv)
126 } 126 }
127 } 127 }
128 128
129 fprintf(stderr, "argc=%d\n", argc);
130 while (argc-- > 0) { 129 while (argc-- > 0) {
131 name = *argv++; 130 name = *argv++;
132 131
@@ -135,10 +134,9 @@ extern int sed_main (int argc, char **argv)
135 perror (name); 134 perror (name);
136 continue; 135 continue;
137 } 136 }
138 fprintf(stderr, "filename is '%s'\n", name);
139 137
140 haystack = (char*)malloc( 80); 138 haystack = (char*)malloc( BUF_SIZE);
141 while (fgets (haystack, sizeof (haystack), fp)) { 139 while (fgets (haystack, BUF_SIZE-1, fp)) {
142 140
143 foundOne = replace_match(haystack, needle, newNeedle, ignoreCase); 141 foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
144 if (noprintFlag==TRUE && foundOne==TRUE) 142 if (noprintFlag==TRUE && foundOne==TRUE)
diff --git a/sed.c b/sed.c
index a3e635d3a..0df53a7f8 100644
--- a/sed.c
+++ b/sed.c
@@ -126,7 +126,6 @@ extern int sed_main (int argc, char **argv)
126 } 126 }
127 } 127 }
128 128
129 fprintf(stderr, "argc=%d\n", argc);
130 while (argc-- > 0) { 129 while (argc-- > 0) {
131 name = *argv++; 130 name = *argv++;
132 131
@@ -135,10 +134,9 @@ extern int sed_main (int argc, char **argv)
135 perror (name); 134 perror (name);
136 continue; 135 continue;
137 } 136 }
138 fprintf(stderr, "filename is '%s'\n", name);
139 137
140 haystack = (char*)malloc( 80); 138 haystack = (char*)malloc( BUF_SIZE);
141 while (fgets (haystack, sizeof (haystack), fp)) { 139 while (fgets (haystack, BUF_SIZE-1, fp)) {
142 140
143 foundOne = replace_match(haystack, needle, newNeedle, ignoreCase); 141 foundOne = replace_match(haystack, needle, newNeedle, ignoreCase);
144 if (noprintFlag==TRUE && foundOne==TRUE) 142 if (noprintFlag==TRUE && foundOne==TRUE)
diff --git a/utility.c b/utility.c
index 41e7ccc14..e0f9d1246 100644
--- a/utility.c
+++ b/utility.c
@@ -778,70 +778,82 @@ int get_console_fd(char* tty_name)
778 778
779 779
780#if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND ) 780#if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND )
781
782/* Do a case insensitive strstr() */
783char* stristr(char *haystack, const char *needle)
784{
785 int len = strlen( needle );
786 while( *haystack ) {
787 if( !strncasecmp( haystack, needle, len ) )
788 break;
789 haystack++;
790 }
791
792 if( !(*haystack) )
793 haystack = NULL;
794
795 return haystack;
796}
797
781/* This tries to find a needle in a haystack, but does so by 798/* This tries to find a needle in a haystack, but does so by
782 * only trying to match literal strings (look 'ma, no regexps!) 799 * only trying to match literal strings (look 'ma, no regexps!)
783 * This is short, sweet, and carries _very_ little baggage, 800 * This is short, sweet, and carries _very_ little baggage,
784 * unlike its beefier cousin a few lines down... 801 * unlike its beefier cousin in regexp.c
785 * -Erik Andersen 802 * -Erik Andersen
786 */ 803 */
787extern int find_match(char *haystack, char *needle, int ignoreCase) 804extern int find_match(char *haystack, char *needle, int ignoreCase)
788{ 805{
789 806
790 if (ignoreCase == FALSE) { 807 if (ignoreCase == FALSE)
791 haystack = strstr (haystack, needle); 808 haystack = strstr (haystack, needle);
792 if (haystack == NULL) 809 else
793 return FALSE; 810 haystack = stristr (haystack, needle);
794 return TRUE; 811 if (haystack == NULL)
795 } else { 812 return FALSE;
796 int i; 813 return TRUE;
797 char needle1[BUF_SIZE];
798 char haystack1[BUF_SIZE];
799
800 strncpy( haystack1, haystack, sizeof(haystack1));
801 strncpy( needle1, needle, sizeof(needle1));
802 for( i=0; i<sizeof(haystack1) && haystack1[i]; i++)
803 haystack1[i]=tolower( haystack1[i]);
804 for( i=0; i<sizeof(needle1) && needle1[i]; i++)
805 needle1[i]=tolower( needle1[i]);
806 haystack = strstr (haystack1, needle1);
807 if (haystack == NULL)
808 return FALSE;
809 return TRUE;
810 }
811} 814}
812 815
813 816
814/* This performs substitutions after a regexp match has been found. */ 817/* This performs substitutions after a string match has been found. */
815extern int replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase) 818extern int replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase)
816{ 819{
817 int foundOne; 820 int foundOne;
818 char *where, *slider; 821 char *where, *slider, *slider1, *oldhayStack;
819 822
820 if (ignoreCase == FALSE) { 823 if (ignoreCase == FALSE)
821 /*Find needle in haystack */
822 where = strstr (haystack, needle); 824 where = strstr (haystack, needle);
823 while(where!=NULL) { 825 else
824 foundOne++; 826 where = stristr (haystack, needle);
825 fprintf(stderr, "A match: haystack='%s'\n", haystack); 827
828 if (strcmp(needle, newNeedle)==0)
829 return FALSE;
830
831 oldhayStack = (char*)malloc((unsigned)(strlen(haystack)));
832 while(where!=NULL) {
833 foundOne++;
834 strcpy(oldhayStack, haystack);
835#if 0
836 if ( strlen(newNeedle) > strlen(needle)) {
826 haystack = (char *)realloc(haystack, (unsigned)(strlen(haystack) - 837 haystack = (char *)realloc(haystack, (unsigned)(strlen(haystack) -
827 strlen(needle) + strlen(newNeedle))); 838 strlen(needle) + strlen(newNeedle)));
828 for(slider=haystack;slider!=where;slider++);
829 *slider=0;
830 haystack=strcat(haystack, newNeedle);
831 slider+=1+sizeof(newNeedle);
832 haystack = strcat(haystack, slider);
833 where = strstr (where+1, needle);
834 } 839 }
835 } else { 840#endif
836 // FIXME 841 for(slider=haystack,slider1=oldhayStack;slider!=where;slider++,slider1++);
837 842 *slider=0;
843 haystack=strcat(haystack, newNeedle);
844 slider1+=strlen(needle);
845 haystack = strcat(haystack, slider1);
846 where = strstr (slider, needle);
838 } 847 }
848 free( oldhayStack);
849
839 if (foundOne) 850 if (foundOne)
840 return TRUE; 851 return TRUE;
841 else 852 else
842 return FALSE; 853 return FALSE;
843} 854}
844 855
856
845#endif 857#endif
846/* END CODE */ 858/* END CODE */
847 859