简体   繁体   中英

How to align function declaration using uncrustify?

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?

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.

    # 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM