Przeglądaj źródła

Add a code formatter

Scott Lahteine 4 lat temu
rodzic
commit
9a0b0d8469

+ 30
- 0
buildroot/bin/format_code Wyświetl plik

@@ -0,0 +1,30 @@
1
+#!/usr/bin/env bash
2
+#
3
+# format_code [dir/file...]
4
+#
5
+
6
+HERE=`dirname $0`
7
+
8
+while [[ $# -gt 0 ]]; do
9
+
10
+  val="$1"
11
+
12
+  if [ -d "$val" ]; then
13
+
14
+    find $val -name *.cpp -exec "$HERE/uncrust" '{}' \;
15
+
16
+  elif [ -d "./Marlin/src/$val" ]; then
17
+
18
+    find "./Marlin/src/$val" -name *.cpp -exec "$HERE/uncrust" '{}' \;
19
+
20
+  elif [ -f "./Marlin/src/$val" ]; then
21
+
22
+    uncrust "./Marlin/src/$val"
23
+
24
+  elif [ -f "$val" ]; then
25
+
26
+    uncrust "$val"
27
+
28
+  fi
29
+
30
+done

+ 16
- 0
buildroot/bin/uncrust Wyświetl plik

@@ -0,0 +1,16 @@
1
+#!/usr/bin/env bash
2
+#
3
+# Run uncrustify for a file in-place
4
+#
5
+
6
+TMPDIR=`mktemp -d`
7
+
8
+# Reformat a single file to tmp/
9
+uncrustify -c ./buildroot/share/extras/uncrustify.cfg -f "$1" >$TMPDIR/uncrustify.out
10
+
11
+# Replace the original file
12
+cp "$TMPDIR/uncrustify.out" "$1"
13
+
14
+# Clean up, deliberately
15
+rm "$TMPDIR/uncrustify.out"
16
+rmdir "$TMPDIR"

+ 295
- 0
buildroot/share/extras/uncrustify.cfg Wyświetl plik

@@ -0,0 +1,295 @@
1
+#
2
+# http://uncrustify.sourceforge.net/
3
+#
4
+# Source beautifier configuration which helps to create
5
+# more consistent look to your source with the expected
6
+# coding style in VICE
7
+#
8
+# Usage: "uncrustify -c uncrustify.cfg source.c"
9
+#
10
+# There's no guarantee the look is perfect after this
11
+# but at least the most common stuff is corrected.
12
+#
13
+# Make sure to use the latest version.
14
+#
15
+
16
+# no cr/lf
17
+newlines = lf
18
+
19
+# no tabs
20
+indent_with_tabs = 0
21
+
22
+# no tabs
23
+output_tab_size = 2
24
+
25
+# small indents
26
+indent_columns = 2
27
+
28
+# Spaces to indent '{' from 'case'.
29
+# By default, the brace will appear under the 'c' in case.
30
+# Usually set to 0 or indent_columns.
31
+indent_case_brace = 4
32
+
33
+# Spaces to indent 'case' from 'switch'
34
+# Usually 0 or indent_columns.
35
+indent_switch_case = 4
36
+
37
+# Add or remove space around arithmetic operator '+', '-', '/', '*', etc
38
+sp_arith = force
39
+
40
+# Add or remove space around assignment operator '=', '+=', etc
41
+sp_assign = force
42
+
43
+# Add or remove space around boolean operators '&&' and '||'
44
+sp_bool = force
45
+
46
+# Add or remove space around compare operator '<', '>', '==', etc
47
+sp_compare = force
48
+
49
+# Add or remove space around the ':' in 'b ? t : f'
50
+sp_cond_colon = force
51
+
52
+# Add or remove space around the '?' in 'b ? t : f'
53
+sp_cond_question = force
54
+
55
+# In the abbreviated ternary form '(a ?: b)', add or remove space between '?'
56
+# and ':'.
57
+#
58
+# Overrides all other sp_cond_* options.
59
+sp_cond_ternary_short = remove
60
+
61
+# Add or remove space between nested parens
62
+sp_paren_paren = remove
63
+
64
+# Add or remove space inside '(' and ')'
65
+sp_inside_sparen = remove
66
+
67
+# Add or remove space between 'else' and '{' if on the same line
68
+sp_else_brace = force
69
+
70
+# Add or remove space between '}' and 'else' if on the same line
71
+sp_brace_else = force
72
+
73
+# Add or remove space inside a non-empty '[' and ']'
74
+sp_inside_square = remove
75
+
76
+# Add or remove space before '(' of 'if', 'for', 'switch', and 'while'
77
+sp_before_sparen = force
78
+
79
+# Add or remove space after ','
80
+sp_after_comma = force
81
+
82
+# Add or remove space before ','
83
+sp_before_comma = remove
84
+
85
+# Add or remove space between ')' and '{'
86
+sp_paren_brace = force
87
+
88
+# Add or remove space after ')' of 'if', 'for', 'switch', and 'while'
89
+sp_after_sparen  = force
90
+
91
+# Add or remove space after ';', except when followed by a comment. Default=Add
92
+sp_after_semi = force
93
+
94
+# Add or remove newline between '}' and 'else'
95
+nl_brace_else = force
96
+
97
+# Add or remove newline between 'enum' and '{'
98
+nl_enum_brace = remove
99
+
100
+# Add or remove newline between 'struct and '{'
101
+nl_struct_brace = remove
102
+
103
+# Add or remove newline between 'union' and '{'
104
+nl_union_brace = remove
105
+
106
+# Whether to put a newline after brace open.
107
+# This also adds a newline before the matching brace close.
108
+nl_after_brace_open = true
109
+
110
+# Add or remove newline between 'if' and '{'
111
+nl_if_brace = remove
112
+
113
+# Add or remove newline between 'else' and '{'
114
+nl_else_brace = remove
115
+
116
+# Add or remove newline between 'switch' and '{'
117
+nl_switch_brace = remove
118
+
119
+# Add or remove newline at the end of the file
120
+nl_end_of_file = add
121
+
122
+# Add or remove newline between function signature and '{'
123
+nl_fdef_brace = remove
124
+
125
+# Whether to remove blank lines after '{'
126
+eat_blanks_after_open_brace = true
127
+
128
+# Whether to remove blank lines before '}'
129
+eat_blanks_before_close_brace = false
130
+
131
+# Whether to enforce that all blocks of an 'if'/'else if'/'else' chain either
132
+# have, or do not have, braces. If true, braces will be added if any block
133
+# needs braces, and will only be removed if they can be removed from all
134
+# blocks.
135
+#
136
+# Overrides mod_full_brace_if.
137
+mod_full_brace_if_chain = true
138
+
139
+# Add or remove braces on single-line 'if' statement. Will not remove the braces if they contain an 'else'.
140
+mod_full_brace_if = false
141
+
142
+# Add or remove braces on single-line 'do' statement
143
+mod_full_brace_do = false
144
+
145
+# Add or remove braces on single-line 'for' statement
146
+mod_full_brace_for = false
147
+
148
+# Add or remove braces on single-line 'while' statement
149
+mod_full_brace_while = false
150
+
151
+# Whether to remove superfluous semicolons
152
+mod_remove_extra_semicolon = true
153
+
154
+# If an #ifdef or #else body exceeds the specified number of newlines and
155
+# doesn't have a comment after the #else, a comment will be added.
156
+mod_add_long_ifdef_else_comment = 40
157
+
158
+
159
+# Whether to put a newline after a brace close.
160
+# Does not apply if followed by a necessary ';'.
161
+nl_after_brace_close = true
162
+
163
+# If false, disable all multi-line comment changes, including cmt_width. keyword substitution, and leading chars.
164
+# Default is true.
165
+cmt_indent_multi = false
166
+
167
+# Add or remove indentation of preprocessor directives inside #if blocks
168
+# at brace level 0 (file-level).
169
+pp_indent = add
170
+
171
+# Whether to indent #if/#else/#endif at the brace level. If false, these are
172
+# indented from column 1.
173
+pp_indent_at_level = true
174
+
175
+# If pp_indent_at_level=true, sets the indent for #if, #else and #endif when
176
+# not at file-level. Negative values decrease indent down to the first column.
177
+#
178
+# =0: Indent preprocessors using output_tab_size
179
+# >0: Column at which all preprocessors will be indented
180
+pp_indent_if = 0
181
+
182
+# Whether to indent case statements between #if, #else, and #endif.
183
+# Only applies to the indent of the preprocesser that the case statements
184
+# directly inside of.
185
+#
186
+# Default: true
187
+pp_indent_case = false
188
+
189
+# Whether to indent the code between #if, #else and #endif.
190
+pp_if_indent_code = true
191
+
192
+# Specifies the number of columns to indent preprocessors per level
193
+# at brace level 0 (file-level). If pp_indent_at_level=false, also specifies
194
+# the number of columns to indent preprocessors per level
195
+# at brace level > 0 (function-level).
196
+#
197
+# Default: 1
198
+pp_indent_count = 2
199
+
200
+
201
+# Whether to indent '#define' at the brace level. If false, these are
202
+# indented from column 1.
203
+pp_define_at_level = true
204
+
205
+# Whether to ignore the '#define' body while formatting.
206
+pp_ignore_define_body = true
207
+
208
+#
209
+# Newline adding and removing options
210
+#
211
+
212
+# Don't split one-line braced assignments, as in 'foo_t f = { 1, 2 };'.
213
+nl_assign_leave_one_liners = true
214
+
215
+# Don't split one-line braced statements inside a 'class xx { }' body.
216
+nl_class_leave_one_liners = true
217
+
218
+# Don't split one-line enums, as in 'enum foo { BAR = 15 };'
219
+nl_enum_leave_one_liners = true
220
+
221
+# Don't split one-line get or set functions.
222
+nl_getset_leave_one_liners = true
223
+
224
+# (C#) Don't split one-line property get or set functions.
225
+nl_cs_property_leave_one_liners = true
226
+
227
+# Don't split one-line function definitions, as in 'int foo() { return 0; }'.
228
+# might modify nl_func_type_name
229
+nl_func_leave_one_liners = true
230
+
231
+# Don't split one-line C++11 lambdas, as in '[]() { return 0; }'.
232
+nl_cpp_lambda_leave_one_liners = false
233
+
234
+# Don't split one-line if/else statements, as in 'if(...) b++;'.
235
+nl_if_leave_one_liners = true
236
+
237
+# Don't split one-line while statements, as in 'while(...) b++;'.
238
+nl_while_leave_one_liners = true
239
+
240
+# Don't split one-line for statements, as in 'for(...) b++;'.
241
+nl_for_leave_one_liners = true
242
+
243
+# Whether to indent the body of a C++11 lambda.
244
+indent_cpp_lambda_body = true
245
+
246
+# The value might be used twice:
247
+# - at the assignment
248
+# - at the opening brace
249
+#
250
+# To prevent the double use of the indentation value, use this option with the
251
+# value 'true'.
252
+#
253
+# true:  indentation will be used only once
254
+# false: indentation will be used every time (default)
255
+indent_cpp_lambda_only_once = true
256
+
257
+# How to reflow comments.
258
+#
259
+# 0: No reflowing (apart from the line wrapping due to cmt_width) (default)
260
+# 1: No touching at all
261
+# 2: Full reflow
262
+cmt_reflow_mode = 1
263
+
264
+# Whether to group cpp-comments that look like they are in a block. Only
265
+# meaningful if cmt_cpp_to_c=true.
266
+cmt_cpp_group = true
267
+
268
+# Whether to put a star on subsequent comment lines.
269
+cmt_star_cont = true
270
+
271
+# The number of spaces to insert at the start of subsequent comment lines.
272
+cmt_sp_before_star_cont = 1
273
+
274
+# The number of spaces to insert after the star on subsequent comment lines.
275
+cmt_sp_after_star_cont = 1
276
+
277
+# Whether to convert all tabs to spaces in comments. If false, tabs in
278
+# comments are left alone, unless used for indenting.
279
+cmt_convert_tab_to_spaces = true
280
+
281
+
282
+# Add a newline before ')' if an if/for/while/switch condition spans multiple
283
+# lines. Overrides nl_before_if_closing_paren if both are specified.
284
+nl_multi_line_sparen_close = ignore
285
+
286
+# Add or remove newline before 'if'/'else if' closing parenthesis.
287
+nl_before_if_closing_paren = ignore
288
+
289
+# Add or remove space around assignment operator '=' in a prototype.
290
+#
291
+# If set to ignore, use sp_assign.
292
+sp_assign_default = remove
293
+
294
+# Whether to right-align numbers.
295
+align_number_right = true

Ładowanie…
Anuluj
Zapisz