1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
|
#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 %d: %s\n", timestamp, list[i]->date.tm_hour, list[i]->title);
}
}
int
main(int argc, char *argv[])
{
struct gemlog_entry **log;
char *aflag;
char *hflag;
char *iflag;
int ch;
aflag = NULL;
hflag = NULL;
iflag = NULL;
while ((ch = getopt(argc, argv, "a:h:i:")) != -1) {
switch (ch) {
case 'a':
aflag = optarg;
break;
case 'h':
hflag = optarg;
break;
case 'i':
iflag = optarg;
break;
default:
fprintf(stderr, "Usage: %s [-a file] [-h path] path\n", argv[0]);
return 1;
}
}
if (optind >= argc) {
fprintf(stderr, "Usage: %s [-a file] [-h path] path\n", argv[0]);
return 1;
}
log = gemlog_readdir(argv[optind]);
if (log == NULL)
err(1, "gemlog_readdir");
if (!aflag && !hflag && !iflag)
_print_gemlog(log);
// if (aflag) {
// if (gemlog_write_atom(log, aflag) == -1)
// err(1, "gemlog_write_atom");
// }
if (hflag) {
if (gemlog_write_html(log, hflag) == -1)
err(1, "gemlog_write_html");
}
if (iflag) {
if (gemlog_write_index(log, iflag) == -1)
err(1, "gemlog_write_index");
}
gemlog_entry_list_free(log);
return 0;
}
|