Description: add an option to fix nested comments Added -fnc/--fix-nested comment option which tries to fix nested comments by replacing '/*' inside comments by a space followed by '*'. By default, this option is turned off. Author: Andrew O. Shadura Last-Update: 2012-01-26 --- a/src/comments.c +++ b/src/comments.c @@ -59,6 +59,9 @@ * `format_col1_comments' ("fc1"): Format comments which * begin in column 1. * + * `fix_nested_comments' ("fnc"): Fix comments which + * have nested opening sequences + * * `unindent_displace' ("d"): The hanging indentation for * comments which do not appear to the right of code. * @@ -190,6 +193,16 @@ /* We have reached the end of the comment, and it's all on * this line. */ + printf("fnc=%d\n", settings.fix_nested_comments); + if (settings.fix_nested_comments) + { + if ((*buf_ptr == '*') && (*(buf_ptr - 1) == '/')) + { + *(e_com - 1) = ' '; + *e_com = '*'; + } + } + if ((*buf_ptr == '*') && (*(buf_ptr + 1) == '/')) { if (buf_ptr == buf_end) --- a/src/args.c +++ b/src/args.c @@ -158,6 +158,7 @@ static int exp_eei = 0; static int exp_fc1 = 0; static int exp_fca = 0; +static int exp_fnc = 0; static int exp_gnu = 0; static int exp_hnl = 0; static int exp_i = 0; @@ -314,6 +315,7 @@ {"hnl", PRO_BOOL, true, ON, &settings.honour_newlines, &exp_hnl}, {"h", PRO_FUNCTION, 0, ONOFF_NA, (int *) usage, &exp_version}, {"gnu", PRO_SETTINGS, 0, ONOFF_NA, GNU_SETTINGS_STRING, &exp_gnu}, + {"fnc", PRO_BOOL, false, ON, &settings.fix_nested_comments, &exp_fnc}, {"fca", PRO_BOOL, true, ON, &settings.format_comments, &exp_fca}, {"fc1", PRO_BOOL, true, ON, &settings.format_col1_comments, &exp_fc1}, {"eei", PRO_BOOL, false, ON, &settings.extra_expression_indent, &exp_eei}, @@ -433,6 +435,7 @@ {"h", PRO_FUNCTION, 0, ONOFF_NA, (int *) usage, &exp_version}, /* This is now the default. */ {"gnu", PRO_SETTINGS, 0, ONOFF_NA, GNU_SETTINGS_STRING, &exp_gnu}, + {"fnc", PRO_BOOL, false, ON, &settings.fix_nested_comments, &exp_fnc}, {"fca", PRO_BOOL, false, ON, &settings.format_comments, &exp_fca}, {"fc1", PRO_BOOL, false, ON, &settings.format_col1_comments, &exp_fc1}, {"eei", PRO_BOOL, false, ON, &settings.extra_expression_indent, &exp_eei}, @@ -548,6 +551,7 @@ {"honour-newlines", "hnl"}, {"help", "h"}, {"gnu-style", "gnu"}, + {"fix-nested-comments", "fnc"}, {"format-first-column-comments", "fc1"}, {"format-all-comments", "fca"}, {"extra-expression-indentation", "eei"}, --- a/src/indent.h +++ b/src/indent.h @@ -268,6 +268,7 @@ int lineup_to_parens; /*!< if true, continued code within parens will be lined up to the open paren */ int honour_newlines; /*!< True when positions at which we read a newline in the input file, should get * a high priority to break long lines at. */ + int fix_nested_comments; /*!< If nested comments are to be fixed */ int format_comments; /*!< If any comments are to be reformatted */ int format_col1_comments; /*!< If comments which start in column 1 are to be magically reformatted */ int extra_expression_indent; /*!< True if continuation lines from the expression part of "if(e)", --- a/doc/indent.texinfo +++ b/doc/indent.texinfo @@ -653,6 +653,12 @@ duration of that comment. The margin is not respected if the comment is not being formatted. address@hidden -fnc address@hidden --fix-nested-comments +If the @option{-fnc} option is specified, all comments with @samp{/*} +embedded will have that character sequence replaced by a space followed +by the character @samp{*} thus eliminating nesting. + @kindex address@hidden @kindex address@hidden If the comment begins a line (i.e., there is no program text to its @@ -1752,6 +1758,11 @@ Do not disable all formatting of address@hidden @xref{Comments}. address@hidden -fnc address@hidden --fix-nested-comments +Fix nested address@hidden address@hidden + @item -gnu @itemx --gnu-style Use GNU coding style. This is the address@hidden