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.4 2000/07/13 07:03:21 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;
46 if (ezplot_firstcall == TRUE) {
49 if (ezset_firstcall == TRUE) {
52 pol_skpword ("please");
58 pol_skpword ("equals");
60 ezset_firstcall = FALSE;
62 pol_usefile (P_USE_STR,"");
63 set_inputline ("!eoc ,");
67 return (ezcmd (command));
77 pol_usefile (P_USE_STR, "");
80 if (pol_usertok (str, &code) == FALSE) {
81 fputs("Illegal EZSET command\n", stderr);
87 if (code != S_INTERACTIVE) {
88 retval = do_cmd (code);
93 fputs ("Enter EZSET command, DATA, EXIT, or HELP\n>", stderr);
94 if (get_inputline (stdin) != TRUE)
96 while (pol_lookchar() != EOF) {
97 if (pol_usertok (str, &code) == FALSE) {
98 if (pol_lookchar() != EOF) {
99 fputs ("illegal EZSET command\n", stderr);
102 } else if (code == S_DATA) {
105 } else if (code == S_HELP) {
108 } else if (code == S_EXIT) {
114 putc (NEWLINE, stderr);
116 modeinteract = FALSE;
120 pol_closefile(); /* close input string file */
134 if (pol_word("no", 2) == TRUE)
141 if (pol_word("no", 2) == TRUE)
147 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
149 if (f >= 0.0 && f <= 1.0) {
151 ez.s_textsize = TRUE;
153 ez.s_textsize = FALSE;
157 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
159 if (n >= 0 && n <= 6)
162 ez.d_prtmode = PRTMODE_DEF;
166 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
168 if (n > 2 && n <= 960)
171 ez.d_xprtbuf = XBUF_DEF;
175 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
177 if (n > 2 && n <= 960)
180 ez.d_yprtbuf = YBUF_DEF;
184 ez.i_plotimmediate = TRUE;
185 ezplot (static_cast<double*>(NULL), static_cast<double*>(NULL), 0);
187 if (modeinteract == TRUE)
190 ez.i_plotimmediate = FALSE;
196 gettext (ez.c_title, MAXTITLE);
199 gettext (ez.c_legend, MAXLEGEND);
200 if (modeinteract == TRUE && curveinteract >= 0)
201 strncpy (ez.curve[curveinteract].legend, ez.c_legend, MAXLEGEND);
204 gettext (ez.c_xlabel, MAXLABEL);
207 gettext (ez.c_ylabel, MAXLABEL);
210 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
217 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
250 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
256 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
262 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
268 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
274 ez.o_linestyle = LS_SOLID;
275 if (modeinteract == TRUE && curveinteract >= 0)
276 ez.curve[curveinteract].linestyle = LS_SOLID;
279 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
281 ez.o_linestyle = LS_DASH1;
283 ez.o_linestyle = LS_DASH2;
285 ez.o_linestyle = LS_DASH3;
287 ez.o_linestyle = LS_DASH4;
289 ez.o_linestyle = LS_DASH1;
291 ez.o_linestyle = LS_DASH1;
292 if (modeinteract == TRUE && curveinteract >= 0)
293 ez.curve[curveinteract].linestyle = ez.o_linestyle;
296 ez.o_linestyle = LS_NOLINE;
297 if (modeinteract == TRUE && curveinteract >= 0)
298 ez.curve[curveinteract].linestyle = LS_NOLINE;
302 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
304 if (n >= 0 && n <= MAXCOLOR)
307 bad_option("The color you picked");
309 if (modeinteract == TRUE && curveinteract >= 0)
310 ez.curve[curveinteract].color = ez.o_color;
325 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
326 if (f > 0.0 && f <= 1.0)
330 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
331 if (f > 0.0 && f <= 1.0)
335 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
336 if (f >= 0.0 && f < 1.0)
340 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
341 if (f >= 0.0 && f < 1.0)
345 if (pol_word("no", 2) == TRUE)
347 else if (pol_word("off", 2) == TRUE)
353 if (pol_word("inside", 2) == TRUE)
354 ez.o_legendbox = INSIDE;
355 else if (pol_word("outside", 3) == TRUE)
356 ez.o_legendbox = OUTSIDE;
357 else if (pol_word("none",2) == TRUE)
358 ez.o_legendbox = NOLEGEND;
360 gettext (str, MAXTOK);
365 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
367 if (f >= 0.0 && f < 1.0) {
372 ez.s_xlegend = FALSE;
376 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
378 if (f >= 0.0 && f < 1.0) {
383 ez.s_ylegend = FALSE;
387 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
390 else if (n > MAXCURVES)
392 if (modeinteract == TRUE) {
393 curveinteract = n - 1;
394 if (ez.o_unknowncurves == FALSE && ez.o_reqcurves < n)
401 if (pol_word ("unknown", 7) == TRUE)
402 ez.o_unknowncurves = TRUE;
403 else if (pol_word ("end", 3) == TRUE) {
404 ez.o_unknowncurves = FALSE;
405 ez.o_reqcurves = ez.i_numcurves;
406 ez.i_plotimmediate = TRUE;
407 ezplot (static_cast<double*>(NULL), static_cast<double*>(NULL), 0);
408 ez.i_plotimmediate = FALSE;
413 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
414 if (n > 0 && n <= MAXSYMBOL)
418 if (modeinteract == TRUE && curveinteract >= 0)
419 ez.curve[curveinteract].symbol = ez.o_symbol;
421 if (pol_word("every",5) == TRUE) {
422 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
427 if (modeinteract == TRUE && curveinteract >= 0)
428 ez.curve[curveinteract].symfreq = ez.o_symfreq;
430 } else if (pol_word ("none",4) == TRUE) {
432 if (modeinteract == TRUE && curveinteract >= 0)
433 ez.curve[curveinteract].symbol = ez.o_symbol;
438 if (pol_usertok(str,&lx) == FALSE)
442 else if (lx == S_BELOW)
444 else if (lx == S_NOLABEL)
445 ez.o_xtlabel = FALSE;
446 else if (lx == S_LABEL)
448 else if (lx == S_MAJOR) {
449 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
450 if (n > 1 && n < 100)
452 } else if (lx == S_MINOR)
453 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
454 if (n >= 0 && n < 100)
458 if (pol_usertok(str,&lx) == FALSE)
462 else if (lx == S_LEFT)
464 else if (lx == S_NOLABEL)
465 ez.o_ytlabel = FALSE;
466 else if (lx == S_LABEL)
468 else if (lx == S_MAJOR) {
469 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
470 if (n > 1 && n < 100)
472 } else if (lx == S_MINOR)
473 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
474 if (n >= 0 && n < 100)
478 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
487 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
496 if (pol_word("no", 2) == TRUE)
502 if (pol_word("no", 2) == TRUE)
503 ez.o_ufinish = FALSE;
508 fprintf (stderr, "Unimplemented EZPLOT command\n");
516 static void do_data (void)
518 double x[MAXPTS], y[MAXPTS], d;
521 printf ("Enter your data in free format\n");
522 printf ("Alternate X and Y coordinates\n");
523 printf ("Type ^Z (control Z) to terminate data entry\n");
525 pol_usefile (P_USE_FILE, "");
526 for (i = 0; i < MAXPTS; i++) {
527 if (pol_float (&d, TT_REAL, FALSE, 0, 0) == TRUE)
531 if (pol_float (&d, TT_REAL, FALSE, 0, 0) == TRUE)
537 if ((c = pol_inchar()) != EOF) {
539 printf("Error reading in points, read char %d, plotting %d points\n", c, i);
547 static void do_help (void )
549 fputs ("EZSET Help: not available\n", stderr);
554 bad_option (char *opt)
556 fprintf(stderr,"%s is an INVALID option (sorry!)\n", opt);
559 /*----------------------------------------------------------------------*/
560 /* LEXIGRAPHICAL CODES */
561 /*----------------------------------------------------------------------*/
569 {"noline", S_NOLINE},
575 {"symbol", S_SYMBOL},
576 /* "every", S_EVERY, */
577 /* "none", S_NONE, */
579 {"curves", S_CURVES},
581 /* "unknown", S_UNKNOWN, */
584 {"legend", S_LEGEND},
585 {"xlegend", S_XLEGEND},
586 {"ylegend", S_YLEGEND},
592 {"xlabel", S_XLABEL},
593 {"ylabel", S_YLABEL},
594 {"xlength", S_XLENGTH},
595 {"ylength", S_YLENGTH},
597 {"xticks", S_XTICKS},
598 {"yticks", S_YTICKS},
602 {"nolabel", S_NOLABEL},
606 {"xautoscale", S_XAUTOSCALE},
607 {"yautoscale", S_YAUTOSCALE},
612 {"lxfrac", S_LXFRAC},
613 {"lyfrac", S_LYFRAC},
614 {"xcross", S_XCROSS},
615 {"ycross", S_YCROSS},
616 {"noxaxis", S_NOXAXIS},
617 {"noyaxis", S_NOYAXIS},
618 {"xporigin", S_XPORIGIN},
619 {"yporigin", S_YPORIGIN},
621 {"xtitle", S_XTITLE},
622 {"ytitle", S_YTITLE},
624 {"replot", S_REPLOT},
627 {"restore", S_RESTORE},
628 {"ustart", S_USTART},
629 {"ufinish", S_UFINISH},
631 {"interactive", S_INTERACTIVE},
633 {"inches", S_INCHES},
643 {"nogrid", S_NOGRID},
647 {"legendbox", S_LEGENDBOX},
653 {"textsize", S_TEXTSIZE},
656 // {"prtmode", S_PRTMOD},
659 static const unsigned int NKEYS=(sizeof(keytab) / sizeof(struct key));
661 static void initkw(void)
663 for (unsigned int i = 0; i < NKEYS; i++)
664 if (pol_install(keytab[i].keyword, keytab[i].code) == FALSE)
665 sys_error(ERR_SEVERE, "error installing ezset keywords [initkw]");