From 9ccb2c57c1e31b244c92baee439873e16518340e Mon Sep 17 00:00:00 2001 From: =?utf8?q?Luk=C3=A1=C5=A1=20Ji=C5=99i=C5=A1t=C4=9B?= Date: Thu, 7 Mar 2024 10:55:06 +0100 Subject: [PATCH] Implement -h flag and specific boss printing Also prepare a little for -l flag. --- TODO | 4 +++- src/main.c | 65 ++++++++++++++++++++++++++++++++++++------------------ 2 files changed, 46 insertions(+), 23 deletions(-) diff --git a/TODO b/TODO index ab7ef36..ef2b646 100644 --- a/TODO +++ b/TODO @@ -1,5 +1,7 @@ TODO give option -l the functionality described in help -implement -h flag? colored output sort available bosses by level? + +DONE +implement -h flag diff --git a/src/main.c b/src/main.c index ff61748..b20b543 100644 --- a/src/main.c +++ b/src/main.c @@ -20,7 +20,9 @@ typedef enum e_basic_command basic_kill, basic_add, basic_list, + basic_loop, basic_remove, + basic_help, } t_basic; typedef struct s_command @@ -196,11 +198,24 @@ int parse_input(t_command *command, int argc, char **argv) command->entry.name = NULL; if (argc == 1) return (0); - else if (argc == 2 && !ft_strcmp(argv[1], "-l")) + else if (argc == 2) + { + if (!ft_strcmp(argv[1], "-l")) + command->basic = basic_loop; + else if (!ft_strcmp(argv[1], "-h")) + command->basic = basic_help; + else + command->entry.name = argv[1]; + return (0); + } + else if (argc == 2) + { + command->entry.name = argv[1]; return (0); + } else if (argc == 3) { - if (ft_strcmp(argv[1], "-l") && ft_strcmp(argv[1], "-k") && ft_strcmp(argv[1], "-r")) + if (ft_strcmp(argv[1], "-k") && ft_strcmp(argv[1], "-r")) return (1); command->entry.name = argv[2]; if (argv[1][1] == 'k') @@ -247,6 +262,30 @@ int find_name_ind(t_vec *database, const char *name, size_t *ind) return (1); } +void print_help(void) +{ + static const char *helpstr = + "Palboss is a simple tracker of cooldown of bosses in Palworld\n" + "Usage:\tpalboss [option option_arguments]\n" + "\tWithout options it lists all the bosses\n" + "Options:\n" + "\tboss\n" + "\t\tPrint the info about the boss\n" + "\t-h\n" + "\t\tPrint this help.\n" + "\t-l\n" + "\t\tPrint the list in a loop. End by using Q key.\n" + "\t-k boss\n" + "\t\tMark the boss as killed, setting the counter to 60 minutes.\n" + "\t-a boss level location\n" + "\t\tAdd a boss to the database. Long strings may break formatting.\n" + "\t-r boss\n" + "\t\tRemove a boss from the database.\n"; + + ft_printf("%s", helpstr); + return ; +} + void carry_out_command(t_command *com, t_vec *database) { size_t ind; @@ -269,26 +308,8 @@ void carry_out_command(t_command *com, t_vec *database) else print_entry(ft_vec_access(database, ind)); } - return ; -} - -void print_help(void) -{ - static const char *helpstr = - "Palboss is a simple tracker of cooldown of bosses in Palworld\n" - "Usage:\tpalboss [option option_arguments]\n" - "\tWithout options it lists all the bosses\n" - "Options:\n" - "\t-l\n" - "\t\tPrint the list in a loop. End by using Q key.\n" - "\t-k boss\n" - "\t\tMark the boss as killed, setting the counter to 60 minutes.\n" - "\t-a boss level location\n" - "\t\tAdd a boss to the database. Long strings may break formatting.\n" - "\t-r boss\n" - "\t\tRemove a boss from the database.\n"; - - ft_printf("%s", helpstr); + else if (com->basic == basic_help) + print_help(); return ; } -- 2.30.2