Author: pfg Date: Wed Aug 3 22:08:07 2016 New Revision: 303735 URL: https://svnweb.freebsd.org/changeset/base/303735
Log: indent(1): add new -sac and -U options. Add -sac (space after cast) and -nsac options. These control whether space character is put after a cast operator or not. Default is -nsac. Add -U option for providing a file containing list of types. This is needed for properly deciding which asterisks denote unary operation and which denote binary. These come from PostgreSQL. Reference: https://github.com/pstef/freebsd_indent/commit/84b00e3d46dfd6d955b2f481a1f3b275de9ad6d1 https://github.com/pstef/freebsd_indent/commit/49c52cf383fa2a246a1a22c6640a5a21b0f1fd90 Differential Revision: https://reviews.freebsd.org/D6966 (Partial) Submitted by: Piotr Stefaniak Modified: head/usr.bin/indent/args.c head/usr.bin/indent/indent.1 head/usr.bin/indent/indent.c head/usr.bin/indent/indent_globs.h head/usr.bin/indent/lexi.c Modified: head/usr.bin/indent/args.c ============================================================================== --- head/usr.bin/indent/args.c Wed Aug 3 20:21:58 2016 (r303734) +++ head/usr.bin/indent/args.c Wed Aug 3 22:08:07 2016 (r303735) @@ -74,8 +74,12 @@ __FBSDID("$FreeBSD$"); static void scan_profile(FILE *); +#define KEY_FILE 5 /* only used for args */ + const char *option_source = "?"; +void add_typedefs_from_file(const char *str); + /* * N.B.: because of the way the table here is scanned, options whose names are * substrings of other options must occur later; that is, with -lp vs -l, -lp @@ -91,6 +95,7 @@ struct pro { } pro[] = { {"T", PRO_SPECIAL, 0, KEY, 0}, + {"U", PRO_SPECIAL, 0, KEY_FILE, 0}, {"bacc", PRO_BOOL, false, ON, &blanklines_around_conditional_compilation}, {"badp", PRO_BOOL, false, ON, &blanklines_after_declarations_at_proctop}, {"bad", PRO_BOOL, false, ON, &blanklines_after_declarations}, @@ -147,6 +152,7 @@ struct pro { {"npro", PRO_SPECIAL, 0, IGN, 0}, {"npsl", PRO_BOOL, true, OFF, &procnames_start_line}, {"nps", PRO_BOOL, false, OFF, &pointer_as_binop}, + {"nsac", PRO_BOOL, false, OFF, &space_after_cast}, {"nsc", PRO_BOOL, true, OFF, &star_comment_cont}, {"nsob", PRO_BOOL, false, OFF, &swallow_optional_blanklines}, {"nut", PRO_BOOL, true, OFF, &use_tabs}, @@ -154,6 +160,7 @@ struct pro { {"pcs", PRO_BOOL, false, ON, &proc_calls_space}, {"psl", PRO_BOOL, true, ON, &procnames_start_line}, {"ps", PRO_BOOL, false, ON, &pointer_as_binop}, + {"sac", PRO_BOOL, false, ON, &space_after_cast}, {"sc", PRO_BOOL, true, ON, &star_comment_cont}, {"sob", PRO_BOOL, false, ON, &swallow_optional_blanklines}, {"st", PRO_SPECIAL, 0, STDIN, 0}, @@ -295,6 +302,12 @@ found: } break; + case KEY_FILE: + if (*param_start == 0) + goto need_param; + add_typedefs_from_file(param_start); + break; + default: errx(1, "set_option: internal error: p_special %d", p->p_special); } @@ -323,3 +336,21 @@ found: errx(1, "set_option: internal error: p_type %d", p->p_type); } } + +void +add_typedefs_from_file(const char *str) +{ + FILE *file; + char line[BUFSIZ]; + + if ((file = fopen(str, "r")) == NULL) { + fprintf(stderr, "indent: cannot open file %s\n", str); + exit(1); + } + while ((fgets(line, BUFSIZ, file)) != NULL) { + /* Remove trailing whitespace */ + *(line + strcspn(line, " \t\n\r")) = '\0'; + addkey(strdup(line), 4); + } + fclose(file); +} Modified: head/usr.bin/indent/indent.1 ============================================================================== --- head/usr.bin/indent/indent.1 Wed Aug 3 20:21:58 2016 (r303734) +++ head/usr.bin/indent/indent.1 Wed Aug 3 22:08:07 2016 (r303735) @@ -30,7 +30,7 @@ .\" @(#)indent.1 8.1 (Berkeley) 7/1/93 .\" $FreeBSD$ .\" -.Dd March 3, 2012 +.Dd August 3, 2016 .Dt INDENT 1 .Os .Sh NAME @@ -74,6 +74,7 @@ .Op Fl npro .Op Fl pcs | Fl npcs .Op Fl psl | Fl npsl +.Op Fl sac | Fl nsac .Op Fl \&sc | Fl nsc .Bk -words .Op Fl sob | Fl nsob @@ -81,6 +82,7 @@ .Op Fl \&st .Op Fl \&ta .Op Fl troff +.Op Fl U Ns Ar file .Op Fl ut | Fl nut .Op Fl v | Fl \&nv .Sh DESCRIPTION @@ -378,6 +380,11 @@ column 1 \- their types, if any, will be The default is .Fl psl . +.It Fl sac , nsac +Control whether parenthesized type names in casts are followed by a space or +not. +The default is +.Fl nsac . .It Fl \&sc , nsc Enables (disables) the placement of asterisks (`*'s) at the left edge of all comments. @@ -430,6 +437,10 @@ listing in much the same spirit as .Xr vgrind 1 . If the output file is not specified, the default is standard output, rather than formatting in place. +.It Fl U Ns Ar file +Adds type names from +.Ar file +to the list of type keywords. .It Fl ut , nut Enables (disables) the use of tab characters in the output. Tabs are assumed to be aligned on columns divisible by 8. Modified: head/usr.bin/indent/indent.c ============================================================================== --- head/usr.bin/indent/indent.c Wed Aug 3 20:21:58 2016 (r303734) +++ head/usr.bin/indent/indent.c Wed Aug 3 22:08:07 2016 (r303735) @@ -555,7 +555,7 @@ check_type: if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.not_cast_mask) { ps.last_u_d = true; ps.cast_mask &= (1 << ps.p_l_follow) - 1; - ps.want_blank = false; + ps.want_blank = space_after_cast; } else ps.want_blank = true; ps.not_cast_mask &= (1 << ps.p_l_follow) - 1; Modified: head/usr.bin/indent/indent_globs.h ============================================================================== --- head/usr.bin/indent/indent_globs.h Wed Aug 3 20:21:58 2016 (r303734) +++ head/usr.bin/indent/indent_globs.h Wed Aug 3 22:08:07 2016 (r303735) @@ -212,6 +212,7 @@ int use_tabs; /* set true to use t * false uses all spaces */ int auto_typedefs; /* set true to recognize identifiers * ending in "_t" like typedefs */ +int space_after_cast; /* "b = (int) a" vs "b = (int)a" */ /* -troff font state information */ Modified: head/usr.bin/indent/lexi.c ============================================================================== --- head/usr.bin/indent/lexi.c Wed Aug 3 20:21:58 2016 (r303734) +++ head/usr.bin/indent/lexi.c Wed Aug 3 22:08:07 2016 (r303735) @@ -64,7 +64,7 @@ struct templ { int rwcode; }; -struct templ specials[1000] = +struct templ specials[16384] = { {"switch", 7}, {"case", 8}, @@ -595,9 +595,10 @@ addkey(char *key, int val) return; else p++; - if (p >= specials + sizeof specials / sizeof specials[0]) - return; /* For now, table overflows are silently - * ignored */ + if (p >= specials + sizeof(specials) / sizeof(specials[0])) { + fprintf(stderr, "indent: typedef table overflow\n"); + exit(1); + } p->rwd = key; p->rwcode = val; p[1].rwd = NULL; _______________________________________________ svn-src-head@freebsd.org mailing list https://lists.freebsd.org/mailman/listinfo/svn-src-head To unsubscribe, send any mail to "svn-src-head-unsubscr...@freebsd.org"