From 1d4e2f7f3a96f4d90862cf0b6c26e62e4a0cec53 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Mon, 16 Feb 2026 20:28:22 +0100 Subject: [PATCH] change args checks in method --- src/feierabend.c | 30 ++++++++++++++++++++---------- 1 file changed, 20 insertions(+), 10 deletions(-) diff --git a/src/feierabend.c b/src/feierabend.c index 9c7f7b1..7b1eef1 100644 --- a/src/feierabend.c +++ b/src/feierabend.c @@ -129,23 +129,33 @@ struct tm _init_tm_with_time(const char* hour, const char* min) return value; } +int _few_arguments(const char* argv[]) +{ + printf("ERROR: %s \n", argv[0]); + return EXIT_FAILURE; +} + +int _invalid_arguments() +{ + printf("ERROR: one or more invalid arguments\n"); + return EXIT_FAILURE; +} + int main(const int argc, const char* argv[]) { - if (argc < 3) { - printf("ERROR: %s \n", argv[0]); - return 1; - } + if (argc < 3) + return _few_arguments(argv); - if (!validate_hourstring(argv[1]) || !validate_minutestring(argv[2])) { - printf("ERROR: one or more invalid arguments\n"); - return 1; - } + const char* hour = argv[1]; + const char* min = argv[2]; + if (!validate_hourstring(hour) || !validate_minutestring(min)) + return _invalid_arguments(); printf("Version: %s\n\n", PROJECT_VERSION); const struct tm now_tm = _init_tm_with_time(NULL, NULL); const time_t now = mktime((struct tm*) &now_tm); - const struct tm begin_tm = _init_tm_with_time(argv[1], argv[2]); + const struct tm begin_tm = _init_tm_with_time(hour, min); const time_t begin = mktime((struct tm*) &begin_tm); const time_t worktime_eight_end = get_eight_hour_end_worktime(begin); const struct tm work_eight_end_tm = _get_tm_from_time(worktime_eight_end); @@ -174,5 +184,5 @@ int main(const int argc, const char* argv[]) _print_time_to_end_worktime(diff_to_end); _print_time_to_max_end_worktime(diff_to_max_end); - return 0; + return EXIT_SUCCESS; } \ No newline at end of file -- 2.47.3