X-Git-Url: http://git.kpe.io/?p=ctsim.git;a=blobdiff_plain;f=libctgraphics%2Fpol.cpp;h=9c0e4278b61b951e7490d9c9e0981eaddcaccfed;hp=1d1a13ab31470cd7bb71fdf560204a3d87cbdfb5;hb=5c6b29ab4885308cc3381af6e0a68f4804956d2e;hpb=c24c1c0721df40e77822ad2b9ec01a944012ff42 diff --git a/libctgraphics/pol.cpp b/libctgraphics/pol.cpp index 1d1a13a..9c0e427 100644 --- a/libctgraphics/pol.cpp +++ b/libctgraphics/pol.cpp @@ -6,7 +6,7 @@ ** 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.8 2000/12/29 15:45:06 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 @@ -54,7 +54,6 @@ const unsigned int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::Key POL::POL() { - bp = 0; currentf = -1; m_bTrace = false; init(); @@ -832,9 +831,10 @@ POL::usefile (int source, char *fn) sys_error (ERR_SEVERE, "files nested too deeply"); 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) { @@ -898,11 +898,13 @@ POL::inchar() int POL::getch (FILE *fp) { - int c; - - if (bp > 0) - return (buf[--bp]); - + int c; + 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) { - lineptr = 0; - bp = 0; + while (! m_stackPushBackInput.empty()) + m_stackPushBackInput.pop(); + + lineptr = 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; }