From 810b5b5bc08ff53f2537ec721deef43b951aecd2 Mon Sep 17 00:00:00 2001 From: Bastian Dehn Date: Sat, 14 Feb 2026 18:21:08 +0100 Subject: [PATCH] change params to const --- src/break.c | 2 +- src/break.h | 2 +- src/feierabend.c | 2 +- src/feierabendxml.c | 2 +- src/time_format.c | 12 ++++++------ src/time_format.h | 12 ++++++------ src/worktime.c | 28 ++++++++++++++++------------ src/worktime.h | 12 ++++++------ src/xml.c | 36 ++++++++++++++++++------------------ src/xml.h | 10 +++++----- 10 files changed, 61 insertions(+), 57 deletions(-) diff --git a/src/break.c b/src/break.c index c1c5219..1afc19f 100644 --- a/src/break.c +++ b/src/break.c @@ -10,7 +10,7 @@ #define THIRTY_MINUTES 1800 #define FOURTY_FIVE_MINITUES 2700 -time_t get_break_time(time_t worktime) +time_t get_break_time(const time_t worktime) { if (worktime > SIX_HOURS_FOURTY_FIVE_MINUTES) return FOURTY_FIVE_MINITUES; diff --git a/src/break.h b/src/break.h index 90fecf4..8f49563 100644 --- a/src/break.h +++ b/src/break.h @@ -2,6 +2,6 @@ #define BREAK_H #include -time_t get_break_time(time_t worktime); +time_t get_break_time(const time_t worktime); #endif \ No newline at end of file diff --git a/src/feierabend.c b/src/feierabend.c index 6a3f1c3..b6b778f 100644 --- a/src/feierabend.c +++ b/src/feierabend.c @@ -126,7 +126,7 @@ struct tm _init_tm_with_time(const char* hour, const char* min) return value; } -int main(int argc, const char* argv[]) +int main(const int argc, const char* argv[]) { if (argc < 3) { printf("ERROR: %s \n", argv[0]); diff --git a/src/feierabendxml.c b/src/feierabendxml.c index 995b762..2bf94b9 100644 --- a/src/feierabendxml.c +++ b/src/feierabendxml.c @@ -5,7 +5,7 @@ #include "validate.h" #include "xml.h" -int main(int argc, char* argv[]) +int main(const int argc, const char* argv[]) { if (argc < 2) { printf("ERROR: %s \n", argv[0]); diff --git a/src/time_format.c b/src/time_format.c index c7cb4f4..f546b97 100644 --- a/src/time_format.c +++ b/src/time_format.c @@ -19,7 +19,7 @@ char* _strdup(const char* str) return new_str; } -char* get_time_str(time_t timediff) +char* get_time_str(const time_t timediff) { int8_t hour = timediff / ONE_HOUR; int16_t rest_minutes = timediff % ONE_HOUR; @@ -42,12 +42,12 @@ char* get_time_str(time_t timediff) return timestr; } -char* get_time_overtime_str(time_t timediff) +char* get_time_overtime_str(const time_t timediff) { return get_time_str(timediff * -1); } -char* get_weekday_str(uint8_t wday) +char* get_weekday_str(const uint8_t wday) { switch (wday) { case 0: @@ -69,7 +69,7 @@ char* get_weekday_str(uint8_t wday) } } -char* get_weekday_short_str(uint8_t wday) +char* get_weekday_short_str(const uint8_t wday) { switch(wday) { case 0: @@ -91,7 +91,7 @@ char* get_weekday_short_str(uint8_t wday) } } -char* get_date_str(struct tm date) +char* get_date_str(const struct tm date) { char* datestr = malloc(sizeof(char) * MAX_TIME_STR_LENGTH); if (datestr == NULL) @@ -107,7 +107,7 @@ char* get_date_str(struct tm date) return datestr; } -char* get_time_str_from_tm(struct tm time) +char* get_time_str_from_tm(const struct tm time) { char* timestr = malloc(sizeof(char) * MAX_TIME_STR_LENGTH); if (timestr == NULL) diff --git a/src/time_format.h b/src/time_format.h index 5922364..2317c3c 100644 --- a/src/time_format.h +++ b/src/time_format.h @@ -4,12 +4,12 @@ #include #include -char* get_time_str(time_t timediff); -char* get_time_overtime_str(time_t timediff); -char* get_weekday_str(uint8_t wday); -char* get_weekday_short_str(uint8_t wday); -char* get_date_str(struct tm date); -char* get_time_str_from_tm(struct tm time); +char* get_time_str(const time_t timediff); +char* get_time_overtime_str(const time_t timediff); +char* get_weekday_str(const uint8_t wday); +char* get_weekday_short_str(const uint8_t wday); +char* get_date_str(const struct tm date); +char* get_time_str_from_tm(const struct tm time); time_t get_seconds_from_str(const char* timestr); uint16_t get_year_from_str(const char* date); diff --git a/src/worktime.c b/src/worktime.c index 501a413..56734db 100644 --- a/src/worktime.c +++ b/src/worktime.c @@ -4,26 +4,30 @@ #define TEN_HOURS 36000 #define ONE_DAY 86400 -time_t get_brutto_worktime(time_t begin, time_t now) +time_t get_brutto_worktime(const time_t begin, const time_t now) { - if (begin > now) - now += ONE_DAY; + time_t tmp_now = now; - return difftime(now, begin); + if (begin > tmp_now) + tmp_now += ONE_DAY; + + return difftime(tmp_now, begin); } -time_t get_current_worktime(time_t begin, time_t now) +time_t get_current_worktime(const time_t begin, const time_t now) { - if (begin > now) - now += ONE_DAY; + time_t tmp_now = now; + + if (begin > tmp_now) + tmp_now += ONE_DAY; - time_t worktime = difftime(now, begin); + time_t worktime = difftime(tmp_now, begin); worktime -= get_break_time(worktime); return worktime; } -time_t get_eight_hour_end_worktime(time_t begin) +time_t get_eight_hour_end_worktime(const time_t begin) { time_t worktime = begin + SOLL_WORKTIME; worktime += get_break_time(worktime); @@ -31,7 +35,7 @@ time_t get_eight_hour_end_worktime(time_t begin) return worktime; } -time_t get_ten_hour_end_worktime(time_t begin) +time_t get_ten_hour_end_worktime(const time_t begin) { time_t worktime = begin + TEN_HOURS; worktime += get_break_time(worktime); @@ -39,12 +43,12 @@ time_t get_ten_hour_end_worktime(time_t begin) return worktime; } -time_t get_current_worktime_diff_to_end_eight_hour(time_t begin, time_t now) +time_t get_current_worktime_diff_to_end_eight_hour(const time_t begin, const time_t now) { return SOLL_WORKTIME - get_current_worktime(begin, now); } -time_t get_current_worktime_diff_to_end_ten_hour(time_t begin, time_t now) +time_t get_current_worktime_diff_to_end_ten_hour(const time_t begin, const time_t now) { return TEN_HOURS - get_current_worktime(begin, now); } \ No newline at end of file diff --git a/src/worktime.h b/src/worktime.h index ac344cd..83f3379 100644 --- a/src/worktime.h +++ b/src/worktime.h @@ -7,11 +7,11 @@ #define ONE_MINUTE 60 #define SOLL_WORKTIME SOLL_HOUR * ONE_HOUR + SOLL_MINUTES * ONE_MINUTE -time_t get_brutto_worktime(time_t begin, time_t now); -time_t get_current_worktime(time_t begin, time_t now); -time_t get_eight_hour_end_worktime(time_t begin); -time_t get_ten_hour_end_worktime(time_t begin); -time_t get_current_worktime_diff_to_end_eight_hour(time_t begin, time_t now); -time_t get_current_worktime_diff_to_end_ten_hour(time_t begin, time_t now); +time_t get_brutto_worktime(const time_t begin, const time_t now); +time_t get_current_worktime(const time_t begin, const time_t now); +time_t get_eight_hour_end_worktime(const time_t begin); +time_t get_ten_hour_end_worktime(const time_t begin); +time_t get_current_worktime_diff_to_end_eight_hour(const time_t begin, const time_t now); +time_t get_current_worktime_diff_to_end_ten_hour(const time_t begin, const time_t now); #endif \ No newline at end of file diff --git a/src/xml.c b/src/xml.c index 3b6c672..a273306 100644 --- a/src/xml.c +++ b/src/xml.c @@ -14,8 +14,8 @@ #define MAX_STRING_LENGTH 36 #define CHUCK_SIZE 32 -memFile* _init_mem() { - memFile* mem = malloc(sizeof(memFile)); +mem_file_t* _init_mem() { + mem_file_t* mem = malloc(sizeof(mem_file_t)); if (mem == NULL) return NULL; @@ -26,12 +26,12 @@ memFile* _init_mem() { return mem; } -void free_mem(memFile* mem) { +void free_mem(mem_file_t* mem) { free(mem->data); mem->data = NULL; } -void _alloc_chunk(memFile* mem) +void _alloc_chunk(mem_file_t* mem) { mem->size += CHUCK_SIZE; char* tmpmem = realloc(mem->data, sizeof(char) * mem->size); @@ -44,7 +44,7 @@ void _alloc_chunk(memFile* mem) mem->data = tmpmem; } -void _shrink_mem(size_t readed, memFile* mem) +void _shrink_mem(const size_t readed, mem_file_t* mem) { mem->size = readed; char* tmpmem = realloc(mem->data, sizeof(char) * mem->size); @@ -57,7 +57,7 @@ void _shrink_mem(size_t readed, memFile* mem) mem->data = tmpmem; } -void _read_stdin_into_memory(memFile* mem) +void _read_stdin_into_memory(mem_file_t* mem) { char* buf = malloc(sizeof(char)); @@ -82,7 +82,7 @@ void _read_stdin_into_memory(memFile* mem) buf = NULL; } -char* _read_last_saldo(memFile* mem) +char* _read_last_saldo(mem_file_t* mem) { char* saldostr = malloc(sizeof(char) * MAX_STRING_LENGTH); if (saldostr == NULL) @@ -166,7 +166,7 @@ void _copy_entry(xmlTextReaderPtr xmlreader, xmlTextWriterPtr xmlwriter) xmlElemContent = NULL; } -struct tm _init_tm_with_date(const char* date, uint8_t hour, uint8_t min) +struct tm _init_tm_with_date(const char* date, const uint8_t hour, const uint8_t min) { struct tm value; const time_t now = time(NULL); @@ -186,11 +186,11 @@ struct tm _init_tm_with_date(const char* date, uint8_t hour, uint8_t min) void _write_entry_node(xmlTextWriterPtr xmlWriter, const char* date, - uint8_t begin_hour, - uint8_t begin_min, - uint8_t end_hour, - uint8_t end_min, - time_t last_saldo) + const uint8_t begin_hour, + const uint8_t begin_min, + const uint8_t end_hour, + const uint8_t end_min, + const time_t last_saldo) { const struct tm begin_tm = _init_tm_with_date(date, begin_hour, begin_min); const struct tm end_tm = _init_tm_with_date(date, end_hour, end_min); @@ -366,12 +366,12 @@ void init_time_acount() } void add_entry(const char* date, - uint8_t begin_hour, - uint8_t begin_min, - uint8_t end_hour, - uint8_t end_min) + const uint8_t begin_hour, + const uint8_t begin_min, + const uint8_t end_hour, + const uint8_t end_min) { - memFile* file_content = _init_mem(); + mem_file_t* file_content = _init_mem(); _read_stdin_into_memory(file_content); char* saldostr = _read_last_saldo(file_content); diff --git a/src/xml.h b/src/xml.h index e7bf2cb..a6381b3 100644 --- a/src/xml.h +++ b/src/xml.h @@ -5,14 +5,14 @@ typedef struct { char* data; size_t size; -} memFile; +} mem_file_t; void init_time_acount(); void add_entry(const char* date, - uint8_t begin_hour, - uint8_t begin_min, - uint8_t end_hour, - uint8_t end_min); + const uint8_t begin_hour, + const uint8_t begin_min, + const uint8_t end_hour, + const uint8_t end_min); void merge(const char* dir); #endif \ No newline at end of file -- 2.47.3