diff options
-rw-r--r-- | usr.bin/mandoc/libmdoc.h | 8 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_argv.c | 43 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_macro.c | 6 |
3 files changed, 38 insertions, 19 deletions
diff --git a/usr.bin/mandoc/libmdoc.h b/usr.bin/mandoc/libmdoc.h index 0cb7626f863..e8c4ac6abea 100644 --- a/usr.bin/mandoc/libmdoc.h +++ b/usr.bin/mandoc/libmdoc.h @@ -1,4 +1,4 @@ -/* $Id: libmdoc.h,v 1.19 2009/08/22 21:55:06 schwarze Exp $ */ +/* $Id: libmdoc.h,v 1.20 2009/08/22 22:39:55 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -171,14 +171,16 @@ void mdoc_argv_free(struct mdoc_arg *); int mdoc_args(struct mdoc *, int, int *, char *, int, char **); int mdoc_zargs(struct mdoc *, int, - int *, char *, char **); + int *, char *, int, char **); +#define ARGS_DELIM (1 << 1) /* See args(). */ +#define ARGS_TABSEP (1 << 2) /* See args(). */ +#define ARGS_NOWARN (1 << 3) /* See args(). */ #define ARGS_ERROR (-1) #define ARGS_EOLN (0) #define ARGS_WORD (1) #define ARGS_PUNCT (2) #define ARGS_QWORD (3) #define ARGS_PHRASE (4) - int mdoc_macroend(struct mdoc *); __END_DECLS diff --git a/usr.bin/mandoc/mdoc_argv.c b/usr.bin/mandoc/mdoc_argv.c index c269cb865b7..440ee702e9b 100644 --- a/usr.bin/mandoc/mdoc_argv.c +++ b/usr.bin/mandoc/mdoc_argv.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_argv.c,v 1.12 2009/07/26 22:48:41 schwarze Exp $ */ +/* $Id: mdoc_argv.c,v 1.13 2009/08/22 22:39:55 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -32,11 +32,6 @@ * There's no limit to the number or arguments that may be allocated. */ -/* FIXME .Bf Li raises "macro-like parameter". */ - -#define ARGS_DELIM (1 << 1) -#define ARGS_TABSEP (1 << 2) - #define ARGV_NONE (1 << 0) #define ARGV_SINGLE (1 << 1) #define ARGV_MULTI (1 << 2) @@ -327,10 +322,11 @@ mdoc_argv_free(struct mdoc_arg *p) int -mdoc_zargs(struct mdoc *m, int line, int *pos, char *buf, char **v) +mdoc_zargs(struct mdoc *m, int line, int *pos, + char *buf, int flags, char **v) { - return(args(m, line, pos, buf, 0, v)); + return(args(m, line, pos, buf, flags, v)); } @@ -379,6 +375,21 @@ args(struct mdoc *m, int line, int *pos, int i; char *p, *pp; + /* + * Parse out the terms (like `val' in `.Xx -arg val' or simply + * `.Xx val'), which can have all sorts of properties: + * + * ARGS_DELIM: use special handling if encountering trailing + * delimiters in the form of [[::delim::][ ]+]+. + * + * ARGS_NOWARN: don't post warnings. This is only used when + * re-parsing delimiters, as the warnings have already been + * posted. + * + * ARGS_TABSEP: use special handling for tab/`Ta' separated + * phrases like in `Bl -column'. + */ + assert(*pos); assert(' ' != buf[*pos]); @@ -403,10 +414,14 @@ args(struct mdoc *m, int line, int *pos, i++; } - /* FIXME: warn about trailing whitespace. */ - if (0 == buf[i]) { *v = &buf[*pos]; + if (' ' != buf[i - 1]) + return(ARGS_PUNCT); + if (ARGS_NOWARN & fl) + return(ARGS_PUNCT); + if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) + return(ARGS_ERROR); return(ARGS_PUNCT); } } @@ -450,7 +465,7 @@ args(struct mdoc *m, int line, int *pos, p = strchr(*v, 0); /* Whitespace check for eoln case... */ - if (0 == *p && ' ' == *(p - 1)) + if (0 == *p && ' ' == *(p - 1) && ! (ARGS_NOWARN & fl)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); @@ -490,6 +505,8 @@ args(struct mdoc *m, int line, int *pos, } if (0 == buf[*pos]) { + if (ARGS_NOWARN & fl) + return(ARGS_QWORD); if ( ! mdoc_pwarn(m, line, *pos, EQUOTTERM)) return(ARGS_ERROR); return(ARGS_QWORD); @@ -503,7 +520,7 @@ args(struct mdoc *m, int line, int *pos, while (' ' == buf[*pos]) (*pos)++; - if (0 == buf[*pos]) + if (0 == buf[*pos] && ! (ARGS_NOWARN & fl)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); @@ -527,7 +544,7 @@ args(struct mdoc *m, int line, int *pos, while (' ' == buf[*pos]) (*pos)++; - if (0 == buf[*pos]) + if (0 == buf[*pos] && ! (ARGS_NOWARN & fl)) if ( ! mdoc_pwarn(m, line, *pos, ETAILWS)) return(ARGS_ERROR); diff --git a/usr.bin/mandoc/mdoc_macro.c b/usr.bin/mandoc/mdoc_macro.c index ceacf896dc4..a3989b9dbde 100644 --- a/usr.bin/mandoc/mdoc_macro.c +++ b/usr.bin/mandoc/mdoc_macro.c @@ -1,4 +1,4 @@ -/* $Id: mdoc_macro.c,v 1.22 2009/08/22 21:55:06 schwarze Exp $ */ +/* $Id: mdoc_macro.c,v 1.23 2009/08/22 22:39:55 schwarze Exp $ */ /* * Copyright (c) 2008, 2009 Kristaps Dzonsons <kristaps@kth.se> * @@ -600,7 +600,7 @@ append_delims(struct mdoc *mdoc, int line, int *pos, char *buf) for (;;) { lastarg = *pos; - c = mdoc_args(mdoc, line, pos, buf, 0, &p); + c = mdoc_zargs(mdoc, line, pos, buf, ARGS_NOWARN, &p); assert(ARGS_PHRASE != c); if (ARGS_ERROR == c) @@ -1326,7 +1326,7 @@ phrase(struct mdoc *m, int line, int ppos, char *buf) la = pos; /* Note: no calling context! */ - w = mdoc_zargs(m, line, &pos, buf, &p); + w = mdoc_zargs(m, line, &pos, buf, 0, &p); if (ARGS_ERROR == w) return(0); |