1
0
mirror of https://github.com/RevCurtisP/C02.git synced 2025-04-22 00:37:19 +00:00

Added command line option -H

This commit is contained in:
Curtis F Kaylor 2018-02-17 14:50:43 -05:00
parent a75f5c8344
commit 6bc29d42a6
3 changed files with 54 additions and 13 deletions

37
c02.c
View File

@ -34,8 +34,6 @@ void init()
lblcnt = 0;
curcol = 0;
curlin = 0;
inpfil = srcfil;
strcpy(inpnam, srcnam);
strcpy(incdir, "../include/");
alcvar = TRUE;
inblck = FALSE;
@ -103,8 +101,8 @@ void epilog()
void compile()
{
DEBUG("Starting Compilation\n", 0);
init();
prolog();
phdrfl(); //Process Header File specified on Command Line
skpchr();
DEBUG("Parsing Code\n", 0);
while (TRUE)
@ -134,16 +132,31 @@ void usage()
exit(EXIT_FAILURE);
}
/* Parse Command Line Argument */
/* Parse Command Line Option */
int popt(int arg, int argc, char *argv[])
{
char opt; //Option
char argstr[32]; //Argument String
char opt; //Option
char optarg[32]; //Option Argument
opt = argv[arg][1];
//if strchr(opt, "i") {
//if (strlen(argv[arg] > 2)
//}
ERROR("Illegal option -%c\n", opt, EXIT_FAILURE);
strncpy (argstr, argv[arg], 31);
if (strlen(argstr) != 2)
ERROR("malformed option %s\n", argstr, EXIT_FAILURE);
opt = toupper(argstr[1]);
if (strchr("H", opt)) {
if (++arg >= argc)
ERROR("Option -%c requires an argument\n", opt, EXIT_FAILURE);
strncpy(optarg, argv[arg], 31);
}
DEBUG("Processing Command Line Option -%c\n", argstr[1]);
switch (opt) {
case 'H':
strcpy(hdrnam, optarg);
DEBUG("Header Name set to '%s'\n", hdrnam);
break;
default:
ERROR("Illegal option -%c\n", opt, EXIT_FAILURE);
}
return arg;
}
/* Parse Command Line Arguments *
@ -180,6 +193,8 @@ int main(int argc, char *argv[])
gencmt = TRUE; //Generate Assembly Language Comments
printf("C02 Compiler (C) 2012 Curtis F Kaylor\n" );
init(); //Initialize Global Variables
pargs(argc, argv); //Parse Command Line Arguments
@ -187,6 +202,8 @@ int main(int argc, char *argv[])
opnout(); //Open Output File
opnlog(); //Open Log File
setsrc(); //Set Input to Source File
compile();
logdef();

View File

@ -50,8 +50,9 @@ char word[LINELEN]; //Word parsed from source file
char uword[LINELEN]; //Word converted too uppercase
char cmtasm[LINELEN]; //Assembly Language Comment Text
char hdrnam[FNAMLEN]; //Header File Name
char incdir[FNAMLEN]; //Include File Directory
char inpnam[FNAMLEN]; //Include File Name
char inpnam[FNAMLEN]; //Input File Name
int alcvar; //Allocate Variables Flag
int inblck; //Multiline Block Flag

View File

@ -167,14 +167,26 @@ void setinc() {
alcvar = FALSE;
}
/* Set Include File Name */
void setinm(char* filext) {
strcpy(incnam, incdir);
strcat(incnam, hdrnam);
strcat(incnam, filext);
}
/* Set Input to Souyrce File */
void setsrc() {
inpfil = srcfil;
strcpy(inpnam, srcnam);
}
/* Restore Source File Pointer*/
void rstsrc() {
nxtchr = savchr;
nxtupc = toupper(nxtchr);
curcol = savcol;
curlin = savlin;
inpfil = srcfil;
strcpy(inpnam, srcnam);
setsrc();
alcvar = TRUE;
}
@ -205,6 +217,17 @@ void inchdr() {
nxtchr = savchr;
}
/* Process Header File specified on Command Line */
void phdrfl()
{
if (hdrnam[0] == 0) return;
DEBUG("Processing Header '%s'\n", hdrnam);
setinm(".h02");
inchdr();
setinm(".a02");
incasm();
}
/* Process include file */
void pincfl()
{