| 33 |
|
|
| 34 |
#include <err.h> |
#include <err.h> |
| 35 |
#include <errno.h> |
#include <errno.h> |
| 36 |
|
#include <fcntl.h> |
| 37 |
#include <stdint.h> |
#include <stdint.h> |
| 38 |
#include <stdio.h> |
#include <stdio.h> |
| 39 |
#include <stdlib.h> |
#include <stdlib.h> |
| 116 |
{ "VERSION", K_VERSION, KWT_NORMAL, ARGT_STRING }, |
{ "VERSION", K_VERSION, KWT_NORMAL, ARGT_STRING }, |
| 117 |
{ NULL, 0, 0, 0 } |
{ NULL, 0, 0, 0 } |
| 118 |
}; |
}; |
| 119 |
|
|
| 120 |
|
void |
| 121 |
|
pfile(const char *fn) |
| 122 |
|
{ |
| 123 |
|
struct parser_result *parsed; |
| 124 |
|
struct parser_res *entry; |
| 125 |
|
int fd; |
| 126 |
|
size_t nument; |
| 127 |
|
|
| 128 |
|
if ((fd = open(fn, O_RDONLY)) < 0) |
| 129 |
|
err(255, "cannot open input file '%s'", fn); |
| 130 |
|
printf("parsing %s…", fn); |
| 131 |
|
parsed = nfo_parse(fd, kwords); |
| 132 |
|
close(fd); |
| 133 |
|
if (CIRCLEQ_EMPTY(parsed)) |
| 134 |
|
errx(1, "error, no entries in the file!"); |
| 135 |
|
nument = 0; |
| 136 |
|
CIRCLEQ_FOREACH(entry, parsed, e) |
| 137 |
|
++nument; |
| 138 |
|
printf("ok, %zu entries\n", nument); |
| 139 |
|
|
| 140 |
|
/* do something with ‘parsed’ */ |
| 141 |
|
nument = 0; |
| 142 |
|
CIRCLEQ_FOREACH(entry, parsed, e) { |
| 143 |
|
printf("entry #%03zu: ", nument++); |
| 144 |
|
parser_dump(entry, kwords); |
| 145 |
|
} |
| 146 |
|
|
| 147 |
|
parser_free(parsed); |
| 148 |
|
} |