1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: pol.h,v 1.7 2000/12/27 03:16:02 kevin Exp $
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
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
19 ******************************************************************************/
28 // codes for pol_usefile
\r
30 P_USE_STR = 1, // use string as input source
\r
31 P_USE_FILE, // use file as input source
\r
39 void skpword (char *w);
40 void skpchar (char *s);
41 int installKeyword (char *str, int code);
42 int word (char *search, int nlet);
43 int usertok (char *str, int *code);
44 int string (char *str);
45 int integer (int *n, int typecode, int boundcode, int bb1, int bb2);
46 bool readfloat (double *n, double typecode, double boundcode, double bb1, double bb2);
49 void gettext (char *str, int lim);
50 void usefile (int source, char *fn);
55 int get_inputline (FILE *fp);
56 void set_inputline (const char* const line);
60 MAXTOK = 200, // maximum length of a token
\r
61 MAXLINE = 1024, // maximum line length
\r
65 MIN_INT = -2000000000,
\r
66 MAX_INT = 2000000000,
\r
71 TT_STRING = 1, // string token
\r
72 TT_INT, // integer token
\r
73 TT_REAL, // floating point token
\r
74 TT_ALPHA, // alphabetic token
\r
75 TT_ALPNUM, // alphanumeric token
\r
78 TT_EOF, // end of file reached
\r
79 TT_ERROR, // error in token, caused by call to wrong type of token reader
\r
80 TT_BLANK, // white space token. pol_tok() skips these
\r
81 TT_USERTOK, // user defined token
\r
87 // codes for pol_int and pol_float
\r
88 // if in reject catagory, get new number from terminal
\r
90 P_FLTINT = 1, // get a real or integer number
\r
91 P_BFLTINT, // get a real or integer number, clip against bounds
\r
92 P_CBFLTINT, // get real or int, reject if outside bounds
\r
93 P_FLT, // get a real number
\r
94 P_BFLT, // get a real, clip against bounds
\r
95 P_CBFLT, // get a floating, reject if outside bounds
\r
96 P_INT, // get a integer number
\r
97 P_BINT, // get a integer, clip against bounds
\r
98 P_CBINT, // get a integer, reject if outside bounds
\r
105 // typedef std::map<std::string,int> KeywordCodeList;
\r
110 struct symlist *next;
\r
112 typedef struct symlist SYMBOL;
\r
115 int ready; // TRUE if token is ready
\r
116 // std::string tokstr; // token string
\r
117 char tokstr[MAXTOK+1];
\r
118 int type; // type of token 'TT_'
\r
119 int code; // holds code for user defined tokens
\r
120 double fnum; // real value of token
\r
121 int inum; // integer value of token
\r
123 typedef struct token_st TOKEN;
\r
126 struct token_st token; // current token
\r
131 // Tables words stored with install() & found with lookup()
\r
132 SYMBOL *skiptable[HASHSIZE]; // words to ignore and skip
\r
133 SYMBOL *cmdtable[HASHSIZE]; // pol parameter commands
\r
134 SYMBOL *usertable[HASHSIZE]; // user defined symbols
\r
137 char eoc; /* end of command character */
\r
138 char str; /* string delimiter */
\r
139 char com; /* comment character */
\r
140 char cmd; /* pol parameter command character */
\r
141 char prg; /* program load character */
\r
142 char con; /* continuation across newline character */
\r
143 char out; /* character that delimits output to terminal */
\r
144 char ter; /* character indicates insertion of input from terminal */
\r
145 char inb; /* input from graphics device */
\r
149 // current pol state
\r
151 char skipchars[MAXSKIPCHAR]; // characters to skip
\r
152 int nl_eoc; // TRUE if newline character ends a command
\r
153 int trace; // TRUE if trace is on
\r
158 struct KeywordCodeList {
\r
163 static const struct KeywordCodeList cmdlist[];
\r
164 static const int NUMCMD;
\r
166 // Internal codes for pol commands
\r
189 int currentf; /* pointer to current fp */
\r
190 FILE *filep[MAXFILE]; /* == NULL for string input */
\r
191 char *fname[MAXFILE]; /* pointer to filename */
\r
193 char inputline[MAXLINE]; /* current input line */
\r
194 int lineptr; /* current position in inputline */
\r
199 int bp; // pointer to next free position
\r
200 int buf[BUFSIZE]; // pushed back input characters
\r
202 int skiptok(char term[]);
\r
203 int tok(struct token_st *token);
\r
204 void dumptok(struct token_st *token);
\r
207 int getpol_tok(struct token_st *token);
\r
209 int gettok (TOKEN *tok);
\r
210 void getblank(char *s, int toksiz);
\r
211 int getalpha(char *s, int toksiz);
\r
212 void getquote(char *qs, int toksiz);
\r
213 void getescape(char *s, int delim, int toksiz);
\r
214 int getnumber (char str[], int strsize, double *fnum, int *inum);
\r
217 void inittable(SYMBOL *table[]);
\r
218 void freetable(SYMBOL *table[]);
\r
220 SYMBOL *lookup(SYMBOL *table[], char *s);
\r
221 SYMBOL *install(SYMBOL *table[], char *s, int def);
\r
222 int getch(FILE *fp);
\r