/
match.c
94 lines (74 loc) · 2.3 KB
/
match.c
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
/*****************************************************************************
*
* Usepackage Environment Manager
* Copyright (C) 1995-2020 Jonathan Hogg <me@jonathanhogg.com>
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
*
* Name : match.c
* Author : Jonathan Hogg <me@jonathanhogg.com>
*
****************************************************************************/
/* match.c */
/*** uses: ***/
#include "linked_list.h"
#include "package.h"
#include <string.h>
/*** prototypes: ***/
int text_matches(char* text, linked_list* matches);
/*** globals: ***/
/*** functions: ***/
int package_matches(package_t* package, char* name, char* arch,
char* os, char* version, char* host, char* shell)
{
if (!text_matches(name, package->name))
return(0);
if (!text_matches(arch, package->arch))
return(0);
if (!text_matches(os, package->os))
return(0);
if (!text_matches(version, package->version))
return(0);
if (!text_matches(host, package->host))
return(0);
if (!text_matches(shell, package->shell))
return(0);
return(1);
}
int text_matches(char* text, linked_list* matches)
{
list_node* node;
match_t* match;
if ( !matches )
return(1);
for (node = head(matches) ; node ; node = next(node))
{
match = (match_t*) get_value(node);
switch (match->type)
{
case MATCH_WILD:
return(1);
case MATCH_PREFIX:
if (!strncasecmp(text, match->text, strlen(match->text)))
return(1);
break;
case MATCH_EXACT:
if (!strcasecmp(text, match->text))
return(1);
break;
}
}
return(0);
}