4 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool
5 * Set (PCCTS) -- PCCTS is in the public domain. An individual or
6 * company may do whatever they wish with source code distributed with
7 * PCCTS or the code generated by PCCTS, including the incorporation of
8 * PCCTS, or its output, into commerical software.
10 * We encourage users to develop software with PCCTS. However, we do ask
11 * that credit is given to us for developing PCCTS. By "credit",
12 * we mean that if you incorporate our source code into one of your
13 * programs (commercial product, research project, or otherwise) that you
14 * acknowledge this fact somewhere in the documentation, research report,
15 * etc... If you like PCCTS and have developed a nice tool with the
16 * output, please mention that you developed it using PCCTS. In
17 * addition, we ask that this header remain intact in our source code.
18 * As long as these guidelines are kept, we expect to continue enhancing
19 * this system and expect to make other tools available as they are
24 * With mods by Terence Parr; AHPCRC, University of Minnesota
41 int err_found
= 0; /* indicates whether problem found */
44 void internal_error(char *s
, char *file
,int line
) /* MR9 23-Sep-97 */
46 void internal_error(s
,file
,line
) /* MR9 23-Sep-97 */
51 fprintf(stderr
,s
,file
,line
);
52 exit(PCCTS_EXIT_FAILURE
);
56 char *dlg_malloc(int bytes
,char *file
,int line
)
58 char *dlg_malloc(bytes
,file
,line
)
66 t
= (char *) malloc(bytes
);
69 internal_error("%s(%d): unable to allocate memory\n",
77 char *dlg_calloc(int n
,int bytes
,char *file
,int line
)
79 char *dlg_calloc(n
,bytes
,file
,line
)
87 t
= (char *) calloc(n
,bytes
);
90 internal_error("%s(%d): unable to allocate memory\n",
98 FILE *read_stream(char *name
)
100 FILE *read_stream(name
)
107 if (name
[0] == '-') {
108 fprintf(stderr
, "dlg: invalid option: '%s'\n", name
);
111 f
= fopen(name
, "r");
113 /* couldn't open file */
115 "dlg: Warning: Can't read file %s.\n",
120 /* open stdin if nothing there */
127 FILE *write_stream(char *name
)
129 FILE *write_stream(name
)
136 if (name
[0] == '-') {
137 fprintf(stderr
, "dlg: invalid option: '%s'\n", name
);
140 f
= fopen(OutMetaName(name
), "w");
142 /* couldn't open file */
144 "dlg: Warning: Can't write to file %s.\n",
149 special_fopen_actions(OutMetaName(name
)); /* MR1 */
155 /* open stdout if nothing there */
163 void fatal(char *message
,int line_no
)
165 void fatal(message
,line_no
)
170 fprintf(stderr
,ErrHdr
,
171 (file_str
[0] ? file_str
[0] : "stdin"), line_no
);
172 fprintf(stderr
, " Fatal: %s\n", message
);
173 exit(PCCTS_EXIT_FAILURE
);
177 void error(char *message
,int line_no
)
179 void error(message
,line_no
)
184 fprintf(stderr
,ErrHdr
,
185 (file_str
[0] ? file_str
[0] : "stdin"), line_no
);
186 fprintf(stderr
, " Error: %s\n", message
);
191 void warning(char *message
,int line_no
)
193 void warning(message
,line_no
)
198 fprintf(stderr
,ErrHdr
,
199 (file_str
[0] ? file_str
[0] : "stdin"), line_no
);
200 fprintf(stderr
, " Warning: %s\n", message
);
203 /* MR10: Jeff Vincent
204 MR10: Changed to remove directory information from n only if
205 MR10: if OutputDirectory was changed by user (-o option)
209 char *OutMetaName(char *n
)
215 static char *dir_sym
= DirectorySymbol
;
216 static char newname
[MaxFileName
+1];
219 /* If OutputDirectory is same as TopDirectory (platform default) then leave n alone. */
220 if (strcmp(OutputDirectory
, TopDirectory
) == 0)
223 /* p will point to filename without path information */
224 if ((p
= strrchr(n
, *dir_sym
)) != NULL
)
229 /* Copy new output directory into newname[] */
230 strcpy(newname
, OutputDirectory
);
232 /* if new output directory does not have trailing dir_sym, add it! */
233 if (newname
[strlen(newname
)-1] != *dir_sym
)
234 strcat(newname
, dir_sym
);
236 /* contatenate FILE NAME ONLY to new output directory */