Browse Source

add an argument for filenames

Yohan Simard 2 months ago
parent
commit
84c51d9446
2 changed files with 30 additions and 10 deletions
  1. 5
    3
      .gitignore
  2. 25
    7
      as.y

+ 5
- 3
.gitignore View File

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

+ 25
- 7
as.y View File

@@ -62,13 +62,31 @@ Instruction : tCPY tNB tNB     {increment_time();
62 62
 
63 63
 %%
64 64
 
65
-int main(void) {
66
-	file = fopen("output.asm", "w");
67
-	file2 = fopen("output_bin.txt", "w");
65
+#include <string.h>
66
+
67
+int main(int argc, char *argv[]) {
68
+  char *output_filename = "output_cross";
69
+
70
+  if (argc >= 2) {
71
+      output_filename = argv[1];
72
+  }
73
+
74
+  char *asm_filename = malloc(strlen(output_filename) + 5);
75
+  char *bin_filename = malloc(strlen(output_filename) + 9);
76
+  strcpy(asm_filename, output_filename);
77
+  strcpy(bin_filename, output_filename);
78
+  strcat(asm_filename, ".asm");
79
+  strcat(bin_filename, "_bin.txt");
80
+
81
+  file = fopen(asm_filename, "w");
82
+  file2 = fopen(bin_filename, "w");
68 83
   init();
69
-	yyparse();
84
+  yyparse();
70 85
   flush_and_init();
71
-	write_asm(file);
72
-	write_code_machine(file2);
73
-	return 0;
86
+  write_asm(file);
87
+  write_code_machine(file2);
88
+
89
+  free(asm_filename);
90
+  free(bin_filename);
91
+  return 0;
74 92
 }

Loading…
Cancel
Save