From 8ee4ce8a2dfd617e29674aa4e0718c32e1ad02c5 Mon Sep 17 00:00:00 2001 From: Ingo Schwarze Date: Sun, 18 Jul 2010 17:00:26 +0000 Subject: 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@ --- libmandoc.h | 6 +++--- man.c | 4 ++-- mandoc.c | 23 +++++++++++++---------- mdoc.c | 4 ++-- mdoc_macro.c | 6 +++--- 5 files changed, 23 insertions(+), 20 deletions(-) diff --git a/libmandoc.h b/libmandoc.h index b25e4a7e..ab21a421 100644 --- a/libmandoc.h +++ b/libmandoc.h @@ -1,6 +1,6 @@ -/* $Id: libmandoc.h,v 1.8 2010/06/19 20:46:27 kristaps Exp $ */ +/* $Id: libmandoc.h,v 1.9 2010/07/18 17:00:26 schwarze Exp $ */ /* - * Copyright (c) 2009 Kristaps Dzonsons + * Copyright (c) 2009, 2010 Kristaps Dzonsons * * 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 diff --git a/man.c b/man.c index d6d9530a..9439d755 100644 --- a/man.c +++ b/man.c @@ -1,4 +1,4 @@ -/* $Id: man.c,v 1.82 2010/07/13 23:53:20 schwarze Exp $ */ +/* $Id: man.c,v 1.83 2010/07/18 17:00:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -409,7 +409,7 @@ man_ptext(struct man *m, int line, char *buf, int offs) */ assert(i); - if (mandoc_eos(buf, (size_t)i)) + if (mandoc_eos(buf, (size_t)i, 0)) m->last->flags |= MAN_EOS; descope: diff --git a/mandoc.c b/mandoc.c index 44de75b4..72eba853 100644 --- a/mandoc.c +++ b/mandoc.c @@ -1,4 +1,4 @@ -/* $Id: mandoc.c,v 1.22 2010/07/18 12:10:08 kristaps Exp $ */ +/* $Id: mandoc.c,v 1.23 2010/07/18 17:00:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * @@ -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); } diff --git a/mdoc.c b/mdoc.c index c8d9fed4..bcc6e4ca 100644 --- a/mdoc.c +++ b/mdoc.c @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.158 2010/07/07 15:04:54 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.159 2010/07/18 17:00:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -721,7 +721,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf, int offs) 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); diff --git a/mdoc_macro.c b/mdoc_macro.c index b4267306..91972f34 100644 --- a/mdoc_macro.c +++ b/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.92 2010/07/04 22:04:04 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.93 2010/07/18 17:00:26 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010 Kristaps Dzonsons * Copyright (c) 2010 Ingo Schwarze @@ -610,7 +610,7 @@ append_delims(struct mdoc *m, int line, int *pos, char *buf) * 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. */ -- cgit v1.2.3-56-ge451