1 /* SCCS Id: @(#)dgn_main.c 3.4 1994/09/23 */
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:"
30 # define SpinCursor(x)
35 extern int NDECL (yyparse);
36 extern int 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] */
70 argc = SIZE(mac_argv);
74 Strcpy(infile, "(stdin)");
76 Strcpy(outfile, "(stdout)");
79 if (argc == 1) { /* Read standard input */
84 errors_encountered = TRUE;
85 } else { /* Otherwise every argument is a filename */
86 for(i=1; i<argc; i++) {
87 fname = strcpy(infile, argv[i]);
88 /* the input file had better be a .pdf file */
89 len = strlen(fname) - 4; /* length excluding suffix */
90 if (len < 0 || strncmp(".pdf", fname + len, 4)) {
92 "Error - file name \"%s\" in wrong format.\n",
94 errors_encountered = TRUE;
98 /* build output file name */
99 #if defined(MAC) && (defined(THINK_C) || defined(__MWERKS__))
100 /* extract basename from path to infile */
101 mark = strrchr(infile, ':');
102 strcpy(basename, mark ? mark+1 : infile);
103 mark = strchr(basename, '.');
104 if (mark) *mark = '\0';
106 /* Use the whole name - strip off the last 3 or 4 chars. */
108 #ifdef VMS /* avoid possible interaction with logical name */
109 len++; /* retain "." as trailing punctuation */
111 (void) strncpy(basename, infile, len);
112 basename[len] = '\0';
117 (void) strcat(outfile, PREFIX);
119 (void) strcat(outfile, basename);
121 fin = freopen(infile, "r", stdin);
123 Fprintf(stderr, "Can't open %s for input.\n", infile);
125 errors_encountered = TRUE;
128 fout = freopen(outfile, WRBMODE, stdout);
130 Fprintf(stderr, "Can't open %s for output.\n", outfile);
132 errors_encountered = TRUE;
139 if (fatal_error > 0) {
140 errors_encountered = TRUE;
145 if (fout && fclose(fout) < 0) {
146 Fprintf(stderr, "Can't finish output file.");
148 errors_encountered = TRUE;
150 exit(errors_encountered ? EXIT_FAILURE : EXIT_SUCCESS);
156 * Each time the parser detects an error, it uses this function.
157 * Here we take count of the errors. To continue farther than
158 * MAX_ERRORS wouldn't be reasonable.
164 (void) fprintf(stderr,"%s : line %d : %s\n",fname,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)
178 (void) fprintf(stderr,"%s : line %d : WARNING : %s\n",fname,line_number,s);
183 SpinCursor(3); /* Don't know if this is a good place to put it ?
184 Is it called for our grammar ? Often enough ?