r316: c++ conversions to POL
authorKevin M. Rosenberg <kevin@rosenberg.net>
Wed, 27 Dec 2000 20:09:19 +0000 (20:09 +0000)
committerKevin M. Rosenberg <kevin@rosenberg.net>
Wed, 27 Dec 2000 20:09:19 +0000 (20:09 +0000)
include/Makefile.am
include/ctsupport.h
include/hashtable.h [new file with mode: 0644]
include/pol.h
libctgraphics/ezplot.cpp
libctgraphics/ezset.cpp
libctgraphics/pol.cpp
libctsupport/Makefile.am
libctsupport/hashtable.cpp [new file with mode: 0644]
libctsupport/syserror.cpp
msvc/ctsim/ctsim.plg

index 97a27b503d6aae0cb709183a6634d448ee973a03..bc6c111a4562490e7486e28f9defda3b1dfecbc0 100644 (file)
@@ -1,4 +1,4 @@
-noinst_HEADERS=ct.h ezplot.h pol.h sgp.h array2d.h imagefile.h backprojectors.h mpiworld.h fnetorderstream.h phantom.h timer.h sstream_subst scanner.h projections.h ctsupport.h filter.h array2dfile.h trace.h transformmatrix.h procsignal.h reconstruct.h plotfile.h
+noinst_HEADERS=ct.h ezplot.h pol.h sgp.h array2d.h imagefile.h backprojectors.h mpiworld.h fnetorderstream.h phantom.h timer.h sstream_subst scanner.h projections.h ctsupport.h filter.h array2dfile.h trace.h transformmatrix.h procsignal.h reconstruct.h plotfile.h hashtable.h
 
 
 
index 460af416de8c3d04a4b1ac7ec187a40598a32fc1..55c25d50c53f71be0616109e4f572d9db25083cd 100644 (file)
@@ -9,7 +9,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ctsupport.h,v 1.16 2000/12/21 03:40:58 kevin Exp $
+**  $Id: ctsupport.h,v 1.17 2000/12/27 20:09:19 kevin Exp $
 **
 **
 **  This program is free software; you can redistribute it and/or modify
@@ -64,6 +64,7 @@
 
 /*----------------------------------------------------------------------*/
 
+#define ERR_TRACE -1\r
 #define ERR_WARNING    0
 #define ERR_SEVERE     1
 #define ERR_FATAL      2
diff --git a/include/hashtable.h b/include/hashtable.h
new file mode 100644 (file)
index 0000000..0f97edf
--- /dev/null
@@ -0,0 +1,87 @@
+/* FILE IDENTIFICATION\r
+**\r
+**     File Name:      hashtable.h\r
+**     Author:         Kevin Rosenberg\r
+**     Purpose:        Header file for hash table library\r
+**     Date Started:   Dec. 2000\r
+**\r
+**  This is part of the CTSim program\r
+**  Copyright (C) 1983-2000 Kevin Rosenberg\r
+**\r
+**  $Id: hashtable.h,v 1.1 2000/12/27 20:09:19 kevin Exp $\r
+**\r
+**\r
+**  This program is free software; you can redistribute it and/or modify\r
+**  it under the terms of the GNU General Public License (version 2) as\r
+**  published by the Free Software Foundation.\r
+**\r
+**  This program is distributed in the hope that it will be useful,\r
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+**  GNU General Public License for more details.\r
+**\r
+**  You should have received a copy of the GNU General Public License\r
+**  along with this program; if not, write to the Free Software\r
+**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+******************************************************************************/\r
+\r
+#ifndef HASHTABLE_H\r
+#define HASHTABLE_H\r
+\r
+\r
+class KeywordCodeEntry\r
+{\r
+private:\r
+  std::string m_strKeyword;\r
+  int m_iCode;\r
+  class KeywordCodeEntry *m_pNext;\r
+  \r
+  public:\r
+    \r
+    KeywordCodeEntry (const char* const pszKeyword, int iCode);\r
+    \r
+    const char* const getKeyword() const\r
+    { return m_strKeyword.c_str(); }\r
+\r
+    bool matchesKeyword (const char* const pszMatch) const;\r
+\r
+    int getCode () const\r
+    { return m_iCode; }\r
+    \r
+    void setCode (int iCode) \r
+    { m_iCode = iCode; }\r
+    \r
+    void setNext (KeywordCodeEntry* pNext)\r
+    { m_pNext = pNext; }\r
+    \r
+    KeywordCodeEntry* getNext ()\r
+    { return m_pNext; }\r
+};\r
+\r
+\r
+class KeywordCodeHashTable {\r
+public:\r
+  enum {\r
+    HASHSIZE = 100,\r
+  };\r
+  \r
+  KeywordCodeHashTable()\r
+  { initTable(); }\r
+  \r
+  ~KeywordCodeHashTable()\r
+  { freeTable(); }\r
+  \r
+  void installKeywordCode (const char* const pszKeyword, int iCode);\r
+  KeywordCodeEntry* lookup (const char* const pszKeyword);\r
+  \r
+private:\r
+  KeywordCodeEntry* m_hashTable[HASHSIZE];\r
+  \r
+  int hash (const char* s);\r
+  void initTable ();\r
+  void freeTable ();\r
+};\r
+\r
+#endif\r
+\r
+\r
index 7ac752595ec83979195bc31d836c8073ccf4501b..262cccbc1c93aa557ac4374d66733c04db7e7e58 100644 (file)
@@ -2,7 +2,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: pol.h,v 1.7 2000/12/27 03:16:02 kevin Exp $
+**  $Id: pol.h,v 1.8 2000/12/27 20:09:19 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
 ******************************************************************************/
 #ifndef __H_POL
 #define __H_POL
-
+\r
+#include "hashtable.h"\r
+\r
 
 class POL {
   
   public:
     
-  // codes for pol_usefile \r
-  enum {\r
-    P_USE_STR = 1,             // use string as input source \r
+    // codes for pol_usefile \r
+    enum {\r
+      P_USE_STR = 1,           // use string as input source \r
       P_USE_FILE,                // use file as input source \r
-  };\r
+    };\r
 \r
   \r
-  POL();
+    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 addSkipWord (const char const *w);
+    void addSkipChar (int c);
+    void addKeyword (const char* const str, int code);
+    bool readWord (char *search, int nlet);
+    bool readUserToken (char *str, int *code);
+    bool readString (char *str);
+    bool readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2);
+    bool readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2);
+    bool skipTokens ();
     void reader ();
-    void gettext (char *str, int lim);
+    bool readText (char *str, int lim);
     void usefile (int source, char *fn);
     void closefile ();
     int lookchar ();
@@ -104,13 +106,6 @@ private:
   \r
 //  typedef std::map<std::string,int> KeywordCodeList;\r
   \r
-  struct symlist {\r
-    char *name;\r
-    int code;\r
-    struct symlist *next;\r
-  };\r
-  typedef struct symlist SYMBOL;\r
-  \r
   struct token_st {\r
     int ready;                         // TRUE if token is ready \r
   //  std::string tokstr;      // token string \r
@@ -121,17 +116,12 @@ private:
     int inum;                      // integer value of token \r
   };\r
   typedef struct token_st TOKEN;\r
-  \r
-  \r
   struct token_st token;                               // current token \r
-  enum {\r
-    HASHSIZE = 100,\r
-  };\r
-  \r
+   \r
   // Tables words stored with install() & found with lookup() \r
-  SYMBOL *skiptable[HASHSIZE];         // words to ignore and skip \r
-  SYMBOL *cmdtable[HASHSIZE];          // pol parameter commands \r
-  SYMBOL *usertable[HASHSIZE];         // user defined symbols \r
+  KeywordCodeHashTable skiptable;              // words to ignore and skip \r
+  KeywordCodeHashTable cmdtable;               // pol parameter commands \r
+  KeywordCodeHashTable usertable;              // user defined symbols \r
   \r
   struct metachar {\r
     char eoc;          /* end of command character */\r
@@ -146,14 +136,9 @@ private:
   } meta;\r
   \r
   \r
-  // current pol state \r
-  struct pol_st {\r
-    char skipchars[MAXSKIPCHAR];       // characters to skip \r
-    int nl_eoc;                                // TRUE if newline character ends a command \r
-    int trace;                         // TRUE if trace is on \r
-  };\r
-  \r
-  struct pol_st pol;\r
+  char m_szSkipChars [MAXSKIPCHAR]; // characters to skip\r
+  bool m_bTrace;\r
+  bool m_bNewlineIsEOC;\r
   \r
   struct KeywordCodeList {\r
     char *keyword;\r
@@ -161,7 +146,7 @@ private:
   };\r
   \r
   static const struct KeywordCodeList cmdlist[];\r
-  static const int NUMCMD;\r
+  static const unsigned int NUMCMD;\r
   \r
   // Internal codes for pol commands \r
   enum {\r
@@ -199,27 +184,22 @@ private:
   int bp;              // pointer to next free position \r
   int buf[BUFSIZE];    // pushed back input characters \r
   \r
-  int skiptok(char term[]);\r
-  int tok(struct token_st *token);\r
-  void dumptok(struct token_st *token);\r
+  bool skipSingleToken (char term[]);\r
+  int tok (struct token_st *token);\r
+  void dumptok (struct token_st *token);\r
   \r
   \r
-  int getpol_tok(struct token_st *token);\r
-  int getcmd();\r
+  int getpol_tok (struct token_st *token);\r
+  int getcmd ();\r
   int gettok (TOKEN *tok);\r
-  void getblank(char *s, int toksiz);\r
-  int getalpha(char *s, int toksiz);\r
-  void getquote(char *qs, int toksiz);\r
-  void getescape(char *s, int delim, int toksiz);\r
+  void getblank (char *s, int toksiz);\r
+  int getalpha (char *s, int toksiz);\r
+  void getquote (char *qs, int toksiz);\r
+  void getescape (char *s, int delim, int toksiz);\r
   int getnumber (char str[], int strsize, double *fnum, int *inum);\r
-  void eatline();\r
-  int type(int c);\r
-  void inittable(SYMBOL *table[]);\r
-  void freetable(SYMBOL *table[]);\r
-  int hash(char *s);\r
-  SYMBOL *lookup(SYMBOL *table[], char *s);\r
-  SYMBOL *install(SYMBOL *table[], char *s, int def);\r
-  int getch(FILE *fp);\r
+  void eatline ();\r
+  int type (int c);\r
+  int getch (FILE *fp);\r
   \r
 };
 
index 383136105a76a91ec5bdf119aec638bf1f3f191c..72f7e5149fbbfdbc9ff0ea53b4b5ed810db6e397 100644 (file)
@@ -6,7 +6,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ezplot.cpp,v 1.24 2000/12/27 03:16:02 kevin Exp $
+**  $Id: ezplot.cpp,v 1.25 2000/12/27 20:09:19 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
@@ -138,14 +138,14 @@ EZPlot::EZPlot (SGP& sgp)
 : rSGP (sgp)
 {
     initKeywords();\r
-    m_pol.skpword ("please");\r
-    m_pol.skpword ("use");\r
-    m_pol.skpword ("are");\r
-    m_pol.skpword ("and");\r
-    m_pol.skpword ("is");\r
-    m_pol.skpword ("the");\r
-    m_pol.skpword ("equals");\r
-    m_pol.skpchar ("=");\r
+    m_pol.addSkipWord ("please");\r
+    m_pol.addSkipWord ("use");\r
+    m_pol.addSkipWord ("are");\r
+    m_pol.addSkipWord ("and");\r
+    m_pol.addSkipWord ("is");\r
+    m_pol.addSkipWord ("the");\r
+    m_pol.addSkipWord ("equals");\r
+    m_pol.addSkipChar ('=');\r
     \r
     m_pol.usefile (POL::P_USE_STR,"");\r
     m_pol.set_inputline ("!eoc ,");\r
index 69131447e5e0da40c8c49475a03c14fe4f2cfc8f..718b2504ec77df2504035502c599ebcf9fea8d9f 100644 (file)
@@ -6,7 +6,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: ezset.cpp,v 1.13 2000/12/27 03:16:02 kevin Exp $
+**  $Id: ezset.cpp,v 1.14 2000/12/27 20:09:19 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
@@ -49,7 +49,7 @@ EZPlot::ezcmd (const char* const comm)
   char str [POL::MAXTOK+1];
   int code;
   bool retval = true;
-  if (! m_pol.usertok (str, &code)) {
+  if (! m_pol.readUserToken (str, &code)) {
     sys_error (ERR_WARNING, "Illegal EZSET command: %s", str);
     m_pol.reader();
     retval = false;
@@ -72,7 +72,7 @@ EZPlot::do_cmd (int lx)
   
   switch (lx) {
   case S_TEXTSIZE:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       if (f >= 0.0 && f <= 1.0) {
         v_textsize = f;
         s_textsize = TRUE;
@@ -87,31 +87,31 @@ EZPlot::do_cmd (int lx)
     clearCurves ();
     break;
   case S_TITLE:
-    m_pol.gettext (strIn, sizeof(strIn));
+    m_pol.readText (strIn, sizeof(strIn));
     c_title = strIn;
     break;
   case S_LEGEND:
-    m_pol.gettext (strIn, sizeof(strIn));\r
+    m_pol.readText (strIn, sizeof(strIn));\r
     if (m_iCurrentCurve >= 0)\r
       setLegend (m_iCurrentCurve, strIn);
     break;
   case S_XLABEL:
-    m_pol.gettext (strIn, sizeof(strIn));
+    m_pol.readText (strIn, sizeof(strIn));
     c_xlabel = strIn;
     break;
   case S_YLABEL:
-    m_pol.gettext (strIn, sizeof(strIn));
+    m_pol.readText (strIn, sizeof(strIn));
     c_ylabel = strIn;
     break;
   case S_XCROSS:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       v_xcross = f;
       s_xcross = TRUE;
     } else
       s_xcross = FALSE;
     break;
   case S_YCROSS:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       v_ycross = f;
       s_ycross = TRUE;
     } else
@@ -144,25 +144,25 @@ EZPlot::do_cmd (int lx)
     s_ymax = FALSE;
     break;
   case S_XMIN:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       v_xmin = f;
       s_xmin = TRUE;
     }
     break;
   case S_XMAX:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       v_xmax = f;
       s_xmax = TRUE;
     }
     break;
   case S_YMIN:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       v_ymin = f;
       s_ymin = TRUE;
     }
     break;
   case S_YMAX:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
       v_ymax = f;
       s_ymax = TRUE;
     }
@@ -173,7 +173,7 @@ EZPlot::do_cmd (int lx)
   case S_DASH:
     int ls;\r
     ls = SGP::LS_DASH1;\r
-    if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {\r
+    if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {\r
       if (n == 1)
         ls = SGP::LS_DASH1;
       else if (n == 2)
@@ -195,7 +195,7 @@ EZPlot::do_cmd (int lx)
     break;
   case S_PEN:
   case S_COLOR:
-    if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
+    if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
     {
       if (n >= 0) {\r
         if (m_iCurrentCurve < 0)
@@ -219,47 +219,47 @@ EZPlot::do_cmd (int lx)
     o_grid = FALSE;
     break;
   case S_XLENGTH:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
       if (f > 0.0 && f <= 1.0)
         o_xlength = f;
       break;
   case S_YLENGTH:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
       if (f > 0.0 && f <= 1.0)
         o_ylength = f;
       break;
   case S_XPORIGIN:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
       if (f >= 0.0 && f < 1.0)
         o_xporigin = f;
       break;
   case S_YPORIGIN:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
       if (f >= 0.0 && f < 1.0)
         o_yporigin = f;
       break;
   case S_TAG:
-    if (m_pol.word("no", 2) == TRUE)
+    if (m_pol.readWord("no", 2) == TRUE)
       o_tag = FALSE;
-    else if (m_pol.word("off", 2) == TRUE)
+    else if (m_pol.readWord("off", 2) == TRUE)
       o_tag = FALSE;
     else
       o_tag = TRUE;
     break;
   case S_LEGENDBOX:
-    if (m_pol.word("inside", 2) == TRUE)
+    if (m_pol.readWord("inside", 2) == TRUE)
       o_legendbox = INSIDE;
-    else if (m_pol.word("outside", 3) == TRUE)
+    else if (m_pol.readWord("outside", 3) == TRUE)
       o_legendbox = OUTSIDE;
-    else if (m_pol.word("none",2) == TRUE)
+    else if (m_pol.readWord("none",2) == TRUE)
       o_legendbox = NOLEGEND;
     else {
-      m_pol.gettext (str, POL::MAXTOK);
+      m_pol.readText (str, POL::MAXTOK);
       bad_option(str);
     }
     break;
   case S_XLEGEND:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
     {
       if (f >= 0.0 && f < 1.0) {
         v_xlegend = f;
@@ -270,7 +270,7 @@ EZPlot::do_cmd (int lx)
     }
     break;
   case S_YLEGEND:
-    if (m_pol.readfloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
+    if (m_pol.readFloat (&f, POL::TT_REAL, FALSE, 0.0, 0.0) == TRUE)
     {
       if (f >= 0.0 && f < 1.0) {
         v_ylegend = f;
@@ -281,7 +281,7 @@ EZPlot::do_cmd (int lx)
     }
     break;
   case S_SYMBOL:
-    if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {
+    if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {
       if (n > 0 && n <= MAXSYMBOL) {
         if (m_iCurrentCurve < 0)\r
           o_symbol = n;\r
@@ -289,8 +289,8 @@ EZPlot::do_cmd (int lx)
           setSymbol (m_iCurrentCurve, n);\r
       }\r
     } else {
-      if (m_pol.word("every",5) == TRUE) {
-        if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {\r
+      if (m_pol.readWord("every",5) == TRUE) {
+        if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {\r
           int sym = 1;
           if (n > 0)\r
             sym = n;\r
@@ -299,22 +299,22 @@ EZPlot::do_cmd (int lx)
           else \r
             setSymbolFreq (m_iCurrentCurve, sym);\r
         }
-      } else if (m_pol.word ("none",4) == TRUE) {
+      } else if (m_pol.readWord ("none",4) == TRUE) {
         o_symbol = -1;
       }
     }
     break;
   case S_CURVE:\r
-    if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {\r
+    if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {\r
       if (n > 0)\r
         m_iCurrentCurve = n - 1;\r
     } else {\r
-      if (m_pol.word ("all",3) == TRUE) \r
+      if (m_pol.readWord ("all",3) == TRUE) \r
         m_iCurrentCurve = -1;\r
     }\r
     break;\r
   case S_XTICKS:
-    if (m_pol.usertok(str,&lx) == FALSE)
+    if (m_pol.readUserToken(str,&lx) == FALSE)
       break;
     if (lx == S_ABOVE)
       o_xticks = ABOVE;
@@ -325,16 +325,16 @@ EZPlot::do_cmd (int lx)
     else if (lx == S_LABEL)
       o_xtlabel = TRUE;
     else if (lx == S_MAJOR) {
-      if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
+      if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
         if (n > 1 && n < 100)
           o_xmajortick = n;
     } else if (lx == S_MINOR)
-      if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
+      if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
         if (n >= 0 && n < 100)
           o_xminortick = n;
         break;
   case S_YTICKS:
-    if (m_pol.usertok(str,&lx) == FALSE)
+    if (m_pol.readUserToken(str,&lx) == FALSE)
       break;
     if (lx == S_RIGHT)
       o_yticks = RIGHT;
@@ -345,16 +345,16 @@ EZPlot::do_cmd (int lx)
     else if (lx == S_LABEL)
       o_ytlabel = TRUE;
     else if (lx == S_MAJOR) {
-      if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
+      if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
         if (n > 1 && n < 100)
           o_ymajortick = n;
     } else if (lx == S_MINOR)
-      if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
+      if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE)
         if (n >= 0 && n < 100)
           o_yminortick = n;
         break;
   case S_LXFRAC:
-    if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {
+    if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {
       if (n >= 0) {
         v_lxfrac = n;
         s_lxfrac = TRUE;
@@ -363,7 +363,7 @@ EZPlot::do_cmd (int lx)
       s_lxfrac = FALSE;
     break;
   case S_LYFRAC:
-    if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {
+    if (m_pol.readInteger (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) {
       if (n >= 0) {
         v_lyfrac = n;
         s_lyfrac = TRUE;
@@ -480,6 +480,5 @@ void
 EZPlot::initKeywords ()
 {
   for (int i = 0; i < NKEYS; i++)
-    if (! m_pol.installKeyword (m_sKeywords[i].keyword, m_sKeywords [i].code))
-      sys_error (ERR_SEVERE, "error installing ezset keywords [EZPlot::initKeywords]");
+    m_pol.addKeyword (m_sKeywords[i].keyword, m_sKeywords [i].code);
 }
index f3ef311a614dccad8c07b1a51251f4b010e462fe..1d1a13ab31470cd7bb71fdf560204a3d87cbdfb5 100644 (file)
@@ -6,7 +6,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: pol.cpp,v 1.6 2000/12/27 03:16:02 kevin Exp $
+**  $Id: pol.cpp,v 1.7 2000/12/27 20:09:19 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
@@ -21,8 +21,6 @@
 **  along with this program; if not, write to the Free Software
 **  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 ******************************************************************************/
-/*                                                                     */
-/*----------------------------------------------------------------------*/
 
 #include "ct.h"\r
 #include <math.h>
@@ -32,9 +30,6 @@
 #include "pol.h"
 
 
-
-
-
 const struct POL::KeywordCodeList POL::cmdlist[] = {
   {    "eoc",  PC_EOC,},
   {    "str",  PC_STR,},
@@ -45,7 +40,7 @@ const struct POL::KeywordCodeList POL::cmdlist[] = {
   {    "out",  PC_OUT,},
   {    "ter",  PC_TER,},
   {    "inb",  PC_INB,},
-
+  
   {    "nl_eoc",PC_NL_EOC,},
   {    "nl_neoc", PC_NL_NEOC,},
   {    "tron",  PC_TRON,},
@@ -54,13 +49,14 @@ const struct POL::KeywordCodeList POL::cmdlist[] = {
   {    "dump",  PC_DUMP,},
 };
 
-const int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::KeywordCodeList));
+const unsigned int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::KeywordCodeList));
 \r
 
 POL::POL()
 {
   bp = 0;
-  currentf = -1;
+  currentf = -1;\r
+  m_bTrace = false;
   init();
 }
 
@@ -71,52 +67,53 @@ POL::~POL()
 void 
 POL::init ()
 {
-       meta.eoc    = SEMICOL;
-       meta.str    = DQUOTE;
-       meta.com    = SHARP;
-       meta.cmd    = EXCLAM;
-       meta.prg    = ATSIGN;
-       meta.con    = AMPERSAND;
-       meta.out    = DOLLAR;
-       meta.ter    = PERCENT;
-       meta.inb    = LBRACK;
-
-       pol.nl_eoc = TRUE;
-       pol.skipchars[0] = EOS;
-
-       inittable (cmdtable);           /* initialize symbol tables */
-       inittable (usertable);
-       inittable (skiptable);
-
-       for (unsigned int i = 0; i < NUMCMD; i++)
-           install (cmdtable, cmdlist[i].keyword, cmdlist[i].code);
-
-       token.ready = FALSE;            /* no token read yet */
+  meta.eoc    = SEMICOL;
+  meta.str    = DQUOTE;
+  meta.com    = SHARP;
+  meta.cmd    = EXCLAM;
+  meta.prg    = ATSIGN;
+  meta.con    = AMPERSAND;
+  meta.out    = DOLLAR;
+  meta.ter    = PERCENT;
+  meta.inb    = LBRACK;
+  
+  m_bNewlineIsEOC = true;\r
+  m_szSkipChars[0] = EOS;
+  
+  
+  for (unsigned int i = 0; i < NUMCMD; i++)
+    cmdtable.installKeywordCode (cmdlist[i].keyword, cmdlist[i].code);
+  
+  token.ready = false;         // no token read yet 
 }
+\r
 
-/* skpword (w)
- *
- * char *w - word for pol to ignore and skip over in input
- *
- * tok() compares all tokens to words given to this routine. If it finds it,
- * it will immediately read another token. 
- */
+/* addSkipWord (w)
+*
+* char *w - word for pol to ignore and skip over in input
+*
+* tok() compares all tokens to words given to this routine. If it finds it,
+* it will immediately read another token. 
+*/
 
 void 
-POL::skpword (char *w)
+POL::addSkipWord (const char* const w)
 {
-       if (install (skiptable, w, 0) == NULL)
-           sys_error (ERR_SEVERE, "Too many skip words defined");
+  skiptable.installKeywordCode (w, 0);
 }
 
 /* skpchar (s)
- *
- * skip all characters that appear in string s
- */
+*
+* skip all characters that appear in string s
+*/
 void 
-POL::skpchar (char *s)
-{
-       strncpy (pol.skipchars, s, MAXSKIPCHAR);
+POL::addSkipChar (int c)
+{\r
+  int n = strlen (m_szSkipChars);\r
+  if (n < MAXSKIPCHAR) {\r
+    m_szSkipChars[n] = c;\r
+    m_szSkipChars[n+1] = 0;\r
+  }
 }
 
 // installKeyword (str, code)
@@ -126,466 +123,460 @@ POL::skpchar (char *s)
 //
 // tok() looks for these user defined tokens.  If it finds one,
 // it stores the tokens code in the token structure and returns TT_USERTOK
-int 
-POL::installKeyword (char *str, int code)
+void\r
+POL::addKeyword (const char* const str, int code)
 {
-    if (install (usertable, str, code) == NULL)
-       {
-           sys_error  (ERR_SEVERE, "Out of memory installing user tokens");
-           return (FALSE);
-       }
-    
-    return(TRUE);
+  usertable.installKeywordCode (str, code);
 }
 
 /* get_word - matches tokens on a letter by letter basis
- *
- * char *search - string to search for
- * int  nlet   - maximum number of chars to search for match
- */
+*
+* char *search - string to search for
+* int  nlet    - maximum number of chars to search for match
+*/
 
-int 
-POL::word (char *search, int nlet)
+bool 
+POL::readWord (char *search, int nlet)
 {
-       tok (&token);
-       if (pol.trace == TRUE)
-           printf ("matching current token %s against word %s\n", token.tokstr, search);
-
-       if (strncasecmp (search, token.tokstr, nlet) == 0) {
-           dumptok (&token);
-           return (TRUE);
-       } else
-           return (FALSE);
+  tok (&token);
+  if (m_bTrace)
+    sys_error (ERR_TRACE, "POL matching current token %s against word %s\n", token.tokstr, search);
+  
+  if (strncasecmp (search, token.tokstr, nlet) == 0) {
+    dumptok (&token);
+    return (true);
+  } else
+    return (false);
 }
 
 /* usertok (str,code)
- *     see if current token is a user defined token set with install()
- *
- *    char *str - token string as read from input
- *    int *code - returned code for user defined symbol
- *    return value - TRUE if current token has been user defined
- *                  FALSE if current token is not user defined
- */
-int 
-POL::usertok (char *str, int *code)
-{
-       tok (&token);
-
-       if (pol.trace == TRUE)
-           printf ("checking if current token '%s' is user defined\n", token.tokstr);
-
-       if (token.type == TT_USERTOK) {
-           *code = token.code;
-           strcpy (str, token.tokstr);
-           dumptok (&token);
-           return (TRUE);
-       } else {
-           *code = 0;
-           return (FALSE);
-       }
+     see if current token is a user defined token set with install()
+*
+*    char *str - token string as read from input
+*    int *code - returned code for user defined symbol
+*    return value - true if current token has been user defined
+*                   false if current token is not user defined
+*/
+bool
+POL::readUserToken (char *str, int *code)
+{
+  tok (&token);
+  
+  if (m_bTrace)
+    sys_error (ERR_TRACE, "POL checking if current token '%s' is user defined\n", token.tokstr);
+  
+  if (token.type == TT_USERTOK) {
+    *code = token.code;
+    strcpy (str, token.tokstr);
+    dumptok (&token);
+    return (true);
+  } else {
+    *code = 0;
+    return (false);
+  }
 }
 
-/* isstring (s) - returns TRUE if current token is a string
- *
- * char *s - pointer to place to store token string
+/* isstring (s) - returns true if current token is a string
+*
+* char *s - pointer to place to store token string
 */
-int 
-POL::string (char *str)
-{
-       tok (&token);
 
-       if (token.type == TT_STRING) {
-           strcpy (str, token.tokstr);
-           dumptok (&token);
-           return (TRUE);
-       } else
-           return (FALSE);
+bool
+POL::readString (char *str)
+{
+  tok (&token);
+  
+  if (token.type == TT_STRING) {
+    strcpy (str, token.tokstr);
+    dumptok (&token);
+    return (true);
+  } else
+    return (false);
 }
 
 /* integer - test for an integer
- *
- * int *n:     returned integer value
- * int typecode = TT_INT if accept only integer values
- *             = TT_REAL if accept both real and integer values
- * int boundcode= TRUE if force to lie between boundries
- *             = FALSE can take any value it likes
- * int bb1:    lower bound
- * int bb2:    upper bound
+*
+* int *n:      returned integer value
+* int typecode = TT_INT if accept only integer values
+             = TT_REAL if accept both real and integer values
+* int boundcode= true if force to lie between boundries
+*              = false can take any value it likes
+* int bb1:     lower bound
+* int bb2:     upper bound
 */
-int 
-POL::integer (int *n, int typecode, int boundcode, int bb1, int bb2)
-{
-       tok (&token);
-
-       if (pol.trace == TRUE)
-           printf ("checking if current token %s is an integer\n", token.tokstr);
-
-       if (token.type == TT_INT || token.type == TT_REAL) {
-          if (boundcode == TRUE) {
-               if (token.inum < bb1)
-                  *n = bb1;
-               else if (token.inum > bb2)
-                  *n = bb2;
-               else
-                   *n = token.inum;
+bool 
+POL::readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2)
+{
+  tok (&token);
+  
+  if (m_bTrace)
+    sys_error (ERR_TRACE, "POL checking if current token %s is an integer\n", token.tokstr);
+  
+  if (token.type == TT_INT || token.type == TT_REAL) {
+          if (boundcode) {
+       if (token.inum < bb1)
+         *n = bb1;
+       else if (token.inum > bb2)
+         *n = bb2;
+       else
+         *n = token.inum;
            } else
-               *n = token.inum;
-           dumptok (&token);
-           return (TRUE);
-       }
-       *n = 0;
-       return (FALSE);
+        *n = token.inum;
+      dumptok (&token);
+      return (true);
+  }
+  *n = 0;
+  return (false);
 }
 
 bool\r
-POL::readfloat (double *n, double typecode, double boundcode, double bb1, double bb2)
-{
-       tok (&token);
-
-       if (pol.trace == TRUE)
-           printf ("checking if current token %s is an floating point number\n", token.tokstr);
-
-       if (token.type == TT_INT || token.type == TT_REAL) {
-          if (boundcode == TRUE) {
-               if (token.fnum < bb1)
-                  *n = bb1;
-               else if (token.fnum > bb2)
-                  *n = bb2;
-               else
-                   *n = token.fnum;
+POL::readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2)
+{
+  tok (&token);
+  
+  if (m_bTrace)
+    sys_error (ERR_TRACE, "POL checking if current token %s is an floating point number\n", token.tokstr);
+  
+  if (token.type == TT_INT || token.type == TT_REAL) {
+          if (boundcode) {
+       if (token.fnum < bb1)
+         *n = bb1;
+       else if (token.fnum > bb2)
+         *n = bb2;
+       else
+         *n = token.fnum;
            } else
-               *n = token.fnum;
-           dumptok (&token);
-           return (TRUE);
-       }
-       *n = 0.0;
-       return (FALSE);
+        *n = token.fnum;
+      dumptok (&token);
+      return (true);
+  }
+  *n = 0.0;
+  return (false);
 }
 
 /*----------------------------------------------------------------------*/
 /* skip() - skip over any token except for end of command sequence     */
 /*                                                                     */
-/*             returns TRUE if succesful skip                          */
-/*             returns FALSE if already at end of command or EOF       */
+/*             returns true if succesful skip                          */
+/*             returns false if already at end of command or EOF       */
 /*----------------------------------------------------------------------*/
 
-int 
-POL::skip()
+bool 
+POL::skipTokens()
 {
-       char term[5];           /* string of characters not to skip */
-
-       term[0] = meta.eoc;
-       if (pol.nl_eoc == TRUE) {
-           term[1] = NEWLINE;
-           term[2] = EOS;
-       } else
-           term[1] = EOS;
-
-       return (skiptok (term));
+  char term[5];                /* string of characters not to skip */
+  
+  term[0] = meta.eoc;
+  if (m_bNewlineIsEOC) {
+    term[1] = NEWLINE;
+    term[2] = EOS;
+  } else
+    term[1] = EOS;
+  
+  return (skipSingleToken (term));
 }
 
 void \r
 POL::reader()
 {
-       while (skip() == TRUE)
-           ;
-
-       dumptok (&token);               /* skip end of command token */
+  while (skipTokens())
+    ;
+  
+  dumptok (&token);            /* skip end of command token */
 }
 
 /* skiptok (term) - skip a token unless the first character of a token is
- *                 in the string of terminators, term.
- * char *term - string of termination characters, don't skip these characters
- *             skiptok() also does NOT skip TT_EOF
- * returns (TRUE) if succesful skip of a token
- * returns (FALSE) if didn't skip, read termination character or TT_EOF
- */
-
-int 
-POL::skiptok (char term[])
-{
-       tok (&token);
+*                  in the string of terminators, term.
+* char *term - string of termination characters, don't skip these characters
+*              skiptok() also does NOT skip TT_EOF
+* returns (true) if succesful skip of a token
+* returns (false) if didn't skip, read termination character or TT_EOF
+*/
 
-       if (token.type == TT_EOF
-       || (token.type == TT_SPECLCHAR && strchr(term, token.tokstr[0]) != NULL))
-               return (FALSE);
-       else {
-           dumptok (&token);
-           return (TRUE);
-       }
+bool 
+POL::skipSingleToken (char term[])
+{
+  tok (&token);
+  
+  if (token.type == TT_EOF
+    || (token.type == TT_SPECLCHAR && strchr(term, token.tokstr[0]) != NULL))
+    return (false);
+  else {
+    dumptok (&token);
+    return (true);
+  }
 }
 
 int 
 POL::tok (struct token_st *token)
 {
-       if (token->ready == FALSE)
-           getpol_tok(token);
-       else
-           if (token->type == TT_EOF && lookchar() != EOF)
-               getpol_tok(token);
-       return (token->type);
+  if (token->ready == false)
+    getpol_tok(token);
+  else
+    if (token->type == TT_EOF && lookchar() != EOF)
+      getpol_tok(token);
+    return (token->type);
 }
 
 void 
 POL::dumptok (struct token_st *token)
 {
-       if (token->ready == FALSE)
-           getpol_tok(token);
-       token->ready = FALSE;
+  if (token->ready == false)
+    getpol_tok(token);
+  token->ready = false;
 }
 
 int 
 POL::getpol_tok (struct token_st *token)
 {
-       SYMBOL *sym;
-
-       token->ready = FALSE;
+  KeywordCodeEntry* sym;
+  
+  token->ready = false;
 nexttok:
-       gettok (token);
-
-       if (token->type == TT_BLANK)
-           goto nexttok;
-       if (token->type == TT_SPECLCHAR) {
-           if (strchr(pol.skipchars, token->tokstr[0]) != NULL)
-               goto nexttok;
-           if (token->tokstr[0] == NEWLINE)
-               goto nexttok;
-           if (token->tokstr[0] == meta.cmd) {
-               getcmd();
-               goto nexttok;
-           }
-           if (token->tokstr[0] == meta.com) {         /* skip comment */
-               eatline ();
-               goto nexttok;
-           }
-           if (token->tokstr[0] == meta.out) {
-               getescape(token->tokstr, meta.out, MAXTOK);
-               fputs (token->tokstr, stderr);
-               goto nexttok;
-           }
-           if (token->tokstr[0] == meta.con) {         /* continuation across NEWLINE */
-               while (lookchar() == BLANK || lookchar() == TAB)
-                   inchar();
-               if (lookchar() == NEWLINE)
-                   inchar();
-           }
-           if (token->tokstr[0] == meta.ter) {         /* get input from terminal */
-               usefile (P_USE_FILE, "");
-               tok (token);
-               closefile();
-               return (token->type);
-           }
-       }
-
-       /* look for filler words */
-
-       if (lookup (skiptable, token->tokstr) != NULL)  /* ignore words in skip table */
-           goto nexttok;
-
-       /* look for user defined symbols */
-
-       if ((sym = lookup (usertable, token->tokstr)) != NULL) {
-           token->type = TT_USERTOK;
-           token->code = sym->code;
-       } else
-           token->code = 0;
-
-       if (pol.trace == TRUE)
-           printf ("Read token '%s', type = %d\n", token->tokstr, token->type);
-
-       return (token->type);
+  gettok (token);
+  
+  if (token->type == TT_BLANK)
+    goto nexttok;
+  if (token->type == TT_SPECLCHAR) {
+    if (strchr(m_szSkipChars, token->tokstr[0]) != NULL)
+      goto nexttok;
+    if (token->tokstr[0] == NEWLINE)
+      goto nexttok;
+    if (token->tokstr[0] == meta.cmd) {
+      getcmd();
+      goto nexttok;
+    }
+    if (token->tokstr[0] == meta.com) {                /* skip comment */
+      eatline ();
+      goto nexttok;
+    }
+    if (token->tokstr[0] == meta.out) {
+      getescape(token->tokstr, meta.out, MAXTOK);
+      fputs (token->tokstr, stderr);
+      goto nexttok;
+    }
+    if (token->tokstr[0] == meta.con) {                /* continuation across NEWLINE */
+      while (lookchar() == BLANK || lookchar() == TAB)
+        inchar();
+      if (lookchar() == NEWLINE)
+        inchar();
+    }
+    if (token->tokstr[0] == meta.ter) {                /* get input from terminal */
+      usefile (P_USE_FILE, "");
+      tok (token);
+      closefile();
+      return (token->type);
+    }
+  }
+  
+  /* look for filler words */
+  
+  if (skiptable.lookup (token->tokstr) != NULL)        /* ignore words in skip table */
+    goto nexttok;
+  
+  /* look for user defined symbols */
+  
+  if ((sym = usertable.lookup (token->tokstr)) != NULL) {
+    token->type = TT_USERTOK;
+    token->code = sym->getCode();
+  } else
+    token->code = 0;
+  
+  if (m_bTrace)
+    sys_error (ERR_TRACE, "POL read token '%s', type = %d\n", token->tokstr, token->type);
+  
+  return (token->type);
 }
 
 
 int 
 POL::getcmd()
 {
-       int tt, found;
-       char str[MAXTOK+1];
-       SYMBOL *cmd;
-       TOKEN tok;
-
-       tt = getalpha (str, MAXTOK);
-       if (tt == TT_ERROR) {
-           sys_error (ERR_WARNING, "Error in POL parameter command");
-           reader();
-           return(FALSE);
-       }
-       if ((cmd = lookup (cmdtable,str)) == NULL) {
-           sys_error  (ERR_WARNING, "POL: Unrecognized command %s", cmd);
-           reader();
-           return (FALSE);
-       } else {
-           found = FALSE;
-           switch (cmd->code) {
-               case PC_TRON:
-                   pol.trace = TRUE;
-                   found = TRUE;
-                   break;
-               case PC_TROFF:
-                   pol.trace = FALSE;
-                   found = TRUE;
-                   break;
-               case PC_FILE:
-                   found = TRUE;
-                   tt = gettok (&tok);
-                   usefile (P_USE_FILE, tok.tokstr);
-                   break;
-               case PC_NL_EOC:
-                   found = TRUE;
-                   pol.nl_eoc = TRUE;
-                   break;
-               case PC_NL_NEOC:
-                   found = TRUE;
-                   pol.nl_eoc = FALSE;
-                   break;
-               case PC_DUMP:
-                   found = TRUE;
-                   printf("eoc = %c  str = %c  com = %c  cmd = %c  prg = %c\n",
-                       meta.eoc, meta.str, meta.com, meta.cmd, meta.prg);
-                   printf("con = %c  out = %c  ter = %c  inb = %c\n",
-                       meta.con, meta.out, meta.ter, meta.inb);
-                   break; 
-           }
-           if (found == FALSE) {
-               tt = gettok (&tok);
-               if (tt != TT_SPECLCHAR) {
-                   sys_error (ERR_SEVERE, "POL: Illegal command character");
-                   return (FALSE);
-               }
-               switch(cmd->code) {
+  int tt, found;
+  char str[MAXTOK+1];
+  KeywordCodeEntry *cmd;
+  TOKEN tok;
+  
+  tt = getalpha (str, MAXTOK);
+  if (tt == TT_ERROR) {
+    sys_error (ERR_WARNING, "Error in POL parameter command");
+    reader();
+    return(false);
+  }
+  if ((cmd = cmdtable.lookup (str)) == NULL) {
+    sys_error  (ERR_WARNING, "POL: Unrecognized command %s", cmd);
+    reader();
+    return (false);
+  } else {
+    found = false;
+    switch (cmd->getCode()) {
+    case PC_TRON:
+                   m_bTrace = true;
+        found = true;
+        break;
+    case PC_TROFF:
+                   m_bTrace = false;
+        found = true;
+        break;
+    case PC_FILE:
+                   found = true;
+        tt = gettok (&tok);
+        usefile (P_USE_FILE, tok.tokstr);
+        break;
+    case PC_NL_EOC:
+                   found = true;
+        m_bNewlineIsEOC = true;
+        break;
+    case PC_NL_NEOC:
+                   found = true;
+        m_bNewlineIsEOC = false;
+        break;
+    case PC_DUMP:
+                   found = true;
+        printf("eoc = %c  str = %c  com = %c  cmd = %c  prg = %c\n",
+          meta.eoc, meta.str, meta.com, meta.cmd, meta.prg);
+        printf("con = %c  out = %c  ter = %c  inb = %c\n",
+          meta.con, meta.out, meta.ter, meta.inb);
+        break; 
+    }
+    if (found == false) {
+      tt = gettok (&tok);
+      if (tt != TT_SPECLCHAR) {
+        sys_error (ERR_SEVERE, "POL: Illegal command character");
+        return (false);
+      }
+      switch(cmd->getCode()) {
                    case PC_EOC:
-                       meta.eoc = tok.tokstr[0];
-                       break;
-                   case PC_STR:
-                       meta.str = tok.tokstr[0];
-                       break;
-                   case PC_COM:
-                       meta.com = tok.tokstr[0];
-                       break;
-                   case PC_CMD:
-                       meta.cmd = tok.tokstr[0];
-                       break;
-                   case PC_PRG:
-                       meta.prg = tok.tokstr[0];
-                       break;
-                   case PC_CON:
-                       meta.con = tok.tokstr[0];
-                       break;
-                   case PC_OUT:
-                       meta.out = tok.tokstr[0];
-                       break;
-                   case PC_TER:
-                       meta.ter = tok.tokstr[0];
-                       break;
-                   case PC_INB:
-                       meta.inb = tok.tokstr[0];
-                       break;
-                   default:
-                       printf("command not implemented\n");
-                       break;
-               }                               /* switch (tok->type) */
-           }                                   /* if (found == FALSE) */
-           reader();                   /* clean up command */
-       }                                       /* if legal command */
-
-       return (TRUE);
+          meta.eoc = tok.tokstr[0];
+          break;
+        case PC_STR:
+          meta.str = tok.tokstr[0];
+          break;
+        case PC_COM:
+          meta.com = tok.tokstr[0];
+          break;
+        case PC_CMD:
+          meta.cmd = tok.tokstr[0];
+          break;
+        case PC_PRG:
+          meta.prg = tok.tokstr[0];
+          break;
+        case PC_CON:
+          meta.con = tok.tokstr[0];
+          break;
+        case PC_OUT:
+          meta.out = tok.tokstr[0];
+          break;
+        case PC_TER:
+          meta.ter = tok.tokstr[0];
+          break;
+        case PC_INB:
+          meta.inb = tok.tokstr[0];
+          break;
+        default:
+          printf("command not implemented\n");
+          break;
+                                     /* switch (tok->type) */
+    }                                  /* if (found == false) */
+    reader();                  /* clean up command */
+  }                                    /* if legal command */
+  
+  return (true);
 }
 
 
 int 
 POL::gettok (TOKEN *tok)
 {
-       int c, toktype;
-       int inum;
-       double fnum;
-       int toksiz = MAXTOK;            /* maximum length of token string */
-
-       while ((c = inchar()) == BLANK || c == TAB)
-           ;
-       ungetch (c);
-
-       c = lookchar();
-       toktype = type(c);
-
-       fnum = 0.0;
-       inum = 0;
-
-       if (c == BLANK || c == TAB) {                   /* skip white space */
-           getblank(tok->tokstr, toksiz);
-           toktype = TT_BLANK;
-       } else if (toktype == LETTER) {
-           toktype = getalpha (tok->tokstr, toksiz);
-       } else if (c == meta.str) {                     /* quoted string */
-           getquote (tok->tokstr, toksiz);
-           toktype = TT_STRING;
-       } else if (type(c) == DIGIT || c == PLUS || c == HYPHEN || c == PERIOD) {
-           toktype = getnumber (tok->tokstr, toksiz, &fnum, &inum);
-       } else if (c == EOF) {
-           tok->tokstr[0] = EOS;
-           toktype = TT_EOF;
-       } else {
-           c = inchar();
-           tok->tokstr[0] = c;
-           tok->tokstr[1] = EOS;
-           toktype = TT_SPECLCHAR;
-       }
-
-       tok->type = toktype;
-       tok->ready = TRUE;
-       if (tok->type == TT_REAL || tok->type == TT_INT) {
-           tok->fnum = fnum;
-           tok->inum = inum;
-       } else {
-           tok->fnum = 0.0;
-           tok->inum = 0;
-       }
-
-       return (toktype);
+  int c, toktype;
+  int inum;
+  double fnum;
+  int toksiz = MAXTOK;         /* maximum length of token string */
+  
+  while ((c = inchar()) == BLANK || c == TAB)
+    ;
+  ungetch (c);
+  
+  c = lookchar();
+  toktype = type(c);
+  
+  fnum = 0.0;
+  inum = 0;
+  
+  if (c == BLANK || c == TAB) {                        /* skip white space */
+    getblank(tok->tokstr, toksiz);
+    toktype = TT_BLANK;
+  } else if (toktype == LETTER) {
+    toktype = getalpha (tok->tokstr, toksiz);
+  } else if (c == meta.str) {                  /* quoted string */
+    getquote (tok->tokstr, toksiz);
+    toktype = TT_STRING;
+  } else if (type(c) == DIGIT || c == PLUS || c == HYPHEN || c == PERIOD) {
+    toktype = getnumber (tok->tokstr, toksiz, &fnum, &inum);
+  } else if (c == EOF) {
+    tok->tokstr[0] = EOS;
+    toktype = TT_EOF;
+  } else {
+    c = inchar();
+    tok->tokstr[0] = c;
+    tok->tokstr[1] = EOS;
+    toktype = TT_SPECLCHAR;
+  }
+  
+  tok->type = toktype;
+  tok->ready = true;
+  if (tok->type == TT_REAL || tok->type == TT_INT) {
+    tok->fnum = fnum;
+    tok->inum = inum;
+  } else {
+    tok->fnum = 0.0;
+    tok->inum = 0;
+  }
+  
+  return (toktype);
 }
 
 
 void 
 POL::getblank (char *s, int toksiz)
 {
-       int c;
-
-       while ((c = inchar()) == BLANK || c == TAB)
-             ;
-       ungetch(c);
-
-       s[0] = BLANK;
-       s[1] = EOS;
+  int c;
+  
+  while ((c = inchar()) == BLANK || c == TAB)
+    ;
+  ungetch(c);
+  
+  s[0] = BLANK;
+  s[1] = EOS;
 }
 
 
 int 
 POL::getalpha (char *s, int toksiz)
 {
-       int i, chartype, alphatype;
-
-       if (type(lookchar()) != LETTER) {
-           s[0] = EOS;
-           return (TT_ERROR);
-       }
-
-       alphatype = TT_ALPHA;
-       for (i = 0; i < toksiz; i++) {          /* get alphanumeric token */
-           s[i] = inchar();
-           chartype = type (s[i]);
-           if (chartype != LETTER && chartype != DIGIT)
-               break;
-           if (chartype == DIGIT)
-               alphatype = TT_ALPNUM;
-       }
-       ungetch(s[i]);
-
-       if (i >= toksiz)
-           sys_error (ERR_SEVERE, "POL token too long.");
-
-       s[i] = EOS;                     /* terminate token */
-       return (alphatype);
+  int i, chartype, alphatype;
+  
+  if (type(lookchar()) != LETTER) {
+    s[0] = EOS;
+    return (TT_ERROR);
+  }
+  
+  alphatype = TT_ALPHA;
+  for (i = 0; i < toksiz; i++) {               /* get alphanumeric token */
+    s[i] = inchar();
+    chartype = type (s[i]);
+    if (chartype != LETTER && chartype != DIGIT)
+      break;
+    if (chartype == DIGIT)
+      alphatype = TT_ALPNUM;
+  }
+  ungetch(s[i]);
+  
+  if (i >= toksiz)
+    sys_error (ERR_SEVERE, "POL token too long.");
+  
+  s[i] = EOS;                  /* terminate token */
+  return (alphatype);
 }
 
 
@@ -594,57 +585,64 @@ POL::getalpha (char *s, int toksiz)
 void 
 POL::getquote (char *qs, int toksiz)
 {
-       int delim;
-
-       delim = inchar();                       /* char = delimiter */
-       getescape(qs, delim, toksiz);
+  int delim;
+  
+  delim = inchar();                    /* char = delimiter */
+  getescape(qs, delim, toksiz);
 }
 
 
 void 
 POL::getescape (       /* reads up to delim */
-    char *s,
-    int delim,
-    int toksiz
-)
-{
-       int i, c;
-
-       for (i = 0; (c = inchar()) != delim; i++) {
-           if (c == NEWLINE) {
-               sys_error (ERR_WARNING, "Missing closing delimiter.");
-               break;
-           }
-           if (i >= toksiz) {
-               sys_error (ERR_SEVERE, "string too long.");
-               break;
-           }
-           if (c == EOF) {
-               ungetch(c);
-               sys_error (ERR_SEVERE, "end of file inside quotation");
-               break;
-           } else if (c == BSLASH) {   /* escape character */
-               s[i++] = c;
-               c = inchar();           /* get escaped character */
-           }
-           s[i] = c;
-       }
-       s[i] = EOS;
+                char *s,
+                int delim,
+                int toksiz
+                )
+{
+  int i, c;
+  
+  for (i = 0; (c = inchar()) != delim; i++) {
+    if (c == NEWLINE) {
+      sys_error (ERR_WARNING, "Missing closing delimiter.");
+      break;
+    }
+    if (i >= toksiz) {
+      sys_error (ERR_SEVERE, "string too long.");
+      break;
+    }
+    if (c == EOF) {
+      ungetch(c);
+      sys_error (ERR_SEVERE, "end of file inside quotation");
+      break;
+    } else if (c == BSLASH) {  /* escape character */
+      s[i++] = c;
+      c = inchar();            /* get escaped character */
+    }
+    s[i] = c;
+  }
+  s[i] = EOS;
 }
+\r
 
-void 
-POL::gettext (char *str, int lim)
-{
-       int c, i;
-
-       while ((c = inchar()) == BLANK || c == TAB)
-           ;
-       ungetch (c);
-
-       for (i = 0; i < lim && (c = inchar()) != EOF && c != NEWLINE; i++)
-           str[i] = c;
-       ungetch (c);
-       str[i] = EOS;
+bool 
+POL::readText (char *str, int lim)
+{
+  int c;
+  while ((c = inchar()) == BLANK || c == TAB)
+    ;
+  ungetch (c);
+  if (c == EOF) {\r
+    str[0] = 0;\r
+    return false;\r
+  }\r
+  \r
+  int i;
+  for (i = 0; i < lim && (c = inchar()) != EOF && c != NEWLINE; i++)
+    str[i] = c;
+  ungetch (c);
+  str[i] = 0;\r
+  \r
+  return true;
 }
 
 //----------------------------------------------
@@ -654,257 +652,161 @@ POL::gettext (char *str, int lim)
 int 
 POL::getnumber 
 (
-    char str[],                                /* string to return token in */
-    int strsize,                               /* maximum length of token string */
-    double *fnum,                              /* floating point value of number read */
-    int *inum                          /* integer value of number read */
-)
-{
-       int c, sp, isSigned;
-       double sign, whole, frac, powerof10, exp, expsign;
-
-       sp = 0;
-       sign = 1.0;
-       isSigned = FALSE;               /* TRUE if number prefixed by '+' or '-' */ 
-       *fnum = 0.0;
-       *inum = 0;
-       str[0] = EOS;
-
-       c = inchar();
-       if (c == HYPHEN) {
-           str[sp++] = c;
-           isSigned = TRUE;
-           sign = -1.0;
-       } else if (c == PLUS) {
-           str[sp++] = c;
-           isSigned = TRUE;
-           sign = 1.0;
-       } else if (c == PERIOD) {
-           if (type(lookchar()) != DIGIT) {
-               str[0] = PERIOD;
-               str[1] = EOS;
-               return (TT_SPECLCHAR);
-           } else
-               ungetch (PERIOD);
-       } else if (type(c) != DIGIT) {
-           ungetch (c);
-           return (TT_ERROR);
-       } else
-           ungetch (c);
-
-       if (isSigned == TRUE) {
-           c = lookchar();
-           if (c == PERIOD) {
-               inchar();               /* get period */
-               c = lookchar();         /* look at character past period */
-               ungetch (PERIOD);       /* put back period */
-               if (type(c) != DIGIT) {
-                   str[sp] = EOS;
-                   return (TT_SPECLCHAR);
-               }
-           } else if (type (c) != DIGIT) {
-               str[sp] = EOS;
-               return (TT_SPECLCHAR);
-           }
-       }
-
-       whole = 0.0;
-       while (type(c = inchar()) == DIGIT) {
-           if (sp < strsize)
-               str[sp++] = c;
-           whole = 10.0 * whole + (c - '0');
-       }
-       ungetch (c);            /* put back non-numeric character */
-
-       if (c != PERIOD && tolower(c) != 'e') {
-           str[sp] = EOS;
-           *fnum = whole * sign;
-           if (*fnum < MIN_INT)
-               *inum = MIN_INT;
-           else if (*fnum > MAX_INT)
-               *inum = MAX_INT;
-           else
-               *inum = (int) *fnum;
-           return (TT_INT);
-       }
-
-       if (lookchar() == PERIOD) {
-           inchar();
-           if (sp < strsize)
-               str[sp++] = PERIOD;
-       }
-
-       frac = 0.0;
-       powerof10 = 10.0;
-
-       while (type(c = inchar()) == DIGIT) {
-           if (sp < strsize)
-               str[sp++] = c;
-           frac += (double) (c - '0') / powerof10;
-           powerof10 *= 10.0;
-       }
-       ungetch (c);
-
-       exp = 0.0;
-       expsign = 1.0;
-       c = inchar();
-       if (tolower(c) != 'e')
-           ungetch (c);
-       else {
-           if (sp < strsize)
-               str[sp++] = c;
-           if ((c = inchar()) == PLUS) {
-               if (sp < strsize)
-                   str[sp++] = c;
-               expsign = 1.0;
-           } else if (c == HYPHEN) {
-               if (sp < strsize)
-                   str[sp++] = c;
-               expsign = -1.0;
-           } else if (type(c) != DIGIT) {
-               --sp;                           /* erase 'e' */
-               ungetch (c);
-               ungetch ('e');
-               goto getnumexit;
-           } else
-               ungetch(c);
-
-           exp = 0;
-           while (type(c = inchar()) == DIGIT) {
-               if (sp < strsize)
-                   str[sp++] = c;
-               exp = 10 * exp + (c - '0');
-           }
-           ungetch (c);
-       }
-
+ char str[],                           /* string to return token in */
+ int strsize,                          /* maximum length of token string */
+ double *fnum,                         /* floating point value of number read */
+ int *inum                             /* integer value of number read */
+ )
+{
+  int sp = 0;
+  double sign = 1.0;
+  bool isSigned = false;               /* true if number prefixed by '+' or '-' */ 
+  *fnum = 0.0;
+  *inum = 0;
+  str[0] = EOS;
+  
+  int c = inchar();
+  if (c == HYPHEN) {
+    str[sp++] = c;
+    isSigned = true;
+    sign = -1.0;
+  } else if (c == PLUS) {
+    str[sp++] = c;
+    isSigned = true;
+    sign = 1.0;
+  } else if (c == PERIOD) {
+    if (type(lookchar()) != DIGIT) {
+      str[0] = PERIOD;
+      str[1] = EOS;
+      return (TT_SPECLCHAR);
+    } else
+      ungetch (PERIOD);
+  } else if (type(c) != DIGIT) {
+    ungetch (c);
+    return (TT_ERROR);
+  } else
+    ungetch (c);
+  
+  if (isSigned) {
+    c = lookchar();
+    if (c == PERIOD) {
+      inchar();                /* get period */
+      c = lookchar();          /* look at character past period */
+      ungetch (PERIOD);        /* put back period */
+      if (type(c) != DIGIT) {
+        str[sp] = EOS;
+        return (TT_SPECLCHAR);
+      }
+    } else if (type (c) != DIGIT) {
+      str[sp] = EOS;
+      return (TT_SPECLCHAR);
+    }
+  }
+  
+  double whole = 0.0;
+  while (type(c = inchar()) == DIGIT) {
+    if (sp < strsize)
+      str[sp++] = c;
+    whole = 10.0 * whole + (c - '0');
+  }
+  ungetch (c);         /* put back non-numeric character */
+  
+  if (c != PERIOD && tolower(c) != 'e') {
+    str[sp] = EOS;
+    *fnum = whole * sign;
+    if (*fnum < MIN_INT)
+      *inum = MIN_INT;
+    else if (*fnum > MAX_INT)
+      *inum = MAX_INT;
+    else
+      *inum = (int) *fnum;
+    return (TT_INT);
+  }
+  
+  if (lookchar() == PERIOD) {
+    inchar();
+    if (sp < strsize)
+      str[sp++] = PERIOD;
+  }
+  
+  double frac = 0.0;
+  double powerof10 = 10.0;
+  
+  while (type(c = inchar()) == DIGIT) {
+    if (sp < strsize)
+      str[sp++] = c;
+    frac += (double) (c - '0') / powerof10;
+    powerof10 *= 10.0;
+  }
+  ungetch (c);
+  
+  double exp = 0.0;
+  double expsign = 1.0;
+  c = inchar();
+  if (tolower(c) != 'e')
+    ungetch (c);
+  else {
+    if (sp < strsize)
+      str[sp++] = c;
+    if ((c = inchar()) == PLUS) {
+      if (sp < strsize)
+        str[sp++] = c;
+      expsign = 1.0;
+    } else if (c == HYPHEN) {
+      if (sp < strsize)
+        str[sp++] = c;
+      expsign = -1.0;
+    } else if (type(c) != DIGIT) {
+      --sp;                            /* erase 'e' */
+      ungetch (c);
+      ungetch ('e');
+      goto getnumexit;
+    } else
+      ungetch(c);
+    
+    exp = 0;
+    while (type(c = inchar()) == DIGIT) {
+      if (sp < strsize)
+        str[sp++] = c;
+      exp = 10 * exp + (c - '0');
+    }
+    ungetch (c);
+  }
+  
 getnumexit:
-       str[sp] = EOS;
-       *fnum = sign * (whole + frac) * pow (10.0, expsign * exp);
-       if (*fnum < MIN_INT)
-           *inum = MIN_INT;
-       else if (*fnum > MAX_INT)
-           *inum = MAX_INT;
-       else
-           *inum = (int) *fnum;
-       return (TT_REAL);
+  str[sp] = EOS;
+  *fnum = sign * (whole + frac) * pow (10.0, expsign * exp);
+  if (*fnum < MIN_INT)
+    *inum = MIN_INT;
+  else if (*fnum > MAX_INT)
+    *inum = MAX_INT;
+  else
+    *inum = (int) *fnum;
+  return (TT_REAL);
 }
 
 void 
 POL::eatline ()
 {
-       char term [2];
-
-       term[0] = NEWLINE;
-       term[1] = EOS;
-       skiptok (term);
+  char term [2];
+  
+  term[0] = NEWLINE;
+  term[1] = EOS;
+  skipSingleToken (term);
 }
 
 // return type of ASCII character 
 int 
 POL::type (int c)
 {
-       if (isalpha(c) || c == UNDERLIN)
-           return (LETTER);
-       else if (isdigit(c))
-           return (DIGIT);
-       else
-           return (c);
+  if (isalpha(c) || c == UNDERLIN)
+    return (LETTER);
+  else if (isdigit(c))
+    return (DIGIT);
+  else
+    return (c);
 }
 
-/*----------------------------------------------------------------------*/
-/*                                                                     */
-/*  hash table routines. Kernighan & Ritchie                           */
-/*                                                                     */
-/*----------------------------------------------------------------------*/
-
-/* inittable (table)
- *     clear symbol table
-*/
-
-void 
-POL::inittable (SYMBOL *table[])
-{
-       int i;
-
-       for (i = 0; i < HASHSIZE; i++)
-           table[i] = NULL;
-}
-
-/* freetable (table)
- *     free all memory allocated to table, then clear table
- */
-
-void 
-POL::freetable (SYMBOL *table[])
-{
-       int i;
-       SYMBOL *p, *np;
-
-       for (i = 0; i < HASHSIZE; i++) {
-           np = table[i];
-           while (np != NULL) {
-               p = np->next;
-               free (np);
-               np = p;
-           }
-       }
-       inittable (table);
-}
-
-// form hash value of string s 
-int 
-POL::hash (char *s)
-{
-       int hashval;
-
-       for (hashval = 0; *s != EOS; )
-           hashval += *s++;
-       return (hashval % HASHSIZE);
-}
-
-/* Look for s in hash table */
-POL::SYMBOL *
-POL::lookup ( SYMBOL *table[], char *s )
-{
-    SYMBOL *np;
-    SYMBOL *found = NULL;
-
-    for (np = table[hash(s)]; np != NULL; np = np->next)
-       if (strcasecmp(s, np->name) == 0) {
-           found = np;         /* found it */
-           break;
-       }
-
-    return (found);
-}
-
-POL::SYMBOL *
-POL::install (SYMBOL *table[], char *name, int def)
-{
-    static char installerr[] = "install: out of memory";
-    SYMBOL *np;
-    int hashval;
-
-    if ((np = lookup (table, name)) == NULL) { /* not found */
-       np = (SYMBOL *) malloc (sizeof(*np));
-       if (np == NULL) {
-           sys_error (ERR_SEVERE, installerr);
-           return (NULL);
-       }
-       if ((np->name = strdup(name)) == NULL) {
-           sys_error (ERR_SEVERE, installerr);
-           return (NULL);
-       }
-       str_lower (np->name);
-       np->code = def;
-       hashval = hash(np->name);
-       np->next = table[hashval];
-       table[hashval] = np;
-    } else                                     /* already there */
-       np->code = def;
-    return (np);
-}
 
 //----------------------------------------------------------------------
 //                             POL INPUT                               
@@ -912,50 +814,50 @@ POL::install (SYMBOL *table[], char *name, int def)
 
 
 /* usefile - set source of POL input
- *
- *    int source - source of input
- *                P_USE_STR  - have POL use strings as input
- *                P_USE_FILE - use file.  filename is in str
- *
+*
+*    int source - source of input
+                P_USE_STR  - have POL use strings as input
+                P_USE_FILE - use file.  filename is in str
+*
 */
 
 void 
 POL::usefile (int source, char *fn)
 {
-       FILE *fp;
-
-       ++currentf;
-       if (currentf >= MAXFILE) {
-           --currentf;
-           sys_error (ERR_SEVERE, "files nested too deeply");
-           return;
-       }
-
-       bp = 0;                         /* clear any pushed back input */
-
-       if (source == P_USE_STR) {
-           filep[currentf] = NULL;
-       } else if (source == P_USE_FILE) {
-           if (fn == NULL || strlen(fn) == 0) {
-               fp = stdin;
-           } else if ((fp = fopen(fn, "r")) == NULL) {
-               --currentf;
-               sys_error (ERR_SEVERE, "can't open file");
-               return;
-           }
-           filep[currentf] = fp;
-           fname[currentf] = strdup (fn);
-       }
+  FILE *fp;
+  
+  ++currentf;
+  if (currentf >= MAXFILE) {
+    --currentf;
+    sys_error (ERR_SEVERE, "files nested too deeply");
+    return;
+  }
+  
+  bp = 0;                              /* clear any pushed back input */
+  
+  if (source == P_USE_STR) {
+    filep[currentf] = NULL;
+  } else if (source == P_USE_FILE) {
+    if (fn == NULL || strlen(fn) == 0) {
+      fp = stdin;
+    } else if ((fp = fopen(fn, "r")) == NULL) {
+      --currentf;
+      sys_error (ERR_SEVERE, "can't open file");
+      return;
+    }
+    filep[currentf] = fp;
+    fname[currentf] = strdup (fn);
+  }
 }
 
 void 
 POL::closefile()
 {
-       if (currentf >= 0) {
-           if (filep[currentf] != NULL)
-               fclose (filep[currentf]);
-           --currentf;
-       }
+  if (currentf >= 0) {
+    if (filep[currentf] != NULL)
+      fclose (filep[currentf]);
+    --currentf;
+  }
 }
 
 /*-----------------------------*/
@@ -966,25 +868,25 @@ POL::closefile()
 int 
 POL::lookchar()
 {
-       int c;
-
-       c = inchar();
-       ungetch (c);
-       return (c);
+  int c;
+  
+  c = inchar();
+  ungetch (c);
+  return (c);
 }
 
 int 
 POL::inchar()
 {
   int c = 0;
-
+  
   if (currentf < 0)
     return (EOF);
-
+  
   while (currentf >= 0 && (c = getch(filep[currentf])) == EOF && filep[currentf] != NULL) {
     closefile ();
   }
-
+  
   return (c);
 }
 
@@ -996,50 +898,50 @@ POL::inchar()
 int 
 POL::getch (FILE *fp)
 {
-       int c;
-
-       if (bp > 0)
-           return (buf[--bp]);
-
-       if (fp == NULL) {
-           if ((c = inputline[lineptr]) == EOS)
-               return (EOF);
-           else {
-               ++lineptr;
-               return (c);
-           }
-       } else
-           c = fgetc(fp);
-
-       return (c);
+  int c;
+  
+  if (bp > 0)
+    return (buf[--bp]);
+  
+  if (fp == NULL) {
+    if ((c = inputline[lineptr]) == EOS)
+      return (EOF);
+    else {
+      ++lineptr;
+      return (c);
+    }
+  } else
+    c = fgetc(fp);
+  
+  return (c);
 }
 
 /* push character back on input */
 void 
 POL::ungetch (int c)
 {
-       if (bp > BUFSIZE)
-           sys_error (ERR_SEVERE, "too many characters pushed back [ungetch]");
-       else
-           buf[bp++] = c;
+  if (bp > BUFSIZE)
+    sys_error (ERR_SEVERE, "too many characters pushed back [ungetch]");
+  else
+    buf[bp++] = c;
 }
 
 
 int 
 POL::get_inputline (FILE *fp)
 {
-       lineptr = 0;
-       bp = 0;
-       if (fgets (inputline, MAXLINE, fp) == NULL)
-           return (EOF);
-       else
-           return (OK);
+  lineptr = 0;
+  bp = 0;
+  if (fgets (inputline, MAXLINE, fp) == NULL)
+    return (EOF);
+  else
+    return (OK);
 }
 
 void 
 POL::set_inputline (const char* const line)
 {
-       lineptr = 0;
-       bp = 0;
-       strncpy (inputline, line, MAXLINE);
+  lineptr = 0;
+  bp = 0;
+  strncpy (inputline, line, MAXLINE);
 }
index c04f4269f240b2b2ab2a58ec2856c8864a2f2f91..c133131ba48cd25872cf023c3150a89531d921f0 100644 (file)
@@ -1,6 +1,6 @@
 noinst_LIBRARIES = libctsupport.a
 INCLUDES=@my_includes@
-libctsupport_a_SOURCES= strfuncs.cpp syserror.cpp fnetorderstream.cpp consoleio.cpp mathfuncs.cpp xform.cpp clip.cpp plotfile.cpp
+libctsupport_a_SOURCES= strfuncs.cpp syserror.cpp fnetorderstream.cpp consoleio.cpp mathfuncs.cpp xform.cpp clip.cpp plotfile.cpp hashtable.cpp
 EXTRA_DIST=Makefile.nt
 
 
diff --git a/libctsupport/hashtable.cpp b/libctsupport/hashtable.cpp
new file mode 100644 (file)
index 0000000..a4dd283
--- /dev/null
@@ -0,0 +1,141 @@
+/*****************************************************************************\r
+** FILE IDENTIFICATION\r
+**\r
+**   Hash Table Class\r
+**\r
+**  This is part of the CTSim program\r
+**  Copyright (C) 1983-2000 Kevin Rosenberg\r
+**\r
+**  $Id: hashtable.cpp,v 1.1 2000/12/27 20:09:19 kevin Exp $\r
+**\r
+**  This program is free software; you can redistribute it and/or modify\r
+**  it under the terms of the GNU General Public License (version 2) as\r
+**  published by the Free Software Foundation.\r
+**\r
+**  This program is distributed in the hope that it will be useful,\r
+**  but WITHOUT ANY WARRANTY; without even the implied warranty of\r
+**  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the\r
+**  GNU General Public License for more details.\r
+**\r
+**  You should have received a copy of the GNU General Public License\r
+**  along with this program; if not, write to the Free Software\r
+**  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA\r
+******************************************************************************/\r
+\r
+#include "ct.h"\r
+#include <math.h>\r
+#include <stdio.h>\r
+#include <ctype.h>\r
+#include "ctsupport.h"\r
+#include "pol.h"\r
+\r
+\r
+KeywordCodeEntry::KeywordCodeEntry (const char* const pszKeyword, int iCode)\r
+    : m_iCode (iCode), m_pNext(NULL)\r
+{\r
+   int nLength = strlen (pszKeyword);\r
+   char* pszCopy = new char [ nLength + 1];\r
+   for (int i = 0; i < nLength; i++) \r
+     pszCopy[i] = tolower (pszKeyword[i]);\r
+   pszCopy[nLength] = 0;\r
+\r
+   m_strKeyword = pszCopy;\r
+\r
+   delete pszCopy;\r
+}\r
+\r
+\r
+bool\r
+KeywordCodeEntry::matchesKeyword (const char* const pszCompare) const\r
+{\r
+    int nLength = strlen (pszCompare);\r
+    char* pszCopy = new char [ nLength + 1];\r
+    for (int i = 0; i < nLength; i++) \r
+      pszCopy[i] = tolower (pszCompare[i]);\r
+    pszCopy[nLength] = 0;\r
+\r
+    bool bMatch = false;\r
+    if (m_strKeyword.compare (pszCompare) == 0)\r
+      bMatch = true;\r
+\r
+    delete pszCopy;\r
+\r
+    return bMatch;\r
+}\r
+\r
+\r
+// inittable (table)\r
+//    clear symbol table\r
+\r
+void \r
+KeywordCodeHashTable::initTable ()\r
+{\r
+       int i;\r
+\r
+       for (i = 0; i < HASHSIZE; i++)\r
+           m_hashTable[i] = NULL;\r
+}\r
+\r
+// freetable (table)\r
+//     free all memory allocated to table, then clear table\r
+\r
+void \r
+KeywordCodeHashTable::freeTable ()\r
+{\r
+       int i;\r
+       KeywordCodeEntry *p, *np;\r
+\r
+       for (i = 0; i < HASHSIZE; i++) {\r
+           np = m_hashTable [i];\r
+           while (np != NULL) {\r
+                   p = np->getNext();\r
+                   delete np;\r
+                   np = p;\r
+      }\r
+       }\r
+       initTable ();\r
+}\r
+\r
+\r
+// form hash value of string s \r
+int \r
+KeywordCodeHashTable::hash (const char* s)\r
+{\r
+       int hashval = 0;\r
+\r
+  while (*s != EOS) {\r
+           hashval += tolower(*s);\r
+      s++;\r
+  }\r
+\r
+       return (hashval % HASHSIZE);\r
+}\r
+\r
+\r
+/* Look for s in hash table */\r
+KeywordCodeEntry *\r
+KeywordCodeHashTable::lookup (const char* const pszLookup)\r
+{\r
+    KeywordCodeEntry *found = NULL;\r
+    for (KeywordCodeEntry* np = m_hashTable[ hash( pszLookup ) ]; np != NULL; np = np->getNext())\r
+           if (np->matchesKeyword (pszLookup)) {\r
+             found = np;               // found it \r
+             break;\r
+       }\r
+\r
+  return (found);\r
+}\r
+\r
+void\r
+KeywordCodeHashTable::installKeywordCode (const char* const pszKeyword, int iCode)\r
+{\r
+    KeywordCodeEntry *np = lookup (pszKeyword);\r
+\r
+    if (np == NULL) {      // not found \r
+           np = new KeywordCodeEntry (pszKeyword, iCode);\r
+           int hashval = hash (np->getKeyword());\r
+       np->setNext (m_hashTable[ hashval ]);\r
+           m_hashTable[hashval] = np;\r
+    } else                                     // already defined\r
+           np->setCode (iCode);\r
+}\r
index f60628840d675189d59d6ccf37ee9ef22d29580c..8721de2e9ecfa668bb43527089254289f43dae7c 100644 (file)
@@ -2,7 +2,7 @@
 **  This is part of the CTSim program
 **  Copyright (C) 1983-2000 Kevin Rosenberg
 **
-**  $Id: syserror.cpp,v 1.8 2000/12/17 23:30:48 kevin Exp $
+**  $Id: syserror.cpp,v 1.9 2000/12/27 20:09:19 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
@@ -83,6 +83,9 @@ void sys_verror (int severity, const char *msg, va_list arg)
     break;
   case ERR_WARNING:
          std::cout << "WARNING ERROR: ";
+    break;\r
+  case ERR_TRACE:\r
+    std::cout << "Trace: ";\r
     break;
   default:
          std::cout << "Illegal error code #" << severity << ": ";
index 427763314aa1346607ff3228126aa582f84f008c..d695bc3ea1dc801f6939aba9027a15c1b02e8640 100644 (file)
@@ -6,26 +6,13 @@
 --------------------Configuration: libctsim - Win32 Debug--------------------\r
 </h3>\r
 <h3>Command Lines</h3>\r
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP42.tmp" with contents\r
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7B.tmp" with contents\r
 [\r
 /nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\..\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c \r
-"C:\ctsim-2.0.6\libctsim\backprojectors.cpp"\r
-"C:\ctsim-2.0.6\libctgraphics\ezplot.cpp"\r
-"C:\ctsim-2.0.6\libctgraphics\ezset.cpp"\r
-"C:\ctsim-2.0.6\libctgraphics\ezsupport.cpp"\r
-"C:\ctsim-2.0.6\libctsim\filter.cpp"\r
-"C:\ctsim-2.0.6\libctsim\imagefile.cpp"\r
-"C:\ctsim-2.0.6\libctsim\phantom.cpp"\r
-"C:\ctsim-2.0.6\libctsupport\plotfile.cpp"\r
 "C:\ctsim-2.0.6\libctgraphics\pol.cpp"\r
-"C:\ctsim-2.0.6\libctsim\procsignal.cpp"\r
-"C:\ctsim-2.0.6\libctsim\projections.cpp"\r
-"C:\ctsim-2.0.6\libctsim\reconstruct.cpp"\r
-"C:\ctsim-2.0.6\libctsim\scanner.cpp"\r
-"C:\ctsim-2.0.6\libctsim\trace.cpp"\r
 ]\r
-Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP42.tmp" \r
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP43.tmp" with contents\r
+Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7B.tmp" \r
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7C.tmp" with contents\r
 [\r
 /nologo /out:"Debug\libctsim.lib" \r
 ".\Debug\array2dfile.obj"\r
@@ -54,41 +41,24 @@ Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP43.tmp" with content
 ".\Debug\trace.obj"\r
 ".\Debug\transformmatrix.obj"\r
 ".\Debug\xform.obj"\r
+".\Debug\hashtable.obj"\r
 ]\r
-Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP43.tmp"\r
+Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7C.tmp"\r
 <h3>Output Window</h3>\r
 Compiling...\r
-backprojectors.cpp\r
-ezplot.cpp\r
-ezset.cpp\r
-ezsupport.cpp\r
-filter.cpp\r
-imagefile.cpp\r
-phantom.cpp\r
-plotfile.cpp\r
 pol.cpp\r
-procsignal.cpp\r
-projections.cpp\r
-reconstruct.cpp\r
-scanner.cpp\r
-trace.cpp\r
 Creating library...\r
 <h3>\r
 --------------------Configuration: ctsim - Win32 Debug--------------------\r
 </h3>\r
 <h3>Command Lines</h3>\r
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP44.tmp" with contents\r
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7D.tmp" with contents\r
 [\r
 /nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "\wx2\include" /I "." /I "..\..\include" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\zlib" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /D VERSION=\"2.5.0\" /D "_DEBUG" /D "__WXMSW__" /D "HAVE_SGP" /D "HAVE_PNG" /D "HAVE_WXWINDOWS" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "HAVE_STRING_H" /D "HAVE_FFTW" /D "HAVE_RFFTW" /D "HAVE_GETOPT_H" /D "MSVC" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /D CTSIMVERSION=\"2.5.0\" /FR"Debug/" /Fp"Debug/ctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c \r
 "C:\ctsim-2.0.6\src\ctsim.cpp"\r
-"C:\ctsim-2.0.6\src\dialogs.cpp"\r
-"C:\ctsim-2.0.6\src\dlgprojections.cpp"\r
-"C:\ctsim-2.0.6\src\dlgreconstruct.cpp"\r
-"C:\ctsim-2.0.6\src\docs.cpp"\r
-"C:\ctsim-2.0.6\src\views.cpp"\r
 ]\r
-Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP44.tmp" \r
-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP45.tmp" with contents\r
+Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7D.tmp" \r
+Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7E.tmp" with contents\r
 [\r
 comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../libctsim/Debug/libctsim.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\lpng108\msvc\win32\libpng\lib_dbg\libpng.lib ..\..\..\lpng108\msvc\win32\zlib\lib_dbg\zlib.lib libcmtd.lib ..\..\..\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib ..\..\..\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib ../../../wx2/lib/wxd.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/ctsim.pdb" /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrtd.lib" /out:"Debug/ctsim.exe" /pdbtype:sept /libpath:"..\..\..\lpng108\msvc\win32\libpng\lib" /libpath:"..\..\..\lpng108\msvc\win32\zlib\lib" \r
 ".\Debug\ctsim.obj"\r
@@ -103,15 +73,10 @@ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib w
 "\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib"\r
 "\wx2\lib\wxd.lib"\r
 ]\r
-Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP45.tmp"\r
+Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP7E.tmp"\r
 <h3>Output Window</h3>\r
 Compiling...\r
 ctsim.cpp\r
-dialogs.cpp\r
-dlgprojections.cpp\r
-dlgreconstruct.cpp\r
-docs.cpp\r
-views.cpp\r
 Linking...\r
 Creating command line "bscmake.exe /nologo /o"Debug/ctsim.bsc"  ".\Debug\ctsim.sbr" ".\Debug\dialogs.sbr" ".\Debug\dlgprojections.sbr" ".\Debug\dlgreconstruct.sbr" ".\Debug\docs.sbr" ".\Debug\views.sbr""\r
 Creating browse info file...\r