=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.62 retrieving revision 1.65 diff -u -p -r1.62 -r1.65 --- texi2mdoc/main.c 2015/03/05 09:36:41 1.62 +++ texi2mdoc/main.c 2015/03/09 18:54:38 1.65 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.62 2015/03/05 09:36:41 kristaps Exp $ */ +/* $Id: main.c,v 1.65 2015/03/09 18:54:38 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -61,7 +61,13 @@ static void doitemize(struct texi *, enum texicmd, siz 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 *); +#if 0 +static void donode(struct texi *, enum texicmd, size_t *); +#endif 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 *); @@ -231,12 +237,20 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { domacro, "macro", 5 }, /* TEXICMD_MACRO */ { doaccent, "=", 1 }, /* TEXICMD_MACRON */ { domath, "math", 4 }, /* TEXICMD_MATH */ +#if 0 + { domenu, "menu", 4 }, /* TEXICMD_MENU */ +#else { doignblock, "menu", 4 }, /* TEXICMD_MENU */ +#endif { dosymbol, "minus", 5 }, /* TEXICMD_MINUS */ { domultitable, "multitable", 10 }, /* TEXICMD_MULTITABLE */ { doignline, "need", 4 }, /* TEXICMD_NEED */ { dosymbol, "\n", 1 }, /* TEXICMD_NEWLINE */ +#if 0 + { donode, "node", 4 }, /* TEXICMD_NODE */ +#else { doignline, "node", 4 }, /* TEXICMD_NODE */ +#endif { doignline, "noindent", 8 }, /* TEXICMD_NOINDENT */ { dosymbol, "O", 1 }, /* TEXICMD_O */ { dosymbol, "OE", 2 }, /* TEXICMD_OE */ @@ -543,6 +557,12 @@ dodefn(struct texi *p, enum texicmd cmd, size_t *pos) } break; } + + if (TEXICMD_END == peekcmd(p, *pos)) { + parseto(p, pos, blk); + return; + } + teximacro(p, "Bd -filled -offset indent"); parseto(p, pos, blk); teximacro(p, "Ed"); @@ -755,11 +775,15 @@ doinline(struct texi *p, enum texicmd cmd, size_t *pos teximacroopen(p, macro); p->seenws = 0; + 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); } @@ -1447,7 +1471,146 @@ doquotation(struct texi *p, enum texicmd cmd, size_t * teximacro(p, "Qc"); } +#if 0 static void +donode(struct texi *p, enum texicmd cmd, size_t *pos) +{ + + teximacroopen(p, "Ix"); + texiputchars(p, "Node"); + while (*pos < BUFSZ(p) && isspace(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); + advanceeoln(p, pos, 1); +} + +static void +domenu(struct texi *p, enum texicmd cmd, size_t *pos) +{ + size_t start, sv; + + if (NULL != p->chapters) { + doignblock(p, cmd, pos); + return; + } + + advanceeoln(p, pos, 1); + + texivspace(p); + teximacro(p, "Bl -tag -width Ds -compact"); + 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); + sv = 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, "Lkx"); + texiputchar(p, '"'); + texiputchars(p, "Node"); + for (start = sv; start < *pos; start++) + texiputchar(p, BUF(p)[start]); + texiputchars(p, "\" \""); + for (start = sv; start < *pos; start++) + texiputchar(p, BUF(p)[start]); + texiputchar(p, '"'); + 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, ' '); + } + } + + teximacro(p, "El"); + + doignblock(p, cmd, pos); +} +#endif + +static void domath(struct texi *p, enum texicmd cmd, size_t *pos) { @@ -1701,7 +1864,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; } @@ -1736,7 +1900,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'); } @@ -1748,6 +1912,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 @@ -1801,7 +1966,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--;