]> git.proxmox.com Git - mirror_edk2.git/blame - Tools/CodeTools/Source/Pccts/dlg/support.c
More renames for Tool Packages
[mirror_edk2.git] / Tools / CodeTools / Source / Pccts / dlg / support.c
CommitLineData
878ddf1f 1/*\r
2 * SOFTWARE RIGHTS\r
3 *\r
4 * We reserve no LEGAL rights to the Purdue Compiler Construction Tool\r
5 * Set (PCCTS) -- PCCTS is in the public domain. An individual or\r
6 * company may do whatever they wish with source code distributed with\r
7 * PCCTS or the code generated by PCCTS, including the incorporation of\r
8 * PCCTS, or its output, into commerical software.\r
9 *\r
10 * We encourage users to develop software with PCCTS. However, we do ask\r
11 * that credit is given to us for developing PCCTS. By "credit",\r
12 * we mean that if you incorporate our source code into one of your\r
13 * programs (commercial product, research project, or otherwise) that you\r
14 * acknowledge this fact somewhere in the documentation, research report,\r
15 * etc... If you like PCCTS and have developed a nice tool with the\r
16 * output, please mention that you developed it using PCCTS. In\r
17 * addition, we ask that this header remain intact in our source code.\r
18 * As long as these guidelines are kept, we expect to continue enhancing\r
19 * this system and expect to make other tools available as they are\r
20 * completed.\r
21 *\r
22 * DLG 1.33\r
23 * Will Cohen\r
24 * With mods by Terence Parr; AHPCRC, University of Minnesota\r
25 * 1989-2001\r
26 */\r
27\r
28#include <stdio.h>\r
29#include <string.h>\r
30#include "dlg.h"\r
31#ifdef MEMCHK\r
32#include "trax.h"\r
33#else\r
34#ifdef __STDC__\r
35#include <stdlib.h>\r
36#else\r
37#include <malloc.h>\r
38#endif /* __STDC__ */\r
39#endif\r
40\r
41int err_found = 0; /* indicates whether problem found */\r
42\r
43#ifdef __USE_PROTOS\r
44void internal_error(char *s, char *file,int line) /* MR9 23-Sep-97 */\r
45#else\r
46void internal_error(s,file,line) /* MR9 23-Sep-97 */\r
47char *s,*file;\r
48int line;\r
49#endif\r
50{\r
51 fprintf(stderr,s,file,line);\r
52 exit(PCCTS_EXIT_FAILURE);\r
53}\r
54\r
55#ifdef __USE_PROTOS\r
56char *dlg_malloc(int bytes,char *file,int line)\r
57#else\r
58char *dlg_malloc(bytes,file,line)\r
59int bytes;\r
60char *file;\r
61int line;\r
62#endif\r
63{\r
64 char *t;\r
65\r
66 t = (char *) malloc(bytes);\r
67 if (!t){\r
68 /* error */\r
69 internal_error("%s(%d): unable to allocate memory\n",\r
70 file,line);\r
71 }\r
72 return t;\r
73}\r
74\r
75\r
76#ifdef __USE_PROTOS\r
77char *dlg_calloc(int n,int bytes,char *file,int line)\r
78#else\r
79char *dlg_calloc(n,bytes,file,line)\r
80int n,bytes;\r
81char *file;\r
82int line;\r
83#endif\r
84{\r
85 char *t;\r
86\r
87 t = (char *) calloc(n,bytes);\r
88 if (!t){\r
89 /* error */\r
90 internal_error("%s(%d): unable to allocate memory\n",\r
91 file,line);\r
92 }\r
93 return t;\r
94}\r
95\r
96\r
97#ifdef __USE_PROTOS\r
98FILE *read_stream(char *name)\r
99#else\r
100FILE *read_stream(name)\r
101char *name;\r
102#endif\r
103{\r
104 FILE *f;\r
105\r
106 if (name){\r
107 if (name[0] == '-') {\r
108 fprintf(stderr, "dlg: invalid option: '%s'\n", name);\r
109 f = NULL;\r
110 }else{\r
111 f = fopen(name, "r");\r
112 if (f == NULL){\r
113 /* couldn't open file */\r
114 fprintf(stderr,\r
115 "dlg: Warning: Can't read file %s.\n",\r
116 name);\r
117 }\r
118 }\r
119 }else{\r
120 /* open stdin if nothing there */\r
121 f = stdin;\r
122 }\r
123 return f;\r
124}\r
125\r
126#ifdef __USE_PROTOS\r
127FILE *write_stream(char *name)\r
128#else\r
129FILE *write_stream(name)\r
130char *name;\r
131#endif\r
132{\r
133 FILE *f;\r
134\r
135 if (name){\r
136 if (name[0] == '-') {\r
137 fprintf(stderr, "dlg: invalid option: '%s'\n", name);\r
138 f = NULL;\r
139 }else{\r
140 f = fopen(OutMetaName(name), "w");\r
141 if (f == NULL){\r
142 /* couldn't open file */\r
143 fprintf(stderr,\r
144 "dlg: Warning: Can't write to file %s.\n",\r
145 name);\r
146 }\r
147 else\r
148#ifdef SPECIAL_FOPEN\r
149 special_fopen_actions(OutMetaName(name)); /* MR1 */\r
150#else\r
151 ; /* MR1 */\r
152#endif\r
153 }\r
154 }else{\r
155 /* open stdout if nothing there */\r
156 f = stdout;\r
157 }\r
158 return f;\r
159}\r
160\r
161\r
162#ifdef __USE_PROTOS\r
163void fatal(char *message,int line_no)\r
164#else\r
165void fatal(message,line_no)\r
166char *message;\r
167int line_no;\r
168#endif\r
169{\r
170 fprintf(stderr,ErrHdr,\r
171 (file_str[0] ? file_str[0] : "stdin"), line_no);\r
172 fprintf(stderr, " Fatal: %s\n", message);\r
173 exit(PCCTS_EXIT_FAILURE);\r
174}\r
175\r
176#ifdef __USE_PROTOS\r
177void error(char *message,int line_no)\r
178#else\r
179void error(message,line_no)\r
180char *message;\r
181int line_no;\r
182#endif\r
183{\r
184 fprintf(stderr,ErrHdr,\r
185 (file_str[0] ? file_str[0] : "stdin"), line_no);\r
186 fprintf(stderr, " Error: %s\n", message);\r
187 err_found = 1;\r
188}\r
189\r
190#ifdef __USE_PROTOS\r
191void warning(char *message,int line_no)\r
192#else\r
193void warning(message,line_no)\r
194char *message;\r
195int line_no;\r
196#endif\r
197{\r
198 fprintf(stderr,ErrHdr,\r
199 (file_str[0] ? file_str[0] : "stdin"), line_no);\r
200 fprintf(stderr, " Warning: %s\n", message);\r
201}\r
202\r
203/* MR10: Jeff Vincent\r
204 MR10: Changed to remove directory information from n only if\r
205 MR10: if OutputDirectory was changed by user (-o option)\r
206*/\r
207\r
208#ifdef __USE_PROTOS\r
209char *OutMetaName(char *n)\r
210#else\r
211char *OutMetaName(n)\r
212char *n;\r
213#endif\r
214{ \r
215 static char *dir_sym = DirectorySymbol;\r
216 static char newname[MaxFileName+1];\r
217 char *p;\r
218\r
219 /* If OutputDirectory is same as TopDirectory (platform default) then leave n alone. */\r
220 if (strcmp(OutputDirectory, TopDirectory) == 0)\r
221 return n;\r
222\r
223 /* p will point to filename without path information */\r
224 if ((p = strrchr(n, *dir_sym)) != NULL)\r
225 p++;\r
226 else\r
227 p = n;\r
228\r
229 /* Copy new output directory into newname[] */\r
230 strcpy(newname, OutputDirectory);\r
231\r
232 /* if new output directory does not have trailing dir_sym, add it! */\r
233 if (newname[strlen(newname)-1] != *dir_sym)\r
234 strcat(newname, dir_sym);\r
235\r
236 /* contatenate FILE NAME ONLY to new output directory */\r
237 strcat(newname, p);\r
238\r
239 return newname;\r
240}\r