=================================================================== RCS file: /cvs/texi2mdoc/util.c,v retrieving revision 1.30 retrieving revision 1.31 diff -u -p -r1.30 -r1.31 --- texi2mdoc/util.c 2015/03/11 12:51:41 1.30 +++ texi2mdoc/util.c 2015/03/12 04:24:19 1.31 @@ -1,4 +1,4 @@ -/* $Id: util.c,v 1.30 2015/03/11 12:51:41 kristaps Exp $ */ +/* $Id: util.c,v 1.31 2015/03/12 04:24:19 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -109,7 +109,7 @@ texidex_free(struct texidex *p) size_t i; for (i = 0; i < p->indexsz; i++) - free(p->index[i]); + free(p->index[i].term); free(p->index); free(p->name); @@ -126,7 +126,7 @@ void texindex(struct texi *p, const char *tok, size_t toksz, const char *index, size_t sz) { - size_t i; + size_t i, isz; #ifdef HAVE_INDEX char *cp; #endif @@ -146,22 +146,21 @@ texindex(struct texi *p, const char *tok, } assert(i < p->indexsz); + isz = p->indexs[i].indexsz; /* Reallocate index's terms. */ p->indexs[i].index = realloc (p->indexs[i].index, - (p->indexs[i].indexsz + 1) * - sizeof(char *)); + (isz + 1) * sizeof(struct texiterm)); if (NULL == p->indexs[i].index) texiabort(p, NULL); /* Add term to term array. */ - p->indexs[i].index[p->indexs[i].indexsz] = - malloc(sz + 1); - if (NULL == p->indexs[i].index[p->indexs[i].indexsz]) + p->indexs[i].index[isz].chapter = p->nodesz - 1; + p->indexs[i].index[isz].term = malloc(sz + 1); + if (NULL == p->indexs[i].index[isz].term) texiabort(p, NULL); - memcpy(p->indexs[i].index[p->indexs[i].indexsz], - index, sz); - p->indexs[i].index[p->indexs[i].indexsz][sz] = '\0'; + memcpy(p->indexs[i].index[isz].term, index, sz); + p->indexs[i].index[isz].term[sz] = '\0'; /* Output mdoc(7) for index. */ #ifdef HAVE_INDEX @@ -169,7 +168,7 @@ texindex(struct texi *p, const char *tok, teximacroopen(p, "Ix"); texiputchars(p, "idx"); texiputchars(p, p->indexs[i].name); - cp = p->indexs[i].index[p->indexs[i].indexsz]; + cp = p->indexs[i].index[isz].term; while ('\n' != *cp) { assert('\0' != *cp); texiputchar(p, *cp++); @@ -204,7 +203,8 @@ texindex_add(struct texi *p, const char *tok, size_t s /* Reallocate indices. */ p->indexs = realloc(p->indexs, - sizeof(struct texidex) * (p->indexsz + 1)); + sizeof(struct texidex) * + (p->indexsz + 1)); if (NULL == p->indexs) texiabort(p, NULL); if (NULL == (cp = malloc(sz + 1))) @@ -246,6 +246,7 @@ texiexit(struct texi *p) for (i = 0; i < p->valsz; i++) texivaluefree(&p->vals[i]); + free(p->nodes); free(p->macros); free(p->vals); free(p->indexs); @@ -1654,7 +1655,8 @@ teximdocclose(struct texi *p, int last) /* Print a reference to the "top" node. */ if (p->chapnum > 1) { texiputchars(p, "Top node,"); - snprintf(buf, sizeof(buf), "node1 7"); + snprintf(buf, sizeof(buf), "%s-1 7", p->chapters); + p->seenvs = 0; teximacroopen(p, "Xr "); texiputchars(p, buf); texiputchars(p, " ;"); @@ -1665,7 +1667,8 @@ teximdocclose(struct texi *p, int last) if (p->chapnum > 2) { texiputchars(p, "previous node,"); snprintf(buf, sizeof(buf), - "node%zu 7", p->chapnum - 1); + "%s-%zu 7", p->chapters, p->chapnum - 1); + p->seenvs = 0; teximacroopen(p, "Xr "); texiputchars(p, buf); if ( ! last) @@ -1680,7 +1683,8 @@ teximdocclose(struct texi *p, int last) else texiputchars(p, "next node,"); snprintf(buf, sizeof(buf), - "node%zu 7", p->chapnum + 1); + "%s-%zu 7", p->chapters, p->chapnum + 1); + p->seenvs = 0; teximacroopen(p, "Xr "); texiputchars(p, buf); teximacroclose(p); @@ -1703,8 +1707,19 @@ teximdocopen(struct texi *p, size_t *pos) char fname[PATH_MAX]; if (NULL != p->chapters) { - snprintf(fname, sizeof(fname), "%s/node%zu.7", - p->chapters, ++p->chapnum); + p->chapnum++; + snprintf(fname, sizeof(fname), "%s-%zu", + p->chapters, p->chapnum); + p->nodes = realloc(p->nodes, + (p->nodesz + 1) * sizeof(char *)); + if (NULL == p->nodes) + texiabort(p, NULL); + p->nodes[p->nodesz] = strdup(fname); + if (NULL == p->nodes[p->nodesz]) + texiabort(p, NULL); + p->nodesz++; + snprintf(fname, sizeof(fname), "%s-%zu.7", + p->chapters, p->chapnum); p->outfile = fopen(fname, "w"); if (NULL == p->outfile) texiabort(p, fname);