X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctgraphics%2Fpol.cpp;fp=libctgraphics%2Fpol.cpp;h=5ba490028b29b371648ef806fd5e714d14798457;hp=d4a162fab9a0c0dcced845928a2538ccca3a7d2e;hb=5ec5449357eaae253d6b1026621262480e2efa63;hpb=2a3686d3bd1f690d318b81766c261da785cf9b57 diff --git a/libctgraphics/pol.cpp b/libctgraphics/pol.cpp index d4a162f..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.4 2000/12/20 14:39:09 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 @@ -32,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 */ @@ -54,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 { @@ -67,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,}, @@ -104,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); @@ -126,7 +129,6 @@ 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 synerr(char *msg); static int pol_getch(FILE *fp); @@ -193,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); } @@ -467,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 { @@ -510,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) { @@ -641,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); @@ -671,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; @@ -949,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,17 +981,10 @@ static char *fname[MAXFILE]; /* pointer to filename */ static char inputline[MAXLINE]; /* current input line */ static int lineptr; /* current position in inputline */ -static void -synerr (char *msg) -{ - fputs (fname[currentf], stderr); - fputs (msg, stderr); - fputc (NEWLINE, stderr); -} -/*----------------------------------------------------------------------*/ -/* POL INPUT */ -/*----------------------------------------------------------------------*/ +//---------------------------------------------------------------------- +// POL INPUT +//---------------------------------------------------------------------- #define BUFSIZE 100 static int bp = 0; /* pointer to next free position */ @@ -1011,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; } @@ -1024,7 +1019,7 @@ pol_usefile (int source, char *fn) 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; @@ -1118,7 +1113,7 @@ get_inputline (FILE *fp) } void -set_inputline (const char const *line) +set_inputline (const char* const line) { lineptr = 0; bp = 0;