diff options
-rw-r--r-- | mdoc.c | 30 | ||||
-rw-r--r-- | mdoc.h | 3 | ||||
-rw-r--r-- | mdoc_term.c | 5 | ||||
-rw-r--r-- | term.c | 9 | ||||
-rw-r--r-- | term.h | 3 |
5 files changed, 43 insertions, 7 deletions
@@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.127 2010/05/08 10:25:27 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.128 2010/05/12 16:01:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -689,7 +689,33 @@ mdoc_ptext(struct mdoc *m, int line, char *buf) /* Allocate the whole word. */ - return(mdoc_word_alloc(m, line, 0, buf)); + if ( ! mdoc_word_alloc(m, line, 0, buf)) + return(0); + + /* + * End-of-sentence check. If the last character is an unescaped + * EOS character, then flag the node as being the end of a + * sentence. The front-end will know how to interpret this. + */ + + assert(i); + + switch (buf[i - 1]) { + case ('.'): + if (i > 1 && '\\' == buf[i - 2]) + break; + /* FALLTHROUGH */ + case ('!'): + /* FALLTHROUGH */ + case ('?'): + m->last->flags |= MDOC_EOS; + break; + default: + break; + + } + + return(1); } @@ -1,4 +1,4 @@ -/* $Id: mdoc.h,v 1.76 2010/05/12 08:41:17 kristaps Exp $ */ +/* $Id: mdoc.h,v 1.77 2010/05/12 16:01:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -260,6 +260,7 @@ struct mdoc_node { int flags; #define MDOC_VALID (1 << 0) #define MDOC_ACTED (1 << 1) +#define MDOC_EOS (1 << 2) enum mdoc_type type; enum mdoc_sec sec; diff --git a/mdoc_term.c b/mdoc_term.c index 4f625a58..490c3e47 100644 --- a/mdoc_term.c +++ b/mdoc_term.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_term.c,v 1.120 2010/05/10 08:05:17 kristaps Exp $ */ +/* $Id: mdoc_term.c,v 1.121 2010/05/12 16:01:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -337,6 +337,9 @@ print_mdoc_node(DECL_ARGS) if (termacts[n->tok].post) (*termacts[n->tok].post)(p, &npair, m, n); + if (MDOC_EOS & n->flags) + p->flags |= TERMP_SENTENCE; + p->offset = offset; p->rmargin = rmargin; } @@ -1,4 +1,4 @@ -/* $Id: term.c,v 1.132 2010/05/07 04:50:44 kristaps Exp $ */ +/* $Id: term.c,v 1.133 2010/05/12 16:01:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -445,12 +445,17 @@ term_word(struct termp *p, const char *word) break; } - if ( ! (TERMP_NOSPACE & p->flags)) + if ( ! (TERMP_NOSPACE & p->flags)) { bufferc(p, ' '); + if (TERMP_SENTENCE & p->flags) + bufferc(p, ' '); + } if ( ! (p->flags & TERMP_NONOSPACE)) p->flags &= ~TERMP_NOSPACE; + p->flags &= ~TERMP_SENTENCE; + /* FIXME: use strcspn. */ while (*word) { @@ -1,4 +1,4 @@ -/* $Id: term.h,v 1.53 2010/05/10 08:05:17 kristaps Exp $ */ +/* $Id: term.h,v 1.54 2010/05/12 16:01:01 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -39,6 +39,7 @@ struct termp { size_t col; /* Bytes in buf. */ int overstep; /* See termp_flushln(). */ int flags; +#define TERMP_SENTENCE (1 << 1) /* Space before a sentence. */ #define TERMP_NOSPACE (1 << 2) /* No space before words. */ #define TERMP_NOLPAD (1 << 3) /* See term_flushln(). */ #define TERMP_NOBREAK (1 << 4) /* See term_flushln(). */ |