Changeset 3459

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

add some debugging – enough to find the endless loop

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • branches/common-nfo/tools/nfotiser/parser.c

    r3457 r3459  
    9090        const struct parser_keywords *kwp; 
    9191        char *cp, *t, *tp, *buf, *buf_base; 
    92         size_t len, n
     92        size_t len, n, lineno
    9393        struct stat sb; 
    9494        char *entry_multi; 
     
    102102 
    103103        /* slurp whole file into mapped memory */ 
    104         if ((cp = mmap(NULL, (len = sb.st_size), PROT_READ, MAP_FILE, fd, 0)) 
    105             == MAP_FAILED) 
     104        len = sb.st_size; 
     105        D(2, "trying to mmap %zu bytes...", len); 
     106        if ((cp = mmap(NULL, len, PROT_READ, MAP_FILE, fd, 0)) == MAP_FAILED) 
    106107                err(255, "cannot mmap %zu bytes", len); 
     108        D(2, "ok\n"); 
    107109        /* make a nice NUL-terminated copy (malloc'd) */ 
     110        D(2, "copying %zu bytes...", len); 
    108111        buf = buf_base = str_nsave(cp, len); 
     112        D(2, " munmap..."); 
    109113        if (munmap(cp, len)) 
    110114                err(255, "cannot munmap"); 
     115        D(2, "ok\n"); 
    111116        /* don't need the file any more */ 
    112117 
     
    115120                errx(1, "syntax error: file does not end with a newline!"); 
    116121 
     122        D(2, "entire string: «%s» (%zu)\n", buf, strlen(buf)); 
     123        lineno = 1; 
     124 
    117125 loop_newline: 
    118126        /* completely new line buffer */ 
     
    121129 loop_getline: 
    122130        /* get a line and add it to line buffer */ 
    123         if (*buf == '\0') 
     131        if (*buf == '\0') { 
     132                D(2, "D: [%4zu] read EOF\n", lineno); 
    124133                goto loop_eof; 
     134        } 
    125135        if (*buf == '\n') { 
     136                D(2, "D: [%4zu] read newline\n", lineno); 
    126137                ++buf; 
     138                ++lineno; 
    127139                goto loop_getline; 
    128140        } 
    129141        if (*buf == '#') { 
    130                 while (*buf != '\n') 
    131                         ++buf; 
     142                D(2, "D: [%4zu] read comment ", lineno); 
     143                t = buf; 
     144                while (*t != '\n') 
     145                        ++t; 
     146                *t++ = '\0'; 
     147                D(2, "'%s'\n", buf); 
     148                buf = t; 
     149                ++lineno; 
    132150                goto loop_getline; 
    133151        } 
    134152        if (*buf == '\t') { 
     153                D(2, "D: [%4zu] read trail line\n", lineno); 
    135154                if (cp == NULL) 
    136155                        errx(1, "syntax error: expected lead line," 
     
    138157                t = ++buf; 
    139158                goto loop_storeline; 
     159        } else { 
     160                D(2, "D: [%4zu] read head line (%02X)\n", lineno, *buf); 
    140161        } 
    141162        if (cp != NULL)