[Initng-svn] r4050 - initng/trunk/src
svn at initng.thinktux.net
svn at initng.thinktux.net
Mon May 8 08:00:45 CEST 2006
Author: jimmy
Date: Mon May 8 08:00:44 2006
New Revision: 4050
Modified:
initng/trunk/src/initng_string_tools.c
initng/trunk/src/initng_string_tools.h
Log:
Add match_in_service(const char * pattern, const char * name);
Modified: initng/trunk/src/initng_string_tools.c
==============================================================================
--- initng/trunk/src/initng_string_tools.c (original)
+++ initng/trunk/src/initng_string_tools.c Mon May 8 08:00:44 2006
@@ -320,6 +320,52 @@
return (stringslash==patternslash);
}
+
+/*
+ * This match is simply dont that we take pattern, removes any leading
+ * '*' or '?', and to a strstr on that string.
+ */
+int match_in_service(const char * string, const char * pattern)
+{
+ char * copy;
+ char * tmp;
+ assert(string);
+ assert(pattern);
+
+ /* if the string contains a '/' it is looking for an exact match, so no searching here */
+ if(strchr(pattern, '/'))
+ return(FALSE);
+
+ /* remove starting wildcards */
+ while (pattern[0] == '*' || pattern[0] == '?')
+ pattern++;
+
+ /* check if it matches */
+ if(strstr(string, pattern))
+ return(TRUE);
+
+ /* if pattern wont have a '*' or '?' there is no ida to continue */
+ if(!strchr(pattern, '*') && !strchr(pattern, '?'))
+ return(FALSE);
+
+ /* now copy pattern, and remove ending '*' && '?' */
+ copy = i_strdup(pattern);
+ assert(copy);
+
+ /* Trunk for any '*' or '?' found */
+ while((tmp=strrchr(copy, '*')) || (tmp=strrchr(copy, '?')))
+ tmp[0]='\0';
+
+ /* check again */
+ tmp=strstr(string, copy);
+
+ /* cleanup */
+ free(copy);
+
+ /* if tmp was set return TRUE */
+ return(tmp!=NULL);
+}
+
/*
* mprintf, a sprintf clone that automaticly mallocs the string
* and new content to same string applys after that content.
Modified: initng/trunk/src/initng_string_tools.h
==============================================================================
--- initng/trunk/src/initng_string_tools.h (original)
+++ initng/trunk/src/initng_string_tools.h Mon May 8 08:00:44 2006
@@ -77,6 +77,7 @@
/* pattern searching */
int service_match(const char *string, const char *pattern);
+int match_in_service(const char *string, const char *pattern);
/*
* mprintf, a sprintf clone that automaticly mallocs the string
More information about the Initng-svn
mailing list