Source:NetHack 3.0.0/lev main.c

From NetHackWiki
Jump to navigation Jump to search

Below is the full text to lev_main.c from the source code of NetHack 3.0.0. To link to a particular line, write [[NetHack 3.0.0/lev_main.c#line123]], for example.

Warning! This is the source code from an old release. For the latest release, see Source code

The NetHack General Public License applies to screenshots, source code and other content from NetHack.

This content was modified from the original NetHack source code distribution (by splitting up NetHack content between wiki pages, and possibly further editing). See the page history for a list of who changed it, and on what dates.

1.    /*	SCCS Id: @(#)lev_main.c	3.0	89/07/02
2.    /*	Copyright (c) 1989 by Jean-Christophe Collet */
3.    /* NetHack may be freely redistributed.  See license for details. */
4.    
5.    /*
6.     * This file contains the main function for the parser
7.     * and some useful functions needed by yacc
8.     */
9.    
10.   #include <stdio.h>
11.   
12.   #define MAX_ERRORS	25
13.   
14.   extern int line_number;
15.   char *fname = "(stdin)";
16.   int fatal_error = 0;
17.   
18.   main(argc, argv) 
19.   int argc;
20.   char **argv;
21.   {
22.   	FILE *fin;
23.   	int i;
24.   
25.   	if (argc == 1)		/* Read standard input */
26.   	    yyparse();
27.   	else 			/* Otherwise every argument is a filename */
28.   	    for(i=1; i<argc; i++) {
29.   		    fin = freopen(argv[i], "r", stdin);
30.   		    fname = argv[i];
31.   		    if (!fin) 
32.   			fprintf(stderr,"Can't open %s\n", argv[i]);
33.   		    else
34.   			yyparse();
35.   		    line_number = 1;
36.   		    fatal_error = 0;
37.   	    }
38.   	return 0;
39.   }
40.   
41.   /* 
42.    * Each time the parser detects an error, it uses this function.
43.    * Here we take count of the errors. To continue farther than
44.    * MAX_ERRORS wouldn't be reasonable.
45.    */
46.   
47.   yyerror(s)
48.   char *s;
49.   {
50.   	fprintf(stderr,"%s : line %d : %s\n",fname,line_number, s);
51.   	if (++fatal_error > MAX_ERRORS) {
52.   		fprintf(stderr,"Too many errors, good bye!\n");
53.   		exit(1);
54.   	}
55.   }
56.   
57.   /* 
58.    * Just display a warning (that is : a non fatal error)
59.    */
60.   
61.   yywarning(s)
62.   char *s;
63.   {
64.   	fprintf(stderr,"%s : line %d : WARNING : %s\n",fname,line_number,s);
65.   }
66.   
67.   yywrap()
68.   {
69.          return 1;
70.   }