Corrected a long-standing error in which ending text with a literal
[xcircuit.git] / spiceparser / scanner.h
blob576b8b13932e405ed49b6b559397e5e4f47b21c1
1 /********************
2 This file is part of the software library CADLIB written by Conrad Ziesler
3 Copyright 2003, Conrad Ziesler, all rights reserved.
5 *************************
6 This program is free software; you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 2 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program; if not, write to the Free Software
18 Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
20 ******************/
21 /* scanner.h, header for scanner routines
22 Conrad Ziesler
25 #include <stdarg.h>
27 #ifndef __SCANNER_H__
28 #define __SCANNER_H__
31 #ifndef __MEMORY_H__
32 #include "memory.h"
33 #endif
35 #ifndef __NAMES_H__
36 #include "names.h"
37 #endif
39 /* we provide a consistent way for tools to read large text files
40 of various line oriented formats
42 in addition, we manage memory, so freeing these structures is simple
44 typedef struct file_line_st
46 unsigned int fileindex:8;
47 unsigned int line:24;
48 }file_line_t;
50 typedef struct tokenmap_st
52 int token;
53 char *str;
54 }tokenmap_t;
57 typedef struct card_st
59 struct card_st *next;
60 int token;
61 char *val;
62 char str[4];
63 }card_t;
65 typedef struct deck_st
67 struct deck_st *next;
68 card_t *card;
69 file_line_t line;
70 }deck_t;
74 typedef struct scanner_def_st
76 char line_stop[32]; /* stop scanning when we hit this line */
77 char eol_continue[8]; /* continue line if this is detected at the end */
78 char bol_continue[8]; /* continue line if this is detected at beggining */
79 int convert_case; /* convert everything to a case ? */
80 char quote_char; /* what to use as value quote */
81 char newline; /* what to use as new line character */
82 char assignment; /* what to use as assignment '=' delimiter */
83 char tokenize[8]; /* prefix for all tokens of interest */
84 char whitespace[32]; /* ignore all of this */
85 char commentstart[8]; /* this starts a comment */
86 }scanner_def_t;
88 typedef struct scanner_sect_st
90 struct scanner_sect_st *back;
91 names_t *tokenizer; /* we use this as our hasher */
92 scanner_def_t *def; /* we get our defaults from here */
94 card_t *cp;
95 deck_t *dp,*dhead;
96 int eolstring; /* got = [space] EOLINE */
97 char lbuf[512]; /* line buffer */
98 char eoline[512]; /* continue buffer */
99 int line_cont;
100 }scanner_sect_t;
102 typedef struct scanner_input_st
104 struct scanner_input_st *back, *next; /* list of all inputs*/
105 void *file_fp; /* FILE * */
106 int line;
107 int index;
108 }scanner_input_t;
110 typedef struct scanner_st
112 memory_t strmem; /* where we allocate our strings */
113 scanner_input_t *inputp; /* current input stack, for #include files */
114 scanner_input_t *allinputs; /* list of all inputs */
115 scanner_sect_t *sectp; /* section stack, who is parsing this */
116 /****** error processing ****/
117 deck_t *errdeck;
118 card_t *errcard;
119 void (*errfunc)(struct scanner_st *sp, char *format, va_list vp);
120 void (*warnfunc)(struct scanner_st *sp, char *format, va_list vp);
121 }scanner_t;
123 #define PARSE_CASE_TOLOWER 1
124 #define PARSE_CASE_TOUPPER 2
125 #define PARSE_NOCASECVT 0
128 /**** initialization and release ******/
129 void scanner_add_tokens(scanner_t *scan, tokenmap_t *map);
130 void scanner_reset_tokens(scanner_t *scan);
132 void scanner_init(scanner_t *scan); /* init all structures */
133 void scanner_release(scanner_t *scan); /* free all associated structures */
135 void scanner_input_newfp(scanner_t *scan, void *fp);
136 void scanner_sect_new(scanner_t *scan, scanner_def_t *defs, tokenmap_t *map);
137 void scanner_input_release(scanner_t *scan); /* release top of stack */
138 void scanner_sect_release(scanner_t *scan); /* release top of stack */
140 /* some standardized scanner defaults */
141 scanner_def_t *scanner_def_spice(void);
142 void scanner_def_err(scanner_t *scan, char *fmt, va_list vp);
144 /* the scanner functions, file section oriented
145 keeps allocating memory, so you get roughly the file size + about 25% overhead
146 of memory usage. free_all dumps it all quickly, though.
149 int scanner_parse_all(scanner_t *scan);
150 void scanner_free_all(scanner_t *scan); /* free all string (&card/&deck) memory */
151 int scanner_parse_line(scanner_t *scan);
152 unsigned parse_binary(char **str);
154 /* misc. */
156 void parse_error (scanner_t *scan, char *fmt, ...);
157 void parse_warn (scanner_t *scan, char *fmt, ...);
158 int scanner_checkvalid(deck_t *d, int qty);
159 void scanner_debug_all(scanner_t *scan, void *dbg);
160 file_line_t scanner_current_file_line(scanner_t *scan);
163 #endif