2

I'm trying to replicate the GNU coding standard using uncrustify. My program has the following function declarations,

static void connect_to_server_cb1 (GObject      *source_object,
                                   GAsyncResult *result,
                                   gpointer      user_data);

static gboolean connect_to_server_cb2 (GObject     *source_object,
                                   GAsyncResult *result,
                                   gpointer      user_data);

static void connect_to_server_cb3 (GObject      *source_object,
                                   GAsyncResult *result,
                                   gpointer      user_data);

I'm expecting output as follows,

static void     connect_to_server_cb1 (GObject      *source_object,
                                       GAsyncResult *result,
                                       gpointer      user_data);

static gboolean connect_to_server_cb2 (GObject      *source_object,
                                       GAsyncResult *result,
                                       gpointer      user_data);

static void     connect_to_server_cb3 (GObject      *source_object,
                                       GAsyncResult *result,
                                       gpointer      user_data);

Which config option I should try to achive this?

smac89
  • 39,374
  • 15
  • 132
  • 179
vishnumotghare
  • 591
  • 1
  • 5
  • 23

2 Answers2

1

I'm not sure that uncrustify can do exactly what you want. You could try to post-process the output with the gcu-lineup-parameters program from GNOME C Utils, which Nautilus already uses for example. The Nautilus source tree contains a run-uncrustify.sh script which does this for each file:

# Aligning prototypes is not working yet, so avoid headers
"$UNCRUSTIFY" -c "$DATA/uncrustify.cfg" --no-backup "$FILE"
"$DATA/lineup-parameters" "$FILE" > "$FILE.temp" && mv "$FILE.temp" "$FILE"

This should work if you only want to process the .c files, but the comment suggests that aligning prototypes in headers is more difficult.

smac89
  • 39,374
  • 15
  • 132
  • 179
0
    # Whether to align variable definitions in prototypes and functions.
    align_func_params               = true     # true/false

    # How to consider (or treat) the '*' in the alignment of variable definitions.
    #
    # 0: Part of the type     'void *   foo;' (default)
    # 1: Part of the variable 'void     *foo;'
    # 2: Dangling             'void    *foo;'
    # Dangling: the '*' will not be taken into account when aligning.
    align_var_def_star_style        = 2        # unsigned number

    # How to consider (or treat) the '&' in the alignment of variable definitions.
    #
    # 0: Part of the type     'long &   foo;' (default)
    # 1: Part of the variable 'long     &foo;'
    # 2: Dangling             'long    &foo;'
    # Dangling: the '&' will not be taken into account when aligning.
    align_var_def_amp_style         = 2        # unsigned number

    # The span for aligning function prototypes.
    #
    # 0: Don't align (default).
    align_func_proto_span           = 4        # unsigned number
CDanU
  • 156
  • 1
  • 9
  • Hi, I tried the above combination, It partially worked. pointers in function declaration are dangling in middle e.g static void * connect_to_server_cb3 (GObject *source_object, GAsyncResult *result, gpointer user_data); – vishnumotghare Jul 22 '20 at 05:37
  • Try out the different options for *align_var_def_star_style* if you don't find a way open a ticket. – CDanU Jul 26 '20 at 22:49