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
|
#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;
}
|