#include <stdio.h>
#include <glob.h>
#include "xml.h"
-#include "feierabend.h"
#include "worktime.h"
#include "break.h"
#include "time_format.h"
-#include "feierabend.h"
#define MAX_STRING_LENGTH 36
#define CHUCK_SIZE 32
mem->data = NULL;
}
-void allocChunk(memFile* mem)
+void alloc_chunk(memFile* mem)
{
mem->size += CHUCK_SIZE;
char* tmpmem = realloc(mem->data, sizeof(char) * mem->size);
mem->data = tmpmem;
}
-void shrinkMem(size_t readed, memFile* mem)
+void shrink_mem(size_t readed, memFile* mem)
{
mem->size = readed;
char* tmpmem = realloc(mem->data, sizeof(char) * mem->size);
if (buf == NULL)
return;
- allocChunk(mem);
+ alloc_chunk(mem);
size_t read_size = 0;
uint8_t current_chunk = CHUCK_SIZE;
while(fread(buf, sizeof(char), 1, stdin) != 0) {
read_size++;
current_chunk--;
if (current_chunk == 0) {
- allocChunk(mem);
+ alloc_chunk(mem);
current_chunk = CHUCK_SIZE;
}
}
- shrinkMem(read_size, mem);
+ shrink_mem(read_size, mem);
free(buf);
buf = NULL;
uint8_t end_min,
time_t last_saldo)
{
- feierabend* fabend = feierabend_init();
+ const time_t now = time(NULL);
+ const struct tm* tmp_now = gmtime(&now);
+ struct tm begin_tm;
+ struct tm end_tm;
+ memcpy(&begin_tm, tmp_now, sizeof(struct tm));
+ memcpy(&end_tm, tmp_now, sizeof(struct tm));
+ if (date != NULL) {
+ begin_tm.tm_year = get_year_from_str(date) - 1900;
+ begin_tm.tm_mon = get_month_from_str(date) - 1;
+ begin_tm.tm_mday = get_day_from_str(date);
+ end_tm.tm_year = get_year_from_str(date) - 1900;
+ end_tm.tm_mon = get_month_from_str(date) - 1;
+ end_tm.tm_mday = get_day_from_str(date);
+ }
+ begin_tm.tm_hour = begin_hour;
+ begin_tm.tm_min = begin_min;
+ end_tm.tm_hour = end_hour;
+ end_tm.tm_min = end_min;
+ const time_t begin = mktime(&begin_tm);
+ const time_t end = mktime(&end_tm);
+ const time_t brutto_worktime = get_brutto_worktime(begin, end);
+ const time_t netto_worktime = get_current_worktime(begin, end);
+ const time_t overtime = get_current_worktime_diff_to_end_eight_hour(begin, end);
+ const time_t breaktime = get_break_time(brutto_worktime);
+ const time_t updated_saldo = last_saldo + (overtime * -1);
+
xmlChar* xmlElemName = NULL;
xmlChar* xmlElemContent = NULL;
free(xmlElemName);
xmlElemName = NULL;
- time(&fabend->now);
- const struct tm* tmp_now = gmtime(&fabend->now);
- memcpy(fabend->now_tm, tmp_now, sizeof(struct tm));
- if (date != NULL) {
- fabend->now_tm->tm_year = get_year_from_str(date) - 1900;
- fabend->now_tm->tm_mon = get_month_from_str(date) - 1;
- fabend->now_tm->tm_mday = get_day_from_str(date);
- }
- fabend->now_tm->tm_hour = end_hour;
- fabend->now_tm->tm_min = end_min;
- fabend->now = mktime(fabend->now_tm);
- char* value = get_short_weekday(fabend->now_tm->tm_wday);
+ char* value = get_short_weekday(end_tm.tm_wday);
xmlElemName = xmlCharStrdup("wochentag");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
value = malloc(sizeof(char) * MAX_STRING_LENGTH);
sprintf(value, "%04d-%02d-%02d",
- fabend->now_tm->tm_year + 1900,
- fabend->now_tm->tm_mon + 1,
- fabend->now_tm->tm_mday);
+ begin_tm.tm_year + 1900,
+ begin_tm.tm_mon + 1,
+ begin_tm.tm_mday);
xmlElemName = xmlCharStrdup("datum");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
free(xmlElemContent);
xmlElemContent = NULL;
- time(&fabend->begin);
- const struct tm* tmp_begin = gmtime(&fabend->begin);
- memcpy(fabend->begin_tm, tmp_begin, sizeof(struct tm));
- if (date != NULL) {
- fabend->begin_tm->tm_year = get_year_from_str(date) - 1900;
- fabend->begin_tm->tm_mon = get_month_from_str(date) - 1;
- fabend->begin_tm->tm_mday = get_day_from_str(date);
- }
- fabend->begin_tm->tm_hour = begin_hour;
- fabend->begin_tm->tm_min = begin_min;
sprintf(value, "%02d:%02d",
- fabend->begin_tm->tm_hour,
- fabend->begin_tm->tm_min);
- fabend->begin = mktime(fabend->begin_tm);
+ begin_tm.tm_hour,
+ begin_tm.tm_min);
xmlElemName = xmlCharStrdup("begin");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
free(xmlElemContent);
xmlElemContent = NULL;
- fabend->worktime = get_eight_hour_end_worktime(fabend->begin);
- const struct tm* tmp_work_end = gmtime(&fabend->worktime);
- memcpy(fabend->work_end_tm, tmp_work_end, sizeof(struct tm));
- if (date != NULL) {
- fabend->work_end_tm->tm_year = get_year_from_str(date) - 1900;
- fabend->work_end_tm->tm_mon = get_month_from_str(date) - 1;
- fabend->work_end_tm->tm_mday = get_day_from_str(date);
- }
- fabend->work_end_tm->tm_hour = end_hour;
- fabend->work_end_tm->tm_min = end_min;
sprintf(value, "%02d:%02d",
- fabend->work_end_tm->tm_hour,
- fabend->work_end_tm->tm_min);
+ end_tm.tm_hour,
+ end_tm.tm_min);
xmlElemName = xmlCharStrdup("ende");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
free(xmlElemContent);
xmlElemContent = NULL;
- fabend->worktime = get_brutto_worktime(fabend->begin, fabend->now);
- time_t breaktime = get_break_time(fabend->worktime);
get_time_str(breaktime, value);
xmlElemName = xmlCharStrdup("pause");
xmlElemContent = xmlCharStrdup(value);
free(xmlElemContent);
xmlElemContent = NULL;
- fabend->worktime = get_current_worktime(fabend->begin, fabend->now);
- get_time_str(fabend->worktime, value);
+ get_time_str(netto_worktime, value);
xmlElemName = xmlCharStrdup("arbeitszeit");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
free(xmlElemContent);
xmlElemContent = NULL;
- fabend->worktime = get_current_worktime_diff_to_end_eight_hour(fabend->begin, fabend->now);
- get_time_str_overtime(fabend->worktime, value);
+ get_time_str_overtime(overtime, value);
xmlElemName = xmlCharStrdup("stunden");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
free(xmlElemContent);
xmlElemContent = NULL;
- fabend->worktime *= -1;
- fabend->worktime += last_saldo;
- get_time_str(fabend->worktime, value);
+ get_time_str(updated_saldo, value);
xmlElemName = xmlCharStrdup("saldo");
xmlElemContent = xmlCharStrdup(value);
xmlTextWriterWriteAttribute(xmlWriter, xmlElemName, xmlElemContent);
xmlElemContent = NULL;
free(xmlElemName);
xmlElemName = NULL;
- feierabend_free(fabend);
- free(fabend);
- fabend = NULL;
}
void createEntry(uint8_t begin_hour,