=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.3 retrieving revision 1.4 diff -u -p -r1.3 -r1.4 --- texi2mdoc/util.c 2015/02/21 12:44:45 1.3 +++ texi2mdoc/util.c 2015/02/21 17:00:33 1.4 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.3 2015/02/21 12:44:45 kristaps Exp $ */ +/* $Id: util.c,v 1.4 2015/02/21 17:00:33 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); @@ -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); } @@ -924,13 +941,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++;