git: b5b9eaa96274 - main - Restore and document -ps / -nps option.
- Go to: [ bottom of page ] [ top of archives ] [ this month ]
Date: Thu, 29 Jun 2023 14:02:06 UTC
The branch main has been updated by des: URL: https://cgit.FreeBSD.org/src/commit/?id=b5b9eaa96274a9c40b06999cadc777c8aeb71d09 commit b5b9eaa96274a9c40b06999cadc777c8aeb71d09 Author: Dag-Erling Smørgrav <des@FreeBSD.org> AuthorDate: 2023-06-29 13:56:28 +0000 Commit: Dag-Erling Smørgrav <des@FreeBSD.org> CommitDate: 2023-06-29 13:59:49 +0000 Restore and document -ps / -nps option. Sponsored by: Klara, Inc. Reviewed by: pauamma_gundo.com, pstef, kevans Differential Revision: https://reviews.freebsd.org/D40788 --- usr.bin/indent/args.c | 2 ++ usr.bin/indent/indent.1 | 10 +++++++++- usr.bin/indent/indent_globs.h | 2 ++ usr.bin/indent/lexi.c | 8 +++++--- usr.bin/indent/tests/Makefile | 3 +++ usr.bin/indent/tests/ps.0 | 4 ++++ usr.bin/indent/tests/ps.0.pro | 1 + usr.bin/indent/tests/ps.0.stdout | 8 ++++++++ 8 files changed, 34 insertions(+), 4 deletions(-) diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c index 4d4cc32373a0..58ab9bf4b9f2 100644 --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -155,12 +155,14 @@ struct pro { {"npcs", PRO_BOOL, false, OFF, &opt.proc_calls_space}, {"npro", PRO_SPECIAL, 0, IGN, 0}, {"npsl", PRO_BOOL, true, OFF, &opt.procnames_start_line}, + {"nps", PRO_BOOL, false, OFF, &opt.pointer_as_binop}, {"nsc", PRO_BOOL, true, OFF, &opt.star_comment_cont}, {"nsob", PRO_BOOL, false, OFF, &opt.swallow_optional_blanklines}, {"nut", PRO_BOOL, true, OFF, &opt.use_tabs}, {"nv", PRO_BOOL, false, OFF, &opt.verbose}, {"pcs", PRO_BOOL, false, ON, &opt.proc_calls_space}, {"psl", PRO_BOOL, true, ON, &opt.procnames_start_line}, + {"ps", PRO_BOOL, false, ON, &opt.pointer_as_binop}, {"sc", PRO_BOOL, true, ON, &opt.star_comment_cont}, {"sob", PRO_BOOL, false, ON, &opt.swallow_optional_blanklines}, {"st", PRO_SPECIAL, 0, STDIN, 0}, diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1 index 04e8ad355e28..5a7ca371b0ae 100644 --- a/usr.bin/indent/indent.1 +++ b/usr.bin/indent/indent.1 @@ -30,7 +30,7 @@ .\" @(#)indent.1 8.1 (Berkeley) 7/1/93 .\" $FreeBSD$ .\" -.Dd June 11, 2018 +.Dd June 28, 2023 .Dt INDENT 1 .Os .Sh NAME @@ -78,6 +78,7 @@ .Op Fl npro .Op Fl P Ns Ar file .Op Fl pcs | Fl npcs +.Op Fl ps | Fl nps .Op Fl psl | Fl npsl .Op Fl \&sc | Fl nsc .Bk -words @@ -421,6 +422,13 @@ all procedure calls will have a space inserted between the name and the `('. The default is .Fl npcs . +.It Fl ps , nps +If true +.Pq Fl ps +the pointer dereference operator (`->') is treated like any other +binary operator. +The default is +.Fl nps . .It Fl psl , npsl If true .Pq Fl psl diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h index ffb70861f5d2..cadf442a2c98 100644 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -200,6 +200,8 @@ struct options { * lined-up code within the margin */ int lineup_to_parens; /* if true, continued code within parens * will be lined up to the open paren */ + int pointer_as_binop; /* if true, the pointer dereference operator + * will be treated as a binary operator */ int proc_calls_space; /* If true, procedure calls look like: * foo (bar) rather than foo(bar) */ int procnames_start_line; /* if true, the names of procedures diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index 83178a72b4f6..c47db6baead3 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -492,9 +492,11 @@ stop_lit: else if (*buf_ptr == '>') { /* check for operator -> */ *e_token++ = *buf_ptr++; - unary_delim = false; - code = unary_op; - state->want_blank = false; + if (!opt.pointer_as_binop) { + unary_delim = false; + code = unary_op; + state->want_blank = false; + } } break; /* buffer overflow will be checked at end of * switch */ diff --git a/usr.bin/indent/tests/Makefile b/usr.bin/indent/tests/Makefile index ede9e5ab246c..b9d208cb8285 100644 --- a/usr.bin/indent/tests/Makefile +++ b/usr.bin/indent/tests/Makefile @@ -45,6 +45,9 @@ ${PACKAGE}FILES+= types_from_file.0.list ${PACKAGE}FILES+= types_from_file.0.pro ${PACKAGE}FILES+= wchar.0 ${PACKAGE}FILES+= wchar.0.stdout +${PACKAGE}FILES+= ps.0 +${PACKAGE}FILES+= ps.0.stdout +${PACKAGE}FILES+= ps.0.pro ATF_TESTS_SH+= functional_test diff --git a/usr.bin/indent/tests/ps.0 b/usr.bin/indent/tests/ps.0 new file mode 100644 index 000000000000..0dc72ccfddf2 --- /dev/null +++ b/usr.bin/indent/tests/ps.0 @@ -0,0 +1,4 @@ +struct s { int i; }; +void f(struct s *p) { + p->i--; +} diff --git a/usr.bin/indent/tests/ps.0.pro b/usr.bin/indent/tests/ps.0.pro new file mode 100644 index 000000000000..5fdebee73785 --- /dev/null +++ b/usr.bin/indent/tests/ps.0.pro @@ -0,0 +1 @@ +-ps diff --git a/usr.bin/indent/tests/ps.0.stdout b/usr.bin/indent/tests/ps.0.stdout new file mode 100644 index 000000000000..08f421e984ff --- /dev/null +++ b/usr.bin/indent/tests/ps.0.stdout @@ -0,0 +1,8 @@ +struct s { + int i; +}; +void +f(struct s *p) +{ + p -> i--; +}