rm dead code - osm-zipcodes - Extract (dutch) addresses from OpenStreetMap OSM XML (HTM) git clone git://git.codemadness.org/osm-zipcodes (DIR) Log (DIR) Files (DIR) Refs (DIR) README (DIR) LICENSE --- (DIR) commit 4d3837466406b228a2c8f6ff9d594ee0a4d507cc (DIR) parent 37ce7f33c3d58a60c9f03f6f5f4ce10eec1c7737 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org> Date: Thu, 11 Apr 2019 18:23:47 +0200 rm dead code Diffstat: M main.c | 147 +++++-------------------------- 1 file changed, 22 insertions(+), 125 deletions(-) --- (DIR) diff --git a/main.c b/main.c @@ -15,30 +15,6 @@ #include <unistd.h> typedef struct xmlparser { - /* handlers */ - void (*xmlattr)(struct xmlparser *, const char *, size_t, - const char *, size_t, const char *, size_t); - void (*xmlattrend)(struct xmlparser *, const char *, size_t, - const char *, size_t); - void (*xmlattrstart)(struct xmlparser *, const char *, size_t, - const char *, size_t); - void (*xmlattrentity)(struct xmlparser *, const char *, size_t, - const char *, size_t, const char *, size_t); - void (*xmlcdatastart)(struct xmlparser *); - void (*xmlcdata)(struct xmlparser *, const char *, size_t); - void (*xmlcdataend)(struct xmlparser *); - void (*xmlcommentstart)(struct xmlparser *); - void (*xmlcomment)(struct xmlparser *, const char *, size_t); - void (*xmlcommentend)(struct xmlparser *); - void (*xmldata)(struct xmlparser *, const char *, size_t); - void (*xmldataend)(struct xmlparser *); - void (*xmldataentity)(struct xmlparser *, const char *, size_t); - void (*xmldatastart)(struct xmlparser *); - void (*xmltagend)(struct xmlparser *, const char *, size_t, int); - void (*xmltagstart)(struct xmlparser *, const char *, size_t); - void (*xmltagstartparsed)(struct xmlparser *, const char *, - size_t, int); - /* current tag */ char tag[1024]; size_t taglen; @@ -72,12 +48,14 @@ struct node_tag { char value[256]; }; -void xmltagstart(XMLParser *x, const char *t, size_t tl); -void xmlattr(XMLParser *x, const char *t, size_t tl, const char *a, size_t al, +void xmltagstart(const char *t, size_t tl); +void xmlattr(const char *t, size_t tl, const char *a, size_t al, const char *v, size_t vl); -void xmlattrentity(XMLParser *x, const char *t, size_t tl, const char *a, +void xmlattrentity(const char *t, size_t tl, const char *a, size_t al, const char *v, size_t vl); -void xmltagend(XMLParser *x, const char *t, size_t tl, int isshort); +void xmltagend(const char *t, size_t tl, int isshort); + +static XMLParser x; static struct node_address na; static struct node_tag nt; @@ -111,20 +89,12 @@ xml_parseattrs(XMLParser *x) } else if (namelen && ((endname && !valuestart && isalpha(c)) || (c == '>' || c == '/'))) { /* attribute without value */ x->name[namelen] = '\0'; - if (x->xmlattrstart) - x->xmlattrstart(x, x->tag, x->taglen, x->name, namelen); - if (x->xmlattr) - x->xmlattr(x, x->tag, x->taglen, x->name, namelen, "", 0); - if (x->xmlattrend) - x->xmlattrend(x, x->tag, x->taglen, x->name, namelen); + xmlattr(x->tag, x->taglen, x->name, namelen, "", 0); endname = 0; x->name[0] = c; namelen = 1; } else if (namelen && valuestart) { /* attribute with value */ - if (x->xmlattrstart) - x->xmlattrstart(x, x->tag, x->taglen, x->name, namelen); - valuelen = 0; if (c == '\'' || c == '"') { endsep = c; @@ -138,8 +108,8 @@ startvalue: if (c == '&') { /* entities */ x->data[valuelen] = '\0'; /* call data function with data before entity if there is data */ - if (valuelen && x->xmlattr) - x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); + if (valuelen) + xmlattr(x->tag, x->taglen, x->name, namelen, x->data, valuelen); x->data[0] = c; valuelen = 1; while ((c = GETNEXT()) != EOF) { @@ -150,16 +120,14 @@ startvalue: else { /* entity too long for buffer, handle as normal data */ x->data[valuelen] = '\0'; - if (x->xmlattr) - x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); + xmlattr(x->tag, x->taglen, x->name, namelen, x->data, valuelen); x->data[0] = c; valuelen = 1; break; } if (c == ';') { x->data[valuelen] = '\0'; - if (x->xmlattrentity) - x->xmlattrentity(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); + xmlattrentity(x->tag, x->taglen, x->name, namelen, x->data, valuelen); valuelen = 0; break; } @@ -169,18 +137,14 @@ startvalue: x->data[valuelen++] = c; } else { x->data[valuelen] = '\0'; - if (x->xmlattr) - x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); + xmlattr(x->tag, x->taglen, x->name, namelen, x->data, valuelen); x->data[0] = c; valuelen = 1; } } if (c == endsep) { x->data[valuelen] = '\0'; - if (x->xmlattr) - x->xmlattr(x, x->tag, x->taglen, x->name, namelen, x->data, valuelen); - if (x->xmlattrend) - x->xmlattrend(x, x->tag, x->taglen, x->name, namelen); + xmlattr(x->tag, x->taglen, x->name, namelen, x->data, valuelen); break; } } @@ -204,34 +168,15 @@ xml_parsecomment(XMLParser *x) size_t datalen = 0, i = 0; int c; - if (x->xmlcommentstart) - x->xmlcommentstart(x); while ((c = GETNEXT()) != EOF) { - if (c == '-' || c == '>') { - if (x->xmlcomment) { - x->data[datalen] = '\0'; - x->xmlcomment(x, x->data, datalen); - datalen = 0; - } - } - if (c == '-') { if (++i > 2) { - if (x->xmlcomment) - for (; i > 2; i--) - x->xmlcomment(x, "-", 1); i = 2; } continue; } else if (c == '>' && i == 2) { - if (x->xmlcommentend) - x->xmlcommentend(x); return; } else if (i) { - if (x->xmlcomment) { - for (; i > 0; i--) - x->xmlcomment(x, "-", 1); - } i = 0; } @@ -239,8 +184,6 @@ xml_parsecomment(XMLParser *x) x->data[datalen++] = c; } else { x->data[datalen] = '\0'; - if (x->xmlcomment) - x->xmlcomment(x, x->data, datalen); x->data[0] = c; datalen = 1; } @@ -253,33 +196,15 @@ xml_parsecdata(XMLParser *x) size_t datalen = 0, i = 0; int c; - if (x->xmlcdatastart) - x->xmlcdatastart(x); while ((c = GETNEXT()) != EOF) { - if (c == ']' || c == '>') { - if (x->xmlcdata) { - x->data[datalen] = '\0'; - x->xmlcdata(x, x->data, datalen); - datalen = 0; - } - } - if (c == ']') { if (++i > 2) { - if (x->xmlcdata) - for (; i > 2; i--) - x->xmlcdata(x, "]", 1); i = 2; } continue; } else if (c == '>' && i == 2) { - if (x->xmlcdataend) - x->xmlcdataend(x); return; } else if (i) { - if (x->xmlcdata) - for (; i > 0; i--) - x->xmlcdata(x, "]", 1); i = 0; } @@ -287,8 +212,6 @@ xml_parsecdata(XMLParser *x) x->data[datalen++] = c; } else { x->data[datalen] = '\0'; - if (x->xmlcdata) - x->xmlcdata(x, x->data, datalen); x->data[0] = c; datalen = 1; } @@ -455,23 +378,18 @@ xml_parse(XMLParser *x) else if (c == '>' || isspace(c)) { x->tag[x->taglen] = '\0'; if (isend) { /* end tag, starts with </ */ - if (x->xmltagend) - x->xmltagend(x, x->tag, x->taglen, x->isshorttag); + xmltagend(x->tag, x->taglen, x->isshorttag); x->tag[0] = '\0'; x->taglen = 0; } else { /* start tag */ - if (x->xmltagstart) - x->xmltagstart(x, x->tag, x->taglen); + xmltagstart(x->tag, x->taglen); if (isspace(c)) xml_parseattrs(x); - if (x->xmltagstartparsed) - x->xmltagstartparsed(x, x->tag, x->taglen, x->isshorttag); } /* call tagend for shortform or processing instruction */ if (x->isshorttag) { - if (x->xmltagend) - x->xmltagend(x, x->tag, x->taglen, x->isshorttag); + xmltagend(x->tag, x->taglen, x->isshorttag); x->tag[0] = '\0'; x->taglen = 0; } @@ -483,14 +401,10 @@ xml_parse(XMLParser *x) } else { /* parse tag data */ datalen = 0; - if (x->xmldatastart) - x->xmldatastart(x); while ((c = GETNEXT()) != EOF) { if (c == '&') { if (datalen) { x->data[datalen] = '\0'; - if (x->xmldata) - x->xmldata(x, x->data, datalen); } x->data[0] = c; datalen = 1; @@ -502,16 +416,12 @@ xml_parse(XMLParser *x) else { /* entity too long for buffer, handle as normal data */ x->data[datalen] = '\0'; - if (x->xmldata) - x->xmldata(x, x->data, datalen); x->data[0] = c; datalen = 1; break; } if (c == ';') { x->data[datalen] = '\0'; - if (x->xmldataentity) - x->xmldataentity(x, x->data, datalen); datalen = 0; break; } @@ -521,18 +431,12 @@ xml_parse(XMLParser *x) x->data[datalen++] = c; } else { x->data[datalen] = '\0'; - if (x->xmldata) - x->xmldata(x, x->data, datalen); x->data[0] = c; datalen = 1; } } if (c == '<') { x->data[datalen] = '\0'; - if (x->xmldata && datalen) - x->xmldata(x, x->data, datalen); - if (x->xmldataend) - x->xmldataend(x); break; } } @@ -599,7 +503,7 @@ printaddress(void) } void -xmltagstart(XMLParser *x, const char *t, size_t tl) +xmltagstart(const char *t, size_t tl) { if (tl == 4 && t[0] == 'n' && t[1] == 'o' && t[2] == 'd' && t[3] == 'e') { isnode = 1; @@ -615,7 +519,7 @@ xmltagstart(XMLParser *x, const char *t, size_t tl) } void -xmltagend(XMLParser *x, const char *t, size_t tl, int isshort) +xmltagend(const char *t, size_t tl, int isshort) { static size_t nodecount; @@ -662,7 +566,7 @@ xmltagend(XMLParser *x, const char *t, size_t tl, int isshort) } void -xmlattr(XMLParser *x, const char *t, size_t tl, +xmlattr(const char *t, size_t tl, const char *a, size_t al, const char *v, size_t vl) { if (isnode && !istag) { @@ -704,7 +608,7 @@ xmlattr(XMLParser *x, const char *t, size_t tl, } void -xmlattrentity(XMLParser *x, const char *t, size_t tl, +xmlattrentity(const char *t, size_t tl, const char *a, size_t al, const char *v, size_t vl) { char buf[16]; @@ -714,26 +618,19 @@ xmlattrentity(XMLParser *x, const char *t, size_t tl, return; if ((len = xml_entitytostr(v, buf, sizeof(buf))) < 0) - xmlattr(x, t, tl, a, al, v, vl); + xmlattr(t, tl, a, al, v, vl); else - xmlattr(x, t, tl, a, al, buf, len); + xmlattr(t, tl, a, al, buf, len); } int main(int argc, char *argv[]) { - XMLParser x = { 0 }; - if (argc < 2) { fprintf(stderr, "usage: %s <file>\n", argv[0]); return 1; } - x.xmltagstart = xmltagstart; - x.xmlattr = xmlattr; - x.xmlattrentity = xmlattrentity; - x.xmltagend = xmltagend; - if ((fd = open(argv[1], O_RDONLY)) < 0) err(1, "open"); if (fstat(fd, &st) < 0)