1 /*****************************************************************************
4 ** EZSET - Parameter control for EZPLOT
6 ** This is part of the CTSim program
7 ** Copyright (C) 1983-2000 Kevin Rosenberg
9 ** $Id: ezset.cpp,v 1.3 2000/06/20 17:54:51 kevin Exp $
11 ** This program is free software; you can redistribute it and/or modify
12 ** it under the terms of the GNU General Public License (version 2) as
13 ** published by the Free Software Foundation.
15 ** This program is distributed in the hope that it will be useful,
16 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
17 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
18 ** GNU General Public License for more details.
20 ** You should have received a copy of the GNU General Public License
21 ** along with this program; if not, write to the Free Software
22 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
23 ******************************************************************************/
24 /*----------------------------------------------------------------------*/
26 /*----------------------------------------------------------------------*/
28 #include "ctsupport.h"
32 static int ezcmd (char *comm);
33 static int do_cmd(int lx);
34 static void do_data(void);
35 static void do_help(void);
36 static void bad_option(char *opt);
37 static void initkw(void);
39 static int modeinteract = FALSE;
40 static int curveinteract = -1;
41 static int ezset_firstcall = TRUE;
42 static int eztrace = TRUE;
47 if (ezplot_firstcall == TRUE) {
50 if (ezset_firstcall == TRUE) {
53 pol_skpword ("please");
59 pol_skpword ("equals");
61 ezset_firstcall = FALSE;
63 pol_usefile (P_USE_STR,"");
64 set_inputline ("!eoc ,");
68 return (ezcmd (command));
78 pol_usefile (P_USE_STR, "");
81 if (pol_usertok (str, &code) == FALSE) {
82 fputs("Illegal EZSET command\n", stderr);
88 if (code != S_INTERACTIVE) {
89 retval = do_cmd (code);
94 fputs ("Enter EZSET command, DATA, EXIT, or HELP\n>", stderr);
95 if (get_inputline (stdin) != TRUE)
97 while (pol_lookchar() != EOF) {
98 if (pol_usertok (str, &code) == FALSE) {
99 if (pol_lookchar() != EOF) {
100 fputs ("illegal EZSET command\n", stderr);
103 } else if (code == S_DATA) {
106 } else if (code == S_HELP) {
109 } else if (code == S_EXIT) {
115 putc (NEWLINE, stderr);
117 modeinteract = FALSE;
121 pol_closefile(); /* close input string file */
135 if (pol_word("no", 2) == TRUE)
142 if (pol_word("no", 2) == TRUE)
148 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
150 if (f >= 0.0 && f <= 1.0) {
152 ez.s_textsize = TRUE;
154 ez.s_textsize = FALSE;
158 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
160 if (n >= 0 && n <= 6)
163 ez.d_prtmode = PRTMODE_DEF;
167 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
169 if (n > 2 && n <= 960)
172 ez.d_xprtbuf = XBUF_DEF;
176 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
178 if (n > 2 && n <= 960)
181 ez.d_yprtbuf = YBUF_DEF;
185 ez.i_plotimmediate = TRUE;
186 ezplot (static_cast<double*>(NULL), static_cast<double*>(NULL), 0);
188 if (modeinteract == TRUE)
191 ez.i_plotimmediate = FALSE;
197 gettext (ez.c_title, MAXTITLE);
200 gettext (ez.c_legend, MAXLEGEND);
201 if (modeinteract == TRUE && curveinteract >= 0)
202 strncpy (ez.curve[curveinteract].legend, ez.c_legend, MAXLEGEND);
205 gettext (ez.c_xlabel, MAXLABEL);
208 gettext (ez.c_ylabel, MAXLABEL);
211 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
218 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
251 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
257 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
263 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
269 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
275 ez.o_linestyle = LS_SOLID;
276 if (modeinteract == TRUE && curveinteract >= 0)
277 ez.curve[curveinteract].linestyle = LS_SOLID;
280 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
282 ez.o_linestyle = LS_DASH1;
284 ez.o_linestyle = LS_DASH2;
286 ez.o_linestyle = LS_DASH3;
288 ez.o_linestyle = LS_DASH4;
290 ez.o_linestyle = LS_DASH1;
292 ez.o_linestyle = LS_DASH1;
293 if (modeinteract == TRUE && curveinteract >= 0)
294 ez.curve[curveinteract].linestyle = ez.o_linestyle;
297 ez.o_linestyle = LS_NOLINE;
298 if (modeinteract == TRUE && curveinteract >= 0)
299 ez.curve[curveinteract].linestyle = LS_NOLINE;
303 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
305 if (n >= 0 && n <= MAXCOLOR)
308 bad_option("The color you picked");
310 if (modeinteract == TRUE && curveinteract >= 0)
311 ez.curve[curveinteract].color = ez.o_color;
326 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
327 if (f > 0.0 && f <= 1.0)
331 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
332 if (f > 0.0 && f <= 1.0)
336 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
337 if (f >= 0.0 && f < 1.0)
341 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
342 if (f >= 0.0 && f < 1.0)
346 if (pol_word("no", 2) == TRUE)
348 else if (pol_word("off", 2) == TRUE)
354 if (pol_word("inside", 2) == TRUE)
355 ez.o_legendbox = INSIDE;
356 else if (pol_word("outside", 3) == TRUE)
357 ez.o_legendbox = OUTSIDE;
358 else if (pol_word("none",2) == TRUE)
359 ez.o_legendbox = NOLEGEND;
361 gettext (str, MAXTOK);
366 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
368 if (f >= 0.0 && f < 1.0) {
373 ez.s_xlegend = FALSE;
377 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
379 if (f >= 0.0 && f < 1.0) {
384 ez.s_ylegend = FALSE;
388 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
391 else if (n > MAXCURVES)
393 if (modeinteract == TRUE) {
394 curveinteract = n - 1;
395 if (ez.o_unknowncurves == FALSE && ez.o_reqcurves < n)
402 if (pol_word ("unknown", 7) == TRUE)
403 ez.o_unknowncurves = TRUE;
404 else if (pol_word ("end", 3) == TRUE) {
405 ez.o_unknowncurves = FALSE;
406 ez.o_reqcurves = ez.i_numcurves;
407 ez.i_plotimmediate = TRUE;
408 ezplot (static_cast<double*>(NULL), static_cast<double*>(NULL), 0);
409 ez.i_plotimmediate = FALSE;
414 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
415 if (n > 0 && n <= MAXSYMBOL)
419 if (modeinteract == TRUE && curveinteract >= 0)
420 ez.curve[curveinteract].symbol = ez.o_symbol;
422 if (pol_word("every",5) == TRUE) {
423 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
428 if (modeinteract == TRUE && curveinteract >= 0)
429 ez.curve[curveinteract].symfreq = ez.o_symfreq;
431 } else if (pol_word ("none",4) == TRUE) {
433 if (modeinteract == TRUE && curveinteract >= 0)
434 ez.curve[curveinteract].symbol = ez.o_symbol;
439 if (pol_usertok(str,&lx) == FALSE)
443 else if (lx == S_BELOW)
445 else if (lx == S_NOLABEL)
446 ez.o_xtlabel = FALSE;
447 else if (lx == S_LABEL)
449 else if (lx == S_MAJOR) {
450 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
451 if (n > 1 && n < 100)
453 } else if (lx == S_MINOR)
454 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
455 if (n >= 0 && n < 100)
459 if (pol_usertok(str,&lx) == FALSE)
463 else if (lx == S_LEFT)
465 else if (lx == S_NOLABEL)
466 ez.o_ytlabel = FALSE;
467 else if (lx == S_LABEL)
469 else if (lx == S_MAJOR) {
470 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
471 if (n > 1 && n < 100)
473 } else if (lx == S_MINOR)
474 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
475 if (n >= 0 && n < 100)
479 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
488 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
497 if (pol_word("no", 2) == TRUE)
503 if (pol_word("no", 2) == TRUE)
504 ez.o_ufinish = FALSE;
509 fprintf (stderr, "Unimplemented EZPLOT command\n");
517 static void do_data (void)
519 double x[MAXPTS], y[MAXPTS], d;
522 printf ("Enter your data in free format\n");
523 printf ("Alternate X and Y coordinates\n");
524 printf ("Type ^Z (control Z) to terminate data entry\n");
526 pol_usefile (P_USE_FILE, "");
527 for (i = 0; i < MAXPTS; i++) {
528 if (pol_float (&d, TT_REAL, FALSE, 0, 0) == TRUE)
532 if (pol_float (&d, TT_REAL, FALSE, 0, 0) == TRUE)
538 if ((c = pol_inchar()) != EOF) {
540 printf("Error reading in points, read char %d, plotting %d points\n", c, i);
548 static void do_help (void )
550 fputs ("EZSET Help: not available\n", stderr);
555 bad_option (char *opt)
557 fprintf(stderr,"%s is an INVALID option (sorry!)\n", opt);
560 /*----------------------------------------------------------------------*/
561 /* LEXIGRAPHICAL CODES */
562 /*----------------------------------------------------------------------*/
577 /* "every", S_EVERY, */
578 /* "none", S_NONE, */
582 /* "unknown", S_UNKNOWN, */
586 "xlegend", S_XLEGEND,
587 "ylegend", S_YLEGEND,
595 "xlength", S_XLENGTH,
596 "ylength", S_YLENGTH,
603 "nolabel", S_NOLABEL,
607 "xautoscale", S_XAUTOSCALE,
608 "yautoscale", S_YAUTOSCALE,
617 "noxaxis", S_NOXAXIS,
618 "noyaxis", S_NOYAXIS,
619 "xporigin", S_XPORIGIN,
620 "yporigin", S_YPORIGIN,
628 "restore", S_RESTORE,
630 "ufinish", S_UFINISH,
632 "interactive", S_INTERACTIVE,
648 "legendbox", S_LEGENDBOX,
654 "textsize", S_TEXTSIZE,
657 "prtmode", S_PRTMODE,
660 #define NKEYS (sizeof(keytab) / sizeof(struct key))
662 static void initkw(void)
666 for (i = 0; i < NKEYS; i++)
667 if (pol_install(keytab[i].keyword, keytab[i].code) == FALSE)
668 sys_error(ERR_SEVERE, "error installing ezset keywords [initkw]");