=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.2 retrieving revision 1.6 diff -u -p -r1.2 -r1.6 --- texi2mdoc/util.c 2015/02/20 12:25:25 1.2 +++ texi2mdoc/util.c 2015/02/21 22:01:32 1.6 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.2 2015/02/20 12:25:25 kristaps Exp $ */ +/* $Id: util.c,v 1.6 2015/02/21 22:01:32 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -67,12 +67,16 @@ texiexit(struct texi *p) for (i = 0; i < p->dirsz; i++) free(p->dirs[i]); + for (i = 0; i < p->indexsz; i++) + free(p->indexs[i]); + for (i = 0; i < p->valsz; i++) { free(p->vals[i].value); free(p->vals[i].key); } free(p->vals); + free(p->indexs); free(p->dirs); free(p->subtitle); free(p->title); @@ -248,7 +252,7 @@ void texivspace(struct texi *p) { - if (p->seenvs) + if (p->seenvs || TEXILIST_TABLE == p->list) return; teximacro(p, "Pp"); p->seenvs = 1; @@ -429,7 +433,7 @@ enum texicmd texicmd(struct texi *p, const char *buf, size_t pos, size_t sz, size_t *end) { - size_t i, len; + size_t i, len, toksz; assert('@' == buf[pos]); @@ -452,11 +456,13 @@ texicmd(struct texi *p, const char *buf, return(TEXICMD__MAX); } + /* Scan to the end of the possible command name. */ for (*end = pos; *end < sz && ! ismspace(buf[*end]); (*end)++) if ((*end > pos && ('@' == buf[*end] || '{' == buf[*end] || '}' == buf[*end]))) break; + /* Look for the command. */ len = *end - pos; for (i = 0; i < TEXICMD__MAX; i++) { if (len != texitoks[i].len) @@ -465,6 +471,17 @@ texicmd(struct texi *p, const char *buf, return(i); } + /* Look for it in our indices. */ + for (i = 0; i < p->indexsz; i++) { + toksz = strlen(p->indexs[i]); + if (len != 5 + toksz) + continue; + if (strncmp(&buf[pos], p->indexs[i], toksz)) + continue; + if (0 == strncmp(&buf[pos + toksz], "index", 5)) + return(TEXICMD_INDEX); + } + texiwarn(p, "bad command: @%.*s", (int)len, &buf[pos]); return(TEXICMD__MAX); } @@ -667,7 +684,7 @@ parselinearg(struct texi *p, const char *buf, size_t s if (*pos < sz && '{' == buf[*pos]) parsebracket(p, buf, sz, pos); - else if ('\n' != buf[*pos]) + else if (*pos < sz && '\n' != buf[*pos]) parsesingle(p, buf, sz, pos); else return(0); @@ -760,7 +777,8 @@ parsefile(struct texi *p, const char *fname, int parse struct stat st; size_t i; - assert(p->filepos < 64); + if (64 == p->filepos) + texierr(p, "too many open files"); f = &p->files[p->filepos]; memset(f, 0, sizeof(struct texifile)); @@ -924,13 +942,12 @@ valueadd(struct texi *p, char *key, char *val) free(p->vals[i].value); p->vals[i].value = val; } else { + /* FIXME: reallocarray() */ p->vals = realloc(p->vals, (p->valsz + 1) * sizeof(struct texivalue)); - if (NULL == p->vals) { - perror(NULL); - exit(EXIT_FAILURE); - } + if (NULL == p->vals) + texiabort(p, NULL); p->vals[p->valsz].key = key; p->vals[p->valsz].value = val; p->valsz++;