=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.66 retrieving revision 1.67 diff -u -p -r1.66 -r1.67 --- texi2mdoc/main.c 2015/03/11 12:51:41 1.66 +++ texi2mdoc/main.c 2015/03/12 04:24:19 1.67 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.66 2015/03/11 12:51:41 kristaps Exp $ */ +/* $Id: main.c,v 1.67 2015/03/12 04:24:19 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -76,7 +76,6 @@ static void donode(struct texi *, enum texicmd, size_t static void doprintindex(struct texi *, enum texicmd, size_t *); static void doquotation(struct texi *, enum texicmd, size_t *); static void dotable(struct texi *, enum texicmd, size_t *); -static void dotop(struct texi *, enum texicmd, size_t *); static void dosecoffs(struct texi *, enum texicmd, size_t *); static void dosection(struct texi *, enum texicmd, size_t *); static void dosp(struct texi *, enum texicmd, size_t *); @@ -326,7 +325,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { doignline, "title", 5 }, /* TEXICMD_TITLE */ { dobracket, "titlefont", 9 }, /* TEXICMD_TITLEFONT */ { doignblock, "titlepage", 9 }, /* TEXICMD_TITLEPAGE */ - { dotop, "top", 3 }, /* TEXICMD_TOP */ + { dosection, "top", 3 }, /* TEXICMD_TOP */ { doindex, "tpindex", 7 }, /* TEXICMD_TPINDEX */ { doaccent, "u", 1 }, /* TEXICMD_U */ { doaccent, "ubaraccent", 10 }, /* TEXICMD_UBARACCENT */ @@ -1477,8 +1476,9 @@ doquotation(struct texi *p, enum texicmd cmd, size_t * static int indexcmp(const void *p1, const void *p2) { + const struct texiterm *t1 = p1, *t2 = p2; - return(strcasecmp(*(const char **)p1, *(const char **)p2)); + return(strcasecmp(t1->term, t2->term)); } static void @@ -1522,26 +1522,41 @@ doprintindex(struct texi *p, enum texicmd cmd, size_t /* Alphabetically sort our indices. */ qsort(p->indexs[i].index, - p->indexs[i].indexsz, sizeof(char *), indexcmp); + p->indexs[i].indexsz, + sizeof(struct texiterm), indexcmp); texivspace(p); teximacro(p, "Bl -tag -width Ds -compact"); for (j = 0; j < p->indexs[i].indexsz; j++) { teximacroopen(p, "It"); #if HAVE_INDEX - teximacroopen(p, "Lkx"); - texiputchars(p, "\"idx"); - texiputchars(p, p->indexs[i].name); - cp = p->indexs[i].index[j]; - while ('\n' != *cp) { - assert('\0' != *cp); - texiputchar(p, *cp++); + if (NULL == p->chapters) { + teximacroopen(p, "Lkx"); + texiputchars(p, "\"idx"); + texiputchars(p, p->indexs[i].name); + cp = p->indexs[i].index[j].term; + while ('\n' != *cp) { + assert('\0' != *cp); + texiputchar(p, *cp++); + } + texiputchars(p, "\" \""); + p->literal++; + } else { + teximacroopen(p, "Xr"); + texiputchars(p, p->nodes[p->indexs[i].index[j].chapter]); + texiputchars(p, " 7 \"idx"); + texiputchars(p, p->indexs[i].name); + cp = p->indexs[i].index[j].term; + while ('\n' != *cp) { + assert('\0' != *cp); + texiputchar(p, *cp++); + } + texiputchars(p, "\" \""); + p->literal++; } - texiputchars(p, "\" \""); - p->literal++; #endif - texisplice(p, p->indexs[i].index[j], - strlen(p->indexs[i].index[j]), *pos); + texisplice(p, p->indexs[i].index[j].term, + strlen(p->indexs[i].index[j].term), *pos); parseeoln(p, pos); #if HAVE_INDEX p->literal--; @@ -1562,27 +1577,30 @@ donode(struct texi *p, enum texicmd cmd, size_t *pos) if (NULL != p->chapters) { advanceeoln(p, pos, 1); - return; - } - + if (0 == p->chapnum) + p->ign--; + teximdocclose(p, 0); + teximdocopen(p, pos); + } else { #if HAVE_INDEX - p->seenvs = -1; - teximacroopen(p, "Ix"); - texiputchars(p, "node"); - while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) - advance(p, pos); - while (*pos < BUFSZ(p)) { - if (BUF(p)[*pos] == ',') - break; - else if (BUF(p)[*pos] == '\n') - break; - texiputchar(p, BUF(p)[*pos]); - advance(p, pos); - } - teximacroclose(p); + p->seenvs = -1; + teximacroopen(p, "Ix"); + texiputchars(p, "node"); + while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) + advance(p, pos); + while (*pos < BUFSZ(p)) { + if (BUF(p)[*pos] == ',') + break; + else if (BUF(p)[*pos] == '\n') + break; + texiputchar(p, BUF(p)[*pos]); + advance(p, pos); + } + teximacroclose(p); #endif - advanceeoln(p, pos, 1); - p->seenvs = sv; + advanceeoln(p, pos, 1); + p->seenvs = sv; + } } /* @@ -1595,11 +1613,6 @@ domenu(struct texi *p, enum texicmd cmd, size_t *pos) { size_t start, end, sv; - if (NULL != p->chapters) { - doignblock(p, cmd, pos); - return; - } - advanceeoln(p, pos, 1); /* @@ -1914,11 +1927,6 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po else texivspace(p); - if (0 == sec && NULL != p->chapters) { - teximdocclose(p, 0); - teximdocopen(p, pos); - } - teximacroopen(p, sects[sec]); parseeoln(p, pos); teximacroclose(p); @@ -1930,18 +1938,6 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po } static void -dotop(struct texi *p, enum texicmd cmd, size_t *pos) -{ - - if (--p->ign) - texierr(p, "@top command while ignoring"); - - if (NULL == p->chapters) - teximdocopen(p, pos); - dosection(p, cmd, pos); -} - -static void dosp(struct texi *p, enum texicmd cmd, size_t *pos) { @@ -2159,8 +2155,10 @@ doindex(struct texi *p, enum texicmd cmd, size_t *pos) advance(p, pos); start = *pos; - while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) + while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) { + assert('\0' != BUF(p)[*pos]); advance(p, pos); + } if (*pos == BUFSZ(p)) { texiwarn(p, "unexpected EOF");