From d8aac6a1bba5c38ed931d3ce908037aa96eccf66 Mon Sep 17 00:00:00 2001 From: Marcin Zelent Date: Mon, 5 Mar 2018 15:23:15 +0100 Subject: Printing timesheets directory in archive view. --- timetracker.c | 27 ++++++++++++++++++++------- 1 file changed, 20 insertions(+), 7 deletions(-) (limited to 'timetracker.c') diff --git a/timetracker.c b/timetracker.c index 2a6c416..ddd4063 100644 --- a/timetracker.c +++ b/timetracker.c @@ -191,15 +191,28 @@ void print_archive(WINDOW *win) { DIR *d; struct dirent *dir; - int i = 1; + int i = 0, j = 1, n = 0; + char tdir[80]; + + snprintf(tdir, sizeof(tdir), "%s/Timesheets", getenv("HOME")); - d = opendir("."); + d = opendir(tdir); if (d) { - while ((dir = readdir(d)) != NULL) { - mvwprintw(win, i + 3, 1, "%s", dir->d_name); - i++; - } - closedir(d); + while ((dir = readdir(d)) != NULL) + if (strcmp(dir->d_name, "timesheet") > 8) n++; + char files[n][25]; + rewinddir(d); + while ((dir = readdir(d)) != NULL) + if (strcmp(dir->d_name, "timesheet") > 8) { + strcpy(files[i], dir->d_name); + i++; + } + while (j < LINES - 5) { + mvwprintw(win, j + 3, 1, "%s", files[n - 1]); + j++; + n--; + } + closedir(d); } } -- cgit v1.2.3