From 65732cc5d8dbf867ed56a021c07c5636cea93b5a Mon Sep 17 00:00:00 2001 From: "Kevin M. Rosenberg" Date: Wed, 27 Dec 2000 03:16:02 +0000 Subject: [PATCH] r315: Coverted POL to C++ class --- ChangeLog | 7 +- include/ezplot.h | 12 +- include/pol.h | 287 ++++++++++++++++++--------- libctgraphics/ezplot.cpp | 43 ++-- libctgraphics/ezset.cpp | 123 +++++------- libctgraphics/pol.cpp | 402 ++++++++++++++++---------------------- libctsupport/plotfile.cpp | 6 +- msvc/ctsim/ctsim.plg | 59 +++++- src/ctsim.cpp | 9 +- src/dialogs.cpp | 13 +- src/docs.cpp | 17 +- src/docs.h | 5 +- src/views.cpp | 39 ++-- 13 files changed, 557 insertions(+), 465 deletions(-) diff --git a/ChangeLog b/ChangeLog index b8cd410..894573e 100644 --- a/ChangeLog +++ b/ChangeLog @@ -4,7 +4,7 @@ TODO Add help button onto dialog's for reconstruction & projections. Consider use of wxWindows help file classes. - Consider changing POL into a Class. Consider making it read tag tokens. + Consider changing POL to to read tag tokens. Consider being able to write Phantom files as text and view as text in ctsim. @@ -37,8 +37,11 @@ TODO * if1: Updated to use new ImageFile class math functions * ezplot: Reworked to better store colors/linestyles/symbols with - Individual curves. Updated to more C++ conventions. + individual curves. Improved display of labels and ticks. Updated + to use POL class member variable. Updated to more C++ conventions. + * pol: converted to C++ class + * sgp: Added linestyle settings 2.5.0 - 12/18/00 diff --git a/include/ezplot.h b/include/ezplot.h index a7559da..b2512aa 100644 --- a/include/ezplot.h +++ b/include/ezplot.h @@ -7,7 +7,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.h,v 1.21 2000/12/25 21:54:26 kevin Exp $ +** $Id: ezplot.h,v 1.22 2000/12/27 03:16:02 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 @@ -32,7 +32,8 @@ #include #include #include "ctsupport.h" -#include "sgp.h" +#include "sgp.h" +#include "pol.h" class EZPlotCurve { @@ -319,6 +320,7 @@ private: int axis_scale (double min, double max, int nint, double *minp, double *maxp, int *nintp); SGP& rSGP; + POL m_pol; void clearCurves (); @@ -327,10 +329,8 @@ private: void bad_option(char *opt); void initPlotSettings(); - static void initKeywords (); - - static bool ezset_initialized; - + void initKeywords (); + double convertWorldToNDC_X (double x) { return xgn_min + (x - xgw_min) * m_xWorldScale; } diff --git a/include/pol.h b/include/pol.h index 54ff9f0..7ac7525 100644 --- a/include/pol.h +++ b/include/pol.h @@ -2,7 +2,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: pol.h,v 1.6 2000/12/25 21:54:26 kevin Exp $ +** $Id: pol.h,v 1.7 2000/12/27 03:16:02 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 @@ -19,98 +19,209 @@ ******************************************************************************/ #ifndef __H_POL #define __H_POL - -// codes for pol_usefile -enum { - P_USE_STR = 1, // use string as input source - P_USE_FILE, // use file as input source -}; -// codes for pol_int and pol_float -// if in reject catagory, get new number from terminal -enum { - P_FLTINT = 1, // get a real or integer number - P_BFLTINT, // get a real or integer number, clip against bounds - P_CBFLTINT, // get real or int, reject if outside bounds - P_FLT, // get a real number - P_BFLT, // get a real, clip against bounds - P_CBFLT, // get a floating, reject if outside bounds - P_INT, // get a integer number - P_BINT, // get a integer, clip against bounds - P_CBINT, // get a integer, reject if outside bounds -}; +class POL { + + public: + + // codes for pol_usefile + enum { + P_USE_STR = 1, // use string as input source + P_USE_FILE, // use file as input source + }; - -#define LETTER 'a' -#define DIGIT '0' - -#define MAXTOK 200 /* maximum length of a token */ -#define MAXLINE 255 -#define MAXIDENT 20 -#define MAXSKIPWORD 20 -#define MAXSKIPCHAR 20 - -#define MIN_INT -32768 -#define MAX_INT 32767 + + 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 reader (); + void gettext (char *str, int lim); + void usefile (int source, char *fn); + void closefile (); + int lookchar (); + int inchar (); + void ungetch (int c); + int get_inputline (FILE *fp); + void set_inputline (const char* const line); + - -// token types -enum { - TT_STRING = 1, // string token - TT_INT, // integer token - TT_REAL, // floating point token - TT_ALPHA, // alphabetic token - TT_ALPNUM, // alphanumeric token - TT_NUMALPHA, - TT_SPECLCHAR, - TT_EOF, // end of file reached - TT_ERROR, // error in token, caused by call to wrong type of token reader - TT_BLANK, // white space token. pol_tok() skips these - TT_USERTOK, // user defined token -}; + enum { + MAXTOK = 200, // maximum length of a token + MAXLINE = 1024, // maximum line length + MAXIDENT = 20, + MAXSKIPWORD = 20, + MAXSKIPCHAR = 20, + MIN_INT = -2000000000, + MAX_INT = 2000000000, + }; + + // token types + enum { + TT_STRING = 1, // string token + TT_INT, // integer token + TT_REAL, // floating point token + TT_ALPHA, // alphabetic token + TT_ALPNUM, // alphanumeric token + TT_NUMALPHA, + TT_SPECLCHAR, + TT_EOF, // end of file reached + TT_ERROR, // error in token, caused by call to wrong type of token reader + TT_BLANK, // white space token. pol_tok() skips these + TT_USERTOK, // user defined token + }; - -struct symlist { - char *name; - int code; - struct symlist *next; + +private: + + // codes for pol_int and pol_float + // if in reject catagory, get new number from terminal + enum { + P_FLTINT = 1, // get a real or integer number + P_BFLTINT, // get a real or integer number, clip against bounds + P_CBFLTINT, // get real or int, reject if outside bounds + P_FLT, // get a real number + P_BFLT, // get a real, clip against bounds + P_CBFLT, // get a floating, reject if outside bounds + P_INT, // get a integer number + P_BINT, // get a integer, clip against bounds + P_CBINT, // get a integer, reject if outside bounds + }; + +#define LETTER 'a' +#define DIGIT '0' + + +// typedef std::map KeywordCodeList; + + struct symlist { + char *name; + int code; + struct symlist *next; + }; + typedef struct symlist SYMBOL; + + struct token_st { + int ready; // TRUE if token is ready + // std::string tokstr; // token string + char tokstr[MAXTOK+1]; + int type; // type of token 'TT_' + int code; // holds code for user defined tokens + double fnum; // real value of token + int inum; // integer value of token + }; + typedef struct token_st TOKEN; + + + struct token_st token; // current token + enum { + HASHSIZE = 100, + }; + + // Tables words stored with install() & found with lookup() + SYMBOL *skiptable[HASHSIZE]; // words to ignore and skip + SYMBOL *cmdtable[HASHSIZE]; // pol parameter commands + SYMBOL *usertable[HASHSIZE]; // user defined symbols + + struct metachar { + char eoc; /* end of command character */ + char str; /* string delimiter */ + char com; /* comment character */ + char cmd; /* pol parameter command character */ + char prg; /* program load character */ + char con; /* continuation across newline character */ + char out; /* character that delimits output to terminal */ + char ter; /* character indicates insertion of input from terminal */ + char inb; /* input from graphics device */ + } meta; + + + // current pol state + struct pol_st { + char skipchars[MAXSKIPCHAR]; // characters to skip + int nl_eoc; // TRUE if newline character ends a command + int trace; // TRUE if trace is on + }; + + struct pol_st pol; + + struct KeywordCodeList { + char *keyword; + int code; + }; + + static const struct KeywordCodeList cmdlist[]; + static const int NUMCMD; + + // Internal codes for pol commands + enum { + PC_EOC = 1, + PC_STR, + PC_COM, + PC_CMD, + PC_PRG, + PC_CON, + PC_OUT, + PC_TER, + PC_INB, + PC_NL_EOC, + PC_NL_NEOC, + PC_TRON, + PC_TROFF, + PC_FILE, + PC_DUMP, + }; + + enum { + MAXFILE = 8, + }; + + int currentf; /* pointer to current fp */ + FILE *filep[MAXFILE]; /* == NULL for string input */ + char *fname[MAXFILE]; /* pointer to filename */ + + char inputline[MAXLINE]; /* current input line */ + int lineptr; /* current position in inputline */ + + enum { + BUFSIZE = 100, + }; + int bp; // pointer to next free position + int buf[BUFSIZE]; // pushed back input characters + + int skiptok(char term[]); + int tok(struct token_st *token); + void dumptok(struct token_st *token); + + + int getpol_tok(struct token_st *token); + int getcmd(); + int gettok (TOKEN *tok); + void getblank(char *s, int toksiz); + int getalpha(char *s, int toksiz); + void getquote(char *qs, int toksiz); + void getescape(char *s, int delim, int toksiz); + int getnumber (char str[], int strsize, double *fnum, int *inum); + void eatline(); + int type(int c); + void inittable(SYMBOL *table[]); + void freetable(SYMBOL *table[]); + int hash(char *s); + SYMBOL *lookup(SYMBOL *table[], char *s); + SYMBOL *install(SYMBOL *table[], char *s, int def); + int getch(FILE *fp); + }; -typedef struct symlist SYMBOL; - -struct token_st { - int ready; // TRUE if token is ready - char tokstr[MAXTOK+1]; // token string - int type; // type of token 'TT_' - int code; // holds code for user defined tokens - double fnum; // real value of token - int inum; // integer value of token -}; - -typedef struct token_st TOKEN; - - -/* pol.c */ -void pol_init (void); -void pol_skpword (char *w); -void pol_skpchar (char *s); -int pol_install (char *str, int code); -int pol_word (char *search, int nlet); -int pol_usertok (char *str, int *code); -int pol_string (char *str); -int pol_integer (int *n, int typecode, int boundcode, int bb1, int bb2); -int pol_float (double *n, double typecode, double boundcode, double bb1, double bb2); -int pol_skip (void); -void pol_reader (void); -void gettext (char *str, int lim); -void pol_usefile (int source, char *fn); -void pol_closefile (void); -int pol_lookchar (void); -int pol_inchar (void); -void pol_ungetch (int c); -int get_inputline (FILE *fp); -void set_inputline (const char* const line); - -#endif +#endif diff --git a/libctgraphics/ezplot.cpp b/libctgraphics/ezplot.cpp index eab8cc3..3831361 100644 --- a/libctgraphics/ezplot.cpp +++ b/libctgraphics/ezplot.cpp @@ -6,7 +6,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ezplot.cpp,v 1.23 2000/12/26 21:13:15 kevin Exp $ +** $Id: ezplot.cpp,v 1.24 2000/12/27 03:16:02 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 @@ -137,7 +137,22 @@ EZPlot::clearCurves () EZPlot::EZPlot (SGP& sgp) : rSGP (sgp) { - initPlotSettings(); + initKeywords(); + m_pol.skpword ("please"); + m_pol.skpword ("use"); + m_pol.skpword ("are"); + m_pol.skpword ("and"); + m_pol.skpword ("is"); + m_pol.skpword ("the"); + m_pol.skpword ("equals"); + m_pol.skpchar ("="); + + m_pol.usefile (POL::P_USE_STR,""); + m_pol.set_inputline ("!eoc ,"); + m_pol.reader (); + m_pol.closefile (); + + initPlotSettings(); } void @@ -544,17 +559,19 @@ EZPlot::plot () if (o_xaxis == NOAXIS || o_xtlabel == FALSE) xtl_ofs = 0.0; else if (o_xticks == BELOW) - xtl_ofs = -1.5 * charheight; + xtl_ofs = -0.5 * charheight; else if (o_xticks == ABOVE) - xtl_ofs = 1.5 * charheight; + xtl_ofs = 0.5 * charheight; if (o_yaxis == NOAXIS || o_ytlabel == FALSE) ytl_ofs = 0.0; else if (o_yticks == LEFT) - ytl_ofs = -(1 + y_fldwid) * charwidth; + ytl_ofs = -(2 + y_fldwid) * charwidth; else if (o_yticks == RIGHT) ytl_ofs = 1.5 * charwidth; + xa_max -= 0.7 * x_fldwid * charwidth; // make room for last x tick label + xt_min = xa_min; yt_min = ya_min; xt_max = xa_max; @@ -563,18 +580,18 @@ EZPlot::plot () // see if need to shrink axis extents and/or tick extents if (xtl_ofs != 0.0 && s_ycross == FALSE) { if (o_xticks == BELOW) { - ya_min += 2.5 * charheight; + ya_min += 1.5 * charheight; yt_min = ya_min; } else if (o_xticks == ABOVE) { ya_min += 0.0; - yt_min = ya_min + 2.5 * charheight; + yt_min = ya_min + 1.5 * charheight; } } else // noaxis, no t-labels, or user set cross yt_min = ya_min; if (ytl_ofs != 0.0 && s_xcross == FALSE) { if (o_yticks == LEFT) { - xa_min += (1 + y_fldwid) * charwidth; + xa_min += (2 + y_fldwid) * charwidth; xt_min = xa_min; } else if (o_yticks == RIGHT) { xa_min += 0.0; @@ -582,7 +599,7 @@ EZPlot::plot () } } else xt_min = xa_min; - + // decrease size of graph, if necessary, to accommadate space // between axis boundary and boundary of ticks double x_added_ticks = 0; // number of tick spaces added to axis @@ -713,9 +730,9 @@ EZPlot::drawAxes() rSGP.setTextColor (1, -1); if (o_xticks == ABOVE) - xticklen = charheight; + xticklen = 0.5 * charheight; else if (o_xticks == BELOW) - xticklen = -charheight; + xticklen = -0.5 * charheight; if (o_yticks == RIGHT) yticklen = charwidth; @@ -884,8 +901,8 @@ EZPlot::drawAxes() axis_near = TRUE; } if (o_ytlabel == TRUE && axis_near == FALSE) { - snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i); - rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight); + snprintf (str, sizeof(str), y_numfmt, ygw_min + yw_tickinc * i); + rSGP.moveAbs (yaxispos + ytl_ofs, y + 0.5 * charheight); rSGP.setTextColor (clr_number, -1); rSGP.drawText (str); } diff --git a/libctgraphics/ezset.cpp b/libctgraphics/ezset.cpp index b380e9a..6913144 100644 --- a/libctgraphics/ezset.cpp +++ b/libctgraphics/ezset.cpp @@ -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.13 2000/12/27 03:16:02 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; - bool EZPlot::ezset (const std::string& command) @@ -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); + + 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.usertok (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.gettext (strIn, sizeof(strIn)); c_title = strIn; break; case S_LEGEND: - gettext (strIn, sizeof(strIn)); + m_pol.gettext (strIn, sizeof(strIn)); if (m_iCurrentCurve >= 0) setLegend (m_iCurrentCurve, strIn); break; case S_XLABEL: - gettext (strIn, sizeof(strIn)); + m_pol.gettext (strIn, sizeof(strIn)); c_xlabel = strIn; break; case S_YLABEL: - gettext (strIn, sizeof(strIn)); + m_pol.gettext (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; ls = SGP::LS_DASH1; - if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) { + if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { 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.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { if (n >= 0) { 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.word("no", 2) == TRUE) o_tag = FALSE; - else if (pol_word("off", 2) == TRUE) + else if (m_pol.word("off", 2) == TRUE) o_tag = FALSE; else o_tag = TRUE; break; case S_LEGENDBOX: - if (pol_word("inside", 2) == TRUE) + if (m_pol.word("inside", 2) == TRUE) o_legendbox = INSIDE; - else if (pol_word("outside", 3) == TRUE) + else if (m_pol.word("outside", 3) == TRUE) o_legendbox = OUTSIDE; - else if (pol_word("none",2) == TRUE) + else if (m_pol.word("none",2) == TRUE) o_legendbox = NOLEGEND; else { - gettext (str, MAXTOK); + m_pol.gettext (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.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { if (n > 0 && n <= MAXSYMBOL) { if (m_iCurrentCurve < 0) o_symbol = n; @@ -308,8 +289,8 @@ EZPlot::do_cmd (int lx) setSymbol (m_iCurrentCurve, n); } } else { - if (pol_word("every",5) == TRUE) { - if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) { + if (m_pol.word("every",5) == TRUE) { + if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { int sym = 1; if (n > 0) sym = n; @@ -318,22 +299,22 @@ EZPlot::do_cmd (int lx) else setSymbolFreq (m_iCurrentCurve, sym); } - } else if (pol_word ("none",4) == TRUE) { + } else if (m_pol.word ("none",4) == TRUE) { o_symbol = -1; } } break; case S_CURVE: - if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) { + if (m_pol.integer (&n, POL::TT_REAL, FALSE, 0, 0) == TRUE) { if (n > 0) m_iCurrentCurve = n - 1; } else { - if (pol_word ("all",3) == TRUE) + if (m_pol.word ("all",3) == TRUE) m_iCurrentCurve = -1; } break; case S_XTICKS: - if (pol_usertok(str,&lx) == FALSE) + if (m_pol.usertok(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.integer (&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.integer (&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.usertok(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.integer (&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.integer (&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.integer (&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.integer (&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,6 @@ 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]"); + if (! m_pol.installKeyword (m_sKeywords[i].keyword, m_sKeywords [i].code)) + sys_error (ERR_SEVERE, "error installing ezset keywords [EZPlot::initKeywords]"); } diff --git a/libctgraphics/pol.cpp b/libctgraphics/pol.cpp index 5ba4900..f3ef311 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.5 2000/12/25 21:54:26 kevin Exp $ +** $Id: pol.cpp,v 1.6 2000/12/27 03:16:02 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 @@ -32,62 +32,10 @@ #include "pol.h" -static const int HASHSIZE=100; -// Tables words stored with install() & found with lookup() -static SYMBOL *skiptable[HASHSIZE]; // words to ignore and skip -static SYMBOL *cmdtable[HASHSIZE]; // pol parameter commands -static SYMBOL *usertable[HASHSIZE]; // user defined symbols -static struct token_st token; // current token - - -static struct metachar { - char eoc; /* end of command character */ - char str; /* string delimiter */ - char com; /* comment character */ - char cmd; /* pol parameter command character */ - char prg; /* program load character */ - char con; /* continuation across newline character */ - char out; /* character that delimits output to terminal */ - char ter; /* character indicates insertion of input from terminal */ - char inb; /* input from graphics device */ -} meta; - - -// current pol state -static struct pol_st { - char skipchars[MAXSKIPCHAR]; // characters to skip - int nl_eoc; // TRUE if newline character ends a command - int trace; // TRUE if trace is on -} pol; - -struct key { - char *keyword; - int code; -}; - -// Internal codes for pol commands -enum { - PC_EOC = 1, - PC_STR, - PC_COM, - PC_CMD, - PC_PRG, - PC_CON, - PC_OUT, - PC_TER, - PC_INB, - PC_NL_EOC, - PC_NL_NEOC, - PC_TRON, - PC_TROFF, - PC_FILE, - PC_DUMP, -}; - -static struct key cmdlist[] = { +const struct POL::KeywordCodeList POL::cmdlist[] = { { "eoc", PC_EOC,}, { "str", PC_STR,}, { "com", PC_COM,}, @@ -106,33 +54,22 @@ static struct key cmdlist[] = { { "dump", PC_DUMP,}, }; -const int NUMCMD = (sizeof(cmdlist) / sizeof (struct key)); +const int POL::NUMCMD = (sizeof(POL::cmdlist) / sizeof (struct POL::KeywordCodeList)); -static int skiptok(char term[]); -static int pol_tok(struct token_st *token); -static void dumptok(struct token_st *token); - - -static int getpol_tok(struct token_st *token); -static int getcmd(void); -static int gettok (TOKEN *tok); -static void getblank(char *s, int toksiz); -static int getalpha(char *s, int toksiz); -static void getquote(char *qs, int toksiz); -static void getescape(char *s, int delim, int toksiz); -static int getnumber (char str[], int strsize, double *fnum, int *inum); -static void eatline(void); -static int type(int c); -static void inittable(SYMBOL *table[]); -static void freetable(SYMBOL *table[]); -static int hash(char *s); -static SYMBOL *lookup(SYMBOL *table[], char *s); -static SYMBOL *install(SYMBOL *table[], char *s, int def); -static int pol_getch(FILE *fp); - - -void pol_init (void) +POL::POL() +{ + bp = 0; + currentf = -1; + init(); +} + +POL::~POL() +{ +} + +void +POL::init () { meta.eoc = SEMICOL; meta.str = DQUOTE; @@ -157,41 +94,40 @@ void pol_init (void) token.ready = FALSE; /* no token read yet */ } -/* pol_skpword (w) +/* skpword (w) * * char *w - word for pol to ignore and skip over in input * - * pol_tok() compares all tokens to words given to this routine. If it finds it, + * tok() compares all tokens to words given to this routine. If it finds it, * it will immediately read another token. */ void -pol_skpword (char *w) +POL::skpword (char *w) { if (install (skiptable, w, 0) == NULL) sys_error (ERR_SEVERE, "Too many skip words defined"); } -/* pol_skpchar (s) +/* skpchar (s) * * skip all characters that appear in string s */ void -pol_skpchar (char *s) +POL::skpchar (char *s) { strncpy (pol.skipchars, s, MAXSKIPCHAR); } -/* pol_install (str, code) - * - * char *str - token string to install - * int code - code to return for token - * - * pol_tok() looks for these user defined tokens. If it finds one, - * it stores the tokens code in the token structure and returns TT_USERTOK - */ +// installKeyword (str, code) +// +// char *str - token string to install +// int code - code to return for token +// +// tok() looks for these user defined tokens. If it finds one, +// it stores the tokens code in the token structure and returns TT_USERTOK int -pol_install (char *str, int code) +POL::installKeyword (char *str, int code) { if (install (usertable, str, code) == NULL) { @@ -209,9 +145,9 @@ pol_install (char *str, int code) */ int -pol_word (char *search, int nlet) +POL::word (char *search, int nlet) { - pol_tok (&token); + tok (&token); if (pol.trace == TRUE) printf ("matching current token %s against word %s\n", token.tokstr, search); @@ -222,8 +158,8 @@ pol_word (char *search, int nlet) return (FALSE); } -/* pol_usertok (str,code) - * see if current token is a user defined token set with pol_install() +/* usertok (str,code) + * see if current token is a user defined token set with install() * * char *str - token string as read from input * int *code - returned code for user defined symbol @@ -231,9 +167,9 @@ pol_word (char *search, int nlet) * FALSE if current token is not user defined */ int -pol_usertok (char *str, int *code) +POL::usertok (char *str, int *code) { - pol_tok (&token); + tok (&token); if (pol.trace == TRUE) printf ("checking if current token '%s' is user defined\n", token.tokstr); @@ -255,9 +191,9 @@ pol_usertok (char *str, int *code) */ int -pol_string (char *str) +POL::string (char *str) { - pol_tok (&token); + tok (&token); if (token.type == TT_STRING) { strcpy (str, token.tokstr); @@ -267,7 +203,7 @@ pol_string (char *str) return (FALSE); } -/* pol_integer - test for an integer +/* integer - test for an integer * * int *n: returned integer value * int typecode = TT_INT if accept only integer values @@ -278,9 +214,9 @@ pol_string (char *str) * int bb2: upper bound */ int -pol_integer (int *n, int typecode, int boundcode, int bb1, int bb2) +POL::integer (int *n, int typecode, int boundcode, int bb1, int bb2) { - pol_tok (&token); + tok (&token); if (pol.trace == TRUE) printf ("checking if current token %s is an integer\n", token.tokstr); @@ -302,10 +238,10 @@ pol_integer (int *n, int typecode, int boundcode, int bb1, int bb2) return (FALSE); } -int -pol_float (double *n, double typecode, double boundcode, double bb1, double bb2) +bool +POL::readfloat (double *n, double typecode, double boundcode, double bb1, double bb2) { - pol_tok (&token); + tok (&token); if (pol.trace == TRUE) printf ("checking if current token %s is an floating point number\n", token.tokstr); @@ -328,13 +264,14 @@ pol_float (double *n, double typecode, double boundcode, double bb1, double bb2) } /*----------------------------------------------------------------------*/ -/* pol_skip() - skip over any token except for end of command sequence */ +/* skip() - skip over any token except for end of command sequence */ /* */ /* returns TRUE if succesful skip */ /* returns FALSE if already at end of command or EOF */ /*----------------------------------------------------------------------*/ -int pol_skip(void) +int +POL::skip() { char term[5]; /* string of characters not to skip */ @@ -348,9 +285,10 @@ int pol_skip(void) return (skiptok (term)); } -void pol_reader(void) +void +POL::reader() { - while (pol_skip() == TRUE) + while (skip() == TRUE) ; dumptok (&token); /* skip end of command token */ @@ -364,10 +302,10 @@ void pol_reader(void) * returns (FALSE) if didn't skip, read termination character or TT_EOF */ -static int -skiptok (char term[]) +int +POL::skiptok (char term[]) { - pol_tok (&token); + tok (&token); if (token.type == TT_EOF || (token.type == TT_SPECLCHAR && strchr(term, token.tokstr[0]) != NULL)) @@ -378,27 +316,27 @@ skiptok (char term[]) } } -static int -pol_tok (struct token_st *token) +int +POL::tok (struct token_st *token) { if (token->ready == FALSE) getpol_tok(token); else - if (token->type == TT_EOF && pol_lookchar() != EOF) + if (token->type == TT_EOF && lookchar() != EOF) getpol_tok(token); return (token->type); } -static void -dumptok (struct token_st *token) +void +POL::dumptok (struct token_st *token) { if (token->ready == FALSE) getpol_tok(token); token->ready = FALSE; } -static int -getpol_tok (struct token_st *token) +int +POL::getpol_tok (struct token_st *token) { SYMBOL *sym; @@ -427,15 +365,15 @@ nexttok: goto nexttok; } if (token->tokstr[0] == meta.con) { /* continuation across NEWLINE */ - while (pol_lookchar() == BLANK || pol_lookchar() == TAB) - pol_inchar(); - if (pol_lookchar() == NEWLINE) - pol_inchar(); + while (lookchar() == BLANK || lookchar() == TAB) + inchar(); + if (lookchar() == NEWLINE) + inchar(); } if (token->tokstr[0] == meta.ter) { /* get input from terminal */ - pol_usefile (P_USE_FILE, ""); - pol_tok (token); - pol_closefile(); + usefile (P_USE_FILE, ""); + tok (token); + closefile(); return (token->type); } } @@ -460,7 +398,8 @@ nexttok: } -static int getcmd(void) +int +POL::getcmd() { int tt, found; char str[MAXTOK+1]; @@ -470,12 +409,12 @@ static int getcmd(void) tt = getalpha (str, MAXTOK); if (tt == TT_ERROR) { sys_error (ERR_WARNING, "Error in POL parameter command"); - pol_reader(); + reader(); return(FALSE); } if ((cmd = lookup (cmdtable,str)) == NULL) { sys_error (ERR_WARNING, "POL: Unrecognized command %s", cmd); - pol_reader(); + reader(); return (FALSE); } else { found = FALSE; @@ -491,7 +430,7 @@ static int getcmd(void) case PC_FILE: found = TRUE; tt = gettok (&tok); - pol_usefile (P_USE_FILE, tok.tokstr); + usefile (P_USE_FILE, tok.tokstr); break; case PC_NL_EOC: found = TRUE; @@ -548,26 +487,26 @@ static int getcmd(void) break; } /* switch (tok->type) */ } /* if (found == FALSE) */ - pol_reader(); /* clean up command */ + reader(); /* clean up command */ } /* if legal command */ return (TRUE); } -static int -gettok (TOKEN *tok) +int +POL::gettok (TOKEN *tok) { int c, toktype; int inum; double fnum; int toksiz = MAXTOK; /* maximum length of token string */ - while ((c = pol_inchar()) == BLANK || c == TAB) + while ((c = inchar()) == BLANK || c == TAB) ; - pol_ungetch (c); + ungetch (c); - c = pol_lookchar(); + c = lookchar(); toktype = type(c); fnum = 0.0; @@ -587,7 +526,7 @@ gettok (TOKEN *tok) tok->tokstr[0] = EOS; toktype = TT_EOF; } else { - c = pol_inchar(); + c = inchar(); tok->tokstr[0] = c; tok->tokstr[1] = EOS; toktype = TT_SPECLCHAR; @@ -607,40 +546,40 @@ gettok (TOKEN *tok) } -static void -getblank (char *s, int toksiz) +void +POL::getblank (char *s, int toksiz) { int c; - while ((c = pol_inchar()) == BLANK || c == TAB) + while ((c = inchar()) == BLANK || c == TAB) ; - pol_ungetch(c); + ungetch(c); s[0] = BLANK; s[1] = EOS; } -static int -getalpha (char *s, int toksiz) +int +POL::getalpha (char *s, int toksiz) { int i, chartype, alphatype; - if (type(pol_lookchar()) != LETTER) { + if (type(lookchar()) != LETTER) { s[0] = EOS; return (TT_ERROR); } alphatype = TT_ALPHA; for (i = 0; i < toksiz; i++) { /* get alphanumeric token */ - s[i] = pol_inchar(); + s[i] = inchar(); chartype = type (s[i]); if (chartype != LETTER && chartype != DIGIT) break; if (chartype == DIGIT) alphatype = TT_ALPNUM; } - pol_ungetch(s[i]); + ungetch(s[i]); if (i >= toksiz) sys_error (ERR_SEVERE, "POL token too long."); @@ -652,18 +591,18 @@ getalpha (char *s, int toksiz) /* getquote - get quoted string from file */ /* have already gotten delimiter in qs[0] */ -static void -getquote (char *qs, int toksiz) +void +POL::getquote (char *qs, int toksiz) { int delim; - delim = pol_inchar(); /* char = delimiter */ + delim = inchar(); /* char = delimiter */ getescape(qs, delim, toksiz); } -static void -getescape ( /* reads up to delim */ +void +POL::getescape ( /* reads up to delim */ char *s, int delim, int toksiz @@ -671,7 +610,7 @@ getescape ( /* reads up to delim */ { int i, c; - for (i = 0; (c = pol_inchar()) != delim; i++) { + for (i = 0; (c = inchar()) != delim; i++) { if (c == NEWLINE) { sys_error (ERR_WARNING, "Missing closing delimiter."); break; @@ -681,12 +620,12 @@ getescape ( /* reads up to delim */ break; } if (c == EOF) { - pol_ungetch(c); + ungetch(c); sys_error (ERR_SEVERE, "end of file inside quotation"); break; } else if (c == BSLASH) { /* escape character */ s[i++] = c; - c = pol_inchar(); /* get escaped character */ + c = inchar(); /* get escaped character */ } s[i] = c; } @@ -694,26 +633,27 @@ getescape ( /* reads up to delim */ } void -gettext (char *str, int lim) +POL::gettext (char *str, int lim) { int c, i; - while ((c = pol_inchar()) == BLANK || c == TAB) + while ((c = inchar()) == BLANK || c == TAB) ; - pol_ungetch (c); + ungetch (c); - for (i = 0; i < lim && (c = pol_inchar()) != EOF && c != NEWLINE; i++) + for (i = 0; i < lim && (c = inchar()) != EOF && c != NEWLINE; i++) str[i] = c; - pol_ungetch (c); + ungetch (c); str[i] = EOS; } -/*----------------------------------------------*/ -/* Get a number for gettok() */ -/*----------------------------------------------*/ +//---------------------------------------------- +// Get a number for gettok() +//---------------------------------------------- -static int -getnumber ( +int +POL::getnumber +( char str[], /* string to return token in */ int strsize, /* maximum length of token string */ double *fnum, /* floating point value of number read */ @@ -730,7 +670,7 @@ getnumber ( *inum = 0; str[0] = EOS; - c = pol_inchar(); + c = inchar(); if (c == HYPHEN) { str[sp++] = c; isSigned = TRUE; @@ -740,24 +680,24 @@ getnumber ( isSigned = TRUE; sign = 1.0; } else if (c == PERIOD) { - if (type(pol_lookchar()) != DIGIT) { + if (type(lookchar()) != DIGIT) { str[0] = PERIOD; str[1] = EOS; return (TT_SPECLCHAR); } else - pol_ungetch (PERIOD); + ungetch (PERIOD); } else if (type(c) != DIGIT) { - pol_ungetch (c); + ungetch (c); return (TT_ERROR); } else - pol_ungetch (c); + ungetch (c); if (isSigned == TRUE) { - c = pol_lookchar(); + c = lookchar(); if (c == PERIOD) { - pol_inchar(); /* get period */ - c = pol_lookchar(); /* look at character past period */ - pol_ungetch (PERIOD); /* put back period */ + inchar(); /* get period */ + c = lookchar(); /* look at character past period */ + ungetch (PERIOD); /* put back period */ if (type(c) != DIGIT) { str[sp] = EOS; return (TT_SPECLCHAR); @@ -769,12 +709,12 @@ getnumber ( } whole = 0.0; - while (type(c = pol_inchar()) == DIGIT) { + while (type(c = inchar()) == DIGIT) { if (sp < strsize) str[sp++] = c; whole = 10.0 * whole + (c - '0'); } - pol_ungetch (c); /* put back non-numeric character */ + ungetch (c); /* put back non-numeric character */ if (c != PERIOD && tolower(c) != 'e') { str[sp] = EOS; @@ -788,8 +728,8 @@ getnumber ( return (TT_INT); } - if (pol_lookchar() == PERIOD) { - pol_inchar(); + if (lookchar() == PERIOD) { + inchar(); if (sp < strsize) str[sp++] = PERIOD; } @@ -797,23 +737,23 @@ getnumber ( frac = 0.0; powerof10 = 10.0; - while (type(c = pol_inchar()) == DIGIT) { + while (type(c = inchar()) == DIGIT) { if (sp < strsize) str[sp++] = c; frac += (double) (c - '0') / powerof10; powerof10 *= 10.0; } - pol_ungetch (c); + ungetch (c); exp = 0.0; expsign = 1.0; - c = pol_inchar(); + c = inchar(); if (tolower(c) != 'e') - pol_ungetch (c); + ungetch (c); else { if (sp < strsize) str[sp++] = c; - if ((c = pol_inchar()) == PLUS) { + if ((c = inchar()) == PLUS) { if (sp < strsize) str[sp++] = c; expsign = 1.0; @@ -823,19 +763,19 @@ getnumber ( expsign = -1.0; } else if (type(c) != DIGIT) { --sp; /* erase 'e' */ - pol_ungetch (c); - pol_ungetch ('e'); + ungetch (c); + ungetch ('e'); goto getnumexit; } else - pol_ungetch(c); + ungetch(c); exp = 0; - while (type(c = pol_inchar()) == DIGIT) { + while (type(c = inchar()) == DIGIT) { if (sp < strsize) str[sp++] = c; exp = 10 * exp + (c - '0'); } - pol_ungetch (c); + ungetch (c); } getnumexit: @@ -850,8 +790,8 @@ getnumexit: return (TT_REAL); } -static void -eatline (void) +void +POL::eatline () { char term [2]; @@ -860,10 +800,9 @@ eatline (void) skiptok (term); } -static int -type ( /* return type of ASCII character */ - int c -) +// return type of ASCII character +int +POL::type (int c) { if (isalpha(c) || c == UNDERLIN) return (LETTER); @@ -883,8 +822,8 @@ type ( /* return type of ASCII character */ * clear symbol table */ -static void -inittable (SYMBOL *table[]) +void +POL::inittable (SYMBOL *table[]) { int i; @@ -896,8 +835,8 @@ inittable (SYMBOL *table[]) * free all memory allocated to table, then clear table */ -static void -freetable (SYMBOL *table[]) +void +POL::freetable (SYMBOL *table[]) { int i; SYMBOL *p, *np; @@ -913,10 +852,9 @@ freetable (SYMBOL *table[]) inittable (table); } -static int -hash ( /* form hash value of string s */ - char *s -) +// form hash value of string s +int +POL::hash (char *s) { int hashval; @@ -926,8 +864,8 @@ hash ( /* form hash value of string s */ } /* Look for s in hash table */ -static SYMBOL * -lookup ( SYMBOL *table[], char *s ) +POL::SYMBOL * +POL::lookup ( SYMBOL *table[], char *s ) { SYMBOL *np; SYMBOL *found = NULL; @@ -941,8 +879,8 @@ lookup ( SYMBOL *table[], char *s ) return (found); } -static SYMBOL * -install (SYMBOL *table[], char *name, int def) +POL::SYMBOL * +POL::install (SYMBOL *table[], char *name, int def) { static char installerr[] = "install: out of memory"; SYMBOL *np; @@ -968,29 +906,12 @@ install (SYMBOL *table[], char *name, int def) return (np); } -/*----------------------------------------------------------------------*/ -/* POL OUTPUT */ -/*----------------------------------------------------------------------*/ - -#define MAXFILE 8 - -static int currentf = -1; /* pointer to current fp */ -static FILE *filep[MAXFILE]; /* == NULL for string input */ -static char *fname[MAXFILE]; /* pointer to filename */ - -static char inputline[MAXLINE]; /* current input line */ -static int lineptr; /* current position in inputline */ - - //---------------------------------------------------------------------- // POL INPUT //---------------------------------------------------------------------- -#define BUFSIZE 100 -static int bp = 0; /* pointer to next free position */ -static int buf[BUFSIZE]; /* pushed back input characters */ -/* pol_usefile - set source of POL input +/* usefile - set source of POL input * * int source - source of input * P_USE_STR - have POL use strings as input @@ -999,7 +920,7 @@ static int buf[BUFSIZE]; /* pushed back input characters */ */ void -pol_usefile (int source, char *fn) +POL::usefile (int source, char *fn) { FILE *fp; @@ -1027,7 +948,8 @@ pol_usefile (int source, char *fn) } } -void pol_closefile(void) +void +POL::closefile() { if (currentf >= 0) { if (filep[currentf] != NULL) @@ -1041,24 +963,26 @@ void pol_closefile(void) /*-----------------------------*/ -int pol_lookchar(void) +int +POL::lookchar() { int c; - c = pol_inchar(); - pol_ungetch (c); + c = inchar(); + ungetch (c); return (c); } -int pol_inchar(void) +int +POL::inchar() { int c = 0; if (currentf < 0) return (EOF); - while (currentf >= 0 && (c = pol_getch(filep[currentf])) == EOF && filep[currentf] != NULL) { - pol_closefile (); + while (currentf >= 0 && (c = getch(filep[currentf])) == EOF && filep[currentf] != NULL) { + closefile (); } return (c); @@ -1069,8 +993,8 @@ int pol_inchar(void) /* if fp == NULL, then get character from inputline */ /*--------------------------------------------------------------*/ -static int -pol_getch (FILE *fp) +int +POL::getch (FILE *fp) { int c; @@ -1092,17 +1016,17 @@ pol_getch (FILE *fp) /* push character back on input */ void -pol_ungetch (int c) +POL::ungetch (int c) { if (bp > BUFSIZE) - sys_error (ERR_SEVERE, "too many characters pushed back [pol_ungetch]"); + sys_error (ERR_SEVERE, "too many characters pushed back [ungetch]"); else buf[bp++] = c; } int -get_inputline (FILE *fp) +POL::get_inputline (FILE *fp) { lineptr = 0; bp = 0; @@ -1113,7 +1037,7 @@ get_inputline (FILE *fp) } void -set_inputline (const char* const line) +POL::set_inputline (const char* const line) { lineptr = 0; bp = 0; diff --git a/libctsupport/plotfile.cpp b/libctsupport/plotfile.cpp index b05705a..706fce1 100644 --- a/libctsupport/plotfile.cpp +++ b/libctsupport/plotfile.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: plotfile.cpp,v 1.5 2000/12/23 18:12:35 kevin Exp $ +** $Id: plotfile.cpp,v 1.6 2000/12/27 03:16:02 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 @@ -242,9 +242,7 @@ PlotFile::headerWrite (std::iostream& fs) } fs.seekp (0); - fs << "\n"; - fs << "" << m_iNumColumns << "\n"; - fs << "" << m_iNumRecords << "\n"; + fs << "\n"; int iNEzset = m_vecStrEzsetCommands.size(); if (iNEzset > 0) { diff --git a/msvc/ctsim/ctsim.plg b/msvc/ctsim/ctsim.plg index c6fc514..4277633 100644 --- a/msvc/ctsim/ctsim.plg +++ b/msvc/ctsim/ctsim.plg @@ -6,13 +6,26 @@ --------------------Configuration: libctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A3.tmp" with contents +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP42.tmp" with contents [ /nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "..\..\..\zlib" /I "..\..\INCLUDE" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /I "..\..\..\wx2\include" /D "_DEBUG" /D "HAVE_WXWIN" /D "HAVE_STRING_H" /D "HAVE_GETOPT_H" /D "WIN32" /D "_MBCS" /D "_LIB" /D "MSVC" /D "HAVE_FFTW" /D "HAVE_PNG" /D "HAVE_SGP" /D "HAVE_WXWINDOWS" /D "__WXMSW__" /FR"Debug/" /Fp"Debug/libctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"C:\ctsim-2.0.6\libctsim\backprojectors.cpp" "C:\ctsim-2.0.6\libctgraphics\ezplot.cpp" +"C:\ctsim-2.0.6\libctgraphics\ezset.cpp" +"C:\ctsim-2.0.6\libctgraphics\ezsupport.cpp" +"C:\ctsim-2.0.6\libctsim\filter.cpp" +"C:\ctsim-2.0.6\libctsim\imagefile.cpp" +"C:\ctsim-2.0.6\libctsim\phantom.cpp" +"C:\ctsim-2.0.6\libctsupport\plotfile.cpp" +"C:\ctsim-2.0.6\libctgraphics\pol.cpp" +"C:\ctsim-2.0.6\libctsim\procsignal.cpp" +"C:\ctsim-2.0.6\libctsim\projections.cpp" +"C:\ctsim-2.0.6\libctsim\reconstruct.cpp" +"C:\ctsim-2.0.6\libctsim\scanner.cpp" +"C:\ctsim-2.0.6\libctsim\trace.cpp" ] -Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A3.tmp" -Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A4.tmp" with contents +Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP42.tmp" +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP43.tmp" with contents [ /nologo /out:"Debug\libctsim.lib" ".\Debug\array2dfile.obj" @@ -42,16 +55,40 @@ Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A4.tmp" with conten ".\Debug\transformmatrix.obj" ".\Debug\xform.obj" ] -Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A4.tmp" +Creating command line "link.exe -lib @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP43.tmp"

Output Window

Compiling... +backprojectors.cpp ezplot.cpp +ezset.cpp +ezsupport.cpp +filter.cpp +imagefile.cpp +phantom.cpp +plotfile.cpp +pol.cpp +procsignal.cpp +projections.cpp +reconstruct.cpp +scanner.cpp +trace.cpp Creating library...

--------------------Configuration: ctsim - Win32 Debug--------------------

Command Lines

-Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A5.tmp" with contents +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP44.tmp" with contents +[ +/nologo /G6 /MTd /W3 /Gm /GR /GX /ZI /Od /I "\wx2\include" /I "." /I "..\..\include" /I "..\..\getopt" /I "..\..\..\lpng108" /I "..\..\..\zlib" /I "..\..\..\fftw-2.1.3\fftw" /I "..\..\..\fftw-2.1.3\rfftw" /D VERSION=\"2.5.0\" /D "_DEBUG" /D "__WXMSW__" /D "HAVE_SGP" /D "HAVE_PNG" /D "HAVE_WXWINDOWS" /D "WIN32" /D "_WINDOWS" /D "_MBCS" /D "HAVE_STRING_H" /D "HAVE_FFTW" /D "HAVE_RFFTW" /D "HAVE_GETOPT_H" /D "MSVC" /D "__WIN95__" /D "__WIN32__" /D WINVER=0x0400 /D "STRICT" /D CTSIMVERSION=\"2.5.0\" /FR"Debug/" /Fp"Debug/ctsim.pch" /YX /Fo"Debug/" /Fd"Debug/" /FD /GZ /c +"C:\ctsim-2.0.6\src\ctsim.cpp" +"C:\ctsim-2.0.6\src\dialogs.cpp" +"C:\ctsim-2.0.6\src\dlgprojections.cpp" +"C:\ctsim-2.0.6\src\dlgreconstruct.cpp" +"C:\ctsim-2.0.6\src\docs.cpp" +"C:\ctsim-2.0.6\src\views.cpp" +] +Creating command line "cl.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP44.tmp" +Creating temporary file "C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP45.tmp" with contents [ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ../libctsim/Debug/libctsim.lib kernel32.lib user32.lib gdi32.lib winspool.lib comdlg32.lib advapi32.lib shell32.lib ole32.lib oleaut32.lib uuid.lib odbc32.lib odbccp32.lib ..\..\..\lpng108\msvc\win32\libpng\lib_dbg\libpng.lib ..\..\..\lpng108\msvc\win32\zlib\lib_dbg\zlib.lib libcmtd.lib ..\..\..\fftw-2.1.3\Win32\FFTW2st\Debug\FFTW2st.lib ..\..\..\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib ../../../wx2/lib/wxd.lib /nologo /subsystem:windows /incremental:yes /pdb:"Debug/ctsim.pdb" /debug /machine:I386 /nodefaultlib:"libcd.lib" /nodefaultlib:"libcid.lib" /nodefaultlib:"msvcrtd.lib" /out:"Debug/ctsim.exe" /pdbtype:sept /libpath:"..\..\..\lpng108\msvc\win32\libpng\lib" /libpath:"..\..\..\lpng108\msvc\win32\zlib\lib" ".\Debug\ctsim.obj" @@ -66,9 +103,19 @@ comctl32.lib winmm.lib rpcrt4.lib ws2_32.lib kernel32.lib user32.lib gdi32.lib w "\fftw-2.1.3\Win32\RFFTW2st\Debug\RFFTW2st.lib" "\wx2\lib\wxd.lib" ] -Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP2A5.tmp" +Creating command line "link.exe @C:\DOCUME~1\kevin\LOCALS~1\Temp\RSP45.tmp"

Output Window

+Compiling... +ctsim.cpp +dialogs.cpp +dlgprojections.cpp +dlgreconstruct.cpp +docs.cpp +views.cpp Linking... +Creating command line "bscmake.exe /nologo /o"Debug/ctsim.bsc" ".\Debug\ctsim.sbr" ".\Debug\dialogs.sbr" ".\Debug\dlgprojections.sbr" ".\Debug\dlgreconstruct.sbr" ".\Debug\docs.sbr" ".\Debug\views.sbr"" +Creating browse info file... +

Output Window

diff --git a/src/ctsim.cpp b/src/ctsim.cpp index b128641..06c91ea 100644 --- a/src/ctsim.cpp +++ b/src/ctsim.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: ctsim.cpp,v 1.20 2000/12/22 04:18:00 kevin Exp $ +** $Id: ctsim.cpp,v 1.21 2000/12/27 03:16:02 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 @@ -61,7 +61,7 @@ #endif #endif -static const char* rcsindent = "$Id: ctsim.cpp,v 1.20 2000/12/22 04:18:00 kevin Exp $"; +static const char* rcsindent = "$Id: ctsim.cpp,v 1.21 2000/12/27 03:16:02 kevin Exp $"; class CTSimApp* theApp = NULL; @@ -292,16 +292,13 @@ CTSimApp::getCompatibleImages (const ImageFileDocument* pIFDoc, std::vectorGetDocuments(); - std::vector vecFilename; for (wxNode* pNode = rListDocs.GetFirst(); pNode != NULL; pNode = pNode->GetNext()) { wxDocument* pDoc = reinterpret_cast(pNode->GetData()); ImageFileDocument* pIFCompareDoc = dynamic_cast(pDoc); if (pIFCompareDoc && (pIFDoc != pIFCompareDoc)) { const ImageFile& rCompareIF = pIFCompareDoc->getImageFile(); - if (rCompareIF.nx() == nx && rCompareIF.ny() == ny) { - std::string strFilename = pDoc->GetFilename(); + if (rCompareIF.nx() == nx && rCompareIF.ny() == ny) vecIF.push_back (pIFCompareDoc); - } } } } diff --git a/src/dialogs.cpp b/src/dialogs.cpp index 7d8c0ec..4a44735 100644 --- a/src/dialogs.cpp +++ b/src/dialogs.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: dialogs.cpp,v 1.20 2000/12/22 04:18:00 kevin Exp $ +** $Id: dialogs.cpp,v 1.21 2000/12/27 03:16:02 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 @@ -47,12 +47,13 @@ #include "wx/statline.h" #include "wx/sizer.h" #include "dialogs.h" -#include "ctsupport.h" #include "ctsim.h" -#include "scanner.h" -#include "phantom.h" -#include "filter.h" -#include "backprojectors.h" +#include "ct.h" +//#include "ctsupport.h" +//#include "scanner.h" +//#include "phantom.h" +//#include "filter.h" +//#include "backprojectors.h" #include "docs.h" #include "views.h" #include "imagefile.h" diff --git a/src/docs.cpp b/src/docs.cpp index c3fd489..ac7e3a6 100644 --- a/src/docs.cpp +++ b/src/docs.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: docs.cpp,v 1.7 2000/12/19 21:37:51 kevin Exp $ +** $Id: docs.cpp,v 1.8 2000/12/27 03:16:02 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 @@ -201,6 +201,18 @@ void PhantomDocument::Modify(bool mod) IMPLEMENT_DYNAMIC_CLASS(PlotFileDocument, wxDocument) +bool PlotFileDocument::OnSaveDocument(const wxString& filename) +{ + m_namePlot = filename.c_str(); + if (! m_plot.fileWrite (filename)) { + *theApp->getLog() << "Unable to write plot file " << filename << "\n"; + return false; + } + *theApp->getLog() << "Wrote plot file " << filename << "\n"; + Modify(false); + return true; +} + bool PlotFileDocument::OnOpenDocument(const wxString& filename) { if (filename == "untitled.plt") { @@ -212,7 +224,8 @@ bool PlotFileDocument::OnOpenDocument(const wxString& filename) return false; } *theApp->getLog() << "Read plot file " << filename << "\n"; - SetFilename(filename, true); + SetFilename(filename, true); + m_namePlot = filename.c_str(); } Modify(false); UpdateAllViews(); diff --git a/src/docs.h b/src/docs.h index 116347c..3729ce4 100644 --- a/src/docs.h +++ b/src/docs.h @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: docs.h,v 1.8 2000/12/22 04:18:00 kevin Exp $ +** $Id: docs.h,v 1.9 2000/12/27 03:16:02 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 @@ -147,7 +147,8 @@ public: PlotFile& getPlotFile () { return m_plot; } - virtual bool OnOpenDocument (const wxString& filename); + virtual bool OnOpenDocument (const wxString& filename); + virtual bool OnSaveDocument (const wxString& filename); virtual bool OnCloseDocument (); virtual bool IsModified () const; virtual void Modify (bool mod); diff --git a/src/views.cpp b/src/views.cpp index 9188b34..4659903 100644 --- a/src/views.cpp +++ b/src/views.cpp @@ -9,7 +9,7 @@ ** This is part of the CTSim program ** Copyright (C) 1983-2000 Kevin Rosenberg ** -** $Id: views.cpp,v 1.38 2000/12/25 21:54:26 kevin Exp $ +** $Id: views.cpp,v 1.39 2000/12/27 03:16:02 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 @@ -91,9 +91,10 @@ ImageFileCanvas::DrawRubberBandCursor (wxDC& dc, int x, int y) int nx = rIF.nx(); int ny = rIF.ny(); + int yPt = ny - y - 1; dc.SetLogicalFunction (wxINVERT); dc.SetPen (*wxGREEN_PEN); - dc.DrawLine (0, y, nx, y); + dc.DrawLine (0, yPt, nx, yPt); dc.DrawLine (x, 0, x, ny); dc.SetLogicalFunction (wxCOPY); } @@ -121,38 +122,33 @@ ImageFileCanvas::OnMouseEvent(wxMouseEvent& event) wxPoint pt(event.GetLogicalPosition(dc)); + const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); + ImageFileArrayConst v = rIF.getArray(); + int nx = rIF.nx(); + int ny = rIF.ny(); + const int yPt = ny - 1 - pt.y; if (event.RightIsDown()) { - const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); - if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) { std::ostringstream os; - os << "Image value (" << pt.x << "," << pt.y << ") = " << v[pt.x][ny - 1 - pt.y] << "\n"; + os << "Image value (" << pt.x << "," << yPt << ") = " << v[pt.x][yPt] << "\n"; *theApp->getLog() << os.str().c_str(); } else - *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n"; + *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n"; } - else if (event.LeftIsDown() || event.LeftUp()) { - const ImageFile& rIF = m_pView->GetDocument()->getImageFile(); - ImageFileArrayConst v = rIF.getArray(); - int nx = rIF.nx(); - int ny = rIF.ny(); - + else if (event.LeftIsDown() || event.LeftUp() || event.RightUp()) { if (pt.x >= 0 && pt.x < nx && pt.y >= 0 && pt.y < ny) { if (m_xCursor >= 0 && m_yCursor >= 0) { DrawRubberBandCursor (dc, m_xCursor, m_yCursor); } - DrawRubberBandCursor (dc, pt.x, pt.y); + DrawRubberBandCursor (dc, pt.x, yPt); m_xCursor = pt.x; - m_yCursor = pt.y; + m_yCursor = yPt; } else - *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << pt.y << ")\n"; + *theApp->getLog() << "Mouse out of image range (" << pt.x << "," << yPt << ")\n"; } if (event.LeftUp()) { std::ostringstream os; - os << "Selected column " << pt.x << " , row " << pt.y << "\n"; + os << "Selected column " << pt.x << " , row " << yPt << "\n"; *theApp->getLog() << os.str().c_str(); } } @@ -501,6 +497,7 @@ ImageFileView::OnPlotRow (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Column"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); rPlotFile.addEzsetCommand ("box"); rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (2, nx); @@ -548,6 +545,7 @@ ImageFileView::OnPlotCol (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Row"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); rPlotFile.addEzsetCommand ("box"); rPlotFile.addEzsetCommand ("grid"); rPlotFile.setCurveSize (2, nx); @@ -609,6 +607,7 @@ ImageFileView::OnCompareCol (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Row"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); rPlotFile.addEzsetCommand ("curve 1"); rPlotFile.addEzsetCommand ("color 2"); rPlotFile.addEzsetCommand ("curve 2"); @@ -680,6 +679,7 @@ ImageFileView::OnCompareRow (wxCommandEvent& event) rPlotFile.addEzsetCommand (title.c_str()); rPlotFile.addEzsetCommand ("xlabel Column"); rPlotFile.addEzsetCommand ("ylabel Pixel Value"); + rPlotFile.addEzsetCommand ("lxfrac 0"); rPlotFile.addEzsetCommand ("curve 1"); rPlotFile.addEzsetCommand ("color 2"); rPlotFile.addEzsetCommand ("curve 2"); @@ -1540,7 +1540,6 @@ PlotFileView::OnDraw (wxDC* dc) m_canvas->GetClientSize (&xsize, &ysize); SGPDriver driver (dc, xsize, ysize); SGP sgp (driver); - const PlotFile& rPhantom = GetDocument()->getPlotFile(); EZPlot plot (sgp); for (int iEzset = 0; iEzset < rPlotFile.getNumEzsetCommands(); iEzset++) -- 2.34.1