Changeset 3459
- Timestamp:
- 08/09/07 15:50:32 (1 year ago)
- Files:
-
- branches/common-nfo/tools/nfotiser/parser.c (modified) (5 diffs)
Legend:
- Unmodified
- Added
- Removed
- Modified
- Copied
- Moved
branches/common-nfo/tools/nfotiser/parser.c
r3457 r3459 90 90 const struct parser_keywords *kwp; 91 91 char *cp, *t, *tp, *buf, *buf_base; 92 size_t len, n ;92 size_t len, n, lineno; 93 93 struct stat sb; 94 94 char *entry_multi; … … 102 102 103 103 /* 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) 106 107 err(255, "cannot mmap %zu bytes", len); 108 D(2, "ok\n"); 107 109 /* make a nice NUL-terminated copy (malloc'd) */ 110 D(2, "copying %zu bytes...", len); 108 111 buf = buf_base = str_nsave(cp, len); 112 D(2, " munmap..."); 109 113 if (munmap(cp, len)) 110 114 err(255, "cannot munmap"); 115 D(2, "ok\n"); 111 116 /* don't need the file any more */ 112 117 … … 115 120 errx(1, "syntax error: file does not end with a newline!"); 116 121 122 D(2, "entire string: «%s» (%zu)\n", buf, strlen(buf)); 123 lineno = 1; 124 117 125 loop_newline: 118 126 /* completely new line buffer */ … … 121 129 loop_getline: 122 130 /* 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); 124 133 goto loop_eof; 134 } 125 135 if (*buf == '\n') { 136 D(2, "D: [%4zu] read newline\n", lineno); 126 137 ++buf; 138 ++lineno; 127 139 goto loop_getline; 128 140 } 129 141 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; 132 150 goto loop_getline; 133 151 } 134 152 if (*buf == '\t') { 153 D(2, "D: [%4zu] read trail line\n", lineno); 135 154 if (cp == NULL) 136 155 errx(1, "syntax error: expected lead line," … … 138 157 t = ++buf; 139 158 goto loop_storeline; 159 } else { 160 D(2, "D: [%4zu] read head line (%02X)\n", lineno, *buf); 140 161 } 141 162 if (cp != NULL)


