/[vps]/baselayout-vserver/trunk/src/core/librcscripts/simple-regex.h
Gentoo

Contents of /baselayout-vserver/trunk/src/core/librcscripts/simple-regex.h

Parent Directory Parent Directory | Revision Log Revision Log


Revision 127 - (show annotations) (download) (as text)
Fri Dec 2 10:56:06 2005 UTC (12 years, 8 months ago) by phreak
File MIME type: text/x-chdr
File size: 2976 byte(s)
Import the latest baselayout changes. Merging revision 1658.
1 /*
2 * simple_regex.h
3 *
4 * Simle regex library.
5 *
6 * Copyright (C) 2004,2005 Martin Schlemmer <azarah@nosferatu.za.org>
7 *
8 *
9 * This program is free software; you can redistribute it and/or modify it
10 * under the terms of the GNU General Public License as published by the
11 * Free Software Foundation version 2 of the License.
12 *
13 * This program is distributed in the hope that it will be useful, but
14 * WITHOUT ANY WARRANTY; without even the implied warranty of
15 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16 * General Public License for more details.
17 *
18 * You should have received a copy of the GNU General Public License along
19 * with this program; if not, write to the Free Software Foundation, Inc.,
20 * 675 Mass Ave, Cambridge, MA 02139, USA.
21 *
22 * $Header$
23 */
24
25 #ifndef _SIMPLE_REGEX_H
26 #define _SIMPLE_REGEX_H
27
28 #define REGEX_NO_MATCH 0 /* We have no match */
29 #define REGEX_PARTIAL_MATCH 1 /* Some of the string matches the regex */
30 #define REGEX_FULL_MATCH 2 /* The whole string matches the regex */
31
32 /* Macro to fill in .data and .regex */
33 #define FILL_REGEX_DATA(_regex_data, _string, _regex) \
34 do { \
35 _regex_data.data = _string; \
36 _regex_data.regex = _regex; \
37 } while (0)
38
39 /* Fill in _regex_data with _data and _regex, on failure goto _error */
40 #define DO_REGEX(_regex_data, _data, _regex, _error) \
41 do { \
42 FILL_REGEX_DATA(_regex_data, _data, _regex); \
43 if (-1 == match(&_regex_data)) { \
44 DBG_MSG("Could not do regex match!\n"); \
45 goto _error; \
46 } \
47 } while (0)
48
49 /* Evaluate to true if we have some kind of match */
50 #define REGEX_MATCH(_regex_data) \
51 ((REGEX_FULL_MATCH == _regex_data.match) \
52 || (REGEX_PARTIAL_MATCH == _regex_data.match))
53
54 /* Same as above, but for use when _regex_data is a pointer */
55 #define REGEX_MATCH_P(_regex_data) \
56 ((REGEX_FULL_MATCH == _regex_data->match) \
57 || (REGEX_PARTIAL_MATCH == _regex_data->match))
58
59 typedef struct {
60 char *data; /* String to perform regex operation on */
61 char *regex; /* String containing regex to use */
62 int match; /* Will be set if there was a match. Check
63 * REGEX_*_MATCH above for possible values */
64 char *where; /* Pointer to where match starts in data */
65 size_t count; /* Count characters from data matched by regex */
66 size_t r_count; /* Count characters of regex used for match. This
67 * should normally be the lenght of regex, but might
68 * not be for some internal functions ... */
69 } regex_data_t;
70
71 /*
72 * Return:
73 *
74 * 0 - There was no error. If there was a match, regex_data->match
75 * - will be > 0 (this is the definitive check - if not true, the
76 * - other values of the struct may be bogus), regex_data->count
77 * - will be the amount of data that was matched (might be 0 for
78 * - some wildcards), and regex_data->r_count will be > 0.
79 *
80 * -1 - An error occured. Check errno for more info.
81 *
82 */
83 int match(regex_data_t *regex_data);
84
85 #endif /* _SIMPLE_REGEX_H */
86

  ViewVC Help
Powered by ViewVC 1.1.20