Changeset 3457

Show
Ignore:
Timestamp:
08/09/07 15:40:07 (1 year ago)
Author:
tg
Message:

hook parser and dumper into main loop, seems to loop and hog all mem tho, a case for the debugger...

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/common-nfo/tools/nfotiser/extern.h

    r3444 r3457  
    1717/* dbscheme.S */ 
    1818extern const char dbscheme[]; 
     19/* pfile.c */ 
     20extern void pfile(const char *); 
    1921__END_DECLS 
    2022 
  • branches/common-nfo/tools/nfotiser/main.c

    r3443 r3457  
    3434#include <err.h> 
    3535#include <errno.h> 
    36 #include <fcntl.h> 
    3736#include <locale.h> 
    3837#include <stdint.h> 
     
    9291 
    9392        /* need at least one .nfo file to parse */ 
    94 //    if (!argc) 
    95 //            usage(); 
     93      if (!argc) 
     94              usage(); 
    9695 
    9796        /* if the output file exists, remove it */ 
     
    115114                    ctp->catname, ctp->catdesc); 
    116115        } 
     116 
     117        /* parse input */ 
     118 
     119        while (*argv) 
     120                pfile(*argv++); 
    117121 
    118122        /* … */ 
  • branches/common-nfo/tools/nfotiser/nfotiser.h

    r3456 r3457  
    6060    const struct parser_keywords *); 
    6161void parser_dump(struct parser_res *, const struct parser_keywords *); 
     62void parser_free(struct parser_result *); 
    6263__END_DECLS 
    6364 
  • branches/common-nfo/tools/nfotiser/parser.c

    r3456 r3457  
    4040#include <stdlib.h> 
    4141#include <string.h> 
    42 #include <unistd.h> 
     42//#include <unistd.h> 
    4343 
    4444#include "nfotiser.h" 
     
    110110                err(255, "cannot munmap"); 
    111111        /* don't need the file any more */ 
    112         close(fd); 
    113112 
    114113        /* now we can operate on the NUL-terminated R/W string “buf” */ 
     
    278277        putchar('\n'); 
    279278} 
     279 
     280void 
     281parser_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  
    3434#include <err.h> 
    3535#include <errno.h> 
     36#include <fcntl.h> 
    3637#include <stdint.h> 
    3738#include <stdio.h> 
     
    116117        { NULL, 0, 0, 0 } 
    117118}; 
     119 
     120void 
     121pfile(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}