=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.39 retrieving revision 1.40 diff -u -p -r1.39 -r1.40 --- texi2mdoc/main.c 2015/02/23 20:54:53 1.39 +++ texi2mdoc/main.c 2015/02/23 22:50:11 1.40 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.39 2015/02/23 20:54:53 kristaps Exp $ */ +/* $Id: main.c,v 1.40 2015/02/23 22:50:11 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -146,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 */ @@ -1597,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 ** @@ -1605,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); @@ -1647,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:"))) @@ -1659,32 +1663,33 @@ main(int argc, char *argv[]) } argv += optind; - if (0 == (argc -= optind)) - goto usage; + argc -= optind; - if (NULL == (dirpath = strdup(argv[0]))) - texiabort(&texi, NULL); - if (NULL == (dir = dirname(dirpath))) - 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); + } - 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.ign = 1; - texi.dirs = parsedirs(&texi, dir, Idir, &texi.dirsz); - free(dirpath); - 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); }