From ae466e022e32b4b72435351b39db7c596626315c Mon Sep 17 00:00:00 2001 From: obrien Date: Sat, 9 Dec 2000 09:45:09 +0000 Subject: "Implement -[n]fcb (formatting of block comments) and attempt to implement no-space=after-sizeof (not optional) and no-space-after 'struct foo *' (not optional). Without these, indent unKNFizes even more perfectly KNF code." Submitted by: bde --- usr.bin/indent/args.c | 2 ++ usr.bin/indent/indent.1 | 10 ++++++++++ usr.bin/indent/indent.c | 6 ++++-- usr.bin/indent/indent_globs.h | 3 +++ usr.bin/indent/lexi.c | 24 ++++++++++++++++++------ usr.bin/indent/pr_comment.c | 12 +++++++++--- 6 files changed, 46 insertions(+), 11 deletions(-) (limited to 'usr.bin/indent') diff --git a/usr.bin/indent/args.c b/usr.bin/indent/args.c index 7a646c0..2e6821f 100644 --- a/usr.bin/indent/args.c +++ b/usr.bin/indent/args.c @@ -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 59ab94d..d03a15f 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,15 @@ 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 08977bd..1a8675581 100644 --- a/usr.bin/indent/indent.c +++ b/usr.bin/indent/indent.c @@ -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_globs.h b/usr.bin/indent/indent_globs.h index ec2df34..5f49f9c 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/lexi.c b/usr.bin/indent/lexi.c index 7a0929f..2db3e0a 100644 --- a/usr.bin/indent/lexi.c +++ b/usr.bin/indent/lexi.c @@ -35,6 +35,7 @@ #ifndef lint static char sccsid[] = "@(#)lexi.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "@(#)$FreeBSD$"; #endif /* not lint */ /* @@ -58,7 +59,7 @@ struct templ { int rwcode; }; -struct templ specials[100] = +struct templ specials[1000] = { "switch", 1, "case", 2, @@ -88,6 +89,8 @@ struct templ specials[100] = "else", 6, "do", 6, "sizeof", 7, + "const", 9, + "volatile", 9, 0, 0 }; @@ -257,18 +260,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/pr_comment.c b/usr.bin/indent/pr_comment.c index 2d4bc90..ec73d6c 100644 --- a/usr.bin/indent/pr_comment.c +++ b/usr.bin/indent/pr_comment.c @@ -35,6 +35,7 @@ #ifndef lint static char sccsid[] = "@(#)pr_comment.c 8.1 (Berkeley) 6/6/93"; +static char rcsid[] = "@(#)$FreeBSD$"; #endif /* not lint */ #include @@ -111,10 +112,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)) { -- cgit v1.1