11 char *pC
= NULL
; /* pointer to code */
12 char pT
[1000]; /* pointer to token */
19 printf("\n<options> <file>\n");
20 printf("<file> Filename to compile.\n");
21 printf(" Filename must end with .jack.\n");
24 void settings_init(void)
29 int main(int argc
, char *argv
[])
31 int i
, size
, file_loc
= 1;
32 char FilenameBuff
[80];
34 FILE *fpSource
, *fpDest
;
36 if(argc
< 2) { exit_error(1, "No Input Files."); usage(); }
37 /* TODO: future versions will accept more than one file */
38 if(argc
> 3) { exit_error(2, "Too Many Files Listed."); usage(); }
40 /* test for switches passed - test for location of file in argv */
44 while(-1 != (i
= getopt(argc
, argv
,
45 "-t" /* print tokenizer output */
46 "--help" /*print out usage statement */
61 if((fpSource
= fopen(argv
[file_loc
], "r")) == NULL
)
63 exit_error(3, "Cannot Open Input (Source) File");
66 strcpy(FilenameBuff
, argv
[file_loc
]);
68 /* verify filename extension */
69 if(strstr(argv
[file_loc
], "jack") == NULL
)
71 exit_error(5, "Filename Extension Not Correct."); usage();
74 /* modify output filename and then open output file */
75 pC
= strrchr(FilenameBuff
, '.');
76 if( pC
== NULL
){ exit_error(5, "Input File Has No Extension"); usage(); }
79 strcpy(pC
, "xml"); /* buffer should contain output filename */
81 if((fpDest
= fopen(FilenameBuff
, "w+")) == NULL
)
83 exit_error(6, "Cannot Open Output (Object) File");
86 fseek(fpSource
, 0, SEEK_END
); /* seek to end of file */
87 size
= ftell(fpSource
); /* get current file pointer */
88 fseek(fpSource
, 0, SEEK_SET
); /* seek back to beginning of file */
89 /* proceed with allocating memory and reading the file */
90 pS
= malloc((sizeof(char) * size
)+1);
92 if(pS
== NULL
) { exit_error(7, "Cannot Allocate Memory For Source"); }
97 pS
[i
] = getc(fpSource
);
102 pC
= pS
; /* move to beginning of source code */
103 parse_class(pS
, pC
, pT
);