diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -155,12 +155,14 @@ {"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 --- 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 @@ 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 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -200,6 +200,8 @@ * 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 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -492,9 +492,11 @@ 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 --- a/usr.bin/indent/tests/Makefile +++ b/usr.bin/indent/tests/Makefile @@ -45,6 +45,9 @@ ${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 --- /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 --- /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 --- /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--; +}