mirror of
https://github.com/subsurface/subsurface.git
synced 2025-02-19 22:16:15 +00:00
Parser: move match() into core/parse-xml.c
The match() function compares a pattern with a name with a twist: The name may either end in '\0' or '.'. If pattern and name match, a parsing function is called on a buffer and a destination value. The result of the parsing is not checked. This seems awfully XML-specific and therefore move the function from the general parse.c to the specialized parse-xml.c unit and make it of local linkage. Signed-off-by: Berthold Stoeger <bstoeger@mail.tuwien.ac.at>
This commit is contained in:
parent
1515b9496b
commit
2de8e70ab0
3 changed files with 18 additions and 19 deletions
|
@ -468,6 +468,24 @@ static void event_divemode(char *buffer, int *value)
|
|||
}
|
||||
}
|
||||
|
||||
typedef void (*matchfn_t)(char *buffer, void *);
|
||||
static int match(const char *pattern, int plen,
|
||||
const char *name,
|
||||
matchfn_t fn, char *buf, void *data)
|
||||
{
|
||||
switch (name[plen]) {
|
||||
case '\0':
|
||||
case '.':
|
||||
break;
|
||||
default:
|
||||
return 0;
|
||||
}
|
||||
if (memcmp(pattern, name, plen))
|
||||
return 0;
|
||||
fn(buf, data);
|
||||
return 1;
|
||||
}
|
||||
|
||||
#define MATCH(pattern, fn, dest) ({ \
|
||||
/* Silly type compatibility test */ \
|
||||
if (0) (fn)("test", dest); \
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue