From bf787c2d6da2a4f1808bffa98eed45e48988326d Mon Sep 17 00:00:00 2001 From: nova Date: Wed, 1 May 2024 22:24:44 +0200 Subject: [PATCH] better parameters (in output, not code) --- main.c | 51 +++++++++++++++++++++++++++++++++++++++------------ 1 file changed, 39 insertions(+), 12 deletions(-) diff --git a/main.c b/main.c index a87a59b..02db592 100644 --- a/main.c +++ b/main.c @@ -46,7 +46,7 @@ int main(int argc, char **argv) { } } - printf("\n%u trytes\n\n", size); + printf("\nfilesize: %u trytes\n\n", size); // Close the file @@ -57,31 +57,59 @@ int main(int argc, char **argv) { } int params(int argc, char **argv){ + //{{{ + printf("%s\n", *argv); + char in = 0; + char out = 0; + char ret = 1; if (argc > 2) { for (int i = 1 ; i < argc; i++) { if (strcmp("-i", argv[i]) == 0 || strcmp("--input", argv[i]) == 0) { - src_asm = fopen(argv[i+1], "r"); - i=i+1; + if (argv[i+1]==NULL) { + //empty + } else { + in = 1; + if((src_asm = fopen(argv[i+1],"r"))!=NULL) { + //src_asm = fopen(argv[i+1], "r"); + i=i+1; + ret = 0; + } else { + printf("tasm: file '%s' does not exist \n", argv[i+1]); + ret = 1; + } + } } else if (strcmp("-o", argv[i]) == 0 || strcmp("--output", argv[i]) == 0) { - dest_asm = fopen(argv[i+1], "w"); - i=i+1; + if (argv[i+1]==NULL) { + //empty + } else { + dest_asm = fopen(argv[i+1], "w"); + i=i+1; + out = 1; + ret = 0; + } } else if (strcmp("-h", argv[i]) == 0 || strcmp("--help", argv[i]) == 0) { printf("Usage: tasm [options] file...\n"); printf("Options:\n"); printf("-h,--help Prints this information\n"); printf("-i,--input Path of input file\n"); printf("-o,--output Path of output file\n"); - return 1; } else { printf("unknown argument: %s\n", argv[i]); - return 1; } } - } else { - printf("tasm: no input file\n"); - return 1; } - return 0; + if (in == 0) { + printf("tasm: no input file\n"); + ret = 1; + } else { + if (out == 0) { + printf("tasm: no output file, using default: output\n\n"); + dest_asm = fopen("output", "w"); + } + } + + return ret; + //}}} } void asm_to_hex(char *_asm, int *opcode, int *in0, int *in1, int *out){ @@ -117,7 +145,6 @@ void asm_to_hex(char *_asm, int *opcode, int *in0, int *in1, int *out){ t0[i] = tryte[j]; j++; } - printf("%s\n",t0); bin_to_hex(t0, opcode); bin_to_hex(t1, in0);