This conforms better with the K&R style as presented in the 2nd edition of The C Programming Language. --- ChangeLog | 2 ++ regression/TEST | 3 ++- regression/standard/bug-hp.c | 2 +- regression/standard/no-space-after-fp-name.c | 23 +++++++++++++++++++++++ src/handletoken.c | 14 ++++++++++++++ src/indent.h | 2 ++ src/parse.c | 1 + 7 files changed, 45 insertions(+), 2 deletions(-) create mode 100644 regression/standard/no-space-after-fp-name.c
diff --git a/ChangeLog b/ChangeLog index c6cf846..2e9f639 100644 --- a/ChangeLog +++ b/ChangeLog @@ -2,6 +2,8 @@ * Added an option (-as/--align-with-spaces) which if indenting with tabs will ident to the current indentation level, and then pad with spces up till the target_column. + * If -npcs is set, don't add a space between a function pointer's + name and its arglist. 2015-06-13 Tim Hentenaar <t...@hentenaar.com> * lexi.c: Fix a compilation error related to the presence of diff --git a/regression/TEST b/regression/TEST index 6b310ac..7d6af44 100755 --- a/regression/TEST +++ b/regression/TEST @@ -68,7 +68,7 @@ SPECIALS="typedef-bug.c bug-hp.c bug-di.c newlined-parms.c indent.pro.c \ bad-comment.c unknown-type.c unknown-type-npsl.c bug-npsl.c bug-psl.c do-cdw.c \ label.c goto-1.c goto-2.c line-count.c decl_block.c pointer-pal.c else-comment-2-br.c else-comment-2-bl.c \ else-comment-2-br-ce.c preserve-newline-after-right-brace.c gettext-strings.c single-line-conditionals.c \ - align-with-spaces.c" + align-with-spaces.c no-space-after-fp-name.c" ARGS="-bad" $INDENT -npro $ARGS input/bad-break.c -o output/bad-break.c @@ -177,6 +177,7 @@ $INDENT -npro -br -ce input/preserve-newline-after-right-brace.c -o output/prese ARGS="" $INDENT -npro -slc input/single-line-conditionals.c -o output/single-line-conditionals.c $INDENT -npro -br -ut -i8 -l70 -ts8 -as input/align-with-spaces.c -o output/align-with-spaces.c +$INDENT -npro -npcs input/fp.c -o output/no-space-after-fp-name.c ARGS="-kr -cp0 -l132 -lps -br -psl" $INDENT -npro $ARGS input/const.c -o output/const.c diff --git a/regression/standard/bug-hp.c b/regression/standard/bug-hp.c index 6b9ca04..0888683 100644 --- a/regression/standard/bug-hp.c +++ b/regression/standard/bug-hp.c @@ -1,4 +1,4 @@ void dblptr_main(void) { - double (*valfnc) (const char *); + double (*valfnc)(const char *); } diff --git a/regression/standard/no-space-after-fp-name.c b/regression/standard/no-space-after-fp-name.c new file mode 100644 index 0000000..6bc5885 --- /dev/null +++ b/regression/standard/no-space-after-fp-name.c @@ -0,0 +1,23 @@ +int (*fp())(); + +register void (*GCForward)() asm("r16"); /* GC Forwarding code */ + +main() +{ + switch (fork()) + { + default: + break; + } +} + +int * +function_2(var) + int var; +{ + int *var_1_0; + + var_1_0 = (int *) make_shape_1d(var); + + return (var_1_0); +} diff --git a/src/handletoken.c b/src/handletoken.c index 5b54bd9..5250cc0 100644 --- a/src/handletoken.c +++ b/src/handletoken.c @@ -1,6 +1,7 @@ /** \file * handletoken.c GNU indent, processing of tokens returned by the parser. * + * Copyright (c) 2015 Tim Hentenaar. All rights reserved.<br> * Copyright (c) 2013 Ćukasz Stelmach. All rights reserved.<br> * Copyright (c) 1999, 2000 Carlo Wood. All rights reserved. <br> * Copyright (c) 1994, 1996, 1997 Joseph Arceneaux. All rights reserved. <br> @@ -328,6 +329,13 @@ static void handle_token_lparen( parser_state_tos->paren_depth++; + /* In the case of nested function pointer declarations, let's ensure + * we output a ' ' between the decl word and the lparen, but NOT + * between the following rparen and lparen. + */ + if (parser_state_tos->is_func_ptr_decl && !settings.proc_calls_space) + parser_state_tos->want_blank = (*(token - 1) != ')' && *(token - 1) != ' '); + if (parser_state_tos->want_blank && (*token != '[') && ( (parser_state_tos->last_token != ident) || @@ -344,6 +352,11 @@ static void handle_token_lparen( set_buf_break (bb_proc_call, paren_target); } + /* Remember if this looks like a function pointer decl. */ + if (parser_state_tos->want_blank && + parser_state_tos->last_token == decl && *(token + 1) == '*') + parser_state_tos->is_func_ptr_decl = true; + if (parser_state_tos->in_decl && !parser_state_tos->block_init) { if ((*token != '[') && !buf_break_used) @@ -944,6 +957,7 @@ static void handle_token_semicolon( parser_state_tos->block_init = 0; parser_state_tos->block_init_level = 0; parser_state_tos->just_saw_decl--; + parser_state_tos->is_func_ptr_decl = false; if (parser_state_tos->in_decl && (s_code == e_code) && !buf_break_used && diff --git a/src/indent.h b/src/indent.h index 8179658..12c4e04 100644 --- a/src/indent.h +++ b/src/indent.h @@ -418,6 +418,8 @@ typedef struct parser_state * scanned was a newline */ int saw_double_colon; /*!< set when we see a ::, reset at first semi- * colon or left brace */ + int is_func_ptr_decl; /*!< set when we see a decl, followed by lparen + * and '*'. */ int broken_at_non_nl; /*!< true when a line was broken at a place * where there was no newline in the input file */ int in_or_st; /*!< Will be true iff there has been a diff --git a/src/parse.c b/src/parse.c index bc661ba..880333e 100644 --- a/src/parse.c +++ b/src/parse.c @@ -136,6 +136,7 @@ extern void reset_parser(void) parser_state_tos->dec_nest = 0; parser_state_tos->can_break = bb_none; parser_state_tos->saw_double_colon = false; + parser_state_tos->is_func_ptr_decl = false; parser_state_tos->il[0] = 0; parser_state_tos->cstk[0] = 0; -- 2.3.6 _______________________________________________ bug-indent mailing list bug-indent@gnu.org https://lists.gnu.org/mailman/listinfo/bug-indent