[BACK]Return to main.c CVS log [TXT][DIR] Up to [cvsweb.bsd.lv] / texi2mdoc

Annotation of texi2mdoc/main.c, Revision 1.42

1.42    ! kristaps    1: /*     $Id: main.c,v 1.41 2015/02/24 14:35:40 kristaps Exp $ */
1.1       kristaps    2: /*
                      3:  * Copyright (c) 2015 Kristaps Dzonsons <kristaps@bsd.lv>
                      4:  *
                      5:  * Permission to use, copy, modify, and distribute this software for any
                      6:  * purpose with or without fee is hereby granted, provided that the above
                      7:  * copyright notice and this permission notice appear in all copies.
                      8:  *
                      9:  * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES
                     10:  * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF
                     11:  * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR
                     12:  * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
                     13:  * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
                     14:  * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF
                     15:  * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
                     16:  */
1.37      kristaps   17: #if defined(__linux__) || defined(__MINT__)
                     18: # define _GNU_SOURCE /* memmem */
                     19: #endif
1.1       kristaps   20: #include <assert.h>
                     21: #include <ctype.h>
                     22: #include <getopt.h>
1.2       kristaps   23: #include <libgen.h>
                     24: #include <limits.h>
1.1       kristaps   25: #include <stdarg.h>
                     26: #include <stdio.h>
                     27: #include <stdlib.h>
                     28: #include <string.h>
1.10      kristaps   29: #include <time.h>
1.1       kristaps   30:
1.24      kristaps   31: #include "extern.h"
1.1       kristaps   32:
1.23      kristaps   33: #define        SECTSZ 4
                     34: static const char *const sects[SECTSZ] = {
                     35:        "Sh",
                     36:        "Ss",
                     37:        "Em",
                     38:        "No",
                     39: };
                     40:
1.16      kristaps   41: static void doaccent(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.3       kristaps   42: static void doblock(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   43: static void dobracket(struct texi *, enum texicmd, const char *, size_t, size_t *);
                     44: static void dobye(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.27      kristaps   45: static void dodefindex(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.15      kristaps   46: static void dodefn(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.3       kristaps   47: static void dodisplay(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.2       kristaps   48: static void doenumerate(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   49: static void doexample(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.8       kristaps   50: static void doignargn(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   51: static void doignblock(struct texi *, enum texicmd, const char *, size_t, size_t *);
                     52: static void doignbracket(struct texi *, enum texicmd, const char *, size_t, size_t *);
                     53: static void doignline(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.12      kristaps   54: static void doinline(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.2       kristaps   55: static void doinclude(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   56: static void doitem(struct texi *, enum texicmd, const char *, size_t, size_t *);
                     57: static void doitemize(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.8       kristaps   58: static void dolink(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.30      kristaps   59: static void domacro(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.3       kristaps   60: static void domath(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.18      kristaps   61: static void domultitable(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   62: static void doquotation(struct texi *, enum texicmd, const char *, size_t, size_t *);
                     63: static void dotable(struct texi *, enum texicmd, const char *, size_t, size_t *);
                     64: static void dotop(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.23      kristaps   65: static void dosecoffs(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   66: static void dosection(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.3       kristaps   67: static void dosp(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   68: static void dosubsection(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.23      kristaps   69: static void dosubsubsection(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   70: static void dosymbol(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.18      kristaps   71: static void dotab(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.10      kristaps   72: static void dotitle(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.24      kristaps   73: static void dovalue(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.25      kristaps   74: static void doverb(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.33      kristaps   75: static void doverbatim(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.16      kristaps   76: static void doverbinclude(struct texi *, enum texicmd, const char *, size_t, size_t *);
1.1       kristaps   77:
1.24      kristaps   78: static const struct texitok __texitoks[TEXICMD__MAX] = {
1.20      kristaps   79:        /* TEXICMD__BEGIN */
1.42    ! kristaps   80:        { doignline, "afourpaper", 10 }, /* TEXICMD_A4PAPER */
        !            81:        { dosymbol, "AA", 2 }, /* TEXICMD_AA */
        !            82:        { dosymbol, "aa", 2 }, /* TEXICMD_AASMALL */
1.8       kristaps   83:        { doignargn, "acronym", 7 }, /* TEXICMD_ACRONYM */
1.16      kristaps   84:        { doaccent, "'", 1 }, /* TEXICMD_ACUTE */
1.42    ! kristaps   85:        { dosymbol, "AE", 2 }, /* TEXICMD_AE */
        !            86:        { dosymbol, "ae", 2 }, /* TEXICMD_AESMALL */
1.1       kristaps   87:        { doignbracket, "anchor", 6 }, /* TEXICMD_ANCHOR */
1.12      kristaps   88:        { dosection, "appendix", 8 }, /* TEXICMD_APPENDIX */
                     89:        { dosection, "appendixsec", 11 }, /* TEXICMD_APPENDIXSEC */
1.20      kristaps   90:        { dosubsection, "appendixsubsec", 14 }, /* TEXICMD_APPENDIXSUBSEC */
1.23      kristaps   91:        { dosubsubsection, "appendixsubsubsec", 17 }, /* TEXICMD_APPENDIXSUBSUBSEC */
1.25      kristaps   92:        { doinline, "asis", 4 }, /* TEXICMD_ASIS */
1.3       kristaps   93:        { dosymbol, "*", 1 }, /* TEXICMD_ASTERISK */
1.1       kristaps   94:        { dosymbol, "@", 1 }, /* TEXICMD_AT */
1.3       kristaps   95:        { doignline, "author", 6 }, /* TEXICMD_AUTHOR */
1.21      kristaps   96:        { doinline, "b", 1 }, /* TEXICMD_BOLD */
1.3       kristaps   97:        { dosymbol, "!", 1 }, /* TEXICMD_BANG */
1.7       kristaps   98:        { dosymbol, "bullet", 6 }, /* TEXICMD_BULLET */
1.1       kristaps   99:        { dobye, "bye", 3 }, /* TEXICMD_BYE */
1.34      kristaps  100:        { doblock, "cartouche", 9 }, /* TEXICMD_CARTOUCHE */
                    101:        { doaccent, ",", 1 }, /* TEXICMD_CEDILLA */
1.12      kristaps  102:        { doignline, "center", 6 }, /* TEXICMD_CENTER */
                    103:        { dosection, "chapter", 7 }, /* TEXICMD_CHAPTER */
1.1       kristaps  104:        { doignline, "cindex", 6 }, /* TEXICMD_CINDEX */
1.16      kristaps  105:        { doaccent, "^", 1 }, /* TEXICMD_CIRCUMFLEX */
1.24      kristaps  106:        { doinline, "cite", 4 }, /* TEXICMD_CITE */
                    107:        { dovalue, "clear", 5 }, /* TEXICMD_CLEAR */
1.21      kristaps  108:        { doinline, "code", 4 }, /* TEXICMD_CODE */
1.3       kristaps  109:        { dosymbol, ":", 1 }, /* TEXICMD_COLON */
1.18      kristaps  110:        { NULL, "columnfractions", 15 }, /* TEXICMD_COLUMNFRACTIONS */
1.35      kristaps  111:        { dosymbol, "comma", 5 }, /* TEXICMD_COMMA */
1.12      kristaps  112:        { doinline, "command", 7 }, /* TEXICMD_COMMAND */
1.1       kristaps  113:        { doignline, "c", 1 }, /* TEXICMD_COMMENT */
1.2       kristaps  114:        { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */
1.1       kristaps  115:        { doignline, "contents", 8 }, /* TEXICMD_CONTENTS */
                    116:        { doignblock, "copying", 7 }, /* TEXICMD_COPYING */
                    117:        { dosymbol, "copyright", 9 }, /* TEXICMD_COPYRIGHT */
1.27      kristaps  118:        { dodefindex, "defcodeindex", 12 }, /* TEXICMD_DEFCODEINDEX */
1.15      kristaps  119:        { dodefn, "deffn", 5 }, /* TEXICMD_DEFFN */
                    120:        { dodefn, "deffnx", 6 }, /* TEXICMD_DEFFNX */
1.27      kristaps  121:        { dodefindex, "defindex", 8 }, /* TEXICMD_DEFINDEX */
1.15      kristaps  122:        { dodefn, "defmac", 6 }, /* TEXICMD_DEFMAC */
                    123:        { dodefn, "defmacx", 7 }, /* TEXICMD_DEFMACX */
                    124:        { dodefn, "deftp", 5 }, /* TEXICMD_DEFTP */
                    125:        { dodefn, "deftpx", 6 }, /* TEXICMD_DEFTPX */
                    126:        { dodefn, "deftypefn", 9 }, /* TEXICMD_DEFTYPEFN */
                    127:        { dodefn, "deftypefnx", 10 }, /* TEXICMD_DEFTYPEFNX */
                    128:        { dodefn, "deftypefun", 10 }, /* TEXICMD_DEFTYPEFUN */
                    129:        { dodefn, "deftypefunx", 11 }, /* TEXICMD_DEFTYPEFUNX */
1.34      kristaps  130:        { dodefn, "deftypemethod", 13 }, /* TEXICMD_DEFTYPEMETHOD */
                    131:        { dodefn, "deftypemethodx", 14 }, /* TEXICMD_DEFTYPEMETHODX */
1.15      kristaps  132:        { dodefn, "deftypevar", 10 }, /* TEXICMD_DEFTYPEVAR */
                    133:        { dodefn, "deftypevarx", 11 }, /* TEXICMD_DEFTYPEVARX */
                    134:        { dodefn, "deftypevr", 9 }, /* TEXICMD_DEFTYPEVR */
                    135:        { dodefn, "deftypevrx", 10 }, /* TEXICMD_DEFTYPEVRX */
                    136:        { dodefn, "defun", 5 }, /* TEXICMD_DEFUN */
                    137:        { dodefn, "defunx", 6 }, /* TEXICMD_DEFUNX */
                    138:        { dodefn, "defvar", 6 }, /* TEXICMD_DEFVAR */
                    139:        { dodefn, "defvarx", 7 }, /* TEXICMD_DEFVARX */
                    140:        { dodefn, "defvr", 5 }, /* TEXICMD_DEFVR */
                    141:        { dodefn, "defvrx", 6 }, /* TEXICMD_DEFVRX */
1.1       kristaps  142:        { doignblock, "detailmenu", 10 }, /* TEXICMD_DETAILMENU */
1.21      kristaps  143:        { doinline, "dfn", 3 }, /* TEXICMD_DFN */
1.42    ! kristaps  144:        { dosymbol, "DH", 2 }, /* TEXICMD_DH */
        !           145:        { dosymbol, "dh", 2 }, /* TEXICMD_DHSMALL */
1.1       kristaps  146:        { doignline, "dircategory", 11 }, /* TEXICMD_DIRCATEGORY */
                    147:        { doignblock, "direntry", 8 }, /* TEXICMD_DIRENTRY */
1.3       kristaps  148:        { dodisplay, "display", 7 }, /* TEXICMD_DISPLAY */
1.28      kristaps  149:        { doignbracket, "dmn", 3 }, /* TEXICMD_DMN */
1.40      kristaps  150:        { doignblock, "documentdescription", 19 }, /* TEXICMD_DOCUMENTDESCRIPTION */
                    151:        { doignline, "documentencoding", 16 }, /* TEXICMD_DOCUMENTENCODING */
1.42    ! kristaps  152:        { doaccent, "dotaccent", 9 }, /* TEXICMD_DOTACCENT */
        !           153:        { doaccent, "dotless", 7 }, /* TEXICMD_DOTLESS */
1.2       kristaps  154:        { dosymbol, "dots", 4 }, /* TEXICMD_DOTS */
1.8       kristaps  155:        { dolink, "email", 5 }, /* TEXICMD_EMAIL */
1.21      kristaps  156:        { doinline, "emph", 4 }, /* TEXICMD_EMPH */
1.1       kristaps  157:        { NULL, "end", 3 }, /* TEXICMD_END */
1.34      kristaps  158:        { dosymbol, "enddots", 7 }, /* TEXICMD_ENDDOTS */
1.2       kristaps  159:        { doenumerate, "enumerate", 9 }, /* TEXICMD_ENUMERATE */
1.12      kristaps  160:        { doinline, "env", 3 }, /* TEXICMD_ENV */
1.28      kristaps  161:        { dosymbol, "equiv", 5 }, /* TEXICMD_EQUIV */
1.15      kristaps  162:        { dosymbol, "error", 5 }, /* TEXICMD_ERROR */
1.1       kristaps  163:        { doexample, "example", 7 }, /* TEXICMD_EXAMPLE */
1.42    ! kristaps  164:        { dosymbol, "exclamdown", 10 }, /* TEXICMD_EXCLAMDOWN */
1.25      kristaps  165:        { doignline, "exdent", 6 }, /* TEXICMD_EXDENT */
1.17      kristaps  166:        { dosymbol, "expansion", 9 }, /* TEXICMD_EXPANSION */
1.12      kristaps  167:        { doinline, "file", 4 }, /* TEXICMD_FILE */
1.17      kristaps  168:        { doignline, "finalout", 8 }, /* TEXICMD_FINALOUT */
1.20      kristaps  169:        { doignline, "findex", 6 }, /* TEXICMD_FINDEX */
1.32      kristaps  170:        { doignbracket, "footnote", 8 }, /* TEXICMD_FOOTNOTE */
1.20      kristaps  171:        { dotable, "ftable", 6 }, /* TEXICMD_FTABLE */
                    172:        { dodisplay, "format", 6 }, /* TEXICMD_FORMAT */
1.16      kristaps  173:        { doaccent, "`", 1 }, /* TEXICMD_GRAVE */
1.3       kristaps  174:        { doblock, "group", 5 }, /* TEXICMD_GROUP */
1.42    ! kristaps  175:        { doaccent, "H", 1 }, /* TEXICMD_H */
1.2       kristaps  176:        { dosection, "heading", 7 }, /* TEXICMD_HEADING */
1.3       kristaps  177:        { doignline, "headings", 8 }, /* TEXICMD_HEADINGS */
1.18      kristaps  178:        { doitem, "headitem", 8 }, /* TEXICMD_HEADITEM */
1.25      kristaps  179:        { doignblock, "html", 4 }, /* TEXICMD_HTML */
1.3       kristaps  180:        { dosymbol, "-", 1 }, /* TEXICMD_HYPHEN */
1.21      kristaps  181:        { doinline, "i", 1 }, /* TEXICMD_I */
1.24      kristaps  182:        { dovalue, "ifclear", 7 }, /* TEXICMD_IFCLEAR */
1.14      kristaps  183:        { doignblock, "ifdocbook", 9 }, /* TEXICMD_IFDOCBOOK */
1.1       kristaps  184:        { doignblock, "ifhtml", 6 }, /* TEXICMD_IFHTML */
1.26      kristaps  185:        { doblock, "ifinfo", 6 }, /* TEXICMD_IFINFO */
1.14      kristaps  186:        { doblock, "ifnotdocbook", 12 }, /* TEXICMD_IFNOTDOCBOOK */
                    187:        { doblock, "ifnothtml", 9 }, /* TEXICMD_IFNOTHTML */
                    188:        { doblock, "ifnotinfo", 9 }, /* TEXICMD_IFNOTINFO */
                    189:        { doignblock, "ifnotplaintext", 14 }, /* TEXICMD_IFNOTPLAINTEXT */
1.3       kristaps  190:        { doblock, "ifnottex", 8 }, /* TEXICMD_IFNOTTEX */
1.14      kristaps  191:        { doblock, "ifnotxml", 8 }, /* TEXICMD_IFNOTXML */
                    192:        { doblock, "ifplaintext", 11 }, /* TEXICMD_IFPLAINTEXT */
1.1       kristaps  193:        { doignblock, "iftex", 5 }, /* TEXICMD_IFTEX */
1.30      kristaps  194:        { dovalue, "ifset", 5 }, /* TEXICMD_IFSET */
1.14      kristaps  195:        { doignblock, "ifxml", 5 }, /* TEXICMD_IFXML */
1.17      kristaps  196:        { doignblock, "ignore", 6 }, /* TEXICMD_IGNORE */
1.1       kristaps  197:        { doignbracket, "image", 5 }, /* TEXICMD_IMAGE */
1.2       kristaps  198:        { doinclude, "include", 7 }, /* TEXICMD_INCLUDE */
1.13      kristaps  199:        { dodisplay, "indentblock", 11 }, /* TEXICMD_INDENTBLOCK */
1.34      kristaps  200:        { dolink, "inforef", 7 }, /* TEXICMD_INDENTBLOCK */
1.5       kristaps  201:        { doignline, "insertcopying", 13 }, /* TEXICMD_INSERTCOPYING */
1.1       kristaps  202:        { doitem, "item", 4 }, /* TEXICMD_ITEM */
                    203:        { doitemize, "itemize", 7 }, /* TEXICMD_ITEMIZE */
1.20      kristaps  204:        { doitem, "itemx", 5 }, /* TEXICMD_ITEMX */
1.21      kristaps  205:        { doinline, "kbd", 3 }, /* TEXICMD_KBD */
1.18      kristaps  206:        { dobracket, "key", 3 }, /* TEXICMD_KEY */
1.20      kristaps  207:        { doignline, "kindex", 6 }, /* TEXICMD_KINDEX */
1.42    ! kristaps  208:        { dosymbol, "L", 1 }, /* TEXICMD_L */
1.1       kristaps  209:        { dosymbol, "LaTeX", 5 }, /* TEXICMD_LATEX */
1.23      kristaps  210:        { dosecoffs, "lowersections", 13 }, /* TEXICMD_LOWERSECTIONS */
1.42    ! kristaps  211:        { dosymbol, "l", 1 }, /* TEXICMD_LSMALL */
1.30      kristaps  212:        { domacro, "macro", 5 }, /* TEXICMD_MACRO */
1.42    ! kristaps  213:        { doaccent, "=", 1 }, /* TEXICMD_MACRON */
1.3       kristaps  214:        { domath, "math", 4 }, /* TEXICMD_MATH */
1.1       kristaps  215:        { doignblock, "menu", 4 }, /* TEXICMD_MENU */
1.25      kristaps  216:        { dosymbol, "minus", 5 }, /* TEXICMD_MINUS */
1.18      kristaps  217:        { domultitable, "multitable", 10 }, /* TEXICMD_MULTITABLE */
1.15      kristaps  218:        { doignline, "need", 4 }, /* TEXICMD_NEED */
1.3       kristaps  219:        { dosymbol, "\n", 1 }, /* TEXICMD_NEWLINE */
1.1       kristaps  220:        { doignline, "node", 4 }, /* TEXICMD_NODE */
1.3       kristaps  221:        { doignline, "noindent", 8 }, /* TEXICMD_NOINDENT */
1.42    ! kristaps  222:        { dosymbol, "O", 1 }, /* TEXICMD_O */
        !           223:        { dosymbol, "OE", 2 }, /* TEXICMD_OE */
        !           224:        { dosymbol, "oe", 2 }, /* TEXICMD_OESMALL */
        !           225:        { doaccent, "ogonek", 6 }, /* TEXICMD_OGONEK */
1.16      kristaps  226:        { doinline, "option", 6 }, /* TEXICMD_OPTION */
1.42    ! kristaps  227:        { dosymbol, "ordf", 4 }, /* TEXICMD_ORDF */
        !           228:        { dosymbol, "ordm", 4 }, /* TEXICMD_ORDM */
        !           229:        { dosymbol, "o", 1 }, /* TEXICMD_OSMALL */
1.3       kristaps  230:        { doignline, "page", 4 }, /* TEXICMD_PAGE */
1.25      kristaps  231:        { doignline, "paragraphindent", 15 }, /* TEXICMD_PARINDENT */
                    232:        { dosymbol, ".", 1 }, /* TEXICMD_PERIOD */
1.28      kristaps  233:        { doignline, "pindex", 6 }, /* TEXICMD_PINDEX */
1.2       kristaps  234:        { doignline, "printindex", 10 }, /* TEXICMD_PRINTINDEX */
1.42    ! kristaps  235:        { dolink, "pxref", 5 }, /* TEXICMD_PXREF */
        !           236:        { dosymbol, "questiondown", 12 }, /* TEXICMD_QUESTIONDOWN */
        !           237:        { dosymbol, "?", 1 }, /* TEXICMD_QUESTIONMARK */
        !           238:        { doquotation, "quotation", 9 }, /* TEXICMD_QUOTATION */
1.21      kristaps  239:        { doinline, "r", 1 }, /* TEXICMD_R */
1.23      kristaps  240:        { dosecoffs, "raisesections", 13 }, /* TEXICMD_RAISESECTIONS */
1.1       kristaps  241:        { dobracket, "ref", 3 }, /* TEXICMD_REF */
1.28      kristaps  242:        { doignline, "refill", 6 }, /* TEXICMD_REFILL */
1.15      kristaps  243:        { dosymbol, "result", 6 }, /* TEXICMD_RESULT */
1.42    ! kristaps  244:        { doaccent, "ringaccent", 10 }, /* TEXICMD_RINGACCENT */
1.21      kristaps  245:        { doinline, "samp", 4 }, /* TEXICMD_SAMP */
                    246:        { doinline, "sansserif", 9 }, /* TEXICMD_SANSSERIF */
1.7       kristaps  247:        { dobracket, "sc", 2 }, /* TEXICMD_SC */
1.1       kristaps  248:        { dosection, "section", 7 }, /* TEXICMD_SECTION */
1.24      kristaps  249:        { dovalue, "set", 3 }, /* TEXICMD_SET */
1.1       kristaps  250:        { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */
1.35      kristaps  251:        { doignline, "setcontentsaftertitlepage", 25 }, /* TEXICMD_SETCONTENTSAFTER */
1.1       kristaps  252:        { doignline, "setfilename", 11 }, /* TEXICMD_SETFILENAME */
1.10      kristaps  253:        { dotitle, "settitle", 8 }, /* TEXICMD_SETTITLE */
1.25      kristaps  254:        { doignline, "shortcontents", 13 }, /* TEXICMD_SHORTCONTENTS */
1.21      kristaps  255:        { doinline, "slanted", 7 }, /* TEXICMD_SLANTED */
1.34      kristaps  256:        { dosymbol, "/", 1 }, /* TEXICMD_SLASH */
1.3       kristaps  257:        { dosp, "sp", 2 }, /* TEXICMD_SP */
                    258:        { dosymbol, " ", 1 }, /* TEXICMD_SPACE */
1.17      kristaps  259:        { doignline, "smallbook", 9 }, /* TEXICMD_SMALLBOOK */
1.12      kristaps  260:        { dodisplay, "smalldisplay", 12 }, /* TEXICMD_SMALLDISPLAY */
1.3       kristaps  261:        { doexample, "smallexample", 12 }, /* TEXICMD_SMALLEXAMPLE */
1.20      kristaps  262:        { dodisplay, "smallformat", 11 }, /* TEXICMD_SMALLFORMAT */
1.13      kristaps  263:        { dodisplay, "smallindentblock", 16 }, /* TEXICMD_SMALLINDENTBLOCK */
1.3       kristaps  264:        { dosymbol, "{", 1 }, /* TEXICMD_SQUIGGLE_LEFT */
                    265:        { dosymbol, "}", 1 }, /* TEXICMD_SQUIGGLE_RIGHT */
1.35      kristaps  266:        { dosymbol, "ss", 2 }, /* TEXICMD_SS */
1.21      kristaps  267:        { doinline, "strong", 6 }, /* TEXICMD_STRONG */
1.20      kristaps  268:        { dosubsection, "subheading", 10 }, /* TEXICMD_SUBHEADING */
1.1       kristaps  269:        { dosubsection, "subsection", 10 }, /* TEXICMD_SUBSECTION */
1.28      kristaps  270:        { dosubsubsection, "subsubheading", 13 }, /* TEXICMD_SUBSUBHEADING */
1.23      kristaps  271:        { dosubsubsection, "subsubsection", 13 }, /* TEXICMD_SUBSUBSECTION */
1.3       kristaps  272:        { doignline, "subtitle", 8 }, /* TEXICMD_SUBTITLE */
1.25      kristaps  273:        { doignline, "summarycontents", 15 }, /* TEXICMD_SUMMARYCONTENTS */
1.27      kristaps  274:        { doignline, "synindex", 8 }, /* TEXICMD_SYNINDEX */
1.20      kristaps  275:        { doignline, "syncodeindex", 12 }, /* TEXICMD_SYNCODEINDEX */
1.21      kristaps  276:        { doinline, "t", 1 }, /* TEXICMD_T */
1.18      kristaps  277:        { dotab, "tab", 3 }, /* TEXICMD_TAB */
                    278:        { dosymbol, "\t", 1 }, /* TEXICMD_TABSYM */
1.1       kristaps  279:        { dotable, "table", 5 }, /* TEXICMD_TABLE */
                    280:        { doignblock, "tex", 3 }, /* TEXICMD_TEX */
                    281:        { dosymbol, "TeX", 3 }, /* TEXICMD_TEXSYM */
1.42    ! kristaps  282:        { dosymbol, "TH", 2 }, /* TEXICMD_TH */
        !           283:        { dosymbol, "th", 2 }, /* TEXICMD_THSMALL */
1.35      kristaps  284:        { dosymbol, "tie", 3 }, /* TEXICMD_TIE */
1.42    ! kristaps  285:        { doaccent, "tieaccent", 9 }, /* TEXICMD_TIEACCENT */
1.16      kristaps  286:        { doaccent, "~", 1 }, /* TEXICMD_TILDE */
1.25      kristaps  287:        { doignline, "tindex", 6 }, /* TEXICMD_TINDEX */
1.3       kristaps  288:        { doignline, "title", 5 }, /* TEXICMD_TITLE */
1.1       kristaps  289:        { dobracket, "titlefont", 9 }, /* TEXICMD_TITLEFONT */
                    290:        { doignblock, "titlepage", 9 }, /* TEXICMD_TITLEPAGE */
                    291:        { dotop, "top", 3 }, /* TEXICMD_TOP */
1.42    ! kristaps  292:        { doaccent, "u", 1 }, /* TEXICMD_U */
        !           293:        { doaccent, "ubaraccent", 10 }, /* TEXICMD_UBARACCENT */
        !           294:        { doaccent, "udotaccent", 10 }, /* TEXICMD_UDOTACCENT */
1.16      kristaps  295:        { doaccent, "\"", 1 }, /* TEXICMD_UMLAUT */
1.12      kristaps  296:        { dosection, "unnumbered", 10 }, /* TEXICMD_UNNUMBERED */
1.2       kristaps  297:        { dosection, "unnumberedsec", 13 }, /* TEXICMD_UNNUMBEREDSEC */
1.20      kristaps  298:        { dosubsection, "unnumberedsubsec", 16 }, /* TEXICMD_UNNUMBEREDSUBSEC */
1.23      kristaps  299:        { dosubsubsection, "unnumberedsubsubsec", 19 }, /* TEXICMD_UNNUMBEREDSUBSUBSEC */
1.8       kristaps  300:        { dolink, "uref", 4 }, /* TEXICMD_UREF */
                    301:        { dolink, "url", 3 }, /* TEXICMD_URL */
1.34      kristaps  302:        { doignline, "", 0 }, /* TEXICMD_USER_INDEX */
1.42    ! kristaps  303:        { doaccent, "v", 1 }, /* TEXICMD_V */
1.24      kristaps  304:        { dovalue, "value", 5 }, /* TEXICMD_VALUE */
1.12      kristaps  305:        { doinline, "var", 3 }, /* TEXICMD_VAR */
1.33      kristaps  306:        { doverb, "verb", 4 }, /* TEXICMD_VERB */
                    307:        { doverbatim, "verbatim", 8 }, /* TEXICMD_VERBATIM */
1.16      kristaps  308:        { doverbinclude, "verbatiminclude", 15 }, /* TEXICMD_VERBATIMINCLUDE */
1.18      kristaps  309:        { doignline, "vindex", 6 }, /* TEXICMD_VINDEX */
1.9       kristaps  310:        { dosp, "vskip", 5 }, /* TEXICMD_VSKIP */
1.20      kristaps  311:        { dotable, "vtable", 6 }, /* TEXICMD_VTABLE */
1.3       kristaps  312:        { dobracket, "w", 1 }, /* TEXICMD_W */
1.8       kristaps  313:        { dolink, "xref", 4 }, /* TEXICMD_XREF */
1.20      kristaps  314:        /* TEXICMD__END */
1.1       kristaps  315: };
                    316:
1.24      kristaps  317: const  struct texitok *const texitoks = __texitoks;
1.18      kristaps  318:
1.2       kristaps  319: static void
1.27      kristaps  320: dodefindex(struct texi *p, enum texicmd cmd,
                    321:        const char *buf, size_t sz, size_t *pos)
                    322: {
                    323:        size_t   start, end;
                    324:        char    *cp;
                    325:
                    326:        while (*pos < sz && isws(buf[*pos]))
                    327:                advance(p, buf, pos);
                    328:
                    329:        start = end = *pos;
                    330:        while (end < sz && ! ismspace(buf[end]))
                    331:                end++;
                    332:
                    333:        if (start == end) {
                    334:                advanceeoln(p, buf, sz, pos, 1);
                    335:                return;
                    336:        } else if (NULL == (cp = malloc(end - start + 1)))
                    337:                texiabort(p, NULL);
                    338:
                    339:        memcpy(cp, &buf[start], end - start);
                    340:        cp[end - start] = '\0';
                    341:
                    342:        p->indexs = realloc(p->indexs,
                    343:                sizeof(char *) * (p->indexsz + 1));
                    344:
                    345:        if (NULL == p->indexs)
                    346:                texiabort(p, NULL);
                    347:        p->indexs[p->indexsz++] = cp;
                    348: }
                    349:
                    350: static void
1.15      kristaps  351: dodefn(struct texi *p, enum texicmd cmd,
1.3       kristaps  352:        const char *buf, size_t sz, size_t *pos)
                    353: {
                    354:        const char      *blk;
                    355:
1.5       kristaps  356:        blk = NULL;
1.3       kristaps  357:        switch (cmd) {
1.15      kristaps  358:        case (TEXICMD_DEFFN):
1.35      kristaps  359:        case (TEXICMD_DEFMAC):
1.15      kristaps  360:        case (TEXICMD_DEFTP):
1.3       kristaps  361:        case (TEXICMD_DEFTYPEFN):
                    362:        case (TEXICMD_DEFTYPEFUN):
1.34      kristaps  363:        case (TEXICMD_DEFTYPEMETHOD):
1.15      kristaps  364:        case (TEXICMD_DEFTYPEVAR):
                    365:        case (TEXICMD_DEFTYPEVR):
                    366:        case (TEXICMD_DEFUN):
                    367:        case (TEXICMD_DEFVAR):
                    368:        case (TEXICMD_DEFVR):
1.5       kristaps  369:                blk = texitoks[cmd].tok;
1.3       kristaps  370:                break;
1.5       kristaps  371:        default:
1.3       kristaps  372:                break;
                    373:        }
                    374:
                    375:        if (p->ign) {
1.15      kristaps  376:                NULL != blk ?
                    377:                        parseto(p, buf, sz, pos, blk) :
                    378:                        parseeoln(p, buf, sz, pos);
1.3       kristaps  379:                return;
                    380:        }
                    381:
1.15      kristaps  382:        if (NULL != blk)
                    383:                texivspace(p);
                    384:
1.3       kristaps  385:        switch (cmd) {
1.34      kristaps  386:        case (TEXICMD_DEFTYPEMETHOD):
                    387:        case (TEXICMD_DEFTYPEMETHODX):
                    388:                texiputchars(p, "Method");
                    389:                break;
1.15      kristaps  390:        case (TEXICMD_DEFMAC):
                    391:        case (TEXICMD_DEFMACX):
                    392:                texiputchars(p, "Macro");
                    393:                break;
                    394:        case (TEXICMD_DEFTYPEVAR):
                    395:        case (TEXICMD_DEFTYPEVARX):
                    396:        case (TEXICMD_DEFVAR):
                    397:        case (TEXICMD_DEFVARX):
                    398:                texiputchars(p, "Variable");
                    399:                break;
1.3       kristaps  400:        case (TEXICMD_DEFTYPEFUN):
1.15      kristaps  401:        case (TEXICMD_DEFTYPEFUNX):
                    402:        case (TEXICMD_DEFUN):
                    403:        case (TEXICMD_DEFUNX):
                    404:                texiputchars(p, "Function");
1.3       kristaps  405:                break;
                    406:        default:
1.15      kristaps  407:                parselinearg(p, buf, sz, pos);
1.3       kristaps  408:                break;
                    409:        }
1.15      kristaps  410:
                    411:        texiputchars(p, ":\n");
                    412:
                    413:        switch (cmd) {
                    414:        case (TEXICMD_DEFMAC):
                    415:        case (TEXICMD_DEFMACX):
                    416:                teximacroopen(p, "Dv");
                    417:                while (parselinearg(p, buf, sz, pos))
                    418:                        /* Spin. */ ;
                    419:                teximacroclose(p);
                    420:                break;
                    421:        case (TEXICMD_DEFFN):
                    422:        case (TEXICMD_DEFFNX):
                    423:        case (TEXICMD_DEFUN):
                    424:        case (TEXICMD_DEFUNX):
                    425:                teximacroopen(p, "Fo");
                    426:                parselinearg(p, buf, sz, pos);
                    427:                teximacroclose(p);
                    428:                teximacroopen(p, "Fa");
                    429:                while (parselinearg(p, buf, sz, pos))
                    430:                        /* Spin. */ ;
                    431:                teximacroclose(p);
                    432:                teximacro(p, "Fc");
                    433:                break;
                    434:        case (TEXICMD_DEFTYPEFUN):
                    435:        case (TEXICMD_DEFTYPEFUNX):
                    436:        case (TEXICMD_DEFTYPEFN):
                    437:        case (TEXICMD_DEFTYPEFNX):
1.34      kristaps  438:        case (TEXICMD_DEFTYPEMETHOD):
                    439:        case (TEXICMD_DEFTYPEMETHODX):
1.15      kristaps  440:                teximacroopen(p, "Ft");
                    441:                parselinearg(p, buf, sz, pos);
                    442:                teximacroclose(p);
                    443:                teximacroopen(p, "Fo");
                    444:                parselinearg(p, buf, sz, pos);
                    445:                teximacroclose(p);
                    446:                teximacroopen(p, "Fa");
                    447:                while (parselinearg(p, buf, sz, pos))
                    448:                        /* Spin. */ ;
                    449:                teximacroclose(p);
                    450:                teximacro(p, "Fc");
                    451:                break;
                    452:        case (TEXICMD_DEFTP):
                    453:        case (TEXICMD_DEFTPX):
                    454:        case (TEXICMD_DEFTYPEVAR):
                    455:        case (TEXICMD_DEFTYPEVARX):
                    456:        case (TEXICMD_DEFTYPEVR):
                    457:        case (TEXICMD_DEFTYPEVRX):
                    458:                teximacroopen(p, "Vt");
                    459:                while (parselinearg(p, buf, sz, pos))
                    460:                        /* Spin. */ ;
                    461:                teximacroclose(p);
                    462:                break;
                    463:        case (TEXICMD_DEFVAR):
                    464:        case (TEXICMD_DEFVARX):
                    465:        case (TEXICMD_DEFVR):
                    466:        case (TEXICMD_DEFVRX):
                    467:                teximacroopen(p, "Va");
                    468:                while (parselinearg(p, buf, sz, pos))
                    469:                        /* Spin. */ ;
                    470:                teximacroclose(p);
                    471:                break;
                    472:        default:
                    473:                abort();
1.3       kristaps  474:        }
1.15      kristaps  475:
1.11      kristaps  476:        texivspace(p);
1.3       kristaps  477:        if (NULL != blk)
                    478:                parseto(p, buf, sz, pos, blk);
                    479: }
                    480:
                    481: static void
1.30      kristaps  482: domacro(struct texi *p, enum texicmd cmd,
                    483:        const char *buf, size_t sz, size_t *pos)
                    484: {
                    485:        size_t            start, end, endtoksz, len;
                    486:        struct teximacro  m;
                    487:        const char       *endtok, *blk;
                    488:
                    489:        memset(&m, 0, sizeof(struct teximacro));
                    490:
                    491:        while (*pos < sz && isws(buf[*pos]))
                    492:                advance(p, buf, pos);
                    493:
                    494:        for (start = end = *pos; end < sz; end++)
                    495:                if (ismspace(buf[end]) || '{' == buf[end])
                    496:                        break;
                    497:
                    498:        if (start == end)
                    499:                texierr(p, "zero-length macro name");
                    500:
                    501:        advanceto(p, buf, pos, end);
                    502:
                    503:        m.key = malloc(end - start + 1);
                    504:        if (NULL == m.key)
                    505:                texiabort(p, NULL);
                    506:        memcpy(m.key, &buf[start], end - start);
                    507:        m.key[end - start] = '\0';
                    508:
1.31      kristaps  509:        m.args = argparse(p, buf, sz, pos, &m.argsz, 0);
1.30      kristaps  510:        advanceeoln(p, buf, sz, pos, 0);
                    511:
                    512:        start = *pos;
                    513:        endtok = "\n@end macro\n";
                    514:        endtoksz = strlen(endtok);
                    515:        blk = memmem(&buf[start], sz, endtok, endtoksz);
                    516:        if (NULL == blk)
                    517:                texierr(p, "unterminated macro body");
                    518:        while (&buf[*pos] != blk)
                    519:                advance(p, buf, pos);
                    520:        assert('\n' == buf[*pos]);
                    521:        advance(p, buf, pos);
                    522:        len = blk - &buf[start];
                    523:        m.value = malloc(len + 1);
                    524:        if (NULL == m.value)
                    525:                texiabort(p, NULL);
                    526:        memcpy(m.value, &buf[start], len);
                    527:        m.value[len] = '\0';
                    528:
                    529:        p->macros = realloc
                    530:                (p->macros,
                    531:                (p->macrosz + 1) *
                    532:                sizeof(struct teximacro));
                    533:        if (NULL == p->macros)
                    534:                texiabort(p, NULL);
                    535:
                    536:        p->macros[p->macrosz++] = m;
                    537:        advanceeoln(p, buf, sz, pos, 1);
                    538: }
                    539:
                    540: static void
1.1       kristaps  541: doignblock(struct texi *p, enum texicmd cmd,
                    542:        const char *buf, size_t sz, size_t *pos)
                    543: {
1.26      kristaps  544:        char             end[32];
                    545:        const char      *term;
                    546:        size_t           endsz, endpos;
                    547:
                    548:        /*
                    549:         * We want to completely ignore everything in these blocks, so
                    550:         * simply jump to the @end block.
                    551:         */
                    552:        endsz = snprintf(end, sizeof(end),
                    553:                "\n@end %s\n", texitoks[cmd].tok);
                    554:        assert(endsz < sizeof(end));
                    555:
                    556:        /*
                    557:         * Look up where our end token occurs.
                    558:         * Set our end position based on the relative offset of that
                    559:         * from our current position, or the EOF if we don't have a
                    560:         * proper ending point.
                    561:         */
                    562:        term = memmem(&buf[*pos], sz, end, endsz);
                    563:        endpos = NULL == term ? sz :
1.36      kristaps  564:                *pos + (size_t)(term - &buf[*pos]);
1.26      kristaps  565:        assert(endpos <= sz);
                    566:        while (*pos < endpos)
                    567:                advance(p, buf, pos);
                    568:
                    569:        /* Only do this if we're not already at the end. */
                    570:        if (endpos < sz)
                    571:                advanceto(p, buf, pos, endpos + endsz);
1.1       kristaps  572: }
                    573:
                    574: static void
1.3       kristaps  575: doblock(struct texi *p, enum texicmd cmd,
1.1       kristaps  576:        const char *buf, size_t sz, size_t *pos)
                    577: {
                    578:
1.5       kristaps  579:        parseto(p, buf, sz, pos, texitoks[cmd].tok);
1.1       kristaps  580: }
                    581:
                    582: static void
1.12      kristaps  583: doinline(struct texi *p, enum texicmd cmd,
                    584:        const char *buf, size_t sz, size_t *pos)
1.1       kristaps  585: {
1.21      kristaps  586:        const char      *macro = NULL;
1.12      kristaps  587:
                    588:        switch (cmd) {
1.21      kristaps  589:        case (TEXICMD_CODE):
                    590:        case (TEXICMD_KBD):
                    591:        case (TEXICMD_SAMP):
                    592:        case (TEXICMD_T):
                    593:                macro = "Li";
                    594:                break;
                    595:        case (TEXICMD_CITE):
                    596:        case (TEXICMD_DFN):
                    597:        case (TEXICMD_EMPH):
                    598:        case (TEXICMD_I):
                    599:        case (TEXICMD_SLANTED):
                    600:                macro = "Em";
                    601:                break;
                    602:        case (TEXICMD_B):
                    603:        case (TEXICMD_STRONG):
                    604:                macro = "Sy";
                    605:                break;
1.12      kristaps  606:        case (TEXICMD_COMMAND):
                    607:                macro = "Xr";
                    608:                break;
                    609:        case (TEXICMD_ENV):
                    610:                macro = "Ev";
                    611:                break;
                    612:        case (TEXICMD_FILE):
                    613:                macro = "Pa";
                    614:                break;
1.16      kristaps  615:        case (TEXICMD_OPTION):
                    616:                macro = "Op";
                    617:                break;
1.12      kristaps  618:        case (TEXICMD_VAR):
                    619:                macro = "Va";
                    620:                break;
                    621:        default:
1.22      kristaps  622:                break;
1.12      kristaps  623:        }
                    624:
1.25      kristaps  625:        if (NULL == macro || p->literal || TEXILIST_TABLE == p->list) {
1.12      kristaps  626:                parsebracket(p, buf, sz, pos);
                    627:                return;
                    628:        }
1.1       kristaps  629:
1.5       kristaps  630:        teximacroopen(p, macro);
1.1       kristaps  631:        p->seenws = 0;
                    632:        parsebracket(p, buf, sz, pos);
1.11      kristaps  633:        texipunctuate(p, buf, sz, pos);
1.5       kristaps  634:        teximacroclose(p);
1.1       kristaps  635: }
                    636:
                    637: static void
1.25      kristaps  638: doverb(struct texi *p, enum texicmd cmd,
1.33      kristaps  639:        const char *buf, size_t sz, size_t *pos)
                    640: {
                    641:        char     delim;
1.34      kristaps  642:        size_t   start;
1.33      kristaps  643:
                    644:        while (*pos < sz && isws(buf[*pos]))
                    645:                advance(p, buf, pos);
                    646:        if (*pos == sz || '{' != buf[*pos])
                    647:                return;
                    648:        advance(p, buf, pos);
                    649:        if (*pos == sz)
                    650:                return;
                    651:
                    652:        delim = buf[*pos];
                    653:        advance(p, buf, pos);
                    654:        /* Make sure we flush out our initial whitespace... */
                    655:        if (p->seenws && p->outcol && 0 == p->literal)
                    656:                texiputchar(p, ' ');
                    657:        p->seenws = 0;
1.34      kristaps  658:        start = *pos;
1.33      kristaps  659:        /* Read until we see the delimiter then end-brace. */
                    660:        while (*pos < sz - 1) {
                    661:                if (buf[*pos] == delim && buf[*pos + 1] == '}')
                    662:                        break;
                    663:                advance(p, buf, pos);
                    664:        }
                    665:        if (*pos == sz - 1)
                    666:                return;
1.34      kristaps  667:        texiputbuf(p, buf, start, *pos);
                    668:
1.33      kristaps  669:        /* Make sure we read after the end-brace. */
                    670:        assert(delim == buf[*pos]);
                    671:        advance(p, buf, pos);
                    672:        assert('}' == buf[*pos]);
                    673:        advance(p, buf, pos);
                    674: }
                    675:
                    676: static void
                    677: doverbatim(struct texi *p, enum texicmd cmd,
1.25      kristaps  678:        const char *buf, size_t sz, size_t *pos)
                    679: {
                    680:        const char      *end, *term;
                    681:        size_t           endsz, endpos;
                    682:
1.26      kristaps  683:        advanceeoln(p, buf, sz, pos, 1);
                    684:
1.25      kristaps  685:        /* We end at exactly this token. */
                    686:        end = "\n@end verbatim\n";
                    687:        endsz = strlen(end);
                    688:
                    689:        /*
                    690:         * Look up where our end token occurs.
                    691:         * Set our end position based on the relative offset of that
                    692:         * from our current position.
                    693:         */
                    694:        term = memmem(&buf[*pos], sz, end, endsz);
                    695:        endpos = NULL == term ? sz :
1.36      kristaps  696:                *pos + (size_t)(term - &buf[*pos]);
1.25      kristaps  697:
                    698:        teximacro(p, "Bd -literal -offset indent");
                    699:        assert(endpos <= sz);
1.26      kristaps  700:        while (*pos < endpos) {
1.41      kristaps  701:                texiputchar(p, buf[*pos]);
1.25      kristaps  702:                advance(p, buf, pos);
                    703:        }
                    704:        teximacro(p, "Ed");
1.26      kristaps  705:        advanceto(p, buf, pos, endpos + endsz);
1.25      kristaps  706: }
                    707:
                    708: static void
1.16      kristaps  709: doverbinclude(struct texi *p, enum texicmd cmd,
                    710:        const char *buf, size_t sz, size_t *pos)
                    711: {
1.25      kristaps  712:        char             fname[PATH_MAX], path[PATH_MAX];
                    713:        int              rc;
                    714:        size_t           i, end;
                    715:        const char      *v;
                    716:        enum texicmd     type;
1.16      kristaps  717:
                    718:        while (*pos < sz && ' ' == buf[*pos])
                    719:                advance(p, buf, pos);
                    720:
1.25      kristaps  721:        for (i = 0; *pos < sz && '\n' != buf[*pos]; ) {
1.16      kristaps  722:                if (i == sizeof(fname) - 1)
                    723:                        break;
1.25      kristaps  724:                if ('@' != buf[*pos]) {
                    725:                        fname[i++] = buf[*pos];
                    726:                        advance(p, buf, pos);
                    727:                        continue;
                    728:                }
1.30      kristaps  729:                type = texicmd(p, buf, *pos, sz, &end, NULL);
1.25      kristaps  730:                advanceto(p, buf, pos, end);
                    731:                if (TEXICMD_VALUE != type)
                    732:                        texierr(p, "unknown verbatiminclude command");
                    733:                v = valueblookup(p, buf, sz, pos);
                    734:                if (NULL == v)
                    735:                        continue;
                    736:                while ('\0' != *v) {
                    737:                        if (i == sizeof(fname) - 1)
                    738:                                break;
                    739:                        fname[i++] = *v++;
                    740:                }
                    741:                if ('\0' != *v)
                    742:                        break;
1.16      kristaps  743:        }
                    744:
                    745:        if (i == 0)
                    746:                texierr(p, "path too short");
                    747:        else if ('\n' != buf[*pos])
                    748:                texierr(p, "path too long");
                    749:        else if ('/' == fname[0])
                    750:                texierr(p, "no absolute paths");
                    751:        fname[i] = '\0';
                    752:
                    753:        if (strstr(fname, "../") || strstr(fname, "/.."))
                    754:                texierr(p, "insecure path");
                    755:
                    756:        rc = snprintf(path, sizeof(path),
                    757:                "%s/%s", p->dirs[0], fname);
                    758:        if (rc < 0)
                    759:                texierr(p, "couldn't format path");
                    760:        else if ((size_t)rc >= sizeof(path))
                    761:                texierr(p, "path too long");
                    762:
                    763:        parsefile(p, path, 0);
                    764: }
                    765:
                    766: static void
1.2       kristaps  767: doinclude(struct texi *p, enum texicmd cmd,
                    768:        const char *buf, size_t sz, size_t *pos)
                    769: {
1.25      kristaps  770:        char             fname[PATH_MAX], path[PATH_MAX];
                    771:        size_t           i, end;
                    772:        int              rc;
                    773:        const char      *v;
                    774:        enum texicmd     type;
1.2       kristaps  775:
                    776:        while (*pos < sz && ' ' == buf[*pos])
                    777:                advance(p, buf, pos);
                    778:
                    779:        /* Read in the filename. */
1.25      kristaps  780:        for (i = 0; *pos < sz && '\n' != buf[*pos]; ) {
1.2       kristaps  781:                if (i == sizeof(fname) - 1)
                    782:                        break;
1.25      kristaps  783:                if ('@' != buf[*pos]) {
                    784:                        fname[i++] = buf[*pos];
                    785:                        advance(p, buf, pos);
                    786:                        continue;
                    787:                }
1.30      kristaps  788:                type = texicmd(p, buf, *pos, sz, &end, NULL);
1.25      kristaps  789:                advanceto(p, buf, pos, end);
                    790:                if (TEXICMD_VALUE != type)
                    791:                        texierr(p, "unknown include command");
                    792:                v = valueblookup(p, buf, sz, pos);
                    793:                if (NULL == v)
                    794:                        continue;
                    795:                while ('\0' != *v) {
                    796:                        if (i == sizeof(fname) - 1)
                    797:                                break;
                    798:                        fname[i++] = *v++;
                    799:                }
                    800:                if ('\0' != *v)
                    801:                        break;
1.2       kristaps  802:        }
                    803:
                    804:        if (i == 0)
                    805:                texierr(p, "path too short");
                    806:        else if ('\n' != buf[*pos])
                    807:                texierr(p, "path too long");
                    808:        else if ('/' == fname[0])
                    809:                texierr(p, "no absolute paths");
                    810:        fname[i] = '\0';
                    811:
                    812:        if (strstr(fname, "../") || strstr(fname, "/.."))
                    813:                texierr(p, "insecure path");
                    814:
1.5       kristaps  815:        for (i = 0; i < p->dirsz; i++) {
                    816:                rc = snprintf(path, sizeof(path),
                    817:                        "%s/%s", p->dirs[i], fname);
                    818:                if (rc < 0)
                    819:                        texierr(p, "couldn't format path");
                    820:                else if ((size_t)rc >= sizeof(path))
                    821:                        texierr(p, "path too long");
                    822:                else if (-1 == access(path, R_OK))
                    823:                        continue;
                    824:
1.16      kristaps  825:                parsefile(p, path, 1);
1.5       kristaps  826:                return;
                    827:        }
1.2       kristaps  828:
1.5       kristaps  829:        texierr(p, "couldn't find %s in includes", fname);
1.2       kristaps  830: }
                    831:
                    832: static void
1.1       kristaps  833: dobracket(struct texi *p, enum texicmd cmd,
                    834:        const char *buf, size_t sz, size_t *pos)
                    835: {
                    836:
                    837:        parsebracket(p, buf, sz, pos);
                    838: }
                    839:
                    840: static void
1.3       kristaps  841: dodisplay(struct texi *p, enum texicmd cmd,
                    842:        const char *buf, size_t sz, size_t *pos)
                    843: {
                    844:
1.20      kristaps  845:        switch (cmd) {
                    846:        case (TEXICMD_FORMAT):
                    847:        case (TEXICMD_SMALLFORMAT):
                    848:                teximacro(p, "Bd -filled");
                    849:                break;
                    850:        default:
                    851:                teximacro(p, "Bd -filled -offset indent");
                    852:                break;
                    853:        }
                    854:
1.11      kristaps  855:        p->seenvs = 1;
1.12      kristaps  856:        /* FIXME: ignore and parseeoln. */
1.3       kristaps  857:        advanceeoln(p, buf, sz, pos, 1);
1.13      kristaps  858:        parseto(p, buf, sz, pos, texitoks[cmd].tok);
1.5       kristaps  859:        teximacro(p, "Ed");
1.3       kristaps  860: }
                    861:
                    862: static void
1.1       kristaps  863: doexample(struct texi *p, enum texicmd cmd,
                    864:        const char *buf, size_t sz, size_t *pos)
                    865: {
                    866:
1.5       kristaps  867:        teximacro(p, "Bd -literal -offset indent");
1.12      kristaps  868:        /* FIXME: ignore and parseeoln. */
1.3       kristaps  869:        advanceeoln(p, buf, sz, pos, 1);
                    870:        p->literal++;
1.13      kristaps  871:        parseto(p, buf, sz, pos, texitoks[cmd].tok);
1.3       kristaps  872:        p->literal--;
1.5       kristaps  873:        teximacro(p, "Ed");
1.1       kristaps  874: }
                    875:
                    876: static void
                    877: dobye(struct texi *p, enum texicmd cmd,
                    878:        const char *buf, size_t sz, size_t *pos)
                    879: {
                    880:
                    881:        texiexit(p);
                    882:        exit(EXIT_SUCCESS);
                    883: }
                    884:
                    885: static void
1.10      kristaps  886: dotitle(struct texi *p, enum texicmd cmd,
                    887:        const char *buf, size_t sz, size_t *pos)
                    888: {
                    889:        size_t   start, end;
                    890:
                    891:        while (*pos < sz && isws(buf[*pos]))
                    892:                advance(p, buf, pos);
                    893:        start = end = *pos;
                    894:        while (end < sz && '\n' != buf[end])
                    895:                end++;
1.26      kristaps  896:        advanceeoln(p, buf, sz, pos, 1);
1.10      kristaps  897:        free(p->subtitle);
                    898:        p->subtitle = malloc(end - start + 1);
1.27      kristaps  899:        if (NULL == p->subtitle)
                    900:                texiabort(p, NULL);
1.10      kristaps  901:        memcpy(p->subtitle, &buf[start], end - start);
                    902:        p->subtitle[end - start] = '\0';
                    903: }
                    904:
                    905: static void
1.16      kristaps  906: doaccent(struct texi *p, enum texicmd cmd,
                    907:        const char *buf, size_t sz, size_t *pos)
                    908: {
1.42    ! kristaps  909:        int      brace = 0;
1.16      kristaps  910:
1.42    ! kristaps  911:        if (*pos == sz) {
        !           912:                texiwarn(p, "truncated: @%s", texitoks[cmd].tok);
1.16      kristaps  913:                return;
1.42    ! kristaps  914:        }
        !           915:
        !           916:        /* Pad us with space, if necessary. */
        !           917:        if (p->seenws && p->outcol && 0 == p->literal) {
1.34      kristaps  918:                texiputchar(p, ' ');
1.42    ! kristaps  919:                p->seenws = 0;
        !           920:        }
        !           921:
        !           922:        /*
        !           923:         * If we're braced, then that's that.
        !           924:         * Otherwise, in a special Texinfo case: if we're a non
        !           925:         * alphabetic command of one letter, then the next character is
        !           926:         * the critical one.
        !           927:         * Otherwise, space can sit between us and our argument.
        !           928:         */
        !           929:        if ('{' == buf[*pos]) {
        !           930:                brace = 1;
        !           931:                advance(p, buf, pos);
        !           932:        } else if (isalpha(texitoks[cmd].tok[0]))
1.34      kristaps  933:                while (*pos < sz && isws(buf[*pos]))
                    934:                        advance(p, buf, pos);
1.42    ! kristaps  935:
        !           936:        if (*pos == sz) {
        !           937:                texiwarn(p, "truncated: @%s", texitoks[cmd].tok);
        !           938:                return;
        !           939:        }
        !           940:
        !           941:        switch (cmd) {
1.16      kristaps  942:        case (TEXICMD_ACUTE):
                    943:                switch (buf[*pos]) {
                    944:                case ('a'): case ('A'):
                    945:                case ('e'): case ('E'):
                    946:                case ('i'): case ('I'):
                    947:                case ('o'): case ('O'):
                    948:                case ('u'): case ('U'):
                    949:                        texiputchars(p, "\\(\'");
                    950:                        break;
                    951:                default:
1.42    ! kristaps  952:                        texiwarn(p, "ignoring accent");
        !           953:                        break;
1.16      kristaps  954:                }
1.42    ! kristaps  955:                texiputchar(p, buf[*pos]);
        !           956:                advance(p, buf, pos);
        !           957:                break;
        !           958:        case (TEXICMD_CEDILLA):
        !           959:                if ('c' == buf[*pos] || 'C' == buf[*pos])
        !           960:                        texiputchars(p, "\\(,");
        !           961:                else
        !           962:                        texiwarn(p, "ignoring accent");
        !           963:                texiputchar(p, buf[*pos]);
        !           964:                advance(p, buf, pos);
1.16      kristaps  965:                break;
                    966:        case (TEXICMD_CIRCUMFLEX):
                    967:                switch (buf[*pos]) {
                    968:                case ('a'): case ('A'):
                    969:                case ('e'): case ('E'):
                    970:                case ('i'): case ('I'):
                    971:                case ('o'): case ('O'):
                    972:                case ('u'): case ('U'):
                    973:                        texiputchars(p, "\\(^");
                    974:                        break;
                    975:                default:
1.42    ! kristaps  976:                        texiwarn(p, "ignoring accent");
1.34      kristaps  977:                        break;
1.16      kristaps  978:                }
1.42    ! kristaps  979:                texiputchar(p, buf[*pos]);
        !           980:                advance(p, buf, pos);
        !           981:                break;
        !           982:        case (TEXICMD_DOTLESS):
        !           983:                if ('i' == buf[*pos] || 'j' == buf[*pos])
        !           984:                        texiputchars(p, "\\(.");
        !           985:                else
        !           986:                        texiwarn(p, "ignoring accent");
        !           987:                texiputchar(p, buf[*pos]);
        !           988:                advance(p, buf, pos);
1.16      kristaps  989:                break;
                    990:        case (TEXICMD_GRAVE):
                    991:                switch (buf[*pos]) {
                    992:                case ('a'): case ('A'):
                    993:                case ('e'): case ('E'):
                    994:                case ('i'): case ('I'):
                    995:                case ('o'): case ('O'):
                    996:                case ('u'): case ('U'):
                    997:                        texiputchars(p, "\\(`");
                    998:                        break;
                    999:                default:
1.42    ! kristaps 1000:                        texiwarn(p, "ignoring accent");
        !          1001:                        break;
1.16      kristaps 1002:                }
1.42    ! kristaps 1003:                texiputchar(p, buf[*pos]);
        !          1004:                advance(p, buf, pos);
1.16      kristaps 1005:                break;
                   1006:        case (TEXICMD_TILDE):
                   1007:                switch (buf[*pos]) {
                   1008:                case ('a'): case ('A'):
                   1009:                case ('n'): case ('N'):
                   1010:                case ('o'): case ('O'):
                   1011:                        texiputchars(p, "\\(~");
                   1012:                        break;
                   1013:                default:
1.42    ! kristaps 1014:                        texiwarn(p, "ignoring accent");
1.34      kristaps 1015:                        break;
1.16      kristaps 1016:                }
1.42    ! kristaps 1017:                texiputchar(p, buf[*pos]);
        !          1018:                advance(p, buf, pos);
1.16      kristaps 1019:                break;
                   1020:        case (TEXICMD_UMLAUT):
                   1021:                switch (buf[*pos]) {
                   1022:                case ('a'): case ('A'):
                   1023:                case ('e'): case ('E'):
                   1024:                case ('i'): case ('I'):
                   1025:                case ('o'): case ('O'):
                   1026:                case ('u'): case ('U'):
                   1027:                case ('y'):
                   1028:                        texiputchars(p, "\\(:");
                   1029:                        break;
                   1030:                default:
1.42    ! kristaps 1031:                        texiwarn(p, "ignoring accent");
1.34      kristaps 1032:                        break;
1.16      kristaps 1033:                }
1.42    ! kristaps 1034:                texiputchar(p, buf[*pos]);
        !          1035:                advance(p, buf, pos);
1.16      kristaps 1036:                break;
                   1037:        default:
1.42    ! kristaps 1038:                texiputchar(p, buf[*pos]);
        !          1039:                advance(p, buf, pos);
        !          1040:                break;
        !          1041:        }
        !          1042:
        !          1043:        if (brace) {
        !          1044:                while (*pos < sz && '}' != buf[*pos]) {
        !          1045:                        texiputchar(p, buf[*pos]);
        !          1046:                        advance(p, buf, pos);
        !          1047:                }
        !          1048:                if (*pos < sz)
        !          1049:                        advance(p, buf, pos);
        !          1050:        }
        !          1051:
        !          1052:        switch (cmd) {
        !          1053:        case (TEXICMD_TIEACCENT):
        !          1054:                texiputchar(p, ']');
        !          1055:                break;
        !          1056:        case (TEXICMD_DOTACCENT):
        !          1057:                texiputchar(p, '*');
        !          1058:                break;
        !          1059:        default:
        !          1060:                break;
1.16      kristaps 1061:        }
                   1062: }
                   1063:
                   1064: static void
1.1       kristaps 1065: dosymbol(struct texi *p, enum texicmd cmd,
                   1066:        const char *buf, size_t sz, size_t *pos)
                   1067: {
                   1068:
1.42    ! kristaps 1069:        /* Remember to pad us. */
1.3       kristaps 1070:        if (p->seenws && p->outcol && 0 == p->literal) {
                   1071:                texiputchar(p, ' ');
                   1072:                p->seenws = 0;
                   1073:        }
                   1074:
1.1       kristaps 1075:        switch (cmd) {
1.42    ! kristaps 1076:        case (TEXICMD_AA):
        !          1077:                texiputchars(p, "\\(oA");
        !          1078:                break;
        !          1079:        case (TEXICMD_AASMALL):
        !          1080:                texiputchars(p, "\\(oa");
        !          1081:                break;
        !          1082:        case (TEXICMD_AE):
        !          1083:                texiputchars(p, "\\(AE");
        !          1084:                break;
        !          1085:        case (TEXICMD_AESMALL):
        !          1086:                texiputchars(p, "\\(ae");
        !          1087:                break;
1.3       kristaps 1088:        case (TEXICMD_ASTERISK):
                   1089:        case (TEXICMD_NEWLINE):
                   1090:        case (TEXICMD_SPACE):
1.18      kristaps 1091:        case (TEXICMD_TABSYM):
1.3       kristaps 1092:                texiputchar(p, ' ');
                   1093:                break;
1.1       kristaps 1094:        case (TEXICMD_AT):
1.3       kristaps 1095:                texiputchar(p, '@');
                   1096:                break;
                   1097:        case (TEXICMD_BANG):
                   1098:                texiputchar(p, '!');
1.7       kristaps 1099:                break;
                   1100:        case (TEXICMD_BULLET):
                   1101:                texiputchars(p, "\\(bu");
1.1       kristaps 1102:                break;
1.35      kristaps 1103:        case (TEXICMD_COMMA):
                   1104:                texiputchar(p, ',');
                   1105:                break;
1.1       kristaps 1106:        case (TEXICMD_COPYRIGHT):
                   1107:                texiputchars(p, "\\(co");
                   1108:                break;
1.42    ! kristaps 1109:        case (TEXICMD_DH):
        !          1110:                texiputchars(p, "\\(-D");
        !          1111:                break;
        !          1112:        case (TEXICMD_DHSMALL):
        !          1113:                texiputchars(p, "\\(Sd");
        !          1114:                break;
1.2       kristaps 1115:        case (TEXICMD_DOTS):
1.34      kristaps 1116:        case (TEXICMD_ENDDOTS):
1.2       kristaps 1117:                texiputchars(p, "...");
                   1118:                break;
1.28      kristaps 1119:        case (TEXICMD_EQUIV):
                   1120:                texiputchars(p, "\\(==");
                   1121:                break;
1.15      kristaps 1122:        case (TEXICMD_ERROR):
                   1123:                texiputchars(p, "error\\(->");
1.17      kristaps 1124:                break;
1.42    ! kristaps 1125:        case (TEXICMD_EXCLAMDOWN):
        !          1126:                texiputchars(p, "\\(r!");
        !          1127:                break;
1.17      kristaps 1128:        case (TEXICMD_EXPANSION):
                   1129:                texiputchars(p, "\\(->");
1.15      kristaps 1130:                break;
1.42    ! kristaps 1131:        case (TEXICMD_L):
        !          1132:                texiputchars(p, "\\(/L");
        !          1133:                break;
1.1       kristaps 1134:        case (TEXICMD_LATEX):
                   1135:                texiputchars(p, "LaTeX");
                   1136:                break;
1.42    ! kristaps 1137:        case (TEXICMD_LSMALL):
        !          1138:                texiputchars(p, "\\(/l");
        !          1139:                break;
1.25      kristaps 1140:        case (TEXICMD_MINUS):
                   1141:                texiputchars(p, "\\-");
                   1142:                break;
1.42    ! kristaps 1143:        case (TEXICMD_O):
        !          1144:                texiputchars(p, "\\(/O");
        !          1145:                break;
        !          1146:        case (TEXICMD_OE):
        !          1147:                texiputchars(p, "\\(OE");
        !          1148:                break;
        !          1149:        case (TEXICMD_OESMALL):
        !          1150:                texiputchars(p, "\\(oe");
        !          1151:                break;
        !          1152:        case (TEXICMD_ORDF):
        !          1153:                texiputchars(p, "a");
        !          1154:                break;
        !          1155:        case (TEXICMD_ORDM):
        !          1156:                texiputchars(p, "o");
        !          1157:                break;
        !          1158:        case (TEXICMD_OSMALL):
        !          1159:                texiputchars(p, "\\(/o");
        !          1160:                break;
1.25      kristaps 1161:        case (TEXICMD_PERIOD):
                   1162:                texiputchar(p, '.');
                   1163:                break;
1.42    ! kristaps 1164:        case (TEXICMD_QUESTIONDOWN):
        !          1165:                texiputchars(p, "\\(r?");
        !          1166:                break;
1.3       kristaps 1167:        case (TEXICMD_QUESTIONMARK):
                   1168:                texiputchar(p, '?');
1.15      kristaps 1169:                break;
                   1170:        case (TEXICMD_RESULT):
                   1171:                texiputchars(p, "\\(rA");
1.3       kristaps 1172:                break;
1.34      kristaps 1173:        case (TEXICMD_SLASH):
                   1174:                texiputchar(p, '/');
                   1175:                break;
1.35      kristaps 1176:        case (TEXICMD_SS):
                   1177:                texiputchars(p, "\\(ss");
                   1178:                break;
1.3       kristaps 1179:        case (TEXICMD_SQUIGGLE_LEFT):
                   1180:                texiputchars(p, "{");
                   1181:                break;
                   1182:        case (TEXICMD_SQUIGGLE_RIGHT):
                   1183:                texiputchars(p, "}");
                   1184:                break;
1.38      kristaps 1185:        case (TEXICMD_TEXSYM):
1.35      kristaps 1186:                texiputchars(p, "TeX");
                   1187:                break;
1.42    ! kristaps 1188:        case (TEXICMD_TH):
        !          1189:                texiputchars(p, "\\(TP");
        !          1190:                break;
        !          1191:        case (TEXICMD_THSMALL):
        !          1192:                texiputchars(p, "\\(Tp");
        !          1193:                break;
1.38      kristaps 1194:        case (TEXICMD_TIE):
1.35      kristaps 1195:                texiputchars(p, "\\ ");
1.1       kristaps 1196:                break;
1.3       kristaps 1197:        case (TEXICMD_COLON):
                   1198:        case (TEXICMD_HYPHEN):
                   1199:                break;
1.1       kristaps 1200:        default:
                   1201:                abort();
                   1202:        }
                   1203:
1.42    ! kristaps 1204:        /* Alphabetic commands have braces we ignore. */
        !          1205:        if (isalpha(texitoks[cmd].tok[0]))
1.5       kristaps 1206:                doignbracket(p, cmd, buf, sz, pos);
1.1       kristaps 1207: }
                   1208:
                   1209: static void
                   1210: doquotation(struct texi *p, enum texicmd cmd,
                   1211:        const char *buf, size_t sz, size_t *pos)
                   1212: {
                   1213:
1.5       kristaps 1214:        teximacro(p, "Qo");
1.1       kristaps 1215:        parseto(p, buf, sz, pos, "quotation");
1.5       kristaps 1216:        teximacro(p, "Qc");
1.1       kristaps 1217: }
                   1218:
1.3       kristaps 1219: static void
                   1220: domath(struct texi *p, enum texicmd cmd,
                   1221:        const char *buf, size_t sz, size_t *pos)
                   1222: {
1.34      kristaps 1223:        size_t   nest, start;
1.3       kristaps 1224:
                   1225:        /*
                   1226:         * Math handling is different from everything else.
                   1227:         * We don't allow any subcomponents, and we ignore the rules in
                   1228:         * terms of @-commands.
                   1229:         * This departs from GNU's rules, but whatever.
                   1230:         */
                   1231:        while (*pos < sz && isws(buf[*pos]))
                   1232:                advance(p, buf, pos);
                   1233:        if (*pos == sz || '{' != buf[*pos])
                   1234:                return;
                   1235:        advance(p, buf, pos);
                   1236:        if (p->seenws && p->outcol && 0 == p->literal)
                   1237:                texiputchar(p, ' ');
                   1238:        p->seenws = 0;
1.34      kristaps 1239:        for (nest = 1, start = *pos; *pos < sz && nest > 0; ) {
1.3       kristaps 1240:                if ('{' == buf[*pos])
                   1241:                        nest++;
                   1242:                else if ('}' == buf[*pos])
                   1243:                        if (0 == --nest)
                   1244:                                continue;
                   1245:                advance(p, buf, pos);
                   1246:        }
                   1247:        if (*pos == sz)
                   1248:                return;
                   1249:        assert('}' == buf[*pos]);
1.34      kristaps 1250:        texiputbuf(p, buf, start, *pos);
1.3       kristaps 1251:        advance(p, buf, pos);
1.24      kristaps 1252: }
                   1253:
                   1254: static void
                   1255: dovalue(struct texi *p, enum texicmd cmd,
                   1256:        const char *buf, size_t sz, size_t *pos)
                   1257: {
1.28      kristaps 1258:        size_t           start, end, i;
1.25      kristaps 1259:        char            *key, *val;
                   1260:        const char      *cp;
1.24      kristaps 1261:
                   1262:        if (TEXICMD_SET == cmd) {
                   1263:                while (*pos < sz && isws(buf[*pos]))
                   1264:                        advance(p, buf, pos);
                   1265:                for (start = end = *pos; end < sz; end++)
                   1266:                        if (ismspace(buf[end]))
                   1267:                                break;
1.25      kristaps 1268:                /* We don't allow empty keys. */
1.24      kristaps 1269:                if (start == end)
                   1270:                        return;
1.25      kristaps 1271:                advanceto(p, buf, pos, end);
1.24      kristaps 1272:
                   1273:                key = malloc(end - start + 1);
1.27      kristaps 1274:                if (NULL == key)
                   1275:                        texiabort(p, NULL);
1.24      kristaps 1276:                memcpy(key, &buf[start], end - start);
                   1277:                key[end - start] = '\0';
                   1278:
                   1279:                while (*pos < sz && isws(buf[*pos]))
                   1280:                        advance(p, buf, pos);
                   1281:                for (start = end = *pos; end < sz; end++)
                   1282:                        if ('\n' == buf[end])
                   1283:                                break;
1.25      kristaps 1284:                /* We do allow empty values. */
                   1285:                advanceeoln(p, buf, sz, pos, 1);
1.24      kristaps 1286:
                   1287:                val = malloc(end - start + 1);
1.27      kristaps 1288:                if (NULL == val)
                   1289:                        texiabort(p, NULL);
1.24      kristaps 1290:                memcpy(val, &buf[start], end - start);
                   1291:                val[end - start] = '\0';
1.25      kristaps 1292:                valueadd(p, key, val);
1.24      kristaps 1293:        } else if (TEXICMD_VALUE == cmd) {
                   1294:                if (p->seenws)
                   1295:                        texiputchar(p, ' ');
                   1296:                p->seenws = 0;
1.28      kristaps 1297:                if (NULL != (cp = valueblookup(p, buf, sz, pos))) {
                   1298:                        for (i = 0; i < p->valstackpos; i++)
                   1299:                                if (cp == p->valstack[i])
                   1300:                                        break;
                   1301:                        if (i < p->valstackpos)
                   1302:                                texierr(p, "recursive value");
1.29      kristaps 1303:                        if (64 == p->valstackpos)
                   1304:                                texierr(p, "too many nested values");
1.28      kristaps 1305:                        p->valstack[p->valstackpos++] = cp;
1.31      kristaps 1306:                        parsemembuf(p, cp, strlen(cp));
1.28      kristaps 1307:                        p->valstackpos--;
                   1308:                } else
1.25      kristaps 1309:                        texiputchars(p, "{No value}");
1.24      kristaps 1310:        } else if (TEXICMD_IFCLEAR == cmd) {
1.26      kristaps 1311:                if (NULL != valuellookup(p, buf, sz, pos))
                   1312:                        doignblock(p, cmd, buf, sz, pos);
                   1313:                else
                   1314:                        parseto(p, buf, sz, pos, texitoks[cmd].tok);
1.30      kristaps 1315:        } else if (TEXICMD_IFSET == cmd) {
                   1316:                if (NULL == valuellookup(p, buf, sz, pos))
                   1317:                        doignblock(p, cmd, buf, sz, pos);
                   1318:                else
                   1319:                        parseto(p, buf, sz, pos, texitoks[cmd].tok);
1.25      kristaps 1320:        } else if (TEXICMD_CLEAR == cmd)
                   1321:                valuelclear(p, buf, sz, pos);
1.3       kristaps 1322: }
                   1323:
1.1       kristaps 1324: static void
1.8       kristaps 1325: dolink(struct texi *p, enum texicmd cmd,
1.1       kristaps 1326:        const char *buf, size_t sz, size_t *pos)
                   1327: {
1.8       kristaps 1328:        int      c;
1.1       kristaps 1329:
                   1330:        switch (cmd) {
                   1331:        case (TEXICMD_EMAIL):
1.5       kristaps 1332:                teximacroopen(p, "Mt");
1.1       kristaps 1333:                break;
1.3       kristaps 1334:        case (TEXICMD_UREF):
1.1       kristaps 1335:        case (TEXICMD_URL):
1.5       kristaps 1336:                teximacroopen(p, "Lk");
1.1       kristaps 1337:                break;
1.8       kristaps 1338:        case (TEXICMD_XREF):
                   1339:                texiputchars(p, "See Section");
1.39      kristaps 1340:                teximacroopen(p, "Dq");
1.8       kristaps 1341:                break;
                   1342:        case (TEXICMD_PXREF):
                   1343:                texiputchars(p, "see Section");
1.39      kristaps 1344:                teximacroopen(p, "Dq");
1.8       kristaps 1345:                break;
1.34      kristaps 1346:        case (TEXICMD_INFOREF):
                   1347:                texiputchars(p, "See Info file node");
1.39      kristaps 1348:                teximacroopen(p, "Dq");
1.34      kristaps 1349:                break;
1.1       kristaps 1350:        default:
1.8       kristaps 1351:                abort();
1.1       kristaps 1352:        }
1.8       kristaps 1353:
                   1354:        c = parsearg(p, buf, sz, pos, 0);
                   1355:        p->ign++;
                   1356:        while (c > 0)
                   1357:                c = parsearg(p, buf, sz, pos, 1);
                   1358:        p->ign--;
                   1359:
1.11      kristaps 1360:        texipunctuate(p, buf, sz, pos);
1.8       kristaps 1361:        teximacroclose(p);
                   1362: }
                   1363:
                   1364: static void
                   1365: doignargn(struct texi *p, enum texicmd cmd,
                   1366:        const char *buf, size_t sz, size_t *pos)
                   1367: {
                   1368:        int      c;
                   1369:
                   1370:        c = parsearg(p, buf, sz, pos, 0);
                   1371:        p->ign++;
                   1372:        while (c > 0)
                   1373:                c = parsearg(p, buf, sz, pos, 1);
                   1374:        p->ign--;
1.1       kristaps 1375: }
                   1376:
1.23      kristaps 1377: /*
                   1378:  * Sections can be made subsections and so on by way of the
                   1379:  * @raiseections and @lowersections commands.
                   1380:  * Perform this check here and return the actual section number adjusted
                   1381:  * to the raise level.
                   1382:  */
                   1383: static int
                   1384: sectioner(struct texi *p, int sec)
                   1385: {
                   1386:
                   1387:        if ((sec -= p->secoffs) < 0) {
                   1388:                texiwarn(p, "section below minimum, clamping");
                   1389:                return(0);
                   1390:        } else if (sec >= SECTSZ) {
                   1391:                texiwarn(p, "section above maximum, clamping");
                   1392:                return(SECTSZ - 1);
                   1393:        }
                   1394:        return(sec);
                   1395: }
                   1396:
                   1397: static void
                   1398: dosubsubsection(struct texi *p, enum texicmd cmd,
                   1399:                const char *buf, size_t sz, size_t *pos)
                   1400: {
                   1401:        int      sec;
                   1402:
                   1403:        sec = sectioner(p, 3);
                   1404:
                   1405:        /* We don't have a subsubsubsection, so make one up. */
                   1406:        texivspace(p);
                   1407:        teximacroopen(p, sects[sec]);
                   1408:        parseeoln(p, buf, sz, pos);
                   1409:        teximacroclose(p);
                   1410:        texivspace(p);
                   1411: }
                   1412:
1.1       kristaps 1413: static void
                   1414: dosubsection(struct texi *p, enum texicmd cmd,
                   1415:                const char *buf, size_t sz, size_t *pos)
                   1416: {
1.23      kristaps 1417:        int      sec;
                   1418:
                   1419:        sec = sectioner(p, 2);
1.13      kristaps 1420:
                   1421:        if (p->outmacro)
1.23      kristaps 1422:                texierr(p, "\"%s\" in open line scope!?", sects[sec]);
1.13      kristaps 1423:        else if (p->literal)
1.23      kristaps 1424:                texierr(p, "\"%s\" in a literal scope!?", sects[sec]);
1.1       kristaps 1425:
1.21      kristaps 1426:        /* We don't have a subsubsection, so make one up. */
1.34      kristaps 1427:        if (sec > 1)
                   1428:                texivspace(p);
1.23      kristaps 1429:        teximacroopen(p, sects[sec]);
1.3       kristaps 1430:        parseeoln(p, buf, sz, pos);
1.5       kristaps 1431:        teximacroclose(p);
1.34      kristaps 1432:        if (sec > 1)
                   1433:                texivspace(p);
1.1       kristaps 1434: }
                   1435:
                   1436: static void
1.23      kristaps 1437: dosecoffs(struct texi *p, enum texicmd cmd,
                   1438:        const char *buf, size_t sz, size_t *pos)
                   1439: {
                   1440:
                   1441:        if (TEXICMD_RAISESECTIONS == cmd)
                   1442:                p->secoffs++;
                   1443:        else
                   1444:                p->secoffs--;
                   1445: }
                   1446:
                   1447: static void
1.1       kristaps 1448: dosection(struct texi *p, enum texicmd cmd,
1.23      kristaps 1449:        const char *buf, size_t sz, size_t *pos)
1.1       kristaps 1450: {
1.23      kristaps 1451:        int              sec;
1.12      kristaps 1452:
                   1453:        switch (cmd) {
                   1454:        case (TEXICMD_APPENDIX):
                   1455:        case (TEXICMD_CHAPTER):
                   1456:        case (TEXICMD_TOP):
                   1457:        case (TEXICMD_UNNUMBERED):
1.23      kristaps 1458:                sec = sectioner(p, 0);
1.12      kristaps 1459:                break;
                   1460:        case (TEXICMD_APPENDIXSEC):
                   1461:        case (TEXICMD_HEADING):
                   1462:        case (TEXICMD_SECTION):
                   1463:        case (TEXICMD_UNNUMBEREDSEC):
1.23      kristaps 1464:                sec = sectioner(p, 1);
1.12      kristaps 1465:                break;
                   1466:        default:
                   1467:                abort();
                   1468:        }
1.1       kristaps 1469:
1.3       kristaps 1470:        if (p->outmacro)
1.23      kristaps 1471:                texierr(p, "\"%s\" in open line scope!?", sects[sec]);
1.3       kristaps 1472:        else if (p->literal)
1.23      kristaps 1473:                texierr(p, "\"%s\" in a literal scope!?", sects[sec]);
1.3       kristaps 1474:
1.23      kristaps 1475:        teximacroopen(p, sects[sec]);
1.3       kristaps 1476:        parseeoln(p, buf, sz, pos);
                   1477:        teximacroclose(p);
1.11      kristaps 1478:        p->seenvs = 1;
1.3       kristaps 1479: }
                   1480:
                   1481: static void
                   1482: dosp(struct texi *p, enum texicmd cmd,
                   1483:        const char *buf, size_t sz, size_t *pos)
                   1484: {
                   1485:
1.37      kristaps 1486:        if (p->literal)
                   1487:                texiputchar(p, '\n');
                   1488:        else
                   1489:                texivspace(p);
1.12      kristaps 1490:        /* FIXME: ignore and parseeoln. */
1.3       kristaps 1491:        advanceeoln(p, buf, sz, pos, 1);
1.1       kristaps 1492: }
                   1493:
                   1494: static void
                   1495: dotop(struct texi *p, enum texicmd cmd,
                   1496:        const char *buf, size_t sz, size_t *pos)
                   1497: {
1.10      kristaps 1498:        const char      *cp;
                   1499:        time_t           t;
                   1500:        char             date[32];
                   1501:
1.26      kristaps 1502:        if (--p->ign)
                   1503:                texierr(p, "@top command while ignoring (%d)", p->ign);
                   1504:
1.18      kristaps 1505:        /*
                   1506:         * Here we print our standard mdoc(7) prologue.
                   1507:         * We use the title set with @settitle for the `Nd' description
                   1508:         * and the source document filename (the first one as invoked on
                   1509:         * the command line) for the title.
                   1510:         * The date is set to the current date.
                   1511:         */
1.10      kristaps 1512:        t = time(NULL);
                   1513:        strftime(date, sizeof(date), "%F", localtime(&t));
1.1       kristaps 1514:
1.10      kristaps 1515:        teximacroopen(p, "Dd");
                   1516:        texiputchars(p, date);
                   1517:        teximacroclose(p);
                   1518:        teximacroopen(p, "Dt");
                   1519:        for (cp = p->title; '\0' != *cp; cp++)
                   1520:                texiputchar(p, toupper(*cp));
1.11      kristaps 1521:        texiputchars(p, " 7");
1.10      kristaps 1522:        teximacroclose(p);
1.5       kristaps 1523:        teximacro(p, "Os");
                   1524:        teximacro(p, "Sh NAME");
1.10      kristaps 1525:        teximacroopen(p, "Nm");
1.41      kristaps 1526:        for (cp = p->title; '\0' != *cp; cp++)
                   1527:                texiputchar(p, *cp);
1.10      kristaps 1528:        teximacroclose(p);
                   1529:        teximacroopen(p, "Nd");
1.41      kristaps 1530:        if (NULL != p->subtitle)
                   1531:                for (cp = p->subtitle; '\0' != *cp; cp++)
                   1532:                        texiputchar(p, *cp);
                   1533:        else
                   1534:                texiputchars(p, "Unknown description");
1.10      kristaps 1535:        teximacroclose(p);
1.11      kristaps 1536:        p->seenvs = 1;
1.12      kristaps 1537:        dosection(p, cmd, buf, sz, pos);
1.1       kristaps 1538: }
                   1539:
                   1540: static void
                   1541: doitem(struct texi *p, enum texicmd cmd,
                   1542:        const char *buf, size_t sz, size_t *pos)
                   1543: {
                   1544:
1.18      kristaps 1545:        /* Multitable is using raw tbl(7). */
                   1546:        if (TEXILIST_TABLE == p->list) {
                   1547:                texiputchar(p, '\n');
                   1548:                return;
                   1549:        }
                   1550:
1.3       kristaps 1551:        if (p->outmacro)
                   1552:                texierr(p, "item in open line scope!?");
                   1553:        else if (p->literal)
                   1554:                texierr(p, "item in a literal scope!?");
                   1555:
                   1556:        switch (p->list) {
                   1557:        case (TEXILIST_ITEM):
1.5       kristaps 1558:                teximacroopen(p, "It");
1.3       kristaps 1559:                break;
                   1560:        case (TEXILIST_NOITEM):
1.5       kristaps 1561:                teximacro(p, "It");
1.3       kristaps 1562:                break;
                   1563:        default:
1.11      kristaps 1564:                texivspace(p);
1.3       kristaps 1565:                break;
                   1566:        }
1.18      kristaps 1567:
                   1568:        /* Trick so we don't start with Pp. */
1.11      kristaps 1569:        p->seenvs = 1;
1.3       kristaps 1570:        parseeoln(p, buf, sz, pos);
1.1       kristaps 1571:
1.3       kristaps 1572:        if (TEXILIST_ITEM == p->list)
                   1573:                teximacroclose(p);
1.9       kristaps 1574:        else if (p->outcol > 0)
1.1       kristaps 1575:                texiputchar(p, '\n');
1.18      kristaps 1576: }
                   1577:
                   1578: static void
                   1579: dotab(struct texi *p, enum texicmd cmd,
                   1580:        const char *buf, size_t sz, size_t *pos)
                   1581: {
                   1582:
                   1583:        /* This command is only useful in @multitable. */
                   1584:        if (TEXILIST_TABLE == p->list)
                   1585:                texiputchar(p, '\t');
                   1586: }
                   1587:
                   1588: static void
                   1589: domultitable(struct texi *p, enum texicmd cmd,
                   1590:        const char *buf, size_t sz, size_t *pos)
                   1591: {
                   1592:        enum texilist   sv = p->list;
1.32      kristaps 1593:        int             svliteral = p->literal;
1.18      kristaps 1594:        enum texicmd    type;
                   1595:        size_t          i, end, columns;
                   1596:
                   1597:        p->list = TEXILIST_TABLE;
1.32      kristaps 1598:        /*
                   1599:         * TS/TE blocks aren't "in mdoc(7)", so we can disregard the
                   1600:         * fact that we're in literal mode right now.
                   1601:         */
                   1602:        p->literal = 0;
1.18      kristaps 1603:        teximacro(p, "TS");
                   1604:        columns = 0;
                   1605:
                   1606:        /* Advance to the first argument... */
                   1607:        while (*pos < sz && isws(buf[*pos]))
                   1608:                advance(p, buf, pos);
                   1609:
                   1610:        /* Make sure we don't print anything when scanning. */
                   1611:        p->ign++;
                   1612:        if ('@' == buf[*pos]) {
                   1613:                /*
                   1614:                 * Look for @columnfractions.
                   1615:                 * We ignore these, but we do use the number of
                   1616:                 * arguments to set the number of columns that we'll
                   1617:                 * have.
                   1618:                 */
1.30      kristaps 1619:                type = texicmd(p, buf, *pos, sz, &end, NULL);
1.18      kristaps 1620:                advanceto(p, buf, pos, end);
                   1621:                if (TEXICMD_COLUMNFRACTIONS != type)
1.25      kristaps 1622:                        texierr(p, "unknown multitable command");
1.18      kristaps 1623:                while (*pos < sz && '\n' != buf[*pos]) {
                   1624:                        while (*pos < sz && isws(buf[*pos]))
                   1625:                                advance(p, buf, pos);
                   1626:                        while (*pos < sz && ! isws(buf[*pos])) {
                   1627:                                if ('\n' == buf[*pos])
                   1628:                                        break;
                   1629:                                advance(p, buf, pos);
                   1630:                        }
                   1631:                        columns++;
                   1632:                }
                   1633:        } else
                   1634:                /*
                   1635:                 * We have arguments.
                   1636:                 * We could parse these, but it's easier to just let
                   1637:                 * tbl(7) figure it out.
                   1638:                 * So use this only to count arguments.
                   1639:                 */
                   1640:                while (parselinearg(p, buf, sz, pos) > 0)
                   1641:                        columns++;
                   1642:        p->ign--;
                   1643:
                   1644:        /* Left-justify each table entry. */
                   1645:        for (i = 0; i < columns; i++) {
                   1646:                if (i > 0)
                   1647:                        texiputchar(p, ' ');
                   1648:                texiputchar(p, 'l');
                   1649:        }
                   1650:        texiputchars(p, ".\n");
                   1651:        p->outmacro++;
                   1652:        parseto(p, buf, sz, pos, texitoks[cmd].tok);
                   1653:        p->outmacro--;
                   1654:        teximacro(p, "TE");
1.32      kristaps 1655:        p->literal = svliteral;
1.18      kristaps 1656:        p->list = sv;
1.1       kristaps 1657: }
                   1658:
                   1659: static void
                   1660: dotable(struct texi *p, enum texicmd cmd,
                   1661:        const char *buf, size_t sz, size_t *pos)
                   1662: {
1.3       kristaps 1663:        enum texilist   sv = p->list;
                   1664:
                   1665:        p->list = TEXILIST_ITEM;
1.5       kristaps 1666:        teximacro(p, "Bl -tag -width Ds");
1.12      kristaps 1667:        /* FIXME: ignore and parseeoln. */
                   1668:        advanceeoln(p, buf, sz, pos, 1);
1.11      kristaps 1669:        p->seenvs = 1;
1.20      kristaps 1670:        parseto(p, buf, sz, pos, texitoks[cmd].tok);
1.5       kristaps 1671:        teximacro(p, "El");
1.3       kristaps 1672:        p->list = sv;
1.1       kristaps 1673: }
                   1674:
                   1675: static void
1.2       kristaps 1676: doenumerate(struct texi *p, enum texicmd cmd,
                   1677:        const char *buf, size_t sz, size_t *pos)
                   1678: {
1.3       kristaps 1679:        enum texilist    sv = p->list;
1.2       kristaps 1680:
1.3       kristaps 1681:        p->list = TEXILIST_NOITEM;
1.5       kristaps 1682:        teximacro(p, "Bl -enum");
1.11      kristaps 1683:        p->seenvs = 1;
1.12      kristaps 1684:        /* FIXME: ignore and parseeoln. */
                   1685:        advanceeoln(p, buf, sz, pos, 1);
1.2       kristaps 1686:        parseto(p, buf, sz, pos, "enumerate");
1.5       kristaps 1687:        teximacro(p, "El");
1.3       kristaps 1688:        p->list = sv;
1.2       kristaps 1689: }
                   1690:
                   1691: static void
1.1       kristaps 1692: doitemize(struct texi *p, enum texicmd cmd,
                   1693:        const char *buf, size_t sz, size_t *pos)
                   1694: {
1.3       kristaps 1695:        enum texilist   sv = p->list;
1.1       kristaps 1696:
1.21      kristaps 1697:        p->list = TEXILIST_NOITEM;
1.5       kristaps 1698:        teximacro(p, "Bl -bullet");
1.11      kristaps 1699:        p->seenvs = 1;
1.12      kristaps 1700:        /* FIXME: ignore and parseeoln. */
                   1701:        advanceeoln(p, buf, sz, pos, 1);
1.1       kristaps 1702:        parseto(p, buf, sz, pos, "itemize");
1.5       kristaps 1703:        teximacro(p, "El");
1.3       kristaps 1704:        p->list = sv;
1.1       kristaps 1705: }
                   1706:
                   1707: static void
                   1708: doignbracket(struct texi *p, enum texicmd cmd,
                   1709:        const char *buf, size_t sz, size_t *pos)
                   1710: {
                   1711:
1.3       kristaps 1712:        p->ign++;
1.1       kristaps 1713:        parsebracket(p, buf, sz, pos);
1.3       kristaps 1714:        p->ign--;
1.1       kristaps 1715: }
                   1716:
                   1717: static void
                   1718: doignline(struct texi *p, enum texicmd cmd,
                   1719:        const char *buf, size_t sz, size_t *pos)
                   1720: {
                   1721:
1.12      kristaps 1722:        /* FIXME: ignore and parseeoln. */
1.3       kristaps 1723:        advanceeoln(p, buf, sz, pos, 1);
1.1       kristaps 1724: }
                   1725:
1.8       kristaps 1726: /*
                   1727:  * Parse colon-separated directories from "cp" (if not NULL) and returns
                   1728:  * the array of pointers.
1.40      kristaps 1729:  * Prepends "base" to the array, if found.
1.8       kristaps 1730:  * This does NOT sanitise the directories!
                   1731:  */
1.5       kristaps 1732: static char **
1.27      kristaps 1733: parsedirs(struct texi *p, const char *base, const char *cp, size_t *sz)
1.5       kristaps 1734: {
                   1735:        char             *tok, *str, *tofree;
                   1736:        const char       *cpp;
1.40      kristaps 1737:        size_t            i = 0;
1.5       kristaps 1738:        char            **dirs;
                   1739:
1.40      kristaps 1740:        /* Count up our expected arguments. */
                   1741:        *sz = NULL != base;
                   1742:        if (NULL != (cpp = cp))
                   1743:                for ((*sz)++; NULL != (cpp = strchr(cpp, ':')); (*sz)++)
1.5       kristaps 1744:                        cpp++;
                   1745:
1.40      kristaps 1746:        if (0 == *sz)
                   1747:                return(NULL);
1.27      kristaps 1748:        if (NULL == (dirs = calloc(*sz, sizeof(char *))))
                   1749:                texiabort(p, NULL);
1.40      kristaps 1750:        if (NULL != base && NULL == (dirs[i++] = strdup(base)))
1.27      kristaps 1751:                texiabort(p, NULL);
1.5       kristaps 1752:        if (NULL == cp)
                   1753:                return(dirs);
1.27      kristaps 1754:        if (NULL == (tofree = tok = str = strdup(cp)))
                   1755:                texiabort(p, NULL);
1.5       kristaps 1756:
1.40      kristaps 1757:        for ( ; NULL != (tok = strsep(&str, ":")); i++)
1.27      kristaps 1758:                if (NULL == (dirs[i] = strdup(tok)))
                   1759:                        texiabort(p, NULL);
1.5       kristaps 1760:
                   1761:        free(tofree);
                   1762:        return(dirs);
                   1763: }
                   1764:
1.1       kristaps 1765: int
                   1766: main(int argc, char *argv[])
                   1767: {
                   1768:        struct texi      texi;
1.2       kristaps 1769:        int              c;
1.37      kristaps 1770:        char            *dirpath, *dir, *ccp;
1.10      kristaps 1771:        const char      *progname, *Idir, *cp;
1.1       kristaps 1772:
                   1773:        progname = strrchr(argv[0], '/');
                   1774:        if (progname == NULL)
                   1775:                progname = argv[0];
                   1776:        else
                   1777:                ++progname;
                   1778:
1.10      kristaps 1779:        memset(&texi, 0, sizeof(struct texi));
1.40      kristaps 1780:        texi.ign = 1;
1.5       kristaps 1781:        Idir = NULL;
1.10      kristaps 1782:
1.5       kristaps 1783:        while (-1 != (c = getopt(argc, argv, "I:")))
1.1       kristaps 1784:                switch (c) {
1.5       kristaps 1785:                case ('I'):
                   1786:                        Idir = optarg;
                   1787:                        break;
1.1       kristaps 1788:                default:
                   1789:                        goto usage;
                   1790:                }
                   1791:
                   1792:        argv += optind;
1.40      kristaps 1793:        argc -= optind;
1.1       kristaps 1794:
1.40      kristaps 1795:        if (argc > 0) {
                   1796:                if (NULL == (dirpath = strdup(argv[0])))
                   1797:                        texiabort(&texi, NULL);
                   1798:                if (NULL == (dir = dirname(dirpath)))
                   1799:                        texiabort(&texi, NULL);
                   1800:                if (NULL != (cp = strrchr(argv[0], '/')))
                   1801:                        texi.title = strdup(cp + 1);
                   1802:                else
                   1803:                        texi.title = strdup(argv[0]);
                   1804:                if (NULL == texi.title)
                   1805:                        texiabort(&texi, NULL);
                   1806:                else if (NULL != (ccp = strchr(texi.title, '.')))
                   1807:                        *ccp = '\0';
                   1808:                texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz);
                   1809:                free(dirpath);
                   1810:                parsefile(&texi, argv[0], 1);
                   1811:        } else {
                   1812:                texi.title = strdup("Unknown Manual");
                   1813:                texi.dirs = parsedirs(&texi, NULL, Idir, &texi.dirsz);
                   1814:                parsestdin(&texi);
                   1815:        }
1.27      kristaps 1816:
1.2       kristaps 1817:        texiexit(&texi);
                   1818:        return(EXIT_FAILURE);
1.1       kristaps 1819: usage:
1.40      kristaps 1820:        fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname);
1.1       kristaps 1821:        return(EXIT_FAILURE);
                   1822: }

CVSweb