summary refs log tree commit diff stats
path: root/main.c
diff options
context:
space:
mode:
Diffstat (limited to 'main.c')
-rw-r--r--main.c66
1 files changed, 66 insertions, 0 deletions
diff --git a/main.c b/main.c
new file mode 100644
index 0000000..1d4577f
--- /dev/null
+++ b/main.c
@@ -0,0 +1,66 @@
+#include <stdio.h>
+#include <time.h>
+#include <unistd.h>
+#include <err.h>
+
+#include <gemtext.h>
+
+#include "gemlog.h"
+
+static void
+_print_gemlog(struct gemlog_entry **list)
+{
+	int i;
+	char timestamp[50];
+
+	for (i = 0; list[i] != NULL; i++) {
+		strftime(timestamp, sizeof(timestamp), "%F: ", &(list[i]->date));
+		printf("%s%s\n", timestamp, list[i]->title);
+	}
+}
+
+int
+main(int argc, char *argv[])
+{
+	struct gemlog_entry **log;
+	int aflag;
+	int hflag;
+	int ch;
+
+	aflag = 0;
+	hflag = 0;
+
+	while ((ch = getopt(argc, argv, "ah")) != -1) {
+		switch (ch) {
+		case 'a':
+			aflag = 1;
+			break;
+		case 'h':
+			hflag = 1;
+			break;
+		default:
+			fprintf(stderr, "Usage: %s <-a | -h> <path>\n", argv[0]);
+			return 1;
+		}
+	}
+
+	if (aflag && hflag)
+		errx(1, "can't have -a and -h used simultaneously");
+	if (!aflag && !hflag) {
+		fprintf(stderr, "Usage: %s <-a | -h> <path>\n", argv[0]);
+		return 1;
+	}
+	if (optind >= argc) {
+		fprintf(stderr, "Usage: %s <-a | -h> <path>\n", argv[0]);
+		return 1;
+	}
+
+	log = gemlog_readdir(argv[optind]);
+	if (log == NULL)
+		err(1, "gemlog_readdir");
+
+	_print_gemlog(log);
+
+	gemlog_entry_list_free(log);
+	return 0;
+}