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 ------------------------------------------------------*/
33 #include <mLib/macros.h>
37 /*----- Main code ---------------------------------------------------------*/
39 /* --- @qd_skipspc@ --- *
41 * Arguments: @qd_parse *qd@ = context
45 * Use: Skips spaces in the string. No errors.
48 void qd_skipspc(qd_parse
*qd
)
50 while (ISSPACE(*qd
->p
))
54 /* --- @qd_delim@ --- *
56 * Arguments: @qd_parse *qd@ = context
57 * @int ch@ = character to compare with
59 * Returns: Nonzero if it was, zero if it wasn't.
61 * Use: Checks the next (non-whitespace) character is what we
62 * expect. If it is, the character is eaten; otherwise it's no
66 int qd_delim(qd_parse
*qd
, int ch
)
75 /* --- @qd_enum@ --- *
77 * Arguments: @qd_parse *qd@ = context
78 * @const char *e@ = list of enum strings, space separated
80 * Returns: Index of the string matched, or @-1@.
82 * Use: Matches a keyword.
85 int qd_enum(qd_parse
*qd
, const char *e
)
95 if (STRNCMP(qd
->p
, ==, e
, n
) && !ISALNUM(qd
->p
[n
])) {
101 qd
->e
= "unrecognized keyword";
105 /* --- @qd_getmp@ --- *
107 * Arguments: @qd_parse *qd@ = context
109 * Returns: The integer extracted, or null.
111 * Use: Parses a multiprecision integer from a string.
114 mp
*qd_getmp(qd_parse
*qd
)
120 m
= mp_readstring(MP_NEW
, qd
->p
, &q
, 0);
121 if (m
&& !ISALNUM(*q
))
125 qd
->e
= "bad number";
130 /* --- @qd_eofp@ --- *
132 * Arguments: @qd_parse *qd@ = context
134 * Returns: Nonzero if at EOF, zero otherwise.
137 int qd_eofp(qd_parse
*qd
)
143 /*----- That's all, folks -------------------------------------------------*/