From owner-svn-src-head@freebsd.org Sun Jun 3 16:43:00 2018 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2610:1c1:1:606c::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id 52D08FDD5BF; Sun, 3 Jun 2018 16:43:00 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from mxrelay.nyi.freebsd.org (mxrelay.nyi.freebsd.org [IPv6:2610:1c1:1:606c::19:3]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client CN "mxrelay.nyi.freebsd.org", Issuer "Let's Encrypt Authority X3" (verified OK)) by mx1.freebsd.org (Postfix) with ESMTPS id 029796E403; Sun, 3 Jun 2018 16:43:00 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org (repo.freebsd.org [IPv6:2610:1c1:1:6068::e6a:0]) (using TLSv1.2 with cipher ECDHE-RSA-AES256-GCM-SHA384 (256/256 bits)) (Client did not present a certificate) by mxrelay.nyi.freebsd.org (Postfix) with ESMTPS id D652021365; Sun, 3 Jun 2018 16:42:59 +0000 (UTC) (envelope-from pstef@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id w53Ggxju091474; Sun, 3 Jun 2018 16:42:59 GMT (envelope-from pstef@FreeBSD.org) Received: (from pstef@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id w53Ggwac091469; Sun, 3 Jun 2018 16:42:58 GMT (envelope-from pstef@FreeBSD.org) Message-Id: <201806031642.w53Ggwac091469@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pstef set sender to pstef@FreeBSD.org using -f From: Piotr Pawel Stefaniak Date: Sun, 3 Jun 2018 16:42:58 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r334566 - in head/usr.bin/indent: . tests X-SVN-Group: head X-SVN-Commit-Author: pstef X-SVN-Commit-Paths: in head/usr.bin/indent: . tests X-SVN-Commit-Revision: 334566 X-SVN-Commit-Repository: base MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit X-BeenThere: svn-src-head@freebsd.org X-Mailman-Version: 2.1.26 Precedence: list List-Id: SVN commit messages for the src tree for head/-current List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sun, 03 Jun 2018 16:43:00 -0000 Author: pstef Date: Sun Jun 3 16:42:58 2018 New Revision: 334566 URL: https://svnweb.freebsd.org/changeset/base/334566 Log: indent(1): don't format function declarations as variables Added: head/usr.bin/indent/tests/f_decls.0 (contents, props changed) head/usr.bin/indent/tests/f_decls.0.stdout (contents, props changed) Modified: head/usr.bin/indent/indent.c head/usr.bin/indent/lexi.c head/usr.bin/indent/tests/Makefile Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Sun Jun 3 16:27:40 2018 (r334565) +++ head/usr.bin/indent/indent.c Sun Jun 3 16:42:58 2018 (r334566) @@ -1029,30 +1029,31 @@ check_type: case funcname: case ident: /* got an identifier or constant */ - if (ps.in_decl) { /* if we are in a declaration, we must indent - * identifier */ - if (type_code != funcname || !procnames_start_line) { - if (!ps.block_init && !ps.dumped_decl_indent && ps.paren_level == 0) { - if (troff) { - if (ps.want_blank) - *e_code++ = ' '; - sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7); - e_code += strlen(e_code); - } else - indent_declaration(dec_ind, tabs_to_var); - ps.dumped_decl_indent = true; - ps.want_blank = false; - } - } else { - if (ps.want_blank && !(procnames_start_line && - type_code == funcname)) - *e_code++ = ' '; - ps.want_blank = false; - if (dec_ind && s_code != e_code) { + if (ps.in_decl) { + if (type_code == funcname) { + ps.in_decl = false; + if (procnames_start_line && s_code != e_code) { *e_code = '\0'; dump_line(); } - dec_ind = 0; + else if (ps.want_blank) { + *e_code++ = ' '; + } + ps.want_blank = false; + } + else if (!ps.block_init && !ps.dumped_decl_indent && + ps.paren_level == 0) { /* if we are in a declaration, we + * must indent identifier */ + + if (troff) { + if (ps.want_blank) + *e_code++ = ' '; + sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7); + e_code += strlen(e_code); + } else + indent_declaration(dec_ind, tabs_to_var); + ps.dumped_decl_indent = true; + ps.want_blank = false; } } else if (sp_sw && ps.p_l_follow == 0) { Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Sun Jun 3 16:27:40 2018 (r334565) +++ head/usr.bin/indent/lexi.c Sun Jun 3 16:42:58 2018 (r334566) @@ -367,12 +367,12 @@ lexi(struct parser_state *state) * token is in fact a declaration keyword -- one that has been * typedefd */ - if (((*buf_ptr == '*' && buf_ptr[1] != '=') || isalpha(*buf_ptr) || *buf_ptr == '_') - && !state->p_l_follow - && !state->block_init - && (state->last_token == rparen || state->last_token == semicolon || - state->last_token == decl || - state->last_token == lbrace || state->last_token == rbrace)) { + else if (!state->p_l_follow && !state->block_init && + !state->in_stmt && + ((*buf_ptr == '*' && buf_ptr[1] != '=') || + isalpha((unsigned char)*buf_ptr)) && + (state->last_token == semicolon || state->last_token == lbrace || + state->last_token == rbrace)) { state->keyword = 4; /* a type name */ state->last_u_d = true; return decl; @@ -578,6 +578,34 @@ stop_lit: *e_token++ = *buf_ptr++; code = (state->last_u_d ? unary_op : binary_op); unary_delim = true; + break; + + case '*': + unary_delim = true; + if (!state->last_u_d) { + if (*buf_ptr == '=') + *e_token++ = *buf_ptr++; + code = binary_op; + break; + } + while (*buf_ptr == '*' || isspace((unsigned char)*buf_ptr)) { + if (*buf_ptr == '*') + *e_token++ = *buf_ptr; + if (++buf_ptr >= buf_end) + fill_buffer(); + } + if (ps.in_decl) { + char *tp = buf_ptr; + + while (isalpha((unsigned char)*tp) || + isspace((unsigned char)*tp)) { + if (++tp >= buf_end) + fill_buffer(); + } + if (*tp == '(') + ps.procname[0] = ' '; + } + code = unary_op; break; default: Modified: head/usr.bin/indent/tests/Makefile ============================================================================== --- head/usr.bin/indent/tests/Makefile Sun Jun 3 16:27:40 2018 (r334565) +++ head/usr.bin/indent/tests/Makefile Sun Jun 3 16:42:58 2018 (r334566) @@ -11,6 +11,8 @@ ${PACKAGE}FILES+= declarations.0.stdout ${PACKAGE}FILES+= elsecomment.0 ${PACKAGE}FILES+= elsecomment.0.stdout ${PACKAGE}FILES+= elsecomment.0.pro +${PACKAGE}FILES+= f_decls.0 +${PACKAGE}FILES+= f_decls.0.stdout ${PACKAGE}FILES+= float.0 ${PACKAGE}FILES+= float.0.stdout ${PACKAGE}FILES+= label.0 Added: head/usr.bin/indent/tests/f_decls.0 ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/f_decls.0 Sun Jun 3 16:42:58 2018 (r334566) @@ -0,0 +1,29 @@ +/* $FreeBSD$ */ + +char * x(void) +{ + type identifier; + type *pointer; + unused * value; + (void)unused * value; + + dmax = (double)3 * 10.0; + dmin = (double)dmax * 10.0; + davg = (double)dmax * dmin; + + return NULL; +} + +int * +y(void) { + +} + +int +z(void) { + +} + +int x; +int *y; +int * * * * z; Added: head/usr.bin/indent/tests/f_decls.0.stdout ============================================================================== --- /dev/null 00:00:00 1970 (empty, because file is newly added) +++ head/usr.bin/indent/tests/f_decls.0.stdout Sun Jun 3 16:42:58 2018 (r334566) @@ -0,0 +1,32 @@ +/* $FreeBSD$ */ + +char * +x(void) +{ + type identifier; + type *pointer; + unused *value; + (void)unused * value; + + dmax = (double)3 * 10.0; + dmin = (double)dmax * 10.0; + davg = (double)dmax * dmin; + + return NULL; +} + +int * +y(void) +{ + +} + +int +z(void) +{ + +} + +int x; +int *y; +int ****z;