1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: pol.h,v 1.11 2001/01/02 16:02:12 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 ******************************************************************************/
23 #include "hashtable.h"
30 // codes for pol_usefile
32 P_USE_STR = 1, // use string as input source
33 P_USE_FILE, // use file as input source
41 void addSkipWord (const char* const w);
42 void addSkipChar (int c);
43 void addKeyword (const char* const str, int code);
44 bool readWord (char *search, int nlet);
45 bool readUserToken (char *str, int *code);
46 bool readString (char *str);
47 bool readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2);
48 bool readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2);
51 bool readText (char *str, int lim);
52 void usefile (int source, char *fn);
57 int get_inputline (FILE *fp);
58 void set_inputline (const char* const line);
62 MAXTOK = 200, // maximum length of a token
63 MAXLINE = 1024, // maximum line length
67 MIN_INT = -2000000000,
73 TT_STRING = 1, // string token
74 TT_INT, // integer token
75 TT_REAL, // floating point token
76 TT_ALPHA, // alphabetic token
77 TT_ALPNUM, // alphanumeric token
80 TT_EOF, // end of file reached
81 TT_ERROR, // error in token, caused by call to wrong type of token reader
82 TT_BLANK, // white space token. pol_tok() skips these
83 TT_USERTOK, // user defined token
89 // codes for pol_int and pol_float
90 // if in reject catagory, get new number from terminal
92 P_FLTINT = 1, // get a real or integer number
93 P_BFLTINT, // get a real or integer number, clip against bounds
94 P_CBFLTINT, // get real or int, reject if outside bounds
95 P_FLT, // get a real number
96 P_BFLT, // get a real, clip against bounds
97 P_CBFLT, // get a floating, reject if outside bounds
98 P_INT, // get a integer number
99 P_BINT, // get a integer, clip against bounds
100 P_CBINT, // get a integer, reject if outside bounds
107 // typedef std::map<std::string,int> KeywordCodeList;
110 int ready; // TRUE if token is ready
111 // std::string tokstr; // token string
112 char tokstr[MAXTOK+1];
113 int type; // type of token 'TT_'
114 int code; // holds code for user defined tokens
115 double fnum; // real value of token
116 int inum; // integer value of token
118 typedef struct token_st TOKEN;
119 struct token_st token; // current token
121 // Tables words stored with install() & found with lookup()
122 KeywordCodeHashTable skiptable; // words to ignore and skip
123 KeywordCodeHashTable cmdtable; // pol parameter commands
124 KeywordCodeHashTable usertable; // user defined symbols
127 char eoc; /* end of command character */
128 char str; /* string delimiter */
129 char com; /* comment character */
130 char cmd; /* pol parameter command character */
131 char prg; /* program load character */
132 char con; /* continuation across newline character */
133 char out; /* character that delimits output to terminal */
134 char ter; /* character indicates insertion of input from terminal */
135 char inb; /* input from graphics device */
139 char m_szSkipChars [MAXSKIPCHAR]; // characters to skip
141 bool m_bNewlineIsEOC;
143 struct KeywordCodeList {
148 static const struct KeywordCodeList cmdlist[];
149 static const unsigned int NUMCMD;
151 // Internal codes for pol commands
177 std::istream* m_pInputStream;
179 char* m_pszInputString;
185 int currentf; /* pointer to current fp */
186 FILE *filep[MAXFILE]; /* == NULL for string input */
187 char *fname[MAXFILE]; /* pointer to filename */
189 char inputline[MAXLINE]; /* current input line */
190 int lineptr; /* current position in inputline */
192 std::stack<int> m_stackPushBackInput;
194 bool skipSingleToken (char term[]);
195 int tok (struct token_st *token);
196 void dumptok (struct token_st *token);
199 int getpol_tok (struct token_st *token);
201 int gettok (TOKEN *tok);
202 void getblank (char *s, int toksiz);
203 int getalpha (char *s, int toksiz);
204 void getquote (char *qs, int toksiz);
205 void getescape (char *s, int delim, int toksiz);
206 int getnumber (char str[], int strsize, double *fnum, int *inum);
209 int getch (FILE *fp);