1 /*****************************************************************************
2 ** This is part of the CTSim program
3 ** Copyright (C) 1983-2000 Kevin Rosenberg
5 ** $Id: ezset.cpp,v 1.1 2000/06/19 18:05:03 kevin Exp $
7 ** This program is free software; you can redistribute it and/or modify
8 ** it under the terms of the GNU General Public License (version 2) as
9 ** published by the Free Software Foundation.
11 ** This program is distributed in the hope that it will be useful,
12 ** but WITHOUT ANY WARRANTY; without even the implied warranty of
13 ** MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 ** GNU General Public License for more details.
16 ** You should have received a copy of the GNU General Public License
17 ** along with this program; if not, write to the Free Software
18 ** Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
19 ******************************************************************************/
20 /*----------------------------------------------------------------------*/
21 /* EZSET - Parameter control for EZPLOT */
23 /*----------------------------------------------------------------------*/
29 static int ezcmd (char *comm);
30 static int do_cmd(int lx);
31 static void do_data(void);
32 static void do_help(void);
33 static void bad_option(char *opt);
34 static void initkw(void);
36 static int modeinteract = FALSE;
37 static int curveinteract = -1;
38 static int ezset_firstcall = TRUE;
39 static int eztrace = TRUE;
44 if (ezplot_firstcall == TRUE) {
47 if (ezset_firstcall == TRUE) {
50 pol_skpword ("please");
56 pol_skpword ("equals");
58 ezset_firstcall = FALSE;
60 pol_usefile (P_USE_STR,"");
61 set_inputline ("!eoc ,");
65 return (ezcmd (command));
75 pol_usefile (P_USE_STR, "");
78 if (pol_usertok (str, &code) == FALSE) {
79 fputs("Illegal EZSET command\n", stderr);
85 if (code != S_INTERACTIVE) {
86 retval = do_cmd (code);
91 fputs ("Enter EZSET command, DATA, EXIT, or HELP\n>", stderr);
92 if (get_inputline (stdin) != TRUE)
94 while (pol_lookchar() != EOF) {
95 if (pol_usertok (str, &code) == FALSE) {
96 if (pol_lookchar() != EOF) {
97 fputs ("illegal EZSET command\n", stderr);
100 } else if (code == S_DATA) {
103 } else if (code == S_HELP) {
106 } else if (code == S_EXIT) {
112 putc (NEWLINE, stderr);
114 modeinteract = FALSE;
118 pol_closefile(); /* close input string file */
132 if (pol_word("no", 2) == TRUE)
139 if (pol_word("no", 2) == TRUE)
145 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
147 if (f >= 0.0 && f <= 1.0) {
149 ez.s_textsize = TRUE;
151 ez.s_textsize = FALSE;
155 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
157 if (n >= 0 && n <= 6)
160 ez.d_prtmode = PRTMODE_DEF;
164 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
166 if (n > 2 && n <= 960)
169 ez.d_xprtbuf = XBUF_DEF;
173 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
175 if (n > 2 && n <= 960)
178 ez.d_yprtbuf = YBUF_DEF;
182 ez.i_plotimmediate = TRUE;
183 ezplot (NULL, NULL, 0);
185 if (modeinteract == TRUE)
188 ez.i_plotimmediate = FALSE;
194 gettext (ez.c_title, MAXTITLE);
197 gettext (ez.c_legend, MAXLEGEND);
198 if (modeinteract == TRUE && curveinteract >= 0)
199 strncpy (ez.curve[curveinteract].legend, ez.c_legend, MAXLEGEND);
202 gettext (ez.c_xlabel, MAXLABEL);
205 gettext (ez.c_ylabel, MAXLABEL);
208 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
215 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
248 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
254 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
260 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
266 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE) {
272 ez.o_linestyle = LS_SOLID;
273 if (modeinteract == TRUE && curveinteract >= 0)
274 ez.curve[curveinteract].linestyle = LS_SOLID;
277 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
279 ez.o_linestyle = LS_DASH1;
281 ez.o_linestyle = LS_DASH2;
283 ez.o_linestyle = LS_DASH3;
285 ez.o_linestyle = LS_DASH4;
287 ez.o_linestyle = LS_DASH1;
289 ez.o_linestyle = LS_DASH1;
290 if (modeinteract == TRUE && curveinteract >= 0)
291 ez.curve[curveinteract].linestyle = ez.o_linestyle;
294 ez.o_linestyle = LS_NOLINE;
295 if (modeinteract == TRUE && curveinteract >= 0)
296 ez.curve[curveinteract].linestyle = LS_NOLINE;
300 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
302 if (n >= 0 && n <= MAXCOLOR)
305 bad_option("The color you picked");
307 if (modeinteract == TRUE && curveinteract >= 0)
308 ez.curve[curveinteract].color = ez.o_color;
323 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
324 if (f > 0.0 && f <= 1.0)
328 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
329 if (f > 0.0 && f <= 1.0)
333 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
334 if (f >= 0.0 && f < 1.0)
338 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
339 if (f >= 0.0 && f < 1.0)
343 if (pol_word("no", 2) == TRUE)
345 else if (pol_word("off", 2) == TRUE)
351 if (pol_word("inside", 2) == TRUE)
352 ez.o_legendbox = INSIDE;
353 else if (pol_word("outside", 3) == TRUE)
354 ez.o_legendbox = OUTSIDE;
355 else if (pol_word("none",2) == TRUE)
356 ez.o_legendbox = NOLEGEND;
358 gettext (str, MAXTOK);
363 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
365 if (f >= 0.0 && f < 1.0) {
370 ez.s_xlegend = FALSE;
374 if (pol_float (&f, TT_REAL, FALSE, 0.0, 0.0) == TRUE)
376 if (f >= 0.0 && f < 1.0) {
381 ez.s_ylegend = FALSE;
385 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
388 else if (n > MAXCURVES)
390 if (modeinteract == TRUE) {
391 curveinteract = n - 1;
392 if (ez.o_unknowncurves == FALSE && ez.o_reqcurves < n)
399 if (pol_word ("unknown", 7) == TRUE)
400 ez.o_unknowncurves = TRUE;
401 else if (pol_word ("end", 3) == TRUE) {
402 ez.o_unknowncurves = FALSE;
403 ez.o_reqcurves = ez.i_numcurves;
404 ez.i_plotimmediate = TRUE;
405 ezplot (NULL, NULL, 0);
406 ez.i_plotimmediate = FALSE;
411 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
412 if (n > 0 && n <= MAXSYMBOL)
416 if (modeinteract == TRUE && curveinteract >= 0)
417 ez.curve[curveinteract].symbol = ez.o_symbol;
419 if (pol_word("every",5) == TRUE) {
420 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
425 if (modeinteract == TRUE && curveinteract >= 0)
426 ez.curve[curveinteract].symfreq = ez.o_symfreq;
428 } else if (pol_word ("none",4) == TRUE) {
430 if (modeinteract == TRUE && curveinteract >= 0)
431 ez.curve[curveinteract].symbol = ez.o_symbol;
436 if (pol_usertok(str,&lx) == FALSE)
440 else if (lx == S_BELOW)
442 else if (lx == S_NOLABEL)
443 ez.o_xtlabel = FALSE;
444 else if (lx == S_LABEL)
446 else if (lx == S_MAJOR) {
447 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
448 if (n > 1 && n < 100)
450 } else if (lx == S_MINOR)
451 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
452 if (n >= 0 && n < 100)
456 if (pol_usertok(str,&lx) == FALSE)
460 else if (lx == S_LEFT)
462 else if (lx == S_NOLABEL)
463 ez.o_ytlabel = FALSE;
464 else if (lx == S_LABEL)
466 else if (lx == S_MAJOR) {
467 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
468 if (n > 1 && n < 100)
470 } else if (lx == S_MINOR)
471 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE)
472 if (n >= 0 && n < 100)
476 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
485 if (pol_integer (&n, TT_REAL, FALSE, 0, 0) == TRUE) {
494 if (pol_word("no", 2) == TRUE)
500 if (pol_word("no", 2) == TRUE)
501 ez.o_ufinish = FALSE;
506 fprintf (stderr, "Unimplemented EZPLOT command\n");
514 static void do_data (void)
516 double x[MAXPTS], y[MAXPTS], d;
519 printf ("Enter your data in free format\n");
520 printf ("Alternate X and Y coordinates\n");
521 printf ("Type ^Z (control Z) to terminate data entry\n");
523 pol_usefile (P_USE_FILE, "");
524 for (i = 0; i < MAXPTS; i++) {
525 if (pol_float (&d, TT_REAL, FALSE, 0, 0) == TRUE)
529 if (pol_float (&d, TT_REAL, FALSE, 0, 0) == TRUE)
535 if ((c = pol_inchar()) != EOF) {
537 printf("Error reading in points, read char %d, plotting %d points\n", c, i);
545 static void do_help (void )
547 fputs ("EZSET Help: not available\n", stderr);
552 bad_option (char *opt)
554 fprintf(stderr,"%s is an INVALID option (sorry!)\n", opt);
557 /*----------------------------------------------------------------------*/
558 /* LEXIGRAPHICAL CODES */
559 /*----------------------------------------------------------------------*/
574 /* "every", S_EVERY, */
575 /* "none", S_NONE, */
579 /* "unknown", S_UNKNOWN, */
583 "xlegend", S_XLEGEND,
584 "ylegend", S_YLEGEND,
592 "xlength", S_XLENGTH,
593 "ylength", S_YLENGTH,
600 "nolabel", S_NOLABEL,
604 "xautoscale", S_XAUTOSCALE,
605 "yautoscale", S_YAUTOSCALE,
614 "noxaxis", S_NOXAXIS,
615 "noyaxis", S_NOYAXIS,
616 "xporigin", S_XPORIGIN,
617 "yporigin", S_YPORIGIN,
625 "restore", S_RESTORE,
627 "ufinish", S_UFINISH,
629 "interactive", S_INTERACTIVE,
645 "legendbox", S_LEGENDBOX,
651 "textsize", S_TEXTSIZE,
654 "prtmode", S_PRTMODE,
657 #define NKEYS (sizeof(keytab) / sizeof(struct key))
659 static void initkw(void)
663 for (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]");