aboutsummaryrefslogtreecommitdiff
path: root/contrib
diff options
context:
space:
mode:
authorChristian Grothoff <christian@grothoff.org>2020-03-03 12:55:36 +0100
committerChristian Grothoff <christian@grothoff.org>2020-03-03 12:55:36 +0100
commitf22abb4d1339fe55f5c10545de4b80fe3ac6aebe (patch)
treead9ebbbeb6584d64310088b9769704f048f9daa4 /contrib
parent0f3f4f01cce39f83f029caa4c285035c409c0ced (diff)
downloadlibextractor-f22abb4d1339fe55f5c10545de4b80fe3ac6aebe.tar.gz
libextractor-f22abb4d1339fe55f5c10545de4b80fe3ac6aebe.zip
uncrustifying indentation
Diffstat (limited to 'contrib')
-rw-r--r--contrib/uncrustify.cfg95
-rwxr-xr-xcontrib/uncrustify.sh14
-rwxr-xr-xcontrib/uncrustify_precommit35
3 files changed, 144 insertions, 0 deletions
diff --git a/contrib/uncrustify.cfg b/contrib/uncrustify.cfg
new file mode 100644
index 0000000..8c9df2c
--- /dev/null
+++ b/contrib/uncrustify.cfg
@@ -0,0 +1,95 @@
1input_tab_size = 2
2output_tab_size = 2
3
4indent_columns = 2
5indent_with_tabs = 0
6indent_case_brace = 2
7indent_label=-16
8
9code_width=80
10#cmd_width=80
11
12# Leave most comments alone for now
13cmt_indent_multi=false
14sp_cmt_cpp_start=add
15
16sp_not=add
17
18sp_func_call_user_paren_paren=remove
19sp_inside_fparen=remove
20sp_after_cast=add
21
22ls_for_split_full=true
23ls_func_split_full=true
24ls_code_width=true
25
26# Arithmetic operations in wrapped expressions should be at the start
27# of the line.
28pos_arith=lead
29
30# Fully parenthesize boolean exprs
31mod_full_paren_if_bool=true
32
33# Braces should be on their own line
34nl_fdef_brace=add
35nl_enum_brace=add
36nl_struct_brace=add
37nl_union_brace=add
38nl_if_brace=add
39nl_brace_else=add
40nl_elseif_brace=add
41nl_while_brace=add
42nl_switch_brace=add
43
44# no newline between "else" and "if"
45nl_else_if=remove
46
47nl_func_paren=remove
48nl_assign_brace=remove
49
50# No extra newlines that cause noisy diffs
51nl_start_of_file=remove
52nl_after_func_proto = 2
53nl_after_func_body = 3
54# If there's no new line, it's not a text file!
55nl_end_of_file=add
56nl_max_blank_in_func = 3
57nl_max = 3
58
59sp_inside_paren = remove
60
61sp_arith = add
62sp_arith_additive = add
63
64# We want spaces before and after "="
65sp_before_assign = add
66sp_after_assign = add
67
68# we want "char *foo;"
69sp_after_ptr_star = remove
70sp_between_ptr_star = remove
71
72# we want "if (foo) { ... }"
73sp_before_sparen = add
74
75sp_inside_fparen = remove
76sp_inside_sparen = remove
77
78# add space before function call and decl: "foo (x)"
79sp_func_call_paren = add
80sp_func_proto_paren = add
81sp_func_proto_paren_empty = add
82sp_func_def_paren = add
83sp_func_def_paren_empty = add
84
85# We'd want it for "if ( (foo) || (bar) )", but not for "if (m())",
86# so as uncrustify doesn't give exactly what we want => ignore
87sp_paren_paren = ignore
88sp_inside_paren = remove
89sp_bool = force
90
91nl_func_type_name = force
92#nl_branch_else = add
93nl_else_brace = add
94nl_elseif_brace = add
95nl_for_brace = add
diff --git a/contrib/uncrustify.sh b/contrib/uncrustify.sh
new file mode 100755
index 0000000..e8e05d3
--- /dev/null
+++ b/contrib/uncrustify.sh
@@ -0,0 +1,14 @@
1#!/usr/bin/env bash
2
3set -eu
4
5DIR="$( cd "$( dirname "${BASH_SOURCE[0]}" )" >/dev/null 2>&1 && pwd )"
6
7if ! uncrustify --version >/dev/null; then
8 echo "you need to install uncrustify for indentation"
9 exit 1
10fi
11
12find "$DIR/../src" \( -name "*.cpp" -o -name "*.c" -o -name "*.h" \) \
13 -exec uncrustify -c "$DIR/uncrustify.cfg" --replace --no-backup {} + \
14 || true
diff --git a/contrib/uncrustify_precommit b/contrib/uncrustify_precommit
new file mode 100755
index 0000000..fd29998
--- /dev/null
+++ b/contrib/uncrustify_precommit
@@ -0,0 +1,35 @@
1#!/bin/sh
2
3# use as .git/hooks/pre-commit
4
5exec 1>&2
6
7RET=0
8changed=$(git diff --cached --name-only)
9crustified=""
10
11for f in $changed;
12do
13 if echo $f | grep \\.[c,h]\$ > /dev/null
14 then
15 # compare result of uncrustify with changes
16 #
17 # only change any of the invocations here if
18 # they are portable across all cmp and shell
19 # implementations !
20 uncrustify -q -c uncrustify.cfg -f $f | cmp -s $f -
21 if test $? = 1 ;
22 then
23 crustified=" $crustified $f"
24 RET=1
25 fi
26 fi
27done
28
29if [ $RET = 1 ];
30then
31 echo "Run"
32 echo "uncrustify --no-backup -c uncrustify.cfg ${crustified}"
33 echo "before commiting."
34fi
35exit $RET