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
17 // ÚÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄ¿
\r
18 // ³ The VergeC Compiler ³
\r
19 // ³ Copyright (C)1998 BJ Eirich (aka vecna) ³
\r
21 // ÀÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÄÙ
\r
23 #define VERSION "2.01c"
\r
26 #define BUILD_TAG "DJGPP V2\0"
\r
30 #define BUILD_TAG "Watcom 11.0\0"
\r
39 #include "compile.h"
\r
40 #include "lexical.h"
\r
43 extern int pp_nomark;
\r
45 // ================================= Data ====================================
\r
47 char outmode, cmode;
\r
49 char quiet, verbose;
\r
57 //struct find_t *ft;
\r
59 // ================================= Code ====================================
\r
61 void dprint(char *message, ...)
\r
69 va_start (lst, message);
\r
70 vsprintf (string, message, lst);
\r
73 printf ("%s \n", string);
\r
76 void vprint(char *message, ...)
\r
81 if (!verbose) return;
\r
84 va_start (lst, message);
\r
85 vsprintf (string, message, lst);
\r
88 printf ("%s \n", string);
\r
91 void err(char *message, ...)
\r
97 va_start (lst, message);
\r
98 vsprintf (string, message, lst);
\r
103 FILE *efile = fopen("ERROR.TXT", "w");
\r
105 fprintf(efile, "%s \n", string);
\r
110 printf("%s \n", string);
\r
113 remove("vcctemp.$$$");
\r
117 void vcerr(char *message, ...)
\r
123 va_start (lst, message);
\r
124 vsprintf (string, message, lst);
\r
127 err("%s(%d) %s", source_file, lines, string);
\r
130 void vcc_compile_mode_map(char *filename)
\r
138 while ('.' != *x) ++x;
\r
141 CompileMAP(filename);
\r
143 sprintf(strbuf, "%s.map", filename);
\r
144 f = fopen(strbuf, "rb+");
\r
146 err("unable to open %s.", strbuf);
\r
148 fread(strbuf, 1, 6, f);
\r
149 fread(&z, 1, 4, f);
\r
152 o = fopen("outtemp.$$$", "wb");
\r
154 err("unable to open outtemp.$$$");
\r
155 x = (char *) malloc(z);
\r
157 fwrite(x, 1, z, o);
\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
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
173 void vcc_compile_mode_system()
\r
179 dump = fopen("system.vcs", "wb");
\r
180 if (!dump) err("unable to open system.vcs");
\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
191 void vcc_compile_mode_all()
\r
197 struct find_t fileinfo;
\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
210 if (_dos_findfirst("*.MAP", _A_NORMAL, &fileinfo))
\r
211 err("No mapfiles found.");
\r
216 memcpy(fname, fileinfo.name, 13);
\r
219 while (fname[i]!='.') i++;
\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
233 o=fopen("outtemp.$$$","wb");
\r
234 x=(char *) malloc(z);
\r
236 fwrite(x, 1, z, o);
\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
247 sprintf(strbuf,"%s.map", fname);
\r
249 rename("outtemp.$$$",strbuf);
\r
254 if (!_dos_findnext(&fileinfo))
\r
260 dprint("%i total VC lines compiled.", tlines);
\r
263 int main(int argc, char *argv[])
\r
269 strbuf= (char *) malloc(2000);
\r
275 for (loop = 1; loop < argc; loop++)
\r
277 // point to argument string
\r
278 argstr = &loop[argv][0];
\r
281 // skip leading punctuators, if any
\r
282 if ('-' == c || '+' == c || '/' == c)
\r
285 if (!stricmp(argstr, "v"))
\r
286 { verbose = 1; continue; }
\r
288 if (!stricmp(argstr, "q"))
\r
289 { quiet = 1; continue; }
\r
291 // compile SYSTEM.VC only
\r
292 if (!stricmp(argstr, "system"))
\r
293 { cmode = 2; continue; }
\r
295 // compile all available .VC files
\r
296 if (!stricmp(argstr, "all"))
\r
297 { cmode = 3; continue; }
\r
299 // disable line/#include markers
\r
300 if (!stricmp(argstr, "ppnomark"))
\r
301 { pp_nomark = 1; continue; }
\r
303 // dump preprocessor output to temp files
\r
304 if (!stricmp(argstr, "ppdump"))
\r
305 { pp_dump = 1; continue; }
\r
307 // debug locator option
\r
308 if ('.' == *argstr)
\r
309 { locate = atoi(argstr+1); continue; }
\r
311 // at this point, the argument is assumed to be a file
\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
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
325 err("No input files.");
\r
327 InitCompileSystem();
\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
335 default: err("you have now entered the twilight zone.");
\r
338 remove("vcctemp.$$$");
\r
339 remove("ERROR.TXT");
\r