12 char *pC
= NULL
; /* pointer to code */
13 char pT
[1000]; /* pointer to token */
20 printf("Usage: jack [options] file\n");
22 printf(" <file> Compile file without tokens\n");
23 printf(" Filename must end with .jack\n");
24 printf(" -h Display this information\n");
25 printf(" -t <file> Compile file and display tokens\n");
26 printf(" -u Run all unit tests\n");
29 void settings_init(void)
35 int main(int argc
, char *argv
[])
37 int i
, size
, file_loc
= 1;
38 char FilenameBuff
[80];
40 FILE *fpSource
, *fpDest
;
42 /* test for switches passed - test for location of file in argv */
44 while ((i
= getopt(argc
, argv
, "uht:")) != -1)
66 printf("\nRUNNING ALL UNIT TESTS ON COMPILER.\n\n");
69 printf("\nUNIT TEST COMPLETE - ALL TESTS RETURNED PASSED.\n\n");
71 exit_error(0, "UNIT TEST FAILED.\n\n");
76 if(argc
< 2) { exit_error(1, "No Input Files."); usage(); }
77 /* TODO: future versions will accept more than one file */
78 if(argc
> 3) { exit_error(2, "Too Many Files Listed."); usage(); }
80 if((fpSource
= fopen(argv
[file_loc
], "r")) == NULL
)
82 exit_error(3, "Cannot Open Input (Source) File");
85 strcpy(FilenameBuff
, argv
[file_loc
]);
87 /* verify filename extension */
88 if(strstr(argv
[file_loc
], "jack") == NULL
)
90 exit_error(5, "Filename Extension Not Correct."); usage();
93 /* modify output filename and then open output file */
94 pC
= strrchr(FilenameBuff
, '.');
95 if( pC
== NULL
){ exit_error(5, "Input File Has No Extension"); usage(); }
98 strcpy(pC
, "xml"); /* buffer should contain output filename */
100 if((fpDest
= fopen(FilenameBuff
, "w+")) == NULL
)
102 exit_error(6, "Cannot Open Output (Object) File");
105 fseek(fpSource
, 0, SEEK_END
); /* seek to end of file */
106 size
= ftell(fpSource
); /* get current file pointer */
107 fseek(fpSource
, 0, SEEK_SET
); /* seek back to beginning of file */
108 /* proceed with allocating memory and reading the file */
109 pS
= malloc((sizeof(char) * size
)+1);
111 if(pS
== NULL
) { exit_error(7, "Cannot Allocate Memory For Source"); }
116 pS
[i
] = getc(fpSource
);
121 pC
= pS
; /* move to beginning of source code */
122 parse_class(pS
, pC
, pT
);