home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 October / usenetsourcesnewsgroupsinfomagicoctober1994disk2.iso / misc / volume8 / gnuplot1.10A / part04 / plot.c next >
Encoding:
C/C++ Source or Header  |  1989-09-09  |  5.3 KB  |  201 lines

  1. /*
  2.  *
  3.  *    G N U P L O T  --  plot.c
  4.  *
  5.  *  Copyright (C) 1986, 1987  Thomas Williams, Colin Kelley
  6.  *
  7.  *  You may use this code as you wish if credit is given and this message
  8.  *  is retained.
  9.  *
  10.  *  Please e-mail any useful additions to vu-vlsi!plot so they may be
  11.  *  included in later releases.
  12.  *
  13.  *  This file should be edited with 4-column tabs!  (:set ts=4 sw=4 in vi)
  14.  *
  15.  *  The Turbo C code was supplied by William E Wilson, 1988-1989
  16.  *
  17.  */
  18.  
  19. #include <stdio.h>
  20. #include <setjmp.h>
  21. #include <signal.h>
  22. #include "plot.h"
  23.  
  24. /* on some compilers (Turbo C) interrupt is a reserved word */
  25. #ifdef MSDOS               
  26. #define interrupt intrrtn  /*something different*/
  27. #endif
  28.  
  29. char *getenv(),*strcat(),*strcpy(),*strncpy();
  30.  
  31. extern char input_line[];
  32. extern FILE *outfile;
  33. extern int term;
  34. extern struct termentry term_tbl[];
  35.  
  36. #ifndef STDOUT
  37. #define STDOUT 1
  38. #endif
  39.  
  40. jmp_buf env;
  41.  
  42. struct value *integer(),*complex();
  43.  
  44.  
  45. extern f_push(),f_pushc(),f_pushd(),f_call(),f_lnot(),f_bnot(),f_uminus()
  46.         ,f_lor(),f_land(),f_bor(),f_xor(),f_band(),f_eq(),f_ne(),f_gt(),f_lt(),
  47.         f_ge(),f_le(),f_plus(),f_minus(),f_mult(),f_div(),f_mod(),f_power(),
  48.         f_factorial(),f_bool(),f_jump(),f_jumpz(),f_jumpnz(),f_jtern();
  49.  
  50. extern f_real(),f_imag(),f_arg(),f_conjg(),f_sin(),f_cos(),f_tan(),f_asin(),
  51.         f_acos(),f_atan(),f_sinh(),f_cosh(),f_tanh(),f_int(),f_abs(),f_sgn(),
  52.         f_sqrt(),f_exp(),f_log10(),f_log(),f_besj0(),f_besj1(),f_besy0(),f_besy1(),
  53. #ifdef GAMMA
  54.         f_gamma(),
  55. #endif
  56.         f_floor(),f_ceil();
  57.  
  58.  
  59. struct ft_entry ft[] = {        /* built-in function table */
  60.  
  61. /* internal functions: */
  62.         {"push", f_push},       {"pushc", f_pushc},     {"pushd", f_pushd},
  63.         {"call", f_call},       {"lnot", f_lnot},       {"bnot", f_bnot},
  64.         {"uminus", f_uminus},                                   {"lor", f_lor},
  65.         {"land", f_land},       {"bor", f_bor},         {"xor", f_xor},
  66.         {"band", f_band},       {"eq", f_eq},           {"ne", f_ne},
  67.         {"gt", f_gt},           {"lt", f_lt},           {"ge", f_ge},
  68.         {"le", f_le},           {"plus", f_plus},       {"minus", f_minus},
  69.         {"mult", f_mult},       {"div", f_div},         {"mod", f_mod},
  70.         {"power", f_power}, {"factorial", f_factorial},
  71.         {"bool", f_bool},       {"jump", f_jump},       {"jumpz", f_jumpz},
  72.         {"jumpnz",f_jumpnz},{"jtern", f_jtern},
  73.  
  74. /* standard functions: */
  75.         {"real", f_real},       {"imag", f_imag},       {"arg", f_arg},
  76.         {"conjg", f_conjg}, {"sin", f_sin},             {"cos", f_cos},
  77.         {"tan", f_tan},         {"asin", f_asin},       {"acos", f_acos},
  78.         {"atan", f_atan},       {"sinh", f_sinh},       {"cosh", f_cosh},
  79.         {"tanh", f_tanh},       {"int", f_int},         {"abs", f_abs},
  80.         {"sgn", f_sgn},         {"sqrt", f_sqrt},       {"exp", f_exp},
  81.         {"log10", f_log10},     {"log", f_log},         {"besj0", f_besj0},
  82.         {"besj1", f_besj1},     {"besy0", f_besy0},     {"besy1", f_besy1},
  83. #ifdef GAMMA
  84.         {"gamma", f_gamma},
  85. #endif
  86.         {"floor", f_floor},     {"ceil", f_ceil},
  87.         {NULL, NULL}
  88. };
  89.  
  90. static struct udvt_entry udv_pi = {NULL, "pi",FALSE};
  91. /* first in linked list */
  92. struct udvt_entry *first_udv = &udv_pi;
  93. struct udft_entry *first_udf = NULL;
  94.  
  95.  
  96.  
  97. #ifdef vms
  98.  
  99. #define HOME "sys$login:"
  100.  
  101. #else /* vms */
  102. #ifdef MSDOS
  103.  
  104. #define HOME "GNUPLOT"
  105.  
  106. #else /* MSDOS */
  107.  
  108. #define HOME "HOME"
  109.  
  110. #endif /* MSDOS */
  111. #endif /* vms */
  112.  
  113. #ifdef unix
  114. #define PLOTRC ".gnuplot"
  115. #else
  116. #define PLOTRC "gnuplot.ini"
  117. #endif
  118.  
  119.  
  120. #ifdef __TURBOC__
  121. void interrupt()
  122. #else
  123. interrupt()
  124. #endif
  125. {
  126. #ifdef MSDOS
  127. #ifdef __TURBOC__
  128.   (void) signal(SIGINT, interrupt);
  129. #else
  130.     void ss_interrupt();
  131.     (void) signal(SIGINT, ss_interrupt);
  132. #endif
  133. #else
  134.     (void) signal(SIGINT, interrupt);
  135. #endif
  136.     (void) signal(SIGFPE, SIG_DFL);    /* turn off FPE trapping */
  137.     if (term)
  138.         (*term_tbl[term].text)();    /* hopefully reset text mode */
  139.     (void) fflush(outfile);
  140.     (void) putc('\n',stderr);
  141.     longjmp(env, TRUE);        /* return to prompt */
  142. }
  143.  
  144.  
  145. main()
  146. {
  147. register FILE *plotrc;
  148. register char *gnuterm=NULL;
  149. static char home[sizeof(PLOTRC)+80];
  150.  
  151.     setbuf(stderr,(char *)NULL);
  152. #ifdef VMS
  153.     outfile = stdout; /* never close stdout--even if duped. */
  154. #else
  155.     outfile = fdopen(dup(STDOUT),"w");
  156. #endif
  157.     (void) complex(&udv_pi.udv_value, Pi, 0.0);
  158.     show_version();
  159.     init();  /* Can set term if it wishes. */
  160.  
  161. /* thanks to osupyr!alden (Dave Alden) for the GNUTERM code */
  162.  
  163.     if (!(gnuterm = getenv("GNUTERM")) && term == 0)
  164.         gnuterm = TERM;
  165.     if (gnuterm != NULL)
  166.         (void) strcat(input_line,gnuterm); /* input_line has "set term " */
  167.     else
  168.         input_line[0] = '\0';   /* No SET TERM command needed. */
  169.  
  170.     if (!setjmp(env))                /* come back here from printerror() */
  171.         do_line();
  172.  
  173.     if (!setjmp(env)) {
  174. #ifdef MSDOS 
  175. #ifdef __TURBOC__
  176.         (void) signal(SIGINT, interrupt);    /* go there on interrupt char */
  177. #else
  178.         void ss_interrupt();
  179.         save_stack();                /* work-around for MSC 4.0/MSDOS 3.x bug */
  180.         (void) signal(SIGINT, ss_interrupt);
  181. #endif
  182. #else /* MSDOS */
  183.         (void) signal(SIGINT, interrupt);    /* go there on interrupt char */
  184. #endif /* MSDOS */
  185.         if (!(plotrc = (fopen(PLOTRC,"r")))) {
  186. #ifdef vms
  187.             (void) strncpy(home,HOME,sizeof(home));
  188.             plotrc = fopen(strcat(home,PLOTRC),"r");
  189. #else /* vms */
  190.             (void) strcat(strncpy(home,getenv(HOME),sizeof(home)),"/");
  191.             plotrc = fopen(strcat(home,PLOTRC),"r");
  192. #endif /* vms */
  193.         }
  194.         if (plotrc)
  195.             load_file(plotrc);
  196.     }
  197.  
  198. loop:    com_line();
  199.         goto loop;
  200. }
  201.