From: schwarze@mandoc.bsd.lv
To: source@mandoc.bsd.lv
Subject: docbook2mdoc: end of sentence detection
Date: Thu, 2 May 2019 07:41:13 -0500 (EST) [thread overview]
Message-ID: <e3fee73fc6c71e7c@fantadrom.bsd.lv> (raw)
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
reply other threads:[~2019-05-02 12:41 UTC|newest]
Thread overview: [no followups] expand[flat|nested] mbox.gz Atom feed
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=e3fee73fc6c71e7c@fantadrom.bsd.lv \
--to=schwarze@mandoc.bsd.lv \
--cc=source@mandoc.bsd.lv \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).