3 * $Id: qdparse.c,v 1.1 2004/03/27 17:54:12 mdw Exp $
5 * Quick-and-dirty parser
7 * (c) 2004 Straylight/Edgeware
10 /*----- Licensing notice --------------------------------------------------*
12 * This file is part of Catacomb.
14 * Catacomb is free software; you can redistribute it and/or modify
15 * it under the terms of the GNU Library General Public License as
16 * published by the Free Software Foundation; either version 2 of the
17 * License, or (at your option) any later version.
19 * Catacomb is distributed in the hope that it will be useful,
20 * but WITHOUT ANY WARRANTY; without even the implied warranty of
21 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
22 * GNU Library General Public License for more details.
24 * You should have received a copy of the GNU Library General Public
25 * License along with Catacomb; if not, write to the Free
26 * Software Foundation, Inc., 59 Temple Place - Suite 330, Boston,
30 /*----- Revision history --------------------------------------------------*
33 * Revision 1.1 2004/03/27 17:54:12 mdw
34 * Standard curves and curve checking.
38 /*----- Header files ------------------------------------------------------*/
45 /*----- Main code ---------------------------------------------------------*/
47 /* --- @qd_skipspc@ --- *
49 * Arguments: @qd_parse *qd@ = context
53 * Use: Skips spaces in the string. No errors.
56 void qd_skipspc(qd_parse
*qd
)
58 while (isspace((unsigned char)*qd
->p
))
62 /* --- @qd_delim@ --- *
64 * Arguments: @qd_parse *qd@ = context
65 * @int ch@ = character to compare with
67 * Returns: Nonzero if it was, zero if it wasn't.
69 * Use: Checks the next (non-whitespace) character is what we
70 * expect. If it is, the character is eaten; otherwise it's no
74 int qd_delim(qd_parse
*qd
, int ch
)
83 /* --- @qd_enum@ --- *
85 * Arguments: @qd_parse *qd@ = context
86 * @const char *e@ = list of enum strings, space separated
88 * Returns: Index of the string matched, or @-1@.
90 * Use: Matches a keyword.
93 int qd_enum(qd_parse
*qd
, const char *e
)
100 e
+= strspn(e
, ", ");
102 n
= strcspn(e
, ", ");
103 if (strncmp(qd
->p
, e
, n
) == 0 && !isalnum((unsigned char)qd
->p
[n
])) {
109 qd
->e
= "unrecognized keyword";
113 /* --- @qd_getmp@ --- *
115 * Arguments: @qd_parse *qd@ = context
117 * Returns: The integer extracted, or null.
119 * Use: Parses a multiprecision integer from a string.
122 mp
*qd_getmp(qd_parse
*qd
)
128 m
= mp_readstring(MP_NEW
, qd
->p
, &q
, 0);
129 if (m
&& !isalnum((unsigned char)*q
))
133 qd
->e
= "bad number";
138 /* --- @qd_eofp@ --- *
140 * Arguments: @qd_parse *qd@ = context
142 * Returns: Nonzero if at EOF, zero otherwise.
145 int qd_eofp(qd_parse
*qd
)
151 /*----- That's all, folks -------------------------------------------------*/