r3: Initial revision
[ctsim.git] / include / pol.h
1 #ifndef __H_POL
2 #define __H_POL
3
4 /* codes for pol_usefile */
5
6 #define P_USE_STR  1            /* use string as input source */
7 #define P_USE_FILE 2            /* use file as input source */
8
9 /* codes for pol_int and pol_float */
10 /* if in reject catagory, get new number from terminal */
11
12 #define P_FLTINT   1    /* get a real or integer number */
13 #define P_BFLTINT  2    /* get a real or integer number, clip against bounds */
14 #define P_CBFLTINT 3    /* get real or int, reject if outside bounds */
15
16 #define P_FLT      4    /* get a real number */
17 #define P_BFLT     5    /* get a real, clip against bounds */
18 #define P_CBFLT    6    /* get a floating, reject if outside bounds */
19
20 #define P_INT      7    /* get a integer number */
21 #define P_BINT     8    /* get a integer, clip against bounds */
22 #define P_CBINT    9    /* get a integer, reject if outside bounds */
23
24 #define LETTER   'a'
25 #define DIGIT    '0'
26
27 #define MAXTOK   200            /* maximum length of a token */
28 #define MAXLINE  255
29 #define MAXIDENT  20
30 #define MAXSKIPWORD 20
31 #define MAXSKIPCHAR 20
32
33 #define MIN_INT -32768
34 #define MAX_INT  32767
35
36 /* token types */
37
38 #define TT_STRING        1              /* string token */
39 #define TT_INT           2              /* integer token */
40 #define TT_REAL          3              /* floating point token */
41 #define TT_ALPHA         4              /* alphabetic token */
42 #define TT_ALPNUM        5              /* alphanumeric token */
43 #define TT_NUMALPHA      6
44 #define TT_SPECLCHAR     7
45
46 #define TT_EOF           8              /* end of file reached */
47 #define TT_ERROR         9              /* error in token, caused by call to wrong */
48                                         /*  type of token reader */
49 #define TT_BLANK        10              /* white space token.  pol_tok() skips these */
50 #define TT_USERTOK      11              /* user defined token */
51
52 struct symlist {
53         char *name;
54         int code;
55         struct symlist *next;
56 };
57
58 typedef struct symlist SYMBOL;
59
60 struct token_st {
61     int ready;                          /* TRUE if token is ready */
62     char tokstr[MAXTOK+1];              /* token string */
63     int type;                           /* type of token 'TT_' */
64     int code;                           /* holds code for user defined tokens */
65     double fnum;                        /* real value of token */
66     int inum;                           /* integer value of token */
67 };
68
69 typedef struct token_st TOKEN;
70
71 /* pol.c */
72 void pol_init(void);
73 void pol_skpword(char *w);
74 void pol_skpchar(char *s);
75 int pol_install(char *str, int code);
76 int pol_word(char *search, int nlet);
77 int pol_usertok(char *str, int *code);
78 int pol_string(char *str);
79 int pol_integer(int *n, int typecode, int boundcode, int bb1, int bb2);
80 int pol_float(double *n, double typecode, double boundcode, double bb1, double bb2);
81 int pol_skip(void);
82 void pol_reader(void);
83 void gettext(char *str, int lim);
84 void pol_usefile(int source, char *fn);
85 void pol_closefile(void);
86 int pol_lookchar(void);
87 int pol_inchar(void);
88 void pol_ungetch(int c);
89 int get_inputline(FILE *fp);
90 void set_inputline(char *line);
91
92 #endif