bug-indent
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[PATCH] Customise '*' alignment in a pointer declaration


From: Łukasz Stelmach
Subject: [PATCH] Customise '*' alignment in a pointer declaration
Date: Tue, 11 Jun 2013 10:11:05 +0200

Signed-off-by: Łukasz Stelmach <address@hidden>
---
Hi.

This patch enables one to customise the style of pointer type
declaration. With -pal -par one can choose between "char* a" and "char
*a", respectively.

 doc/indent.texinfo |   10 ++++++++++
 src/args.c         |    7 +++++++
 src/handletoken.c  |   14 +++++++++++++-
 src/indent.h       |    1 +
 4 files changed, 31 insertions(+), 1 deletion(-)

diff --git a/doc/indent.texinfo b/doc/indent.texinfo
index 08f35f6..e652d52 100644
--- a/doc/indent.texinfo
+++ b/doc/indent.texinfo
@@ -1958,6 +1958,16 @@ Use the original Berkeley coding address@hidden
 Do not read @file{.indent.pro} address@hidden
 @xref{Invoking indent}.
 
address@hidden -pal
address@hidden --pointer-align-left
+Put asterisks in pointer declarations on the left of spaces, next to
+types: ``char* p''.
+
address@hidden -par
address@hidden --pointer-align-left
+Put asterisks in pointer declarations on the righ of spaces, next to
+types: ``char *p''. This is the default behaviour.
+
 @item -pcs  
 @itemx --space-after-procedure-calls
 Insert a space between the name of the 
diff --git a/src/args.c b/src/args.c
index f392cce..a0603c2 100644
--- a/src/args.c
+++ b/src/args.c
@@ -191,6 +191,7 @@ static int exp_ts   = 0;
 static int exp_ut   = 0;
 static int exp_v    = 0;
 static int exp_version = 0;
+static int exp_par  = 0;
 
 /**
  * The following structure is controlled by command line parameters and
@@ -350,6 +351,8 @@ const pro_ty pro[] =
     {"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},
+    {"pal",     PRO_BOOL,                            true,      OFF, 
&settings.pointer_align_right,              &exp_par},
+    {"par",     PRO_BOOL,                            true,       ON, 
&settings.pointer_align_right,              &exp_par},
     /* Signify end of structure.  */
     {0,         PRO_IGN,                                0, ONOFF_NA, 0,        
                                  0}
 };
@@ -469,6 +472,8 @@ const pro_ty pro[] =
     {"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},
+    {"pal",     PRO_BOOL,                            true,      OFF, 
&settings.pointer_align_right,              &exp_par},
+    {"par",     PRO_BOOL,                            true,       ON, 
&settings.pointer_align_right,              &exp_par},
     /* Signify end of structure.  */
     {0,         PRO_IGN,                                0, ONOFF_NA, 0,        
                                  0}
 };
@@ -598,6 +603,8 @@ const long_option_conversion_ty option_conversions[] =
     {"berkeley",                                    "orig"},
     {"Bill-Shannon",                                "bs"},
     {"preprocessor-indentation",                    "ppi"},
+    {"pointer-align-right",                         "par"},
+    {"pointer-align-left",                          "pal"},
     /* Signify end of structure.  */
     {0,                                             0},
 };
diff --git a/src/handletoken.c b/src/handletoken.c
index 7b0338c..806c693 100644
--- a/src/handletoken.c
+++ b/src/handletoken.c
@@ -575,11 +575,15 @@ static void handle_token_unary_op(
 {
     char           * t_ptr;
     
-    if (parser_state_tos->want_blank)
+    if (parser_state_tos->want_blank &&
+       !(parser_state_tos->in_decl &&
+          !settings.pointer_align_right &&
+          *token == '*'))
     {
         set_buf_break (bb_unary_op, paren_target);
         *(e_code++) = ' ';
         *e_code = '\0';     /* null terminate code sect */
+        parser_state_tos->want_blank = false;
     }
     else if (can_break)
     {
@@ -628,6 +632,14 @@ static void handle_token_unary_op(
             *(e_code++) = *t_ptr;
         }
 
+        if (parser_state_tos->want_blank &&
+            !(parser_state_tos->in_decl &&
+              settings.pointer_align_right &&
+              *token == '*'))
+        {
+            set_buf_break (bb_unary_op, paren_target);
+           *(e_code++) = ' ';
+        }
         *e_code = '\0';     /* null terminate code sect */
     }
 
diff --git a/src/indent.h b/src/indent.h
index 60ccb5a..b418682 100644
--- a/src/indent.h
+++ b/src/indent.h
@@ -318,6 +318,7 @@ typedef struct user_options_st
     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 pointer_align_right;  /*!< true: "char *a", false: "char* a" */
 } user_options_ty;
 
 extern user_options_ty settings;
-- 
1.7.9.5





reply via email to

[Prev in Thread] Current Thread [Next in Thread]