=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.34 retrieving revision 1.40 diff -u -p -r1.34 -r1.40 --- texi2mdoc/main.c 2015/02/23 14:36:03 1.34 +++ texi2mdoc/main.c 2015/02/23 22:50:11 1.40 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.34 2015/02/23 14:36:03 kristaps Exp $ */ +/* $Id: main.c,v 1.40 2015/02/23 22:50:11 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -14,6 +14,9 @@ * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ +#if defined(__linux__) || defined(__MINT__) +# define _GNU_SOURCE /* memmem */ +#endif #include #include @@ -106,6 +109,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { doinline, "code", 4 }, /* TEXICMD_CODE */ { dosymbol, ":", 1 }, /* TEXICMD_COLON */ { NULL, "columnfractions", 15 }, /* TEXICMD_COLUMNFRACTIONS */ + { dosymbol, "comma", 5 }, /* TEXICMD_COMMA */ { doinline, "command", 7 }, /* TEXICMD_COMMAND */ { doignline, "c", 1 }, /* TEXICMD_COMMENT */ { doignline, "comment", 7 }, /* TEXICMD_COMMENT_LONG */ @@ -142,6 +146,8 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { doignblock, "direntry", 8 }, /* TEXICMD_DIRENTRY */ { dodisplay, "display", 7 }, /* TEXICMD_DISPLAY */ { doignbracket, "dmn", 3 }, /* TEXICMD_DMN */ + { doignblock, "documentdescription", 19 }, /* TEXICMD_DOCUMENTDESCRIPTION */ + { doignline, "documentencoding", 16 }, /* TEXICMD_DOCUMENTENCODING */ { dosymbol, "dots", 4 }, /* TEXICMD_DOTS */ { dolink, "email", 5 }, /* TEXICMD_EMAIL */ { doinline, "emph", 4 }, /* TEXICMD_EMPH */ @@ -225,6 +231,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dosection, "section", 7 }, /* TEXICMD_SECTION */ { dovalue, "set", 3 }, /* TEXICMD_SET */ { doignline, "setchapternewpage", 17 }, /* TEXICMD_SETCHAPNEWPAGE */ + { doignline, "setcontentsaftertitlepage", 25 }, /* TEXICMD_SETCONTENTSAFTER */ { doignline, "setfilename", 11 }, /* TEXICMD_SETFILENAME */ { dotitle, "settitle", 8 }, /* TEXICMD_SETTITLE */ { doignline, "shortcontents", 13 }, /* TEXICMD_SHORTCONTENTS */ @@ -239,6 +246,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dodisplay, "smallindentblock", 16 }, /* TEXICMD_SMALLINDENTBLOCK */ { dosymbol, "{", 1 }, /* TEXICMD_SQUIGGLE_LEFT */ { dosymbol, "}", 1 }, /* TEXICMD_SQUIGGLE_RIGHT */ + { dosymbol, "ss", 2 }, /* TEXICMD_SS */ { doinline, "strong", 6 }, /* TEXICMD_STRONG */ { dosubsection, "subheading", 10 }, /* TEXICMD_SUBHEADING */ { dosubsection, "subsection", 10 }, /* TEXICMD_SUBSECTION */ @@ -254,6 +262,7 @@ static const struct texitok __texitoks[TEXICMD__MAX] = { dotable, "table", 5 }, /* TEXICMD_TABLE */ { doignblock, "tex", 3 }, /* TEXICMD_TEX */ { dosymbol, "TeX", 3 }, /* TEXICMD_TEXSYM */ + { dosymbol, "tie", 3 }, /* TEXICMD_TIE */ { doaccent, "~", 1 }, /* TEXICMD_TILDE */ { doignline, "tindex", 6 }, /* TEXICMD_TINDEX */ { doignline, "title", 5 }, /* TEXICMD_TITLE */ @@ -323,6 +332,7 @@ dodefn(struct texi *p, enum texicmd cmd, blk = NULL; switch (cmd) { case (TEXICMD_DEFFN): + case (TEXICMD_DEFMAC): case (TEXICMD_DEFTP): case (TEXICMD_DEFTYPEFN): case (TEXICMD_DEFTYPEFUN): @@ -527,7 +537,7 @@ doignblock(struct texi *p, enum texicmd cmd, */ term = memmem(&buf[*pos], sz, end, endsz); endpos = NULL == term ? sz : - *pos + term - &buf[*pos]; + *pos + (size_t)(term - &buf[*pos]); assert(endpos <= sz); while (*pos < endpos) advance(p, buf, pos); @@ -659,7 +669,7 @@ doverbatim(struct texi *p, enum texicmd cmd, */ term = memmem(&buf[*pos], sz, end, endsz); endpos = NULL == term ? sz : - *pos + term - &buf[*pos]; + *pos + (size_t)(term - &buf[*pos]); teximacro(p, "Bd -literal -offset indent"); assert(endpos <= sz); @@ -1010,6 +1020,9 @@ dosymbol(struct texi *p, enum texicmd cmd, case (TEXICMD_BULLET): texiputchars(p, "\\(bu"); break; + case (TEXICMD_COMMA): + texiputchar(p, ','); + break; case (TEXICMD_COPYRIGHT): texiputchars(p, "\\(co"); break; @@ -1044,6 +1057,9 @@ dosymbol(struct texi *p, enum texicmd cmd, case (TEXICMD_SLASH): texiputchar(p, '/'); break; + case (TEXICMD_SS): + texiputchars(p, "\\(ss"); + break; case (TEXICMD_SQUIGGLE_LEFT): texiputchars(p, "{"); break; @@ -1053,6 +1069,9 @@ dosymbol(struct texi *p, enum texicmd cmd, case (TEXICMD_TEXSYM): texiputchars(p, "TeX"); break; + case (TEXICMD_TIE): + texiputchars(p, "\\ "); + break; case (TEXICMD_COLON): case (TEXICMD_HYPHEN): break; @@ -1195,15 +1214,15 @@ dolink(struct texi *p, enum texicmd cmd, break; case (TEXICMD_XREF): texiputchars(p, "See Section"); - teximacroopen(p, "Qq"); + teximacroopen(p, "Dq"); break; case (TEXICMD_PXREF): texiputchars(p, "see Section"); - teximacroopen(p, "Qq"); + teximacroopen(p, "Dq"); break; case (TEXICMD_INFOREF): texiputchars(p, "See Info file node"); - teximacroopen(p, "Qq"); + teximacroopen(p, "Dq"); break; default: abort(); @@ -1341,7 +1360,10 @@ dosp(struct texi *p, enum texicmd cmd, const char *buf, size_t sz, size_t *pos) { - texivspace(p); + if (p->literal) + texiputchar(p, '\n'); + else + texivspace(p); /* FIXME: ignore and parseeoln. */ advanceeoln(p, buf, sz, pos, 1); } @@ -1577,7 +1599,7 @@ doignline(struct texi *p, enum texicmd cmd, /* * Parse colon-separated directories from "cp" (if not NULL) and returns * the array of pointers. - * Prepends "base" to the array. + * Prepends "base" to the array, if found. * This does NOT sanitise the directories! */ static char ** @@ -1585,26 +1607,27 @@ parsedirs(struct texi *p, const char *base, const char { char *tok, *str, *tofree; const char *cpp; - size_t i; + size_t i = 0; char **dirs; - *sz = NULL != (cpp = cp) ? 2 : 1; - if (*sz > 1) - for ( ; NULL != (cpp = strchr(cpp, ':')); (*sz)++) + /* Count up our expected arguments. */ + *sz = NULL != base; + if (NULL != (cpp = cp)) + for ((*sz)++; NULL != (cpp = strchr(cpp, ':')); (*sz)++) cpp++; + if (0 == *sz) + return(NULL); if (NULL == (dirs = calloc(*sz, sizeof(char *)))) texiabort(p, NULL); - else if (NULL == (dirs[0] = strdup(base))) + if (NULL != base && NULL == (dirs[i++] = strdup(base))) texiabort(p, NULL); - if (NULL == cp) return(dirs); - if (NULL == (tofree = tok = str = strdup(cp))) texiabort(p, NULL); - for (i = 1; NULL != (tok = strsep(&str, ":")); i++) + for ( ; NULL != (tok = strsep(&str, ":")); i++) if (NULL == (dirs[i] = strdup(tok))) texiabort(p, NULL); @@ -1617,7 +1640,7 @@ main(int argc, char *argv[]) { struct texi texi; int c; - char *path, *dir; + char *dirpath, *dir, *ccp; const char *progname, *Idir, *cp; progname = strrchr(argv[0], '/'); @@ -1627,6 +1650,7 @@ main(int argc, char *argv[]) ++progname; memset(&texi, 0, sizeof(struct texi)); + texi.ign = 1; Idir = NULL; while (-1 != (c = getopt(argc, argv, "I:"))) @@ -1639,33 +1663,33 @@ main(int argc, char *argv[]) } argv += optind; - if (0 == (argc -= optind)) - goto usage; + argc -= optind; - if (NULL == (path = strdup(argv[0]))) - texiabort(&texi, NULL); - else if (NULL == (dir = dirname(path))) - texiabort(&texi, NULL); + if (argc > 0) { + if (NULL == (dirpath = strdup(argv[0]))) + texiabort(&texi, NULL); + if (NULL == (dir = dirname(dirpath))) + texiabort(&texi, NULL); + if (NULL != (cp = strrchr(argv[0], '/'))) + texi.title = strdup(cp + 1); + else + texi.title = strdup(argv[0]); + if (NULL == texi.title) + texiabort(&texi, NULL); + else if (NULL != (ccp = strchr(texi.title, '.'))) + *ccp = '\0'; + texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz); + free(dirpath); + parsefile(&texi, argv[0], 1); + } else { + texi.title = strdup("Unknown Manual"); + texi.dirs = parsedirs(&texi, NULL, Idir, &texi.dirsz); + parsestdin(&texi); + } - free(path); - - if (NULL != (cp = strrchr(argv[0], '/'))) - texi.title = strdup(cp + 1); - else - texi.title = strdup(argv[0]); - - if (NULL == texi.title) - texiabort(&texi, NULL); - else if (NULL != (path = strchr(texi.title, '.'))) - *path = '\0'; - - texi.ign = 1; - texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz); - parsefile(&texi, argv[0], 1); - /* We shouldn't get here. */ texiexit(&texi); return(EXIT_FAILURE); usage: - fprintf(stderr, "usage: %s [-Idirs] file\n", progname); + fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname); return(EXIT_FAILURE); }