source@mandoc.bsd.lv
 help / color / mirror / Atom feed
From: schwarze@mdocml.bsd.lv
To: source@mdocml.bsd.lv
Subject: mdocml: Text ending in a full stop, exclamation mark or question mark
Date: Sun, 18 Jul 2010 13:00:26 -0400 (EDT)	[thread overview]
Message-ID: <201007181700.o6IH0QM1011161@krisdoz.my.domain> (raw)

Log Message:
-----------
Text ending in a full stop, exclamation mark or question mark
should not flag the end of a sentence if:

1) The punctuation is followed by closing delimiters
and not preceded by alphanumeric characters, like in
"There is no full stop (.) in this sentence"

or

2) The punctuation is a child of a macro
and not preceded by alphanumeric characters, like in
"There is no full stop
.Pq \&.
in this sentence"

"looks fine" to kristaps@; tested by jmc@ and sobrado@

Modified Files:
--------------
    mdocml:
        libmandoc.h
        man.c
        mandoc.c
        mdoc.c
        mdoc_macro.c

Revision Data
-------------
Index: mandoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mandoc.c,v
retrieving revision 1.22
retrieving revision 1.23
diff -Lmandoc.c -Lmandoc.c -u -p -r1.22 -r1.23
--- mandoc.c
+++ mandoc.c
@@ -240,8 +240,10 @@ mandoc_a2time(int flags, const char *p)
 
 
 int
-mandoc_eos(const char *p, size_t sz)
+mandoc_eos(const char *p, size_t sz, int enclosed)
 {
+	const char *q;
+	int found;
 
 	if (0 == sz)
 		return(0);
@@ -252,8 +254,9 @@ mandoc_eos(const char *p, size_t sz)
 	 * propogate outward.
 	 */
 
-	for ( ; sz; sz--) {
-		switch (p[(int)sz - 1]) {
+	found = 0;
+	for (q = p + sz - 1; q >= p; q--) {
+		switch (*q) {
 		case ('\"'):
 			/* FALLTHROUGH */
 		case ('\''):
@@ -261,22 +264,22 @@ mandoc_eos(const char *p, size_t sz)
 		case (']'):
 			/* FALLTHROUGH */
 		case (')'):
+			if (0 == found)
+				enclosed = 1;
 			break;
 		case ('.'):
-			/* Escaped periods. */
-			if (sz > 1 && '\\' == p[(int)sz - 2])
-				return(0);
 			/* FALLTHROUGH */
 		case ('!'):
 			/* FALLTHROUGH */
 		case ('?'):
-			return(1);
+			found = 1;
+			break;
 		default:
-			return(0);
+			return(found && (!enclosed || isalnum(*q)));
 		}
 	}
 
-	return(0);
+	return(found && !enclosed);
 }
 
 
Index: mdoc_macro.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc_macro.c,v
retrieving revision 1.92
retrieving revision 1.93
diff -Lmdoc_macro.c -Lmdoc_macro.c -u -p -r1.92 -r1.93
--- mdoc_macro.c
+++ mdoc_macro.c
@@ -610,7 +610,7 @@ append_delims(struct mdoc *m, int line, 
 		 * knowing which symbols break this behaviour, for
 		 * example, `.  ;' shouldn't propogate the double-space.
 		 */
-		if (mandoc_eos(p, strlen(p)))
+		if (mandoc_eos(p, strlen(p), 0))
 			m->last->flags |= MDOC_EOS;
 	}
 
@@ -1266,7 +1266,7 @@ blk_part_imp(MACRO_PROT_ARGS)
 	 */
 
 	if (n && MDOC_TEXT == n->type && n->string)
-		if (mandoc_eos(n->string, strlen(n->string)))
+		if (mandoc_eos(n->string, strlen(n->string), 1))
 			n->flags |= MDOC_EOS;
 
 	/* Up-propogate the end-of-space flag. */
Index: man.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/man.c,v
retrieving revision 1.82
retrieving revision 1.83
diff -Lman.c -Lman.c -u -p -r1.82 -r1.83
--- man.c
+++ man.c
@@ -409,7 +409,7 @@ man_ptext(struct man *m, int line, char 
 	 */
 
 	assert(i);
-	if (mandoc_eos(buf, (size_t)i))
+	if (mandoc_eos(buf, (size_t)i, 0))
 		m->last->flags |= MAN_EOS;
 
 descope:
Index: mdoc.c
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/mdoc.c,v
retrieving revision 1.158
retrieving revision 1.159
diff -Lmdoc.c -Lmdoc.c -u -p -r1.158 -r1.159
--- mdoc.c
+++ mdoc.c
@@ -721,7 +721,7 @@ mdoc_ptext(struct mdoc *m, int line, cha
 
 	assert(buf < end);
 
-	if (mandoc_eos(buf+offs, (size_t)(end-buf-offs)))
+	if (mandoc_eos(buf+offs, (size_t)(end-buf-offs), 0))
 		m->last->flags |= MDOC_EOS;
 
 	return(1);
Index: libmandoc.h
===================================================================
RCS file: /usr/vhosts/mdocml.bsd.lv/cvs/mdocml/libmandoc.h,v
retrieving revision 1.8
retrieving revision 1.9
diff -Llibmandoc.h -Llibmandoc.h -u -p -r1.8 -r1.9
--- libmandoc.h
+++ libmandoc.h
@@ -1,6 +1,6 @@
 /*	$Id$ */
 /*
- * Copyright (c) 2009 Kristaps Dzonsons <kristaps@bsd.lv>
+ * Copyright (c) 2009, 2010 Kristaps Dzonsons <kristaps@bsd.lv>
  *
  * Permission to use, copy, modify, and distribute this software for any
  * purpose with or without fee is hereby granted, provided that the above
@@ -29,7 +29,7 @@ time_t		 mandoc_a2time(int, const char *
 #define		 MTIME_REDUCED		(1 << 1)
 #define		 MTIME_MDOCDATE		(1 << 2)
 #define		 MTIME_ISO_8601		(1 << 3)
-int		 mandoc_eos(const char *, size_t);
+int		 mandoc_eos(const char *, size_t, int);
 int		 mandoc_hyph(const char *, const char *);
 
 __END_DECLS
--
 To unsubscribe send an email to source+unsubscribe@mdocml.bsd.lv

                 reply	other threads:[~2010-07-18 17:00 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=201007181700.o6IH0QM1011161@krisdoz.my.domain \
    --to=schwarze@mdocml.bsd.lv \
    --cc=source@mdocml.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).