1 /* NetHack 3.6 dgn_main.c $NHDT-Date: 1432512785 2015/05/25 00:13:05 $ $NHDT-Branch: master $:$NHDT-Revision: 1.11 $ */
2 /* Copyright (c) 1989 by Jean-Christophe Collet */
3 /* Copyright (c) 1990 by M. Stephenson */
4 /* NetHack may be freely redistributed. See license for details. */
7 * This file contains the main function for the parser
8 * and some useful functions needed by yacc
14 /* Macintosh-specific code */
15 #if defined(__APPLE__) && defined(__MACH__)
16 /* MacOS X has Unix-style files and processes */
20 #if defined(__SC__) || defined(__MRC__)
22 #include <CursorCtl.h>
24 /* put dungeon file in library location */
25 #define PREFIX ":lib:"
35 extern int NDECL(yyparse);
36 extern int nh_line_number;
37 const char *fname = "(stdin)";
40 int FDECL(main, (int, char **));
41 void FDECL(yyerror, (const char *));
42 void FDECL(yywarning, (const char *));
44 void FDECL(init_yyin, (FILE *));
45 void FDECL(init_yyout, (FILE *));
48 FILE *FDECL(freopen, (char *, char *, FILE *));
50 #define Fprintf (void) fprintf
52 #if defined(__BORLANDC__) && !defined(_WIN32)
53 extern unsigned _stklen = STKSIZ;
60 char infile[64], outfile[64], basename[64];
63 boolean errors_encountered = FALSE;
64 #if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__))
66 static char *mac_argv[] = { "dgn_comp", /* dummy argv[0] */
69 argc = SIZE(mac_argv);
73 Strcpy(infile, "(stdin)");
75 Strcpy(outfile, "(stdout)");
78 if (argc == 1) { /* Read standard input */
83 errors_encountered = TRUE;
84 } else { /* Otherwise every argument is a filename */
85 for (i = 1; i < argc; i++) {
86 fname = strcpy(infile, argv[i]);
87 /* the input file had better be a .pdf file */
88 len = strlen(fname) - 4; /* length excluding suffix */
89 if (len < 0 || strncmp(".pdf", fname + len, 4)) {
90 Fprintf(stderr, "Error - file name \"%s\" in wrong format.\n",
92 errors_encountered = TRUE;
96 /* build output file name */
97 #if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__))
98 /* extract basename from path to infile */
99 mark = strrchr(infile, ':');
100 strcpy(basename, mark ? mark + 1 : infile);
101 mark = strchr(basename, '.');
105 /* Use the whole name - strip off the last 3 or 4 chars. */
107 #ifdef VMS /* avoid possible interaction with logical name */
108 len++; /* retain "." as trailing punctuation */
110 (void) strncpy(basename, infile, len);
111 basename[len] = '\0';
116 (void) strcat(outfile, PREFIX);
118 (void) strcat(outfile, basename);
120 fin = freopen(infile, "r", stdin);
122 Fprintf(stderr, "Can't open %s for input.\n", infile);
124 errors_encountered = TRUE;
127 fout = freopen(outfile, WRBMODE, stdout);
129 Fprintf(stderr, "Can't open %s for output.\n", outfile);
131 errors_encountered = TRUE;
138 if (fatal_error > 0) {
139 errors_encountered = TRUE;
144 if (fout && fclose(fout) < 0) {
145 Fprintf(stderr, "Can't finish output file.");
147 errors_encountered = TRUE;
149 exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS);
155 * Each time the parser detects an error, it uses this function.
156 * Here we take count of the errors. To continue farther than
157 * MAX_ERRORS wouldn't be reasonable.
164 (void) fprintf(stderr, "%s : line %d : %s\n", fname, nh_line_number, s);
165 if (++fatal_error > MAX_ERRORS) {
166 (void) fprintf(stderr, "Too many errors, good bye!\n");
172 * Just display a warning (that is : a non fatal error)
179 (void) fprintf(stderr, "%s : line %d : WARNING : %s\n", fname,
186 SpinCursor(3); /* Don't know if this is a good place to put it ?
187 Is it called for our grammar ?