** This is part of the CTSim program
** Copyright (C) 1983-2000 Kevin Rosenberg
**
-** $Id: pol.cpp,v 1.7 2000/12/27 20:09:19 kevin Exp $
+** $Id: pol.cpp,v 1.9 2001/01/02 16:02:13 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
** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
******************************************************************************/
-#include "ct.h"\r
+#include "ct.h"
#include <math.h>
#include <stdio.h>
#include <ctype.h>
};
const unsigned int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::KeywordCodeList));
-\r
+
POL::POL()
{
- bp = 0;
- currentf = -1;\r
+ currentf = -1;
m_bTrace = false;
init();
}
meta.ter = PERCENT;
meta.inb = LBRACK;
- m_bNewlineIsEOC = true;\r
+ m_bNewlineIsEOC = true;
m_szSkipChars[0] = EOS;
token.ready = false; // no token read yet
}
-\r
+
/* addSkipWord (w)
*
*/
void
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
+{
+ int n = strlen (m_szSkipChars);
+ if (n < MAXSKIPCHAR) {
+ m_szSkipChars[n] = c;
+ m_szSkipChars[n+1] = 0;
}
}
//
// tok() looks for these user defined tokens. If it finds one,
// it stores the tokens code in the token structure and returns TT_USERTOK
-void\r
+void
POL::addKeyword (const char* const str, int code)
{
usertable.installKeywordCode (str, code);
return (false);
}
-bool\r
+bool
POL::readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2)
{
tok (&token);
return (skipSingleToken (term));
}
-void \r
+void
POL::reader()
{
while (skipTokens())
}
s[i] = EOS;
}
-\r
+
bool
POL::readText (char *str, int lim)
while ((c = inchar()) == BLANK || c == TAB)
;
ungetch (c);
- if (c == EOF) {\r
- str[0] = 0;\r
- return false;\r
- }\r
- \r
+ if (c == EOF) {
+ str[0] = 0;
+ return false;
+ }
+
int i;
for (i = 0; i < lim && (c = inchar()) != EOF && c != NEWLINE; i++)
str[i] = c;
ungetch (c);
- str[i] = 0;\r
- \r
+ str[i] = 0;
+
return true;
}
return;
}
- bp = 0; /* clear any pushed back input */
-
+ while (! m_stackPushBackInput.empty())
+ m_stackPushBackInput.pop();
+
if (source == P_USE_STR) {
filep[currentf] = NULL;
} else if (source == P_USE_FILE) {
POL::getch (FILE *fp)
{
int c;
-
- if (bp > 0)
- return (buf[--bp]);
-
+ if (m_stackPushBackInput.size() > 0) {
+ c = m_stackPushBackInput.top();
+ m_stackPushBackInput.pop();
+ return c;
+ }
+
if (fp == NULL) {
if ((c = inputline[lineptr]) == EOS)
return (EOF);
return (c);
}
-/* push character back on input */
+// 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;
+ m_stackPushBackInput.push (c);
}
int
POL::get_inputline (FILE *fp)
{
+ while (! m_stackPushBackInput.empty())
+ m_stackPushBackInput.pop();
+
lineptr = 0;
- bp = 0;
if (fgets (inputline, MAXLINE, fp) == NULL)
return (EOF);
else
void
POL::set_inputline (const char* const line)
{
- lineptr = 0;
- bp = 0;
+ while (! m_stackPushBackInput.empty())
+ m_stackPushBackInput.pop();
+
strncpy (inputline, line, MAXLINE);
+ lineptr = 0;
}