| 1 |
/* dctrl-tools - Debian control file inspection tools |
| 2 |
Copyright © 2011 Antti-Juhani Kaijanaho |
| 3 |
|
| 4 |
This program is free software; you can redistribute it and/or modify |
| 5 |
it under the terms of the GNU General Public License as published by |
| 6 |
the Free Software Foundation; either version 2 of the License, or |
| 7 |
(at your option) any later version. |
| 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 along |
| 15 |
with this program; if not, write to the Free Software Foundation, Inc., |
| 16 |
51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
| 17 |
*/ |
| 18 |
|
| 19 |
#ifndef GUARD_LIB_ATOM_H |
| 20 |
#define GUARD_LIB_ATOM_H |
| 21 |
|
| 22 |
#include <regex.h> |
| 23 |
#include "paragraph.h" |
| 24 |
#include "util.h" |
| 25 |
|
| 26 |
/* An atomic predicate. */ |
| 27 |
struct atom { |
| 28 |
/* The name of field to which matching is limited. Empty |
| 29 |
* field_name specifies the whole paragraph (in which case |
| 30 |
* field_inx is -1. */ |
| 31 |
char const * field_name; size_t field_inx; |
| 32 |
/* The index to the field whose value is to be used when this |
| 33 |
* field is empty. */ |
| 34 |
size_t repl_inx; |
| 35 |
/* Matching mode */ |
| 36 |
enum matching_mode { |
| 37 |
M_SUBSTR, /* substring matching */ |
| 38 |
M_REGEX, /* POSIX regular expression match */ |
| 39 |
M_EREGEX, /* POSIX extended regular expression matching */ |
| 40 |
M_EXACT, /* exact string match */ |
| 41 |
#define M_FIRST_VERSION M_VER_EQ |
| 42 |
M_VER_EQ, /* numeric equality comparison */ |
| 43 |
M_VER_LT, /* numeric < */ |
| 44 |
M_VER_LE, /* numeric <= */ |
| 45 |
M_VER_GT, /* numeric > */ |
| 46 |
M_VER_GE, /* numeric >= */ |
| 47 |
#define M_LAST_VERSION M_VER_GE |
| 48 |
} mode; |
| 49 |
/* Flag: should matching ignore case */ |
| 50 |
unsigned ignore_case; |
| 51 |
/* The pattern as given on the command line; interpretation |
| 52 |
* depends on matching mode. Must be null-terminated and |
| 53 |
* patlen must equal strlen(pat). */ |
| 54 |
char const * pat; size_t patlen; |
| 55 |
/* A compiled version of pat; valid only when mode is M_REGEX |
| 56 |
* or M_EREGEX. */ |
| 57 |
regex_t regex; |
| 58 |
/* Flag: (extended) regex should match whole package names */ |
| 59 |
unsigned whole_pkg; |
| 60 |
}; |
| 61 |
|
| 62 |
void atom_finish(struct atom * atom); |
| 63 |
bool atom_verify(struct atom * atom, para_t * para); |
| 64 |
|
| 65 |
#endif /* GUARD_LIB_ATOM_H */ |