]> git.sur5r.net Git - cc65/blob - src/grc/grc.c
Added search paths similar to that of the linker and compiler.
[cc65] / src / grc / grc.c
1
2 /*
3     GEOS resource compiler
4
5     by Maciej 'YTM/Elysium' Witkowiak
6
7     see GEOSLib documentation for license info
8
9 */
10
11 /*
12  - make it work, then do it better
13  - more or less comments? it was hard to code, should be even harder to
14    understand =D
15  - add loadable icons feature (binary - 63 bytes)
16 */
17
18 /* - err, maybe free allocated memory, huh? (who cares, it's just a little prog...)
19 */
20
21 #include <stdio.h>
22 #include <stdlib.h>
23 #include <stdarg.h>
24 #include <string.h>
25 #include <errno.h>
26 #include <time.h>
27
28 #include "grc.h"
29
30 /* common stuff */
31 #include "fname.h"
32 #include "abend.h"
33 #include "chartype.h"
34
35 void VLIRLinker(int argc, char *argv[]) {
36 FILE *outCVT, *input;
37 unsigned char *buffer;
38 unsigned char vlirtabt[127];
39 unsigned char vlirtabs[127];
40 int i,j,lastarg;
41 unsigned l;
42 int bytes;
43 int blocks,rest;
44
45         i=2;
46
47         /* check if we know enough */
48
49         if (argc<4)
50             AbEnd("too few arguments, required [out] [cvthead] [vlir0] ...\n");
51
52         /* first open and copy CVT header */
53
54         outCVT = fopen(argv[i],"wb+");
55         if (outCVT==NULL)
56             AbEnd("can't open output:%s\n",strerror(errno));
57
58         ++i;
59         input = fopen(argv[i],"rb");
60         if (input==NULL)
61             AbEnd("can't open input:%s\n",strerror(errno));
62
63         buffer = malloc(THIS_BUFFER_IS_SOOO_HUGE);
64         memset(buffer,0,THIS_BUFFER_IS_SOOO_HUGE);
65
66         bytes = fread(buffer,1,1024,input);
67         fclose(input);
68         if (bytes!=508)
69                 AbEnd("%s is not a cvt header\n",argv[i]);
70
71         fwrite(buffer,1,bytes,outCVT);
72
73         /* now put 254 bytes of VLIR table, to update later */
74
75         /* clear out things */
76         memset(buffer,0,512);
77         fwrite(buffer,1,254,outCVT);
78         for (l=0;l<sizeof(vlirtabt)/sizeof(vlirtabt[0]);l++) {
79                 vlirtabt[l]=0;
80                 vlirtabs[l]=0;
81         }
82
83         /* scan arguments for the last one that is not blank or nonexistant */
84         j=argc;
85         lastarg=argc-1;
86         while (j!=3) {
87                 --j;
88                 if ((strcmp(argv[j],"blank")==0)||(strcmp(argv[j],"noexist")==0))
89                         --lastarg;
90         }
91
92         /* now read all VLIR chains, align to 254 bytes */
93
94         ++i;
95         j=0;
96         while (i!=argc) {
97                 if (strcmp(argv[i],"blank")==0) {
98                         vlirtabt[j]=0; vlirtabs[j]=0; }
99                 else if (strcmp(argv[i],"noexist")==0) {
100                         vlirtabt[j]=0; vlirtabs[j]=0xff; }
101                 else {
102                         memset(buffer,0,bytes+512);
103                         input = fopen(argv[i],"rb");
104                         if (input==NULL)
105                                 AbEnd("couldn't open %s:%s\n",argv[i],strerror(errno));
106                         bytes = fread(buffer,1,THIS_BUFFER_IS_SOOO_HUGE,input);
107                         fclose(input);
108                         if (bytes==0)
109                                 AbEnd("couldn't read %s:%s\n",argv[i],strerror(errno));
110                         blocks = bytes / 254;
111                         rest = bytes % 254;
112                         if (rest==0) {
113                             rest = 255;
114                             --blocks;
115                         } else {
116                             ++rest;
117                         }
118                         vlirtabt[j]=blocks+1; vlirtabs[j]=rest;
119                         /* do not pad the last chain - it doesn't change or break anything
120                            but filesize in bytes of .cvt will be identical to native cvt */
121                         if (i==lastarg)
122                                 fwrite(buffer,1,bytes,outCVT);
123                         else
124                                 fwrite(buffer,1,(blocks+1)*254,outCVT);
125                 }
126                 ++j;
127                 ++i;
128         }
129
130         free(buffer);
131
132         /* now rewind and update VLIR table */
133
134         fflush(outCVT);
135         fseek(outCVT,508,SEEK_SET);
136         for (l=0;l<sizeof(vlirtabt)/sizeof(vlirtabt[0]);l++) {
137                 fputc(vlirtabt[l],outCVT);
138                 fputc(vlirtabs[l],outCVT);
139         }
140         fclose(outCVT);
141         exit(EXIT_SUCCESS);
142 }
143
144 void printCHeader (void) {
145
146     fprintf(outputCFile, "\n/*\n\tThis file was generated by GEOS Resource Compiler\n"
147             "\n\tDO NOT EDIT! Any changes will be lost!\n"
148             "\n\tEdit proper resource file instead\n"
149             "\n*/\n\n");
150 }
151
152 void printSHeader (void) {
153
154     fprintf(outputSFile, "\n;\n;\tThis file was generated by GEOS Resource Compiler\n;"
155             "\n;\tDO NOT EDIT! Any changes will be lost!\n;"
156             "\n;\tEdit proper resource file instead\n;"
157             "\n;\n\n");
158 }
159
160 void printVHeader (void) {
161     fprintf(outputVFile, "\n#\n#\tThis file was generated by GEOS Resource Compiler\n#"
162             "\n#\tDO NOT EDIT! Any changes will be lost!\n#"
163             "\n#\tEdit proper resource file instead\n#"
164             "\n#\tLook at end of this file to find commandline that must be used\n"
165               "#\tto invoke ld65 and grc (as VLIR linker)\n#"
166             "\n#\n\n");
167 }
168
169 void openCFile (void) {
170     if ((CFnum==0) && (forceFlag==0)) {
171         /* test if file exists already and no forcing*/
172             if ((outputCFile = fopen (outputCName,"r"))!=0)
173                 AbEnd("file %s already exists, aborting\n", outputCName);
174         }
175     if ((outputCFile = fopen (outputCName,outputCMode))==0)
176             AbEnd("can't open file %s for writing: %s\n",outputCName,strerror (errno));
177     if (CFnum==0) {
178                 outputCMode[0]='a';
179                 printCHeader();
180                 CFnum++;
181         }
182 }
183
184 void openSFile (void) {
185     if ((SFnum==0) && (forceFlag==0)) {
186         /* test if file exists already and no forcing*/
187             if ((outputSFile = fopen (outputSName,"r"))!=0)
188                 AbEnd("file %s already exists, aborting\n", outputSName);
189         }
190     if ((outputSFile = fopen (outputSName,outputSMode))==0)
191              AbEnd("can't open file %s for writing: %s\n",outputSName,strerror (errno));
192     if (SFnum==0) {
193                 outputSMode[0]='a';
194                 printSHeader();
195                 SFnum++;
196         }
197 }
198
199 void openVFile (void) {
200     if ((VFnum==0) && (forceFlag==0)) {
201         /* test if file exists already and no forcing*/
202             if ((outputVFile = fopen (outputVName,"r"))!=0)
203                 AbEnd("file %s already exists, aborting\n", outputVName);
204         }
205     if ((outputVFile = fopen (outputVName,outputVMode))==0)
206              AbEnd("can't open file %s for writting: %s\n",outputVName,strerror (errno));
207     if (VFnum==0) {
208                 outputVMode[0]='a';
209                 printVHeader();
210                 VFnum++;
211         }
212 }
213
214 void printUsage (void) {
215     printf("Usage: %s [options] file\n"
216            "Options:\n"
217            "\t-h, -?\t\tthis help\n"
218            "\t-f\t\tforce writting files\n"
219            "\t-o name\t\tname C output file\n"
220            "\t-s name\t\tname asm output file\n"
221            "\t-l name\t\tname ld65 config output file (for vlir)\n"
222            "Or as VLIR linker: %s -vlir output.cvt header [vlir0] ... [blank] ... [vlir_n]\n",
223            ProgName,ProgName);
224 }
225
226 int findToken (const char **tokenTbl, const char *token) {
227 /* takes as input table of tokens and token, returns position in table or -1 if not found */
228 int a=0;
229
230     while (strlen(tokenTbl[a])!=0) {
231                 if (strcmp(tokenTbl[a],token)==0) break;
232                 a++;
233     }
234     if (strlen(tokenTbl[a])==0) a=-1;
235     return a;
236 }
237
238 char *nextPhrase() {
239     return strtok(NULL, "\"");
240     }
241
242 char *nextWord() {
243     return strtok(NULL, " ");
244     }
245
246 void setLen (char *name, unsigned len) {
247     if (strlen(name)>len)
248         name[len]='\0';
249 }
250
251 void fillOut (char *name, int len, char *filler) {
252 int a;
253     setLen (name, len);
254     fprintf(outputSFile, ".byte \"%s\"\n\t\t", name);
255     a = len - strlen(name);
256     if (a!=0) {
257         fprintf(outputSFile, ".byte %s", filler);
258         while (--a!=0) fprintf(outputSFile, ", %s", filler);
259         fprintf(outputSFile, "\n\t\t");
260         }
261 }
262
263 char *bintos(unsigned char a, char out[7]) {
264 int i=0;
265     for (;i<8;i++) {
266     out[7-i] = ((a & 1)==0) ? '0' : '1';
267     a = a >> 1; };
268     out[i]='\0';
269 return out;
270 }
271
272 int getNameSize (const char *word) {
273 /* count length of a word using BSW 9 font table */
274 int a=0, i=0;
275
276     while (word[i]!='\0') {
277         a+=(BSWTab[word[i]-31] - BSWTab[word[i]-32]); i++; }
278
279     return a;
280 }
281
282 void DoMenu (void) {
283
284 int a, size, tmpsize, item=0;
285 char *token;
286 char namebuff[255]="";
287 struct menu myMenu;
288 struct menuitem *curItem, *newItem;
289
290     openCFile();
291
292     myMenu.name=nextWord();
293     myMenu.left=atoi(nextWord());
294     myMenu.top=atoi(nextWord());
295     myMenu.type=nextWord();
296
297     if (strcmp(nextWord(),"{")!=0) {
298         AbEnd ("menu '%s' description has no opening bracket!\n", myMenu.name);
299         };
300     curItem=malloc(sizeof(struct menuitem));
301     myMenu.item=curItem;
302     do {
303         token = nextWord();
304         if (strcmp(token,"}")==0) break;
305         if (token[strlen(token)-1]!='"') {
306             strcpy (namebuff, token);
307             do {
308                 token = nextWord();
309                 strcat (namebuff, " ");
310                 strcat (namebuff, token);
311                 } while (token[strlen(token)-1]!='"');
312             token = malloc(strlen(namebuff));
313             strcpy (token, namebuff);
314         }
315         curItem->name=token;
316         curItem->type=nextWord();
317         curItem->target=nextWord();
318         newItem=malloc(sizeof(struct menuitem));
319         curItem->next=newItem;
320         curItem=newItem;
321         item++;
322         } while (strcmp(token,"}")!=0);
323     if (item==0) AbEnd ("menu '%s' has 0 items!\n", myMenu.name);
324     if (item>31) AbEnd ("menu '%s' has too many items!\n", myMenu.name);
325
326     curItem->next=NULL;
327
328     /* Count menu sizes */
329
330     size=0;
331     curItem=myMenu.item;
332     if (strstr(myMenu.type,"HORIZONTAL")!=NULL) {
333         /* menu is HORIZONTAL, ysize=15, sum xsize of all items +~8?*/
334             myMenu.bot=myMenu.top+15;
335             for (a=0;a!=item;a++) {
336                 size+=getNameSize(curItem->name);
337                 curItem=curItem->next;
338                 };
339         } else {
340         /* menu is VERTICAL, ysize=item*15, count largest xsize of all items +~8? */
341             myMenu.bot=myMenu.top+(14*item);
342             for (a=0;a!=item;a++) {
343                 tmpsize=getNameSize(curItem->name);
344                 size = (size > tmpsize) ? size : tmpsize;
345                 curItem=curItem->next;
346                 };
347         };
348     myMenu.right=myMenu.left+size-1;
349
350     curItem=myMenu.item;
351     for (a=0;a!=item;a++) {
352         /* print prototype only if MENU_ACTION or DYN_SUB_MENU are present in type */
353         if ((strstr(curItem->type, "MENU_ACTION")!=NULL) || (strstr(curItem->type, "DYN_SUB_MENU")!=NULL))
354             fprintf(outputCFile, "void %s (void);\n", curItem->target);
355         curItem=curItem->next;
356         }
357
358     fprintf(outputCFile, "\nconst void %s = {\n\t(char)%i, (char)%i,\n\t(int)%i, (int)%i,\n\t"
359             "(char)(%i | %s),\n", myMenu.name, myMenu.top, myMenu.bot, myMenu.left,
360             myMenu.right, item, myMenu.type);
361
362     curItem=myMenu.item;
363     for (a=0;a!=item;a++) {
364         fprintf(outputCFile, "\t%s, (char)%s, (int)", curItem->name, curItem->type);
365         if ((strstr(curItem->type, "SUB_MENU")!=NULL) && (strstr(curItem->type, "DYN_SUB_MENU")==NULL))
366             fprintf(outputCFile, "&");
367         fprintf(outputCFile, "%s,\n", curItem->target);
368         curItem=curItem->next;
369         }
370
371     fprintf(outputCFile, "\t};\n\n");
372
373     if (fclose (outputCFile)!=0)
374         AbEnd("error closing %s: %s\n",outputCName,strerror (errno));
375 }
376
377 void DoHeader (void) {
378
379 time_t t;
380 struct tm *my_tm;
381
382 struct appheader myHead;
383 char *token;
384 char i1[9], i2[9], i3[9];
385 int a, b;
386
387     openSFile();
388
389     token = nextWord();
390
391     a = findToken (hdrFTypes, token);
392
393     if (a>1)
394            AbEnd("filetype '%s' is not supported yet\n", token);
395
396     switch (a) {
397         case 0: myHead.geostype = 6; break;
398         case 1: myHead.geostype = 14; break;
399         }
400
401     myHead.dosname = nextPhrase();
402     nextPhrase();
403     myHead.classname = nextPhrase();
404     nextPhrase();
405     myHead.version = nextPhrase();
406
407     /* put default values into myHead here */
408     myHead.author = "cc65";
409     myHead.info = "Program compiled with cc65 and GEOSLib.";
410     myHead.dostype = 128+3;
411     myHead.structure = 0;
412     myHead.mode = 0;
413
414     t = time(NULL);
415     my_tm = localtime (&t);
416
417     myHead.year = my_tm->tm_year;
418     myHead.month = my_tm->tm_mon+1;
419     myHead.day = my_tm->tm_mday;
420     myHead.hour = my_tm->tm_hour;
421     myHead.min = my_tm->tm_min;
422
423     if (strcmp(nextWord(),"{")!=0)
424                 AbEnd ("header '%s' has no opening bracket!\n", myHead.dosname);
425
426     do {
427         token=nextWord();
428         if (strcmp(token, "}")==0) break;
429         switch (a = findToken (hdrFields, token)) {
430                 case -1:
431                     AbEnd ("unknown field '%s' in header '%s'\n", token, myHead.dosname);
432                     break;
433                 case 0: /* author */
434                     myHead.author = nextPhrase(); break;
435                 case 1: /* info */
436                     myHead.info = nextPhrase(); break;
437                 case 2: /* date */
438                     myHead.year = atoi(nextWord());
439                     myHead.month = atoi(nextWord());
440                     myHead.day = atoi(nextWord());
441                     myHead.hour = atoi(nextWord());
442                     myHead.min = atoi(nextWord());
443                     break;
444                 case 3: /* dostype */
445                     switch (b = findToken (hdrDOSTp, nextWord())) {
446                         case -1:
447                             AbEnd ("unknown dostype in header '%s'\n", myHead.dosname);
448                             break;
449                         default:
450                             myHead.dostype = b/2 + 128 + 1;
451                             break;
452                     }
453                     break;
454                 case 4: /* mode */
455                     switch (b = findToken (hdrModes, nextWord())) {
456                         case -1:
457                             AbEnd ("unknown mode in header '%s'\n", myHead.dosname);
458                         case 0:
459                             myHead.mode = 0x40; break;
460                         case 1:
461                             myHead.mode = 0x00; break;
462                         case 2:
463                             myHead.mode = 0xc0; break;
464                         case 3:
465                             myHead.mode = 0x80; break;
466                     }
467                     break;
468                 case 5: /* structure */
469                     switch (b = findToken(hdrStructTp, nextWord())) {
470                         case -1:
471                             AbEnd ("unknown structure type in header '%s'\n", myHead.dosname);
472                         case 0:
473                         case 1:
474                             myHead.structure = 0; break;
475                         case 2:
476                         case 3:
477                             myHead.structure = 1; break;
478                     }
479                     break;
480         }
481
482     } while (strcmp(token, "}")!=0);
483
484     /* OK, all information is gathered, do flushout */
485
486     fprintf(outputSFile,
487          "\t\t\t.segment \"HEADER\"\n\n\t\t.byte %i\n\t\t.word 0\n\t\t", myHead.dostype);
488
489     fillOut(myHead.dosname,16,"$a0");
490
491     fprintf(outputSFile,
492         ".word 0\n\t\t.byte %i\n\t\t.byte %i\n\t\t.byte %i, %i, %i, %i, %i\n\n\t\t"
493         ".word 0\n\t\t.byte \"PRG formatted GEOS file V1.0\"\n\n\t\t.res $c4\n\n\t\t"
494         ".byte 3, 21, 63 | $80\n\t\t",
495         myHead.structure, myHead.geostype, myHead.year, myHead.month, myHead.day,
496         myHead.hour, myHead.min);
497
498     for (a=0;a!=63;a=a+3) {
499         fprintf(outputSFile,
500              ".byte %%%s, %%%s, %%%s\n\t\t",
501              bintos(icon1[a], i1), bintos(icon1[a+1], i2), bintos(icon1[a+2], i3)); };
502
503     fprintf(outputSFile,
504             "\n\t\t.byte %i, %i, %i\n\t\t.word $0400, $0400-1, $0400\n\n\t\t",
505             myHead.dostype, myHead.geostype, myHead.structure);
506
507     fillOut(myHead.classname,12,"$20");
508
509     fillOut(myHead.version,4,"0");
510
511     fprintf(outputSFile,
512             ".byte 0, 0, 0\n\t\t.byte %i\n\n\t\t", myHead.mode);
513
514     setLen(myHead.author,62);
515     fprintf(outputSFile,
516             ".byte \"%s\"\n\t\t.byte 0\n\t\t.res (63-%i)\n\n\t\t",
517             myHead.author, (int) (strlen(myHead.author)+1));
518
519     setLen(myHead.info, 95);
520     fprintf(outputSFile,
521             ".byte \"%s\"\n\t\t.byte 0\n\t\t.res (96-%i)\n\n",
522             myHead.info, (int) (strlen(myHead.info)+1));
523
524     if (fclose (outputSFile)!=0)
525                 AbEnd("error closing %s: %s\n",outputSName,strerror (errno));
526
527 }
528
529 void DoVLIR (void) {
530
531 char *token;
532 char *headname;
533 int i,numchains,vlirbase;
534 struct vlirentry {
535     char *chainname;
536     int exist;
537 };
538
539 struct vlirentry vlirtable[127];
540
541     openVFile();
542
543     headname = nextWord();
544
545     vlirbase = strtol(nextWord(),NULL,0);
546
547     if (strcmp(nextWord(),"{")!=0)
548                 AbEnd ("VLIR description has no opening bracket!\n");
549
550     numchains=0;
551
552     do {
553         token=nextWord();
554         if (strcmp(token, "}")==0) break;
555         numchains++;
556         if (numchains>127) {
557             AbEnd("Too many VLIR chains!\n");
558         }
559         vlirtable[numchains].chainname=token;
560
561         /* for first chain - name header */
562         if (numchains==1) {
563           fprintf(outputVFile,"MEMORY {\n\tHEADER: start = $204, size = 508, file = \"%s\";\n"
564             "\tVLIR0: start = $0400, size = $5C00, file = \"%s\";\n",headname,token);
565         } else {
566         /* for all other - segment */
567           /* ignore non-existing segments */
568           vlirtable[numchains].exist=1;
569           if ( (strcmp(token,"blank")==0) || (strcmp(token,"noexist")==0) ) {
570             vlirtable[numchains].exist=0;
571             fprintf(outputVFile,"#");
572           }
573           fprintf(outputVFile,"\tVLIR%i: start = $%x, size = $%x, file = \"%s\";\n",
574             numchains-1,vlirbase,0x5c00-vlirbase,token);
575         }
576
577     } while (strcmp(token, "}")!=0);
578     fprintf(outputVFile,"}\n\n");
579
580     if (numchains==0) {
581         AbEnd("There must be at least one VLIR chain.\n");
582     };
583
584     /* now put segments info */
585     fprintf(outputVFile,"SEGMENTS {\n\tHEADER: load = HEADER, type = ro;\n"
586         "\tCODE: load = VLIR0, type = ro;\n"
587         "\tRODATA: load = VLIR0, type = ro;\n"
588         "\tDATA: load = VLIR0, type = rw;\n"
589         "\tBSS: load = VLIR0, type = bss, define = yes;\n\n");
590
591     for (i=2;i<=numchains;i++) {
592         if (vlirtable[i].exist==0) {
593             fprintf(outputVFile,"#");
594         }
595         fprintf(outputVFile,"\tVLIR%i: load = VLIR%i, type = rw, define = yes;\n",i-1,i-1);
596     }
597     fprintf(outputVFile,"}\n");
598
599     /* now put usage info */
600     fprintf(outputVFile,"\n# ld65 -o output.cvt -C %s file1.o file2.o ...",outputVName);
601     fprintf(outputVFile,"\n# grc -vlir outputname %s",headname);
602     for (i=1;i<=numchains;i++) {
603         fprintf(outputVFile," %s",vlirtable[i].chainname);
604     }
605     fprintf(outputVFile,"\n");
606
607     if (fclose (outputVFile)!=0)
608                 AbEnd("error closing %s: %s\n",outputVName,strerror (errno));
609 }
610
611 char *filterInput (FILE *F, char *tbl) {
612 /* loads file into buffer filtering it out */
613 int a, prevchar=-1, i=0, bracket=0, quote=1;
614
615     while (1) {
616         a = getc(F);
617         if ((a=='\n')||(a=='\015')) a = ' ';
618         if (a==',' && quote) a = ' ';
619         if (a=='\042') quote=!quote;
620         if (quote) {
621             if ((a=='{')||(a=='(')) bracket++;
622             if ((a=='}')||(a==')')) bracket--;
623         }
624         if (a==EOF) { tbl[i]='\0'; realloc(tbl, i+1); break; };
625         if (IsSpace(a)) {
626             if ((prevchar!=' ') && (prevchar!=-1)) { tbl[i++]=' '; prevchar=' '; }
627         } else {
628             if (a==';' && quote) { do { a = getc (F); } while (a!='\n'); fseek(F,-1,SEEK_CUR); }
629                 else {
630                     tbl[i++]=a; prevchar=a; }
631         }
632     }
633
634     if (bracket!=0) AbEnd("there are unclosed brackets!\n");
635
636     return tbl;
637 }
638
639 void processFile (const char *filename) {
640
641 FILE *F;
642
643 char *str;
644 char *token;
645
646 int head=0;     /* number of processed HEADER sections */
647 int vlir=0;     /* number of processed VLIR sections */
648
649     if ((F = fopen (filename,"r"))==0)
650                 AbEnd("can't open file %s for reading: %s\n",filename,strerror (errno));
651
652     str=filterInput(F, malloc(BLOODY_BIG_BUFFER));
653
654     token = strtok (str," ");
655
656     do {
657         if (str!=NULL) {
658             switch (findToken (mainToken, token)) {
659
660             case 0: DoMenu(); break;
661             case 1:
662                 if (++head!=1) {
663                         AbEnd ("more than one HEADER section, aborting.\n");
664                     } else {
665                         DoHeader();
666                     }
667                 break;
668             case 2: break;      /* icon not implemented yet */
669             case 3: break;      /* dialog not implemented yet */
670             case 4:
671                 if (++vlir!=1) {
672                         AbEnd ("more than one VLIR section, aborting.\n");
673                 } else {
674                         DoVLIR();
675                 }
676                 break;
677             default: AbEnd ("unknown section %s.\n",token); break;
678             }
679         }
680         token = nextWord();
681     } while (token!=NULL);
682 }
683
684 int main(int argc, char *argv[]) {
685
686 int ffile=0, i=1;
687
688     ProgName = argv[0];
689     while (i < argc) {
690         const char *arg = argv[i];
691         if (arg[0] == '-') {
692             switch (arg[1]) {
693                 case 'f':
694                     forceFlag=1;
695                     break;
696                 case 'o':
697                     outputCName=argv[++i];
698                     break;
699                 case 's':
700                     outputSName=argv[++i];
701                     break;
702                 case 'l':
703                     outputVName=argv[++i];
704                     break;
705                 case 'h':
706                 case '?':
707                     printUsage();
708                     exit (EXIT_SUCCESS);
709                     break;
710                 case 'v':
711                     if (strcmp(arg,"-vlir")==0) {
712                         VLIRLinker(argc,argv);
713                         exit (EXIT_SUCCESS);
714                         break;
715                     } else {
716                         AbEnd("unknown option %s\n",arg);
717                         break;
718                     }
719                 default: AbEnd("unknown option %s\n",arg);
720             }
721         } else {
722             ffile++;
723
724                 if (outputCName==NULL)
725                         outputCName = MakeFilename(arg,".h");
726                 if (outputSName==NULL)
727                         outputSName = MakeFilename(arg,".s");
728                 if (outputVName==NULL)
729                         outputVName = MakeFilename(arg,".cfg");
730
731             processFile(arg);
732
733             }
734         i++;
735         }
736     if (ffile==0) AbEnd("no input file\n");
737
738     return EXIT_SUCCESS;
739 }