X-Git-Url: http://git.kpe.io/?a=blobdiff_plain;f=libctgraphics%2Fpol.cpp;h=5ba490028b29b371648ef806fd5e714d14798457;hb=5ec5449357eaae253d6b1026621262480e2efa63;hp=9db01ce1c7b7797403882c6fe5e91eaadc81f2e0;hpb=081b06d3a3372e5db56755c1fe5b2af9f8c189f3;p=ctsim.git diff --git a/libctgraphics/pol.cpp b/libctgraphics/pol.cpp index 9db01ce..5ba4900 100644 --- a/libctgraphics/pol.cpp +++ b/libctgraphics/pol.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pol.cpp,v 1.1 2000/07/30 15:58:18 kevin Exp $ +** $Id: pol.cpp,v 1.5 2000/12/25 21:54:26 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 @@ -24,6 +24,7 @@ /* */ /*----------------------------------------------------------------------*/ +#include "ct.h" #include #include #include @@ -31,15 +32,16 @@ #include "pol.h" -static const int HASHSIZE=20; +static const int HASHSIZE=100; -/* Tables words stored with install() & found with lookup() */ -static SYMBOL *skiptable[HASHSIZE]; /* words to ignore and skip */ -static SYMBOL *cmdtable[HASHSIZE]; /* pol parameter commands */ -static SYMBOL *usertable[HASHSIZE]; /* user defined symbols */ +// Tables words stored with install() & found with lookup() +static SYMBOL *skiptable[HASHSIZE]; // words to ignore and skip +static SYMBOL *cmdtable[HASHSIZE]; // pol parameter commands +static SYMBOL *usertable[HASHSIZE]; // user defined symbols -static struct token_st token; /* current token */ +static struct token_st token; // current token + static struct metachar { char eoc; /* end of command character */ @@ -53,12 +55,12 @@ static struct metachar { char inb; /* input from graphics device */ } meta; -/* current pol state */ - + +// current pol state static 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 */ + char skipchars[MAXSKIPCHAR]; // characters to skip + int nl_eoc; // TRUE if newline character ends a command + int trace; // TRUE if trace is on } pol; struct key { @@ -66,24 +68,25 @@ struct key { int code; }; -/* internal codes for pol commands */ - -#define PC_EOC 1 -#define PC_STR 2 -#define PC_COM 3 -#define PC_CMD 4 -#define PC_PRG 5 -#define PC_CON 6 -#define PC_OUT 7 -#define PC_TER 8 -#define PC_INB 9 -#define PC_NL_EOC 10 -#define PC_NL_NEOC 11 -#define PC_TRON 12 -#define PC_TROFF 13 -#define PC_FILE 14 -#define PC_DUMP 15 - +// 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, +}; + static struct key cmdlist[] = { { "eoc", PC_EOC,}, { "str", PC_STR,}, @@ -103,7 +106,8 @@ static struct key cmdlist[] = { { "dump", PC_DUMP,}, }; -#define NUMCMD (sizeof(cmdlist) / sizeof (struct key)) +const int NUMCMD = (sizeof(cmdlist) / sizeof (struct key)); + static int skiptok(char term[]); static int pol_tok(struct token_st *token); @@ -125,13 +129,7 @@ static void freetable(SYMBOL *table[]); static int hash(char *s); static SYMBOL *lookup(SYMBOL *table[], char *s); static SYMBOL *install(SYMBOL *table[], char *s, int def); -static void outch(int c); -static void inc_line(void); -static int getlinect(void); -static void setlinect(int n); -static void synerr(char *msg); static int pol_getch(FILE *fp); -static void ungets(char *s); void pol_init (void) @@ -171,7 +169,7 @@ void pol_skpword (char *w) { if (install (skiptable, w, 0) == NULL) - synerr ("Too many skip words defined"); + sys_error (ERR_SEVERE, "Too many skip words defined"); } /* pol_skpchar (s) @@ -197,7 +195,7 @@ pol_install (char *str, int code) { if (install (usertable, str, code) == NULL) { - synerr ("Out ot memory installing user tokens"); + sys_error (ERR_SEVERE, "Out of memory installing user tokens"); return (FALSE); } @@ -471,12 +469,12 @@ static int getcmd(void) tt = getalpha (str, MAXTOK); if (tt == TT_ERROR) { - synerr ("error in pol parameter command"); + sys_error (ERR_WARNING, "Error in POL parameter command"); pol_reader(); return(FALSE); } if ((cmd = lookup (cmdtable,str)) == NULL) { - synerr ("unrecognized command"); + sys_error (ERR_WARNING, "POL: Unrecognized command %s", cmd); pol_reader(); return (FALSE); } else { @@ -514,7 +512,7 @@ static int getcmd(void) if (found == FALSE) { tt = gettok (&tok); if (tt != TT_SPECLCHAR) { - synerr("illegal command character"); + sys_error (ERR_SEVERE, "POL: Illegal command character"); return (FALSE); } switch(cmd->code) { @@ -645,7 +643,7 @@ getalpha (char *s, int toksiz) pol_ungetch(s[i]); if (i >= toksiz) - synerr("token too long."); + sys_error (ERR_SEVERE, "POL token too long."); s[i] = EOS; /* terminate token */ return (alphatype); @@ -675,16 +673,16 @@ getescape ( /* reads up to delim */ for (i = 0; (c = pol_inchar()) != delim; i++) { if (c == NEWLINE) { - synerr ("Missing closing delimiter."); + sys_error (ERR_WARNING, "Missing closing delimiter."); break; } if (i >= toksiz) { - synerr("string too long."); + sys_error (ERR_SEVERE, "string too long."); break; } if (c == EOF) { pol_ungetch(c); - synerr("end of file inside quotation"); + sys_error (ERR_SEVERE, "end of file inside quotation"); break; } else if (c == BSLASH) { /* escape character */ s[i++] = c; @@ -953,11 +951,11 @@ install (SYMBOL *table[], char *name, int def) if ((np = lookup (table, name)) == NULL) { /* not found */ np = (SYMBOL *) malloc (sizeof(*np)); if (np == NULL) { - synerr(installerr); + sys_error (ERR_SEVERE, installerr); return (NULL); } if ((np->name = strdup(name)) == NULL) { - synerr(installerr); + sys_error (ERR_SEVERE, installerr); return (NULL); } str_lower (np->name); @@ -979,49 +977,14 @@ install (SYMBOL *table[], char *name, int def) static int currentf = -1; /* pointer to current fp */ static FILE *filep[MAXFILE]; /* == NULL for string input */ static char *fname[MAXFILE]; /* pointer to filename */ -static int linect[MAXFILE]; /* line count in file */ static char inputline[MAXLINE]; /* current input line */ static int lineptr; /* current position in inputline */ -static void -outch (int c) -{ - putchar (c); -} - -static void inc_line(void) -{ - if (currentf >= 0) - ++linect[currentf]; -} - -static int getlinect(void) -{ - return (linect[currentf]); -} - -static void -setlinect (int n) -{ - if (currentf >= 0) - linect[currentf] = n; -} - -static void -synerr (char *msg) -{ - fputs (fname[currentf], stderr); - fprintf(stderr, "%d", linect[currentf]); - fputc (COLON, stderr); - fputs (msg, stderr); - fputc (NEWLINE, stderr); -} - -/*----------------------------------------------------------------------*/ -/* POL INPUT */ -/*----------------------------------------------------------------------*/ +//---------------------------------------------------------------------- +// POL INPUT +//---------------------------------------------------------------------- #define BUFSIZE 100 static int bp = 0; /* pointer to next free position */ @@ -1043,7 +1006,7 @@ pol_usefile (int source, char *fn) ++currentf; if (currentf >= MAXFILE) { --currentf; - synerr ("files nested too deeply"); + sys_error (ERR_SEVERE, "files nested too deeply"); return; } @@ -1051,17 +1014,15 @@ pol_usefile (int source, char *fn) if (source == P_USE_STR) { filep[currentf] = NULL; - linect[currentf] = 1; } else if (source == P_USE_FILE) { if (fn == NULL || strlen(fn) == 0) { fp = stdin; } else if ((fp = fopen(fn, "r")) == NULL) { --currentf; - synerr ("can't open file"); + sys_error (ERR_SEVERE, "can't open file"); return; } filep[currentf] = fp; - linect[currentf] = 1; fname[currentf] = strdup (fn); } } @@ -1140,16 +1101,6 @@ pol_ungetch (int c) } -/* push back string onto input */ -static void -ungets (char *s) -{ - int i; - - for (i = strlen(s) - 1; i >= 0; i--) - pol_ungetch (s[i]); -} - int get_inputline (FILE *fp) { @@ -1162,7 +1113,7 @@ get_inputline (FILE *fp) } void -set_inputline (char *line) +set_inputline (const char* const line) { lineptr = 0; bp = 0;