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