diff options
author | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-10-11 21:14:12 +0000 |
---|---|---|
committer | Ingo Schwarze <schwarze@cvs.openbsd.org> | 2014-10-11 21:14:12 +0000 |
commit | 2e415b96562e7d1c4902027fde487820751f92a3 (patch) | |
tree | 1841e12a884cb63c17dc3d7e615115c2a1f2888f | |
parent | bdbdf4be7a0e082ab3f80aa85bd45a0b03092c65 (diff) |
warn about parentheses in function names after .Fn and .Fo;
particularly useful when converting from other languages to mdoc(7);
feature suggested by bentley@
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Fo/Makefile | 6 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Fo/warn.in | 13 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Fo/warn.out_ascii | 13 | ||||
-rw-r--r-- | regress/usr.bin/mandoc/mdoc/Fo/warn.out_lint | 2 | ||||
-rw-r--r-- | usr.bin/mandoc/mandoc.h | 3 | ||||
-rw-r--r-- | usr.bin/mandoc/mdoc_validate.c | 31 | ||||
-rw-r--r-- | usr.bin/mandoc/read.c | 3 |
7 files changed, 64 insertions, 7 deletions
diff --git a/regress/usr.bin/mandoc/mdoc/Fo/Makefile b/regress/usr.bin/mandoc/mdoc/Fo/Makefile index 892440232e7..6a2ac068a77 100644 --- a/regress/usr.bin/mandoc/mdoc/Fo/Makefile +++ b/regress/usr.bin/mandoc/mdoc/Fo/Makefile @@ -1,7 +1,7 @@ -# $OpenBSD: Makefile,v 1.9 2014/07/02 20:18:42 schwarze Exp $ +# $OpenBSD: Makefile,v 1.10 2014/10/11 21:14:11 schwarze Exp $ -REGRESS_TARGETS = basic section break noarg font eos obsolete -LINT_TARGETS = noarg obsolete +REGRESS_TARGETS = basic break eos font noarg obsolete section warn +LINT_TARGETS = noarg obsolete warn # groff does not handle .nr nS diff --git a/regress/usr.bin/mandoc/mdoc/Fo/warn.in b/regress/usr.bin/mandoc/mdoc/Fo/warn.in new file mode 100644 index 00000000000..d41e658ce3b --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Fo/warn.in @@ -0,0 +1,13 @@ +.Dd October 11, 2014 +.Dt FO-WARN 1 +.Os OpenBSD +.Sh NAME +.Nm Fo-warn +.Nd warnings related to function blocks +.Sh SYNOPSIS +.Ft double +.Fo sin() +.Fa "double x" +.Fc +.Ft double +.Fn atan2 "double y, double x" diff --git a/regress/usr.bin/mandoc/mdoc/Fo/warn.out_ascii b/regress/usr.bin/mandoc/mdoc/Fo/warn.out_ascii new file mode 100644 index 00000000000..fd1890b560c --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Fo/warn.out_ascii @@ -0,0 +1,13 @@ +FO-WARN(1) General Commands Manual FO-WARN(1) + +NNAAMMEE + FFoo--wwaarrnn - warnings related to function blocks + +SSYYNNOOPPSSIISS + _d_o_u_b_l_e + ssiinn(())(_d_o_u_b_l_e _x); + + _d_o_u_b_l_e + aattaann22(_d_o_u_b_l_e _y_, _d_o_u_b_l_e _x); + +OpenBSD October 11, 2014 OpenBSD diff --git a/regress/usr.bin/mandoc/mdoc/Fo/warn.out_lint b/regress/usr.bin/mandoc/mdoc/Fo/warn.out_lint new file mode 100644 index 00000000000..09fc534fda3 --- /dev/null +++ b/regress/usr.bin/mandoc/mdoc/Fo/warn.out_lint @@ -0,0 +1,2 @@ +mandoc: warn.in:9:8: WARNING: parenthesis in function name: sin() +mandoc: warn.in:13:19: WARNING: comma in function argument: double y, double x diff --git a/usr.bin/mandoc/mandoc.h b/usr.bin/mandoc/mandoc.h index 161020e9b86..b2a531adfea 100644 --- a/usr.bin/mandoc/mandoc.h +++ b/usr.bin/mandoc/mandoc.h @@ -1,4 +1,4 @@ -/* $OpenBSD: mandoc.h,v 1.103 2014/10/10 15:25:06 schwarze Exp $ */ +/* $OpenBSD: mandoc.h,v 1.104 2014/10/11 21:14:11 schwarze Exp $ */ /* * Copyright (c) 2010, 2011, 2014 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -114,6 +114,7 @@ enum mandocerr { MANDOCERR_BL_SKIPW, /* skipping -width argument: Bl -type */ MANDOCERR_AT_BAD, /* unknown AT&T UNIX version: At version */ MANDOCERR_FA_COMMA, /* comma in function argument: arg */ + MANDOCERR_FN_PAREN, /* parenthesis in function name: arg */ MANDOCERR_RS_BAD, /* invalid content in Rs block: macro */ MANDOCERR_SM_BAD, /* invalid Boolean argument: macro arg */ MANDOCERR_FT_BAD, /* unknown font, skipping request: ft font */ diff --git a/usr.bin/mandoc/mdoc_validate.c b/usr.bin/mandoc/mdoc_validate.c index 2cc58af547e..acc44b3f45a 100644 --- a/usr.bin/mandoc/mdoc_validate.c +++ b/usr.bin/mandoc/mdoc_validate.c @@ -1,4 +1,4 @@ -/* $OpenBSD: mdoc_validate.c,v 1.166 2014/09/12 00:53:21 schwarze Exp $ */ +/* $OpenBSD: mdoc_validate.c,v 1.167 2014/10/11 21:14:11 schwarze Exp $ */ /* * Copyright (c) 2008-2012 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -100,6 +100,8 @@ static int post_es(POST_ARGS); static int post_eoln(POST_ARGS); static int post_ex(POST_ARGS); static int post_fa(POST_ARGS); +static int post_fn(POST_ARGS); +static int post_fname(POST_ARGS); static int post_fo(POST_ARGS); static int post_hyph(POST_ARGS); static int post_hyphtext(POST_ARGS); @@ -160,7 +162,7 @@ static const struct valids mdoc_valids[MDOC_MAX] = { { NULL, post_fa }, /* Fa */ { NULL, ewarn_ge1 }, /* Fd */ { NULL, NULL }, /* Fl */ - { NULL, post_fa }, /* Fn */ + { NULL, post_fn }, /* Fn */ { NULL, NULL }, /* Ft */ { NULL, NULL }, /* Ic */ { NULL, ewarn_eq1 }, /* In */ @@ -999,11 +1001,36 @@ post_eoln(POST_ARGS) } static int +post_fname(POST_ARGS) +{ + const struct mdoc_node *n; + size_t pos; + + n = mdoc->last->child; + pos = strcspn(n->string, "()"); + if (n->string[pos] != '\0') + mandoc_msg(MANDOCERR_FN_PAREN, mdoc->parse, + n->line, n->pos + pos, n->string); + return(1); +} + +static int +post_fn(POST_ARGS) +{ + + post_fname(mdoc); + post_fa(mdoc); + return(1); +} + +static int post_fo(POST_ARGS) { hwarn_eq1(mdoc); bwarn_ge1(mdoc); + if (mdoc->last->type == MDOC_HEAD) + post_fname(mdoc); return(1); } diff --git a/usr.bin/mandoc/read.c b/usr.bin/mandoc/read.c index 11e2b2a6ffc..70eaf3a2751 100644 --- a/usr.bin/mandoc/read.c +++ b/usr.bin/mandoc/read.c @@ -1,4 +1,4 @@ -/* $OpenBSD: read.c,v 1.64 2014/09/12 00:53:21 schwarze Exp $ */ +/* $OpenBSD: read.c,v 1.65 2014/10/11 21:14:11 schwarze Exp $ */ /* * Copyright (c) 2008, 2009, 2010, 2011 Kristaps Dzonsons <kristaps@bsd.lv> * Copyright (c) 2010-2014 Ingo Schwarze <schwarze@openbsd.org> @@ -153,6 +153,7 @@ static const char * const mandocerrs[MANDOCERR_MAX] = { "skipping -width argument", "unknown AT&T UNIX version", "comma in function argument", + "parenthesis in function name", "invalid content in Rs block", "invalid Boolean argument", "unknown font, skipping request", |