From 2de711957aa3575a54319a91416c6abd33b0cbba Mon Sep 17 00:00:00 2001 From: Augusto Gunsch Date: Mon, 4 Jan 2021 17:12:32 -0300 Subject: [PATCH] Fix file output (all assembly must be in one file) --- .gitignore | 2 +- main.c | 4 ++-- misc/io.c | 4 ++-- 3 files changed, 5 insertions(+), 5 deletions(-) diff --git a/.gitignore b/.gitignore index 8728a54..97d8529 100644 --- a/.gitignore +++ b/.gitignore @@ -1,2 +1,2 @@ -jack-compiler +jackc tags diff --git a/main.c b/main.c index a2ba9b3..0bdaa53 100644 --- a/main.c +++ b/main.c @@ -57,19 +57,19 @@ int main(int argc, char* argv[]) { actonunits(head, vmtranslateunit); currunit = head; + FILE* output = fopen("out.asm", "w"); while(currunit != NULL) { - FILE* output = fopen(currunit->file->outname, "w"); if(output == NULL) { eprintf("%s", strerror(errno)); exit(1); } printstrlist(currunit->asmlns, output); - fclose(output); COMPILEUNIT* next = currunit->next; freeunit(currunit); currunit = next; } + fclose(output); freecompiler(compiler); freetree(headclass); diff --git a/misc/io.c b/misc/io.c index bf09704..04a576e 100644 --- a/misc/io.c +++ b/misc/io.c @@ -93,9 +93,9 @@ bool isdir(char* f, int len) { char* getoutname(char* fullname, int len) { char* trimmed = trimstr(fullname, len, 4); - int sz = sizeof(char) * (len); + int sz = sizeof(char) * (len-1); char* outname = (char*)malloc(sz); - snprintf(outname, sz, "%sasm", trimmed); + snprintf(outname, sz, "%svm", trimmed); free(trimmed); return outname; }