-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathindent.sh
More file actions
executable file
·72 lines (64 loc) · 2.11 KB
/
Copy pathindent.sh
File metadata and controls
executable file
·72 lines (64 loc) · 2.11 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
#!/bin/sh
usage(){
echo "usage: indent *.[ch]" 1>&2
exit 1
}
dos2unixall(){
for i in "$@"; do
echo "warning: "$i" is a windows file, converting" 1>&2
sed -E -i 's/\r//g' "$i"
done
}
case $# in
0)
usage
esac
if od -c "$@" |egrep '\\r' >/dev/null 2>&1; then
dos2unixall "$@"
fi
uncomment() {
gcc -fpreprocessed -dD -E "$@"
}
types() {
uncomment "$1" | fgrep typedef | fgrep struct | sed -E 's/.*[ \t]([a-zA-Z_]+) *[;}].*/\1/g'| sort -u
}
typesall() {
for i in "$@"; do
types "$i"
done
}
for i in "$@"; do
BADTYPEDEF=false
ts=`typesall "$@"`
if echo $ts|egrep 'struct|{' > /dev/null 2>&1 ; then
echo Warning: separate typedef from type definition 1>&2
egrep -n 'typedef.*struct' $i /dev/null |sed -E 's/^/\t/' 2>&1
BADTYPEDEF=true
fi
tparam=""
for t in $ts; do
tparam="$tparam "-T$t
done
if ! echo $i|grep '.*\.[hc]' > /dev/null 2>&1; then
echo "$i" is not a C file 1>&2;
usage
fi
if ! test -f $i > /dev/null 2>&1; then
echo "$i does not exist or is not a file" 1>&2;
usage
fi
if ! file "$i" |grep 'C source' > /dev/null 2>&1; then
echo "$i does not contain C code" 1>&2;
usage
fi
if [ $BADTYPEDEF = false ]; then
#indent twice to undo trashy formatting
indent -par -hnl -nsc -bl -ts8 -i8 -ut -bad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -ip0 -l80 -lp -npcs -nprs -psl -sai -saf -saw -ncs -sob -nfca -cp33 -ss -il1 -cdw "$i"> /dev/null 2>&1
indent $tparam -par -hnl -nsc -bl -ts8 -i8 -ut -bad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -ip0 -l80 -lp -npcs -nprs -psl -sai -saf -saw -ncs -sob -nfca -cp33 -ss -il1 -cdw "$i"
else
#indent twice to undo trashy formatting
indent -par -hnl -nsc -bl -ts8 -i8 -ut -bad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -ip0 -l80 -lp -npcs -nprs -psl -sai -saf -saw -ncs -sob -nfca -cp33 -ss -il1 -cdw "$i"> /dev/null 2>&1
indent -par -hnl -nsc -bl -ts8 -i8 -ut -bad -bap -nbc -bbo -hnl -br -brs -c33 -cd33 -ncdb -ce -ci4 -cli0 -d0 -di1 -nfc1 -ip0 -l80 -lp -npcs -nprs -psl -sai -saf -saw -ncs -sob -nfca -cp33 -ss -il1 -cdw "$i"
fi
rm -f "$i"~
done