]> 4ch.mooo.com Git - 16.git/blob - 16/v2/source/verge/VCC/VCC.C
wwww
[16.git] / 16 / v2 / source / verge / VCC / VCC.C
1 /*\r
2 Copyright (C) 1998 BJ Eirich (aka vecna)\r
3 This program is free software; you can redistribute it and/or\r
4 modify it under the terms of the GNU General Public License\r
5 as published by the Free Software Foundation; either version 2\r
6 of the License, or (at your option) any later version.\r
7 This program is distributed in the hope that it will be useful,\r
8 but WITHOUT ANY WARRANTY; without even the implied warranty of\r
9 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.\r
10 See the GNU General Public Lic\r
11 See the GNU General Public License for more details.\r
12 You should have received a copy of the GNU General Public License\r
13 along with this program; if not, write to the Free Software\r
14 Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.\r
15 */\r
16 \r
17 // ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿\r
18 // ³                        The VergeC Compiler                          ³\r
19 // ³              Copyright (C)1998 BJ Eirich (aka vecna)                ³\r
20 // ³                            Main module                              ³\r
21 // ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ\r
22 \r
23 #define VERSION "2.01c"\r
24 \r
25 #ifdef __DJGPP__\r
26 #define BUILD_TAG "DJGPP V2\0"\r
27 #endif\r
28 \r
29 #ifdef __WATCOMC__\r
30 #define BUILD_TAG "Watcom 11.0\0"\r
31 #endif\r
32 \r
33 #include <dos.h>\r
34 #include <stdio.h>\r
35 #include <stdlib.h>\r
36 #include <string.h>\r
37 #include <stdarg.h>\r
38 \r
39 #include "compile.h"\r
40 #include "lexical.h"\r
41 \r
42 extern int pp_dump;\r
43 extern int pp_nomark;\r
44 \r
45 // ================================= Data ====================================\r
46 \r
47 char outmode, cmode;\r
48 char fname[80];\r
49 char quiet, verbose;\r
50 char *strbuf;\r
51 int locate=0;\r
52 \r
53 // -- locals --\r
54 \r
55 //FILE *f;\r
56 //int i;\r
57 //struct find_t *ft;\r
58 \r
59 // ================================= Code ====================================\r
60 \r
61 void dprint(char *message, ...)\r
62 {\r
63   va_list  lst;\r
64   char     string[1024];\r
65 \r
66   if (quiet) return;\r
67 \r
68   // compose message\r
69   va_start (lst, message);\r
70   vsprintf (string, message, lst);\r
71   va_end   (lst);\r
72 \r
73   printf   ("%s \n", string);\r
74 }\r
75 \r
76 void vprint(char *message, ...)\r
77 {\r
78   va_list  lst;\r
79   char     string[1024];\r
80 \r
81   if (!verbose) return;\r
82 \r
83   // compose message\r
84   va_start (lst, message);\r
85   vsprintf (string, message, lst);\r
86   va_end   (lst);\r
87 \r
88   printf   ("%s \n", string);\r
89 }\r
90 \r
91 void err(char *message, ...)\r
92 {\r
93   va_list  lst;\r
94   char     string[1024];\r
95 \r
96   // compose message\r
97   va_start (lst, message);\r
98   vsprintf (string, message, lst);\r
99   va_end   (lst);\r
100 \r
101   if (quiet)\r
102   {\r
103     FILE *efile = fopen("ERROR.TXT", "w");\r
104 \r
105     fprintf(efile, "%s \n", string);\r
106     fclose(efile);\r
107   }\r
108   else\r
109   {\r
110     printf("%s \n", string);\r
111   }\r
112 \r
113   remove("vcctemp.$$$");\r
114   exit(-1);\r
115 }\r
116 \r
117 void vcerr(char *message, ...)\r
118 {\r
119   va_list  lst;\r
120   char     string[1024];\r
121 \r
122   // compose message\r
123   va_start (lst, message);\r
124   vsprintf (string, message, lst);\r
125   va_end   (lst);\r
126 \r
127   err("%s(%d) %s", source_file, lines, string);\r
128 }\r
129 \r
130 void vcc_compile_mode_map(char *filename)\r
131 {\r
132   FILE *o=0;\r
133   FILE *f=0;\r
134   char *x=0;\r
135   int   z=0;\r
136 \r
137   x = filename;\r
138   while ('.' != *x) ++x;\r
139   *x = 0;\r
140 \r
141   CompileMAP(filename);\r
142 \r
143   sprintf(strbuf, "%s.map", filename);\r
144   f = fopen(strbuf, "rb+");\r
145   if (!f)\r
146     err("unable to open %s.", strbuf);\r
147 \r
148   fread(strbuf, 1, 6, f);\r
149   fread(&z, 1, 4, f);\r
150   fseek(f, 0, 0);\r
151 \r
152   o = fopen("outtemp.$$$", "wb");\r
153   if (!o)\r
154     err("unable to open outtemp.$$$");\r
155   x = (char *) malloc(z);\r
156   fread(x, 1, z, f);\r
157   fwrite(x, 1, z, o);\r
158   fclose(f);\r
159 \r
160   fwrite(&mfuncs, 1, 4, o);\r
161   fwrite(&functbl, 4, mfuncs, o);\r
162   mfuncs = (int) code - (int) outbuf;\r
163   fwrite(&mfuncs, 1, 4, o);\r
164   fwrite(outbuf, 1, code-outbuf, o);\r
165   fclose(o);\r
166 \r
167   // remove existing map file\r
168   sprintf(strbuf,"%s.map", filename); remove(strbuf);\r
169   // rename temp file to map file name\r
170   rename("outtemp.$$$", strbuf);\r
171 }\r
172 \r
173 void vcc_compile_mode_system()\r
174 {\r
175   FILE *dump=0;\r
176 \r
177   CompileSystem();\r
178 \r
179   dump = fopen("system.vcs", "wb");\r
180   if (!dump) err("unable to open system.vcs");\r
181 \r
182   fwrite(&numfuncs, 1, 4, dump);\r
183   fwrite(&curstartofs, 1, 4, dump);\r
184   fwrite(&sstartofs, 1, 4, dump);\r
185   fwrite(outbuf, 1, code-outbuf, dump);\r
186   fputc(255, dump);\r
187 \r
188   fclose(dump);\r
189 }\r
190 \r
191 void vcc_compile_mode_all()\r
192 {\r
193   FILE *o=0;\r
194   FILE *f=0;\r
195   char *x=0;\r
196   int   z=0;\r
197   struct find_t fileinfo;\r
198 \r
199   CompileSystem();\r
200   f=fopen("system.vcs","wb");\r
201   fwrite(&numfuncs, 1, 4, f);\r
202   fwrite(&curstartofs, 1, 4, f);\r
203   fwrite(&sstartofs, 1, 4, f);\r
204   fwrite(outbuf, 1, code-outbuf, f);\r
205   fputc(255, f);\r
206   fclose(f);\r
207   free(source);\r
208   free(outbuf);\r
209 \r
210   if (_dos_findfirst("*.MAP", _A_NORMAL, &fileinfo))\r
211     err("No mapfiles found.");\r
212 \r
213   while (1)\r
214   {\r
215     int i;\r
216     memcpy(fname, fileinfo.name, 13);\r
217 \r
218     i=0;\r
219     while (fname[i]!='.') i++;\r
220     fname[i]=0;\r
221 \r
222     strlwr(fname);\r
223     mfuncs=0;\r
224 \r
225     CompileMAP(fname);\r
226 \r
227     sprintf(strbuf,"%s.map", fname);\r
228     f=fopen(strbuf,"rb+");\r
229     fread(strbuf, 1, 6, f);\r
230     fread(&z, 1, 4, f);\r
231     fseek(f, 0, 0);\r
232 \r
233     o=fopen("outtemp.$$$","wb");\r
234     x=(char *) malloc(z);\r
235     fread(x, 1, z, f);\r
236     fwrite(x, 1, z, o);\r
237     fclose(f);\r
238     free(x);\r
239 \r
240     fwrite(&mfuncs, 1, 4, o);\r
241     fwrite(&functbl, 4, mfuncs, o);\r
242     mfuncs=(int) code - (int) outbuf;\r
243     fwrite(&mfuncs, 1, 4, o);\r
244     fwrite(outbuf, 1, code-outbuf, o);\r
245     fclose(o);\r
246 \r
247     sprintf(strbuf,"%s.map", fname);\r
248     remove(strbuf);\r
249     rename("outtemp.$$$",strbuf);\r
250 \r
251     free(source);\r
252     free(outbuf);\r
253 \r
254     if (!_dos_findnext(&fileinfo))\r
255       continue;\r
256 \r
257     break;\r
258   }\r
259 \r
260   dprint("%i total VC lines compiled.", tlines);\r
261 }\r
262 \r
263 int main(int argc, char *argv[])\r
264 {\r
265   int loop = 0;\r
266   char c = 0;\r
267   char *argstr = 0;\r
268 \r
269   strbuf= (char *) malloc(2000);\r
270 \r
271   cmode = 0;\r
272   pp_dump = 0;\r
273   pp_nomark = 0;\r
274 \r
275   for (loop = 1; loop < argc; loop++)\r
276   {\r
277     // point to argument string\r
278     argstr = &loop[argv][0];\r
279 \r
280     c = *argstr;\r
281     // skip leading punctuators, if any\r
282     if ('-' == c || '+' == c || '/' == c)\r
283       ++argstr;\r
284 \r
285     if (!stricmp(argstr, "v"))\r
286       { verbose = 1; continue; }\r
287 \r
288     if (!stricmp(argstr, "q"))\r
289       { quiet = 1; continue; }\r
290 \r
291     // compile SYSTEM.VC only\r
292     if (!stricmp(argstr, "system"))\r
293       { cmode = 2; continue; }\r
294 \r
295     // compile all available .VC files\r
296     if (!stricmp(argstr, "all"))\r
297       { cmode = 3; continue; }\r
298 \r
299     // disable line/#include markers\r
300     if (!stricmp(argstr, "ppnomark"))\r
301       { pp_nomark = 1; continue; }\r
302 \r
303     // dump preprocessor output to temp files\r
304     if (!stricmp(argstr, "ppdump"))\r
305       { pp_dump = 1; continue; }\r
306 \r
307     // debug locator option\r
308     if ('.' == *argstr)\r
309       { locate = atoi(argstr+1); continue; }\r
310 \r
311     // at this point, the argument is assumed to be a file\r
312 \r
313     if (strlen(argstr) > 79)\r
314       { printf("filename '%s' too long!", argstr); argstr[79] = 0; }\r
315     memcpy(fname, argstr, strlen(argstr)+1);\r
316 \r
317     cmode = 1;\r
318     continue;\r
319   }\r
320 \r
321   dprint("vcc v.%s Copyright (C)1998 Benjamin Eirich. All rights reserved.", VERSION);\r
322   vprint("%s build %s on %s %s", BUILD_TAG, __FILE__, __DATE__, __TIME__);\r
323 \r
324   if (!cmode)\r
325     err("No input files.");\r
326 \r
327   InitCompileSystem();\r
328 \r
329   switch (cmode)\r
330   {\r
331     case 1: vcc_compile_mode_map(fname); break;\r
332     case 2: vcc_compile_mode_system(); break;\r
333     case 3: vcc_compile_mode_all(); break;\r
334 \r
335     default: err("you have now entered the twilight zone.");\r
336   }\r
337 \r
338   remove("vcctemp.$$$");\r
339   remove("ERROR.TXT");\r
340 \r
341   return 0;\r
342 }\r