added indent feature
"Kevin Lussier" <[email protected]>
| Newsgroups | gmane.comp.gnu.indent.bugs |
|---|---|
| Message-ID | <96E2B1E54FC04A40B57769BD89F2D60EB26076@exchange1.codegreennetworks.com> |
Hello,
I have added a new option to the gnu indent program that I think others
may find useful. Basically the option allows the user to turn off
indenting when 'extern "C" {' is seen.
Four files were modified: args.c, indent.h, lexi.c and parse.c. Their
respective diff files are attached.
Thanks,
Kevin
_______________________________________________
bug-indent mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/bug-indent
parse.c.diff
(application/octet-stream, 1.5 KB)
*** indent-2.2.9.mod/src/parse.c 2007-08-22 09:41:58.000000000 -0700
--- indent-2.2.9/src/parse.c 2002-08-04 10:08:41.000000000 -0700
***************
*** 77,83 ****
parser_state_tos->i_l_follow = 0;
parser_state_tos->ind_level = 0;
parser_state_tos->last_u_d = false;
- parser_state_tos->last_extern_c = false;
parser_state_tos->p_l_follow = 0;
parser_state_tos->paren_level = 0;
parser_state_tos->paren_depth = 0;
--- 77,82 ----
***************
*** 314,325 ****
}
else if (parser_state_tos->p_stack[parser_state_tos->tos] == decl)
{
! if ((parser_state_tos->last_extern_c == false) ||
! (settings.indent_after_extern_c == true))
! {
! parser_state_tos->i_l_follow += settings.ind_size;
! }
!
if ( ( (parser_state_tos->last_rw == rw_struct_like) ||
(parser_state_tos->last_rw == rw_enum)) &&
( (parser_state_tos->block_init != 1) ||
--- 313,320 ----
}
else if (parser_state_tos->p_stack[parser_state_tos->tos] == decl)
{
! parser_state_tos->i_l_follow += settings.ind_size;
!
if ( ( (parser_state_tos->last_rw == rw_struct_like) ||
(parser_state_tos->last_rw == rw_enum)) &&
( (parser_state_tos->block_init != 1) ||
args.c.diff
(application/octet-stream, 2.5 KB)
*** indent-2.2.9.mod/src/args.c 2007-08-22 09:33:50.000000000 -0700
--- indent-2.2.9/src/args.c 2002-11-10 13:02:48.000000000 -0800
***************
*** 149,155 ****
static int exp_ut = 0;
static int exp_v = 0;
static int exp_version = 0;
- static int exp_iaec = 0;
/* The following structure is controlled by command line parameters and
* their meaning is explained in indent.h. */
--- 149,154 ----
***************
*** 297,304 ****
{"bacc", PRO_BOOL, false, ON, &settings.blanklines_around_conditional_compilation, &exp_bacc},
{"T", PRO_KEY, 0, ONOFF_NA, 0, &exp_T},
{"ppi", PRO_INT, 0, ONOFF_NA, &settings.force_preproc_width, &exp_ppi},
- {"niaec", PRO_BOOL, true, OFF, &settings.indent_after_extern_c, &exp_iaec},
- {"iaec", PRO_BOOL, false, ON, &settings.indent_after_extern_c, &exp_iaec},
/* Signify end of structure. */
{0, PRO_IGN, 0, ONOFF_NA, 0, 0}
};
--- 296,301 ----
***************
*** 413,420 ****
{"bacc", PRO_BOOL, false, ON, &settings.blanklines_around_conditional_compilation, &exp_bacc},
{"T", PRO_KEY, 0, ONOFF_NA, 0, &exp_T},
{"ppi", PRO_INT, 0, ONOFF_NA, &settings.force_preproc_width, &exp_ppi},
- {"niaec", PRO_BOOL, true, OFF, &settings.indent_after_extern_c, &exp_iaec},
- {"iaec", PRO_BOOL, false, ON, &settings.indent_after_extern_c, &exp_iaec},
/* Signify end of structure. */
{0, PRO_IGN, 0, ONOFF_NA, 0, 0}
};
--- 410,415 ----
***************
*** 540,547 ****
{"berkeley", "orig"},
{"Bill-Shannon", "bs"},
{"preprocessor-indentation", "ppi"},
- {"dont-indent-after-extern-c", "niaec"},
- {"indent-after-extern-c", "iaec"},
{0, 0},
};
--- 535,540 ----
indent.h.diff
(application/octet-stream, 1.2 KB)
*** indent-2.2.9.mod/src/indent.h 2007-08-22 09:41:40.000000000 -0700
--- indent-2.2.9/src/indent.h 2002-11-10 13:02:48.000000000 -0800
***************
*** 254,260 ****
int brace_indent; /* number of spaces to indent braces from the suround if, while, etc. in -bl
* (bype_2 == 0) code */
int expect_output_file; /* Means "-o" was specified. */
- int indent_after_extern_c; /* when true, 'extern "C" {' will cause subsequent code to be indented */
} user_options_ty;
extern user_options_ty settings;
--- 254,259 ----
***************
*** 371,378 ****
* middle of a stmt */
int last_u_d; /* set to true after scanning a token which
* forces a following operator to be unary */
- int last_extern_c; /* set to true if the last thing scanned was
- * 'extern "C"' */
int p_l_follow; /* used to remember how to indent following
* statement */
int paren_level; /* parenthesization level. used to indent
--- 370,375 ----
lexi.c.diff
(application/octet-stream, 824 B)
*** indent-2.2.9.mod/src/lexi.c 2007-08-15 09:14:44.000000000 -0700
--- indent-2.2.9/src/lexi.c 2002-08-04 10:08:41.000000000 -0700
***************
*** 252,259 ****
/* we have a character or number */
templ_ty *p;
- parser_state_tos->last_extern_c = false;
-
if (isdigit (*buf_ptr) ||
((buf_ptr[0] == '.') && isdigit (buf_ptr[1])))
{
--- 252,257 ----
***************
*** 770,781 ****
}
token_end = buf_ptr;
- /* check for 'extern "C"' */
- if ((last_code = decl) && (qchar == '"') &&
- ((token_end - token) == 3) && (token[1] == 'C'))
- {
- parser_state_tos->last_extern_c = true;
- }
code = ident;
break;
--- 768,773 ----