Skip to content
GitLab
Menu
Projects
Groups
Snippets
Help
Help
Support
Community forum
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in
Toggle navigation
Menu
Open sidebar
Elsa Gonsiorowski
codes
Commits
c3f2c08e
Commit
c3f2c08e
authored
Mar 16, 2015
by
Jonathan Jenkins
Browse files
uncrustify config and reformatting tool
parent
a28856ca
Changes
2
Expand all
Hide whitespace changes
Inline
Side-by-side
reformat.sh
0 → 100755
View file @
c3f2c08e
#!/bin/bash
script_dir
=
"
$(
cd
"
$(
dirname
"
${
BASH_SOURCE
[0]
}
"
)
"
&&
pwd
)
"
function
error
()
{
echo
"ERROR:
$@
"
>
&2
exit
1
}
function
usage
()
{
cat
\
<<
EOF
USAGE: reformat.sh [-x] [-i] [-c CFG] [-b FILE] {-a | FILE...}
-i: perform in-place (will ask to confirm if being done recursively)
-c CFG: use CFG as the uncrustify config (default:
$script_dir
/uc-codes.cfg)
-b FILE[,...]: add FILE to the blacklist of directories (in the form *FILE/*)
multiple files can be added by separating with commas
-a: perform recursively on all files ending in .c or .h
if -a not provided, then perform on all files passed in
-x: instead of formatting, check if output format is the same as input
EOF
}
function
build_blacklist
()
{
for
x
in
$@
;
do
echo
-n
"-and -not -path
\*
$x
/
\*
"
done
}
function
getfiles
()
{
find
.
\(
-name
\*
.c
-or
-name
\*
.h
\)
$(
build_blacklist
$@
)
}
cfg
=
$script_dir
/uc-codes.cfg
which uncrustify
>
/dev/null 2>&1
||
error
"uncrustify not found"
do_inplace
=
no
do_recursive
=
no
do_check
=
no
blacklist
=
while
getopts
":ib:ax"
opt
;
do
case
$opt
in
i
)
do_inplace
=
yes
;;
b
)
blacklist
=
$(
cat
$OPTARG
|
sed
s/,/ /g
)
;;
c
)
cfg
=
$OPTARG
;;
a
)
do_recursive
=
yes
;;
x
)
do_check
=
yes
;;
\?
)
usage
error
"invalid argument: -
$OPTARG
"
;;
esac
done
shift
$((
OPTIND-1
))
[[
-e
$cfg
]]
||
(
usage
&&
error
"config file
$cfg
not found"
)
[[
$#
-gt
0
&&
$do_recursive
==
yes
]]
&&
\
usage
&&
error
"no file args expected in recursive mode"
[[
$#
-eq
0
&&
$do_recursive
==
no
]]
&&
\
usage
&&
error
"expected file args in non-recursive mode"
if
[[
$do_recursive
==
yes
]]
;
then
file_list
=
"
$(
getfiles
$blacklist
)
"
else
file_list
=
"
$@
"
fi
if
[[
$do_recursive
==
yes
&&
$do_inplace
==
yes
]]
;
then
echo
-n
"Do recursive in-place reformat? (y/n) "
read
answer
[[
$answer
=
~
"[^y].*"
]]
&&
echo
"...aborting reformat"
&&
exit
1
fi
[[
$do_inplace
==
yes
]]
\
&&
output_arg
=
"--replace"
\
||
output_arg
=
if
[[
$do_check
==
yes
]]
;
then
check_arg
=
--check
output_arg
=
echo
"checking format..."
else
check_arg
=
fi
function
echolines
()
{
for
x
in
$@
;
do
echo
$x
;
done
}
echolines
$file_list
| uncrustify
$check_arg
-c
$cfg
$output_arg
-F
-
uc-codes.cfg
0 → 100644
View file @
c3f2c08e
This diff is collapsed.
Click to expand it.
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
.
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment