indent(1): don't format function declarations as variables
This commit is contained in:
parent
fc608f4a8c
commit
861356c5ef
@ -1029,30 +1029,31 @@ check_type:
|
||||
|
||||
case funcname:
|
||||
case ident: /* got an identifier or constant */
|
||||
if (ps.in_decl) { /* if we are in a declaration, we must indent
|
||||
* identifier */
|
||||
if (type_code != funcname || !procnames_start_line) {
|
||||
if (!ps.block_init && !ps.dumped_decl_indent && ps.paren_level == 0) {
|
||||
if (troff) {
|
||||
if (ps.want_blank)
|
||||
*e_code++ = ' ';
|
||||
sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
|
||||
e_code += strlen(e_code);
|
||||
} else
|
||||
indent_declaration(dec_ind, tabs_to_var);
|
||||
ps.dumped_decl_indent = true;
|
||||
ps.want_blank = false;
|
||||
}
|
||||
} else {
|
||||
if (ps.want_blank && !(procnames_start_line &&
|
||||
type_code == funcname))
|
||||
*e_code++ = ' ';
|
||||
ps.want_blank = false;
|
||||
if (dec_ind && s_code != e_code) {
|
||||
if (ps.in_decl) {
|
||||
if (type_code == funcname) {
|
||||
ps.in_decl = false;
|
||||
if (procnames_start_line && s_code != e_code) {
|
||||
*e_code = '\0';
|
||||
dump_line();
|
||||
}
|
||||
dec_ind = 0;
|
||||
else if (ps.want_blank) {
|
||||
*e_code++ = ' ';
|
||||
}
|
||||
ps.want_blank = false;
|
||||
}
|
||||
else if (!ps.block_init && !ps.dumped_decl_indent &&
|
||||
ps.paren_level == 0) { /* if we are in a declaration, we
|
||||
* must indent identifier */
|
||||
|
||||
if (troff) {
|
||||
if (ps.want_blank)
|
||||
*e_code++ = ' ';
|
||||
sprintf(e_code, "\n.De %dp+\200p\n", dec_ind * 7);
|
||||
e_code += strlen(e_code);
|
||||
} else
|
||||
indent_declaration(dec_ind, tabs_to_var);
|
||||
ps.dumped_decl_indent = true;
|
||||
ps.want_blank = false;
|
||||
}
|
||||
}
|
||||
else if (sp_sw && ps.p_l_follow == 0) {
|
||||
|
@ -367,12 +367,12 @@ lexi(struct parser_state *state)
|
||||
* token is in fact a declaration keyword -- one that has been
|
||||
* typedefd
|
||||
*/
|
||||
if (((*buf_ptr == '*' && buf_ptr[1] != '=') || isalpha(*buf_ptr) || *buf_ptr == '_')
|
||||
&& !state->p_l_follow
|
||||
&& !state->block_init
|
||||
&& (state->last_token == rparen || state->last_token == semicolon ||
|
||||
state->last_token == decl ||
|
||||
state->last_token == lbrace || state->last_token == rbrace)) {
|
||||
else if (!state->p_l_follow && !state->block_init &&
|
||||
!state->in_stmt &&
|
||||
((*buf_ptr == '*' && buf_ptr[1] != '=') ||
|
||||
isalpha((unsigned char)*buf_ptr)) &&
|
||||
(state->last_token == semicolon || state->last_token == lbrace ||
|
||||
state->last_token == rbrace)) {
|
||||
state->keyword = 4; /* a type name */
|
||||
state->last_u_d = true;
|
||||
return decl;
|
||||
@ -580,6 +580,34 @@ stop_lit:
|
||||
unary_delim = true;
|
||||
break;
|
||||
|
||||
case '*':
|
||||
unary_delim = true;
|
||||
if (!state->last_u_d) {
|
||||
if (*buf_ptr == '=')
|
||||
*e_token++ = *buf_ptr++;
|
||||
code = binary_op;
|
||||
break;
|
||||
}
|
||||
while (*buf_ptr == '*' || isspace((unsigned char)*buf_ptr)) {
|
||||
if (*buf_ptr == '*')
|
||||
*e_token++ = *buf_ptr;
|
||||
if (++buf_ptr >= buf_end)
|
||||
fill_buffer();
|
||||
}
|
||||
if (ps.in_decl) {
|
||||
char *tp = buf_ptr;
|
||||
|
||||
while (isalpha((unsigned char)*tp) ||
|
||||
isspace((unsigned char)*tp)) {
|
||||
if (++tp >= buf_end)
|
||||
fill_buffer();
|
||||
}
|
||||
if (*tp == '(')
|
||||
ps.procname[0] = ' ';
|
||||
}
|
||||
code = unary_op;
|
||||
break;
|
||||
|
||||
default:
|
||||
if (token[0] == '/' && *buf_ptr == '*') {
|
||||
/* it is start of comment */
|
||||
|
@ -11,6 +11,8 @@ ${PACKAGE}FILES+= declarations.0.stdout
|
||||
${PACKAGE}FILES+= elsecomment.0
|
||||
${PACKAGE}FILES+= elsecomment.0.stdout
|
||||
${PACKAGE}FILES+= elsecomment.0.pro
|
||||
${PACKAGE}FILES+= f_decls.0
|
||||
${PACKAGE}FILES+= f_decls.0.stdout
|
||||
${PACKAGE}FILES+= float.0
|
||||
${PACKAGE}FILES+= float.0.stdout
|
||||
${PACKAGE}FILES+= label.0
|
||||
|
29
usr.bin/indent/tests/f_decls.0
Normal file
29
usr.bin/indent/tests/f_decls.0
Normal file
@ -0,0 +1,29 @@
|
||||
/* $FreeBSD$ */
|
||||
|
||||
char * x(void)
|
||||
{
|
||||
type identifier;
|
||||
type *pointer;
|
||||
unused * value;
|
||||
(void)unused * value;
|
||||
|
||||
dmax = (double)3 * 10.0;
|
||||
dmin = (double)dmax * 10.0;
|
||||
davg = (double)dmax * dmin;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int *
|
||||
y(void) {
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
z(void) {
|
||||
|
||||
}
|
||||
|
||||
int x;
|
||||
int *y;
|
||||
int * * * * z;
|
32
usr.bin/indent/tests/f_decls.0.stdout
Normal file
32
usr.bin/indent/tests/f_decls.0.stdout
Normal file
@ -0,0 +1,32 @@
|
||||
/* $FreeBSD$ */
|
||||
|
||||
char *
|
||||
x(void)
|
||||
{
|
||||
type identifier;
|
||||
type *pointer;
|
||||
unused *value;
|
||||
(void)unused * value;
|
||||
|
||||
dmax = (double)3 * 10.0;
|
||||
dmin = (double)dmax * 10.0;
|
||||
davg = (double)dmax * dmin;
|
||||
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int *
|
||||
y(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int
|
||||
z(void)
|
||||
{
|
||||
|
||||
}
|
||||
|
||||
int x;
|
||||
int *y;
|
||||
int ****z;
|
Loading…
x
Reference in New Issue
Block a user