diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-10-29 06:50:17 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-10-29 06:50:17 +0000 |
commit | b23b7da7f1cbec3d3744e6a2c40a11d52c0a6dc0 (patch) | |
tree | 2da0e6ade947ff1a5a77d3911015781a457df458 /utility.c | |
parent | 2f8c4fd21e700eb3a87b36dc405bcd2360c99eba (diff) | |
download | busybox-w32-b23b7da7f1cbec3d3744e6a2c40a11d52c0a6dc0.tar.gz busybox-w32-b23b7da7f1cbec3d3744e6a2c40a11d52c0a6dc0.tar.bz2 busybox-w32-b23b7da7f1cbec3d3744e6a2c40a11d52c0a6dc0.zip |
Stuf
git-svn-id: svn://busybox.net/trunk/busybox@66 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r-- | utility.c | 86 |
1 files changed, 49 insertions, 37 deletions
@@ -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() */ | ||
783 | char* 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 | */ |
787 | extern int find_match(char *haystack, char *needle, int ignoreCase) | 804 | extern 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. */ |
815 | extern int replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase) | 818 | extern 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 | ||