diff options
author | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-10-29 00:07:31 +0000 |
---|---|---|
committer | andersen <andersen@69ca8d6d-28ef-0310-b511-8ec308f3f277> | 1999-10-29 00:07:31 +0000 |
commit | 2f8c4fd21e700eb3a87b36dc405bcd2360c99eba (patch) | |
tree | bef01229299c4ad89f2e353df0e88af292a8795c /utility.c | |
parent | 2e723b93d635572788b1afbe0bb55870305669db (diff) | |
download | busybox-w32-2f8c4fd21e700eb3a87b36dc405bcd2360c99eba.tar.gz busybox-w32-2f8c4fd21e700eb3a87b36dc405bcd2360c99eba.tar.bz2 busybox-w32-2f8c4fd21e700eb3a87b36dc405bcd2360c99eba.zip |
Stuff
git-svn-id: svn://busybox.net/trunk/busybox@65 69ca8d6d-28ef-0310-b511-8ec308f3f277
Diffstat (limited to '')
-rw-r--r-- | utility.c | 101 |
1 files changed, 66 insertions, 35 deletions
@@ -686,41 +686,6 @@ my_getgrgid(char* group, gid_t gid) | |||
686 | 686 | ||
687 | 687 | ||
688 | 688 | ||
689 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND ) | ||
690 | /* This tries to find a needle in a haystack, but does so by | ||
691 | * only trying to match literal strings (look 'ma, no regexps!) | ||
692 | * This is short, sweet, and carries _very_ little baggage, | ||
693 | * unlike its beefier cousin a few lines down... | ||
694 | * -Erik Andersen | ||
695 | */ | ||
696 | extern int find_match(char *haystack, char *needle, int ignoreCase) | ||
697 | { | ||
698 | |||
699 | if (ignoreCase == FALSE) { | ||
700 | haystack = strstr (haystack, needle); | ||
701 | if (haystack == NULL) | ||
702 | return FALSE; | ||
703 | return TRUE; | ||
704 | } else { | ||
705 | int i; | ||
706 | char needle1[BUF_SIZE]; | ||
707 | char haystack1[BUF_SIZE]; | ||
708 | |||
709 | strncpy( haystack1, haystack, sizeof(haystack1)); | ||
710 | strncpy( needle1, needle, sizeof(needle1)); | ||
711 | for( i=0; i<sizeof(haystack1) && haystack1[i]; i++) | ||
712 | haystack1[i]=tolower( haystack1[i]); | ||
713 | for( i=0; i<sizeof(needle1) && needle1[i]; i++) | ||
714 | needle1[i]=tolower( needle1[i]); | ||
715 | haystack = strstr (haystack1, needle1); | ||
716 | if (haystack == NULL) | ||
717 | return FALSE; | ||
718 | return TRUE; | ||
719 | } | ||
720 | } | ||
721 | #endif | ||
722 | |||
723 | |||
724 | 689 | ||
725 | #if (defined BB_CHVT) || (defined BB_DEALLOCVT) | 690 | #if (defined BB_CHVT) || (defined BB_DEALLOCVT) |
726 | 691 | ||
@@ -812,5 +777,71 @@ int get_console_fd(char* tty_name) | |||
812 | #endif | 777 | #endif |
813 | 778 | ||
814 | 779 | ||
780 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND ) | ||
781 | /* This tries to find a needle in a haystack, but does so by | ||
782 | * only trying to match literal strings (look 'ma, no regexps!) | ||
783 | * This is short, sweet, and carries _very_ little baggage, | ||
784 | * unlike its beefier cousin a few lines down... | ||
785 | * -Erik Andersen | ||
786 | */ | ||
787 | extern int find_match(char *haystack, char *needle, int ignoreCase) | ||
788 | { | ||
789 | |||
790 | if (ignoreCase == FALSE) { | ||
791 | haystack = strstr (haystack, needle); | ||
792 | if (haystack == NULL) | ||
793 | return FALSE; | ||
794 | return TRUE; | ||
795 | } else { | ||
796 | int i; | ||
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 | } | ||
812 | |||
813 | |||
814 | /* This performs substitutions after a regexp match has been found. */ | ||
815 | extern int replace_match(char *haystack, char *needle, char *newNeedle, int ignoreCase) | ||
816 | { | ||
817 | int foundOne; | ||
818 | char *where, *slider; | ||
819 | |||
820 | if (ignoreCase == FALSE) { | ||
821 | /*Find needle in haystack */ | ||
822 | where = strstr (haystack, needle); | ||
823 | while(where!=NULL) { | ||
824 | foundOne++; | ||
825 | fprintf(stderr, "A match: haystack='%s'\n", haystack); | ||
826 | haystack = (char *)realloc(haystack, (unsigned)(strlen(haystack) - | ||
827 | 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 | } | ||
835 | } else { | ||
836 | // FIXME | ||
837 | |||
838 | } | ||
839 | if (foundOne) | ||
840 | return TRUE; | ||
841 | else | ||
842 | return FALSE; | ||
843 | } | ||
844 | |||
845 | #endif | ||
815 | /* END CODE */ | 846 | /* END CODE */ |
816 | 847 | ||