=================================================================== RCS file: /cvs/mandoc/man_macro.c,v retrieving revision 1.6 retrieving revision 1.14 diff -u -p -r1.6 -r1.14 --- mandoc/man_macro.c 2009/03/25 15:36:05 1.6 +++ mandoc/man_macro.c 2009/04/12 19:45:26 1.14 @@ -1,33 +1,58 @@ -/* $Id: man_macro.c,v 1.6 2009/03/25 15:36:05 kristaps Exp $ */ +/* $Id: man_macro.c,v 1.14 2009/04/12 19:45:26 kristaps Exp $ */ /* * Copyright (c) 2008, 2009 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 copyright notice and this permission notice appear in all - * copies. + * purpose with or without fee is hereby granted, provided that the above + * copyright notice and this permission notice appear in all copies. * - * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL - * WARRANTIES WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED - * WARRANTIES OF MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE - * AUTHOR BE LIABLE FOR ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL - * DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR - * PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER - * TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR - * PERFORMANCE OF THIS SOFTWARE. + * THE SOFTWARE IS PROVIDED "AS IS" AND THE AUTHOR DISCLAIMS ALL WARRANTIES + * WITH REGARD TO THIS SOFTWARE INCLUDING ALL IMPLIED WARRANTIES OF + * MERCHANTABILITY AND FITNESS. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR + * ANY SPECIAL, DIRECT, INDIRECT, OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES + * WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN + * ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF + * OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. */ #include #include -#include /* XXX */ #include -#include #include #include "libman.h" +#define FL_NLINE (1 << 0) +#define FL_TLINE (1 << 1) + static int man_args(struct man *, int, int *, char *, char **); +static int man_flags[MAN_MAX] = { + 0, /* __ */ + 0, /* TH */ + 0, /* SH */ + 0, /* SS */ + FL_TLINE, /* TP */ + 0, /* LP */ + 0, /* PP */ + 0, /* P */ + 0, /* IP */ + 0, /* HP */ + FL_NLINE, /* SM */ + FL_NLINE, /* SB */ + FL_NLINE, /* BI */ + FL_NLINE, /* IB */ + FL_NLINE, /* BR */ + FL_NLINE, /* RB */ + FL_NLINE, /* R */ + FL_NLINE, /* B */ + FL_NLINE, /* I */ + FL_NLINE, /* IR */ + FL_NLINE, /* RI */ + 0, /* br */ + 0, /* na */ + FL_NLINE, /* i */ +}; int man_macro(struct man *man, int tok, int line, @@ -56,8 +81,32 @@ man_macro(struct man *man, int tok, int line, man->next = MAN_NEXT_SIBLING; } - for ( ; man->last && man->last != n; - man->last = man->last->parent) { + if (n == man->last && (FL_NLINE & man_flags[tok])) { + if (MAN_NLINE & man->flags) + return(man_verr(man, line, ppos, + "next-line scope already open")); + man->flags |= MAN_NLINE; + return(1); + } + + if (FL_TLINE & man_flags[tok]) { + if (MAN_NLINE & man->flags) + return(man_verr(man, line, ppos, + "next-line scope already open")); + man->flags |= MAN_NLINE; + return(1); + } + + /* + * Note that when TH is pruned, we'll be back at the root, so + * make sure that we don't clobber as its sibling. + */ + + for ( ; man->last; man->last = man->last->parent) { + if (man->last == n) + break; + if (man->last->type == MAN_ROOT) + break; if ( ! man_valid_post(man)) return(0); if ( ! man_action_post(man)) @@ -66,13 +115,17 @@ man_macro(struct man *man, int tok, int line, assert(man->last); - if ( ! man_valid_post(man)) + /* + * Same here regarding whether we're back at the root. + */ + + if (man->last->type != MAN_ROOT && ! man_valid_post(man)) return(0); - if ( ! man_action_post(man)) + if (man->last->type != MAN_ROOT && ! man_action_post(man)) return(0); + if (man->last->type != MAN_ROOT) + man->next = MAN_NEXT_SIBLING; - man->next = MAN_NEXT_SIBLING; - return(1); } @@ -88,6 +141,7 @@ man_macroend(struct man *m) if ( ! man_action_post(m)) return(0); } + assert(m->last == m->first); if ( ! man_valid_post(m)) return(0); @@ -100,7 +154,7 @@ man_macroend(struct man *m) /* ARGSUSED */ static int -man_args(struct man *man, int line, +man_args(struct man *m, int line, int *pos, char *buf, char **v) { @@ -133,8 +187,10 @@ man_args(struct man *man, int line, if (buf[*pos]) return(1); - warnx("tail whitespace"); - return(-1); + if ( ! man_vwarn(m, line, *pos, "trailing spaces")) + return(-1); + + return(1); } /* @@ -149,8 +205,9 @@ man_args(struct man *man, int line, (*pos)++; if (0 == buf[*pos]) { - warnx("unterminated quotation"); - return(-1); + if ( ! man_vwarn(m, line, *pos, "unterminated quote")) + return(-1); + return(1); } buf[(*pos)++] = 0; @@ -163,6 +220,7 @@ man_args(struct man *man, int line, if (buf[*pos]) return(1); - warnx("tail whitespace"); - return(-1); + if ( ! man_vwarn(m, line, *pos, "trailing spaces")) + return(-1); + return(1); }