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); \
|
||||
|
|
17
core/parse.c
17
core/parse.c
|
@ -114,23 +114,6 @@ void nonmatch(const char *type, const char *name, char *buffer)
|
|||
type, name, buffer);
|
||||
}
|
||||
|
||||
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;
|
||||
}
|
||||
|
||||
void event_start(void)
|
||||
{
|
||||
memset(&cur_event, 0, sizeof(cur_event));
|
||||
|
|
|
@ -61,8 +61,6 @@ int trimspace(char *buffer);
|
|||
void clear_table(struct dive_table *table);
|
||||
void start_match(const char *type, const char *name, char *buffer);
|
||||
void nonmatch(const char *type, const char *name, char *buffer);
|
||||
typedef void (*matchfn_t)(char *buffer, void *);
|
||||
int match(const char *pattern, int plen, const char *name, matchfn_t fn, char *buf, void *data);
|
||||
void event_start(void);
|
||||
void event_end(void);
|
||||
struct divecomputer *get_dc(void);
|
||||
|
|
Loading…
Add table
Reference in a new issue