X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctgraphics%2Fpol.cpp;h=42ddf3e4403c0c889a8c1ceed5d33b66378ed6b7;hp=1d1a13ab31470cd7bb71fdf560204a3d87cbdfb5;hb=8a7697ce57b56cdc43698cd1241ad98d49f9b5ac;hpb=df761d2b3cac3d347f4ef0f9f69e88d3bb66b2fa diff --git a/libctgraphics/pol.cpp b/libctgraphics/pol.cpp index 1d1a13a..42ddf3e 100644 --- a/libctgraphics/pol.cpp +++ b/libctgraphics/pol.cpp @@ -4,9 +4,9 @@ ** POL - Problem Oriented Language ** ** This is part of the CTSim program -** Copyright (C) 1983-2000 Kevin Rosenberg +** Copyright (c) 1983-2001 Kevin Rosenberg ** -** $Id: pol.cpp,v 1.7 2000/12/27 20:09:19 kevin Exp $ +** $Id$ ** ** 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 @@ -22,7 +22,7 @@ ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA ******************************************************************************/ -#include "ct.h" +#include "ct.h" #include #include #include @@ -50,12 +50,11 @@ const struct POL::KeywordCodeList POL::cmdlist[] = { }; const unsigned int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::KeywordCodeList)); - + POL::POL() { - bp = 0; - currentf = -1; + currentf = -1; m_bTrace = false; init(); } @@ -77,7 +76,7 @@ POL::init () meta.ter = PERCENT; meta.inb = LBRACK; - m_bNewlineIsEOC = true; + m_bNewlineIsEOC = true; m_szSkipChars[0] = EOS; @@ -86,7 +85,7 @@ POL::init () token.ready = false; // no token read yet } - + /* addSkipWord (w) * @@ -108,11 +107,11 @@ POL::addSkipWord (const char* const w) */ void POL::addSkipChar (int c) -{ - int n = strlen (m_szSkipChars); - if (n < MAXSKIPCHAR) { - m_szSkipChars[n] = c; - m_szSkipChars[n+1] = 0; +{ + int n = strlen (m_szSkipChars); + if (n < MAXSKIPCHAR) { + m_szSkipChars[n] = c; + m_szSkipChars[n+1] = 0; } } @@ -123,7 +122,7 @@ POL::addSkipChar (int c) // // 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 +void POL::addKeyword (const char* const str, int code) { usertable.installKeywordCode (str, code); @@ -229,7 +228,7 @@ POL::readInteger (int *n, int typecode, bool boundcode, int bb1, int bb2) return (false); } -bool +bool POL::readFloat (double *n, double typecode, bool boundcode, double bb1, double bb2) { tok (&token); @@ -276,7 +275,7 @@ POL::skipTokens() return (skipSingleToken (term)); } -void +void POL::reader() { while (skipTokens()) @@ -622,7 +621,7 @@ POL::getescape ( /* reads up to delim */ } s[i] = EOS; } - + bool POL::readText (char *str, int lim) @@ -631,17 +630,17 @@ POL::readText (char *str, int lim) while ((c = inchar()) == BLANK || c == TAB) ; ungetch (c); - if (c == EOF) { - str[0] = 0; - return false; - } - + 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; - + str[i] = 0; + return true; } @@ -833,8 +832,9 @@ POL::usefile (int source, char *fn) 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) { @@ -899,10 +899,12 @@ int 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); @@ -916,22 +918,21 @@ POL::getch (FILE *fp) 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 @@ -941,7 +942,9 @@ POL::get_inputline (FILE *fp) 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; }