-
Notifications
You must be signed in to change notification settings - Fork 2
/
line_tokens_match.h
98 lines (94 loc) · 3.28 KB
/
line_tokens_match.h
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
94
95
96
97
98
/*
* Copyright © 2021 - 2023 Eero Häkkinen <Eero+pam-ssh-auth-info@Häkkinen.fi>
*
* This program is free software: you can redistribute it and/or modify
* it under the terms of the GNU Lesser General Public License as
* published by the Free Software Foundation, either version 3 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 Lesser General Public License for more details.
*
* You should have received a copy of the GNU Lesser General Public
* License along with this program. If not, see
* <http://www.gnu.org/licenses/>.
*/
#include <stdbool.h>
#include <string.h>
#include "tokens_match.h"
/* Check if the tokens on the line match the pattern.
*
* Any character byte that appears in a pattern, other than the extended
* patterns and the special pattern characters described below, matches
* itself.
*
* The special pattern characters:
*
* * Matches any number of (including zero) token character bytes but not
* a token separator (space).
* = Matches equal-sign (=) or a token separator (space).
* ? Matches any token character byte but not a token separator (space).
* [ A pair of brackets introduces a character byte class.
* A character byte class ([...]) matches any token character byte in
* the class. A complemented character byte class ([!...]) matches any
* token character byte not in the class. Neither matches a token separator
* (space). A class may contain character bytes ([abcde]) and character
* byte ranges ([a-e]).
* \ Preserves the literal meaning of the following character byte.
*
* The extended patterns:
*
* ?(pattern|pattern|...) Matches zero or one occurence of the given
* patterns.
* Does not match a token separator (space).
* *(pattern|pattern|...) Matches zero or more occurences of the given
* patterns.
* Does not match a token separator (space).
* +(pattern|pattern|...) Matches one or more occurences of the given
* patterns.
* Does not match a token separator (space).
* @(pattern|pattern|...) Matches one of the given patterns.
* Does not match a token separator (space).
* !(pattern|pattern|...) Matches anything except one of the given
* patterns or a token separator (space).
*/
static bool
line_tokens_match(
char const *line,
char const *const line_end,
char const *pattern,
char const *const pattern_end,
bool const allow_prefix_match,
unsigned const recursion_limit
) {
struct tokens_match_config const config = {
allow_prefix_match,
{{1, "="}, {1, " "}}
};
return tokens_match(
&config,
line,
line_end,
pattern,
pattern_end,
recursion_limit
);
}
static bool
first_line_tokens_match(
char const *const lines,
char const *const pattern,
bool const allow_prefix_match,
unsigned const recursion_limit
) {
return line_tokens_match(
lines,
lines + strcspn(lines, "\n"),
pattern,
pattern + strlen(pattern),
allow_prefix_match,
recursion_limit
);
}