version 1.31, 2015/03/12 04:24:19 |
version 1.32, 2015/03/12 10:44:34 |
Line 155 texindex(struct texi *p, const char *tok, |
|
Line 155 texindex(struct texi *p, const char *tok, |
|
texiabort(p, NULL); |
texiabort(p, NULL); |
|
|
/* Add term to term array. */ |
/* Add term to term array. */ |
p->indexs[i].index[isz].chapter = p->nodesz - 1; |
p->indexs[i].index[isz].chapter = p->nodecur; |
p->indexs[i].index[isz].term = malloc(sz + 1); |
p->indexs[i].index[isz].term = malloc(sz + 1); |
if (NULL == p->indexs[i].index[isz].term) |
if (NULL == p->indexs[i].index[isz].term) |
texiabort(p, NULL); |
texiabort(p, NULL); |
Line 169 texindex(struct texi *p, const char *tok, |
|
Line 169 texindex(struct texi *p, const char *tok, |
|
texiputchars(p, "idx"); |
texiputchars(p, "idx"); |
texiputchars(p, p->indexs[i].name); |
texiputchars(p, p->indexs[i].name); |
cp = p->indexs[i].index[isz].term; |
cp = p->indexs[i].index[isz].term; |
while ('\n' != *cp) { |
while ('\n' != *cp) |
assert('\0' != *cp); |
|
texiputchar(p, *cp++); |
texiputchar(p, *cp++); |
} |
|
teximacroclose(p); |
teximacroclose(p); |
#endif |
#endif |
p->indexs[i].indexsz++; |
p->indexs[i].indexsz++; |
Line 246 texiexit(struct texi *p) |
|
Line 244 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->nodecache); |
free(p->macros); |
free(p->macros); |
free(p->vals); |
free(p->vals); |
free(p->indexs); |
free(p->indexs); |
Line 1130 peekcmd(const struct texi *p, size_t pos) |
|
Line 1128 peekcmd(const struct texi *p, size_t pos) |
|
* Parse a single word or command. |
* Parse a single word or command. |
* This will return immediately at the EOF. |
* This will return immediately at the EOF. |
*/ |
*/ |
static void |
void |
parsesingle(struct texi *p, size_t *pos) |
parsesingle(struct texi *p, size_t *pos) |
{ |
{ |
size_t end, sv; |
size_t end, sv; |
Line 1647 teximdocclose(struct texi *p, int last) |
|
Line 1645 teximdocclose(struct texi *p, int last) |
|
{ |
{ |
char buf[PATH_MAX]; |
char buf[PATH_MAX]; |
|
|
if (NULL == p->chapters || 0 == p->chapnum) |
if (NULL == p->chapters || 1 == p->nodesz) |
return; |
return; |
|
|
teximacro(p, "Sh INFO NAVIGATION"); |
teximacro(p, "Sh INFO NAVIGATION"); |
|
|
/* Print a reference to the "top" node. */ |
/* Print a reference to the "top" node. */ |
if (p->chapnum > 1) { |
if (-1 != p->nodecache[p->nodecur].up) { |
texiputchars(p, "Top node,"); |
texiputchars(p, "Top node,"); |
snprintf(buf, sizeof(buf), "%s-1 7", p->chapters); |
snprintf(buf, sizeof(buf), "%s-%zd 7", |
|
p->chapters, p->nodecache[p->nodecur].up); |
p->seenvs = 0; |
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
Line 1663 teximdocclose(struct texi *p, int last) |
|
Line 1662 teximdocclose(struct texi *p, int last) |
|
teximacroclose(p); |
teximacroclose(p); |
} |
} |
|
|
/* Print a reference to the previous node. */ |
if (-1 != p->nodecache[p->nodecur].prev) { |
if (p->chapnum > 2) { |
|
texiputchars(p, "previous node,"); |
texiputchars(p, "previous node,"); |
snprintf(buf, sizeof(buf), |
snprintf(buf, sizeof(buf), "%s-%zd 7", |
"%s-%zu 7", p->chapters, p->chapnum - 1); |
p->chapters, p->nodecache[p->nodecur].prev); |
p->seenvs = 0; |
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
Line 1676 teximdocclose(struct texi *p, int last) |
|
Line 1674 teximdocclose(struct texi *p, int last) |
|
teximacroclose(p); |
teximacroclose(p); |
} |
} |
|
|
/* Print a reference to the next node. */ |
if (-1 != p->nodecache[p->nodecur].next) { |
if ( ! last) { |
texiputchars(p, "next node,"); |
if (1 == p->chapnum) |
snprintf(buf, sizeof(buf), "%s-%zd 7", |
texiputchars(p, "Next node,"); |
p->chapters, p->nodecache[p->nodecur].next); |
else |
|
texiputchars(p, "next node,"); |
|
snprintf(buf, sizeof(buf), |
|
"%s-%zu 7", p->chapters, p->chapnum + 1); |
|
p->seenvs = 0; |
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
Line 1691 teximdocclose(struct texi *p, int last) |
|
Line 1685 teximdocclose(struct texi *p, int last) |
|
} |
} |
|
|
fclose(p->outfile); |
fclose(p->outfile); |
|
p->outfile = NULL; |
} |
} |
|
|
|
ssize_t |
|
texicache(struct texi *p, const char *buf, size_t sz) |
|
{ |
|
size_t i; |
|
|
|
for (i = 0; i < p->nodecachesz; i++) { |
|
if (sz != strlen(p->nodecache[i].name)) |
|
continue; |
|
if (strncmp(buf, p->nodecache[i].name, sz)) |
|
continue; |
|
break; |
|
} |
|
if (i < p->nodecachesz) |
|
return(i); |
|
if (NULL == buf) |
|
return(-1); |
|
p->nodecache = realloc |
|
(p->nodecache, |
|
(p->nodecachesz + 1) * sizeof(struct texinode)); |
|
if (NULL == p->nodecache) |
|
texiabort(p, NULL); |
|
p->nodecache[p->nodecachesz].name = malloc(sz + 1); |
|
if (NULL == p->nodecache[p->nodecachesz].name) |
|
texiabort(p, NULL); |
|
memcpy(p->nodecache[p->nodecachesz].name, buf, sz); |
|
p->nodecache[p->nodecachesz].name[sz] = '\0'; |
|
p->nodecache[p->nodecachesz].up = |
|
p->nodecache[p->nodecachesz].next = |
|
p->nodecache[p->nodecachesz].prev = -1; |
|
p->nodecachesz++; |
|
return(p->nodecachesz - 1); |
|
} |
|
|
/* |
/* |
* Open a mdoc(7) context. |
* Here we print our standard mdoc(7) prologue. |
* If we're printing chapters, then open the outfile here, too. |
* We use the title set with @settitle for the `Nd' description |
* Otherwise just print the mdoc(7) prologue. |
* and the source document filename (the first one as invoked on |
|
* the command line) for the title. |
|
* The date is set to the current date. |
*/ |
*/ |
void |
void |
teximdocopen(struct texi *p, size_t *pos) |
teximdocopen(struct texi *p, size_t *pos) |
Line 1704 teximdocopen(struct texi *p, size_t *pos) |
|
Line 1734 teximdocopen(struct texi *p, size_t *pos) |
|
const char *cp; |
const char *cp; |
time_t t; |
time_t t; |
char date[32]; |
char date[32]; |
char fname[PATH_MAX]; |
|
|
|
if (NULL != 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"); |
|
if (NULL == p->outfile) |
|
texiabort(p, fname); |
|
} |
|
|
|
/* |
|
* Here we print our standard mdoc(7) prologue. |
|
* We use the title set with @settitle for the `Nd' description |
|
* and the source document filename (the first one as invoked on |
|
* the command line) for the title. |
|
* The date is set to the current date. |
|
*/ |
|
t = time(NULL); |
t = time(NULL); |
strftime(date, sizeof(date), "%F", localtime(&t)); |
strftime(date, sizeof(date), "%F", localtime(&t)); |
|
|