svn commit: r309380 - head/usr.bin/indent

Pedro F. Giffuni pfg at FreeBSD.org
Fri Dec 2 01:25:52 UTC 2016


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:;
 	}


More information about the svn-src-all mailing list