From owner-svn-src-head@freebsd.org Fri Dec 2 01:25:52 2016 Return-Path: Delivered-To: svn-src-head@mailman.ysv.freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:1900:2254:206a::19:1]) by mailman.ysv.freebsd.org (Postfix) with ESMTP id AC928C61610; Fri, 2 Dec 2016 01:25:52 +0000 (UTC) (envelope-from pfg@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 mx1.freebsd.org (Postfix) with ESMTPS id 872DA15C2; Fri, 2 Dec 2016 01:25:52 +0000 (UTC) (envelope-from pfg@FreeBSD.org) Received: from repo.freebsd.org ([127.0.1.37]) by repo.freebsd.org (8.15.2/8.15.2) with ESMTP id uB21Pp9B032019; Fri, 2 Dec 2016 01:25:51 GMT (envelope-from pfg@FreeBSD.org) Received: (from pfg@localhost) by repo.freebsd.org (8.15.2/8.15.2/Submit) id uB21PpaF032015; Fri, 2 Dec 2016 01:25:51 GMT (envelope-from pfg@FreeBSD.org) Message-Id: <201612020125.uB21PpaF032015@repo.freebsd.org> X-Authentication-Warning: repo.freebsd.org: pfg set sender to pfg@FreeBSD.org using -f From: "Pedro F. Giffuni" Date: Fri, 2 Dec 2016 01:25:51 +0000 (UTC) To: src-committers@freebsd.org, svn-src-all@freebsd.org, svn-src-head@freebsd.org Subject: svn commit: r309380 - head/usr.bin/indent X-SVN-Group: head 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.23 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: Fri, 02 Dec 2016 01:25:52 -0000 Author: pfg Date: Fri Dec 2 01:25:51 2016 New Revision: 309380 URL: https://svnweb.freebsd.org/changeset/base/309380 Log: indent(1): Fix indent's confusion about custom FreeBSD macros. Teach indent(1) about storage-class specifiers. Don't assume "in_parameter_declaration" state if "in_decl" hasn't been set. Don't set "in_decl" for storage-class specifiers. That set of changes helps with recognizing the difference between file scope declarations like this: static LIST_HEAD(, alq) ald_active; static int ald_shuttingdown = 0; struct thread *ald_thread; and old style function declarators like this: static int do_execve(td, args, mac_p) struct thread *td; struct image_args *args; struct mac *mac_p; { Unfortunately, at the same time this change makes indent(1) require explicit int in declarations like "static a;", in order to understand that it's part of a declaration. On the other hand, declarations like in the first example are no longer indented as if ald_shuttingdown and ald_thread were parameters of a function named LIST_HEAD. Submitted by: Piotr Stefaniak Modified: head/usr.bin/indent/indent.c head/usr.bin/indent/indent_codes.h head/usr.bin/indent/lexi.c Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Fri Dec 2 00:23:10 2016 (r309379) +++ head/usr.bin/indent/indent.c Fri Dec 2 01:25:51 2016 (r309380) @@ -920,8 +920,11 @@ check_type: } goto copy_id; /* move the token into line */ - case decl: /* we have a declaration type (int, register, - * etc.) */ + case storage: + prefix_blankline_requested = 0; + goto copy_id; + + case decl: /* we have a declaration type (int, etc.) */ parse(decl); /* let parser worry about indentation */ if (ps.last_token == rparen && ps.tos <= 1) { ps.in_parameter_declaration = 1; Modified: head/usr.bin/indent/indent_codes.h ============================================================================== --- head/usr.bin/indent/indent_codes.h Fri Dec 2 00:23:10 2016 (r309379) +++ head/usr.bin/indent/indent_codes.h Fri Dec 2 01:25:51 2016 (r309380) @@ -69,3 +69,4 @@ #define elsehead 31 #define period 32 #define strpfx 33 +#define storage 34 Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Fri Dec 2 00:23:10 2016 (r309379) +++ head/usr.bin/indent/lexi.c Fri Dec 2 01:25:51 2016 (r309380) @@ -70,6 +70,7 @@ struct templ { */ struct templ specials[] = { + {"auto", 10}, {"break", 9}, {"case", 8}, {"char", 4}, @@ -79,7 +80,7 @@ struct templ specials[] = {"double", 4}, {"else", 6}, {"enum", 3}, - {"extern", 4}, + {"extern", 10}, {"float", 4}, {"for", 5}, {"global", 4}, @@ -88,14 +89,14 @@ struct templ specials[] = {"int", 4}, {"long", 4}, {"offsetof", 1}, - {"register", 4}, + {"register", 10}, {"return", 9}, {"short", 4}, {"sizeof", 2}, - {"static", 4}, + {"static", 10}, {"struct", 3}, {"switch", 7}, - {"typedef", 4}, + {"typedef", 10}, {"union", 3}, {"unsigned", 4}, {"void", 4}, @@ -312,6 +313,9 @@ lexi(void) case 6: /* do, else */ return (sp_nparen); + case 10: /* storage class specifier */ + return (storage); + default: /* all others are treated like any other * identifier */ return (ident); @@ -323,7 +327,8 @@ lexi(void) if (*tp++ == ')' && (*tp == ';' || *tp == ',')) goto not_proc; strncpy(ps.procname, token, sizeof ps.procname - 1); - ps.in_parameter_declaration = 1; + if (ps.in_decl) + ps.in_parameter_declaration = 1; rparen_count = 1; not_proc:; }