git: e441e0cf8ec9 - stable/13 - indent: Restore and document -ps / -nps option.

From: Dag-Erling Smørgrav <des_at_FreeBSD.org>
Date: Thu, 07 Sep 2023 14:51:00 UTC
The branch stable/13 has been updated by des:

URL: https://cgit.FreeBSD.org/src/commit/?id=e441e0cf8ec93e009249d0c978bee110797f313d

commit e441e0cf8ec93e009249d0c978bee110797f313d
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-09-07 08:56:23 +0000

    indent: Restore and document -ps / -nps option.
    
    Sponsored by:   Klara, Inc.
    Reviewed by:    pauamma_gundo.com, pstef, kevans
    Differential Revision:  https://reviews.freebsd.org/D40788
    
    (cherry picked from commit b5b9eaa96274a9c40b06999cadc777c8aeb71d09)
---
 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 c54c5b9fde5f..2f8ea7659128 100644
--- a/usr.bin/indent/args.c
+++ b/usr.bin/indent/args.c
@@ -153,12 +153,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 b6f10824c6f7..68c0fad2c021 100644
--- a/usr.bin/indent/indent.1
+++ b/usr.bin/indent/indent.1
@@ -29,7 +29,7 @@
 .\"
 .\"	@(#)indent.1	8.1 (Berkeley) 7/1/93
 .\"
-.Dd June 11, 2018
+.Dd June 28, 2023
 .Dt INDENT 1
 .Os
 .Sh NAME
@@ -77,6 +77,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
@@ -420,6 +421,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 ba2afefefd8e..640ba1bf48ec 100644
--- a/usr.bin/indent/indent_globs.h
+++ b/usr.bin/indent/indent_globs.h
@@ -199,6 +199,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 9fb7cf30afb7..7ad1ddc74fff 100644
--- a/usr.bin/indent/lexi.c
+++ b/usr.bin/indent/lexi.c
@@ -490,9 +490,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 57e7c4db71b1..2369999e268d 100644
--- a/usr.bin/indent/tests/Makefile
+++ b/usr.bin/indent/tests/Makefile
@@ -44,6 +44,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--;
+}