home *** CD-ROM | disk | FTP | other *** search
Text File | 1990-03-25 | 72.8 KB | 2,924 lines |
- Newsgroups: comp.sources.misc
- organization: Pixar -- Marin County, California
- subject: v11i070: Gnuplot 2.0 - 5 of 14
- From: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
- Sender: allbery@uunet.UU.NET (Brandon S. Allbery - comp.sources.misc)
-
- Posting-number: Volume 11, Issue 70
- Submitted-by: thaw@ucbvax.Berkeley.EDU@pixar.UUCP (Tom Williams)
- Archive-name: gnuplot2/part05
-
- This is gnuplot.sh05
-
- --- CUT HERE ---
- #! /bin/sh
- echo x - command.c
- sed 's/^X//' >command.c <<'*-*-END-of-command.c-*-*'
- X/* GNUPLOT - command.c */
- X/*
- X * Copyright (C) 1986, 1987, 1990 Thomas Williams, Colin Kelley
- X *
- X * Permission to use, copy, and distribute this software and its
- X * documentation for any purpose with or without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and
- X * that both that copyright notice and this permission notice appear
- X * in supporting documentation.
- X *
- X * Permission to modify the software is granted, but not the right to
- X * distribute the modified code. Modifications are to be distributed
- X * as patches to released version.
- X *
- X * This software is provided "as is" without express or implied warranty.
- X *
- X *
- X * AUTHORS
- X *
- X * Original Software:
- X * Thomas Williams, Colin Kelley.
- X *
- X * Gnuplot 2.0 additions:
- X * Russell Lang, Dave Kotz, John Campbell.
- X *
- X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
- X *
- X */
- X
- X#include <stdio.h>
- X#include <math.h>
- X
- X#ifdef MSDOS
- X#include <process.h>
- X
- X#ifdef __ZTC__
- X#define P_WAIT 0
- X#include <time.h> /* usleep() */
- X#else
- X
- X#ifdef __TURBOC__
- X#include <dos.h> /* sleep() */
- X
- X#else /* must be MSC */
- X#include <time.h> /* kludge to provide sleep() */
- Xvoid sleep(); /* defined later */
- X#endif /* TURBOC */
- X#endif /* ZTC */
- X
- X#endif /* MSDOS */
- X
- X
- X#include "plot.h"
- X#include "setshow.h"
- X#include "help.h"
- X
- X#ifndef STDOUT
- X#define STDOUT 1
- X#endif
- X
- X#ifndef HELPFILE
- X#define HELPFILE "docs/gnuplot.gih" /* changed by makefile */
- X#endif
- X
- X#define inrange(z,min,max) ((min<max) ? ((z>=min)&&(z<=max)) : ((z>=max)&&(z<=min)) )
- X
- X/*
- X * instead of <strings.h>
- X */
- X
- Xextern char *gets(),*getenv();
- Xextern char *strcpy(),*strncpy(),*strcat();
- Xextern int strlen(), strcmp();
- X
- Xextern double magnitude(),angle(),real(),imag();
- Xextern struct value *const_express(), *pop(), *complex();
- Xextern struct at_type *temp_at(), *perm_at();
- Xextern struct udft_entry *add_udf();
- Xextern struct udvt_entry *add_udv();
- Xextern void squash_spaces();
- Xextern void lower_case();
- X
- Xextern BOOLEAN interactive; /* from plot.c */
- X
- X/* input data, parsing variables */
- Xstruct lexical_unit token[MAX_TOKENS];
- Xchar input_line[MAX_LINE_LEN+1] = "";
- Xint num_tokens, c_token;
- Xint inline_num = 0; /* input line number */
- X
- Xchar c_dummy_var[MAX_ID_LEN+1]; /* current dummy var */
- X
- X/* the curves of the plot */
- Xstruct curve_points *first_plot = NULL;
- Xstatic struct udft_entry plot_func;
- Xstruct udft_entry *dummy_func;
- X
- X/* support for replot command */
- Xchar replot_line[MAX_LINE_LEN+1] = "";
- Xstatic int plot_token; /* start of 'plot' command */
- X
- Xcom_line()
- X{
- X read_line(PROMPT);
- X
- X /* So we can flag any new output: if false at time of error, */
- X /* we reprint the command line before printing caret. */
- X /* TRUE for interactive terminals, since the command line is typed. */
- X /* FALSE for non-terminal stdin, so command line is printed anyway. */
- X /* (DFK 11/89) */
- X screen_ok = interactive;
- X
- X do_line();
- X}
- X
- X
- Xdo_line() /* also used in load_file */
- X{
- X if (is_system(input_line[0])) {
- X do_system();
- X (void) fputs("!\n",stderr);
- X return;
- X }
- X num_tokens = scanner(input_line);
- X c_token = 0;
- X while(c_token < num_tokens) {
- X command();
- X if (c_token < num_tokens) /* something after command */
- X if (equals(c_token,";"))
- X c_token++;
- X else
- X int_error("';' expected",c_token);
- X }
- X}
- X
- X
- X
- Xcommand()
- X{
- X char sv_file[MAX_LINE_LEN+1];
- X /* string holding name of save or load file */
- X
- X c_dummy_var[0] = '\0'; /* no dummy variable */
- X
- X if (is_definition(c_token))
- X define();
- X else if (equals(c_token,"help") || equals(c_token,"?")) {
- X c_token++;
- X do_help();
- X }
- X else if (almost_equals(c_token,"test")) {
- X c_token++;
- X test_term();
- X }
- X else if (almost_equals(c_token,"pa$use")) {
- X struct value a;
- X int stime, text=0;
- X char buf[MAX_LINE_LEN+1];
- X
- X c_token++;
- X stime = (int )real(const_express(&a));
- X if (!(END_OF_COMMAND)) {
- X if (!isstring(c_token))
- X int_error("expecting string",c_token);
- X else {
- X quotel_str(buf,c_token);
- X (void) fprintf (stderr, "%s",buf);
- X text = 1;
- X }
- X }
- X if (stime < 0) (void) fgets (buf,MAX_LINE_LEN,stdin);
- X /* Hold until CR hit. */
- X#ifdef __ZTC__
- X if (stime > 0) usleep((unsigned long) stime);
- X#else
- X if (stime > 0) sleep((unsigned int) stime);
- X#endif
- X if (text != 0 && stime >= 0) (void) fprintf (stderr,"\n");
- X c_token++;
- X screen_ok = FALSE;
- X }
- X else if (almost_equals(c_token,"pr$int")) {
- X struct value a;
- X
- X c_token++;
- X (void) const_express(&a);
- X (void) putc('\t',stderr);
- X disp_value(stderr,&a);
- X (void) putc('\n',stderr);
- X screen_ok = FALSE;
- X }
- X else if (almost_equals(c_token,"p$lot")) {
- X plot_token = c_token++;
- X plotrequest();
- X }
- X else if (almost_equals(c_token,"rep$lot")) {
- X if (replot_line[0] == '\0')
- X int_error("no previous plot",c_token);
- X c_token++;
- X replotrequest();
- X }
- X else if (almost_equals(c_token,"se$t"))
- X set_command();
- X else if (almost_equals(c_token,"sh$ow"))
- X show_command();
- X else if (almost_equals(c_token,"cl$ear")) {
- X if (!term_init) {
- X (*term_tbl[term].init)();
- X term_init = TRUE;
- X }
- X (*term_tbl[term].graphics)();
- X (*term_tbl[term].text)();
- X (void) fflush(outfile);
- X screen_ok = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"she$ll")) {
- X do_shell();
- X screen_ok = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"sa$ve")) {
- X if (almost_equals(++c_token,"f$unctions")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X save_functions(fopen(sv_file,"w"));
- X }
- X }
- X else if (almost_equals(c_token,"v$ariables")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X save_variables(fopen(sv_file,"w"));
- X }
- X }
- X else if (almost_equals(c_token,"s$et")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X save_set(fopen(sv_file,"w"));
- X }
- X }
- X else if (isstring(c_token)) {
- X quote_str(sv_file,c_token);
- X save_all(fopen(sv_file,"w"));
- X }
- X else {
- X int_error(
- X "filename or keyword 'functions', 'variables', or 'set' expected",
- X c_token);
- X }
- X c_token++;
- X }
- X else if (almost_equals(c_token,"l$oad")) {
- X if (!isstring(++c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(sv_file,c_token);
- X load_file(fopen(sv_file,"r"), sv_file);
- X /* input_line[] and token[] now destroyed! */
- X c_token = num_tokens = 0;
- X }
- X }
- X else if (almost_equals(c_token,"ex$it") ||
- X almost_equals(c_token,"q$uit")) {
- X done(IO_SUCCESS);
- X }
- X else if (!equals(c_token,";")) { /* null statement */
- X int_error("invalid command",c_token);
- X }
- X}
- X
- Xreplotrequest()
- X{
- Xchar str[MAX_LINE_LEN+1];
- X if(equals(c_token,"["))
- X int_error("cannot set range with replot",c_token);
- X if (!END_OF_COMMAND) {
- X capture(str,c_token,num_tokens-1);
- X if ( (strlen(str) + strlen(input_line)) <= MAX_LINE_LEN-1) {
- X (void) strcat(replot_line,",");
- X (void) strcat(replot_line,str);
- X } else {
- X int_error("plot line too long with replot arguments",c_token);
- X }
- X }
- X (void) strcpy(input_line,replot_line);
- X screen_ok = FALSE;
- X num_tokens = scanner(input_line);
- X c_token = 1; /* skip the 'plot' part */
- X plotrequest();
- X}
- X
- X
- Xplotrequest()
- X{
- X BOOLEAN changed;
- X int dummy_token = -1;
- X
- X autoscale_lx = autoscale_x;
- X autoscale_ly = autoscale_y;
- X
- X if (!term) /* unknown */
- X int_error("use 'set term' to set terminal type first",c_token);
- X
- X if (equals(c_token,"[")) {
- X c_token++;
- X if (isletter(c_token)) {
- X if (equals(c_token+1,"=")) {
- X dummy_token = c_token;
- X c_token += 2;
- X } else {
- X /* oops; probably an expression with a variable. */
- X /* Parse it as an xmin expression. */
- X /* used to be: int_error("'=' expected",c_token); */
- X }
- X }
- X changed = load_range(&xmin,&xmax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_lx = FALSE;
- X }
- X
- X if (equals(c_token,"[")) { /* set optional y ranges */
- X c_token++;
- X changed = load_range(&ymin,&ymax);
- X if (!equals(c_token,"]"))
- X int_error("']' expected",c_token);
- X c_token++;
- X if (changed)
- X autoscale_ly = FALSE;
- X }
- X
- X /* use the default dummy variable unless changed */
- X if (dummy_token >= 0)
- X copy_str(c_dummy_var,dummy_token);
- X else
- X (void) strcpy(c_dummy_var,dummy_var);
- X
- X eval_plots();
- X}
- X
- X
- Xdefine()
- X{
- Xregister int start_token; /* the 1st token in the function definition */
- Xregister struct udvt_entry *udv;
- Xregister struct udft_entry *udf;
- X
- X if (equals(c_token+1,"(")) {
- X /* function ! */
- X start_token = c_token;
- X copy_str(c_dummy_var, c_token + 2);
- X c_token += 5; /* skip (, dummy, ) and = */
- X if (END_OF_COMMAND)
- X int_error("function definition expected",c_token);
- X udf = dummy_func = add_udf(start_token);
- X if (udf->at) /* already a dynamic a.t. there */
- X free((char *)udf->at); /* so free it first */
- X if ((udf->at = perm_at()) == (struct at_type *)NULL)
- X int_error("not enough memory for function",start_token);
- X m_capture(&(udf->definition),start_token,c_token-1);
- X }
- X else {
- X /* variable ! */
- X start_token = c_token;
- X c_token +=2;
- X udv = add_udv(start_token);
- X (void) const_express(&(udv->udv_value));
- X udv->udv_undef = FALSE;
- X }
- X}
- X
- X
- Xget_data(this_plot)
- Xstruct curve_points *this_plot;
- X{
- Xstatic char data_file[MAX_LINE_LEN+1], line[MAX_LINE_LEN+1];
- Xregister int i, l_num, datum;
- Xregister FILE *fp;
- Xfloat x, y;
- Xint npoints; /* number of points and breaks read */
- X
- X quote_str(data_file, c_token);
- X this_plot->plot_type = DATA;
- X if ((fp = fopen(data_file, "r")) == (FILE *)NULL)
- X os_error("can't open data file", c_token);
- X
- X l_num = 0;
- X datum = 0;
- X i = 0;
- X npoints = 0;
- X while ( fgets(line, MAX_LINE_LEN, fp) != (char *)NULL ) {
- X l_num++;
- X if (is_comment(line[0]))
- X continue; /* ignore comments */
- X npoints++;
- X if (i >= samples) /* should never be > samples */
- X continue; /* Overflow! keep looping to get count */
- X if (!line[1]) { /* is it blank line ? */
- X /* break in data, make next point undefined */
- X this_plot->points[i].type = UNDEFINED;
- X i++;
- X continue;
- X }
- X
- X switch (sscanf(line, "%f %f", &x, &y)) {
- X case 1: { /* only one number on the line */
- X y = x; /* assign that number to y */
- X x = datum; /* and make the index into x */
- X /* no break; !!! */
- X }
- X case 2: {
- X datum++;
- X this_plot->points[i].type = INRANGE;
- X
- X if (log_x) {
- X if (x < 0.0) {
- X this_plot->points[i].type = UNDEFINED;
- X } else if (x == 0.0) {
- X this_plot->points[i].type = OUTRANGE;
- X this_plot->points[i].x = -VERYLARGE;
- X } else
- X this_plot->points[i].x = log10(x);
- X } else
- X this_plot->points[i].x = x;
- X
- X if (log_y) {
- X if (y < 0.0) {
- X this_plot->points[i].type = UNDEFINED;
- X } else if (y == 0.0) {
- X this_plot->points[i].type = OUTRANGE;
- X this_plot->points[i].y = -VERYLARGE;
- X } else
- X this_plot->points[i].y = log10(y);
- X } else
- X this_plot->points[i].y = y;
- X
- X if (this_plot->points[i].type == INRANGE)
- X if ( (autoscale_lx || inrange(x,xmin,xmax))
- X && (autoscale_ly || inrange(y,ymin,ymax) || polar)) {
- X if (autoscale_lx) {
- X if (x < xmin) xmin = x;
- X if (x > xmax) xmax = x;
- X }
- X if (autoscale_ly) {
- X if (y < ymin) ymin = y;
- X if (y > ymax) ymax = y;
- X }
- X } else {
- X this_plot->points[i].type = OUTRANGE;
- X }
- X i++;
- X break;
- X }
- X default: {
- X (void) sprintf(line, "bad data on line %d", l_num);
- X int_error(line,c_token);
- X }
- X }
- X }
- X if (npoints > samples) {
- X (void) sprintf(line,
- X "%d data points and breaks found--samples must be set at least this high",
- X npoints);
- X int_error(line,c_token);
- X }
- X this_plot->p_count = i;
- X (void) fclose(fp);
- X}
- X
- X/* This parses the plot command after any range specifications.
- X * To support autoscaling on the x axis, we want any data files to
- X * define the x range, then to plot any functions using that range.
- X * We thus parse the input twice, once to pick up the data files,
- X * and again to pick up the functions. Definitions are processed
- X * twice, but that won't hurt.
- X */
- Xeval_plots()
- X{
- Xregister int i;
- Xregister struct curve_points *this_plot, **tp_ptr;
- Xregister int start_token, mysamples;
- Xregister int begin_token;
- Xregister double x_min, x_max, y_min, y_max, x;
- Xregister double xdiff, temp;
- Xstatic struct value a;
- XBOOLEAN some_data_files = FALSE;
- Xint plot_num, line_num, point_num;
- X
- X mysamples = samples;
- X
- X if (autoscale_ly) {
- X ymin = VERYLARGE;
- X ymax = -VERYLARGE;
- X } else if (log_y && (ymin <= 0.0 || ymax <= 0.0))
- X int_error("y range must be above 0 for log scale!",
- X NO_CARET);
- X
- X tp_ptr = &(first_plot);
- X plot_num = 0;
- X line_num = 0; /* default line type */
- X point_num = 0; /* default point type */
- X
- X begin_token = c_token;
- X
- X/*** First Pass: Read through data files ***/
- X/* This pass serves to set the xrange and to parse the command, as well
- X * as filling in every thing except the function data. That is done after
- X * the xrange is defined.
- X */
- X while (TRUE) {
- X if (END_OF_COMMAND)
- X int_error("function to plot expected",c_token);
- X
- X start_token = c_token;
- X
- X if (is_definition(c_token)) {
- X define();
- X } else {
- X plot_num++;
- X if (*tp_ptr)
- X this_plot = *tp_ptr;
- X else { /* no memory malloc()'d there yet */
- X this_plot = (struct curve_points *)
- X alloc((unsigned int) (sizeof(struct curve_points) -
- X (MAX_POINTS -(samples+1))*sizeof(struct coordinate)),
- X "curve points");
- X this_plot->next_cp = NULL;
- X this_plot->title = NULL;
- X *tp_ptr = this_plot;
- X }
- X
- X if (isstring(c_token)) { /* data file to plot */
- X if (!some_data_files && autoscale_lx) {
- X xmin = VERYLARGE;
- X xmax = -VERYLARGE;
- X }
- X some_data_files = TRUE;
- X
- X this_plot->plot_type = DATA;
- X this_plot->plot_style = data_style;
- X get_data(this_plot);
- X c_token++;
- X }
- X else { /* function to plot */
- X this_plot->plot_type = FUNC;
- X this_plot->plot_style = func_style;
- X dummy_func = &plot_func;
- X plot_func.at = temp_at();
- X /* ignore it for now */
- X }
- X
- X if (almost_equals(c_token,"t$itle")) {
- X c_token++;
- X if ( (input_line[token[c_token].start_index]=='\'')
- X ||(input_line[token[c_token].start_index]=='"') ) {
- X m_quote_capture(&(this_plot->title),c_token,c_token);
- X }
- X else {
- X int_error("expecting \"title\" for plot",c_token);
- X }
- X c_token++;
- X }
- X else {
- X m_capture(&(this_plot->title),start_token,c_token-1);
- X }
- X
- X this_plot->line_type = line_num;
- X this_plot->point_type = point_num;
- X
- X if (almost_equals(c_token,"w$ith")) {
- X this_plot->plot_style = get_style();
- X }
- X
- X if ( !equals(c_token,",") && !END_OF_COMMAND ) {
- X struct value t;
- X this_plot->line_type = (int)real(const_express(&t))-1;
- X }
- X if ( !equals(c_token,",") && !END_OF_COMMAND ) {
- X struct value t;
- X this_plot->point_type = (int)real(const_express(&t))-1;
- X }
- X if ( (this_plot->plot_style == POINTS) ||
- X (this_plot->plot_style == LINESPOINTS) )
- X point_num++;
- X line_num++;
- X
- X tp_ptr = &(this_plot->next_cp);
- X }
- X
- X if (equals(c_token,","))
- X c_token++;
- X else
- X break;
- X }
- X
- X/*** Second Pass: Evaluate the functions ***/
- X/* Everything is defined now, except the function data. We expect
- X * no syntax errors, etc, since the above parsed it all. This makes
- X * the code below simpler. If autoscale_ly, the yrange may still change.
- X */
- X if (xmin == xmax)
- X if (autoscale_lx) {
- X fprintf(stderr, "Warning: empty x range [%g:%g], ", xmin,xmax);
- X if (xmin == 0.0) {
- X /* completely arbitary */
- X xmin = -1.;
- X xmax = 1.;
- X } else {
- X /* expand range by 10% in either direction */
- X xmin = xmin * 0.9;
- X xmax = xmax * 1.1;
- X }
- X fprintf(stderr, "adjusting to [%g:%g]\n", xmin,xmax);
- X } else {
- X int_error("x range is empty", c_token);
- X }
- X
- X if (log_x) {
- X if (xmin <= 0.0 || xmax <= 0.0)
- X int_error("x range must be greater than 0 for log scale!",NO_CARET);
- X x_min = log10(xmin);
- X x_max = log10(xmax);
- X } else {
- X x_min = xmin;
- X x_max = xmax;
- X }
- X
- X xdiff = (x_max - x_min) / mysamples;
- X
- X plot_num = 0;
- X this_plot = first_plot;
- X c_token = begin_token; /* start over */
- X
- X /* Read through functions */
- X while (TRUE) {
- X if (is_definition(c_token)) {
- X define();
- X } else {
- X plot_num++;
- X if (isstring(c_token)) { /* data file to plot */
- X /* ignore this now */
- X c_token++;
- X }
- X else { /* function to plot */
- X dummy_func = &plot_func;
- X plot_func.at = temp_at(); /* reparse function */
- X
- X for (i = 0; i <= mysamples; i++) {
- X if (i == samples+1)
- X int_error("number of points exceeded samples",
- X NO_CARET);
- X x = x_min + i*xdiff;
- X /* if (log_x) PEM fix logscale x axis */
- X /* x = pow(10.0,x); 26-Sep-89 */
- X (void) complex(&plot_func.dummy_value,
- X log_x ? pow(10.0,x) : x,
- X 0.0);
- X
- X evaluate_at(plot_func.at,&a);
- X
- X if (undefined || (fabs(imag(&a)) > zero)) {
- X this_plot->points[i].type = UNDEFINED;
- X continue;
- X }
- X
- X temp = real(&a);
- X
- X if (log_y && temp < 0.0) {
- X this_plot->points[i].type = UNDEFINED;
- X continue;
- X }
- X
- X this_plot->points[i].x = x;
- X if (log_y) {
- X if (temp == 0.0) {
- X this_plot->points[i].type = OUTRANGE;
- X this_plot->points[i].y = -VERYLARGE;
- X continue;
- X } else {
- X this_plot->points[i].y = log10(temp);
- X }
- X } else
- X this_plot->points[i].y = temp;
- X
- X if (autoscale_ly || polar
- X || inrange(temp, ymin, ymax)) {
- X this_plot->points[i].type = INRANGE;
- X if (autoscale_ly && temp < ymin) ymin = temp;
- X if (autoscale_ly && temp > ymax) ymax = temp;
- X } else
- X this_plot->points[i].type = OUTRANGE;
- X }
- X this_plot->p_count = i; /* mysamples + 1 */
- X }
- X
- X /* title was handled above */
- X if (almost_equals(c_token,"t$itle")) {
- X c_token++;
- X c_token++;
- X }
- X
- X /* style was handled above */
- X if (almost_equals(c_token,"w$ith")) {
- X c_token++;
- X c_token++;
- X }
- X
- X /* line and point types were handled above */
- X if ( !equals(c_token,",") && !END_OF_COMMAND ) {
- X struct value t;
- X (void)real(const_express(&t));
- X }
- X if ( !equals(c_token,",") && !END_OF_COMMAND ) {
- X struct value t;
- X (void)real(const_express(&t));
- X }
- X
- X this_plot = this_plot->next_cp;
- X }
- X
- X if (equals(c_token,","))
- X c_token++;
- X else
- X break;
- X }
- X
- X if (ymin == ymax)
- X /* if autoscale, widen range */
- X if (autoscale_ly) {
- X fprintf(stderr, "Warning: empty y range [%g:%g], ", ymin, ymax);
- X if (ymin == 0.0) {
- X ymin = -1.;
- X ymax = 1.;
- X } else {
- X /* expand range by 10% in either direction */
- X ymin = ymin * 0.9;
- X ymax = ymax * 1.1;
- X }
- X fprintf(stderr, "adjusting to [%g:%g]\n", ymin, ymax);
- X } else {
- X int_error("y range is empty", c_token);
- X }
- X
- X/* Now we finally know the real ymin and ymax */
- X if (log_y) {
- X y_min = log10(ymin);
- X y_max = log10(ymax);
- X } else {
- X y_min = ymin;
- X y_max = ymax;
- X }
- X capture(replot_line,plot_token,c_token);
- X do_plot(first_plot,plot_num,x_min,x_max,y_min,y_max);
- X}
- X
- X
- X
- Xdone(status)
- Xint status;
- X{
- X if (term && term_init)
- X (*term_tbl[term].reset)();
- X#ifdef VMS
- X vms_reset();
- X#endif
- X exit(status);
- X}
- X
- X#ifdef MSDOS
- X#ifndef __TURBOC__ /* Turbo C already has sleep() */
- X#ifndef __ZTC__ /* ZTC already has usleep() */
- X/* kludge to provide sleep() for msc 5.1 */
- Xvoid sleep(delay)
- Xunsigned int delay;
- X{
- Xunsigned long time_is_up;
- X time_is_up = time(NULL) + (unsigned long) delay;
- X while (time(NULL)<time_is_up)
- X /* wait */ ;
- X}
- X#endif /* not ZTC */
- X#endif /* not TURBOC */
- X#endif /* MSDOS */
- X
- X
- X/* Support for input, shell, and help for various systems */
- X
- X#ifdef vms
- X
- X#include <descrip.h>
- X#include <rmsdef.h>
- X#include <errno.h>
- X
- Xextern lib$get_input(), lib$put_output();
- X
- Xint vms_len;
- X
- Xunsigned int status[2] = {1, 0};
- X
- Xstatic char help[MAX_LINE_LEN+1] = "gnuplot";
- X
- X$DESCRIPTOR(prompt_desc,PROMPT);
- X$DESCRIPTOR(line_desc,input_line);
- X
- X$DESCRIPTOR(help_desc,help);
- X$DESCRIPTOR(helpfile_desc,"GNUPLOT$HELP");
- X
- X
- Xread_line(prompt)
- Xchar *prompt;
- X{
- X int more, start=0;
- X char expand_prompt[40];
- X
- X prompt_desc.dsc$w_length = strlen (prompt);
- X prompt_desc.dsc$a_pointer = prompt;
- X (void) strcpy (expand_prompt, "_");
- X (void) strncat (expand_prompt, prompt, 38);
- X do {
- X line_desc.dsc$w_length = MAX_LINE_LEN - start;
- X line_desc.dsc$a_pointer = &input_line[start];
- X switch(status[1] = lib$get_input(&line_desc, &prompt_desc, &vms_len)){
- X case RMS$_EOF:
- X done(IO_SUCCESS); /* ^Z isn't really an error */
- X break;
- X case RMS$_TNS: /* didn't press return in time *
- X /
- X vms_len--; /* skip the last character */
- X break; /* and parse anyway */
- X case RMS$_BES: /* Bad Escape Sequence */
- X case RMS$_PES: /* Partial Escape Sequence */
- X sys$putmsg(status);
- X vms_len = 0; /* ignore the line */
- X break;
- X case SS$_NORMAL:
- X break; /* everything's fine */
- X default:
- X done(status[1]); /* give the error message */
- X }
- X start += vms_len;
- X input_line[start] = '\0';
- X inline_num++;
- X if (input_line[start-1] == '\\') {
- X /* Allow for a continuation line. */
- X prompt_desc.dsc$w_length = strlen (expand_prompt);
- X prompt_desc.dsc$a_pointer = expand_prompt;
- X more = 1;
- X --start;
- X }
- X else {
- X line_desc.dsc$w_length = strlen(input_line);
- X line_desc.dsc$a_pointer = input_line;
- X more = 0;
- X }
- X } while (more);
- X}
- X
- X
- Xdo_help()
- X{
- X help_desc.dsc$w_length = strlen(help);
- X if ((vaxc$errno = lbr$output_help(lib$put_output,0,&help_desc,
- X &helpfile_desc,0,lib$get_input)) != SS$_NORMAL)
- X os_error("can't open GNUPLOT$HELP");
- X}
- X
- X
- Xdo_shell()
- X{
- X if ((vaxc$errno = lib$spawn()) != SS$_NORMAL) {
- X os_error("spawn error",NO_CARET);
- X }
- X}
- X
- X
- Xdo_system()
- X{
- X input_line[0] = ' '; /* an embarrassment, but... */
- X
- X if ((vaxc$errno = lib$spawn(&line_desc)) != SS$_NORMAL)
- X os_error("spawn error",NO_CARET);
- X
- X (void) putc('\n',stderr);
- X}
- X
- X#else /* vms */
- X
- X/* do_help: (not VMS, although it would work)
- X * Give help to the user.
- X * It parses the command line into helpbuf and supplies help for that
- X * string. Then, if there are subtopics available for that key,
- X * it prompts the user with this string. If more input is
- X * given, do_help is called recursively, with the argument the index of
- X * null character in the string. Thus a more specific help can be
- X * supplied. This can be done repeatedly.
- X * If null input is given, the function returns, effecting a
- X * backward climb up the tree.
- X * David Kotz (dfk@cs.duke.edu) 10/89
- X */
- Xdo_help()
- X{
- X static char helpbuf[MAX_LINE_LEN] = "";
- X static char prompt[MAX_LINE_LEN] = "";
- X int base; /* index of first char AFTER help string */
- X int len; /* length of current help string */
- X BOOLEAN more_help;
- X BOOLEAN only; /* TRUE if only printing subtopics */
- X int subtopics; /* 0 if no subtopics for this topic */
- X int start; /* starting token of help string */
- X char *help_ptr; /* name of help file */
- X
- X if ( (help_ptr = getenv("GNUHELP")) == (char *)NULL )
- X /* if can't find environment variable then just use HELPFILE */
- X help_ptr = HELPFILE;
- X
- X len = base = strlen(helpbuf);
- X
- X /* find the end of the help command */
- X for (start = c_token; !(END_OF_COMMAND); c_token++)
- X ;
- X /* copy new help input into helpbuf */
- X if (len > 0)
- X helpbuf[len++] = ' '; /* add a space */
- X capture(helpbuf+len, start, c_token-1);
- X squash_spaces(helpbuf+base); /* only bother with new stuff */
- X lower_case(helpbuf+base); /* only bother with new stuff */
- X len = strlen(helpbuf);
- X
- X /* now, a lone ? will print subtopics only */
- X if (strcmp(helpbuf + (base ? base+1 : 0), "?") == 0) {
- X /* subtopics only */
- X subtopics = 1;
- X only = TRUE;
- X helpbuf[base] = '\0'; /* cut off question mark */
- X } else {
- X /* normal help request */
- X subtopics = 0;
- X only = FALSE;
- X }
- X
- X switch (help(helpbuf, help_ptr, &subtopics)) {
- X case H_FOUND: {
- X /* already printed the help info */
- X /* subtopics now is true if there were any subtopics */
- X screen_ok = FALSE;
- X
- X do {
- X if (subtopics && !only) {
- X /* prompt for subtopic with current help string */
- X if (len > 0)
- X (void) sprintf(prompt, "Subtopic of %s: ", helpbuf);
- X else
- X (void) strcpy(prompt, "Help topic: ");
- X read_line(prompt);
- X num_tokens = scanner(input_line);
- X c_token = 0;
- X more_help = !(END_OF_COMMAND);
- X if (more_help)
- X /* base for next level is all of current helpbuf */
- X do_help();
- X } else
- X more_help = FALSE;
- X } while(more_help);
- X
- X break;
- X }
- X case H_NOTFOUND: {
- X printf("Sorry, no help for '%s'\n", helpbuf);
- X break;
- X }
- X case H_ERROR: {
- X perror(help_ptr);
- X break;
- X }
- X default: { /* defensive programming */
- X int_error("Impossible case in switch\n", NO_CARET);
- X /* NOTREACHED */
- X }
- X }
- X
- X helpbuf[base] = '\0'; /* cut it off where we started */
- X}
- X
- Xdo_system()
- X{
- X if (system(input_line + 1))
- X os_error("system() failed",NO_CARET);
- X}
- X
- X#ifdef MSDOS
- X
- Xread_line(prompt)
- X char *prompt;
- X{
- X register int i;
- X int start = 0;
- X BOOLEAN more;
- X int last;
- X
- X#ifndef __ZTC__
- X if (interactive) { /* if interactive use console IO so CED will work */
- X cputs(prompt);
- X do {
- X input_line[start] = MAX_LINE_LEN - start - 1;
- X cgets(&(input_line[start]));
- X (void) putc('\n',stderr);
- X if (input_line[start+2] == 26) {
- X /* end-of-file */
- X (void) putc('\n',stderr);
- X input_line[start] = '\0';
- X inline_num++;
- X if (start > 0) /* don't quit yet - process what we have */
- X more = FALSE;
- X else {
- X (void) putc('\n',stderr);
- X done(IO_SUCCESS);
- X /* NOTREACHED */
- X }
- X } else {
- X /* normal line input */
- X register i = start;
- X while ( (input_line[i] = input_line[i+2]) != (char)NULL )
- X i++; /* yuck! move everything down two characters */
- X
- X inline_num++;
- X last = strlen(input_line) - 1;
- X if (last + 1 >= MAX_LINE_LEN)
- X int_error("Input line too long",NO_CARET);
- X
- X if (input_line[last] == '\\') { /* line continuation */
- X start = last;
- X more = TRUE;
- X } else
- X more = FALSE;
- X }
- X if (more)
- X cputs("> ");
- X } while(more);
- X }
- X else { /* not interactive */
- X#endif /* not ZTC */
- X if (interactive)
- X fputs(prompt,stderr);
- X do {
- X /* grab some input */
- X if ( fgets(&(input_line[start]), MAX_LINE_LEN - start, stdin)
- X == (char *)NULL ) {
- X /* end-of-file */
- X if (interactive)
- X (void) putc('\n',stderr);
- X input_line[start] = '\0';
- X inline_num++;
- X if (start > 0) /* don't quit yet - process what we have */
- X more = FALSE;
- X else
- X done(IO_SUCCESS); /* no return */
- X } else {
- X /* normal line input */
- X last = strlen(input_line) - 1;
- X if (input_line[last] == '\n') { /* remove any newline */
- X input_line[last] = '\0';
- X /* Watch out that we don't backup beyond 0 (1-1-1) */
- X if (last > 0) --last;
- X inline_num++;
- X } else if (last+1 >= MAX_LINE_LEN)
- X int_error("Input line too long",NO_CARET);
- X
- X if (input_line[last] == '\\') { /* line continuation */
- X start = last;
- X more = TRUE;
- X } else
- X more = FALSE;
- X }
- X if (more && interactive)
- X fputs("> ", stderr);
- X } while(more);
- X#ifndef __ZTC
- X }
- X#endif
- X}
- X
- X
- Xdo_shell()
- X{
- Xregister char *comspec;
- X if ((comspec = getenv("COMSPEC")) == (char *)NULL)
- X comspec = "\command.com";
- X if (spawnl(P_WAIT,comspec,NULL) == -1)
- X os_error("unable to spawn shell",NO_CARET);
- X}
- X
- X#else /* MSDOS */
- X /* plain old Unix */
- X
- Xread_line(prompt)
- X char *prompt;
- X{
- X int start = 0;
- X BOOLEAN more;
- X int last = 0;
- X
- X if (interactive)
- X fputs(prompt,stderr);
- X do {
- X /* grab some input */
- X if ( fgets(&(input_line[start]), MAX_LINE_LEN - start, stdin)
- X == (char *)NULL ) {
- X /* end-of-file */
- X if (interactive)
- X (void) putc('\n',stderr);
- X input_line[start] = '\0';
- X inline_num++;
- X if (start > 0) /* don't quit yet - process what we have */
- X more = FALSE;
- X else
- X done(IO_SUCCESS); /* no return */
- X } else {
- X /* normal line input */
- X last = strlen(input_line) - 1;
- X if (input_line[last] == '\n') { /* remove any newline */
- X input_line[last] = '\0';
- X /* Watch out that we don't backup beyond 0 (1-1-1) */
- X if (last > 0) --last;
- X inline_num++;
- X } else if (last+1 >= MAX_LINE_LEN)
- X int_error("Input line too long",NO_CARET);
- X
- X if (input_line[last] == '\\') { /* line continuation */
- X start = last;
- X more = TRUE;
- X } else
- X more = FALSE;
- X }
- X if (more && interactive)
- X fputs("> ", stderr);
- X } while(more);
- X}
- X
- X#ifdef VFORK
- X
- Xdo_shell()
- X{
- Xregister char *shell;
- Xregister int p;
- Xstatic int execstat;
- X if (!(shell = getenv("SHELL")))
- X shell = SHELL;
- X if ((p = vfork()) == 0) {
- X execstat = execl(shell,shell,NULL);
- X _exit(1);
- X } else if (p == -1)
- X os_error("vfork failed",c_token);
- X else
- X while (wait(NULL) != p)
- X ;
- X if (execstat == -1)
- X os_error("shell exec failed",c_token);
- X (void) putc('\n',stderr);
- X}
- X#else /* VFORK */
- X
- X#define EXEC "exec "
- Xdo_shell()
- X{
- Xstatic char exec[100] = EXEC;
- Xregister char *shell;
- X if (!(shell = getenv("SHELL")))
- X shell = SHELL;
- X
- X if (system(strncpy(&exec[sizeof(EXEC)-1],shell,
- X sizeof(exec)-sizeof(EXEC)-1)))
- X os_error("system() failed",NO_CARET);
- X
- X (void) putc('\n',stderr);
- X}
- X#endif /* VFORK */
- X#endif /* MSDOS */
- X#endif /* vms */
- *-*-END-of-command.c-*-*
- echo x - setshow.c
- sed 's/^X//' >setshow.c <<'*-*-END-of-setshow.c-*-*'
- X/* GNUPLOT - setshow.c */
- X/*
- X * Copyright (C) 1986, 1987, 1990 Thomas Williams, Colin Kelley
- X *
- X * Permission to use, copy, and distribute this software and its
- X * documentation for any purpose with or without fee is hereby granted,
- X * provided that the above copyright notice appear in all copies and
- X * that both that copyright notice and this permission notice appear
- X * in supporting documentation.
- X *
- X * Permission to modify the software is granted, but not the right to
- X * distribute the modified code. Modifications are to be distributed
- X * as patches to released version.
- X *
- X * This software is provided "as is" without express or implied warranty.
- X *
- X *
- X * AUTHORS
- X *
- X * Original Software:
- X * Thomas Williams, Colin Kelley.
- X *
- X * Gnuplot 2.0 additions:
- X * Russell Lang, Dave Kotz, John Campbell.
- X *
- X * send your comments or suggestions to (pixar!info-gnuplot@sun.com).
- X *
- X */
- X
- X#include <stdio.h>
- X#include <math.h>
- X#include "plot.h"
- X#include "setshow.h"
- X
- X#define DEF_FORMAT "%g" /* default format for tic mark labels */
- X#define SIGNIF (0.01) /* less than one hundredth of a tic mark */
- X
- X/*
- X * global variables to hold status of 'set' options
- X *
- X */
- XBOOLEAN autoscale_x = TRUE;
- XBOOLEAN autoscale_y = TRUE;
- XBOOLEAN autoscale_lx = TRUE;
- XBOOLEAN autoscale_ly = TRUE;
- XBOOLEAN clip_points = FALSE;
- XBOOLEAN clip_lines1 = TRUE;
- XBOOLEAN clip_lines2 = FALSE;
- Xchar dummy_var[MAX_ID_LEN+1] = "x";
- Xchar xformat[MAX_ID_LEN+1] = DEF_FORMAT;
- Xchar yformat[MAX_ID_LEN+1] = DEF_FORMAT;
- Xenum PLOT_STYLE data_style = POINTS,
- X func_style = LINES;
- XBOOLEAN grid = FALSE;
- Xint key = -1; /* default position */
- Xdouble key_x, key_y; /* user specified position for key */
- XBOOLEAN log_x = FALSE,
- X log_y = FALSE;
- XFILE* outfile;
- Xchar outstr[MAX_ID_LEN+1] = "STDOUT";
- XBOOLEAN polar = FALSE;
- Xint samples = SAMPLES;
- Xfloat xsize = 1.0; /* scale factor for size */
- Xfloat ysize = 1.0; /* scale factor for size */
- Xint term = 0; /* unknown term is 0 */
- Xchar title[MAX_LINE_LEN+1] = "";
- Xchar xlabel[MAX_LINE_LEN+1] = "";
- Xchar ylabel[MAX_LINE_LEN+1] = "";
- Xdouble xmin = -10.0,
- X xmax = 10.0,
- X ymin = -10.0,
- X ymax = 10.0;
- Xdouble loff = 0.0,
- X roff = 0.0,
- X toff = 0.0,
- X boff = 0.0;
- Xdouble zero = ZERO; /* zero threshold, not 0! */
- X
- XBOOLEAN xtics = TRUE;
- XBOOLEAN ytics = TRUE;
- X
- Xstruct ticdef xticdef = {TIC_COMPUTED};
- Xstruct ticdef yticdef = {TIC_COMPUTED};
- X
- XBOOLEAN tic_in = TRUE;
- X
- Xstruct text_label *first_label = NULL;
- Xstruct arrow_def *first_arrow = NULL;
- X
- X/*** other things we need *****/
- Xextern char *strcpy(),*strcat();
- Xextern int strlen();
- X
- X/* input data, parsing variables */
- Xextern struct lexical_unit token[];
- Xextern char input_line[];
- Xextern int num_tokens, c_token;
- X
- Xextern char replot_line[];
- Xextern struct udvt_entry *first_udv;
- X
- Xextern double magnitude(),real();
- Xextern struct value *const_express();
- X
- X/******** Local functions ********/
- Xstatic void set_label();
- Xstatic void set_nolabel();
- Xstatic void set_arrow();
- Xstatic void set_noarrow();
- Xstatic void load_tics();
- Xstatic void load_tic_user();
- Xstatic void free_marklist();
- Xstatic void load_tic_series();
- Xstatic void load_offsets();
- X
- Xstatic void show_style(), show_range(), show_zero();
- Xstatic void show_offsets(), show_output(), show_samples(), show_size();
- Xstatic void show_title(), show_xlabel(), show_ylabel();
- Xstatic void show_label(), show_arrow(), show_grid(), show_key();
- Xstatic void show_polar(), show_tics(), show_ticdef();
- Xstatic void show_term(), show_plot(), show_autoscale(), show_clip();
- Xstatic void show_format(), show_logscale(), show_variables();
- X
- Xstatic void delete_label();
- Xstatic int assign_label_tag();
- Xstatic void delete_arrow();
- Xstatic int assign_arrow_tag();
- X
- X/******** The 'set' command ********/
- Xvoid
- Xset_command()
- X{
- X static char testfile[MAX_LINE_LEN+1];
- X
- X c_token++;
- X
- X if (almost_equals(c_token,"ar$row")) {
- X c_token++;
- X set_arrow();
- X }
- X else if (almost_equals(c_token,"noar$row")) {
- X c_token++;
- X set_noarrow();
- X }
- X else if (almost_equals(c_token,"au$toscale")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X autoscale_x = autoscale_y = TRUE;
- X } else if (equals(c_token, "xy") || equals(c_token, "yx")) {
- X autoscale_x = autoscale_y = TRUE;
- X c_token++;
- X } else if (equals(c_token, "x")) {
- X autoscale_x = TRUE;
- X c_token++;
- X } else if (equals(c_token, "y")) {
- X autoscale_y = TRUE;
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"noau$toscale")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X autoscale_x = autoscale_y = FALSE;
- X } else if (equals(c_token, "xy") || equals(c_token, "yx")) {
- X autoscale_x = autoscale_y = FALSE;
- X c_token++;
- X } else if (equals(c_token, "x")) {
- X autoscale_x = FALSE;
- X c_token++;
- X } else if (equals(c_token, "y")) {
- X autoscale_y = FALSE;
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"c$lip")) {
- X c_token++;
- X if (END_OF_COMMAND)
- X /* assuming same as points */
- X clip_points = TRUE;
- X else if (almost_equals(c_token, "p$oints"))
- X clip_points = TRUE;
- X else if (almost_equals(c_token, "o$ne"))
- X clip_lines1 = TRUE;
- X else if (almost_equals(c_token, "t$wo"))
- X clip_lines2 = TRUE;
- X else
- X int_error("expecting 'points', 'one', or 'two'", c_token);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"noc$lip")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X /* same as all three */
- X clip_points = FALSE;
- X clip_lines1 = FALSE;
- X clip_lines2 = FALSE;
- X } else if (almost_equals(c_token, "p$oints"))
- X clip_points = FALSE;
- X else if (almost_equals(c_token, "o$ne"))
- X clip_lines1 = FALSE;
- X else if (almost_equals(c_token, "t$wo"))
- X clip_lines2 = FALSE;
- X else
- X int_error("expecting 'points', 'one', or 'two'", c_token);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"d$ata")) {
- X c_token++;
- X if (!almost_equals(c_token,"s$tyle"))
- X int_error("expecting keyword 'style'",c_token);
- X data_style = get_style();
- X }
- X else if (almost_equals(c_token,"d$ummy")) {
- X c_token++;
- X copy_str(dummy_var,c_token++);
- X }
- X else if (almost_equals(c_token,"fo$rmat")) {
- X BOOLEAN setx, sety;
- X c_token++;
- X if (equals(c_token,"x")) {
- X setx = TRUE; sety = FALSE;
- X c_token++;
- X }
- X else if (equals(c_token,"y")) {
- X setx = FALSE; sety = TRUE;
- X c_token++;
- X }
- X else if (equals(c_token,"xy") || equals(c_token,"yx")) {
- X setx = sety = TRUE;
- X c_token++;
- X }
- X else if (isstring(c_token) || END_OF_COMMAND) {
- X /* Assume he wants both */
- X setx = sety = TRUE;
- X }
- X if (END_OF_COMMAND) {
- X if (setx)
- X (void) strcpy(xformat,DEF_FORMAT);
- X if (sety)
- X (void) strcpy(yformat,DEF_FORMAT);
- X }
- X else {
- X if (!isstring(c_token))
- X int_error("expecting format string",c_token);
- X else {
- X if (setx)
- X quote_str(xformat,c_token);
- X if (sety)
- X quote_str(yformat,c_token);
- X c_token++;
- X }
- X }
- X }
- X else if (almost_equals(c_token,"fu$nction")) {
- X c_token++;
- X if (!almost_equals(c_token,"s$tyle"))
- X int_error("expecting keyword 'style'",c_token);
- X func_style = get_style();
- X }
- X else if (almost_equals(c_token,"la$bel")) {
- X c_token++;
- X set_label();
- X }
- X else if (almost_equals(c_token,"nola$bel")) {
- X c_token++;
- X set_nolabel();
- X }
- X else if (almost_equals(c_token,"lo$gscale")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X log_x = log_y = TRUE;
- X } else if (equals(c_token, "xy") || equals(c_token, "yx")) {
- X log_x = log_y = TRUE;
- X c_token++;
- X } else if (equals(c_token, "x")) {
- X log_x = TRUE;
- X c_token++;
- X } else if (equals(c_token, "y")) {
- X log_y = TRUE;
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"nolo$gscale")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X log_x = log_y = FALSE;
- X } else if (equals(c_token, "xy") || equals(c_token, "yx")) {
- X log_x = log_y = FALSE;
- X c_token++;
- X } else if (equals(c_token, "x")) {
- X log_x = FALSE;
- X c_token++;
- X } else if (equals(c_token, "y")) {
- X log_y = FALSE;
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"of$fsets")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X loff = roff = toff = boff = 0.0; /* Reset offsets */
- X }
- X else {
- X load_offsets (&loff,&roff,&toff,&boff);
- X }
- X }
- X else if (almost_equals(c_token,"o$utput")) {
- X register FILE *f;
- X
- X c_token++;
- X if (term && term_init)
- X (*term_tbl[term].reset)();
- X if (END_OF_COMMAND) { /* no file specified */
- X UP_redirect (4);
- X if (outfile != stdout) /* Never close stdout */
- X (void) fclose(outfile);
- X outfile = stdout; /* Don't dup... */
- X term_init = FALSE;
- X (void) strcpy(outstr,"STDOUT");
- X } else if (!isstring(c_token))
- X int_error("expecting filename",c_token);
- X else {
- X quote_str(testfile,c_token);
- X if ((f = fopen(testfile,"w")) == (FILE *)NULL) {
- X os_error("cannot open file; output not changed",c_token);
- X }
- X if (outfile != stdout) /* Never close stdout */
- X (void) fclose(outfile);
- X outfile = f;
- X term_init = FALSE;
- X outstr[0] = '\'';
- X (void) strcat(strcpy(outstr+1,testfile),"'");
- X UP_redirect (1);
- X }
- X c_token++;
- X }
- X else if (almost_equals(c_token,"tit$le")) {
- X c_token++;
- X if (END_OF_COMMAND) { /* no label specified */
- X title[0] = '\0';
- X } else {
- X quotel_str(title,c_token);
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"xl$abel")) {
- X c_token++;
- X if (END_OF_COMMAND) { /* no label specified */
- X xlabel[0] = '\0';
- X } else {
- X quotel_str(xlabel,c_token);
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"yl$abel")) {
- X c_token++;
- X if (END_OF_COMMAND) { /* no label specified */
- X ylabel[0] = '\0';
- X } else {
- X quotel_str(ylabel,c_token);
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"pol$ar")) {
- X if (!polar) {
- X polar = TRUE;
- X xmin = 0.0;
- X xmax = 2*Pi;
- X }
- X c_token++;
- X }
- X else if (almost_equals(c_token,"nopo$lar")) {
- X if (polar) {
- X polar = FALSE;
- X xmin = -10.0;
- X xmax = 10.0;
- X }
- X c_token++;
- X }
- X else if (almost_equals(c_token,"g$rid")) {
- X grid = TRUE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"nog$rid")) {
- X grid = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"k$ey")) {
- X struct value a;
- X c_token++;
- X if (END_OF_COMMAND) {
- X key = -1;
- X }
- X else {
- X key_x = real(const_express(&a));
- X if (!equals(c_token,","))
- X int_error("',' expected",c_token);
- X c_token++;
- X key_y = real(const_express(&a));
- X key = 1;
- X }
- X }
- X else if (almost_equals(c_token,"nok$ey")) {
- X key = 0;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"tic$s")) {
- X tic_in = TRUE;
- X c_token++;
- X if (almost_equals(c_token,"i$n")) {
- X tic_in = TRUE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"o$ut")) {
- X tic_in = FALSE;
- X c_token++;
- X }
- X }
- X else if (almost_equals(c_token,"xt$ics")) {
- X xtics = TRUE;
- X c_token++;
- X if (END_OF_COMMAND) { /* reset to default */
- X if (xticdef.type == TIC_USER) {
- X free_marklist(xticdef.def.user);
- X xticdef.def.user = NULL;
- X }
- X xticdef.type = TIC_COMPUTED;
- X }
- X else
- X load_tics(&xticdef);
- X }
- X else if (almost_equals(c_token,"noxt$ics")) {
- X xtics = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"yt$ics")) {
- X ytics = TRUE;
- X c_token++;
- X if (END_OF_COMMAND) { /* reset to default */
- X if (yticdef.type == TIC_USER) {
- X free_marklist(yticdef.def.user);
- X yticdef.def.user = NULL;
- X }
- X yticdef.type = TIC_COMPUTED;
- X }
- X else
- X load_tics(&yticdef);
- X }
- X else if (almost_equals(c_token,"noyt$ics")) {
- X ytics = FALSE;
- X c_token++;
- X }
- X else if (almost_equals(c_token,"sa$mples")) {
- X register int tsamp;
- X struct value a;
- X
- X c_token++;
- X tsamp = (int)magnitude(const_express(&a));
- X if (tsamp < 1)
- X int_error("sampling rate must be > 0; sampling unchanged",
- X c_token);
- X else {
- X extern struct curve_points *first_plot;
- X register struct curve_points *f_p = first_plot;
- X
- X first_plot = NULL;
- X cp_free(f_p);
- X samples = tsamp;
- X }
- X }
- X else if (almost_equals(c_token,"si$ze")) {
- X struct value s;
- X c_token++;
- X if (END_OF_COMMAND) {
- X xsize = 1.0;
- X ysize = 1.0;
- X }
- X else {
- X xsize=real(const_express(&s));
- X if (!equals(c_token,","))
- X int_error("',' expected",c_token);
- X c_token++;
- X ysize=real(const_express(&s));
- X }
- X }
- X else if (almost_equals(c_token,"t$erminal")) {
- X c_token++;
- X if (END_OF_COMMAND) {
- X list_terms();
- X screen_ok = FALSE;
- X }
- X else {
- X if (term && term_init) {
- X (*term_tbl[term].reset)();
- X (void) fflush(outfile);
- X }
- X term = set_term(c_token);
- X }
- X c_token++;
- X }
- X else if (almost_equals(c_token,"xr$ange")) {
- X BOOLEAN changed;
- X c_token++;
- X if (!equals(c_token,"["))
- X int_error("expecting '['",c_token);
- X c_token++;
- X changed = load_range(&xmin,&xmax);
- X if (!equals(c_token,"]"))
- X int_error("expecting ']'",c_token);
- X c_token++;
- X if (changed)
- X autoscale_x = FALSE;
- X }
- X else if (almost_equals(c_token,"yr$ange")) {
- X BOOLEAN changed;
- X c_token++;
- X if (!equals(c_token,"["))
- X int_error("expecting '['",c_token);
- X c_token++;
- X changed = load_range(&ymin,&ymax);
- X if (!equals(c_token,"]"))
- X int_error("expecting ']'",c_token);
- X c_token++;
- X if (changed)
- X autoscale_y = FALSE;
- X }
- X else if (almost_equals(c_token,"z$ero")) {
- X struct value a;
- X c_token++;
- X zero = magnitude(const_express(&a));
- X }
- X else
- X int_error(
- X "valid set options: '{no}arrow', {no}autoscale', '{no}clip', data', \n\
- X 'dummy', 'format', 'function', '{no}grid', '{no}key', '{no}label', \n\
- X '{no}logscale','offsets', 'output', '{no}polar', 'samples', \n\
- X 'size', 'terminal', 'tics', 'title', 'xlabel', 'xrange', 'xtics', \n\
- X 'ylabel', 'yrange', 'ytics', 'zero',\n\ ",
- X c_token);
- X}
- X
- X/*********** Support functions for set_command ***********/
- X
- X/* process a 'set label' command */
- X/* set label {tag} {label_text} {at x,y} {pos} */
- Xstatic void
- Xset_label()
- X{
- X struct value a;
- X struct text_label *this_label = NULL;
- X struct text_label *new_label = NULL;
- X struct text_label *prev_label = NULL;
- X double x, y;
- X char text[MAX_LINE_LEN+1];
- X enum JUSTIFY just;
- X int tag;
- X BOOLEAN set_text, set_position, set_just;
- X
- X /* get tag */
- X if (!END_OF_COMMAND
- X && !isstring(c_token)
- X && !equals(c_token, "at")
- X && !equals(c_token, "left")
- X && !equals(c_token, "center")
- X && !equals(c_token, "centre")
- X && !equals(c_token, "right")) {
- X /* must be a tag expression! */
- X tag = (int)real(const_express(&a));
- X if (tag <= 0)
- X int_error("tag must be > zero", c_token);
- X } else
- X tag = assign_label_tag(); /* default next tag */
- X
- X /* get text */
- X if (!END_OF_COMMAND && isstring(c_token)) {
- X /* get text */
- X quotel_str(text, c_token);
- X c_token++;
- X set_text = TRUE;
- X } else {
- X text[0] = '\0'; /* default no text */
- X set_text = FALSE;
- X }
- X
- X /* get justification - what the heck, let him put it here */
- X if (!END_OF_COMMAND && !equals(c_token, "at")) {
- X if (almost_equals(c_token,"l$eft")) {
- X just = LEFT;
- X }
- X else if (almost_equals(c_token,"c$entre")
- X || almost_equals(c_token,"c$enter")) {
- X just = CENTRE;
- X }
- X else if (almost_equals(c_token,"r$ight")) {
- X just = RIGHT;
- X }
- X else
- X int_error("bad syntax in set label", c_token);
- X c_token++;
- X set_just = TRUE;
- X } else {
- X just = LEFT; /* default left justified */
- X set_just = FALSE;
- X }
- X
- X /* get position */
- X if (!END_OF_COMMAND && equals(c_token, "at")) {
- X c_token++;
- X if (END_OF_COMMAND)
- X int_error("coordinates expected", c_token);
- X /* get coordinates */
- X x = real(const_express(&a));
- X if (!equals(c_token,","))
- X int_error("',' expected",c_token);
- X c_token++;
- X y = real(const_express(&a));
- X set_position = TRUE;
- X } else {
- X x = y = 0; /* default at origin */
- X set_position = FALSE;
- X }
- X
- X /* get justification */
- X if (!END_OF_COMMAND) {
- X if (set_just)
- X int_error("only one justification is allowed", c_token);
- X if (almost_equals(c_token,"l$eft")) {
- X just = LEFT;
- X }
- X else if (almost_equals(c_token,"c$entre")
- X || almost_equals(c_token,"c$enter")) {
- X just = CENTRE;
- X }
- X else if (almost_equals(c_token,"r$ight")) {
- X just = RIGHT;
- X }
- X else
- X int_error("bad syntax in set label", c_token);
- X c_token++;
- X set_just = TRUE;
- X }
- X
- X if (!END_OF_COMMAND)
- X int_error("extraneous or out-of-order arguments in set label", c_token);
- X
- X /* OK! add label */
- X if (first_label != NULL) { /* skip to last label */
- X for (this_label = first_label; this_label != NULL ;
- X prev_label = this_label, this_label = this_label->next)
- X /* is this the label we want? */
- X if (tag <= this_label->tag)
- X break;
- X }
- X if (this_label != NULL && tag == this_label->tag) {
- X /* changing the label */
- X if (set_position) {
- X this_label->x = x;
- X this_label->y = y;
- X }
- X if (set_text)
- X (void) strcpy(this_label->text, text);
- X if (set_just)
- X this_label->pos = just;
- X } else {
- X /* adding the label */
- X new_label = (struct text_label *)
- X alloc ( (unsigned int) sizeof(struct text_label), "label");
- X if (prev_label != NULL)
- X prev_label->next = new_label; /* add it to end of list */
- X else
- X first_label = new_label; /* make it start of list */
- X new_label->tag = tag;
- X new_label->next = this_label;
- X new_label->x = x;
- X new_label->y = y;
- X (void) strcpy(new_label->text, text);
- X new_label->pos = just;
- X }
- X}
- X
- X/* process 'set nolabel' command */
- X/* set nolabel {tag} */
- Xstatic void
- Xset_nolabel()
- X{
- X struct value a;
- X struct text_label *this_label;
- X struct text_label *prev_label;
- X int tag;
- X
- X if (END_OF_COMMAND) {
- X /* delete all labels */
- X while (first_label != NULL)
- X delete_label((struct text_label *)NULL,first_label);
- X }
- X else {
- X /* get tag */
- X tag = (int)real(const_express(&a));
- X if (!END_OF_COMMAND)
- X int_error("extraneous arguments to set nolabel", c_token);
- X for (this_label = first_label, prev_label = NULL;
- X this_label != NULL;
- X prev_label = this_label, this_label = this_label->next) {
- X if (this_label->tag == tag) {
- X delete_label(prev_label,this_label);
- X return; /* exit, our job is done */
- X }
- X }
- X int_error("label not found", c_token);
- X }
- X}
- X
- X/* assign a new label tag */
- X/* labels are kept sorted by tag number, so this is easy */
- Xstatic int /* the lowest unassigned tag number */
- Xassign_label_tag()
- X{
- X struct text_label *this_label;
- X int last = 0; /* previous tag value */
- X
- X for (this_label = first_label; this_label != NULL;
- X this_label = this_label->next)
- X if (this_label->tag == last+1)
- X last++;
- X else
- X break;
- X
- X return (last+1);
- X}
- X
- X/* delete label from linked list started by first_label.
- X * called with pointers to the previous label (prev) and the
- X * label to delete (this).
- X * If there is no previous label (the label to delete is
- X * first_label) then call with prev = NULL.
- X */
- Xstatic void
- Xdelete_label(prev,this)
- X struct text_label *prev, *this;
- X{
- X if (this!=NULL) { /* there really is something to delete */
- X if (prev!=NULL) /* there is a previous label */
- X prev->next = this->next;
- X else /* this = first_label so change first_label */
- X first_label = this->next;
- X free((char *)this);
- X }
- X}
- X
- X
- X/* process a 'set arrow' command */
- X/* set arrow {tag} {from x,y} {to x,y} */
- Xstatic void
- Xset_arrow()
- X{
- X struct value a;
- X struct arrow_def *this_arrow = NULL;
- X struct arrow_def *new_arrow = NULL;
- X struct arrow_def *prev_arrow = NULL;
- X double sx, sy;
- X double ex, ey;
- X int tag;
- X BOOLEAN set_start, set_end;
- X
- X /* get tag */
- X if (!END_OF_COMMAND
- X && !equals(c_token, "from")
- X && !equals(c_token, "to")) {
- X /* must be a tag expression! */
- X tag = (int)real(const_express(&a));
- X if (tag <= 0)
- X int_error("tag must be > zero", c_token);
- X } else
- X tag = assign_arrow_tag(); /* default next tag */
- X
- X /* get start position */
- X if (!END_OF_COMMAND && equals(c_token, "from")) {
- X c_token++;
- X if (END_OF_COMMAND)
- X int_error("start coordinates expected", c_token);
- X /* get coordinates */
- X sx = real(const_express(&a));
- X if (!equals(c_token,","))
- X int_error("',' expected",c_token);
- X c_token++;
- X sy = real(const_express(&a));
- X set_start = TRUE;
- X } else {
- X sx = sy = 0; /* default at origin */
- X set_start = FALSE;
- X }
- X
- X /* get end position */
- X if (!END_OF_COMMAND && equals(c_token, "to")) {
- X c_token++;
- X if (END_OF_COMMAND)
- X int_error("end coordinates expected", c_token);
- X /* get coordinates */
- X ex = real(const_express(&a));
- X if (!equals(c_token,","))
- X int_error("',' expected",c_token);
- X c_token++;
- X ey = real(const_express(&a));
- X set_end = TRUE;
- X } else {
- X ex = ey = 0; /* default at origin */
- X set_end = FALSE;
- X }
- X
- X /* get start position - what the heck, either order is ok */
- X if (!END_OF_COMMAND && equals(c_token, "from")) {
- X if (set_start)
- X int_error("only one 'from' is allowed", c_token);
- X c_token++;
- X if (END_OF_COMMAND)
- X int_error("start coordinates expected", c_token);
- X /* get coordinates */
- X sx = real(const_express(&a));
- X if (!equals(c_token,","))
- X int_error("',' expected",c_token);
- X c_token++;
- X sy = real(const_express(&a));
- X set_start = TRUE;
- X }
- X
- X if (!END_OF_COMMAND)
- X int_error("extraneous or out-of-order arguments in set arrow", c_token);
- X
- X /* OK! add arrow */
- X if (first_arrow != NULL) { /* skip to last arrow */
- X for (this_arrow = first_arrow; this_arrow != NULL ;
- X prev_arrow = this_arrow, this_arrow = this_arrow->next)
- X /* is this the arrow we want? */
- X if (tag <= this_arrow->tag)
- X break;
- X }
- X if (this_arrow != NULL && tag == this_arrow->tag) {
- X /* changing the arrow */
- X if (set_start) {
- X this_arrow->sx = sx;
- X this_arrow->sy = sy;
- X }
- X if (set_end) {
- X this_arrow->ex = ex;
- X this_arrow->ey = ey;
- X }
- X } else {
- X /* adding the arrow */
- X new_arrow = (struct arrow_def *)
- X alloc ( (unsigned int) sizeof(struct arrow_def), "arrow");
- X if (prev_arrow != NULL)
- X prev_arrow->next = new_arrow; /* add it to end of list */
- X else
- X first_arrow = new_arrow; /* make it start of list */
- X new_arrow->tag = tag;
- X new_arrow->next = this_arrow;
- X new_arrow->sx = sx;
- X new_arrow->sy = sy;
- X new_arrow->ex = ex;
- X new_arrow->ey = ey;
- X }
- X}
- X
- X/* process 'set noarrow' command */
- X/* set noarrow {tag} */
- Xstatic void
- Xset_noarrow()
- X{
- X struct value a;
- X struct arrow_def *this_arrow;
- X struct arrow_def *prev_arrow;
- X int tag;
- X
- X if (END_OF_COMMAND) {
- X /* delete all arrows */
- X while (first_arrow != NULL)
- X delete_arrow((struct arrow_def *)NULL,first_arrow);
- X }
- X else {
- X /* get tag */
- X tag = (int)real(const_express(&a));
- X if (!END_OF_COMMAND)
- X int_error("extraneous arguments to set noarrow", c_token);
- X for (this_arrow = first_arrow, prev_arrow = NULL;
- X this_arrow != NULL;
- X prev_arrow = this_arrow, this_arrow = this_arrow->next) {
- X if (this_arrow->tag == tag) {
- X delete_arrow(prev_arrow,this_arrow);
- X return; /* exit, our job is done */
- X }
- X }
- X int_error("arrow not found", c_token);
- X }
- X}
- X
- X/* assign a new arrow tag */
- X/* arrows are kept sorted by tag number, so this is easy */
- Xstatic int /* the lowest unassigned tag number */
- Xassign_arrow_tag()
- X{
- X struct arrow_def *this_arrow;
- X int last = 0; /* previous tag value */
- X
- X for (this_arrow = first_arrow; this_arrow != NULL;
- X this_arrow = this_arrow->next)
- X if (this_arrow->tag == last+1)
- X last++;
- X else
- X break;
- X
- X return (last+1);
- X}
- X
- X/* delete arrow from linked list started by first_arrow.
- X * called with pointers to the previous arrow (prev) and the
- X * arrow to delete (this).
- X * If there is no previous arrow (the arrow to delete is
- X * first_arrow) then call with prev = NULL.
- X */
- Xstatic void
- Xdelete_arrow(prev,this)
- X struct arrow_def *prev, *this;
- X{
- X if (this!=NULL) { /* there really is something to delete */
- X if (prev!=NULL) /* there is a previous arrow */
- X prev->next = this->next;
- X else /* this = first_arrow so change first_arrow */
- X first_arrow = this->next;
- X free((char *)this);
- X }
- X}
- X
- X
- Xenum PLOT_STYLE /* not static; used by command.c */
- Xget_style()
- X{
- Xregister enum PLOT_STYLE ps;
- X
- X c_token++;
- X if (almost_equals(c_token,"l$ines"))
- X ps = LINES;
- X else if (almost_equals(c_token,"i$mpulses"))
- X ps = IMPULSES;
- X else if (almost_equals(c_token,"p$oints"))
- X ps = POINTS;
- X else if (almost_equals(c_token,"linesp$oints"))
- X ps = LINESPOINTS;
- X else if (almost_equals(c_token,"d$ots"))
- X ps = DOTS;
- X else
- X int_error("expecting 'lines', 'points', 'linespoints', 'dots', or 'impulses'",c_token);
- X c_token++;
- X return(ps);
- X}
- X
- X/* For set [xy]tics... command*/
- Xstatic void
- Xload_tics(tdef)
- X struct ticdef *tdef; /* change this ticdef */
- X{
- X if (equals(c_token,"(")) { /* set : TIC_USER */
- X c_token++;
- X load_tic_user(tdef);
- X } else { /* series : TIC_SERIES */
- X load_tic_series(tdef);
- X }
- X}
- X
- X/* load TIC_USER definition */
- X/* (tic[,tic]...)
- X * where tic is ["string"] value
- X * Left paren is already scanned off before entry.
- X */
- Xstatic void
- Xload_tic_user(tdef)
- X struct ticdef *tdef;
- X{
- X struct ticmark *list = NULL; /* start of list */
- X struct ticmark *last = NULL; /* end of list */
- X struct ticmark *tic = NULL; /* new ticmark */
- X char temp_string[MAX_LINE_LEN];
- X struct value a;
- X
- X while (!END_OF_COMMAND) {
- X /* parse a new ticmark */
- X tic = (struct ticmark *)alloc(sizeof(struct ticmark), (char *)NULL);
- X if (tic == (struct ticmark *)NULL) {
- X free_marklist(list);
- X int_error("out of memory for tic mark", c_token);
- X }
- X
- X /* has a string with it? */
- X if (isstring(c_token)) {
- X quote_str(temp_string,c_token);
- X tic->label = alloc((unsigned int)strlen(temp_string)+1, "tic label");
- X (void) strcpy(tic->label, temp_string);
- X c_token++;
- X } else
- X tic->label = NULL;
- X
- X /* in any case get the value */
- X tic->position = real(const_express(&a));
- X tic->next = NULL;
- X
- X /* append to list */
- X if (list == NULL)
- X last = list = tic; /* new list */
- X else { /* append to list */
- X last->next = tic;
- X last = tic;
- X }
- X
- X /* expect "," or ")" here */
- X if (!END_OF_COMMAND && equals(c_token, ","))
- X c_token++; /* loop again */
- X else
- X break; /* hopefully ")" */
- X }
- X
- X if (END_OF_COMMAND || !equals(c_token, ")")) {
- X free_marklist(list);
- X int_error("expecting right parenthesis )", c_token);
- X }
- X c_token++;
- X
- X /* successful list */
- X if (tdef->type == TIC_USER) {
- X /* remove old list */
- X /* VAX Optimiser was stuffing up following line. Turn Optimiser OFF */
- X free_marklist(tdef->def.user);
- X tdef->def.user = NULL;
- X }
- X tdef->type = TIC_USER;
- X tdef->def.user = list;
- X}
- X
- Xstatic void
- Xfree_marklist(list)
- X struct ticmark *list;
- X{
- X register struct ticmark *freeable;
- X
- X while (list != NULL) {
- X freeable = list;
- X list = list->next;
- X if (freeable->label != NULL)
- X free( (char *)freeable->label );
- X free( (char *)freeable );
- X }
- X}
- X
- X/* load TIC_SERIES definition */
- X/* start,incr[,end] */
- Xstatic void
- Xload_tic_series(tdef)
- X struct ticdef *tdef;
- X{
- X double start, incr, end;
- X struct value a;
- X int incr_token;
- X
- X start = real(const_express(&a));
- X if (!equals(c_token, ","))
- X int_error("expecting comma to separate start,incr", c_token);
- X c_token++;
- X
- X incr_token = c_token;
- X incr = real(const_express(&a));
- X
- X if (END_OF_COMMAND)
- X end = VERYLARGE;
- X else {
- X if (!equals(c_token, ","))
- X int_error("expecting comma to separate incr,end", c_token);
- X c_token++;
- X
- X end = real(const_express(&a));
- X }
- X if (!END_OF_COMMAND)
- X int_error("tic series is defined by start,increment[,end]",
- X c_token);
- X
- X if (start < end && incr <= 0)
- X int_error("increment must be positive", incr_token);
- X if (start > end && incr >= 0)
- X int_error("increment must be negative", incr_token);
- X if (start > end) {
- X /* put in order */
- X double numtics;
- X numtics = floor( (end*(1+SIGNIF) - start)/incr );
- X end = start;
- X start = end + numtics*incr;
- X incr = -incr;
- X/*
- X double temp = start;
- X start = end;
- X end = temp;
- X incr = -incr;
- X */
- X }
- X
- X if (tdef->type == TIC_USER) {
- X /* remove old list */
- X /* VAX Optimiser was stuffing up following line. Turn Optimiser OFF */
- X free_marklist(tdef->def.user);
- X tdef->def.user = NULL;
- X }
- X tdef->type = TIC_SERIES;
- X tdef->def.series.start = start;
- X tdef->def.series.incr = incr;
- X tdef->def.series.end = end;
- X}
- X
- Xstatic void
- Xload_offsets (a, b, c, d)
- Xdouble *a,*b, *c, *d;
- X{
- Xstruct value t;
- X
- X *a = real (const_express(&t)); /* loff value */
- X c_token++;
- X if (equals(c_token,","))
- X c_token++;
- X if (END_OF_COMMAND)
- X return;
- X
- X *b = real (const_express(&t)); /* roff value */
- X c_token++;
- X if (equals(c_token,","))
- X c_token++;
- X if (END_OF_COMMAND)
- X return;
- X
- X *c = real (const_express(&t)); /* toff value */
- X c_token++;
- X if (equals(c_token,","))
- X c_token++;
- X if (END_OF_COMMAND)
- X return;
- X
- X *d = real (const_express(&t)); /* boff value */
- X c_token++;
- X}
- X
- X
- XBOOLEAN /* TRUE if a or b were changed */
- Xload_range(a,b) /* also used by command.c */
- Xdouble *a,*b;
- X{
- Xstruct value t;
- XBOOLEAN changed = FALSE;
- X
- X if (equals(c_token,"]"))
- X return(FALSE);
- X if (END_OF_COMMAND) {
- X int_error("starting range value or ':' or 'to' expected",c_token);
- X } else if (!equals(c_token,"to") && !equals(c_token,":")) {
- X *a = real(const_express(&t));
- X changed = TRUE;
- X }
- X if (!equals(c_token,"to") && !equals(c_token,":"))
- X int_error("':' or keyword 'to' expected",c_token);
- X c_token++;
- X if (!equals(c_token,"]")) {
- X *b = real(const_express(&t));
- X changed = TRUE;
- X }
- X return(changed);
- X}
- X
- X
- X
- X/******* The 'show' command *******/
- Xvoid
- Xshow_command()
- X{
- X c_token++;
- X
- X if (almost_equals(c_token,"ac$tion_table") ||
- X equals(c_token,"at") ) {
- X c_token++;
- X show_at();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"ar$row")) {
- X struct value a;
- X int tag = 0;
- X
- X c_token++;
- X if (!END_OF_COMMAND) {
- X tag = (int)real(const_express(&a));
- X if (tag <= 0)
- X int_error("tag must be > zero", c_token);
- X }
- X
- X (void) putc('\n',stderr);
- X show_arrow(tag);
- X }
- X else if (almost_equals(c_token,"au$toscale")) {
- X (void) putc('\n',stderr);
- X show_autoscale();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"c$lip")) {
- X (void) putc('\n',stderr);
- X show_clip();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"d$ata")) {
- X c_token++;
- X if (!almost_equals(c_token,"s$tyle"))
- X int_error("expecting keyword 'style'",c_token);
- X (void) putc('\n',stderr);
- X show_style("data",data_style);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"d$ummy")) {
- X (void) fprintf(stderr,"\n\tdummy variable is %s\n",dummy_var);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"fo$rmat")) {
- X show_format();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"f$unctions")) {
- X c_token++;
- X if (almost_equals(c_token,"s$tyle")) {
- X (void) putc('\n',stderr);
- X show_style("functions",func_style);
- X c_token++;
- X }
- X else
- X show_functions();
- X }
- X else if (almost_equals(c_token,"lo$gscale")) {
- X (void) putc('\n',stderr);
- X show_logscale();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"of$fsets")) {
- X (void) putc('\n',stderr);
- X show_offsets();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"o$utput")) {
- X (void) putc('\n',stderr);
- X show_output();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"tit$le")) {
- X (void) putc('\n',stderr);
- X show_title();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"xl$abel")) {
- X (void) putc('\n',stderr);
- X show_xlabel();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"yl$abel")) {
- X (void) putc('\n',stderr);
- X show_ylabel();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"la$bel")) {
- X struct value a;
- X int tag = 0;
- X
- X c_token++;
- X if (!END_OF_COMMAND) {
- X tag = (int)real(const_express(&a));
- X if (tag <= 0)
- X int_error("tag must be > zero", c_token);
- X }
- X
- X (void) putc('\n',stderr);
- X show_label(tag);
- X }
- X else if (almost_equals(c_token,"g$rid")) {
- X (void) putc('\n',stderr);
- X show_grid();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"k$ey")) {
- X (void) putc('\n',stderr);
- X show_key();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"p$lot")) {
- X (void) putc('\n',stderr);
- X show_plot();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"pol$ar")) {
- X (void) putc('\n',stderr);
- X show_polar();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"ti$cs")) {
- X (void) putc('\n',stderr);
- X show_tics(TRUE, TRUE);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"xti$cs")) {
- X show_tics(TRUE, FALSE);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"yti$cs")) {
- X show_tics(FALSE, TRUE);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"sa$mples")) {
- X (void) putc('\n',stderr);
- X show_samples();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"si$ze")) {
- X (void) putc('\n',stderr);
- X show_size();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"t$erminal")) {
- X (void) putc('\n',stderr);
- X show_term();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"v$ariables")) {
- X show_variables();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"ve$rsion")) {
- X show_version();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"xr$ange")) {
- X (void) putc('\n',stderr);
- X show_range('x',xmin,xmax);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"yr$ange")) {
- X (void) putc('\n',stderr);
- X show_range('y',ymin,ymax);
- X c_token++;
- X }
- X else if (almost_equals(c_token,"z$ero")) {
- X (void) putc('\n',stderr);
- X show_zero();
- X c_token++;
- X }
- X else if (almost_equals(c_token,"a$ll")) {
- X c_token++;
- X show_version();
- X show_autoscale();
- X show_clip();
- X (void) fprintf(stderr,"\tdummy variable is %s\n",dummy_var);
- X show_format();
- X show_style("data",data_style);
- X show_style("functions",func_style);
- X show_grid();
- X show_label(0);
- X show_arrow(0);
- X show_key();
- X show_logscale();
- X show_offsets();
- X show_output();
- X show_polar();
- X show_samples();
- X show_size();
- X show_term();
- X show_tics(TRUE,TRUE);
- X show_range('x',xmin,xmax);
- X show_range('y',ymin,ymax);
- X show_title();
- X show_xlabel();
- X show_ylabel();
- X show_zero();
- X show_plot();
- X show_variables();
- X show_functions();
- X c_token++;
- X }
- X else
- X int_error(
- X "valid show options: 'action_table', 'all', 'arrow', 'autoscale', \n\
- X 'clip', 'data', 'dummy', 'format', 'function', 'grid', 'key', 'label', \n\
- X 'logscale', 'offsets', 'output', 'plot', 'polar', 'samples', \n\
- X 'size', 'terminal', 'tics', 'title', 'variables', 'version', \n\
- X 'xlabel', 'xrange', 'xtics', 'ylabel', 'yrange', 'ytics', 'zero'", c_token);
- X screen_ok = FALSE;
- X (void) putc('\n',stderr);
- X}
- X
- X
- X/*********** support functions for 'show' **********/
- Xstatic void
- Xshow_style(name,style)
- Xchar name[];
- Xenum PLOT_STYLE style;
- X{
- X fprintf(stderr,"\t%s are plotted with ",name);
- X switch (style) {
- X case LINES: fprintf(stderr,"lines\n"); break;
- X case POINTS: fprintf(stderr,"points\n"); break;
- X case IMPULSES: fprintf(stderr,"impulses\n"); break;
- X case LINESPOINTS: fprintf(stderr,"linespoints\n"); break;
- X }
- X}
- X
- Xstatic void
- Xshow_range(name,min,max)
- Xchar name;
- Xdouble min,max;
- X{
- X fprintf(stderr,"\t%crange is [%g : %g]\n",name,min,max);
- X}
- X
- Xstatic void
- Xshow_zero()
- X{
- X fprintf(stderr,"\tzero is %g\n",zero);
- X}
- X
- Xstatic void
- Xshow_offsets()
- X{
- X fprintf(stderr,"\toffsets are %g, %g, %g, %g\n",loff,roff,toff,boff);
- X}
- X
- Xstatic void
- Xshow_output()
- X{
- X fprintf(stderr,"\toutput is sent to %s\n",outstr);
- X}
- X
- Xstatic void
- Xshow_samples()
- X{
- X fprintf(stderr,"\tsampling rate is %d\n",samples);
- X}
- X
- Xstatic void
- Xshow_size()
- X{
- X fprintf(stderr,"\tsize is scaled by %g,%g\n",xsize,ysize);
- X}
- X
- Xstatic void
- Xshow_title()
- X{
- X fprintf(stderr,"\ttitle is \"%s\"\n",title);
- X}
- X
- Xstatic void
- Xshow_xlabel()
- X{
- X fprintf(stderr,"\txlabel is \"%s\"\n",xlabel);
- X}
- X
- Xstatic void
- Xshow_ylabel()
- X{
- X fprintf(stderr,"\tylabel is \"%s\"\n",ylabel);
- X}
- X
- Xstatic void
- Xshow_label(tag)
- X int tag; /* 0 means show all */
- X{
- X struct text_label *this_label;
- X BOOLEAN showed = FALSE;
- X
- X for (this_label = first_label; this_label != NULL;
- X this_label = this_label->next) {
- X if (tag == 0 || tag == this_label->tag) {
- X showed = TRUE;
- X fprintf(stderr,"\tlabel %d \"%s\" at %g,%g ",
- X this_label->tag, this_label->text,
- X this_label->x, this_label->y);
- X switch(this_label->pos) {
- X case LEFT : {
- X fprintf(stderr,"left");
- X break;
- X }
- X case CENTRE : {
- X fprintf(stderr,"centre");
- X break;
- X }
- X case RIGHT : {
- X fprintf(stderr,"right");
- X break;
- X }
- X }
- X fputc('\n',stderr);
- X }
- X }
- X if (tag > 0 && !showed)
- X int_error("label not found", c_token);
- X}
- X
- Xstatic void
- Xshow_arrow(tag)
- X int tag; /* 0 means show all */
- X{
- X struct arrow_def *this_arrow;
- X BOOLEAN showed = FALSE;
- X
- X for (this_arrow = first_arrow; this_arrow != NULL;
- X this_arrow = this_arrow->next) {
- X if (tag == 0 || tag == this_arrow->tag) {
- X showed = TRUE;
- X fprintf(stderr,"\tarrow %d from %g,%g to %g,%g\n",
- X this_arrow->tag,
- X this_arrow->sx, this_arrow->sy,
- X this_arrow->ex, this_arrow->ey);
- X }
- X }
- X if (tag > 0 && !showed)
- X int_error("arrow not found", c_token);
- X}
- X
- Xstatic void
- Xshow_grid()
- X{
- X fprintf(stderr,"\tgrid is %s\n",(grid)? "ON" : "OFF");
- X}
- X
- Xstatic void
- Xshow_key()
- X{
- X switch (key) {
- X case -1 :
- X fprintf(stderr,"\tkey is ON\n");
- X break;
- X case 0 :
- X fprintf(stderr,"\tkey is OFF\n");
- X break;
- X case 1 :
- X fprintf(stderr,"\tkey is at %g,%g\n",key_x,key_y);
- X break;
- X }
- X}
- X
- Xstatic void
- Xshow_polar()
- X{
- X fprintf(stderr,"\tpolar is %s\n",(polar)? "ON" : "OFF");
- X}
- X
- Xstatic void
- Xshow_tics(showx, showy)
- X BOOLEAN showx, showy;
- X{
- X fprintf(stderr,"\ttics are %s\n",(tic_in)? "IN" : "OUT");
- X
- X if (showx)
- X show_ticdef(xtics, 'x', &xticdef);
- X if (showy)
- X show_ticdef(ytics, 'y', &yticdef);
- X screen_ok = FALSE;
- X}
- X
- X/* called by show_tics */
- Xstatic void
- Xshow_ticdef(tics, axis, tdef)
- X BOOLEAN tics; /* xtics or ytics */
- X char axis; /* 'x' or 'y' */
- X struct ticdef *tdef; /* xticdef or yticdef */
- X{
- X register struct ticmark *t;
- X
- X fprintf(stderr, "\t%c-axis tic labelling is ", axis);
- X if (!tics) {
- X fprintf(stderr, "OFF\n");
- X return;
- X }
- X
- X switch(tdef->type) {
- X case TIC_COMPUTED: {
- X fprintf(stderr, "computed automatically\n");
- X break;
- X }
- X case TIC_SERIES: {
- X if (tdef->def.series.end == VERYLARGE)
- X fprintf(stderr, "series from %g by %g\n",
- X tdef->def.series.start, tdef->def.series.incr);
- X else
- X fprintf(stderr, "series from %g by %g until %g\n",
- X tdef->def.series.start, tdef->def.series.incr,
- X tdef->def.series.end);
- X break;
- X }
- X case TIC_USER: {
- X fprintf(stderr, "list (");
- X for (t = tdef->def.user; t != NULL; t=t->next) {
- X if (t->label)
- X fprintf(stderr, "\"%s\" ", t->label);
- X if (t->next)
- X fprintf(stderr, "%g, ", t->position);
- X else
- X fprintf(stderr, "%g", t->position);
- X }
- X fprintf(stderr, ")\n");
- X break;
- X }
- X default: {
- X int_error("unknown ticdef type in show_ticdef()", NO_CARET);
- X /* NOTREACHED */
- X }
- X }
- X}
- X
- Xstatic void
- Xshow_term()
- X{
- X fprintf(stderr,"\tterminal type is %s\n",term_tbl[term].name);
- X}
- X
- Xstatic void
- Xshow_plot()
- X{
- X fprintf(stderr,"\tlast plot command was: %s\n",replot_line);
- X}
- X
- Xstatic void
- Xshow_autoscale()
- X{
- X fprintf(stderr,"\tx autoscaling is %s\n",(autoscale_x)? "ON" : "OFF");
- X fprintf(stderr,"\ty autoscaling is %s\n",(autoscale_y)? "ON" : "OFF");
- X}
- X
- Xstatic void
- Xshow_clip()
- X{
- X fprintf(stderr,"\tpoint clip is %s\n",(clip_points)? "ON" : "OFF");
- X
- X if (clip_lines1)
- X fprintf(stderr,
- X "\tdrawing and clipping lines between inrange and outrange points\n");
- X else
- X fprintf(stderr,
- X "\tnot drawing lines between inrange and outrange points\n");
- X
- X if (clip_lines2)
- X fprintf(stderr,
- X "\tdrawing and clipping lines between two outrange points\n");
- X else
- X fprintf(stderr,
- X "\tnot drawing lines between two outrange points\n");
- X}
- X
- Xstatic void
- Xshow_format()
- X{
- X fprintf(stderr, "\tx-axis tic format is \"%s\"\n", xformat);
- X fprintf(stderr, "\ty-axis tic format is \"%s\"\n", yformat);
- X}
- X
- Xstatic void
- Xshow_logscale()
- X{
- X if (log_x && log_y)
- X fprintf(stderr,"\tlogscaling both x and y axes\n");
- X else if (log_x)
- X fprintf(stderr,"\tlogscaling x axis\n");
- X else if (log_y)
- X fprintf(stderr,"\tlogscaling y axis\n");
- X else
- X fprintf(stderr,"\tno logscaling\n");
- X}
- X
- Xstatic void
- Xshow_variables()
- X{
- Xregister struct udvt_entry *udv = first_udv;
- Xint len;
- X
- X fprintf(stderr,"\n\tVariables:\n");
- X while (udv) {
- X len = instring(udv->udv_name, ' ');
- X fprintf(stderr,"\t%-*s ",len,udv->udv_name);
- X if (udv->udv_undef)
- X fputs("is undefined\n",stderr);
- X else {
- X fputs("= ",stderr);
- X disp_value(stderr,&(udv->udv_value));
- X (void) putc('\n',stderr);
- X }
- X udv = udv->next_udv;
- X }
- X}
- X
- Xvoid /* used by plot.c */
- Xshow_version()
- X{
- Xextern char version[];
- Xextern char patchlevel[];
- Xextern char date[];
- Xextern char bug_email[];
- Xstatic char *authors[] = {"Thomas Williams","Colin Kelley"}; /* primary */
- Xint x;
- Xlong time();
- X
- X x = time((long *)NULL) & 1;
- X fprintf(stderr,"\n\t%s\n\t%sversion %s\n",
- X PROGRAM, OS, version);
- X fprintf(stderr,"\tpatchlevel %s\n",patchlevel);
- X fprintf(stderr, "\tlast modified %s\n", date);
- X fprintf(stderr,"\tCopyright (C) 1986, 1987, 1990 %s, %s\n",
- X authors[x],authors[1-x]);
- X#ifdef __TURBOC__
- X fprintf(stderr,"\tCreated using Turbo C, Copyright Borland 1987, 1988\n");
- X#endif
- X fprintf(stderr, "\n\tSend bugs and comments to %s\n", bug_email);
- X}
- *-*-END-of-setshow.c-*-*
- exit
-
-
-