home *** CD-ROM | disk | FTP | other *** search
- /*
- * misc.c
- *
- * Copyright (C) 1989, 1991, Craig E. Kolb
- * All rights reserved.
- *
- * This software may be freely copied, modified, and redistributed
- * provided that this copyright notice is preserved on all copies.
- *
- * You may not distribute this software, in whole or in part, as part of
- * any commercial product without the express consent of the authors.
- *
- * There is no warranty or other guarantee of fitness of this software
- * for any purpose. It is provided solely "as is".
- *
- * $Id: misc.c,v 4.0 91/07/17 14:46:31 kolb Exp Locker: kolb $
- *
- * $Log: misc.c,v $
- * Revision 4.0 91/07/17 14:46:31 kolb
- * Initial version.
- *
- */
- #include "rayshade.h"
- #include "options.h"
- #include "stats.h"
-
- Float RSabstmp; /* Temporary value used by fabs macro. Ugly. */
- static void RSmessage();
-
- /*
- * Open input file and call yyparse().
- */
- void
- RSReadInputFile()
- {
- extern FILE *yyin; /* lex/yacc file pointer */
- extern char yyfilename[];
-
- if (Options.inputname == (char *)NULL) {
- yyin = stdin;
- (void)strcpy(yyfilename, "stdin");
- } else {
- (void)strcpy(yyfilename, Options.inputname);
- yyin = fopen(Options.inputname, "r");
- if (yyin == (FILE *)NULL)
- RLerror(RL_PANIC,"Cannot open %s.\n",Options.inputname,0,0);
- }
- /*
- * Initialize symbol table.
- */
- SymtabInit();
- (void)yyparse();
- }
-
- void
- RLerror(level, pat, arg1, arg2, arg3)
- int level;
- char *pat, *arg1, *arg2, *arg3;
- {
- int loop, loop2 ;
-
-
- switch (level) {
- case RL_ADVISE:
- if (!Options.quiet)
- RSAlert("Warning", pat, arg1, arg2, arg3);
- break;
- case RL_WARN:
- RSAlert("Warning", pat, arg1, arg2, arg3);
- break;
- case RL_ABORT:
- RSAlert("Error", pat, arg1, arg2, arg3);
- exit(1);
- break;
- case RL_PANIC:
- RSAlert("Fatal error", pat, arg1, arg2, arg3);
- exit(2);
- break;
- default:
- RSAlert("Unknown error", pat, arg1, arg2, arg3);
- exit(3);
- }
- }
-
- static void
- RSmessage(type, pat, arg1, arg2, arg3)
- char *type, *pat, *arg1, *arg2, *arg3;
- {
- extern FILE *yyin;
- extern int yylineno;
- extern char yyfilename[];
-
- if (yyin) {
- /*
- * cleanup() hasn't nulled yyin, so line #
- * info is valid.
- */
- printf("%s: %s: %s, line %d: ",
- Options.progname, type,
- yyfilename == (char *)NULL ? "stdin" :
- yyfilename, yylineno);
- } else {
- printf("%s: %s: ", Options.progname, type);
- }
- printf(pat, arg1, arg2, arg3);
- }