X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=include%2Fpol.h;fp=include%2Fpol.h;h=7ac752595ec83979195bc31d836c8073ccf4501b;hb=65732cc5d8dbf867ed56a021c07c5636cea93b5a;hp=54ff9f01435fe8f7dc4f6977dc718084bbb16960;hpb=fd726516dd11fd37a675a94c1e7165c47d793b34;p=ctsim.git diff --git a/include/pol.h b/include/pol.h index 54ff9f0..7ac7525 100644 --- a/include/pol.h +++ b/include/pol.h @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pol.h,v 1.6 2000/12/25 21:54:26 kevin Exp $ +** $Id: pol.h,v 1.7 2000/12/27 03:16:02 kevin Exp $ ** ** This program is free software; you can redistribute it and/or modify ** it under the terms of the GNU General Public License (version 2) as @@ -19,98 +19,209 @@ ******************************************************************************/ #ifndef __H_POL #define __H_POL - -// codes for pol_usefile -enum { - P_USE_STR = 1, // use string as input source - P_USE_FILE, // use file as input source -}; -// codes for pol_int and pol_float -// if in reject catagory, get new number from terminal -enum { - P_FLTINT = 1, // get a real or integer number - P_BFLTINT, // get a real or integer number, clip against bounds - P_CBFLTINT, // get real or int, reject if outside bounds - P_FLT, // get a real number - P_BFLT, // get a real, clip against bounds - P_CBFLT, // get a floating, reject if outside bounds - P_INT, // get a integer number - P_BINT, // get a integer, clip against bounds - P_CBINT, // get a integer, reject if outside bounds -}; +class POL { + + public: + + // codes for pol_usefile + enum { + P_USE_STR = 1, // use string as input source + P_USE_FILE, // use file as input source + }; - -#define LETTER 'a' -#define DIGIT '0' - -#define MAXTOK 200 /* maximum length of a token */ -#define MAXLINE 255 -#define MAXIDENT 20 -#define MAXSKIPWORD 20 -#define MAXSKIPCHAR 20 - -#define MIN_INT -32768 -#define MAX_INT 32767 + + POL(); + ~POL(); + + void init (); + void skpword (char *w); + void skpchar (char *s); + int installKeyword (char *str, int code); + int word (char *search, int nlet); + int usertok (char *str, int *code); + int string (char *str); + int integer (int *n, int typecode, int boundcode, int bb1, int bb2); + bool readfloat (double *n, double typecode, double boundcode, double bb1, double bb2); + int skip (); + void reader (); + void gettext (char *str, int lim); + void usefile (int source, char *fn); + void closefile (); + int lookchar (); + int inchar (); + void ungetch (int c); + int get_inputline (FILE *fp); + void set_inputline (const char* const line); + - -// token types -enum { - TT_STRING = 1, // string token - TT_INT, // integer token - TT_REAL, // floating point token - TT_ALPHA, // alphabetic token - TT_ALPNUM, // alphanumeric token - TT_NUMALPHA, - TT_SPECLCHAR, - TT_EOF, // end of file reached - TT_ERROR, // error in token, caused by call to wrong type of token reader - TT_BLANK, // white space token. pol_tok() skips these - TT_USERTOK, // user defined token -}; + enum { + MAXTOK = 200, // maximum length of a token + MAXLINE = 1024, // maximum line length + MAXIDENT = 20, + MAXSKIPWORD = 20, + MAXSKIPCHAR = 20, + MIN_INT = -2000000000, + MAX_INT = 2000000000, + }; + + // token types + enum { + TT_STRING = 1, // string token + TT_INT, // integer token + TT_REAL, // floating point token + TT_ALPHA, // alphabetic token + TT_ALPNUM, // alphanumeric token + TT_NUMALPHA, + TT_SPECLCHAR, + TT_EOF, // end of file reached + TT_ERROR, // error in token, caused by call to wrong type of token reader + TT_BLANK, // white space token. pol_tok() skips these + TT_USERTOK, // user defined token + }; - -struct symlist { - char *name; - int code; - struct symlist *next; + +private: + + // codes for pol_int and pol_float + // if in reject catagory, get new number from terminal + enum { + P_FLTINT = 1, // get a real or integer number + P_BFLTINT, // get a real or integer number, clip against bounds + P_CBFLTINT, // get real or int, reject if outside bounds + P_FLT, // get a real number + P_BFLT, // get a real, clip against bounds + P_CBFLT, // get a floating, reject if outside bounds + P_INT, // get a integer number + P_BINT, // get a integer, clip against bounds + P_CBINT, // get a integer, reject if outside bounds + }; + +#define LETTER 'a' +#define DIGIT '0' + + +// typedef std::map KeywordCodeList; + + struct symlist { + char *name; + int code; + struct symlist *next; + }; + typedef struct symlist SYMBOL; + + struct token_st { + int ready; // TRUE if token is ready + // std::string tokstr; // token string + char tokstr[MAXTOK+1]; + int type; // type of token 'TT_' + int code; // holds code for user defined tokens + double fnum; // real value of token + int inum; // integer value of token + }; + typedef struct token_st TOKEN; + + + struct token_st token; // current token + enum { + HASHSIZE = 100, + }; + + // Tables words stored with install() & found with lookup() + SYMBOL *skiptable[HASHSIZE]; // words to ignore and skip + SYMBOL *cmdtable[HASHSIZE]; // pol parameter commands + SYMBOL *usertable[HASHSIZE]; // user defined symbols + + struct metachar { + char eoc; /* end of command character */ + char str; /* string delimiter */ + char com; /* comment character */ + char cmd; /* pol parameter command character */ + char prg; /* program load character */ + char con; /* continuation across newline character */ + char out; /* character that delimits output to terminal */ + char ter; /* character indicates insertion of input from terminal */ + char inb; /* input from graphics device */ + } meta; + + + // current pol state + struct pol_st { + char skipchars[MAXSKIPCHAR]; // characters to skip + int nl_eoc; // TRUE if newline character ends a command + int trace; // TRUE if trace is on + }; + + struct pol_st pol; + + struct KeywordCodeList { + char *keyword; + int code; + }; + + static const struct KeywordCodeList cmdlist[]; + static const int NUMCMD; + + // Internal codes for pol commands + enum { + PC_EOC = 1, + PC_STR, + PC_COM, + PC_CMD, + PC_PRG, + PC_CON, + PC_OUT, + PC_TER, + PC_INB, + PC_NL_EOC, + PC_NL_NEOC, + PC_TRON, + PC_TROFF, + PC_FILE, + PC_DUMP, + }; + + enum { + MAXFILE = 8, + }; + + int currentf; /* pointer to current fp */ + FILE *filep[MAXFILE]; /* == NULL for string input */ + char *fname[MAXFILE]; /* pointer to filename */ + + char inputline[MAXLINE]; /* current input line */ + int lineptr; /* current position in inputline */ + + enum { + BUFSIZE = 100, + }; + int bp; // pointer to next free position + int buf[BUFSIZE]; // pushed back input characters + + int skiptok(char term[]); + int tok(struct token_st *token); + void dumptok(struct token_st *token); + + + int getpol_tok(struct token_st *token); + int getcmd(); + int gettok (TOKEN *tok); + void getblank(char *s, int toksiz); + int getalpha(char *s, int toksiz); + void getquote(char *qs, int toksiz); + void getescape(char *s, int delim, int toksiz); + int getnumber (char str[], int strsize, double *fnum, int *inum); + void eatline(); + int type(int c); + void inittable(SYMBOL *table[]); + void freetable(SYMBOL *table[]); + int hash(char *s); + SYMBOL *lookup(SYMBOL *table[], char *s); + SYMBOL *install(SYMBOL *table[], char *s, int def); + int getch(FILE *fp); + }; -typedef struct symlist SYMBOL; - -struct token_st { - int ready; // TRUE if token is ready - char tokstr[MAXTOK+1]; // token string - int type; // type of token 'TT_' - int code; // holds code for user defined tokens - double fnum; // real value of token - int inum; // integer value of token -}; - -typedef struct token_st TOKEN; - - -/* pol.c */ -void pol_init (void); -void pol_skpword (char *w); -void pol_skpchar (char *s); -int pol_install (char *str, int code); -int pol_word (char *search, int nlet); -int pol_usertok (char *str, int *code); -int pol_string (char *str); -int pol_integer (int *n, int typecode, int boundcode, int bb1, int bb2); -int pol_float (double *n, double typecode, double boundcode, double bb1, double bb2); -int pol_skip (void); -void pol_reader (void); -void gettext (char *str, int lim); -void pol_usefile (int source, char *fn); -void pol_closefile (void); -int pol_lookchar (void); -int pol_inchar (void); -void pol_ungetch (int c); -int get_inputline (FILE *fp); -void set_inputline (const char* const line); - -#endif +#endif