From fa3606a495e4df0c6231e433d3dffa19b7471a60 Mon Sep 17 00:00:00 2001 From: Joseph Hunkeler Date: Tue, 18 Jan 2022 23:04:23 -0500 Subject: Refactor project structure --- dump.c | 37 +++++++++++++++++++++++++++++++++++++ 1 file changed, 37 insertions(+) create mode 100644 dump.c (limited to 'dump.c') diff --git a/dump.c b/dump.c new file mode 100644 index 0000000..182a2b6 --- /dev/null +++ b/dump.c @@ -0,0 +1,37 @@ +#include "weekly.h" + +int dump_file(const char *filename, int style) { + FILE *fp; + fp = fopen(filename, "r"); + if (!fp) { + return -1; + } + struct Record *record; + while ((record = record_read(&fp)) != NULL) { + record_show(record, style); + record_free(record); + puts(""); + } + fclose(fp); + return 0; +} + +int dump_week(const char *root, int year, int week, int style) { + char path_week[PATH_MAX] = {0}; + char path_year[PATH_MAX] = {0}; + const int max_days = 7; + + sprintf(path_year, "%s%c%d", root, DIRSEP_C, year); + sprintf(path_week, "%s%c%d%c%d", root, DIRSEP_C, year, DIRSEP_C, week); + + if (!dir_empty(path_year)) { + return -1; + } + + for (int i = 0; i < max_days; i++) { + char tmp[PATH_MAX]; + sprintf(tmp, "%s%c%d", path_week, DIRSEP_C, i); + dump_file(tmp, style); + } + return 0; +} -- cgit