home *** CD-ROM | disk | FTP | other *** search
/ The C Users' Group Library 1994 August / wc-cdrom-cusersgrouplibrary-1994-08.iso / vol_300 / 334_02 / plot2.c < prev    next >
Text File  |  1991-02-05  |  3KB  |  118 lines

  1. /*
  2.  *
  3.  *    gnutex/gnuplot translator  --  plot.c
  4.  *
  5.  * By David Kotz, 1990.
  6.  * Department of Computer Science, Duke University, Durham, NC 27706.
  7.  * Mail to dfk@cs.duke.edu.
  8.  */
  9.  
  10. #include <stdio.h>
  11. #include <setjmp.h>
  12. #include <signal.h>
  13. #include "plot.h"
  14.  
  15. extern FILE *infile;
  16. extern FILE *outfile;
  17.  
  18. jmp_buf env;
  19.  
  20. struct value stack[STACK_DEPTH];
  21.  
  22. struct lexical_unit token[MAX_TOKENS];
  23.  
  24. struct value *integer(),*complex();
  25.  
  26. extern f_push(),f_pushc(),f_pushd(),f_call(),f_terniary(),f_lnot(),f_bnot(),
  27.     f_uminus(),f_lor(),f_land(),f_bor(),f_xor(),f_band(),f_eq(),f_ne(),
  28.     f_gt(),f_lt(),f_ge(),f_le(),f_plus(),f_minus(),f_mult(),f_div(),
  29.     f_mod(),f_power();
  30.  
  31. extern f_real(),f_imag(),f_arg(),f_conjg(),f_sin(),f_cos(),f_tan(),f_asin(),
  32.     f_acos(),f_atan(),f_sinh(),f_cosh(),f_tanh(),f_int(),f_abs(),f_sgn(),
  33.     f_sqrt(),f_exp(),f_log10(),f_log(),f_besj0(),f_besj1(),f_besy0(),f_besy1(),
  34.     f_floor(),f_ceil();
  35.     
  36.  
  37. struct ft_entry ft[] = {    /* built-in function table */
  38.  
  39. /* internal functions: */
  40.     {"push", f_push},    {"pushc", f_pushc},    {"pushd", f_pushd},
  41.     {"call", f_call},    {"?:", f_terniary},    {"lnot", f_lnot},
  42.     {"bnot", f_bnot},    {"uminus", f_uminus},    {"lor", f_lor},
  43.     {"land", f_land},    {"bor", f_bor},        {"xor", f_xor},
  44.     {"band", f_band},    {"eq", f_eq},        {"ne", f_ne},
  45.     {"gt", f_gt},        {"lt", f_lt},        {"ge", f_ge},
  46.     {"le", f_le},        {"plus", f_plus},    {"minus", f_minus},
  47.     {"mult", f_mult},    {"div", f_div},        {"mod", f_mod},
  48.     {"power", f_power},
  49.  
  50. /* standard functions: */
  51.     {"real", f_real},    {"imag", f_imag},    {"arg", f_arg},
  52.     {"conjg", f_conjg}, {"sin", f_sin},        {"cos", f_cos},
  53.     {"tan", f_tan},        {"asin", f_asin},    {"acos", f_acos},
  54.     {"atan", f_atan},    {"sinh", f_sinh},    {"cosh", f_cosh},
  55.     {"tanh", f_tanh},    {"int", f_int},        {"abs", f_abs},
  56.     {"sgn", f_sgn},        {"sqrt", f_sqrt},    {"exp", f_exp},
  57.     {"log10", f_log10},    {"log", f_log},        {"besj0", f_besj0},
  58.     {"besj1", f_besj1},    {"besy0", f_besy0},    {"besy1", f_besy1},
  59.     {"floor", f_floor},    {"ceil", f_ceil},     {NULL, NULL}
  60. };
  61.  
  62. struct udft_entry udft[MAX_UDFS+1];
  63.  
  64. struct vt_entry vt[MAX_VALUES] = {
  65.     {"pi"},            {"xmin"},        {"xmax"},
  66.     {"ymin"},         {"ymax"},        {"autoscale"}
  67. };
  68.  
  69. struct st_entry st[MAX_STYLES] = {
  70.     /* include the fixed styles by default */
  71.     /* These must match the positions in enum PLOT_STYLE */
  72.     {"lines"},         {"points"},        {"impulses"},        {"linespoints"},
  73.     {"dots"}
  74. };
  75. int next_style = FIXED_STYLES+1;
  76.  
  77. catch()                    /* interrupts */
  78. {
  79.     (void) signal(SIGFPE, SIG_DFL);    /* turn off FPE trapping */
  80.     (void) fflush(outfile);
  81.     (void) putc('\n',stderr);
  82.     longjmp(env, TRUE);        /* return to prompt */
  83. }
  84.  
  85.  
  86. main(argc, argv)
  87.     int argc;
  88.     char **argv;
  89. {
  90.     setbuf(stderr,NULL);
  91.  
  92.     if (argc == 3) {
  93.        infile = fopen(argv[1], "r");
  94.        if (infile == (FILE *)NULL) {
  95.           fprintf(stderr, "Cannot open '%s' for input\n", argv[1]);
  96.           exit(1);
  97.        }
  98.        outfile = fopen(argv[2], "w");
  99.        if (outfile == (FILE *)NULL) {
  100.           fprintf(stderr, "Cannot open '%s' for output\n", argv[2]);
  101.           exit(1);
  102.        }
  103.     } else {
  104.        fprintf(stderr, "usage: gnut2p infile outfile\n");
  105.        exit(2);
  106.     }
  107.  
  108.     (void) complex(&vt[(int)C_PI].vt_value, Pi, 0.0);
  109.  
  110.     setjmp(env);
  111.  
  112.     /* setting to some of the old defaults */
  113.     fprintf(outfile, "set noclip one; set noclip two; set clip points\n");
  114.  
  115.     while(TRUE)
  116.      com_line();
  117. }
  118.