Hi.

I've created a patch (attached) and sent it already to bug-indent
list. Unfortunately I haven't got any repsponse yet.

The patch solves 2/3 of the problem reported in this bug. It allows for
either:

"function(type *variable)"
"function(type* variable)"

but not

"function(type * variable)"

-- 
Łukasz Stelmach
Samsung R&D Institute Poland
Samsung Electronics

>From e0bee642b7ccdee2f6db251795c423f3e20494c3 Mon Sep 17 00:00:00 2001
From: =?UTF-8?q?=C5=81ukasz=20Stelmach?= <l.stelm...@samsung.com>
Date: Fri, 7 Jun 2013 14:49:43 +0200
Subject: [PATCH] Customise '*' alignment in a pointer declaration
MIME-Version: 1.0
Content-Type: text/plain; charset=UTF-8
Content-Transfer-Encoding: 8bit
Organization: Samsung R&D Institute Poland

Signed-off-by: Łukasz Stelmach <l.stelm...@samsung.com>
---
 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 style.@*
 Do not read @file{.indent.pro} files.@*
 @xref{Invoking indent}.
 
+@item -pal
+@itemx --pointer-align-left
+Put asterisks in pointer declarations on the left of spaces, next to
+types: ``char* p''.
+
+@item -par
+@itemx --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