version 1.30, 2015/03/11 12:51:41 |
version 1.31, 2015/03/12 04:24:19 |
Line 109 texidex_free(struct texidex *p) |
|
Line 109 texidex_free(struct texidex *p) |
|
size_t i; |
size_t i; |
|
|
for (i = 0; i < p->indexsz; i++) |
for (i = 0; i < p->indexsz; i++) |
free(p->index[i]); |
free(p->index[i].term); |
|
|
free(p->index); |
free(p->index); |
free(p->name); |
free(p->name); |
|
|
texindex(struct texi *p, const char *tok, |
texindex(struct texi *p, const char *tok, |
size_t toksz, const char *index, size_t sz) |
size_t toksz, const char *index, size_t sz) |
{ |
{ |
size_t i; |
size_t i, isz; |
#ifdef HAVE_INDEX |
#ifdef HAVE_INDEX |
char *cp; |
char *cp; |
#endif |
#endif |
Line 146 texindex(struct texi *p, const char *tok, |
|
Line 146 texindex(struct texi *p, const char *tok, |
|
} |
} |
|
|
assert(i < p->indexsz); |
assert(i < p->indexsz); |
|
isz = p->indexs[i].indexsz; |
/* Reallocate index's terms. */ |
/* Reallocate index's terms. */ |
p->indexs[i].index = realloc |
p->indexs[i].index = realloc |
(p->indexs[i].index, |
(p->indexs[i].index, |
(p->indexs[i].indexsz + 1) * |
(isz + 1) * sizeof(struct texiterm)); |
sizeof(char *)); |
|
if (NULL == p->indexs[i].index) |
if (NULL == p->indexs[i].index) |
texiabort(p, NULL); |
texiabort(p, NULL); |
|
|
/* Add term to term array. */ |
/* Add term to term array. */ |
p->indexs[i].index[p->indexs[i].indexsz] = |
p->indexs[i].index[isz].chapter = p->nodesz - 1; |
malloc(sz + 1); |
p->indexs[i].index[isz].term = malloc(sz + 1); |
if (NULL == p->indexs[i].index[p->indexs[i].indexsz]) |
if (NULL == p->indexs[i].index[isz].term) |
texiabort(p, NULL); |
texiabort(p, NULL); |
memcpy(p->indexs[i].index[p->indexs[i].indexsz], |
memcpy(p->indexs[i].index[isz].term, index, sz); |
index, sz); |
p->indexs[i].index[isz].term[sz] = '\0'; |
p->indexs[i].index[p->indexs[i].indexsz][sz] = '\0'; |
|
|
|
/* Output mdoc(7) for index. */ |
/* Output mdoc(7) for index. */ |
#ifdef HAVE_INDEX |
#ifdef HAVE_INDEX |
Line 169 texindex(struct texi *p, const char *tok, |
|
Line 168 texindex(struct texi *p, const char *tok, |
|
teximacroopen(p, "Ix"); |
teximacroopen(p, "Ix"); |
texiputchars(p, "idx"); |
texiputchars(p, "idx"); |
texiputchars(p, p->indexs[i].name); |
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) { |
while ('\n' != *cp) { |
assert('\0' != *cp); |
assert('\0' != *cp); |
texiputchar(p, *cp++); |
texiputchar(p, *cp++); |
Line 204 texindex_add(struct texi *p, const char *tok, size_t s |
|
Line 203 texindex_add(struct texi *p, const char *tok, size_t s |
|
|
|
/* Reallocate indices. */ |
/* Reallocate indices. */ |
p->indexs = realloc(p->indexs, |
p->indexs = realloc(p->indexs, |
sizeof(struct texidex) * (p->indexsz + 1)); |
sizeof(struct texidex) * |
|
(p->indexsz + 1)); |
if (NULL == p->indexs) |
if (NULL == p->indexs) |
texiabort(p, NULL); |
texiabort(p, NULL); |
if (NULL == (cp = malloc(sz + 1))) |
if (NULL == (cp = malloc(sz + 1))) |
Line 246 texiexit(struct texi *p) |
|
Line 246 texiexit(struct texi *p) |
|
for (i = 0; i < p->valsz; i++) |
for (i = 0; i < p->valsz; i++) |
texivaluefree(&p->vals[i]); |
texivaluefree(&p->vals[i]); |
|
|
|
free(p->nodes); |
free(p->macros); |
free(p->macros); |
free(p->vals); |
free(p->vals); |
free(p->indexs); |
free(p->indexs); |
Line 1654 teximdocclose(struct texi *p, int last) |
|
Line 1655 teximdocclose(struct texi *p, int last) |
|
/* Print a reference to the "top" node. */ |
/* Print a reference to the "top" node. */ |
if (p->chapnum > 1) { |
if (p->chapnum > 1) { |
texiputchars(p, "Top node,"); |
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 "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
texiputchars(p, " ;"); |
texiputchars(p, " ;"); |
Line 1665 teximdocclose(struct texi *p, int last) |
|
Line 1667 teximdocclose(struct texi *p, int last) |
|
if (p->chapnum > 2) { |
if (p->chapnum > 2) { |
texiputchars(p, "previous node,"); |
texiputchars(p, "previous node,"); |
snprintf(buf, sizeof(buf), |
snprintf(buf, sizeof(buf), |
"node%zu 7", p->chapnum - 1); |
"%s-%zu 7", p->chapters, p->chapnum - 1); |
|
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
if ( ! last) |
if ( ! last) |
Line 1680 teximdocclose(struct texi *p, int last) |
|
Line 1683 teximdocclose(struct texi *p, int last) |
|
else |
else |
texiputchars(p, "next node,"); |
texiputchars(p, "next node,"); |
snprintf(buf, sizeof(buf), |
snprintf(buf, sizeof(buf), |
"node%zu 7", p->chapnum + 1); |
"%s-%zu 7", p->chapters, p->chapnum + 1); |
|
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
teximacroclose(p); |
teximacroclose(p); |
Line 1703 teximdocopen(struct texi *p, size_t *pos) |
|
Line 1707 teximdocopen(struct texi *p, size_t *pos) |
|
char fname[PATH_MAX]; |
char fname[PATH_MAX]; |
|
|
if (NULL != p->chapters) { |
if (NULL != p->chapters) { |
snprintf(fname, sizeof(fname), "%s/node%zu.7", |
p->chapnum++; |
p->chapters, ++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"); |
p->outfile = fopen(fname, "w"); |
if (NULL == p->outfile) |
if (NULL == p->outfile) |
texiabort(p, fname); |
texiabort(p, fname); |