432c4e18 |
1 | /* -*-c-*- |
2 | * |
432c4e18 |
3 | * Quick-and-dirty parser |
4 | * |
5 | * (c) 2004 Straylight/Edgeware |
6 | */ |
7 | |
45c0fd36 |
8 | /*----- Licensing notice --------------------------------------------------* |
432c4e18 |
9 | * |
10 | * This file is part of Catacomb. |
11 | * |
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. |
45c0fd36 |
16 | * |
432c4e18 |
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. |
45c0fd36 |
21 | * |
432c4e18 |
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, |
25 | * MA 02111-1307, USA. |
26 | */ |
27 | |
432c4e18 |
28 | #ifndef CATACOMB_QDPARSE_H |
29 | #define CATACOMB_QDPARSE_H |
30 | |
31 | #ifdef __cplusplus |
32 | extern "C" { |
33 | #endif |
34 | |
35 | /*----- Header files ------------------------------------------------------*/ |
36 | |
37 | #ifndef CATACOMB_MP_H |
38 | # include "mp.h" |
39 | #endif |
40 | |
41 | /*----- Data structures ---------------------------------------------------*/ |
42 | |
43 | typedef struct qd_parse { |
44 | const char *p; /* Where we are right now */ |
45 | const char *e; /* Error string (output) */ |
46 | } qd_parse; |
47 | |
48 | /*----- Functions provided ------------------------------------------------*/ |
49 | |
50 | /* --- @qd_skipspc@ --- * |
51 | * |
52 | * Arguments: @qd_parse *qd@ = context |
53 | * |
54 | * Returns: --- |
55 | * |
56 | * Use: Skips spaces in the string. No errors. |
57 | */ |
58 | |
59 | extern void qd_skipspc(qd_parse */*qd*/); |
60 | |
61 | /* --- @qd_delim@ --- * |
62 | * |
63 | * Arguments: @qd_parse *qd@ = context |
64 | * @int ch@ = character to compare with |
65 | * |
66 | * Returns: Nonzero if it was, zero if it wasn't. |
67 | * |
68 | * Use: Checks the next (non-whitespace) character is what we |
69 | * expect. If it is, the character is eaten; otherwise it's no |
70 | * big deal. |
71 | */ |
72 | |
73 | extern int qd_delim(qd_parse */*qd*/, int /*ch*/); |
74 | |
75 | /* --- @qd_enum@ --- * |
76 | * |
77 | * Arguments: @qd_parse *qd@ = context |
78 | * @const char *e@ = list of enum strings, space separated |
79 | * |
80 | * Returns: Index of the string matched, or @-1@. |
81 | * |
82 | * Use: Matches a keyword. |
83 | */ |
84 | |
85 | extern int qd_enum(qd_parse */*qd*/, const char */*e*/); |
86 | |
87 | /* --- @qd_getmp@ --- * |
88 | * |
89 | * Arguments: @qd_parse *qd@ = context |
90 | * |
91 | * Returns: The integer extracted, or null. |
92 | * |
93 | * Use: Parses a multiprecision integer from a string. |
94 | */ |
95 | |
96 | extern mp *qd_getmp(qd_parse */*qd*/); |
97 | |
98 | /* --- @qd_eofp@ --- * |
99 | * |
100 | * Arguments: @qd_parse *qd@ = context |
101 | * |
102 | * Returns: Nonzero if at EOF, zero otherwise. |
103 | */ |
104 | |
105 | extern int qd_eofp(qd_parse */*qd*/); |
106 | |
107 | /*----- That's all, folks -------------------------------------------------*/ |
108 | |
109 | #ifdef __cplusplus |
110 | } |
111 | #endif |
112 | |
113 | #endif |