r316: c++ conversions to POL
[ctsim.git] / include / pol.h
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
 };