=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.46 retrieving revision 1.64 diff -u -p -r1.46 -r1.64 --- texi2mdoc/main.c 2015/02/25 14:37:17 1.46 +++ texi2mdoc/main.c 2015/03/07 11:49:32 1.64 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.46 2015/02/25 14:37:17 kristaps Exp $ */ +/* $Id: main.c,v 1.64 2015/03/07 11:49:32 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -26,7 +26,7 @@ #include #include #include -#include +#include #include "extern.h" @@ -42,6 +42,7 @@ static void doaccent(struct texi *, enum texicmd, size static void doblock(struct texi *, enum texicmd, size_t *); static void dobracket(struct texi *, enum texicmd, size_t *); static void dobye(struct texi *, enum texicmd, size_t *); +static void docopying(struct texi *, enum texicmd, size_t *); static void dodefindex(struct texi *, enum texicmd, size_t *); static void dodefn(struct texi *, enum texicmd, size_t *); static void dodisplay(struct texi *, enum texicmd, size_t *); @@ -54,11 +55,15 @@ static void doignbracket(struct texi *, enum texicmd, static void doignline(struct texi *, enum texicmd, size_t *); static void doinline(struct texi *, enum texicmd, size_t *); static void doinclude(struct texi *, enum texicmd, size_t *); +static void doinsertcopying(struct texi *, enum texicmd, size_t *); static void doitem(struct texi *, enum texicmd, size_t *); static void doitemize(struct texi *, enum texicmd, size_t *); static void dolink(struct texi *, enum texicmd, size_t *); static void domacro(struct texi *, enum texicmd, size_t *); static void domath(struct texi *, enum texicmd, size_t *); +#if 0 +static void domenu(struct texi *, enum texicmd, size_t *); +#endif static void domultitable(struct texi *, enum texicmd, size_t *); static void doquotation(struct texi *, enum texicmd, size_t *); static void dotable(struct texi *, enum texicmd, size_t *); @@ -94,7 +99,8 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dosymbol, "*", 1 }, /* TEXICMD_ASTERISK */ { dosymbol, "@", 1 }, /* TEXICMD_AT */ { doignline, "author", 6 }, /* TEXICMD_AUTHOR */ - { doinline, "b", 1 }, /* TEXICMD_BOLD */ + { doinline, "b", 1 }, /* TEXICMD_B */ + { dosymbol, "\\", 1 }, /* TEXICMD_BACKSLASH */ { dosymbol, "!", 1 }, /* TEXICMD_BANG */ { dosymbol, "bullet", 6 }, /* TEXICMD_BULLET */ { dobye, "bye", 3 }, /* TEXICMD_BYE */ @@ -114,7 +120,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { doignline, "c", 1 }, /* TEXICMD_COMMENT */ { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */ { doignline, "contents", 8 }, /* TEXICMD_CONTENTS */ - { doignblock, "copying", 7 }, /* TEXICMD_COPYING */ + { docopying, "copying", 7 }, /* TEXICMD_COPYING */ { dosymbol, "copyright", 9 }, /* TEXICMD_COPYRIGHT */ { dodefindex, "defcodeindex", 12 }, /* TEXICMD_DEFCODEINDEX */ { dodefn, "deffn", 5 }, /* TEXICMD_DEFFN */ @@ -213,7 +219,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */ { dolink, "indicateurl", 11 }, /* TEXICMD_INDICATEURL */ { dolink, "inforef", 7 }, /* TEXICMD_INFOREF */ - { doignline, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */ + { doinsertcopying, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */ { doitem, "item", 4 }, /* TEXICMD_ITEM */ { doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */ { doitem, "itemx", 5 }, /* TEXICMD_ITEMX */ @@ -268,7 +274,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { doaccent, "ringaccent", 10 }, /* TEXICMD_RINGACCENT */ { doinline, "samp", 4 }, /* TEXICMD_SAMP */ { doinline, "sansserif", 9 }, /* TEXICMD_SANSSERIF */ - { dobracket, "sc", 2 }, /* TEXICMD_SC */ + { doinline, "sc", 2 }, /* TEXICMD_SC */ { dosection, "section", 7 }, /* TEXICMD_SECTION */ { dovalue, "set", 3 }, /* TEXICMD_SET */ { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */ @@ -295,8 +301,8 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dosubsubsection, "subsubsection", 13 }, /* TEXICMD_SUBSUBSECTION */ { doignline, "subtitle", 8 }, /* TEXICMD_SUBTITLE */ { doignline, "summarycontents", 15 }, /* TEXICMD_SUMMARYCONTENTS */ - { doignline, "synindex", 8 }, /* TEXICMD_SYNINDEX */ - { doignline, "syncodeindex", 12 }, /* TEXICMD_SYNCODEINDEX */ + { dodefindex, "synindex", 8 }, /* TEXICMD_SYNINDEX */ + { dodefindex, "syncodeindex", 12 }, /* TEXICMD_SYNCODEINDEX */ { doinline, "t", 1 }, /* TEXICMD_T */ { dotab, "tab", 3 }, /* TEXICMD_TAB */ { dosymbol, "\t", 1 }, /* TEXICMD_TABSYM */ @@ -341,6 +347,12 @@ static const struct texitok __texitoks[TEXICMD__MAX] = const struct texitok *const texitoks = __texitoks; +/* + * Texinfo has lots of indexes. + * You can add new ones in a variety of ways. + * We maintain an array of all of these index names (usually a few + * letters) and pass unknown commands through the array list. + */ static void dodefindex(struct texi *p, enum texicmd cmd, size_t *pos) { @@ -349,7 +361,6 @@ dodefindex(struct texi *p, enum texicmd cmd, size_t *p while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) advance(p, pos); - start = end = *pos; while (end < BUFSZ(p) && ! ismspace(BUF(p)[end])) end++; @@ -357,18 +368,21 @@ dodefindex(struct texi *p, enum texicmd cmd, size_t *p if (start == end) { advanceeoln(p, pos, 1); return; - } else if (NULL == (cp = malloc(end - start + 1))) + } + + if (NULL == (cp = malloc(end - start + 1))) texiabort(p, NULL); - memcpy(cp, &BUF(p)[start], end - start); cp[end - start] = '\0'; + /* FIXME: use reallocarray(). */ p->indexs = realloc(p->indexs, sizeof(char *) * (p->indexsz + 1)); - if (NULL == p->indexs) texiabort(p, NULL); p->indexs[p->indexsz++] = cp; + + advanceeoln(p, pos, 1); } static void @@ -431,7 +445,8 @@ dodefn(struct texi *p, enum texicmd cmd, size_t *pos) break; } - texiputchars(p, ":\n"); + texiputchar(p, ':'); + texiputchar(p, '\n'); switch (cmd) { case (TEXICMD_DEFMAC): @@ -496,9 +511,45 @@ dodefn(struct texi *p, enum texicmd cmd, size_t *pos) abort(); } - texivspace(p); - if (NULL != blk) - parseto(p, pos, blk); + if (NULL == blk) + return; + + /* + * All "block" definitions have their block bodies indented + * unless they have the "x" form of the command following. + * E.g., + * @deffn some function + * @deffnx another + * An explanation. + * @end deffn + * With this loop, we delay opening the indented block until we + * skipped past conformant macros. + */ + for (;;) { + switch (peekcmd(p, *pos)) { + case (TEXICMD_DEFFNX): + case (TEXICMD_DEFMACX): + case (TEXICMD_DEFTPX): + case (TEXICMD_DEFTYPEFNX): + case (TEXICMD_DEFTYPEFUNX): + case (TEXICMD_DEFTYPEMETHODX): + case (TEXICMD_DEFTYPEVARX): + case (TEXICMD_DEFTYPEVRX): + case (TEXICMD_DEFUNX): + case (TEXICMD_DEFVARX): + case (TEXICMD_DEFVRX): + texivspace(p); + parseeoln(p, pos); + continue; + default: + break; + } + break; + } + teximacro(p, "Bd -filled -offset indent"); + parseto(p, pos, blk); + teximacro(p, "Ed"); + p->seenvs = 1; } static void @@ -612,8 +663,8 @@ doignblock(struct texi *p, enum texicmd cmd, size_t *p * Thus, we keep track of scopes for matching "end" blocks. */ while (stack > 0 && *pos < BUFSZ(p)) { - if (stack > 10) - abort(); + if (stack > 64) + texierr(p, "run-away nested stack?"); endt = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, esz); startt = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, start, ssz); if (NULL == endt) { @@ -688,13 +739,34 @@ doinline(struct texi *p, enum texicmd cmd, size_t *pos } if (NULL == macro || p->literal || TEXILIST_TABLE == p->list) { - parsebracket(p, pos); + if (TEXICMD_SC == cmd) + p->uppercase++; + parsebracket(p, pos, 0); + if (TEXICMD_SC == cmd) + p->uppercase--; return; } + /* + * If we haven't seen any whitespace, then we don't want the + * subsequent macro to insert any whitespace. + */ + if (p->outmacro && 0 == p->seenws) { + teximacroopen(p, "Ns"); + teximacroclose(p); + } + teximacroopen(p, macro); p->seenws = 0; - parsebracket(p, pos); + if (TEXICMD_CODE == cmd) + p->literal++; + if (TEXICMD_SC == cmd) + p->uppercase++; + parsebracket(p, pos, 0); + if (TEXICMD_SC == cmd) + p->uppercase--; + if (TEXICMD_CODE == cmd) + p->literal--; texipunctuate(p, pos); teximacroclose(p); } @@ -726,7 +798,7 @@ doverb(struct texi *p, enum texicmd cmd, size_t *pos) break; advance(p, pos); } - if (*pos == BUFSZ(p) - 1) + if (*pos >= BUFSZ(p) - 1) return; texiputbuf(p, start, *pos); @@ -738,6 +810,53 @@ doverb(struct texi *p, enum texicmd cmd, size_t *pos) } static void +doinsertcopying(struct texi *p, enum texicmd cmd, size_t *pos) +{ + + advanceeoln(p, pos, 0); + if (NULL == p->copying) + return; + texisplice(p, p->copying, p->copyingsz, *pos); +} + +static void +docopying(struct texi *p, enum texicmd cmd, size_t *pos) +{ + const char *end, *term; + size_t endsz, endpos; + + /* We retain our starting (but not ending) newlines. */ + end = "\n@end copying\n"; + endsz = strlen(end); + advanceeoln(p, pos, 0); + if (*pos == BUFSZ(p)) { + texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok); + return; + } + + term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz); + if (NULL == term) { + texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok); + endpos = BUFSZ(p); + } else + endpos = *pos + (size_t)(term - &BUF(p)[*pos]); + + assert(endpos <= BUFSZ(p)); + assert('\n' == BUF(p)[*pos]); + advance(p, pos); + + p->copying = malloc(endpos - *pos + 1); + p->copyingsz = endpos - *pos; + memcpy(p->copying, &BUF(p)[*pos], p->copyingsz); + p->copying[endpos - *pos] = '\0'; + + while (*pos < endpos) + advance(p, pos); + if (*pos < BUFSZ(p)) + advanceto(p, pos, endpos + endsz); +} + +static void doverbatim(struct texi *p, enum texicmd cmd, size_t *pos) { const char *end, *term; @@ -748,13 +867,13 @@ doverbatim(struct texi *p, enum texicmd cmd, size_t *p endsz = strlen(end); advanceeoln(p, pos, 0); if (*pos == BUFSZ(p)) { - texiwarn(p, "unexpected end of file"); + texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok); return; } term = memmem(&BUF(p)[*pos], BUFSZ(p) - *pos, end, endsz); if (NULL == term) { - texiwarn(p, "unterminated verbatim block"); + texiwarn(p, "unterminated \"%s\"", texitoks[cmd].tok); endpos = BUFSZ(p); } else endpos = *pos + (size_t)(term - &BUF(p)[*pos]); @@ -768,6 +887,7 @@ doverbatim(struct texi *p, enum texicmd cmd, size_t *p advance(p, pos); } teximacro(p, "Ed"); + p->seenvs = 1; if (*pos < BUFSZ(p)) advanceto(p, pos, endpos + endsz); } @@ -898,13 +1018,15 @@ static void dobracket(struct texi *p, enum texicmd cmd, size_t *pos) { - parsebracket(p, pos); + parsebracket(p, pos, 0); } static void dodisplay(struct texi *p, enum texicmd cmd, size_t *pos) { + advanceeoln(p, pos, 1); + switch (cmd) { case (TEXICMD_FORMAT): case (TEXICMD_SMALLFORMAT): @@ -915,24 +1037,23 @@ dodisplay(struct texi *p, enum texicmd cmd, size_t *po break; } - p->seenvs = 1; - /* FIXME: ignore and parseeoln. */ - advanceeoln(p, pos, 1); parseto(p, pos, texitoks[cmd].tok); teximacro(p, "Ed"); + p->seenvs = 1; } static void doexample(struct texi *p, enum texicmd cmd, size_t *pos) { - teximacro(p, "Bd -literal -offset indent"); - /* FIXME: ignore and parseeoln. */ advanceeoln(p, pos, 1); + + teximacro(p, "Bd -literal -offset indent"); p->literal++; parseto(p, pos, texitoks[cmd].tok); p->literal--; teximacro(p, "Ed"); + p->seenvs = 1; } static void @@ -946,20 +1067,27 @@ dobye(struct texi *p, enum texicmd cmd, size_t *pos) static void dotitle(struct texi *p, enum texicmd cmd, size_t *pos) { - size_t start, end; + size_t start; while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) advance(p, pos); - start = end = *pos; - while (end < BUFSZ(p) && '\n' != BUF(p)[end]) - end++; - advanceeoln(p, pos, 1); + + /* We want to suck down the entire line, inclusive \n. */ + start = *pos; + while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) { + if ('@' == BUF(p)[*pos]) + advance(p, pos); + advance(p, pos); + } + if (*pos < BUFSZ(p)) + advance(p, pos); + + /* Copy this into a buffer. */ free(p->subtitle); - p->subtitle = malloc(end - start + 1); - if (NULL == p->subtitle) + if (NULL == (p->subtitle = malloc(*pos - start + 1))) texiabort(p, NULL); - memcpy(p->subtitle, &BUF(p)[start], end - start); - p->subtitle[end - start] = '\0'; + memcpy(p->subtitle, &BUF(p)[start], *pos - start); + p->subtitle[*pos - start] = '\0'; } static void @@ -988,7 +1116,7 @@ doaccent(struct texi *p, enum texicmd cmd, size_t *pos if ('{' == BUF(p)[*pos]) { brace = 1; advance(p, pos); - } else if (isalpha(texitoks[cmd].tok[0])) + } else if (isalpha((unsigned char)texitoks[cmd].tok[0])) while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) advance(p, pos); @@ -1152,6 +1280,9 @@ dosymbol(struct texi *p, enum texicmd cmd, size_t *pos case (TEXICMD_AT): texiputchar(p, '@'); break; + case (TEXICMD_BACKSLASH): + texiputchar(p, '\\'); + break; case (TEXICMD_BANG): texiputchar(p, '!'); break; @@ -1310,7 +1441,7 @@ dosymbol(struct texi *p, enum texicmd cmd, size_t *pos } /* Alphabetic commands have braces we ignore. */ - if (isalpha(texitoks[cmd].tok[0])) + if (isalpha((unsigned char)texitoks[cmd].tok[0])) doignbracket(p, cmd, pos); } @@ -1323,41 +1454,125 @@ doquotation(struct texi *p, enum texicmd cmd, size_t * teximacro(p, "Qc"); } +#if 0 static void -domath(struct texi *p, enum texicmd cmd, size_t *pos) +domenu(struct texi *p, enum texicmd cmd, size_t *pos) { - size_t nest, start; + size_t start; - /* - * Math handling is different from everything else. - * We don't allow any subcomponents, and we ignore the rules in - * terms of @-commands. - * This departs from GNU's rules, but whatever. - */ - while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) - advance(p, pos); - if (*pos == BUFSZ(p) || '{' != BUF(p)[*pos]) + if (NULL != p->chapters) { + doignblock(p, cmd, pos); return; - advance(p, pos); - if (p->seenws && p->outcol && 0 == p->literal) - texiputchar(p, ' '); - p->seenws = 0; - for (nest = 1, start = *pos; *pos < BUFSZ(p) && nest > 0; ) { - if ('{' == BUF(p)[*pos]) - nest++; - else if ('}' == BUF(p)[*pos]) - if (0 == --nest) - continue; + } + + advanceeoln(p, pos, 1); + + teximacro(p, "Bl -tag -width Ds"); + while (*pos < BUFSZ(p)) { + /* Read to next menu item. */ + while (*pos < BUFSZ(p) && ismspace(BUF(p)[*pos])) + advance(p, pos); + if ('*' != BUF(p)[*pos]) + break; + + assert('*' == BUF(p)[*pos]); advance(p, pos); + while (*pos < BUFSZ(p) && ismspace(BUF(p)[*pos])) + advance(p, pos); + start = *pos; + while (*pos < BUFSZ(p) && ':' != BUF(p)[*pos]) + advance(p, pos); + if (*pos == BUFSZ(p) || *pos == start) { + texiwarn(p, "empty menu name"); + break; + } + teximacroopen(p, "It"); + teximacroopen(p, "Sx"); + for ( ; start < *pos; start++) + texiputchar(p, BUF(p)[start]); + teximacroclose(p); + teximacroclose(p); + + advance(p, pos); + if (*pos == BUFSZ(p)) { + texiwarn(p, "bad menu syntax"); + break; + } else if (':' != BUF(p)[*pos]) { + while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) + advance(p, pos); + start = *pos; + while (*pos < BUFSZ(p)) { + switch (BUF(p)[*pos]) { + case ('\t'): + case ('\n'): + case (','): + break; + case ('.'): + if (*pos + 1 == BUFSZ(p)) { + advance(p, pos); + continue; + } + if (' ' == BUF(p)[*pos + 1]) { + advance(p, pos); + break; + } + /* FALLTHROUGH */ + default: + advance(p, pos); + continue; + } + advance(p, pos); + break; + } + } else + advance(p, pos); + + while (*pos < BUFSZ(p) && isws(BUF(p)[*pos])) + advance(p, pos); + + if (*pos == BUFSZ(p)) { + texiwarn(p, "bad menu syntax"); + break; + } + + while (*pos < BUFSZ(p)) { + if ('*' == BUF(p)[*pos]) + break; + if ('\n' != BUF(p)[*pos]) { + texiputchar(p, BUF(p)[*pos]); + advance(p, pos); + continue; + } + advance(p, pos); + while (*pos == BUFSZ(p)) { + texiwarn(p, "bad menu syntax"); + break; + } + if ('\n' == BUF(p)[*pos]) { + advance(p, pos); + break; + } else if ('*' == BUF(p)[*pos]) { + continue; + } else if ('@' == BUF(p)[*pos]) + break; + texiputchar(p, ' '); + } } - if (*pos == BUFSZ(p)) - return; - assert('}' == BUF(p)[*pos]); - texiputbuf(p, start, *pos); - advance(p, pos); + + teximacro(p, "El"); + + doignblock(p, cmd, pos); } +#endif static void +domath(struct texi *p, enum texicmd cmd, size_t *pos) +{ + + parsebracket(p, pos, 1); +} + +static void dovalue(struct texi *p, enum texicmd cmd, size_t *pos) { size_t start, end; @@ -1400,7 +1615,7 @@ dovalue(struct texi *p, enum texicmd cmd, size_t *pos) texiputchar(p, ' '); p->seenws = 0; if (NULL != (cp = valueblookup(p, pos))) - texisplice(p, cp, strlen(cp), pos); + texisplice(p, cp, strlen(cp), *pos); else texiputchars(p, "{No value}"); } else if (TEXICMD_IFCLEAR == cmd) { @@ -1542,9 +1757,11 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po int sec; switch (cmd) { + case (TEXICMD_TOP): + sec = 0; + break; case (TEXICMD_APPENDIX): case (TEXICMD_CHAPTER): - case (TEXICMD_TOP): case (TEXICMD_UNNUMBERED): sec = sectioner(p, 0); break; @@ -1563,67 +1780,37 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po else if (p->literal) texierr(p, "\"%s\" in a literal scope!?", sects[sec]); + if (0 == sec && NULL != p->chapters) { + teximdocclose(p, 0); + teximdocopen(p, pos); + } + teximacroopen(p, sects[sec]); parseeoln(p, pos); teximacroclose(p); - p->seenvs = 1; } static void -dosp(struct texi *p, enum texicmd cmd, size_t *pos) -{ - - if (p->literal) - texiputchar(p, '\n'); - else - texivspace(p); - /* FIXME: ignore and parseeoln. */ - advanceeoln(p, pos, 1); -} - -static void dotop(struct texi *p, enum texicmd cmd, size_t *pos) { - const char *cp; - time_t t; - char date[32]; if (--p->ign) texierr(p, "@top command while ignoring"); - /* - * 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); - strftime(date, sizeof(date), "%F", localtime(&t)); + if (NULL == p->chapters) + teximdocopen(p, pos); + dosection(p, cmd, pos); +} - teximacroopen(p, "Dd"); - texiputchars(p, date); - teximacroclose(p); - teximacroopen(p, "Dt"); - for (cp = p->title; '\0' != *cp; cp++) - texiputchar(p, toupper(*cp)); - texiputchars(p, " 7"); - teximacroclose(p); - teximacro(p, "Os"); - teximacro(p, "Sh NAME"); - teximacroopen(p, "Nm"); - for (cp = p->title; '\0' != *cp; cp++) - texiputchar(p, *cp); - teximacroclose(p); - teximacroopen(p, "Nd"); - if (NULL != p->subtitle) - for (cp = p->subtitle; '\0' != *cp; cp++) - texiputchar(p, *cp); +static void +dosp(struct texi *p, enum texicmd cmd, size_t *pos) +{ + + advanceeoln(p, pos, 1); + if (p->literal) + texiputchar(p, '\n'); else - texiputchars(p, "Unknown description"); - teximacroclose(p); - p->seenvs = 1; - dosection(p, cmd, pos); + texivspace(p); } static void @@ -1632,7 +1819,8 @@ doitem(struct texi *p, enum texicmd cmd, size_t *pos) /* Multitable is using raw tbl(7). */ if (TEXILIST_TABLE == p->list) { - texiputchar(p, '\n'); + if (p->outcol > 0) + texiputchar(p, '\n'); return; } @@ -1654,7 +1842,6 @@ doitem(struct texi *p, enum texicmd cmd, size_t *pos) } /* Trick so we don't start with Pp. */ - p->seenvs = 1; parseeoln(p, pos); if (TEXILIST_ITEM == p->list) @@ -1668,7 +1855,7 @@ dotab(struct texi *p, enum texicmd cmd, size_t *pos) { /* This command is only useful in @multitable. */ - if (TEXILIST_TABLE == p->list) + if (TEXILIST_TABLE == p->list && p->outcol) texiputchar(p, '\t'); } @@ -1680,6 +1867,7 @@ domultitable(struct texi *p, enum texicmd cmd, size_t enum texicmd type; size_t i, end, columns; + texivspace(p); p->list = TEXILIST_TABLE; /* * TS/TE blocks aren't "in mdoc(7)", so we can disregard the @@ -1695,7 +1883,7 @@ domultitable(struct texi *p, enum texicmd cmd, size_t /* Make sure we don't print anything when scanning. */ p->ign++; - if ('@' == BUF(p)[*pos]) { + if (*pos < BUFSZ(p) && '@' == BUF(p)[*pos]) { /* * Look for @columnfractions. * We ignore these, but we do use the number of @@ -1733,7 +1921,9 @@ domultitable(struct texi *p, enum texicmd cmd, size_t texiputchar(p, ' '); texiputchar(p, 'l'); } - texiputchars(p, ".\n"); + + texiputchar(p, '.'); + texiputchar(p, '\n'); p->outmacro++; parseto(p, pos, texitoks[cmd].tok); p->outmacro--; @@ -1747,13 +1937,13 @@ dotable(struct texi *p, enum texicmd cmd, size_t *pos) { enum texilist sv = p->list; + advanceeoln(p, pos, 1); + p->list = TEXILIST_ITEM; teximacro(p, "Bl -tag -width Ds"); - /* FIXME: ignore and parseeoln. */ - advanceeoln(p, pos, 1); - p->seenvs = 1; parseto(p, pos, texitoks[cmd].tok); teximacro(p, "El"); + p->seenvs = 1; p->list = sv; } @@ -1768,7 +1958,8 @@ doend(struct texi *p, enum texicmd cmd, size_t *pos) while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) advance(p, pos); - texiwarn(p, "unexpected \"end\": %.*s", (int)(*pos - start), &BUF(p)[start]); + texiwarn(p, "unexpected \"end\": %.*s", + (int)(*pos - start), &BUF(p)[start]); advanceeoln(p, pos, 1); } @@ -1777,13 +1968,13 @@ doenumerate(struct texi *p, enum texicmd cmd, size_t * { enum texilist sv = p->list; + advanceeoln(p, pos, 1); + p->list = TEXILIST_NOITEM; teximacro(p, "Bl -enum"); - p->seenvs = 1; - /* FIXME: ignore and parseeoln. */ - advanceeoln(p, pos, 1); - parseto(p, pos, "enumerate"); + parseto(p, pos, texitoks[cmd].tok); teximacro(p, "El"); + p->seenvs = 1; p->list = sv; } @@ -1792,13 +1983,13 @@ doitemize(struct texi *p, enum texicmd cmd, size_t *po { enum texilist sv = p->list; + advanceeoln(p, pos, 1); + p->list = TEXILIST_NOITEM; teximacro(p, "Bl -bullet"); - p->seenvs = 1; - /* FIXME: ignore and parseeoln. */ - advanceeoln(p, pos, 1); - parseto(p, pos, "itemize"); + parseto(p, pos, texitoks[cmd].tok); teximacro(p, "El"); + p->seenvs = 1; p->list = sv; } @@ -1807,7 +1998,7 @@ doignbracket(struct texi *p, enum texicmd cmd, size_t { p->ign++; - parsebracket(p, pos); + parsebracket(p, pos, 0); p->ign--; } @@ -1815,8 +2006,7 @@ static void doignline(struct texi *p, enum texicmd cmd, size_t *pos) { - /* FIXME: ignore and parseeoln. */ - advanceeoln(p, pos, 1); + advanceeoln(p, pos, 1); } /* @@ -1874,10 +2064,14 @@ main(int argc, char *argv[]) memset(&texi, 0, sizeof(struct texi)); texi.ign = 1; + texi.outfile = stdout; Idir = NULL; - while (-1 != (c = getopt(argc, argv, "I:"))) + while (-1 != (c = getopt(argc, argv, "C:I:"))) switch (c) { + case ('C'): + texi.chapters = optarg; + break; case ('I'): Idir = optarg; break; @@ -1911,8 +2105,8 @@ main(int argc, char *argv[]) } texiexit(&texi); - return(EXIT_FAILURE); + exit(EXIT_SUCCESS); usage: - fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname); + fprintf(stderr, "usage: %s [-Cdir] [-Idirs] [file]\n", progname); return(EXIT_FAILURE); }