home *** CD-ROM | disk | FTP | other *** search
/ Otherware / Otherware_1_SB_Development.iso / mac / developm / source / macraysh.sit / Code / Source / misc.c < prev    next >
Encoding:
C/C++ Source or Header  |  1992-04-27  |  2.3 KB  |  106 lines

  1. /*
  2.  * misc.c
  3.  *
  4.  * Copyright (C) 1989, 1991, Craig E. Kolb
  5.  * All rights reserved.
  6.  *
  7.  * This software may be freely copied, modified, and redistributed
  8.  * provided that this copyright notice is preserved on all copies.
  9.  *
  10.  * You may not distribute this software, in whole or in part, as part of
  11.  * any commercial product without the express consent of the authors.
  12.  *
  13.  * There is no warranty or other guarantee of fitness of this software
  14.  * for any purpose.  It is provided solely "as is".
  15.  *
  16.  * $Id: misc.c,v 4.0 91/07/17 14:46:31 kolb Exp Locker: kolb $
  17.  *
  18.  * $Log:    misc.c,v $
  19.  * Revision 4.0  91/07/17  14:46:31  kolb
  20.  * Initial version.
  21.  * 
  22.  */
  23. #include "rayshade.h"
  24. #include "options.h"
  25. #include "stats.h"
  26.  
  27. Float RSabstmp;    /* Temporary value used by fabs macro.  Ugly. */
  28. static void RSmessage();
  29.  
  30. /*
  31.  * Open input file and call yyparse().
  32.  */
  33. void
  34. RSReadInputFile()
  35. {
  36.     extern FILE *yyin;    /* lex/yacc file pointer */
  37.     extern char yyfilename[];
  38.  
  39.     if (Options.inputname == (char *)NULL) {
  40.         yyin = stdin;
  41.         (void)strcpy(yyfilename, "stdin");
  42.     } else {
  43.         (void)strcpy(yyfilename, Options.inputname);
  44.         yyin = fopen(Options.inputname, "r");
  45.         if (yyin == (FILE *)NULL)
  46.             RLerror(RL_PANIC,"Cannot open %s.\n",Options.inputname,0,0);
  47.     }
  48.     /*
  49.      * Initialize symbol table.
  50.      */
  51.     SymtabInit();
  52.     (void)yyparse();
  53. }
  54.  
  55. void
  56. RLerror(level, pat, arg1, arg2, arg3)
  57. int level;
  58. char *pat, *arg1, *arg2, *arg3;
  59. {
  60.     int loop, loop2 ;
  61.  
  62.  
  63.     switch (level) {
  64.         case RL_ADVISE:
  65.             if (!Options.quiet)
  66.                 RSAlert("Warning", pat, arg1, arg2, arg3);
  67.             break;
  68.         case RL_WARN:
  69.             RSAlert("Warning", pat, arg1, arg2, arg3);
  70.             break;
  71.         case RL_ABORT:
  72.             RSAlert("Error", pat, arg1, arg2, arg3);
  73.             exit(1);
  74.             break;
  75.         case RL_PANIC:
  76.             RSAlert("Fatal error", pat, arg1, arg2, arg3);
  77.             exit(2);
  78.             break;
  79.         default:
  80.             RSAlert("Unknown error", pat, arg1, arg2, arg3);
  81.             exit(3);
  82.     }
  83. }
  84.  
  85. static void
  86. RSmessage(type, pat, arg1, arg2, arg3)
  87. char *type, *pat, *arg1, *arg2, *arg3;
  88. {
  89.     extern FILE *yyin;
  90.     extern int yylineno;
  91.     extern char yyfilename[];
  92.  
  93.     if (yyin) {
  94.         /*
  95.          * cleanup() hasn't nulled yyin, so line #
  96.          * info is valid.
  97.          */
  98.         printf("%s: %s: %s, line %d: ",
  99.             Options.progname, type,
  100.             yyfilename == (char *)NULL ? "stdin" :
  101.                 yyfilename, yylineno);
  102.     } else {
  103.         printf("%s: %s: ", Options.progname, type);
  104.     }
  105.     printf(pat, arg1, arg2, arg3);
  106. }