"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
This commit is contained in:
parent
fc3438d892
commit
a5e1cac0f5
Notes:
svn2git
2020-12-20 02:59:44 +00:00
svn path=/head/; revision=69795
@ -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,
|
||||
|
@ -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
|
||||
|
@ -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 @@ main(argc, argv)
|
||||
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 @@ main(argc, argv)
|
||||
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 */
|
||||
|
@ -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
|
||||
|
@ -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);
|
||||
|
@ -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 <stdio.h>
|
||||
@ -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)) {
|
||||
|
Loading…
Reference in New Issue
Block a user