=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.36 retrieving revision 1.40 diff -u -p -r1.36 -r1.40 --- texi2mdoc/main.c 2015/02/23 15:23:44 1.36 +++ texi2mdoc/main.c 2015/02/23 22:50:11 1.40 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.36 2015/02/23 15:23:44 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 @@ -143,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 */ @@ -1061,10 +1066,10 @@ dosymbol(struct texi *p, enum texicmd cmd, case (TEXICMD_SQUIGGLE_RIGHT): texiputchars(p, "}"); break; - case (TEXICMD_TIE): + case (TEXICMD_TEXSYM): texiputchars(p, "TeX"); break; - case (TEXICMD_TEXSYM): + case (TEXICMD_TIE): texiputchars(p, "\\ "); break; case (TEXICMD_COLON): @@ -1209,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(); @@ -1355,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); } @@ -1591,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 ** @@ -1599,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); @@ -1631,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], '/'); @@ -1641,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:"))) @@ -1653,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); }