version 1.30, 2015/03/11 12:51:41 |
version 1.33, 2015/03/13 08:07:34 |
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->nodecur; |
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); |
|
texiputchar(p, *cp++); |
texiputchar(p, *cp++); |
} |
|
teximacroclose(p); |
teximacroclose(p); |
#endif |
#endif |
p->indexs[i].indexsz++; |
p->indexs[i].indexsz++; |
Line 204 texindex_add(struct texi *p, const char *tok, size_t s |
|
Line 201 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 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->nodecache); |
free(p->macros); |
free(p->macros); |
free(p->vals); |
free(p->vals); |
free(p->indexs); |
free(p->indexs); |
Line 583 advanceeoln(struct texi *p, size_t *pos, int consumenl |
|
Line 582 advanceeoln(struct texi *p, size_t *pos, int consumenl |
|
while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) { |
while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) { |
if ('@' == BUF(p)[*pos]) |
if ('@' == BUF(p)[*pos]) |
advance(p, pos); |
advance(p, pos); |
advance(p, pos); |
if (*pos < BUFSZ(p)) |
|
advance(p, pos); |
} |
} |
if (*pos < BUFSZ(p) && consumenl) |
if (*pos < BUFSZ(p) && consumenl) |
advance(p, pos); |
advance(p, pos); |
Line 1061 parseeoln(struct texi *p, size_t *pos) |
|
Line 1061 parseeoln(struct texi *p, size_t *pos) |
|
texiputchar(p, BUF(p)[*pos]); |
texiputchar(p, BUF(p)[*pos]); |
advance(p, pos); |
advance(p, pos); |
} |
} |
|
if (*pos == BUFSZ(p)) { |
|
texiwarn(p, "unexpected EOF"); |
|
return; |
|
} |
switch (BUF(p)[*pos]) { |
switch (BUF(p)[*pos]) { |
case ('}'): |
case ('}'): |
if (0 == p->ign) |
if (0 == p->ign) |
Line 1129 peekcmd(const struct texi *p, size_t pos) |
|
Line 1133 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 1646 teximdocclose(struct texi *p, int last) |
|
Line 1650 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), "node1 7"); |
snprintf(buf, sizeof(buf), "%s-%zd 7", |
|
p->chapters, p->nodecache[p->nodecur].up); |
|
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
texiputchars(p, " ;"); |
texiputchars(p, " ;"); |
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", |
"node%zu 7", p->chapnum - 1); |
p->chapters, p->nodecache[p->nodecur].prev); |
|
p->seenvs = 0; |
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
if ( ! last) |
if ( ! last) |
Line 1673 teximdocclose(struct texi *p, int last) |
|
Line 1679 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 |
p->seenvs = 0; |
texiputchars(p, "next node,"); |
|
snprintf(buf, sizeof(buf), |
|
"node%zu 7", p->chapnum + 1); |
|
teximacroopen(p, "Xr "); |
teximacroopen(p, "Xr "); |
texiputchars(p, buf); |
texiputchars(p, buf); |
teximacroclose(p); |
teximacroclose(p); |
} |
} |
|
|
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 1700 teximdocopen(struct texi *p, size_t *pos) |
|
Line 1739 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) { |
|
snprintf(fname, sizeof(fname), "%s/node%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)); |
|
|