=================================================================== RCS file: /cvs/texi2mdoc/main.c,v retrieving revision 1.53 retrieving revision 1.56 diff -u -p -r1.53 -r1.56 --- texi2mdoc/main.c 2015/02/28 08:41:59 1.53 +++ texi2mdoc/main.c 2015/03/01 13:39:51 1.56 @@ -1,4 +1,4 @@ -/* $Id: main.c,v 1.53 2015/02/28 08:41:59 kristaps Exp $ */ +/* $Id: main.c,v 1.56 2015/03/01 13:39:51 kristaps Exp $ */ /* * Copyright (c) 2015 Kristaps Dzonsons * @@ -26,7 +26,6 @@ #include #include #include -#include #include #include "extern.h" @@ -498,9 +497,45 @@ dodefn(struct texi *p, enum texicmd cmd, size_t *pos) abort(); } - texivspace(p); - if (NULL != blk) - parseto(p, pos, blk); + if (NULL == blk) + return; + + /* + * All "block" definitions have their block bodies indented + * unless they have the "x" form of the command following. + * E.g., + * @deffn some function + * @deffnx another + * An explanation. + * @end deffn + * With this loop, we delay opening the indented block until we + * skipped past conformant macros. + */ + for (;;) { + switch (peekcmd(p, *pos)) { + case (TEXICMD_DEFFNX): + case (TEXICMD_DEFMACX): + case (TEXICMD_DEFTPX): + case (TEXICMD_DEFTYPEFNX): + case (TEXICMD_DEFTYPEFUNX): + case (TEXICMD_DEFTYPEMETHODX): + case (TEXICMD_DEFTYPEVARX): + case (TEXICMD_DEFTYPEVRX): + case (TEXICMD_DEFUNX): + case (TEXICMD_DEFVARX): + case (TEXICMD_DEFVRX): + texivspace(p); + parseeoln(p, pos); + continue; + default: + break; + } + break; + } + teximacro(p, "Bd -filled -offset indent"); + p->seenvs = 1; + parseto(p, pos, blk); + teximacro(p, "Ed"); } static void @@ -955,6 +990,8 @@ dotitle(struct texi *p, enum texicmd cmd, size_t *pos) start = end = *pos; while (end < BUFSZ(p) && '\n' != BUF(p)[end]) end++; + if (end < BUFSZ(p)) + end++; advanceeoln(p, pos, 1); free(p->subtitle); p->subtitle = malloc(end - start + 1); @@ -1375,7 +1412,7 @@ dovalue(struct texi *p, enum texicmd cmd, size_t *pos) texiputchar(p, ' '); p->seenws = 0; if (NULL != (cp = valueblookup(p, pos))) - texisplice(p, cp, strlen(cp), pos); + texisplice(p, cp, strlen(cp), *pos); else texiputchars(p, "{No value}"); } else if (TEXICMD_IFCLEAR == cmd) { @@ -1517,9 +1554,11 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po int sec; switch (cmd) { + case (TEXICMD_TOP): + sec = 0; + break; case (TEXICMD_APPENDIX): case (TEXICMD_CHAPTER): - case (TEXICMD_TOP): case (TEXICMD_UNNUMBERED): sec = sectioner(p, 0); break; @@ -1538,6 +1577,11 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po else if (p->literal) texierr(p, "\"%s\" in a literal scope!?", sects[sec]); + if (0 == sec && NULL != p->chapters) { + teximdocclose(p, 0); + teximdocopen(p, pos); + } + teximacroopen(p, sects[sec]); parseeoln(p, pos); teximacroclose(p); @@ -1545,6 +1589,18 @@ dosection(struct texi *p, enum texicmd cmd, size_t *po } static void +dotop(struct texi *p, enum texicmd cmd, size_t *pos) +{ + + if (--p->ign) + texierr(p, "@top command while ignoring"); + + if (NULL == p->chapters) + teximdocopen(p, pos); + dosection(p, cmd, pos); +} + +static void dosp(struct texi *p, enum texicmd cmd, size_t *pos) { @@ -1557,51 +1613,6 @@ dosp(struct texi *p, enum texicmd cmd, size_t *pos) } static void -dotop(struct texi *p, enum texicmd cmd, size_t *pos) -{ - const char *cp; - time_t t; - char date[32]; - - if (--p->ign) - texierr(p, "@top command while ignoring"); - - /* - * Here we print our standard mdoc(7) prologue. - * We use the title set with @settitle for the `Nd' description - * and the source document filename (the first one as invoked on - * the command line) for the title. - * The date is set to the current date. - */ - t = time(NULL); - strftime(date, sizeof(date), "%F", localtime(&t)); - - teximacroopen(p, "Dd"); - texiputchars(p, date); - teximacroclose(p); - teximacroopen(p, "Dt"); - for (cp = p->title; '\0' != *cp; cp++) - texiputchar(p, toupper((unsigned int)*cp)); - texiputchars(p, " 7"); - teximacroclose(p); - teximacro(p, "Os"); - teximacro(p, "Sh NAME"); - teximacroopen(p, "Nm"); - for (cp = p->title; '\0' != *cp; cp++) - texiputchar(p, *cp); - teximacroclose(p); - teximacroopen(p, "Nd"); - if (NULL != p->subtitle) - for (cp = p->subtitle; '\0' != *cp; cp++) - texiputchar(p, *cp); - else - texiputchars(p, "Unknown description"); - teximacroclose(p); - p->seenvs = 1; - dosection(p, cmd, pos); -} - -static void doitem(struct texi *p, enum texicmd cmd, size_t *pos) { @@ -1743,7 +1754,8 @@ doend(struct texi *p, enum texicmd cmd, size_t *pos) while (*pos < BUFSZ(p) && '\n' != BUF(p)[*pos]) advance(p, pos); - texiwarn(p, "unexpected \"end\": %.*s", (int)(*pos - start), &BUF(p)[start]); + texiwarn(p, "unexpected \"end\": %.*s", + (int)(*pos - start), &BUF(p)[start]); advanceeoln(p, pos, 1); } @@ -1849,10 +1861,14 @@ main(int argc, char *argv[]) memset(&texi, 0, sizeof(struct texi)); texi.ign = 1; + texi.outfile = stdout; Idir = NULL; - while (-1 != (c = getopt(argc, argv, "I:"))) + while (-1 != (c = getopt(argc, argv, "C:I:"))) switch (c) { + case ('C'): + texi.chapters = optarg; + break; case ('I'): Idir = optarg; break; @@ -1886,8 +1902,8 @@ main(int argc, char *argv[]) } texiexit(&texi); - return(EXIT_FAILURE); + exit(EXIT_SUCCESS); usage: - fprintf(stderr, "usage: %s [-Idirs] [file]\n", progname); + fprintf(stderr, "usage: %s [-Cdir] [-Idirs] [file]\n", progname); return(EXIT_FAILURE); }