diff options
Diffstat (limited to 'utility.c')
-rw-r--r-- | utility.c | 111 |
1 files changed, 110 insertions, 1 deletions
@@ -771,7 +771,7 @@ int get_console_fd(char* tty_name) | |||
771 | #endif | 771 | #endif |
772 | 772 | ||
773 | 773 | ||
774 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_FIND || defined BB_SED) | 774 | #if !defined BB_REGEXP && (defined BB_GREP || defined BB_SED) |
775 | 775 | ||
776 | /* Do a case insensitive strstr() */ | 776 | /* Do a case insensitive strstr() */ |
777 | char* stristr(char *haystack, const char *needle) | 777 | char* stristr(char *haystack, const char *needle) |
@@ -851,6 +851,108 @@ extern int replace_match(char *haystack, char *needle, char *newNeedle, int igno | |||
851 | #endif | 851 | #endif |
852 | 852 | ||
853 | 853 | ||
854 | #if defined BB_FIND | ||
855 | /* | ||
856 | * Routine to see if a text string is matched by a wildcard pattern. | ||
857 | * Returns TRUE if the text is matched, or FALSE if it is not matched | ||
858 | * or if the pattern is invalid. | ||
859 | * * matches zero or more characters | ||
860 | * ? matches a single character | ||
861 | * [abc] matches 'a', 'b' or 'c' | ||
862 | * \c quotes character c | ||
863 | * Adapted from code written by Ingo Wilken, and | ||
864 | * then taken from sash, Copyright (c) 1999 by David I. Bell | ||
865 | * Permission is granted to use, distribute, or modify this source, | ||
866 | * provided that this copyright notice remains intact. | ||
867 | * Permission to distribute this code under the GPL has been granted. | ||
868 | */ | ||
869 | extern int | ||
870 | check_wildcard_match(const char* text, const char* pattern) | ||
871 | { | ||
872 | const char* retryPat; | ||
873 | const char* retryText; | ||
874 | int ch; | ||
875 | int found; | ||
876 | |||
877 | retryPat = NULL; | ||
878 | retryText = NULL; | ||
879 | |||
880 | while (*text || *pattern) | ||
881 | { | ||
882 | ch = *pattern++; | ||
883 | |||
884 | switch (ch) | ||
885 | { | ||
886 | case '*': | ||
887 | retryPat = pattern; | ||
888 | retryText = text; | ||
889 | break; | ||
890 | |||
891 | case '[': | ||
892 | found = FALSE; | ||
893 | |||
894 | while ((ch = *pattern++) != ']') | ||
895 | { | ||
896 | if (ch == '\\') | ||
897 | ch = *pattern++; | ||
898 | |||
899 | if (ch == '\0') | ||
900 | return FALSE; | ||
901 | |||
902 | if (*text == ch) | ||
903 | found = TRUE; | ||
904 | } | ||
905 | |||
906 | //if (!found) | ||
907 | if (found==TRUE) | ||
908 | { | ||
909 | pattern = retryPat; | ||
910 | text = ++retryText; | ||
911 | } | ||
912 | |||
913 | /* fall into next case */ | ||
914 | |||
915 | case '?': | ||
916 | if (*text++ == '\0') | ||
917 | return FALSE; | ||
918 | |||
919 | break; | ||
920 | |||
921 | case '\\': | ||
922 | ch = *pattern++; | ||
923 | |||
924 | if (ch == '\0') | ||
925 | return FALSE; | ||
926 | |||
927 | /* fall into next case */ | ||
928 | |||
929 | default: | ||
930 | if (*text == ch) | ||
931 | { | ||
932 | if (*text) | ||
933 | text++; | ||
934 | break; | ||
935 | } | ||
936 | |||
937 | if (*text) | ||
938 | { | ||
939 | pattern = retryPat; | ||
940 | text = ++retryText; | ||
941 | break; | ||
942 | } | ||
943 | |||
944 | return FALSE; | ||
945 | } | ||
946 | |||
947 | if (pattern == NULL) | ||
948 | return FALSE; | ||
949 | } | ||
950 | |||
951 | return TRUE; | ||
952 | } | ||
953 | #endif | ||
954 | |||
955 | |||
854 | 956 | ||
855 | 957 | ||
856 | #if defined BB_DF | defined BB_MTAB | 958 | #if defined BB_DF | defined BB_MTAB |
@@ -910,3 +1012,10 @@ extern void whine_if_fstab_is_missing() | |||
910 | /* END CODE */ | 1012 | /* END CODE */ |
911 | 1013 | ||
912 | 1014 | ||
1015 | |||
1016 | |||
1017 | |||
1018 | |||
1019 | |||
1020 | |||
1021 | |||