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