better parameters (in output, not code)

This commit is contained in:
nova 2024-05-01 22:24:44 +02:00
parent 46aa1e9ce9
commit bf787c2d6d
1 changed files with 39 additions and 12 deletions

51
main.c
View File

@ -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 <arg> Path of input file\n");
printf("-o,--output <arg> 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);