=================================================================== RCS file: /cvs/docbook2mdoc/macro.c,v retrieving revision 1.16 retrieving revision 1.20 diff -u -p -r1.16 -r1.20 --- docbook2mdoc/macro.c 2019/04/24 18:38:02 1.16 +++ docbook2mdoc/macro.c 2019/05/02 12:40:42 1.20 @@ -1,4 +1,4 @@ -/* $Id: macro.c,v 1.16 2019/04/24 18:38:02 schwarze Exp $ */ +/* $Id: macro.c,v 1.20 2019/05/02 12:40:42 schwarze Exp $ */ /* * Copyright (c) 2019 Ingo Schwarze * @@ -28,27 +28,36 @@ */ void -macro_open(struct format *f, const char *name) +para_check(struct format *f) { - if (f->parastate == PARA_WANT) { - if (f->linestate != LINE_NEW) { - putchar('\n'); - f->linestate = LINE_NEW; - } - puts(".Pp"); + if (f->parastate != PARA_WANT) + return; + if (f->linestate != LINE_NEW) { + putchar('\n'); + f->linestate = LINE_NEW; } + puts(".Pp"); + f->parastate = PARA_HAVE; +} + +void +macro_open(struct format *f, const char *name) +{ + para_check(f); switch (f->linestate) { case LINE_MACRO: if (f->flags & FMT_NOSPC) { fputs(" Ns ", stdout); break; } - if (f->flags & (FMT_CHILD | FMT_IMPL)) { + if (f->nofill || f->flags & (FMT_CHILD | FMT_IMPL)) { putchar(' '); break; } /* FALLTHROUGH */ case LINE_TEXT: + if (f->nofill && f->linestate == LINE_TEXT) + fputs(" \\c", stdout); putchar('\n'); /* FALLTHROUGH */ case LINE_NEW: @@ -239,13 +248,9 @@ macro_nodeline(struct format *f, const char *name, str void print_text(struct format *f, const char *word, int flags) { - if (f->parastate == PARA_WANT) { - if (f->linestate != LINE_NEW) { - putchar('\n'); - f->linestate = LINE_NEW; - } - puts(".Pp"); - } + int ateos, inword; + + para_check(f); switch (f->linestate) { case LINE_NEW: break; @@ -259,7 +264,53 @@ print_text(struct format *f, const char *word, int fla } if (f->linestate == LINE_NEW && (*word == '.' || *word == '\'')) fputs("\\&", stdout); + ateos = inword = 0; while (*word != '\0') { + if (f->nofill == 0) { + switch (*word) { + case ' ': + if (ateos == 0) { + inword = 0; + break; + } + ateos = inword = 0; + /* Handle the end of a sentence. */ + while (*word == ' ') + word++; + switch (*word) { + case '\0': + break; + case '\'': + case '.': + fputs("\n\\&", stdout); + break; + default: + putchar('\n'); + break; + } + continue; + /* Detect the end of a sentence. */ + case '!': + case '.': + case '?': + if (inword > 1 && + (word[-2] != 'n' || word[-1] != 'c') && + (word[-2] != 'v' || word[-1] != 's')) + ateos = 1; + /* FALLTHROUGH */ + case '"': + case '\'': + case ')': + case ']': + inword = 0; + break; + default: + if (isalnum((unsigned char)*word)) + inword++; + ateos = 0; + break; + } + } putchar(*word); if (*word++ == '\\') putchar('e');