Package: indent
Version: 2.2.11-1
Severity: wishlist
Tags: patch upstream

The patch attached to add an option to fix nested comments by replacing
'/*' with ' *'.

-- System Information:
Debian Release: wheezy/sid
  APT prefers unstable
  APT policy: (500, 'unstable'), (500, 'stable'), (1, 'experimental')
Architecture: i386 (i686)

Kernel: Linux 3.2.0-rc7-686-pae (SMP w/2 CPU cores)
Locale: LANG=en_GB.UTF-8, LC_CTYPE=en_GB.UTF-8 (charmap=UTF-8) (ignored: LC_ALL 
set to en_GB.UTF-8)
Shell: /bin/sh linked to /bin/dash

Versions of packages indent depends on:
ii  dpkg          1.16.1.2      
ii  install-info  4.13a.dfsg.1-4
ii  libc6         2.13-7        

indent recommends no packages.

indent suggests no packages.

-- no debconf information
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 <bugzi...@tut.by>
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,15 @@
         /* We have reached the end of the comment, and it's all on
          * this line. */
 
+         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.
 
+@kindex -fnc
+@kindex --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 -d@var{n}
 @kindex --line-comments-indentation@var{n}
 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 comments.@*
 @xref{Comments}.
 
+@item -fnc
+@itemx --fix-nested-comments
+Fix nested comments.@*
+@xref{Comments}.
+
 @item -gnu
 @itemx --gnu-style
 Use GNU coding style.  This is the default.@*

Reply via email to