Changeset 3457
- Timestamp:
- 08/09/07 15:40:07 (1 year ago)
- Files:
-
- branches/common-nfo/tools/nfotiser/extern.h (modified) (1 diff)
- branches/common-nfo/tools/nfotiser/main.c (modified) (3 diffs)
- branches/common-nfo/tools/nfotiser/nfotiser.h (modified) (1 diff)
- branches/common-nfo/tools/nfotiser/parser.c (modified) (3 diffs)
- branches/common-nfo/tools/nfotiser/pfile.c (modified) (2 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/common-nfo/tools/nfotiser/extern.h
r3444 r3457 17 17 /* dbscheme.S */ 18 18 extern const char dbscheme[]; 19 /* pfile.c */ 20 extern void pfile(const char *); 19 21 __END_DECLS 20 22 branches/common-nfo/tools/nfotiser/main.c
r3443 r3457 34 34 #include <err.h> 35 35 #include <errno.h> 36 #include <fcntl.h>37 36 #include <locale.h> 38 37 #include <stdint.h> … … 92 91 93 92 /* need at least one .nfo file to parse */ 94 //if (!argc)95 //usage();93 if (!argc) 94 usage(); 96 95 97 96 /* if the output file exists, remove it */ … … 115 114 ctp->catname, ctp->catdesc); 116 115 } 116 117 /* parse input */ 118 119 while (*argv) 120 pfile(*argv++); 117 121 118 122 /* … */ branches/common-nfo/tools/nfotiser/nfotiser.h
r3456 r3457 60 60 const struct parser_keywords *); 61 61 void parser_dump(struct parser_res *, const struct parser_keywords *); 62 void parser_free(struct parser_result *); 62 63 __END_DECLS 63 64 branches/common-nfo/tools/nfotiser/parser.c
r3456 r3457 40 40 #include <stdlib.h> 41 41 #include <string.h> 42 #include <unistd.h>42 //#include <unistd.h> 43 43 44 44 #include "nfotiser.h" … … 110 110 err(255, "cannot munmap"); 111 111 /* don't need the file any more */ 112 close(fd);113 112 114 113 /* now we can operate on the NUL-terminated R/W string “buf” */ … … 278 277 putchar('\n'); 279 278 } 279 280 void 281 parser_free(struct parser_result *head) 282 { 283 struct parser_res *entry; 284 285 if (head == NULL) 286 return; 287 288 while (!CIRCLEQ_EMPTY(head)) { 289 entry = CIRCLEQ_FIRST(head); 290 CIRCLEQ_REMOVE(head, entry, e); 291 if (entry->kw_multi != NULL) 292 free(entry->kw_multi); 293 if (entry->value != NULL) 294 free(entry->value); 295 free(entry); 296 } 297 298 free(head); 299 } branches/common-nfo/tools/nfotiser/pfile.c
r3444 r3457 34 34 #include <err.h> 35 35 #include <errno.h> 36 #include <fcntl.h> 36 37 #include <stdint.h> 37 38 #include <stdio.h> … … 116 117 { NULL, 0, 0, 0 } 117 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 }


