[nautilus/wip/csoriano/uncrustify: 9/9] general: add uncrustify script
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/uncrustify: 9/9] general: add uncrustify script
- Date: Mon, 18 Apr 2016 17:09:46 +0000 (UTC)
commit 6ae53f99be262cf8389ea2742325f1b80f7f120f
Author: Carlos Soriano <csoriano gnome org>
Date: Mon Apr 18 18:57:12 2016 +0200
general: add uncrustify script
The current style of nautilus is rather poor and mixes at least 3
different code styles.
Specific issues that affect my personal performance are:
- tabs for multiline alignment.
- mix of tabs and spaces.
- errors on no braced one liners conditionals.
- errors on non braced case statements with variable declarations.
So I would say requirements for the style is to address the previous
issues and also be well known. I don't want new contributors to see a
new style completely different from C books authors.
So far, I found Allman (aka BSD) style which seems the choice of most C
books authors as far as I can see on internet and address the previous
issues.
So as a matter of practicity I'm going to convert all Nautilus style to
this one, and if the next person who contributes most on Nautilus has
a different choice, please feel free to change whatever makes your
performance the best.
data/run-uncrustify.sh | 10 ++++
data/uncrustify.cfg | 121 ++++++++++++++++++++++++++++++++++++++++++++++
test/uncrustify-sample.c | 63 ++++++++++++++++++++++++
3 files changed, 194 insertions(+), 0 deletions(-)
---
diff --git a/data/run-uncrustify.sh b/data/run-uncrustify.sh
new file mode 100755
index 0000000..0c037e7
--- /dev/null
+++ b/data/run-uncrustify.sh
@@ -0,0 +1,10 @@
+#!/bin/bash
+
+#for DIR in ../src ../libnautilus-private ../nautilus-desktop ../test ../libnautilus-extension ../eel
../nautilus-sendto-extension
+for DIR in ../libnautilus-private
+do
+ # Aligning prototypes is not working yet, so avoid headers
+ #uncrustify -c kr-gnome-indent.cfg --no-backup $(find $DIR -name "*.[ch]")
+ uncrustify -c uncrustify.cfg --no-backup $(find $DIR -name "*.c")
+done
+
diff --git a/data/uncrustify.cfg b/data/uncrustify.cfg
new file mode 100644
index 0000000..18683a8
--- /dev/null
+++ b/data/uncrustify.cfg
@@ -0,0 +1,121 @@
+#
+# This program is free software; you can redistribute it and/or modify
+# it under the terms of the GNU General Public License as published by
+# the Free Software Foundation; either version 2, or (at your option)
+# any later version.
+#
+# This program is distributed in the hope that it will be useful,
+# but WITHOUT ANY WARRANTY; without even the implied warranty of
+# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+# GNU General Public License for more details.
+#
+# You should have received a copy of the GNU General Public License
+# along with this program; if not, write to the Free Software
+# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
+#
+# Allman style
+#
+
+# indent using tabs
+output_tab_size = 4
+indent_columns = output_tab_size
+indent_with_tabs = 0
+
+# indent case
+indent_switch_case = indent_columns
+indent_case_brace = 0
+
+# newlines
+newlines = lf
+nl_after_semicolon = true
+nl_end_of_file = force
+
+# spaces
+sp_return_paren = force # "return (1);" vs "return(1);"
+sp_sizeof_paren = force # "sizeof (int)" vs "sizeof(int)"
+sp_assign = force
+sp_arith = force
+sp_bool = force
+sp_compare = force
+sp_after_comma = force
+sp_case_label = force
+sp_func_call_paren = force # "foo (" vs "foo("
+sp_func_proto_paren = force # "int foo ();" vs "int foo();"
+sp_before_ptr_star = force
+sp_after_ptr_star_qualifier = force # "const char * const" vs. "const char *const"
+sp_after_ptr_star = remove
+sp_between_ptr_star = remove # "**var" vs "* *var"
+sp_inside_paren = remove # "( 1 )" vs "(1)"
+sp_inside_fparen = remove # "( 1 )" vs "(1)" - functions
+sp_inside_sparen = remove # "( 1 )" vs "(1)" - if/for/etc
+sp_after_cast = remove # "(int) a" vs "(int)a"
+sp_func_call_user_paren = remove # For gettext, "_()" vs. "_ ()"
+set func_call_user _ N_ C_ # Needed for sp_after_cast
+sp_before_semi = remove
+sp_paren_paren = remove # Space between (( and ))
+
+eat_blanks_before_close_brace = true
+eat_blanks_after_open_brace = true
+
+# Allman style for curly braces
+nl_assign_brace = force
+nl_enum_brace = force
+nl_union_brace = force
+nl_struct_brace = force
+nl_class_brace = force
+nl_do_brace = force
+nl_if_brace = force
+nl_for_brace = force
+nl_else_brace = force
+nl_while_brace = force
+nl_switch_brace = force
+nl_before_case = true
+nl_fcall_brace = force
+nl_fdef_brace = force
+nl_brace_else = force
+nl_brace_while = force
+nl_case_colon_brace = force
+nl_after_brace_open = true
+
+# Function calls and parameters
+nl_func_paren = remove
+nl_func_def_paren = remove
+nl_func_decl_start = remove
+nl_func_def_start = remove
+nl_func_decl_args = force
+nl_func_def_args = force
+nl_func_decl_end = remove
+nl_func_def_end = remove
+
+# Code modifying options (non-whitespace)
+mod_full_brace_do = force
+mod_full_brace_for = force
+mod_full_brace_function = force
+mod_full_brace_if = force
+mod_full_brace_while = force
+mod_case_brace = add
+
+# Align
+align_func_params = true
+align_single_line_func = true
+align_var_def_star_style = 2
+
+# one liners
+nl_func_leave_one_liners = true
+nl_enum_leave_one_liners = true
+nl_assign_leave_one_liners = true
+
+# Comments
+cmt_cpp_to_c = true # "/* */" vs. "//"
+cmt_convert_tab_to_spaces = true
+#cmt_reflow_mode = 2 # Full reflow (seems doesn't work quite well, it
doesn't reorder the comments)
+#cmt_width = 80 # Line width
+cmt_star_cont = true # Whether to put a star on subsequent comment lines
+cmt_sp_after_star_cont = 1 # The number of spaces to insert after the star on
subsequent comment lines
+cmt_c_nl_start = false # false/true
+cmt_c_nl_end = true # false/true
+
+# Encoding
+utf8_bom = remove
+utf8_force = true
+
diff --git a/test/uncrustify-sample.c b/test/uncrustify-sample.c
new file mode 100644
index 0000000..2ed14be
--- /dev/null
+++ b/test/uncrustify-sample.c
@@ -0,0 +1,63 @@
+/*
+Extremely poorly formatted code to test uncrustify.cfg against the contiki code style
+ */
+
+#if defined (FOO)
+ # define BAR 3
+#else
+ # define BAR 3
+# endif
+
+/* Aligment of parameters doesn't work as completely expected. Should align the
+ * stars themselves. */
+static int some_function ( int *f , char **c, LongTypeException a) {
+
+ /* This is indented with a tab. Should become spaces */
+ int a = 5; // This should become a C comment
+ int d= - 10; /* Space around assignment, No space between - and 10 */
+ int* b; /* no space before the *, yes space between * and variable name */
+
+ some_function(
+ a,
+ b
+ )
+
+/* Should indent the for correctly and sort out spacing mess:
+ - for(i = 0; i < 10; ++i)
+ - Should pull the opening brace up to the same line as the for
+*/
+for( i=0 ;i<10; ++ i ) { if (a < 0) {
+ a= ! c ; /* Should add space after a and remove space before and after c */
+
+ /* } else { always in the same line */
+ }
+ else
+ {
+ /* incorrect indentation here */
+
+ f();
+ }
+ }
+
+ b = & c; /* 'address of' adjacent to variable */
+ * b = 3; /* dereference: no space */
+
+ /* Should automatically add braces below */
+ if(a == 0)
+ printf ( "a\n") ;
+
+ while(1) ; /* This needs fixed */
+
+ switch(a) {
+ case 3 :
+4;
+5;
+ break;
+ }
+
+ /* No blank lines before the closing brace */
+
+ return (-1); /* No parenthesis around return values */
+
+
+}
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]