]> gitweb.hhaalo.de Git - feierabend.git/commitdiff
change args checks in method
authorBastian Dehn <hhaalo@arcor.de>
Mon, 16 Feb 2026 19:28:22 +0000 (20:28 +0100)
committerBastian Dehn <hhaalo@arcor.de>
Mon, 16 Feb 2026 19:28:40 +0000 (20:28 +0100)
src/feierabend.c

index 9c7f7b10bdabb502fd0e9910b85b6bbd15e9d80a..7b1eef1a98b18aa419bdc9d6c6a5a8a352368c36 100644 (file)
@@ -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 <begin_hours> <begin_minutes>\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 <begin_hours> <begin_minutes>\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