Skip to content

Commit 05ebcd8

Browse files
committed
Adding a general --help command
1 parent c20a3b3 commit 05ebcd8

1 file changed

Lines changed: 23 additions & 0 deletions

File tree

main.c

Lines changed: 23 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -87,13 +87,31 @@ str2int_errno str2int(int *out, const char *s, int base) {
8787
return STR2INT_SUCCESS;
8888
}
8989

90+
void print_help(void) {
91+
printf(
92+
"\033[1;4mTAU Help\033[0m\n\n"
93+
"\033[3;4mGeneral command syntax:\033[0m\n"
94+
" ./tau <filename>\n\n"
95+
"\033[3;4mFlags:\033[0m\n"
96+
" --help Prints this help message.\n"
97+
" --view-width Sets the amount of cells that are being printed.\n"
98+
" \033[2m(default: 9)\033[0m\n"
99+
" --max-iter Sets the maximum amount of iterations the Turing Machine can do.\n"
100+
" \033[2m(default: 5000)\033[0m\n"
101+
);
102+
}
90103

91104
int check_long(struct Arguments* arguments, const int argc, const char** const argv) {
92105
if(argc == 0) {
93106
// error
94107
return 0;
95108
}
96109

110+
if(strcmp(&argv[0][2], "help") == 0) {
111+
print_help();
112+
exit(EXIT_SUCCESS);
113+
}
114+
97115
int second;
98116
if(str2int(&second, argv[1], 10) != STR2INT_SUCCESS) {
99117
fprintf(stderr, "\033[31mThe content of the flag has to be a number.\033[0m\n");
@@ -160,6 +178,11 @@ int main(const int argc, const char** const argv) {
160178
.max_iter = 5000
161179
};
162180

181+
if(strcmp(argv[1], "--help") == 0) {
182+
print_help();
183+
return 0;
184+
}
185+
163186
if(argc > 2 && !parse_arguments(&arguments, argc, argv)) {
164187
fprintf(stderr, "Something went wrong: Aborting.\n");
165188
return 10;

0 commit comments

Comments
 (0)