add an argument for filenames

This commit is contained in:
Yohan Simard 2021-05-20 11:09:56 +02:00
parent 2fbae7f7fe
commit 84c51d9446
2 changed files with 30 additions and 10 deletions

8
.gitignore vendored
View file

@ -1,6 +1,8 @@
*.o *.o
lex.yy.c lex.yy.*
as.tab.* as.tab.*
output.asm *.asm
output_bin.txt !input.asm
*.txt
cross_assembleur cross_assembleur

32
as.y
View file

@ -62,13 +62,31 @@ Instruction : tCPY tNB tNB {increment_time();
%% %%
int main(void) { #include <string.h>
file = fopen("output.asm", "w");
file2 = fopen("output_bin.txt", "w"); int main(int argc, char *argv[]) {
char *output_filename = "output_cross";
if (argc >= 2) {
output_filename = argv[1];
}
char *asm_filename = malloc(strlen(output_filename) + 5);
char *bin_filename = malloc(strlen(output_filename) + 9);
strcpy(asm_filename, output_filename);
strcpy(bin_filename, output_filename);
strcat(asm_filename, ".asm");
strcat(bin_filename, "_bin.txt");
file = fopen(asm_filename, "w");
file2 = fopen(bin_filename, "w");
init(); init();
yyparse(); yyparse();
flush_and_init(); flush_and_init();
write_asm(file); write_asm(file);
write_code_machine(file2); write_code_machine(file2);
return 0;
free(asm_filename);
free(bin_filename);
return 0;
} }