source@mandoc.bsd.lv
 help / color / Atom feed
* docbook2mdoc: end of sentence detection
@ 2019-05-02 12:41 schwarze
  0 siblings, 0 replies; only message in thread
From: schwarze @ 2019-05-02 12:41 UTC (permalink / raw)
  To: source

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

^ permalink raw reply	[flat|nested] only message in thread

only message in thread, back to index

Thread overview: (only message) (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2019-05-02 12:41 docbook2mdoc: end of sentence detection schwarze

source@mandoc.bsd.lv

Archives are clonable: git clone --mirror http://inbox.vuxu.org/mandoc-source

Example config snippet for mirrors

Newsgroup available over NNTP:
	nntp://inbox.vuxu.org/vuxu.archive.mandoc.source


AGPL code for this site: git clone https://public-inbox.org/public-inbox.git