home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume26 / psgraph / part01 / input.c next >
Encoding:
C/C++ Source or Header  |  1992-09-06  |  11.0 KB  |  369 lines

  1. /* $Header: input.c,v 1.9 92/08/04 17:55:05 mogul Exp $ */
  2.  
  3. /*
  4.  *               Copyright 1989, 1992 Digital Equipment Corporation
  5.  *                          All Rights Reserved
  6.  * 
  7.  * 
  8.  * Permission to use, copy, and modify this software and its documentation
  9.  * is hereby granted only under the following terms and conditions.  Both
  10.  * the above copyright notice and this permission notice must appear in
  11.  * all copies of the software, derivative works or modified versions, and
  12.  * any portions threof, and both notices must appear in supporting
  13.  * documentation.
  14.  * 
  15.  * Users of this software agree to the terms and conditions set forth
  16.  * herein, and hereby grant back to Digital a non-exclusive, unrestricted,
  17.  * royalty-free right and license under any changes, enhancements or
  18.  * extensions made to the core functions of the software, including but
  19.  * not limited to those affording compatibility with other hardware or
  20.  * software environments, but excluding applications which incorporate
  21.  * this software.  Users further agree to use their best efforts to return
  22.  * to Digital any such changes, enhancements or extensions that they make
  23.  * and inform Digital of noteworthy uses of this software.  Correspondence
  24.  * should be provided to Digital at:
  25.  * 
  26.  *                       Director of Licensing
  27.  *                       Western Research Laboratory
  28.  *                       Digital Equipment Corporation
  29.  *                       250 University Avenue
  30.  *                       Palo Alto, California  94301  
  31.  * 
  32.  * This software may be distributed (but not offered for sale or
  33.  * transferred for compensation) to third parties, provided such third
  34.  * parties agree to abide by the terms and conditions of this notice.
  35.  * 
  36.  * THE SOFTWARE IS PROVIDED "AS IS" AND DIGITAL EQUIPMENT CORP. DISCLAIMS
  37.  * ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED
  38.  * WARRANTIES OF MERCHANTABILITY AND FITNESS.   IN NO EVENT SHALL DIGITAL
  39.  * EQUIPMENT CORPORATION BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR
  40.  * CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF
  41.  * USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR
  42.  * OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR
  43.  * PERFORMANCE OF THIS SOFTWARE.
  44.  */
  45.  
  46. /* 
  47.  * input.c - Read and parse command and data input
  48.  * 
  49.  * Author:    Christopher A. Kent
  50.  *         Western Research Laboratory
  51.  *         Digital Equipment Corporation
  52.  * Date:    Wed Jan  4 1989
  53.  */
  54.  
  55. /*
  56.  * $Log:    input.c,v $
  57.  * Revision 1.9  92/08/04  17:55:05  mogul
  58.  * undo RCS botch
  59.  * 
  60.  * Revision 1.8  1992/04/03  23:55:47  kent
  61.  * Fixed a problem where "include" reset the world.
  62.  *
  63.  * Revision 1.7  1992/04/01  23:27:34  kent
  64.  * Added datalabel verb, fixed a bug in handling blank input lines.
  65.  *
  66.  * Revision 1.6  1992/03/31  23:13:12  kent
  67.  * Added "dataticks" verb.
  68.  *
  69.  * Revision 1.5  1992/03/31  02:31:34  kent
  70.  * Added markergray verb and fixed inverted gray values.
  71.  *
  72.  * Revision 1.4  1992/03/31  00:21:29  kent
  73.  * Added "include" verb
  74.  *
  75.  * Revision 1.3  1992/03/31  00:07:39  kent
  76.  * Added markerscale verb.
  77.  *
  78.  * Revision 1.2  1992/03/30  23:33:47  kent
  79.  * Added halfopen, halfticks grid styles, range frames, and gray.
  80.  *
  81.  * Revision 1.1  1992/03/20  21:25:43  kent
  82.  * Initial revision
  83.  *
  84.  * Revision 1.7  92/02/21  17:13:21  mogul
  85.  * Added Digital license info
  86.  * 
  87.  * Revision 1.6  90/12/11  20:41:26  reid
  88.  * Added code to parse input for new "color" and "linewidth" commands
  89.  * 
  90.  * Revision 1.5  89/01/10  18:19:57  kent
  91.  * Moved marker code to prolog, added error checking and messages.
  92.  * 
  93.  * Revision 1.4  89/01/09  22:18:41  kent
  94.  * Added log scales.
  95.  * 
  96.  * Revision 1.3  89/01/04  17:30:27  kent
  97.  * Made command line arguments override compiled-in defaults for
  98.  * all plots in a run, not just the first one. 
  99.  * 
  100.  * Revision 1.2  89/01/04  15:22:03  kent
  101.  * Massive renaming. No functional change.
  102.  * 
  103.  * Revision 1.1  89/01/04  13:57:49  kent
  104.  * Initial revision
  105.  * 
  106.  */
  107.  
  108. static char rcs_ident[] = "$Header: input.c,v 1.9 92/08/04 17:55:05 mogul Exp $";
  109.  
  110. #include <stdio.h>
  111.  
  112. #include "psgraph.h"
  113.  
  114. /*
  115.  * Read the input consisting of both numeric and text data.  An array, Token[*]
  116.  * is built by this routine containing both numeric (type==POINT) and non-numeric
  117.  * data.  Only the commands that take affect at a point relative to their
  118.  * appearence in the input are placed in the Token array.  All others just
  119.  * affect global data.
  120.  */
  121.  
  122. doinput(s)
  123.     FILE *s;
  124. {
  125.     char *argv[ARGC];
  126.     int argc;
  127.     char buf[BUFSIZ], cmd[BUFSIZ];
  128.  
  129.     for(;;) {
  130.         if ( NumTokens >= SizeofToken ) {
  131.             SizeofToken += TOKENINC;
  132.             Token = (token_t *)realloc((char *)Token,(unsigned)(SizeofToken*sizeof(token_t)));
  133.         }
  134.         if( fgets(buf, BUFSIZ, s) == NULL )
  135.             break;
  136.         if ( strlen(buf)==0 || *buf=='#' || buf[0]=='\n')
  137.             continue;
  138.         strcpy(cmd,buf);
  139.         parse(cmd,&argc,argv);
  140. #ifdef DEBUG
  141.         if ( Debug ) {
  142.             fprintf(stderr,"argc=%d, ",argc);
  143.             fprintf(stderr,"input=%s\n",buf);
  144.         }
  145. #endif
  146.         if ( isalpha(argv[0][0]) ) {
  147.             if ( docmd(argc,argv) )
  148.                 fprintf(stderr,"Error in input: %s\n",buf);
  149.         } else {
  150.             Token[NumTokens].type = POINT;
  151.             Token[NumTokens].xval = atof(argv[0]);
  152.             Token[NumTokens].yval = 0.0;
  153.             if ( argc > 1 ) Token[NumTokens].yval = atof(argv[1]);
  154.             if ( argc > 2 )
  155.                 Token[NumTokens].label = newstr(argv[2]);
  156.             else
  157.                 Token[NumTokens].label = NULL;
  158.             NumTokens++;
  159.         }
  160.     }
  161. }
  162.  
  163. docmd(argc,argv)
  164. int argc;
  165. char *argv[];
  166. {
  167.         FILE *f;
  168.     
  169.     if ( strcmp(argv[0],"break")==0 ) {
  170.         Token[NumTokens].type = BREAK;
  171.         NumTokens++;
  172.     } else if ( strcmp(argv[0],"include")==0 ) {
  173.             if ( argc > 1 ) {
  174.             f = fopen(argv[1], "r");
  175.             if (f != NULL)
  176.             doinput(f);
  177.         }
  178.     } else if ( strcmp(argv[0],"line")==0 ) {
  179.         Token[NumTokens].type = LINETYPE;
  180.         if ( argc > 1 )
  181.             Token[NumTokens].label = newstr(argv[1]);
  182.         else
  183.             Token[NumTokens].label = NULL;
  184.         NumTokens++;
  185.     } else if ( strcmp(argv[0],"color")==0 ) {
  186.         Token[NumTokens].type = LINECOLOR;
  187.         if ( argc > 1 )
  188.             Token[NumTokens].label = newstr(argv[1]);
  189.         else
  190.             Token[NumTokens].label = NULL;
  191.         NumTokens++;
  192.     } else if ( strcmp(argv[0],"linewidth")==0 ) {
  193.         Token[NumTokens].type = LINEWIDTH;
  194.         if ( argc > 1 )
  195.             Token[NumTokens].label = newstr(argv[1]);
  196.         else
  197.             Token[NumTokens].label = "0.6";
  198.         NumTokens++;
  199.     } else if ( strcmp(argv[0],"spline")==0 ) {
  200.         Token[NumTokens].type = SPLINE;
  201.         NumTokens++;
  202.     } else if ( strcmp(argv[0],"label")==0 )
  203.         DoAxisLabels = TRUE;
  204.     else if ( strcmp(argv[0],"nolabel")==0 )
  205.         DoAxisLabels = FALSE;
  206.     else if ( strcmp(argv[0],"transparent")==0 ) {
  207.         Token[NumTokens].type = TRANS;
  208.         Token[NumTokens].ival = TRUE;
  209.         NumTokens++;
  210.     } else if ( strcmp(argv[0],"notransparent")==0 ) {
  211.         Token[NumTokens].type = TRANS;
  212.         Token[NumTokens].ival = FALSE;
  213.         NumTokens++;
  214.     } else if ( strcmp(argv[0],"grid")==0 ) {
  215.         Xaxis.gridtype = Yaxis.gridtype = gridval(argv[1]);
  216.         if (Xaxis.gridtype == HALFOPEN) {
  217.             Xaxis.gridtype = Yaxis.gridtype = OPEN;
  218.             Xaxis.halfgrid = Yaxis.halfgrid = TRUE;
  219.         }
  220.         if (Xaxis.gridtype == HALFTICKS) {
  221.             Xaxis.gridtype = Yaxis.gridtype = TICKS;
  222.             Xaxis.halfgrid = Yaxis.halfgrid = TRUE;
  223.         }
  224.     } else if ( strncmp(argv[0],"datatick",8)==0 ) {
  225.             Xaxis.datatick = Yaxis.datatick = TRUE;
  226.     } else if ( strncmp(argv[0],"datalabel",9)==0 ) {
  227.             Xaxis.datalabel = Yaxis.datalabel = TRUE;
  228.     } else if ( strcmp(argv[0],"tickgray")==0 )
  229.         Xaxis.tickgray = Yaxis.tickgray = 1.0 - atof(argv[1])/100.0;
  230.     else if ( strcmp(argv[0],"axisgray")==0 )
  231.         Xaxis.axisgray = Yaxis.axisgray = 1.0 - atof(argv[1])/100.0;
  232.     else if ( strcmp(argv[0],"title")==0 ) {
  233.           if (argc > 1) 
  234.             Title.title = newstr(argv[1]);
  235.         else 
  236.             Title.title = "";
  237.     } else if ( strcmp(argv[0],"titlefont")==0 )
  238.         Title.font = newstr(argv[1]);
  239.     else if ( strncmp(argv[0],"tick", 4)==0 ) {
  240.         TickLen = Tick2Len = atof(argv[1]);
  241.         if ( argc > 2 )
  242.             Tick2Len = atof(argv[2]);
  243.     } else if ( strcmp(argv[0], "clip")==0 ) {
  244.         if ( argc > 1 )
  245.             ClipDist = atof(argv[1]);
  246.     } else if ( strcmp(argv[0],"width")==0 )
  247.         Xaxis.size = atof(argv[1]);
  248.     else if ( strcmp(argv[0],"height")==0 )
  249.         Yaxis.size = atof(argv[1]);
  250.     else if ( strcmp(argv[0],"rangeframe")==0 )
  251.             Xaxis.rangeframe = Yaxis.rangeframe = TRUE;
  252.     else if ( strcmp(argv[0],"center")==0 )
  253.         Xcenter = atof(argv[1]);
  254.     else if ( strcmp(argv[0],"marker")==0 ) {
  255.         if ( argc > 1 ) {
  256.             Token[NumTokens].type = MARKER;
  257.             Token[NumTokens].label = newstr(argv[1]);
  258.             NumTokens++;
  259.         }
  260.     } else if ( strcmp(argv[0],"markerscale")==0 ) {
  261.             if ( argc > 1 ) {
  262.             Token[NumTokens].type = MARKERSCALE;
  263.             Token[NumTokens].val[0] = atof(argv[1]);
  264.             NumTokens++;
  265.         }
  266.     } else if ( strcmp(argv[0],"markergray")==0 ) {
  267.             if ( argc > 1 ) {
  268.             Token[NumTokens].type = MARKERGRAY;
  269.             Token[NumTokens].val[0] = 1.0 - atof(argv[1])/100.0;
  270.             NumTokens++;
  271.         }
  272.     } else if ( strcmp(argv[0],"x")==0 )
  273.         return domods(argc, argv, &Xaxis);
  274.     else if ( strcmp(argv[0],"y")==0 )
  275.         return domods(argc, argv, &Yaxis);
  276.     else if ( strcmp(argv[0],"font")==0 ) {
  277.         Token[NumTokens].type = FONT;
  278.         if (argc > 1)
  279.             Token[NumTokens].label = newstr(argv[1]);
  280.         else
  281.             Token[NumTokens].label = NULL;
  282.         NumTokens++;
  283.     } else
  284.         return TRUE;
  285.     return FALSE;
  286. }
  287. /*
  288.  * domods - parse and handle input lines for making modifications to
  289.  * x & y argument structure.
  290.  *
  291.  * The input lines handled by this module are
  292.  *
  293.  *    x options
  294.  *
  295.  * where "options" is one or more of the following
  296.  *
  297.  *    intervals N
  298.  *    log
  299.  *    min N
  300.  *    max N
  301.  *    rangeframe
  302.  *    step N
  303.  *    tick N
  304.  *    size N
  305.  *    offset N
  306.  *    label "foo"
  307.  *    grid {none,open,ticks,full,halfopen,halfticks}
  308.  *    words
  309.  *    font "foo"
  310.  */
  311.  
  312. domods(argc, argv, p)
  313. int argc;
  314. char *argv[];
  315. axis_t *p;
  316. {
  317.     int arg;
  318.     for ( arg=1 ; arg<argc ; arg++ ) {
  319.         if (strcmp(argv[arg], "intervals") == 0)
  320.             p->intervals = atoi(argv[++arg]);
  321.         else if ( strcmp(argv[arg],"log")==0 )
  322.             p->tform = LOG10;
  323.         else if ( strcmp(argv[arg],"min")==0 ) {
  324.             p->minflag = TRUE;
  325.             p->gmin = atof(argv[++arg]);
  326.         } else if ( strcmp(argv[arg],"max")==0 ) {
  327.             p->maxflag = TRUE;
  328.             p->gmax = atof(argv[++arg]);
  329.         } else if ( strcmp(argv[arg],"step")==0 ) {
  330.             p->distf = TRUE;
  331.             p->dist = atof(argv[++arg]);
  332.         } else if ( strncmp(argv[arg],"tick",4)==0 ) {
  333.             p->tickflag = TRUE;
  334.             p->tick = atof(argv[++arg]);
  335.         } else if ( strcmp(argv[arg],"rangeframe")==0 ) {
  336.                 p->rangeframe = TRUE;
  337.         } else if ( strcmp(argv[arg],"offset")==0 ) {
  338.             p->offset = atof(argv[++arg]);
  339.         } else if ( strcmp(argv[arg],"label")== 0 ) {
  340.             p->label = newstr(argv[++arg]);
  341.         } else if ( strcmp(argv[arg],"font")== 0 ) {
  342.             p->font = newstr(argv[++arg]);
  343.         } else if ( strcmp(argv[arg],"size")== 0 ) {
  344.             p->size = atof(argv[++arg]);
  345.         } else if ( strcmp(argv[arg],"grid")==0 ) {
  346.             p->gridtype = gridval(argv[++arg]);
  347.             if (p->gridtype == HALFOPEN) { /* hack hack */
  348.                 p->gridtype = OPEN;
  349.                 p->halfgrid = TRUE;
  350.             }
  351.             if (p->gridtype == HALFTICKS) {
  352.                 p->gridtype = TICKS;
  353.                 p->halfgrid = TRUE;
  354.             }
  355.         } else if ( strncmp(argv[0],"datatick",8)==0 ) {
  356.                 p->datatick = TRUE;
  357.         } else if ( strncmp(argv[0],"datalabel",9)==0 ) {
  358.                 p->datalabel = TRUE;
  359.         } else if ( strcmp(argv[0],"tickgray")==0 )
  360.                 p->tickgray =  1.0 - atof(argv[++arg])/100.0;
  361.         else if ( strcmp(argv[0],"axisgray")==0 )
  362.                 p->axisgray = 1.0 - atof(argv[++arg])/100.0;
  363.         else
  364.             return TRUE;
  365.     }
  366.     return FALSE;
  367. }
  368.  
  369.