3 * Quick-and-dirty parser
5 * (c) 2004 Straylight/Edgeware
8 /*----- Licensing notice --------------------------------------------------*
10 * This file is part of Catacomb.
12 * Catacomb is free software; you can redistribute it and/or modify
13 * it under the terms of the GNU Library General Public License as
14 * published by the Free Software Foundation; either version 2 of the
15 * License, or (at your option) any later version.
17 * Catacomb is distributed in the hope that it will be useful,
18 * but WITHOUT ANY WARRANTY; without even the implied warranty of
19 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
20 * GNU Library General Public License for more details.
22 * You should have received a copy of the GNU Library General Public
23 * License along with Catacomb; if not, write to the Free
24 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
28 /*----- Header files ------------------------------------------------------*/
35 /*----- Main code ---------------------------------------------------------*/
37 /* --- @qd_skipspc@ --- *
39 * Arguments: @qd_parse *qd@ = context
43 * Use: Skips spaces in the string. No errors.
46 void qd_skipspc(qd_parse *qd)
48 while (isspace((unsigned char)*qd->p))
52 /* --- @qd_delim@ --- *
54 * Arguments: @qd_parse *qd@ = context
55 * @int ch@ = character to compare with
57 * Returns: Nonzero if it was, zero if it wasn't.
59 * Use: Checks the next (non-whitespace) character is what we
60 * expect. If it is, the character is eaten; otherwise it's no
64 int qd_delim(qd_parse *qd, int ch)
73 /* --- @qd_enum@ --- *
75 * Arguments: @qd_parse *qd@ = context
76 * @const char *e@ = list of enum strings, space separated
78 * Returns: Index of the string matched, or @-1@.
80 * Use: Matches a keyword.
83 int qd_enum(qd_parse *qd, const char *e)
93 if (strncmp(qd->p, e, n) == 0 && !isalnum((unsigned char)qd->p[n])) {
99 qd->e = "unrecognized keyword";
103 /* --- @qd_getmp@ --- *
105 * Arguments: @qd_parse *qd@ = context
107 * Returns: The integer extracted, or null.
109 * Use: Parses a multiprecision integer from a string.
112 mp *qd_getmp(qd_parse *qd)
118 m = mp_readstring(MP_NEW, qd->p, &q, 0);
119 if (m && !isalnum((unsigned char)*q))
123 qd->e = "bad number";
128 /* --- @qd_eofp@ --- *
130 * Arguments: @qd_parse *qd@ = context
132 * Returns: Nonzero if at EOF, zero otherwise.
135 int qd_eofp(qd_parse *qd)
141 /*----- That's all, folks -------------------------------------------------*/