diff options
| -rw-r--r-- | usr.bin/indent/args.c | 4 | ||||
| -rw-r--r-- | usr.bin/indent/indent.1 | 13 | ||||
| -rw-r--r-- | usr.bin/indent/indent.c | 8 | ||||
| -rw-r--r-- | usr.bin/indent/indent_codes.h | 1 | ||||
| -rw-r--r-- | usr.bin/indent/indent_globs.h | 3 | ||||
| -rw-r--r-- | usr.bin/indent/io.c | 2 | ||||
| -rw-r--r-- | usr.bin/indent/lexi.c | 25 | ||||
| -rw-r--r-- | usr.bin/indent/parse.c | 2 | ||||
| -rw-r--r-- | usr.bin/indent/pr_comment.c | 13 |
9 files changed, 57 insertions, 14 deletions
diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c index 7a646c0fcfd9..3ddab3309a2f 100644 --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)args.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$FreeBSD$"; + "@(#)$FreeBSD$"; #endif /* not lint */ /* @@ -110,6 +110,7 @@ struct pro { "fbx", PRO_FONT, 0, 0, (int *) &boxcomf, "fb", PRO_FONT, 0, 0, (int *) &bodyf, "fc1", PRO_BOOL, true, ON, &format_col1_comments, + "fcb", PRO_BOOL, true, ON, &format_block_comments, "fc", PRO_FONT, 0, 0, (int *) &scomf, "fk", PRO_FONT, 0, 0, (int *) &keywordf, "fs", PRO_FONT, 0, 0, (int *) &stringf, @@ -131,6 +132,7 @@ struct pro { "neei", PRO_BOOL, false, OFF, &extra_expression_indent, "nei", PRO_BOOL, true, OFF, &ps.else_if, "nfc1", PRO_BOOL, true, OFF, &format_col1_comments, + "nfcb", PRO_BOOL, true, OFF, &format_block_comments, "nip", PRO_BOOL, true, OFF, &ps.indent_parameters, "nlp", PRO_BOOL, true, OFF, &lineup_to_parens, "npcs", PRO_BOOL, false, OFF, &proc_calls_space, diff --git a/usr.bin/indent/indent.1 b/usr.bin/indent/indent.1 index 59ab94d61ebd..58c5c13210d4 100644 --- a/usr.bin/indent/indent.1 +++ b/usr.bin/indent/indent.1 @@ -63,6 +63,7 @@ .Op Fl \&di Ns Ar n .Bk -words .Op Fl fc1 | Fl nfc1 +.Op Fl fcb | Fl nfcb .Ek .Op Fl i Ns Ar n .Op Fl \&ip | Fl nip @@ -245,6 +246,18 @@ hand formatted by the programmer. In such cases, should be used. The default is .Fl fc1 . +.It Fl fcb , nfcb +Enables (disables) the formatting of block comments (ones that begin +with `/*\\n'). +Often, block comments have been not so carefully hand formatted by the +programmer, but reformatting that would just change the line breaks is not +wanted. +In such cases, +.Fl nfcb +should be used. +Block comments are then handled like box comments. +The default is +.Fl fcb . .It Fl i Ns Ar n The number of spaces for one indentation level. The default is 8. .It Fl \&ip , nip diff --git a/usr.bin/indent/indent.c b/usr.bin/indent/indent.c index 08977bdd23cc..3b82e95f38de 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -46,7 +46,7 @@ static const char copyright[] = static char sccsid[] = "@(#)indent.c 5.17 (Berkeley) 6/7/93"; #endif static const char rcsid[] = - "$FreeBSD$"; + "@(#)$FreeBSD$"; #endif /* not lint */ #include <sys/param.h> @@ -165,6 +165,7 @@ main(argc, argv) cuddle_else = 1; /* -ce */ ps.unindent_displace = 0; /* -d0 */ ps.case_indent = 0; /* -cli0 */ + format_block_comments = 1; /* -fcb */ format_col1_comments = 1; /* -fc1 */ procnames_start_line = 1; /* -psl */ proc_calls_space = 0; /* -npcs */ @@ -533,7 +534,9 @@ check_type: if (ps.cast_mask & (1 << ps.p_l_follow) & ~ps.sizeof_mask) { ps.last_u_d = true; ps.cast_mask &= (1 << ps.p_l_follow) - 1; - } + ps.want_blank = false; + } else + ps.want_blank = true; ps.sizeof_mask &= (1 << ps.p_l_follow) - 1; if (--ps.p_l_follow < 0) { ps.p_l_follow = 0; @@ -543,7 +546,6 @@ check_type: ps.paren_level = ps.p_l_follow; /* then indent it */ *e_code++ = token[0]; - ps.want_blank = true; if (sp_sw && (ps.p_l_follow == 0)) { /* check for end of if * (...), or some such */ diff --git a/usr.bin/indent/indent_codes.h b/usr.bin/indent/indent_codes.h index 8373d4e933ae..e1ff294e2576 100644 --- a/usr.bin/indent/indent_codes.h +++ b/usr.bin/indent/indent_codes.h @@ -33,6 +33,7 @@ * SUCH DAMAGE. * * @(#)indent_codes.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD$ */ #define newline 1 diff --git a/usr.bin/indent/indent_globs.h b/usr.bin/indent/indent_globs.h index ec2df34c928e..5f49f9c0b683 100644 --- a/usr.bin/indent/indent_globs.h +++ b/usr.bin/indent/indent_globs.h @@ -33,6 +33,7 @@ * SUCH DAMAGE. * * @(#)indent_globs.h 8.1 (Berkeley) 6/6/93 + * $FreeBSD$ */ #define BACKSLASH '\\' @@ -155,6 +156,8 @@ int procnames_start_line; /* if true, the names of procedures * name) */ int proc_calls_space; /* If true, procedure calls look like: * foo(bar) rather than foo (bar) */ +int format_block_comments; /* true if comments beginning with + * `/*\n' are to be reformatted */ int format_col1_comments; /* If comments which start in column 1 * are to be magically reformatted * (just like comments that begin in diff --git a/usr.bin/indent/io.c b/usr.bin/indent/io.c index 596c849d6c35..bc186e713eb5 100644 --- a/usr.bin/indent/io.c +++ b/usr.bin/indent/io.c @@ -38,7 +38,7 @@ static char sccsid[] = "@(#)io.c 8.1 (Berkeley) 6/6/93"; #endif static const char rcsid[] = - "$FreeBSD$"; + "@(#)$FreeBSD$"; #endif /* not lint */ #include <ctype.h> diff --git a/usr.bin/indent/lexi.c b/usr.bin/indent/lexi.c index 7a0929f13682..67fea44d153e 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -35,6 +35,8 @@ #ifndef lint static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93"; +static const char rcsid[] = + "@(#)$FreeBSD$"; #endif /* not lint */ /* @@ -58,7 +60,7 @@ struct templ { int rwcode; }; -struct templ specials[100] = +struct templ specials[1000] = { "switch", 1, "case", 2, @@ -88,6 +90,8 @@ struct templ specials[100] = "else", 6, "do", 6, "sizeof", 7, + "const", 9, + "volatile", 9, 0, 0 }; @@ -257,18 +261,27 @@ lexi() return (casestmt); case 3: /* a "struct" */ - if (ps.p_l_follow) - break; /* inside parens: cast */ + /* + * Next time around, we may want to know that we have had a + * 'struct' + */ l_struct = true; /* - * Next time around, we will want to know that we have had a - * 'struct' + * Fall through to test for a cast, function prototype or + * sizeof(). */ case 4: /* one of the declaration keywords */ if (ps.p_l_follow) { ps.cast_mask |= 1 << ps.p_l_follow; - break; /* inside parens: cast */ + + /* + * Forget that we saw `struct' if we're in a sizeof(). + */ + if (ps.sizeof_mask) + l_struct = false; + + break; /* inside parens: cast, prototype or sizeof() */ } last_code = decl; return (decl); diff --git a/usr.bin/indent/parse.c b/usr.bin/indent/parse.c index eeeb30acc22f..33ce79e28a8e 100644 --- a/usr.bin/indent/parse.c +++ b/usr.bin/indent/parse.c @@ -35,6 +35,8 @@ #ifndef lint static char sccsid[] = "@(#)parse.c 8.1 (Berkeley) 6/6/93"; +static const char rcsid[] = + "@(#)$FreeBSD$"; #endif /* not lint */ #include <stdio.h> diff --git a/usr.bin/indent/pr_comment.c b/usr.bin/indent/pr_comment.c index 2d4bc90567e0..357d9072db46 100644 --- a/usr.bin/indent/pr_comment.c +++ b/usr.bin/indent/pr_comment.c @@ -35,6 +35,8 @@ #ifndef lint static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; +static const char rcsid[] = + "@(#)$FreeBSD$"; #endif /* not lint */ #include <stdio.h> @@ -111,10 +113,15 @@ pr_comment() ps.com_col = 1; } else { - if (*buf_ptr == '-' || *buf_ptr == '*') { - ps.box_com = true; /* a comment with a '-' or '*' immediately + if (*buf_ptr == '-' || *buf_ptr == '*' || + (*buf_ptr == '\n' && !format_block_comments)) { + ps.box_com = true; /* A comment with a '-' or '*' immediately * after the /* is assumed to be a boxed - * comment */ + * comment. A comment with a newline + * immediately after the /* is assumed to + * be a block comment and is treated as a + * box comment unless format_block_comments + * is nonzero (the default). */ break_delim = 0; } if ( /* ps.bl_line && */ (s_lab == e_lab) && (s_code == e_code)) { |
