=================================================================== RCS file: /cvs/mandoc/mdoc.c,v retrieving revision 1.126 retrieving revision 1.135 diff -u -p -r1.126 -r1.135 --- mandoc/mdoc.c 2010/05/08 08:36:44 1.126 +++ mandoc/mdoc.c 2010/05/16 10:59:36 1.135 @@ -1,4 +1,4 @@ -/* $Id: mdoc.c,v 1.126 2010/05/08 08:36:44 kristaps Exp $ */ +/* $Id: mdoc.c,v 1.135 2010/05/16 10:59:36 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 */ @@ -151,9 +150,10 @@ static struct mdoc_node *node_alloc(struct mdoc *, int enum mdoct, enum mdoc_type); static int node_append(struct mdoc *, struct mdoc_node *); -static int mdoc_ptext(struct mdoc *, int, char *); -static int mdoc_pmacro(struct mdoc *, int, char *); -static int macrowarn(struct mdoc *, int, const char *); +static int mdoc_ptext(struct mdoc *, int, char *, int); +static int mdoc_pmacro(struct mdoc *, int, char *, int); +static int macrowarn(struct mdoc *, int, + const char *, int); const struct mdoc_node * @@ -191,6 +191,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); } @@ -283,14 +285,16 @@ mdoc_endparse(struct mdoc *m) * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). */ int -mdoc_parseln(struct mdoc *m, int ln, char *buf) +mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) { if (MDOC_HALT & m->flags) return(0); - return('.' == *buf ? mdoc_pmacro(m, ln, buf) : - mdoc_ptext(m, ln, buf)); + m->flags |= MDOC_NEWLINE; + return(('.' == buf[offs] || '\'' == buf[offs]) ? + mdoc_pmacro(m, ln, buf, offs) : + mdoc_ptext(m, ln, buf, offs)); } @@ -453,7 +457,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); } @@ -625,32 +631,34 @@ mdoc_node_delete(struct mdoc *m, struct mdoc_node *p) * control character. */ static int -mdoc_ptext(struct mdoc *m, int line, char *buf) +mdoc_ptext(struct mdoc *m, int line, char *buf, int offs) { int i; /* Ignore bogus comments. */ - if ('\\' == buf[0] && '.' == buf[1] && '\"' == buf[2]) - return(mdoc_pwarn(m, line, 0, EBADCOMMENT)); + if ('\\' == buf[offs] && + '.' == buf[offs + 1] && + '"' == buf[offs + 2]) + return(mdoc_pwarn(m, line, offs, EBADCOMMENT)); /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) - return(mdoc_perr(m, line, 0, ETEXTPROL)); + return(mdoc_perr(m, line, offs, ETEXTPROL)); /* Literal just gets pulled in as-is. */ if (MDOC_LITERAL & m->flags) - return(mdoc_word_alloc(m, line, 0, buf)); + return(mdoc_word_alloc(m, line, offs, buf + offs)); /* Check for a blank line, which may also consist of spaces. */ - for (i = 0; ' ' == buf[i]; i++) + for (i = offs; ' ' == buf[i]; i++) /* Skip to first non-space. */ ; if ('\0' == buf[i]) { - if ( ! mdoc_pwarn(m, line, 0, ENOBLANK)) + if ( ! mdoc_pwarn(m, line, offs, ENOBLANK)) return(0); /* @@ -658,7 +666,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf) * blank lines aren't allowed, but enough manuals assume this * behaviour that we want to work around it. */ - if ( ! mdoc_elem_alloc(m, line, 0, MDOC_Pp, NULL)) + if ( ! mdoc_elem_alloc(m, line, offs, MDOC_Pp, NULL)) return(0); m->next = MDOC_NEXT_SIBLING; @@ -674,8 +682,7 @@ mdoc_ptext(struct mdoc *m, int line, char *buf) assert(i); if (' ' == buf[i - 1] || '\t' == buf[i - 1]) { - assert(i > 1); - if ('\\' != buf[i - 2]) + if (i > 1 && '\\' != buf[i - 2]) if ( ! mdoc_pwarn(m, line, i - 1, ETAILWS)) return(0); @@ -683,7 +690,6 @@ mdoc_ptext(struct mdoc *m, int line, char *buf) /* Spin back to non-space. */ ; /* Jump ahead of escaped whitespace. */ - assert(i); i += '\\' == buf[i] ? 2 : 1; buf[i] = '\0'; @@ -691,17 +697,30 @@ 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, offs, buf + offs)) + 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); + if (mandoc_eos(buf, (size_t)i)) + m->last->flags |= MDOC_EOS; + + return(1); } static int -macrowarn(struct mdoc *m, int ln, const char *buf) +macrowarn(struct mdoc *m, int ln, const char *buf, int offs) { if ( ! (MDOC_IGN_MACRO & m->pflags)) - return(mdoc_verr(m, ln, 0, "unknown macro: %s%s", + return(mdoc_verr(m, ln, offs, "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); - return(mdoc_vwarn(m, ln, 0, "unknown macro: %s%s", + return(mdoc_vwarn(m, ln, offs, "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); } @@ -711,18 +730,20 @@ macrowarn(struct mdoc *m, int ln, const char *buf) * character. */ int -mdoc_pmacro(struct mdoc *m, int ln, char *buf) +mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs) { enum mdoct tok; - int i, j; + int i, j, sv; char mac[5]; /* Empty lines are ignored. */ - if ('\0' == buf[1]) + offs++; + + if ('\0' == buf[offs]) return(1); - i = 1; + i = offs; /* Accept whitespace after the initial control char. */ @@ -734,6 +755,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++) { @@ -749,16 +772,16 @@ mdoc_pmacro(struct mdoc *m, int ln, char *buf) return(mdoc_perr(m, ln, i, EPRINT)); } - mac[j] = 0; + mac[j] = '\0'; if (j == 4 || j < 2) { - if ( ! macrowarn(m, ln, mac)) + if ( ! macrowarn(m, ln, mac, sv)) goto err; return(1); } if (MDOC_MAX == (tok = mdoc_hash_find(mac))) { - if ( ! macrowarn(m, ln, mac)) + if ( ! macrowarn(m, ln, mac, sv)) goto err; return(1); } @@ -781,7 +804,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);