Module Name: src Committed By: rillig Date: Mon Oct 18 22:30:35 UTC 2021
Modified Files: src/distrib/sets/lists/tests: mi src/tests/usr.bin/indent: Makefile token_comment.c Added Files: src/tests/usr.bin/indent: token_binary_op.c token_case_label.c token_colon.c token_comma.c token_decl.c token_do_stmt.c token_end_of_file.c token_for_exprs.c token_form_feed.c token_funcname.c token_if_expr.c token_if_expr_stmt.c token_if_expr_stmt_else.c token_keyword_do.c token_keyword_do_else.c token_keyword_else.c token_keyword_for_if_while.c token_keyword_struct_union_enum.c token_lbrace.c token_lparen.c token_newline.c token_period.c token_postfix_op.c token_preprocessing.c token_question.c token_rbrace.c token_rparen.c token_semicolon.c token_stmt.c token_stmt_list.c token_storage_class.c token_string_prefix.c token_switch_expr.c token_type_def.c token_unary_op.c token_while_expr.c Removed Files: src/tests/usr.bin/indent: token-binary_op.0 token-binary_op.0.pro token-binary_op.0.stdout token-case_label.0 token-case_label.0.pro token-case_label.0.stdout token-colon.0 token-colon.0.pro token-colon.0.stdout token-comma.0 token-comma.0.pro token-comma.0.stdout token-decl.0 token-decl.0.pro token-decl.0.stdout token-do_stmt.0 token-do_stmt.0.pro token-do_stmt.0.stdout token-end_of_file.0 token-end_of_file.0.pro token-end_of_file.0.stdout token-for_exprs.0 token-for_exprs.0.pro token-for_exprs.0.stdout token-form_feed.0 token-form_feed.0.pro token-form_feed.0.stdout token-funcname.0 token-funcname.0.pro token-funcname.0.stdout token-if_expr.0 token-if_expr.0.pro token-if_expr.0.stdout token-if_expr_stmt.0 token-if_expr_stmt.0.pro token-if_expr_stmt.0.stdout token-if_expr_stmt_else.0 token-if_expr_stmt_else.0.pro token-if_expr_stmt_else.0.stdout token-keyword_do.0 token-keyword_do.0.pro token-keyword_do.0.stdout token-keyword_do_else.0 token-keyword_do_else.0.pro token-keyword_do_else.0.stdout token-keyword_else.0 token-keyword_else.0.pro token-keyword_else.0.stdout token-keyword_for_if_while.0 token-keyword_for_if_while.0.pro token-keyword_for_if_while.0.stdout token-keyword_struct_union_enum.0 token-keyword_struct_union_enum.0.pro token-keyword_struct_union_enum.0.stdout token-lbrace.0 token-lbrace.0.pro token-lbrace.0.stdout token-lparen.0 token-lparen.0.pro token-lparen.0.stdout token-newline.0 token-newline.0.pro token-newline.0.stdout token-period.0 token-period.0.pro token-period.0.stdout token-postfix_op.0 token-postfix_op.0.pro token-postfix_op.0.stdout token-preprocessing.0 token-preprocessing.0.pro token-preprocessing.0.stdout token-question.0 token-question.0.pro token-question.0.stdout token-rbrace.0 token-rbrace.0.pro token-rbrace.0.stdout token-rparen.0 token-rparen.0.pro token-rparen.0.stdout token-semicolon.0 token-semicolon.0.pro token-semicolon.0.stdout token-stmt.0 token-stmt.0.pro token-stmt.0.stdout token-stmt_list.0 token-stmt_list.0.pro token-stmt_list.0.stdout token-storage_class.0 token-storage_class.0.pro token-storage_class.0.stdout token-string_prefix.0 token-string_prefix.0.pro token-string_prefix.0.stdout token-switch_expr.0 token-switch_expr.0.pro token-switch_expr.0.stdout token-type_def.0 token-type_def.0.pro token-type_def.0.stdout token-unary_op.0 token-unary_op.0.pro token-unary_op.0.stdout token-while_expr.0 token-while_expr.0.pro token-while_expr.0.stdout Log Message: tests/indent: condense the token tests This reduces the number of files in the test directory. It also allows the tests to be read from top to bottom, looking at only a single file. Since t_options.awk complains about files that don't have any test case at all, add some test for each token kind. Most of the tests had previously been effectively empty. To generate a diff of this commit: cvs rdiff -u -r1.1144 -r1.1145 src/distrib/sets/lists/tests/mi cvs rdiff -u -r1.19 -r1.20 src/tests/usr.bin/indent/Makefile cvs rdiff -u -r1.2 -r0 src/tests/usr.bin/indent/token-binary_op.0 \ src/tests/usr.bin/indent/token-binary_op.0.pro \ src/tests/usr.bin/indent/token-binary_op.0.stdout \ src/tests/usr.bin/indent/token-colon.0 \ src/tests/usr.bin/indent/token-colon.0.stdout \ src/tests/usr.bin/indent/token-keyword_do_else.0.stdout \ src/tests/usr.bin/indent/token-keyword_else.0 \ src/tests/usr.bin/indent/token-keyword_else.0.stdout \ src/tests/usr.bin/indent/token-lparen.0.pro \ src/tests/usr.bin/indent/token-while_expr.0 \ src/tests/usr.bin/indent/token-while_expr.0.stdout cvs rdiff -u -r1.1 -r0 src/tests/usr.bin/indent/token-case_label.0 \ src/tests/usr.bin/indent/token-case_label.0.pro \ src/tests/usr.bin/indent/token-case_label.0.stdout \ src/tests/usr.bin/indent/token-colon.0.pro \ src/tests/usr.bin/indent/token-comma.0 \ src/tests/usr.bin/indent/token-comma.0.pro \ src/tests/usr.bin/indent/token-comma.0.stdout \ src/tests/usr.bin/indent/token-decl.0 \ src/tests/usr.bin/indent/token-decl.0.pro \ src/tests/usr.bin/indent/token-decl.0.stdout \ src/tests/usr.bin/indent/token-do_stmt.0 \ src/tests/usr.bin/indent/token-do_stmt.0.pro \ src/tests/usr.bin/indent/token-do_stmt.0.stdout \ src/tests/usr.bin/indent/token-end_of_file.0 \ src/tests/usr.bin/indent/token-end_of_file.0.pro \ src/tests/usr.bin/indent/token-end_of_file.0.stdout \ src/tests/usr.bin/indent/token-for_exprs.0 \ src/tests/usr.bin/indent/token-for_exprs.0.pro \ src/tests/usr.bin/indent/token-for_exprs.0.stdout \ src/tests/usr.bin/indent/token-form_feed.0 \ src/tests/usr.bin/indent/token-form_feed.0.pro \ src/tests/usr.bin/indent/token-form_feed.0.stdout \ src/tests/usr.bin/indent/token-funcname.0 \ src/tests/usr.bin/indent/token-funcname.0.pro \ src/tests/usr.bin/indent/token-funcname.0.stdout \ src/tests/usr.bin/indent/token-if_expr.0 \ src/tests/usr.bin/indent/token-if_expr.0.pro \ src/tests/usr.bin/indent/token-if_expr.0.stdout \ src/tests/usr.bin/indent/token-if_expr_stmt.0 \ src/tests/usr.bin/indent/token-if_expr_stmt.0.pro \ src/tests/usr.bin/indent/token-if_expr_stmt.0.stdout \ src/tests/usr.bin/indent/token-if_expr_stmt_else.0 \ src/tests/usr.bin/indent/token-if_expr_stmt_else.0.pro \ src/tests/usr.bin/indent/token-if_expr_stmt_else.0.stdout \ src/tests/usr.bin/indent/token-keyword_do.0 \ src/tests/usr.bin/indent/token-keyword_do.0.pro \ src/tests/usr.bin/indent/token-keyword_do.0.stdout \ src/tests/usr.bin/indent/token-keyword_do_else.0 \ src/tests/usr.bin/indent/token-keyword_do_else.0.pro \ src/tests/usr.bin/indent/token-keyword_else.0.pro \ src/tests/usr.bin/indent/token-keyword_for_if_while.0 \ src/tests/usr.bin/indent/token-keyword_for_if_while.0.pro \ src/tests/usr.bin/indent/token-keyword_for_if_while.0.stdout \ src/tests/usr.bin/indent/token-keyword_struct_union_enum.0 \ src/tests/usr.bin/indent/token-keyword_struct_union_enum.0.pro \ src/tests/usr.bin/indent/token-keyword_struct_union_enum.0.stdout \ src/tests/usr.bin/indent/token-lbrace.0 \ src/tests/usr.bin/indent/token-lbrace.0.pro \ src/tests/usr.bin/indent/token-lbrace.0.stdout \ src/tests/usr.bin/indent/token-newline.0 \ src/tests/usr.bin/indent/token-newline.0.pro \ src/tests/usr.bin/indent/token-newline.0.stdout \ src/tests/usr.bin/indent/token-period.0 \ src/tests/usr.bin/indent/token-period.0.pro \ src/tests/usr.bin/indent/token-period.0.stdout \ src/tests/usr.bin/indent/token-postfix_op.0 \ src/tests/usr.bin/indent/token-postfix_op.0.pro \ src/tests/usr.bin/indent/token-postfix_op.0.stdout \ src/tests/usr.bin/indent/token-preprocessing.0.pro \ src/tests/usr.bin/indent/token-question.0 \ src/tests/usr.bin/indent/token-question.0.pro \ src/tests/usr.bin/indent/token-question.0.stdout \ src/tests/usr.bin/indent/token-rbrace.0 \ src/tests/usr.bin/indent/token-rbrace.0.pro \ src/tests/usr.bin/indent/token-rbrace.0.stdout \ src/tests/usr.bin/indent/token-rparen.0 \ src/tests/usr.bin/indent/token-rparen.0.pro \ src/tests/usr.bin/indent/token-rparen.0.stdout \ src/tests/usr.bin/indent/token-semicolon.0 \ src/tests/usr.bin/indent/token-semicolon.0.pro \ src/tests/usr.bin/indent/token-semicolon.0.stdout \ src/tests/usr.bin/indent/token-stmt.0 \ src/tests/usr.bin/indent/token-stmt.0.pro \ src/tests/usr.bin/indent/token-stmt.0.stdout \ src/tests/usr.bin/indent/token-stmt_list.0 \ src/tests/usr.bin/indent/token-stmt_list.0.pro \ src/tests/usr.bin/indent/token-stmt_list.0.stdout \ src/tests/usr.bin/indent/token-storage_class.0 \ src/tests/usr.bin/indent/token-storage_class.0.pro \ src/tests/usr.bin/indent/token-storage_class.0.stdout \ src/tests/usr.bin/indent/token-string_prefix.0 \ src/tests/usr.bin/indent/token-string_prefix.0.pro \ src/tests/usr.bin/indent/token-string_prefix.0.stdout \ src/tests/usr.bin/indent/token-switch_expr.0 \ src/tests/usr.bin/indent/token-switch_expr.0.pro \ src/tests/usr.bin/indent/token-switch_expr.0.stdout \ src/tests/usr.bin/indent/token-type_def.0 \ src/tests/usr.bin/indent/token-type_def.0.pro \ src/tests/usr.bin/indent/token-type_def.0.stdout \ src/tests/usr.bin/indent/token-unary_op.0 \ src/tests/usr.bin/indent/token-unary_op.0.pro \ src/tests/usr.bin/indent/token-unary_op.0.stdout \ src/tests/usr.bin/indent/token-while_expr.0.pro cvs rdiff -u -r1.3 -r0 src/tests/usr.bin/indent/token-lparen.0 cvs rdiff -u -r1.5 -r0 src/tests/usr.bin/indent/token-lparen.0.stdout cvs rdiff -u -r1.6 -r0 src/tests/usr.bin/indent/token-preprocessing.0 cvs rdiff -u -r1.8 -r0 src/tests/usr.bin/indent/token-preprocessing.0.stdout cvs rdiff -u -r0 -r1.1 src/tests/usr.bin/indent/token_binary_op.c \ src/tests/usr.bin/indent/token_case_label.c \ src/tests/usr.bin/indent/token_colon.c \ src/tests/usr.bin/indent/token_comma.c \ src/tests/usr.bin/indent/token_decl.c \ src/tests/usr.bin/indent/token_do_stmt.c \ src/tests/usr.bin/indent/token_end_of_file.c \ src/tests/usr.bin/indent/token_for_exprs.c \ src/tests/usr.bin/indent/token_form_feed.c \ src/tests/usr.bin/indent/token_funcname.c \ src/tests/usr.bin/indent/token_if_expr.c \ src/tests/usr.bin/indent/token_if_expr_stmt.c \ src/tests/usr.bin/indent/token_if_expr_stmt_else.c \ src/tests/usr.bin/indent/token_keyword_do.c \ src/tests/usr.bin/indent/token_keyword_do_else.c \ src/tests/usr.bin/indent/token_keyword_else.c \ src/tests/usr.bin/indent/token_keyword_for_if_while.c \ src/tests/usr.bin/indent/token_keyword_struct_union_enum.c \ src/tests/usr.bin/indent/token_lbrace.c \ src/tests/usr.bin/indent/token_lparen.c \ src/tests/usr.bin/indent/token_newline.c \ src/tests/usr.bin/indent/token_period.c \ src/tests/usr.bin/indent/token_postfix_op.c \ src/tests/usr.bin/indent/token_preprocessing.c \ src/tests/usr.bin/indent/token_question.c \ src/tests/usr.bin/indent/token_rbrace.c \ src/tests/usr.bin/indent/token_rparen.c \ src/tests/usr.bin/indent/token_semicolon.c \ src/tests/usr.bin/indent/token_stmt.c \ src/tests/usr.bin/indent/token_stmt_list.c \ src/tests/usr.bin/indent/token_storage_class.c \ src/tests/usr.bin/indent/token_string_prefix.c \ src/tests/usr.bin/indent/token_switch_expr.c \ src/tests/usr.bin/indent/token_type_def.c \ src/tests/usr.bin/indent/token_unary_op.c \ src/tests/usr.bin/indent/token_while_expr.c cvs rdiff -u -r1.1 -r1.2 src/tests/usr.bin/indent/token_comment.c Please note that diffs are not public domain; they are subject to the copyright notices on the relevant files.
Modified files: Index: src/distrib/sets/lists/tests/mi diff -u src/distrib/sets/lists/tests/mi:1.1144 src/distrib/sets/lists/tests/mi:1.1145 --- src/distrib/sets/lists/tests/mi:1.1144 Mon Oct 18 20:18:00 2021 +++ src/distrib/sets/lists/tests/mi Mon Oct 18 22:30:34 2021 @@ -1,4 +1,4 @@ -# $NetBSD: mi,v 1.1144 2021/10/18 20:18:00 rillig Exp $ +# $NetBSD: mi,v 1.1145 2021/10/18 22:30:34 rillig Exp $ # # Note: don't delete entries from here - mark them as "obsolete" instead. # @@ -5036,120 +5036,120 @@ ./usr/tests/usr.bin/indent/t_misc tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/t_options tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/t_options.awk tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-binary_op.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-binary_op.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-binary_op.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-case_label.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-case_label.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-case_label.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-colon.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-colon.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-colon.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-comma.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-comma.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-comma.0.stdout tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/token-binary_op.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-binary_op.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-binary_op.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-case_label.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-case_label.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-case_label.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-colon.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-colon.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-colon.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-comma.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-comma.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-comma.0.stdout tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token-comment.0 tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token-comment.0.pro tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token-comment.0.stdout tests-obsolete obsolete,atf -./usr/tests/usr.bin/indent/token-decl.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-decl.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-decl.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-do_stmt.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-do_stmt.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-do_stmt.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-end_of_file.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-end_of_file.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-end_of_file.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-for_exprs.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-for_exprs.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-for_exprs.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-form_feed.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-form_feed.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-form_feed.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-funcname.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-funcname.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-funcname.0.stdout tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/token-decl.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-decl.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-decl.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-do_stmt.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-do_stmt.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-do_stmt.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-end_of_file.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-end_of_file.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-end_of_file.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-for_exprs.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-for_exprs.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-for_exprs.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-form_feed.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-form_feed.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-form_feed.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-funcname.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-funcname.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-funcname.0.stdout tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token-ident.0 tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token-ident.0.pro tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token-ident.0.stdout tests-obsolete obsolete,atf -./usr/tests/usr.bin/indent/token-if_expr.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr_stmt.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr_stmt.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr_stmt.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr_stmt_else.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr_stmt_else.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-if_expr_stmt_else.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_do.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_do.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_do.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_do_else.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_do_else.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_do_else.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_else.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_else.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_else.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_for_if_while.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_for_if_while.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_for_if_while.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_struct_union_enum.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_struct_union_enum.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-keyword_struct_union_enum.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-lbrace.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-lbrace.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-lbrace.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-lparen.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-lparen.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-lparen.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-newline.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-newline.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-newline.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-period.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-period.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-period.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-postfix_op.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-postfix_op.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-postfix_op.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-preprocessing.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-preprocessing.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-preprocessing.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-question.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-question.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-question.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-rbrace.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-rbrace.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-rbrace.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-rparen.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-rparen.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-rparen.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-semicolon.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-semicolon.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-semicolon.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-stmt.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-stmt.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-stmt.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-stmt_list.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-stmt_list.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-stmt_list.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-storage_class.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-storage_class.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-storage_class.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-string_prefix.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-string_prefix.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-string_prefix.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-switch_expr.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-switch_expr.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-switch_expr.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-type_def.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-type_def.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-type_def.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-unary_op.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-unary_op.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-unary_op.0.stdout tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-while_expr.0 tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-while_expr.0.pro tests-usr.bin-tests compattestfile,atf -./usr/tests/usr.bin/indent/token-while_expr.0.stdout tests-usr.bin-tests compattestfile,atf +./usr/tests/usr.bin/indent/token-if_expr.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr_stmt.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr_stmt.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr_stmt.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr_stmt_else.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr_stmt_else.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-if_expr_stmt_else.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_do.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_do.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_do.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_do_else.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_do_else.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_do_else.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_else.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_else.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_else.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_for_if_while.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_for_if_while.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_for_if_while.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_struct_union_enum.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_struct_union_enum.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-keyword_struct_union_enum.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-lbrace.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-lbrace.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-lbrace.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-lparen.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-lparen.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-lparen.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-newline.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-newline.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-newline.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-period.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-period.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-period.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-postfix_op.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-postfix_op.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-postfix_op.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-preprocessing.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-preprocessing.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-preprocessing.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-question.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-question.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-question.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-rbrace.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-rbrace.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-rbrace.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-rparen.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-rparen.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-rparen.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-semicolon.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-semicolon.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-semicolon.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-stmt.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-stmt.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-stmt.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-stmt_list.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-stmt_list.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-stmt_list.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-storage_class.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-storage_class.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-storage_class.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-string_prefix.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-string_prefix.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-string_prefix.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-switch_expr.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-switch_expr.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-switch_expr.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-type_def.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-type_def.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-type_def.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-unary_op.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-unary_op.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-unary_op.0.stdout tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-while_expr.0 tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-while_expr.0.pro tests-obsolete obsolete,atf +./usr/tests/usr.bin/indent/token-while_expr.0.stdout tests-obsolete obsolete,atf ./usr/tests/usr.bin/indent/token_comment.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/token_ident.c tests-usr.bin-tests compattestfile,atf ./usr/tests/usr.bin/indent/types_from_file.0 tests-usr.bin-tests compattestfile,atf Index: src/tests/usr.bin/indent/Makefile diff -u src/tests/usr.bin/indent/Makefile:1.19 src/tests/usr.bin/indent/Makefile:1.20 --- src/tests/usr.bin/indent/Makefile:1.19 Mon Oct 18 20:18:00 2021 +++ src/tests/usr.bin/indent/Makefile Mon Oct 18 22:30:34 2021 @@ -1,4 +1,4 @@ -# $NetBSD: Makefile,v 1.19 2021/10/18 20:18:00 rillig Exp $ +# $NetBSD: Makefile,v 1.20 2021/10/18 22:30:34 rillig Exp $ .include <bsd.own.mk> @@ -146,116 +146,44 @@ FILES+= surplusbad.0 FILES+= surplusbad.0.stdout FILES+= surplusbad.0.pro FILES+= t_options.awk -FILES+= token-binary_op.0 -FILES+= token-binary_op.0.pro -FILES+= token-binary_op.0.stdout -FILES+= token-case_label.0 -FILES+= token-case_label.0.pro -FILES+= token-case_label.0.stdout -FILES+= token-colon.0 -FILES+= token-colon.0.pro -FILES+= token-colon.0.stdout -FILES+= token-comma.0 -FILES+= token-comma.0.pro -FILES+= token-comma.0.stdout -FILES+= token-decl.0 -FILES+= token-decl.0.pro -FILES+= token-decl.0.stdout -FILES+= token-do_stmt.0 -FILES+= token-do_stmt.0.pro -FILES+= token-do_stmt.0.stdout -FILES+= token-end_of_file.0 -FILES+= token-end_of_file.0.pro -FILES+= token-end_of_file.0.stdout -FILES+= token-for_exprs.0 -FILES+= token-for_exprs.0.pro -FILES+= token-for_exprs.0.stdout -FILES+= token-form_feed.0 -FILES+= token-form_feed.0.pro -FILES+= token-form_feed.0.stdout -FILES+= token-funcname.0 -FILES+= token-funcname.0.pro -FILES+= token-funcname.0.stdout -FILES+= token-if_expr.0 -FILES+= token-if_expr.0.pro -FILES+= token-if_expr.0.stdout -FILES+= token-if_expr_stmt.0 -FILES+= token-if_expr_stmt.0.pro -FILES+= token-if_expr_stmt.0.stdout -FILES+= token-if_expr_stmt_else.0 -FILES+= token-if_expr_stmt_else.0.pro -FILES+= token-if_expr_stmt_else.0.stdout -FILES+= token-keyword_do.0 -FILES+= token-keyword_do.0.pro -FILES+= token-keyword_do.0.stdout -FILES+= token-keyword_do_else.0 -FILES+= token-keyword_do_else.0.pro -FILES+= token-keyword_do_else.0.stdout -FILES+= token-keyword_else.0 -FILES+= token-keyword_else.0.pro -FILES+= token-keyword_else.0.stdout -FILES+= token-keyword_for_if_while.0 -FILES+= token-keyword_for_if_while.0.pro -FILES+= token-keyword_for_if_while.0.stdout -FILES+= token-keyword_struct_union_enum.0 -FILES+= token-keyword_struct_union_enum.0.pro -FILES+= token-keyword_struct_union_enum.0.stdout -FILES+= token-lbrace.0 -FILES+= token-lbrace.0.pro -FILES+= token-lbrace.0.stdout -FILES+= token-lparen.0 -FILES+= token-lparen.0.pro -FILES+= token-lparen.0.stdout -FILES+= token-newline.0 -FILES+= token-newline.0.pro -FILES+= token-newline.0.stdout -FILES+= token-period.0 -FILES+= token-period.0.pro -FILES+= token-period.0.stdout -FILES+= token-postfix_op.0 -FILES+= token-postfix_op.0.pro -FILES+= token-postfix_op.0.stdout -FILES+= token-preprocessing.0 -FILES+= token-preprocessing.0.pro -FILES+= token-preprocessing.0.stdout -FILES+= token-question.0 -FILES+= token-question.0.pro -FILES+= token-question.0.stdout -FILES+= token-rbrace.0 -FILES+= token-rbrace.0.pro -FILES+= token-rbrace.0.stdout -FILES+= token-rparen.0 -FILES+= token-rparen.0.pro -FILES+= token-rparen.0.stdout -FILES+= token-semicolon.0 -FILES+= token-semicolon.0.pro -FILES+= token-semicolon.0.stdout -FILES+= token-stmt.0 -FILES+= token-stmt.0.pro -FILES+= token-stmt.0.stdout -FILES+= token-stmt_list.0 -FILES+= token-stmt_list.0.pro -FILES+= token-stmt_list.0.stdout -FILES+= token-storage_class.0 -FILES+= token-storage_class.0.pro -FILES+= token-storage_class.0.stdout -FILES+= token-string_prefix.0 -FILES+= token-string_prefix.0.pro -FILES+= token-string_prefix.0.stdout -FILES+= token-switch_expr.0 -FILES+= token-switch_expr.0.pro -FILES+= token-switch_expr.0.stdout -FILES+= token-type_def.0 -FILES+= token-type_def.0.pro -FILES+= token-type_def.0.stdout -FILES+= token-unary_op.0 -FILES+= token-unary_op.0.pro -FILES+= token-unary_op.0.stdout -FILES+= token-while_expr.0 -FILES+= token-while_expr.0.pro -FILES+= token-while_expr.0.stdout +FILES+= token_binary_op.c +FILES+= token_case_label.c +FILES+= token_colon.c +FILES+= token_comma.c FILES+= token_comment.c +FILES+= token_decl.c +FILES+= token_do_stmt.c +FILES+= token_end_of_file.c +FILES+= token_for_exprs.c +FILES+= token_form_feed.c +FILES+= token_funcname.c FILES+= token_ident.c +FILES+= token_if_expr.c +FILES+= token_if_expr_stmt.c +FILES+= token_if_expr_stmt_else.c +FILES+= token_keyword_do.c +FILES+= token_keyword_do_else.c +FILES+= token_keyword_else.c +FILES+= token_keyword_for_if_while.c +FILES+= token_keyword_struct_union_enum.c +FILES+= token_lbrace.c +FILES+= token_lparen.c +FILES+= token_newline.c +FILES+= token_period.c +FILES+= token_postfix_op.c +FILES+= token_preprocessing.c +FILES+= token_question.c +FILES+= token_rbrace.c +FILES+= token_rparen.c +FILES+= token_semicolon.c +FILES+= token_stmt.c +FILES+= token_stmt_list.c +FILES+= token_storage_class.c +FILES+= token_string_prefix.c +FILES+= token_switch_expr.c +FILES+= token_type_def.c +FILES+= token_unary_op.c +FILES+= token_while_expr.c FILES+= types_from_file.0 FILES+= types_from_file.0.stdout FILES+= types_from_file.0.list Index: src/tests/usr.bin/indent/token_comment.c diff -u src/tests/usr.bin/indent/token_comment.c:1.1 src/tests/usr.bin/indent/token_comment.c:1.2 --- src/tests/usr.bin/indent/token_comment.c:1.1 Mon Oct 18 19:36:30 2021 +++ src/tests/usr.bin/indent/token_comment.c Mon Oct 18 22:30:34 2021 @@ -1,4 +1,4 @@ -/* $NetBSD: token_comment.c,v 1.1 2021/10/18 19:36:30 rillig Exp $ */ +/* $NetBSD: token_comment.c,v 1.2 2021/10/18 22:30:34 rillig Exp $ */ /* $FreeBSD$ */ /* @@ -43,6 +43,330 @@ * - with/without ps.last_nl */ +#include <assert.h> +#include <stdio.h> +#include <string.h> + +#include "indent.h" + +static void +com_add_char(char ch) +{ + if (com.e + 1 >= com.l) + buf_expand(&com, 1); + *com.e++ = ch; +} + +static void +com_add_delim(void) +{ + if (!opt.star_comment_cont) + return; + size_t len = 3; + if (com.e + len >= com.l) + buf_expand(&com, len); + memcpy(com.e, " * ", len); + com.e += len; +} + +static void +com_terminate(void) +{ + if (com.e + 1 >= com.l) + buf_expand(&com, 1); + *com.e = '\0'; +} + +static bool +fits_in_one_line(int max_line_length) +{ + for (const char *p = inp.s; *p != '\n'; p++) { + assert(*p != '\0'); + assert(inp.e - p >= 2); + if (!(p[0] == '*' && p[1] == '/')) + continue; + + int len = indentation_after_range(ps.com_ind + 3, inp.s, p); + len += is_hspace(p[-1]) ? 2 : 3; + if (len <= max_line_length) + return true; + } + return false; +} + +/* + * Scan, reformat and output a single comment, which is either a block comment + * starting with '/' '*' or an end-of-line comment starting with '//'. + * + * Try to keep comments from going over the maximum line length. If a line is + * too long, move everything starting from the last blank to the next comment + * line. Blanks and tabs from the beginning of the input line are removed. + * + * ALGORITHM: + * 1) Decide where the comment should be aligned, and if lines should + * be broken. + * 2) If lines should not be broken and filled, just copy up to end of + * comment. + * 3) If lines should be filled, then scan through the input buffer, + * copying characters to com_buf. Remember where the last blank, + * tab, or newline was. When line is filled, print up to last blank + * and continue copying. + */ +void +process_comment(void) +{ + int adj_max_line_length; /* Adjusted max_line_length for comments that + * spill over the right margin */ + ssize_t last_blank; /* index of the last blank in com.buf */ + bool break_delim = opt.comment_delimiter_on_blankline; + int l_just_saw_decl = ps.just_saw_decl; + int com_ind; + + adj_max_line_length = opt.max_line_length; + ps.just_saw_decl = 0; + last_blank = -1; /* no blanks found so far */ + bool may_wrap = true; + ps.stats.comments++; + + /* Figure where to align and how to treat the comment */ + + if (ps.col_1 && !opt.format_col1_comments) { + may_wrap = false; + break_delim = false; + com_ind = 0; + + } else { + if (*inp.s == '-' || *inp.s == '*' || token.e[-1] == '/' || + (*inp.s == '\n' && !opt.format_block_comments)) { + may_wrap = false; + break_delim = false; + } + + if (lab.s == lab.e && code.s == code.e) { + com_ind = (ps.ind_level - opt.unindent_displace) * opt.indent_size; + adj_max_line_length = opt.block_comment_max_line_length; + if (com_ind <= 0) + com_ind = opt.format_col1_comments ? 0 : 1; + + } else { + break_delim = false; + + int target_ind; + if (code.s != code.e) + target_ind = indentation_after(compute_code_indent(), code.s); + else if (lab.s != lab.e) + target_ind = indentation_after(compute_label_indent(), lab.s); + else + target_ind = 0; + + com_ind = ps.decl_on_line || ps.ind_level == 0 + ? opt.decl_comment_column - 1 : opt.comment_column - 1; + if (com_ind <= target_ind) + com_ind = next_tab(target_ind); + if (com_ind + 25 > adj_max_line_length) + adj_max_line_length = com_ind + 25; + } + } + + ps.com_ind = com_ind; + + if (!may_wrap) { + /* + * Find out how much indentation there was originally, because that + * much will have to be ignored by dump_line(). This is a box comment, + * so nothing changes -- not even indentation. + * + * The comment we're about to read usually comes from inp.buf, + * unless it has been copied into save_com. + */ + const char *start; + + /* + * XXX: ordered comparison between pointers from different objects + * invokes undefined behavior (C99 6.5.8). + */ + start = inp.s >= save_com && inp.s < save_com + sc_size ? + sc_buf : inp.buf; + ps.n_comment_delta = -indentation_after_range(0, start, inp.s - 2); + } else { + ps.n_comment_delta = 0; + while (is_hspace(*inp.s)) + inp.s++; + } + + ps.comment_delta = 0; + com_add_char('/'); + com_add_char(token.e[-1]); /* either '*' or '/' */ + if (*inp.s != ' ' && may_wrap) + com_add_char(' '); + + if (break_delim && fits_in_one_line(adj_max_line_length)) + break_delim = false; + + if (break_delim) { + char *t = com.e; + com.e = com.s + 2; + *com.e = '\0'; + if (opt.blanklines_before_block_comments && ps.last_token != lbrace) + prefix_blankline_requested = true; + dump_line(); + com.e = com.s = t; + com_add_delim(); + } + + /* Start to copy the comment */ + + for (;;) { /* this loop will go until the comment is + * copied */ + switch (*inp.s) { /* this checks for various special cases */ + case '\f': + if (may_wrap) { /* in a text comment, break the line here */ + ps.use_ff = true; + dump_line(); + last_blank = -1; + com_add_delim(); + inp.s++; + while (is_hspace(*inp.s)) + inp.s++; + } else { + inbuf_skip(); + com_add_char('\f'); + } + break; + + case '\n': + if (token.e[-1] == '/') + goto end_of_line_comment; + + if (had_eof) { + diag(1, "Unterminated comment"); + dump_line(); + return; + } + + last_blank = -1; + if (!may_wrap || ps.last_nl) { /* if this is a boxed comment, + * we handle the newline */ + if (com.s == com.e) + com_add_char(' '); + if (may_wrap && com.e - com.s > 3) { + dump_line(); + com_add_delim(); + } + dump_line(); + if (may_wrap) + com_add_delim(); + + } else { + ps.last_nl = true; + if (!is_hspace(com.e[-1])) + com_add_char(' '); + last_blank = com.e - 1 - com.buf; + } + ++line_no; + if (may_wrap) { + bool skip_asterisk = true; + do { /* flush any blanks and/or tabs at start of + * next line */ + inbuf_skip(); + if (*inp.s == '*' && skip_asterisk) { + skip_asterisk = false; + inbuf_skip(); + if (*inp.s == '/') + goto end_of_comment; + } + } while (is_hspace(*inp.s)); + } else + inbuf_skip(); + break; /* end of case for newline */ + + case '*': + inbuf_skip(); + if (*inp.s == '/') { + end_of_comment: + inbuf_skip(); + + end_of_line_comment: + if (break_delim) { + if (com.e > com.s + 3) + dump_line(); + else + com.s = com.e; /* XXX: why not e = s? */ + com_add_char(' '); + } + + if (!is_hspace(com.e[-1]) && may_wrap) + com_add_char(' '); + if (token.e[-1] != '/') { + com_add_char('*'); + com_add_char('/'); + } + com_terminate(); + + ps.just_saw_decl = l_just_saw_decl; + return; + + } else /* handle isolated '*' */ + com_add_char('*'); + break; + + default: /* we have a random char */ + ; + int now_len = indentation_after_range(ps.com_ind, com.s, com.e); + for (;;) { + char ch = inbuf_next(); + if (is_hspace(ch)) + last_blank = com.e - com.buf; + com_add_char(ch); + now_len++; + if (memchr("*\n\r\b\t", *inp.s, 6) != NULL) + break; + if (now_len >= adj_max_line_length && last_blank != -1) + break; + } + + ps.last_nl = false; + + /* XXX: signed character comparison '>' does not work for UTF-8 */ + if (now_len > adj_max_line_length && + may_wrap && com.e[-1] > ' ') { + + /* the comment is too long, it must be broken up */ + if (last_blank == -1) { + dump_line(); + com_add_delim(); + break; + } + + com_terminate(); /* mark the end of the last word */ + com.e = com.buf + last_blank; + dump_line(); + + com_add_delim(); + + const char *p = com.buf + last_blank + 1; + while (is_hspace(*p)) + p++; + last_blank = -1; + + /* + * p still points to the last word from the previous line, in + * the same buffer that it is copied to, but to the right of + * the writing region [com.s, com.e). Calling dump_line only + * moved com.e back to com.s, it did not clear the contents of + * the buffer. This ensures that the buffer is already large + * enough. + */ + while (*p != '\0') { + assert(!is_hspace(*p)); + *com.e++ = *p++; + } + } + break; + } + } +} + /* For variations on this theme, try some of these options: */ /* -c20 */ /* -cd20 */ Added files: Index: src/tests/usr.bin/indent/token_binary_op.c diff -u /dev/null src/tests/usr.bin/indent/token_binary_op.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_binary_op.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,220 @@ +/* $NetBSD: token_binary_op.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for binary operators like '+', '&&' and several others. + * + * Several binary operators can be used as unary operators as well, or in + * other contexts. An example for such an operator is '*', which can be a + * multiplication, or pointer dereference, or pointer type declaration. + */ + +/* See C99 6.4.6 */ +#indent input +void +punctuators(void) +{ + int brackets = array[subscript]; + int parentheses = function(argument); + int braces = { initializer }; + int period = structure.member; + int arrow = structure->member; + + ++prefix_increment; + postfix_increment++; + --prefix_decrement; + postfix_decrement--; + int *address = &lvalue; + int bitwise_and = value & mask; + int product = factor * factor; + int dereferenced = *address; + int positive = +number; + int sum = number + number; + int negative = -number; + int difference = number - number; + bool negated = !condition; + + int quotient = number / number; + int modulo = number % number; + int shifted_left = number << number; + int shifted_right = number >> number; + bool less_than = number < number; + bool greater_than = number > number; + bool less_equal = number <= number; + bool greater_equal = number >= number; + bool equal = number == number; + bool unequal = number != number; + int bitwise_exclusive_or = number ^ number; + int bitwise_or = number | number; + bool logical_and = condition && condition; + bool logical_or = condition || condition; + + int conditional = condition ? number : number; + + /* combined assignment operators */ + number = (expression); + number *= number; + number /= number; + number %= number; + number += number; + number -= number; + number <<= number; + number >>= number; + number &= number; + number ^= number; + number |= number; + + number = function(argument1, argument2); + number = function(argument), number; + + /* digraphs */ + number = array<:subscript:>; + number = (int)<% initializer %>; +} +#indent end + +#indent run -ldi0 +void +punctuators(void) +{ + int brackets = array[subscript]; + int parentheses = function(argument); +/* $ XXX: The spaces around the initializer are gone. */ + int braces = {initializer}; + int period = structure.member; + int arrow = structure->member; + + ++prefix_increment; + postfix_increment++; + --prefix_decrement; + postfix_decrement--; + int *address = &lvalue; + int bitwise_and = value & mask; + int product = factor * factor; + int dereferenced = *address; + int positive = +number; + int sum = number + number; + int negative = -number; + int difference = number - number; + bool negated = !condition; + + int quotient = number / number; + int modulo = number % number; + int shifted_left = number << number; + int shifted_right = number >> number; + bool less_than = number < number; + bool greater_than = number > number; + bool less_equal = number <= number; + bool greater_equal = number >= number; + bool equal = number == number; + bool unequal = number != number; + int bitwise_exclusive_or = number ^ number; + int bitwise_or = number | number; + bool logical_and = condition && condition; + bool logical_or = condition || condition; + + int conditional = condition ? number : number; + + /* combined assignment operators */ + number = (expression); + number *= number; + number /= number; + number %= number; + number += number; + number -= number; + number <<= number; + number >>= number; + number &= number; + number ^= number; + number |= number; + + number = function(argument1, argument2); + number = function(argument), number; + + /* digraphs */ +/* $ XXX: indent is confused by the digraphs for '[' and ']'. */ +/* $ This probably doesn't matter since digraphs are not used in practice. */ +number = array <:subscript:>; + number = (int)<%initializer % >; +} +#indent end + +#indent input +void +peculiarities(void) +{ + /* + * When indent tokenizes some of the operators, it allows for + * arbitrary repetitions of the operator character, followed by an + * arbitrary amount of '='. This is used for operators like '&&' or + * '|||==='. + * + * Before 2021-03-07 22:11:01, the comment '//' was treated as an + * operator as well, and so was the comment '/////', leading to + * unexpected results; see comment-line-end.0 for more details. + * + * See lexi.c, lexi, "default:". + */ + if (a &&&&&&& b) + return; + if (a |||=== b) + return; + + /*- + * For '+' and '-', this does not work since the lexer has to + * distinguish between '++' and '+' early. The following sequence is + * thus tokenized as: + * + * ident 'a' + * postfix '++' + * binary_op '++' + * unary_op '++' + * unary_op '+' + * ident 'b' + * + * See lexi.c, lexi, "case '+':". + */ + if (a +++++++ b) + return; +} +#indent end + +#indent run -ldi0 +void +peculiarities(void) +{ + /* + * When indent tokenizes some of the operators, it allows for + * arbitrary repetitions of the operator character, followed by an + * arbitrary amount of '='. This is used for operators like '&&' or + * '|||==='. + * + * Before 2021-03-07 22:11:01, the comment '//' was treated as an + * operator as well, and so was the comment '/////', leading to + * unexpected results; see comment-line-end.0 for more details. + * + * See lexi.c, lexi, "default:". + */ + if (a &&&&&&& b) + return; + if (a |||=== b) + return; + + /*- + * For '+' and '-', this does not work since the lexer has to + * distinguish between '++' and '+' early. The following sequence is + * thus tokenized as: + * + * ident 'a' + * postfix '++' + * binary_op '++' + * unary_op '++' + * unary_op '+' + * ident 'b' + * + * See lexi.c, lexi, "case '+':". + */ + if (a++ ++ +++b) + return; +} +#indent end Index: src/tests/usr.bin/indent/token_case_label.c diff -u /dev/null src/tests/usr.bin/indent/token_case_label.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_case_label.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,47 @@ +/* $NetBSD: token_case_label.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for formatting of case labels in switch statements. + */ + +#indent input +void function(void){switch(expr){case 1:;case 2:break;case 3:switch( +inner){case 4:break;}}} +#indent end + +#indent run +void +function(void) +{ + switch (expr) { + case 1: ; + case 2: + break; + case 3: + switch ( + inner) { + case 4: + break; + } + } +} +#indent end + +#indent run -cli0.5 +void +function(void) +{ + switch (expr) { + case 1:; + case 2: + break; + case 3: + switch ( + inner) { + case 4: + break; + } + } +} +#indent end Index: src/tests/usr.bin/indent/token_colon.c diff -u /dev/null src/tests/usr.bin/indent/token_colon.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_colon.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,72 @@ +/* $NetBSD: token_colon.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for formatting of the colon token, which is used in the following + * contexts: + * + * After a label that is the target of a goto statement. + * + * In a switch statement, after a case label or the default label. + * + * As part of the conditional expression operator '?:'. + * + * In the declaration of a struct member that is a bit-field. + */ + +#indent input +void endless(void) +{ +label1: +goto label2; + + if (true)if (true)if (true)if (true)label2 :goto label1; +} +#indent end + +#indent run +void +endless(void) +{ +label1: + goto label2; + + if (true) + if (true) + if (true) + if (true) + label2: goto label1; +} +#indent end + +#indent input +int constant_expression = true?4:12345; +#indent end + +#indent run +int constant_expression = true ? 4 : 12345; +#indent end + +#indent input +struct bit_field { +bool flag:1; +int maybe_signed : 4; +signed int definitely_signed:3; +signed int : 0;/* finish the storage unit for the bit-field */ +unsigned int definitely_unsigned:3; +unsigned int:0;/* finish the storage unit for the bit-field */ +}; +#indent end + +#indent run +struct bit_field { + bool flag:1; + int maybe_signed:4; + signed int definitely_signed:3; +/* $ XXX: Placing the colon directly at the type looks inconsistent. */ + signed int: 0; /* finish the storage unit for the bit-field */ + unsigned int definitely_unsigned:3; +/* $ XXX: Placing the colon directly at the type looks inconsistent. */ + unsigned int: 0; /* finish the storage unit for the bit-field */ +}; +#indent end Index: src/tests/usr.bin/indent/token_comma.c diff -u /dev/null src/tests/usr.bin/indent/token_comma.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_comma.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,59 @@ +/* $NetBSD: token_comma.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the comma, which is used in the following contexts: + * + * The binary operator ',' inserts a sequence point between the evaluation of + * its operands. + * + * The parameters of a function declaration or a macro definition are + * separated by a comma. + * + * The arguments of a function call expression or a macro invocation are + * separated by a comma. + */ + +#indent input +int +comma_expression(void) +{ + return 1,3; + return a=b,c=d; +} +#indent end + +#indent run +int +comma_expression(void) +{ + return 1, 3; + return a = b, c = d; +} +#indent end + +/* + * A comma that occurs at the beginning of a line is probably part of an + * initializer list, placed there for alignment. + */ +#indent input +int +comma_at_beginning_of_line(void) +{ + return 1, + 3; + return 1 + ,3; +} +#indent end + +#indent run -ci4 +int +comma_at_beginning_of_line(void) +{ + return 1, + 3; + return 1 + ,3; +} +#indent end Index: src/tests/usr.bin/indent/token_decl.c diff -u /dev/null src/tests/usr.bin/indent/token_decl.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_decl.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,32 @@ +/* $NetBSD: token_decl.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for declarations. + * + * Indent distinguishes global and local declarations. + * + * Declarations can be for functions or for variables. + */ + +#indent input +int global_var; +int global_array = [1,2,3,4]; +int global_array = [ +1 +,2, +3, +4, +]; +#indent end + +#indent run -di0 +int global_var; +int global_array = [1, 2, 3, 4]; +int global_array = [ + 1 + ,2, + 3, + 4, +]; +#indent end Index: src/tests/usr.bin/indent/token_do_stmt.c diff -u /dev/null src/tests/usr.bin/indent/token_do_stmt.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_do_stmt.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,30 @@ +/* $NetBSD: token_do_stmt.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for do-while statements. + */ + +#indent input +void function(void) { + do stmt(); while (0); + do { stmt(); } while (0); + do /* comment */ stmt(); while (0); +} +#indent end + +#indent run +void +function(void) +{ + do + stmt(); + while (0); + do { + stmt(); + } while (0); + do /* comment */ + stmt(); + while (0); +} +#indent end Index: src/tests/usr.bin/indent/token_end_of_file.c diff -u /dev/null src/tests/usr.bin/indent/token_end_of_file.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_end_of_file.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,17 @@ +/* $NetBSD: token_end_of_file.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the end of a file. + * + * The end of a file typically occurs after a top-level declaration, or after + * a preprocessing directive. Everything else is a syntax error. + */ + +#indent input +int decl; +#indent end + +#indent run +int decl; +#indent end Index: src/tests/usr.bin/indent/token_for_exprs.c diff -u /dev/null src/tests/usr.bin/indent/token_for_exprs.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_for_exprs.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,58 @@ +/* $NetBSD: token_for_exprs.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Test for 'for' loops. + * + * Most 'for' loops have 3 expressions in their head. Each of these + * expressions is optional though. + * + * When all 3 expressions are omitted, the 'for' loop is often called a + * 'forever' loop. + */ + +#indent input +void +function(void) +{ + for (int i = 0; i < 6; i++) + print_char("hello\n"[i]); + forever { + stmt(); + } +} +#indent end + +#indent run-equals-input + + +/* + * Indent can cope with various syntax errors, which may be caused by + * syntactic macros like 'forever' or 'foreach'. + */ +#indent input +#define forever for (;;) +#define foreach(list, it) for (it = list.first; it != NULL; it = it->next) + +void +function(void) +{ + forever + stmt(); + + forever { + stmt(); + } + +/* $ No space after 'foreach' since it looks like a function name. */ + foreach(list, it) + println(it->data); + +/* $ No space after 'foreach' since it looks like a function name. */ + foreach(list, it) { + println(it->data); + } +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_form_feed.c diff -u /dev/null src/tests/usr.bin/indent/token_form_feed.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_form_feed.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,14 @@ +/* $NetBSD: token_form_feed.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for form feeds, which is a control character (C99 5.2.1p3). + */ + +#indent input +void function_1(void); + +void function_2(void); +#indent end + +#indent run-equals-input -di0 Index: src/tests/usr.bin/indent/token_funcname.c diff -u /dev/null src/tests/usr.bin/indent/token_funcname.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_funcname.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,18 @@ +/* $NetBSD: token_funcname.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for function names. + */ + +#indent input +void +function(void) +{ + func(); + (func)(); + func(1, 2, 3); +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_if_expr.c diff -u /dev/null src/tests/usr.bin/indent/token_if_expr.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_if_expr.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,21 @@ +/* $NetBSD: token_if_expr.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for 'if' followed by a parenthesized expression. + */ + +#indent input +void function(void) { + if(cond) stmt(); +} +#indent end + +#indent run +void +function(void) +{ + if (cond) + stmt(); +} +#indent end Index: src/tests/usr.bin/indent/token_if_expr_stmt.c diff -u /dev/null src/tests/usr.bin/indent/token_if_expr_stmt.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_if_expr_stmt.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,26 @@ +/* $NetBSD: token_if_expr_stmt.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for 'if' followed by a parenthesized expression and a statement. + * + * At this point, the 'if' statement is not necessarily complete, it can be + * completed with the keyword 'else' followed by a statement. + * + * Any token other than 'else' completes the 'if' statement. + */ + +#indent input +void +function(void) +{ + if (cond) + stmt(); + if (cond) + stmt(); + else /* belongs to the second 'if' */ + stmt(); +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_if_expr_stmt_else.c diff -u /dev/null src/tests/usr.bin/indent/token_if_expr_stmt_else.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_if_expr_stmt_else.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,22 @@ +/* $NetBSD: token_if_expr_stmt_else.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for 'if' followed by a parenthesized expression, a statement and the + * keyword 'else'. + * + * At this point, the statement needs to be completed with another statement. + */ + +#indent input +void +function(void) +{ + if (cond) + stmt(); + else + stmt(); +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_keyword_do.c diff -u /dev/null src/tests/usr.bin/indent/token_keyword_do.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_keyword_do.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,25 @@ +/* $NetBSD: token_keyword_do.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keyword 'do' that begins a do-while statement. + */ + +#indent input +void function(void) { + do stmt(); while (0); + do {} while (0); +} +#indent end + +#indent run +void +function(void) +{ + do + stmt(); + while (0); + do { + } while (0); +} +#indent end Index: src/tests/usr.bin/indent/token_keyword_do_else.c diff -u /dev/null src/tests/usr.bin/indent/token_keyword_do_else.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_keyword_do_else.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,31 @@ +/* $NetBSD: token_keyword_do_else.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keyword 'do' or 'else'. These two keywords are followed by + * a space. In contrast to 'for', 'if' and 'while', the space is not + * followed by a parenthesized expression. + */ + +#indent input +void +function(void) +{ + do(var)--;while(var>0); + if(var>0)var=0;else(var=3); +} +#indent end + +#indent run +void +function(void) +{ + do + (var)--; + while (var > 0); + if (var > 0) + var = 0; + else + (var = 3); +} +#indent end Index: src/tests/usr.bin/indent/token_keyword_else.c diff -u /dev/null src/tests/usr.bin/indent/token_keyword_else.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_keyword_else.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,47 @@ +/* $NetBSD: token_keyword_else.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keyword 'else'. + * + * When parsing nested incomplete 'if' statements, the problem of the + * 'dangling else' occurs. It is resolved by binding the 'else' to the + * innermost incomplete 'if' statement. + */ + +/* + * In 'parse', an if_expr_stmt is reduced to a simple statement, unless the + * next token is 'else'. The comment does not influence this since it never + * reaches 'parse'. + */ +#indent input +void +example(bool cond) +{ + if (cond) + if (cond) + if (cond) + stmt(); + else + stmt(); + /* comment */ + else + stmt(); +} +#indent end + +#indent run +void +example(bool cond) +{ + if (cond) + if (cond) + if (cond) + stmt(); + else + stmt(); + /* comment */ + else + stmt(); +} +#indent end Index: src/tests/usr.bin/indent/token_keyword_for_if_while.c diff -u /dev/null src/tests/usr.bin/indent/token_keyword_for_if_while.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_keyword_for_if_while.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,36 @@ +/* $NetBSD: token_keyword_for_if_while.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keywords 'for', 'if' and 'while'. These keywords have in + * common that they are followed by a space and a parenthesized statement + * head. For 'if' and 'while', this head is a single expression. For 'for', + * the head is 0 to 3 expressions, separated by semicolons. + */ + +#indent input +void +function(void) +{ + if(cond)stmt(); + while(cond)stmt(); + for(;cond;)stmt(); + do stmt();while(cond); +} +#indent end + +#indent run +void +function(void) +{ + if (cond) + stmt(); + while (cond) + stmt(); + for (; cond;) + stmt(); + do + stmt(); + while (cond); +} +#indent end Index: src/tests/usr.bin/indent/token_keyword_struct_union_enum.c diff -u /dev/null src/tests/usr.bin/indent/token_keyword_struct_union_enum.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_keyword_struct_union_enum.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,23 @@ +/* $NetBSD: token_keyword_struct_union_enum.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keywords 'struct', 'union' and 'enum'. + */ + +#indent input +struct stat { + mode_t st_mode; +}; + +union variant { + enum { + } tag; + int v_int; + long v_long; + bool v_bool; + void *v_pointer; +}; +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_lbrace.c diff -u /dev/null src/tests/usr.bin/indent/token_lbrace.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_lbrace.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,26 @@ +/* $NetBSD: token_lbrace.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the token '{'. + * + * It is used as the start marker of a block of statements. + * + * It is used in initializers. + * + * In macro arguments, a '{' is an ordinary character, it does not need to be + * balanced. This is in contrast to '(', which must be balanced with ')'. + */ + +#indent input +void +function(void) +{ + struct person p = { + .name = "Name", + .age = {{{35}}}, /* C11 6.7.9 allows this. */ + }; +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_lparen.c diff -u /dev/null src/tests/usr.bin/indent/token_lparen.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_lparen.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,94 @@ +/* $NetBSD: token_lparen.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the tokens '(', which has several possible meanings, and for '['. + * + * In an expression, '(' overrides the precedence rules by explicitly grouping + * a subexpression in parentheses. + * + * In an expression, '(' marks the beginning of a type cast or conversion. + * + * In a function call expression, '(' marks the beginning of the function + * arguments. + * + * In a type declaration, '(' marks the beginning of the function parameters. + */ + +/* This is the maximum supported number of parentheses. */ +#indent input +int zero = (((((((((((((((((((0))))))))))))))))))); +#indent end + +#indent run-equals-input -di0 + + +#indent input +void (*action)(void); +#indent end + +#indent run-equals-input -di0 + + +#indent input +#define macro(arg) ((arg) + 1) +#indent end +#indent run-equals-input -di0 + + +#indent input +void +function(void) +{ + other_function(); + other_function("first", 2, "last argument"[4]); + + if (false)(void)x; + if (false)(func)(arg); + if (false)(cond)?123:456; + + /* C99 compound literal */ + origin = (struct point){0,0}; + + /* GCC statement expression */ + /* expr = ({if(expr)debug();expr;}); */ +/* $ XXX: Generates wrong 'Error@36: Unbalanced parens'. */ +} +#indent end + +#indent run +void +function(void) +{ + other_function(); + other_function("first", 2, "last argument"[4]); + + if (false) + (void)x; + if (false) + (func)(arg); + if (false) + (cond) ? 123 : 456; + + /* C99 compound literal */ + origin = (struct point){ + 0, 0 + }; + + /* GCC statement expression */ + /* expr = ({if(expr)debug();expr;}); */ +} +#indent end + + +/* + * C99 designator initializers are the rare situation where there is a space + * before a '['. + */ +#indent input +int array[] = { + 1, 2, [2] = 3, [3] = 4, +}; +#indent end + +#indent run-equals-input -di0 Index: src/tests/usr.bin/indent/token_newline.c diff -u /dev/null src/tests/usr.bin/indent/token_newline.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_newline.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,30 @@ +/* $NetBSD: token_newline.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/*- + * Tests for the token '\n', which ends a line. + * + * A newline ends an end-of-line comment that has been started with '//'. + * + * When a line ends with a backslash immediately followed by '\n', these two + * characters are merged and continue the logical line (C11 5.1.1.2p1i2). + * + * In other contexts, a newline is an ordinary space character from a + * compiler's point of view. Indent preserves line breaks though. + */ + +#indent input +int var= +1 + +2 + +3 + +4; +#indent end + +#indent run +int var = +1 ++ 2 ++ 3 ++ 4; +#indent end Index: src/tests/usr.bin/indent/token_period.c diff -u /dev/null src/tests/usr.bin/indent/token_period.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_period.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,33 @@ +/* $NetBSD: token_period.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the token '.'. + * + * The '.' in numbers such as 3.14159265358979 is not a token '.'. + * + * The token '.' is used to access a member of a struct or union. + */ + + +/* + * The ellipsis for the function parameter is a sequence of three '.' tokens. + * It would have been more intuitive to model them as a single token, but it + * doesn't make any difference for formatting the code. + */ +#indent input +void my_printf(const char *, ...); +#indent end + +#indent run-equals-input -di0 + + +#indent input +int var = str.member; +int var = str . member; +#indent end + +#indent run -di0 +int var = str.member; +int var = str.member; +#indent end Index: src/tests/usr.bin/indent/token_postfix_op.c diff -u /dev/null src/tests/usr.bin/indent/token_postfix_op.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_postfix_op.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,19 @@ +/* $NetBSD: token_postfix_op.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the postfix increment and decrement operators '++' and '--'. + */ + +#indent input +void +function(void) +{ + counter++; + ++counter; /* this is a prefix unary operator instead */ + counter--; + --counter; /* this is a prefix unary operator instead */ +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_preprocessing.c diff -u /dev/null src/tests/usr.bin/indent/token_preprocessing.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_preprocessing.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,183 @@ +/* $NetBSD: token_preprocessing.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/*- + * Tests for indenting preprocessing directives: + * + * #define + * #ifdef + * #pragma + * #line + */ + + +#indent input +#include <system-header.h> +#include "local-header.h" +#indent end + +#indent run-equals-input + + +/* + * Nested conditional compilation. + */ +#indent input +#if 0 +#else +#endif + +#if 0 /* if comment */ +#else /* else comment */ +#endif /* endif comment */ + +#if 0 /* outer if comment */ +# if nested /* inner if comment */ +# else /* inner else comment */ +# endif /* inner endif comment */ +#endif /* outer endif comment */ +#indent end + +#indent run +#if 0 +#else +#endif + +#if 0 /* if comment */ +#else /* else comment */ +#endif /* endif comment */ + +#if 0 /* outer if comment */ +/* $ XXX: The indentation is removed, which can get confusing */ +#if nested /* inner if comment */ +#else /* inner else comment */ +#endif /* inner endif comment */ +#endif /* outer endif comment */ +#indent end + + +#indent input +#define multi_line_definition /* first line + * middle + * final line + */ actual_value +#indent end + +#indent run-equals-input + + +/* + * Before indent.c 1.129 from 2021-10-08, indent mistakenly interpreted quotes + * in comments as starting a string literal. The '"' in the comment started a + * string, the next '"' finished the string, and the following '/' '*' was + * interpreted as the beginning of a comment. This comment lasted until the + * next '*' '/', which in this test is another preprocessor directive, solely + * for symmetry. + * + * The effect was that the extra space after d2 was not formatted, as that + * line was considered part of the comment. + */ +#indent input +#define comment_in_string_literal "/* no comment " +int this_is_an_ordinary_line_again; + +int d1 ; +#define confuse_d /*"*/ "/*" +int d2 ; +#define resolve_d "*/" +int d3 ; + +int s1 ; +#define confuse_s /*'*/ '/*' +int s2 ; +#define resolve_s '*/' +int s3 ; +#indent end + +#indent run +#define comment_in_string_literal "/* no comment " +int this_is_an_ordinary_line_again; + +int d1; +#define confuse_d /*"*/ "/*" +int d2; +#define resolve_d "*/" +int d3; + +int s1; +#define confuse_s /*'*/ '/*' +int s2; +#define resolve_s '*/' +int s3; +#indent end + + +/* + * A preprocessing directive inside an expression keeps the state about + * whether the next operator is unary or binary. + */ +#indent input +int binary_plus = 3 +#define intermediate 1 + +4; +int unary_plus = +#define intermediate 1 + + 4; +#indent end + +#indent run +int binary_plus = 3 +#define intermediate 1 ++ 4; +int unary_plus = +#define intermediate 1 ++4; +#indent end + + +/* + * Preprocessing lines that don't expect an argument but have one are fixed. + * They are indented with a single tab. + */ +#indent input +#if 0 +#elif 1 +#else if 3 +#endif 0 +#indent end + +#indent run +#if 0 +#elif 1 +#else /* if 3 */ +#endif /* 0 */ +#indent end + + +/* + * Existing comments are indented just like code comments. + * + * This means that the above wrong preprocessing lines (#else with argument) + * need to be fed through indent twice until they become stable. Since + * compilers issue warnings about these invalid lines, not much code still has + * these, making this automatic fix an edge case. + */ +#indent input +#if 0 /* comment */ +#else /* comment */ +#endif /* comment */ + +#if 0/* comment */ +#else/* comment */ +#endif/* comment */ +#indent end + +#indent run +#if 0 /* comment */ +#else /* comment */ +#endif /* comment */ + +#if 0 /* comment */ +#else /* comment */ +#endif /* comment */ +#indent end Index: src/tests/usr.bin/indent/token_question.c diff -u /dev/null src/tests/usr.bin/indent/token_question.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_question.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,14 @@ +/* $NetBSD: token_question.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the '?:' operator. + */ + +#indent input +int var = cond ? 1 : 0; + +int multi = cond ? 1 : cond ? 2 : cond ? 3 : 4; +#indent end + +#indent run-equals-input -di0 Index: src/tests/usr.bin/indent/token_rbrace.c diff -u /dev/null src/tests/usr.bin/indent/token_rbrace.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_rbrace.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,17 @@ +/* $NetBSD: token_rbrace.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the token '}', which ends the corresponding '{' token. + */ + +#indent input +void function(void){} +#indent end + +#indent run +void +function(void) +{ +} +#indent end Index: src/tests/usr.bin/indent/token_rparen.c diff -u /dev/null src/tests/usr.bin/indent/token_rparen.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_rparen.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,18 @@ +/* $NetBSD: token_rparen.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the token ')', which ends the corresponding ')', as well as ']', + * which ends the corresponding ']'. + */ + +#indent input +int var = (3); +int cast = (int)3; +int cast = (int)(3); +int call = function(3); +int array[3] = {1, 2, 3}; +int array[3] = {[2] = 3}; +#indent end + +#indent run-equals-input -di0 Index: src/tests/usr.bin/indent/token_semicolon.c diff -u /dev/null src/tests/usr.bin/indent/token_semicolon.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_semicolon.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,43 @@ +/* $NetBSD: token_semicolon.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the token ';'. + * + * The ';' ends a declaration. + * + * The ';' ends a statement. + * + * The ';' separates the 3 expressions in the head of the 'for' loop. + */ + +#indent input +struct { + int member; +} global_var; +#indent end + +#indent run-equals-input -di0 + + +#indent input +void +function(void) +{ + for ( ; ; ) + stmt(); + for (;;) + stmt(); +} +#indent end + +#indent run +void +function(void) +{ + for (;;) + stmt(); + for (;;) + stmt(); +} +#indent end Index: src/tests/usr.bin/indent/token_stmt.c diff -u /dev/null src/tests/usr.bin/indent/token_stmt.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_stmt.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,26 @@ +/* $NetBSD: token_stmt.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for statements. + */ + +#indent input +#define unless(cond) if (!(cond)) + +void +function(void) +{ + stmt(); + stmt; /* probably some macro */ + + unless(cond) + stmt(); +} +#indent end + +/* + * There is no space after 'unless' since indent cannot know that it is a + * syntactic macro, especially not when its definition is in a header file. + */ +#indent run-equals-input Index: src/tests/usr.bin/indent/token_stmt_list.c diff -u /dev/null src/tests/usr.bin/indent/token_stmt_list.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_stmt_list.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,26 @@ +/* $NetBSD: token_stmt_list.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for lists of statements. + * + * Since C99, in such a statement list, statements can be intermixed with + * declarations in arbitrary ways. + */ + +#indent input +void +function(void) +{ + stmt(); + int var; + stmt(); + { + stmt(); + int var; + stmt(); + } +} +#indent end + +#indent run-equals-input -ldi0 Index: src/tests/usr.bin/indent/token_storage_class.c diff -u /dev/null src/tests/usr.bin/indent/token_storage_class.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_storage_class.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,14 @@ +/* $NetBSD: token_storage_class.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for storage classes such as 'extern', 'static', but not 'typedef'. + */ + +#indent input +static int var; +extern int var; +int var; +#indent end + +#indent run-equals-input -di0 Index: src/tests/usr.bin/indent/token_string_prefix.c diff -u /dev/null src/tests/usr.bin/indent/token_string_prefix.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_string_prefix.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,18 @@ +/* $NetBSD: token_string_prefix.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for strings of wide characters, which are prefixed with 'L'. + */ + +#indent input +wchar_t wide_string[] = L"wide string"; +#indent end + +/* + * Regardless of the line length, the 'L' must never be separated from the + * string literal. + */ +#indent run-equals-input -di0 +#indent run-equals-input -di0 -l25 +#indent run-equals-input -di0 -l1 Index: src/tests/usr.bin/indent/token_switch_expr.c diff -u /dev/null src/tests/usr.bin/indent/token_switch_expr.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_switch_expr.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,17 @@ +/* $NetBSD: token_switch_expr.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keyword 'switch' followed by a parenthesized expression. + */ + +#indent input +void +function(void) +{ + switch (expr) { + } +} +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_type_def.c diff -u /dev/null src/tests/usr.bin/indent/token_type_def.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_type_def.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,16 @@ +/* $NetBSD: token_type_def.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keyword 'typedef'. + */ + +/* + * Contrary to declarations, type definitions are not affected by the option + * '-di'. + */ +#indent input +typedef int number; +#indent end + +#indent run-equals-input Index: src/tests/usr.bin/indent/token_unary_op.c diff -u /dev/null src/tests/usr.bin/indent/token_unary_op.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_unary_op.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,22 @@ +/* $NetBSD: token_unary_op.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for unary operators, such as '+', '-', '*', '&'. + */ + +#indent input +int var=+3; +int mixed=+-+-+-+-+-+-+-+-+-+-+-+-+-3; +int count=~-~-~-~-~-~-~-~-~-~-~-~-~-3; +int same = + + + + + - - - - - 3; +#indent end + +#indent run -di0 +int var = +3; +int mixed = +-+-+-+-+-+-+-+-+-+-+-+-+-3; +int count = ~-~-~-~-~-~-~-~-~-~-~-~-~-3; +/* $ FIXME: There must be spaces between adjacent '+'. */ +/* $ FIXME: There must be spaces between adjacent '-'. */ +int same = +++++-----3; +#indent end Index: src/tests/usr.bin/indent/token_while_expr.c diff -u /dev/null src/tests/usr.bin/indent/token_while_expr.c:1.1 --- /dev/null Mon Oct 18 22:30:35 2021 +++ src/tests/usr.bin/indent/token_while_expr.c Mon Oct 18 22:30:34 2021 @@ -0,0 +1,30 @@ +/* $NetBSD: token_while_expr.c,v 1.1 2021/10/18 22:30:34 rillig Exp $ */ +/* $FreeBSD$ */ + +/* + * Tests for the keyword 'while', followed by a parenthesized expression. + */ + +#indent input +int main(int argc,char**argv){int o;while((o=getopt(argc,argv,"x:"))!=-1) +switch(o){case'x':do{o++;}while(o<5);break;default:usage();}return 0;} +#indent end + +#indent run +int +main(int argc, char **argv) +{ + int o; + while ((o = getopt(argc, argv, "x:")) != -1) + switch (o) { + case 'x': + do { + o++; + } while (o < 5); + break; + default: + usage(); +/* $ XXX: The 'return' should be in a separate line. */ + } return 0; +} +#indent end