=================================================================== RCS file: /cvsrepo/anoncvs/cvs/src/usr.bin/mandoc/mdoc.c,v retrieving revision 1.52 retrieving revision 1.53 diff -c -r1.52 -r1.53 *** src/usr.bin/mandoc/mdoc.c 2010/05/16 20:46:15 1.52 --- src/usr.bin/mandoc/mdoc.c 2010/05/20 00:58:02 1.53 *************** *** 1,4 **** ! /* $Id: mdoc.c,v 1.52 2010/05/16 20:46:15 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * --- 1,4 ---- ! /* $Id: mdoc.c,v 1.53 2010/05/20 00:58:02 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons * *************** *** 146,154 **** 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 *); const struct mdoc_node * --- 146,155 ---- enum mdoct, enum mdoc_type); static int node_append(struct mdoc *, struct mdoc_node *); ! 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 * *************** *** 280,295 **** * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). */ int ! mdoc_parseln(struct mdoc *m, int ln, char *buf) { if (MDOC_HALT & m->flags) return(0); m->flags |= MDOC_NEWLINE; ! return(('.' == *buf || '\'' == *buf) ? ! mdoc_pmacro(m, ln, buf) : ! mdoc_ptext(m, ln, buf)); } --- 281,296 ---- * the macro (mdoc_pmacro()) or text parser (mdoc_ptext()). */ int ! mdoc_parseln(struct mdoc *m, int ln, char *buf, int offs) { if (MDOC_HALT & m->flags) return(0); m->flags |= MDOC_NEWLINE; ! return(('.' == buf[offs] || '\'' == buf[offs]) ? ! mdoc_pmacro(m, ln, buf, offs) : ! mdoc_ptext(m, ln, buf, offs)); } *************** *** 626,651 **** * control character. */ static int ! mdoc_ptext(struct mdoc *m, int line, char *buf) { char *c, *ws, *end; /* Ignore bogus comments. */ ! if ('\\' == buf[0] && '.' == buf[1] && '\"' == buf[2]) ! return(mdoc_pwarn(m, line, 0, EBADCOMMENT)); /* No text before an initial macro. */ if (SEC_NONE == m->lastnamed) ! return(mdoc_perr(m, line, 0, ETEXTPROL)); /* * Search for the beginning of unescaped trailing whitespace (ws) * and for the first character not to be output (end). */ ws = NULL; ! for (c = end = buf; *c; c++) { switch (*c) { case ' ': if (NULL == ws) --- 627,654 ---- * control character. */ static int ! mdoc_ptext(struct mdoc *m, int line, char *buf, int offs) { char *c, *ws, *end; /* Ignore bogus comments. */ ! 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, offs, ETEXTPROL)); /* * Search for the beginning of unescaped trailing whitespace (ws) * and for the first character not to be output (end). */ ws = NULL; ! for (c = end = buf + offs; *c; c++) { switch (*c) { case ' ': if (NULL == ws) *************** *** 683,689 **** if ( ! mdoc_pwarn(m, line, (int)(ws-buf), ETAILWS)) return(0); ! if ('\0' == *buf && ! (MDOC_LITERAL & m->flags)) { if ( ! mdoc_pwarn(m, line, (int)(c-buf), ENOBLANK)) return(0); --- 686,692 ---- if ( ! mdoc_pwarn(m, line, (int)(ws-buf), ETAILWS)) return(0); ! if ('\0' == buf[offs] && ! (MDOC_LITERAL & m->flags)) { if ( ! mdoc_pwarn(m, line, (int)(c-buf), ENOBLANK)) return(0); *************** *** 692,705 **** * 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)) return(0); m->next = MDOC_NEXT_SIBLING; return(1); } ! if ( ! mdoc_word_alloc(m, line, 0, buf)) return(0); if (MDOC_LITERAL & m->flags) --- 695,708 ---- * blank lines aren't allowed, but enough manuals assume this * behaviour that we want to work around it. */ ! if ( ! mdoc_elem_alloc(m, line, offs, MDOC_Pp, NULL)) return(0); m->next = MDOC_NEXT_SIBLING; return(1); } ! if ( ! mdoc_word_alloc(m, line, offs, buf+offs)) return(0); if (MDOC_LITERAL & m->flags) *************** *** 713,719 **** assert(buf < end); ! if (mandoc_eos(buf, (size_t)(end-buf))) m->last->flags |= MDOC_EOS; return(1); --- 716,722 ---- assert(buf < end); ! if (mandoc_eos(buf+offs, (size_t)(end-buf-offs))) m->last->flags |= MDOC_EOS; return(1); *************** *** 721,732 **** static int ! macrowarn(struct mdoc *m, int ln, const char *buf) { if ( ! (MDOC_IGN_MACRO & m->pflags)) ! return(mdoc_verr(m, ln, 0, "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); ! return(mdoc_vwarn(m, ln, 0, "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); } --- 724,735 ---- static int ! macrowarn(struct mdoc *m, int ln, const char *buf, int offs) { if ( ! (MDOC_IGN_MACRO & m->pflags)) ! return(mdoc_verr(m, ln, offs, "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); ! return(mdoc_vwarn(m, ln, offs, "unknown macro: %s%s", buf, strlen(buf) > 3 ? "..." : "")); } *************** *** 736,742 **** * character. */ int ! mdoc_pmacro(struct mdoc *m, int ln, char *buf) { enum mdoct tok; int i, j, sv; --- 739,745 ---- * character. */ int ! mdoc_pmacro(struct mdoc *m, int ln, char *buf, int offs) { enum mdoct tok; int i, j, sv; *************** *** 744,753 **** /* Empty lines are ignored. */ ! if ('\0' == buf[1]) return(1); ! i = 1; /* Accept whitespace after the initial control char. */ --- 747,758 ---- /* Empty lines are ignored. */ ! offs++; ! ! if ('\0' == buf[offs]) return(1); ! i = offs; /* Accept whitespace after the initial control char. */ *************** *** 776,791 **** return(mdoc_perr(m, ln, i, EPRINT)); } ! mac[j] = 0; if (j == 4 || j < 2) { ! if ( ! macrowarn(m, ln, mac)) goto err; return(1); } if (MDOC_MAX == (tok = mdoc_hash_find(mac))) { ! if ( ! macrowarn(m, ln, mac)) goto err; return(1); } --- 781,796 ---- return(mdoc_perr(m, ln, i, EPRINT)); } ! mac[j] = '\0'; if (j == 4 || j < 2) { ! if ( ! macrowarn(m, ln, mac, sv)) goto err; return(1); } if (MDOC_MAX == (tok = mdoc_hash_find(mac))) { ! if ( ! macrowarn(m, ln, mac, sv)) goto err; return(1); }