OpenVAS Libraries  9.0.3
strutils.c
Go to the documentation of this file.
1 /* Nessus Attack Scripting Language
2  *
3  * Copyright (C) 2002 - 2004 Tenable Network Security
4  *
5  * This program is free software; you can redistribute it and/or modify
6  * it under the terms of the GNU General Public License version 2,
7  * as published by the Free Software Foundation
8  *
9  * This program is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12  * GNU General Public License for more details.
13  *
14  * You should have received a copy of the GNU General Public License
15  * along with this program; if not, write to the Free Software
16  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
17  *
18  */
19 
20 #include <ctype.h> /* for tolower */
21 
28 int
29 str_match (const char *string, const char *pattern, int icase)
30 {
31  while (*pattern != '\0')
32  {
33  if (*pattern == '?')
34  {
35  if (*string == '\0')
36  return 0;
37  }
38  else if (*pattern == '*')
39  {
40  const char *p = string;
41  do
42  if (str_match (p, pattern + 1, icase))
43  return 1;
44  while (*p++ != '\0');
45  return 0;
46  }
47  else if ((icase && (tolower (*pattern) != tolower (*string)))
48  || (!icase && (*pattern != *string)))
49  return 0;
50  pattern++;
51  string++;
52  }
53  return *string == '\0';
54 }
int str_match(const char *string, const char *pattern, int icase)
Definition: strutils.c:29
gchar * string