home *** CD-ROM | disk | FTP | other *** search
/ Usenet 1994 January / usenetsourcesnewsgroupsinfomagicjanuary1994.iso / sources / unix / volume8 / graph+ / part03 / main.c < prev    next >
Encoding:
C/C++ Source or Header  |  1987-03-01  |  3.6 KB  |  166 lines

  1. /*
  2.  * Copyright (C) 1986   Alan Kent
  3.  *
  4.  * Permission is granted to freely distribute part or
  5.  * all of this code as long as it is not for profit
  6.  * and this message is retained in the code.
  7.  *
  8.  * No resposibility is taken for any damage or incorect
  9.  * results this program generates.
  10.  * 
  11.  */
  12.  
  13.  
  14. #include <stdio.h>
  15. #include <signal.h>
  16. #include "graph.h"
  17. #include "y.tab.h"
  18.  
  19. /* if not on cc line, use default */
  20. #ifndef GLOB_LIB
  21. #define GLOB_LIB "/usr/lib/graph+rc"
  22. #endif
  23.  
  24.  
  25. extern char *getenv ();
  26.  
  27.  
  28. extern char *PROG_NAME;
  29. extern int gargc;
  30. extern char **gargv;
  31. extern char *infilename;
  32. extern int linenum;
  33. extern axis_st xaxis;
  34. extern axis_st yaxis;
  35. extern int warnings;
  36. extern FILE *yyin;
  37. extern int horiz_legend;
  38. extern int vert_legend;
  39. extern int num_graphs;
  40.  
  41.  
  42. main ( argc , argv )
  43. int argc;
  44. char **argv;
  45. {
  46.     int float_exception ();
  47.  
  48.     char *home;
  49.     char buf[200];
  50.     FILE *fp;
  51.     int read_stdin;
  52.  
  53.  
  54.     signal ( SIGFPE , float_exception );
  55.     if ( argc < 1 ) {
  56.     fprintf ( stderr , "usage: %s [ commandfile | - ] [ parameter ... ]\n" , PROG_NAME );
  57.     exit ( 1 );
  58.     }
  59.  
  60.     warnings = 1;    /* should be an option */
  61.  
  62.     num_graphs = 0;
  63.     horiz_legend = RIGHT;
  64.     vert_legend = TOP;
  65.  
  66.     xaxis.format = yaxis.format = "%.1f";
  67.     xaxis.user_format = yaxis.user_format = NULL;
  68.     xaxis.label = yaxis.label = "";
  69.     xaxis.scale = yaxis.scale = AUTO;
  70.     xaxis.frame = yaxis.frame = GRID;
  71.     xaxis.linear = yaxis.linear = LINEAR;
  72.     xaxis.auto_tick_size = yaxis.auto_tick_size = 1;
  73.     xaxis.range.min = yaxis.range.min = 0.0;
  74.     xaxis.range.max = yaxis.range.max = -1.0;
  75.     xaxis.interval = yaxis.interval = NULL;
  76.  
  77.     pdef_fun ();
  78.     pdef_var ();
  79.     pdef_tab ();
  80.  
  81.     if ( ( fp = fopen ( GLOB_LIB , "r" ) ) != NULL ) {
  82.     yyin = fp;
  83.     linenum = 1;
  84.     infilename = GLOB_LIB;
  85.     yyparse ();
  86.     fclose ( yyin );
  87.     }
  88.  
  89.     if ( ( home = getenv ( "HOME" ) ) != NULL ) {
  90.     sprintf ( buf , "%s/.graph+rc" , home );
  91.     if ( ( fp = fopen ( buf , "r" ) ) != NULL ) {
  92.         yyin = fp;
  93.         linenum = 1;
  94.         infilename = buf;
  95.         yyparse ();
  96.         fclose ( yyin );
  97.     }
  98.     }
  99.  
  100.     read_stdin = ( argc < 2  ||  strcmp ( argv[1] , "-" ) == 0 );
  101.  
  102.     gargc = argc;
  103.     gargv = argv;
  104.  
  105.     if ( ! read_stdin ) {
  106.     if ( ( fp = fopen ( argv[1] , "r" ) ) == NULL ) {
  107.         fprintf ( stderr , "%s: failed to open command file '%s'\n" ,
  108.         PROG_NAME , argv[1] );
  109.         exit ( 1 );
  110.     }
  111.     yyin = fp;
  112.     infilename = argv[1];
  113.     linenum = 1;
  114.     }
  115.     else {
  116.     yyin = stdin;
  117.     infilename = "stdin";
  118.     linenum = 1;
  119.     }
  120.  
  121.     yyparse ();
  122.  
  123. }
  124.  
  125.  
  126. /* FOR VAX-11 ONLY - well, our vax anyway */
  127.  
  128. float_exception ( sig , code )
  129. int sig , code;
  130. {
  131.     switch ( code ) {
  132.  
  133. #ifdef FPE_INTOVF_TRAP 
  134.     case FPE_INTOVF_TRAP : abort ( "Integer overflow trap" );
  135. #endif
  136. #ifdef FPE_INTDIV_TRAP 
  137.     case FPE_INTDIV_TRAP : abort ( "Integer division by zero trap" );
  138. #endif
  139. #ifdef FPE_FLTOVF_TRAP 
  140.     case FPE_FLTOVF_TRAP : abort ( "Floating point overflow trap" );
  141. #endif
  142. #ifdef FPE_FLTDIV_TRAP 
  143.     case FPE_FLTDIV_TRAP : abort ( "Floating/decimal division by zero trap" );
  144. #endif
  145. #ifdef FPE_FLTUND_TRAP 
  146.     case FPE_FLTUND_TRAP : abort ( "Floating underflow trap" );
  147. #endif
  148. #ifdef FPE_DECOVF_TRAP 
  149.     case FPE_DECOVF_TRAP : abort ( "Decimal overflow trap" );
  150. #endif
  151. #ifdef FPE_SUBRNG_TRAP 
  152.     case FPE_SUBRNG_TRAP : abort ( "Subscript range trap" );
  153. #endif
  154. #ifdef FPE_FLTOVF_FAULT
  155.     case FPE_FLTOVF_FAULT: abort ( "Floating overflow fault" );
  156. #endif
  157. #ifdef FPE_FLTDIV_FAULT
  158.     case FPE_FLTDIV_FAULT: abort ( "Floating divide by zero fault" );
  159. #endif
  160. #ifdef FPE_FLTUND_FAULT
  161.     case FPE_FLTUND_FAULT: abort ( "Floating underflow fault" );
  162. #endif
  163.     default              : abort ( "Floating exception" );
  164.     }
  165. }
  166.