From mboxrd@z Thu Jan 1 00:00:00 1970 Received: from localhost (fantadrom.bsd.lv [local]) by fantadrom.bsd.lv (OpenSMTPD) with ESMTPA id 7d37df19 for ; Thu, 2 May 2019 07:41:13 -0500 (EST) Date: Thu, 2 May 2019 07:41:13 -0500 (EST) X-Mailinglist: mandoc-source Reply-To: source@mandoc.bsd.lv MIME-Version: 1.0 From: schwarze@mandoc.bsd.lv To: source@mandoc.bsd.lv Subject: docbook2mdoc: end of sentence detection X-Mailer: activitymail 1.26, http://search.cpan.org/dist/activitymail/ Content-Type: text/plain; charset=utf-8 Message-ID: Log Message: ----------- end of sentence detection Modified Files: -------------- docbook2mdoc: docbook2mdoc.1 macro.c Revision Data ------------- Index: docbook2mdoc.1 =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/docbook2mdoc.1,v retrieving revision 1.16 retrieving revision 1.17 diff -Ldocbook2mdoc.1 -Ldocbook2mdoc.1 -u -p -r1.16 -r1.17 --- docbook2mdoc.1 +++ docbook2mdoc.1 @@ -203,13 +203,3 @@ was written by .An Kristaps Dzonsons Aq Mt kristaps@bsd.lv and .An Ingo Schwarze Aq Mt schwarze@openbsd.org . -.Sh CAVEATS -The -.Nm -utility is experimental. -Many elements are not recognized yet. -.Pp -The output -.Xr mdoc 7 -could be much nicer: trailing spaces, superfluous space removal, -new-line new-sentence, and other niceties are not used. Index: macro.c =================================================================== RCS file: /home/cvs/mdocml/docbook2mdoc/macro.c,v retrieving revision 1.19 retrieving revision 1.20 diff -Lmacro.c -Lmacro.c -u -p -r1.19 -r1.20 --- macro.c +++ macro.c @@ -248,6 +248,8 @@ macro_nodeline(struct format *f, const c void print_text(struct format *f, const char *word, int flags) { + int ateos, inword; + para_check(f); switch (f->linestate) { case LINE_NEW: @@ -262,7 +264,53 @@ print_text(struct format *f, const char } 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'); -- To unsubscribe send an email to source+unsubscribe@mandoc.bsd.lv