r316: c++ conversions to POL
[ctsim.git] / libctgraphics / ezset.cpp
index b380e9a00ff4f021eef71ff1d5d030c421dd056b..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.12 2000/12/25 21:54:26 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
@@ -26,8 +26,6 @@
 #include "ezplot.h"
 #include "pol.h"
 
-bool EZPlot::ezset_initialized = false;
-\r
 \r
 bool\r
 EZPlot::ezset (const std::string& command)\r
@@ -38,45 +36,28 @@ EZPlot::ezset (const std::string& command)
 bool 
 EZPlot::ezset (const char* const command)
 {
-  if (! ezset_initialized) {
-    pol_init();
-    initKeywords();
-    pol_skpword ("please");
-    pol_skpword ("use");
-    pol_skpword ("are");
-    pol_skpword ("and");
-    pol_skpword ("is");
-    pol_skpword ("the");
-    pol_skpword ("equals");
-    pol_skpchar ("=");
-    
-    pol_usefile (P_USE_STR,"");
-    set_inputline ("!eoc ,");
-    pol_reader ();
-    pol_closefile ();
-    ezset_initialized = true;
-  }
-  return ezcmd (command);
+\r
+    return ezcmd (command);
 }
 
 bool 
 EZPlot::ezcmd (const char* const comm)
 {
-  pol_usefile (P_USE_STR, "");
-  set_inputline (comm);
+  m_pol.usefile (POL::P_USE_STR, "");
+  m_pol.set_inputline (comm);
   
-  char str[MAXTOK+1];
+  char str [POL::MAXTOK+1];
   int code;
   bool retval = true;
-  if (! pol_usertok (str, &code)) {
-    sys_error(ERR_WARNING, "Illegal EZSET command: %s", str);
-    pol_reader();
+  if (! m_pol.readUserToken (str, &code)) {
+    sys_error (ERR_WARNING, "Illegal EZSET command: %s", str);
+    m_pol.reader();
     retval = false;
   }
   else
     retval = do_cmd (code);
   
-  pol_closefile();                     /* close input string file */
+  m_pol.closefile();                   /* close input string file */
   return (retval);
 }
 
@@ -91,7 +72,7 @@ EZPlot::do_cmd (int lx)
   
   switch (lx) {
   case S_TEXTSIZE:
-    if (pol_float (&f, 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;
@@ -106,31 +87,31 @@ EZPlot::do_cmd (int lx)
     clearCurves ();
     break;
   case S_TITLE:
-    gettext (strIn, sizeof(strIn));
+    m_pol.readText (strIn, sizeof(strIn));
     c_title = strIn;
     break;
   case S_LEGEND:
-    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:
-    gettext (strIn, sizeof(strIn));
+    m_pol.readText (strIn, sizeof(strIn));
     c_xlabel = strIn;
     break;
   case S_YLABEL:
-    gettext (strIn, sizeof(strIn));
+    m_pol.readText (strIn, sizeof(strIn));
     c_ylabel = strIn;
     break;
   case S_XCROSS:
-    if (pol_float (&f, 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 (pol_float (&f, 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
@@ -163,25 +144,25 @@ EZPlot::do_cmd (int lx)
     s_ymax = FALSE;
     break;
   case S_XMIN:
-    if (pol_float (&f, 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 (pol_float (&f, 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 (pol_float (&f, 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 (pol_float (&f, 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;
     }
@@ -192,7 +173,7 @@ EZPlot::do_cmd (int lx)
   case S_DASH:
     int ls;\r
     ls = SGP::LS_DASH1;\r
-    if (pol_integer (&n, 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)
@@ -214,7 +195,7 @@ EZPlot::do_cmd (int lx)
     break;
   case S_PEN:
   case S_COLOR:
-    if (pol_integer (&n, 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)
@@ -238,47 +219,47 @@ EZPlot::do_cmd (int lx)
     o_grid = FALSE;
     break;
   case S_XLENGTH:
-    if (pol_float (&f, 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 (pol_float (&f, 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 (pol_float (&f, 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 (pol_float (&f, 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 (pol_word("no", 2) == TRUE)
+    if (m_pol.readWord("no", 2) == TRUE)
       o_tag = FALSE;
-    else if (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 (pol_word("inside", 2) == TRUE)
+    if (m_pol.readWord("inside", 2) == TRUE)
       o_legendbox = INSIDE;
-    else if (pol_word("outside", 3) == TRUE)
+    else if (m_pol.readWord("outside", 3) == TRUE)
       o_legendbox = OUTSIDE;
-    else if (pol_word("none",2) == TRUE)
+    else if (m_pol.readWord("none",2) == TRUE)
       o_legendbox = NOLEGEND;
     else {
-      gettext (str, MAXTOK);
+      m_pol.readText (str, POL::MAXTOK);
       bad_option(str);
     }
     break;
   case S_XLEGEND:
-    if (pol_float (&f, 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;
@@ -289,7 +270,7 @@ EZPlot::do_cmd (int lx)
     }
     break;
   case S_YLEGEND:
-    if (pol_float (&f, 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;
@@ -300,7 +281,7 @@ EZPlot::do_cmd (int lx)
     }
     break;
   case S_SYMBOL:
-    if (pol_integer (&n, 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
@@ -308,8 +289,8 @@ EZPlot::do_cmd (int lx)
           setSymbol (m_iCurrentCurve, n);\r
       }\r
     } else {
-      if (pol_word("every",5) == TRUE) {
-        if (pol_integer (&n, 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
@@ -318,22 +299,22 @@ EZPlot::do_cmd (int lx)
           else \r
             setSymbolFreq (m_iCurrentCurve, sym);\r
         }
-      } else if (pol_word ("none",4) == TRUE) {
+      } else if (m_pol.readWord ("none",4) == TRUE) {
         o_symbol = -1;
       }
     }
     break;
   case S_CURVE:\r
-    if (pol_integer (&n, 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 (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 (pol_usertok(str,&lx) == FALSE)
+    if (m_pol.readUserToken(str,&lx) == FALSE)
       break;
     if (lx == S_ABOVE)
       o_xticks = ABOVE;
@@ -344,16 +325,16 @@ EZPlot::do_cmd (int lx)
     else if (lx == S_LABEL)
       o_xtlabel = TRUE;
     else if (lx == S_MAJOR) {
-      if (pol_integer (&n, 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 (pol_integer (&n, 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 (pol_usertok(str,&lx) == FALSE)
+    if (m_pol.readUserToken(str,&lx) == FALSE)
       break;
     if (lx == S_RIGHT)
       o_yticks = RIGHT;
@@ -364,16 +345,16 @@ EZPlot::do_cmd (int lx)
     else if (lx == S_LABEL)
       o_ytlabel = TRUE;
     else if (lx == S_MAJOR) {
-      if (pol_integer (&n, 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 (pol_integer (&n, 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 (pol_integer (&n, 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;
@@ -382,7 +363,7 @@ EZPlot::do_cmd (int lx)
       s_lxfrac = FALSE;
     break;
   case S_LYFRAC:
-    if (pol_integer (&n, 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;
@@ -396,7 +377,7 @@ EZPlot::do_cmd (int lx)
     break;
   }
   
-  pol_reader ();
+  m_pol.reader ();
   return (true);
 }
 
@@ -499,6 +480,5 @@ void
 EZPlot::initKeywords ()
 {
   for (int i = 0; i < NKEYS; i++)
-    if (! pol_install (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);
 }