xml.c: sync some of the improvements to this modified version - grabtitle - stupid HTML title grabber
 (HTM) git clone git://git.codemadness.org/grabtitle
 (DIR) Log
 (DIR) Files
 (DIR) Refs
 (DIR) README
 (DIR) LICENSE
       ---
 (DIR) commit e0263471557e79c3a178e6da41b5f7e2f4234625
 (DIR) parent 29e4807c53d136de19f775b7d08b3c1c3a14d76d
 (HTM) Author: Hiltjo Posthuma <hiltjo@codemadness.org>
       Date:   Sun, 30 Jun 2024 10:19:01 +0200
       
       xml.c: sync some of the improvements to this modified version
       
       Diffstat:
         M xml.c                               |      20 +++++++++++---------
         M xml.h                               |       8 ++++----
       
       2 files changed, 15 insertions(+), 13 deletions(-)
       ---
 (DIR) diff --git a/xml.c b/xml.c
       @@ -1,4 +1,3 @@
       -#include <ctype.h>
        #include <errno.h>
        #include <stdio.h>
        #include <stdlib.h>
       @@ -6,6 +5,9 @@
        
        #include "xml.h"
        
       +#define ISALPHA(c) ((((unsigned)c) | 32) - 'a' < 26)
       +#define ISSPACE(c) ((c) == ' ' || ((((unsigned)c) - '\t') < 5))
       +
        static void
        xml_parseattrs(XMLParser *x)
        {
       @@ -13,7 +15,7 @@ xml_parseattrs(XMLParser *x)
                int c, endsep, endname = 0, valuestart = 0;
        
                while ((c = GETNEXT()) != EOF) {
       -                if (isspace(c)) {
       +                if (ISSPACE(c)) {
                                if (namelen)
                                        endname = 1;
                                continue;
       @@ -22,7 +24,7 @@ xml_parseattrs(XMLParser *x)
                        else if (c == '=') {
                                valuestart = 1;
                                endname = 1;
       -                } else if (namelen && ((endname && !valuestart && isalpha(c)) || (c == '>' || c == '/'))) {
       +                } else if (namelen && ((endname && !valuestart && ISALPHA(c)) || (c == '>' || c == '/'))) {
                                endname = 0;
                                namelen = 1;
                        } else if (namelen && valuestart) {
       @@ -35,7 +37,7 @@ xml_parseattrs(XMLParser *x)
                                        }
                                } else {
                                        while ((c = GETNEXT()) != EOF) {
       -                                        if (c == '>' || isspace(c))
       +                                        if (c == '>' || ISSPACE(c))
                                                        break;
                                        }
                                }
       @@ -238,7 +240,7 @@ xml_parse(XMLParser *x)
                                if ((c = GETNEXT()) == EOF)
                                        return;
        
       -                        if (c == '!') { /* cdata and comments */
       +                        if (c == '!') { /* CDATA and comments */
                                        for (tagdatalen = 0; (c = GETNEXT()) != EOF;) {
                                                /* NOTE: sizeof(x->data) must be at least sizeof("[CDATA[") */
                                                if (tagdatalen <= sizeof("[CDATA[") - 1)
       @@ -263,7 +265,7 @@ xml_parse(XMLParser *x)
                                        x->taglen = 1;
                                        x->isshorttag = isend = 0;
        
       -                                /* treat processing instruction as shorttag, don't strip "?" prefix. */
       +                                /* treat processing instruction as short tag, don't strip "?" prefix. */
                                        if (c == '?') {
                                                x->isshorttag = 1;
                                        } else if (c == '/') {
       @@ -276,7 +278,7 @@ xml_parse(XMLParser *x)
                                        while ((c = GETNEXT()) != EOF) {
                                                if (c == '/')
                                                        x->isshorttag = 1; /* short tag */
       -                                        else if (c == '>' || isspace(c)) {
       +                                        else if (c == '>' || ISSPACE(c)) {
                                                        x->tag[x->taglen] = '\0';
                                                        if (isend) { /* end tag, starts with </ */
                                                                while (c != '>' && c != EOF) /* skip until > */
       @@ -289,10 +291,10 @@ xml_parse(XMLParser *x)
                                                                /* start tag */
                                                                if (x->xmltagstart)
                                                                        x->xmltagstart(x, x->tag, x->taglen);
       -                                                        if (isspace(c))
       +                                                        if (ISSPACE(c))
                                                                        xml_parseattrs(x);
                                                        }
       -                                                /* call tagend for shortform or processing instruction */
       +                                                /* call tagend for short tag or processing instruction */
                                                        if (x->isshorttag) {
                                                                if (x->xmltagend)
                                                                        x->xmltagend(x, x->tag, x->taglen, x->isshorttag);
 (DIR) diff --git a/xml.h b/xml.h
       @@ -1,5 +1,5 @@
       -#ifndef _XML_H_
       -#define _XML_H_
       +#ifndef XML_H
       +#define XML_H
        
        #include <stdio.h>
        
       @@ -17,9 +17,9 @@ typedef struct xmlparser {
                /* current tag */
                char tag[1024];
                size_t taglen;
       -        /* current tag is in short form ? <tag /> */
       +        /* current tag is a short tag ? <tag /> */
                int isshorttag;
       -        /* data buffer used for tag data, cdata and attribute data */
       +        /* data buffer used for tag data, CDATA and attribute data */
                char data[BUFSIZ];
        } XMLParser;