=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.125 retrieving revision 1.133 diff -u -p -r1.125 -r1.133 --- mandoc/mdoc.c 2010/05/08 07:30:19 1.125 +++ mandoc/mdoc.c 2010/05/15 16:24:37 1.133 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.125 2010/05/08 07:30:19 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.133 2010/05/15 16:24:37 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * @@ -69,7 +69,6 @@ const char *const __mdoc_merrnames[MERRMAX] = { "prologue macro out of conventional order", /* EPROLOOO */ "prologue macro repeated", /* EPROLREP */ "invalid manual section", /* EBADMSEC */ - "invalid section", /* EBADSEC */ "invalid font mode", /* EFONT */ "invalid date syntax", /* EBADDATE */ "invalid number format", /* ENUMFMT */ @@ -191,6 +190,8 @@ mdoc_free1(struct mdoc *mdoc) free(mdoc->meta.arch); if (mdoc->meta.vol) free(mdoc->meta.vol); + if (mdoc->meta.msec) + free(mdoc->meta.msec); } @@ -289,7 +290,9 @@ mdoc_parseln(struct mdoc *m, int ln, char *buf) if (MDOC_HALT & m->flags) return(0); - return('.' == *buf ? mdoc_pmacro(m, ln, buf) : + m->flags |= MDOC_NEWLINE; + return('.' == *buf ? + mdoc_pmacro(m, ln, buf) : mdoc_ptext(m, ln, buf)); } @@ -453,7 +456,9 @@ node_alloc(struct mdoc *m, int line, int pos, p->pos = pos; p->tok = tok; p->type = type; - + if (MDOC_NEWLINE & m->flags) + p->flags |= MDOC_LINE; + m->flags &= ~MDOC_NEWLINE; return(p); } @@ -665,19 +670,47 @@ mdoc_ptext(struct mdoc *m, int line, char *buf) return(1); } - /* Warn if the last un-escaped character is whitespace. */ + /* + * Warn if the last un-escaped character is whitespace. Then + * strip away the remaining spaces (tabs stay!). + */ i = (int)strlen(buf); assert(i); - if (' ' == buf[i - 1] || '\t' == buf[i - 1]) - if (1 == i || ('\\' != buf[i - 2])) + if (' ' == buf[i - 1] || '\t' == buf[i - 1]) { + if (i > 1 && '\\' != buf[i - 2]) if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS)) return(0); + for (--i; i && ' ' == buf[i]; i--) + /* Spin back to non-space. */ ; + + /* Jump ahead of escaped whitespace. */ + i += '\\' == buf[i] ? 2 : 1; + + buf[i] = '\0'; + } + /* 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. + */ + + /* FIXME: chain of close delims. */ + + assert(i); + + if (mandoc_eos(buf, (size_t)i)) + m->last->flags |= MDOC_EOS; + + return(1); } @@ -700,7 +733,7 @@ int mdoc_pmacro(struct mdoc *m, int ln, char *buf) { enum mdoct tok; - int i, j; + int i, j, sv; char mac[5]; /* Empty lines are ignored. */ @@ -720,6 +753,8 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf) return(1); } + sv = i; + /* Copy the first word into a nil-terminated buffer. */ for (j = 0; j < 4; j++, i++) { @@ -767,7 +802,7 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf) * Begin recursive parse sequence. Since we're at the start of * the line, we don't need to do callable/parseable checks. */ - if ( ! mdoc_macro(m, tok, ln, 1, &i, buf)) + if ( ! mdoc_macro(m, tok, ln, sv, &i, buf)) goto err; return(1);