1 /* ************************************************************************** 2 * 3 * --- File: gexpr.h 4 * 5 * --- Purpose: header file for gexpr. 6 * 7 * --- Copyright (C) Guido Gonzato, guido@ibogeo.df.unibo.it 8 * 9 * --- Last updated: 31 May 2001 10 * 11 * This program is free software; you can redistribute it and/or modify 12 * it under the terms of the GNU General Public License as published by 13 * the Free Software Foundation; either version 2 of the License, or 14 * (at your option) any later version. 15 * 16 * This program is distributed in the hope that it will be useful, 17 * but WITHOUT ANY WARRANTY; without even the implied warranty of 18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 19 * GNU General Public License for more details. 20 * 21 * You should have received a copy of the GNU General Public License 22 * along with this program; if not, write to the Free Software 23 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. 24 * 25 * ************************************************************************ */ 26 27 #ifndef GEXPR_H 28 #define GEXPR_H 29 30 #include <setjmp.h> /* for longjmp() */ 31 32 /* a few constants */ 33 34 #define PROGNAME "gexpr" 35 #define VERSION "2.0.2" 36 #define DATE "31 May 2001" 37 38 #define MAX_TOKEN_LENGTH 80 39 40 /* the ubiquitous boolean type */ 41 42 typedef enum { FALSE, TRUE } BOOL; 43 44 /* where the input comes from */ 45 46 typedef enum { STDIN, ARGV_1 } WHERE; 47 48 /* these are the possible tokens that make up an expression */ 49 50 typedef enum { 51 T_NONE, T_ERROR, T_END, T_EOF, T_EOL, T_COMMA, T_DIGIT, T_IDENT, 52 T_CONST, T_FUNCTION, T_COMMAND, T_MISC, T_OP_PLUS, T_OP_MINUS, 53 T_OP_MULT, T_OP_DIV, T_OPEN_PAR, T_CLOSED_PAR, 54 T_REL, T_EQ, T_LE, T_LT, T_GE, T_GT 55 } TOKEN_TYPE; 56 57 /* now let's define what a token is */ 58 59 typedef struct { 60 TOKEN_TYPE type; /* what's this token? */ 61 char string[MAX_TOKEN_LENGTH]; /* token as string */ 62 double value; /* its value, if a number */ 63 short args; /* argument(s), if function */ 64 } TOKEN; 65 66 /* these are all the available functions, except the static ones */ 67 68 void handle_command (const char *); /* defined in commands.c*/ 69 void error (const char *, TOKEN_TYPE); /* defined in errors.c */ 70 void flush_stdin (void); /* ditto */ 71 double expression (void); /* defined in eval.c */ 72 void output (double); /* defined in output.c */ 73 double my_strtod (const char *, char **); /* ditto */ 74 TOKEN read_token (void); /* defined in read_token.c */ 75 void check_token (TOKEN_TYPE, TOKEN_TYPE); /* ditto */ 76 double function_value (short, double, double); /* ditto */ 77 78 /* "only" six global variables: first, where to jump in case of error */ 79 80 extern jmp_buf jump; /* defined in gexpr.c */ 81 82 /* second, whether a token has already been read. Some functions read 83 * tokens and stop when they find one they can't use. It would be nice to 84 * have something like ungetc() to send back the token we don't want. When 85 * a function reads a token it can't use, it sets token_read to 86 * TRUE; upon the next call, read_token() will return the old token. 87 */ 88 89 extern BOOL token_read; /* defined in gexpr.c */ 90 91 /* third, whether the program is over 92 */ 93 94 extern BOOL program_over; /* defined in gexpr.c */ 95 96 /* fourth, where the input comes from: stdin or argv[1] 97 */ 98 99 extern WHERE input_source; /* defined in gexpr.c */ 100 101 /* fifth, a pointer to the expression if it is a string 102 */ 103 104 extern char *expression_source; /* defined in gexpr.c */ 105 106 /* sixth, the output base (2 to 16) 107 */ 108 109 extern int output_base; /* defined in output.c */ 110 111 #endif 112 113 /* --- End of file gexpr.h --- */ 114