Skip to content

Commit

Permalink
Adding a general --help command
Browse files Browse the repository at this point in the history
  • Loading branch information
QuickWrite committed Dec 9, 2024
1 parent c20a3b3 commit 05ebcd8
Showing 1 changed file with 23 additions and 0 deletions.
23 changes: 23 additions & 0 deletions main.c
Original file line number Diff line number Diff line change
Expand Up @@ -87,13 +87,31 @@ str2int_errno str2int(int *out, const char *s, int base) {
return STR2INT_SUCCESS;
}

void print_help(void) {
printf(
"\033[1;4mTAU Help\033[0m\n\n"
"\033[3;4mGeneral command syntax:\033[0m\n"
" ./tau <filename>\n\n"
"\033[3;4mFlags:\033[0m\n"
" --help Prints this help message.\n"
" --view-width Sets the amount of cells that are being printed.\n"
" \033[2m(default: 9)\033[0m\n"
" --max-iter Sets the maximum amount of iterations the Turing Machine can do.\n"
" \033[2m(default: 5000)\033[0m\n"
);
}

int check_long(struct Arguments* arguments, const int argc, const char** const argv) {
if(argc == 0) {
// error
return 0;
}

if(strcmp(&argv[0][2], "help") == 0) {
print_help();
exit(EXIT_SUCCESS);
}

int second;
if(str2int(&second, argv[1], 10) != STR2INT_SUCCESS) {
fprintf(stderr, "\033[31mThe content of the flag has to be a number.\033[0m\n");
Expand Down Expand Up @@ -160,6 +178,11 @@ int main(const int argc, const char** const argv) {
.max_iter = 5000
};

if(strcmp(argv[1], "--help") == 0) {
print_help();
return 0;
}

if(argc > 2 && !parse_arguments(&arguments, argc, argv)) {
fprintf(stderr, "Something went wrong: Aborting.\n");
return 10;
Expand Down

0 comments on commit 05ebcd8

Please sign in to comment.