forked from se-sic/cppstats
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathcppstats_dmacros_prepare.sh
executable file
·158 lines (128 loc) · 3.69 KB
/
cppstats_dmacros_prepare.sh
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
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
#!/bin/bash
# parameters
# cmd - script-name itself
# indir - input-directory
cmd=${0}
# get the abspath of the input-directory
if [ -z ${1} ]; then
echo '### no input directory given!'
exit -1
fi
indir=${1}
D=`dirname "${indir}"`
B=`basename "${indir}"`
indirabs="`cd \"$D\" 2>/dev/null && pwd || echo \"$D\"`/$B"
# change to script directory
if [ `dirname ${cmd}` != '.' ]; then
cd `dirname ${cmd}` || exit -1
fi
# check the preconditions
bin=${PWD}
echo ${bin}
echo '### preliminaries ...'
case `uname -s` in
Linux|linux) s2sml=${bin}/src2srcml.linux; sml2s=${bin}/srcml2src.linux;;
Darwin|darwin) s2sml=${bin}/src2srcml.osx; sml2s=${bin}/srcml2src.osx;;
*) echo '### program src2srcml missing'
echo ' see: http://www.sdml.info/projects/srcml/trunk/'
exit 1;;
esac
which python > /dev/null
if [ $? -ne 0 ]; then
echo '### programm python missing!'
echo ' see: http://www.python.org/'
exit 1
fi
which astyle > /dev/null
if [ $? -ne 0 ]; then
echo '### programm astyle missing!'
echo ' see: http://astyle.sourceforge.net/'
exit 1
fi
which xsltproc > /dev/null
if [ $? -ne 0 ]; then
echo '### programm xsltproc missing!'
echo ' see: http://www.xmlsoft.org/XSLT/xsltproc2.html'
exit 1
fi
which notify-send > /dev/null
if [ $? -ne 0 ]; then
echo '### program notify-send missing!'
echo ' aptitude install libnotify-bin'
exit 1
fi
# create the working directory within the sw-project
cd ${indirabs}
sourcedir=${indirabs}/source
invest=${indirabs}/_cppstats_discipline
if [ -e ${invest} ]; then
rm -rf ${invest}
fi
mkdir ${invest}
notify-send "starting ${indirabs}"
# copy source-files
echo '### preparing sources ...'
echo '### copying all-files to one folder ...'
cd ${sourcedir}
find . -type f \( -name "*.h" -o -name "*.c" \) -exec cp --parents '{}' ${invest} \;
cd ${invest}
# reformat source-files and delete comments and include guards
echo '### reformat source-files'
SAVEIFS=$IFS
IFS=$(echo -en "\n\b")
for f in `find . -type f \( -name "*.h" -o -name "*.c" \)`; do
f=${invest}/${f}
# translate macros that span over multiple lines to one line
cp ${f} ${f}.bak01
mv ${f} ${f}tmp.txt
${bin}/move_multiple_macros.py ${f}tmp.txt ${f}
rm -f ${f}tmp.txt
# delete comments
cp ${f} ${f}.bak02
$s2sml --language=C ${f} -o ${f}tmp.xml
xsltproc ${bin}/delete_comments.xsl ${f}tmp.xml > ${f}tmp_out.xml
$sml2s ${f}tmp_out.xml -o ${f}
rm -f ${f}tmp.xml ${f}tmp_out.xml
# format source-code
cp ${f} ${f}.bak03
# astyle --style=java ${f}
if [ -e ${f}.orig ]; then
rm -f ${f}.orig
fi
# delete leading, trailing and inter (# ... if) whitespaces
cp ${f} ${f}.bak04
cat ${f} | sed 's/^[ \t]\+//g;s/[ \t]\+$//g;s/\#[ \t]\+/\#/g' > ${f}tmp.txt
mv ${f}tmp.txt ${f}
# delete multipe whitespaces
cp ${f} ${f}.bak05
cat ${f} | sed 's/\t/ /g;s/[ \t]\{2,\}/ /g' > ${f}tmp.txt
mv ${f}tmp.txt ${f}
# rewrite ifdefs and ifndefs
cp ${f} ${f}.bak06
${bin}/rewriteifdefs.py ${f} > ${f}tmp.txt
mv ${f}tmp.txt ${f}
# delete include guards
if [ ${f/*./} == 'h' ]; then
echo 'deleting include guard in ' ${f}
cp ${f} ${f}.bak07
mv ${f} ${f}tmp.txt
${bin}/delete_include_guards.py ${f}tmp.txt > ${f}
rm -f ${f}tmp.txt
fi
# delete preprocessor directives in #ifdefs
cp ${f} ${f}.bak08
${bin}/partial_preprocessor.py -i ${f} -o ${f}tmp.txt
mv ${f}tmp.txt ${f}
# delete empty lines
cp ${f} ${f}.bak09
mv ${f} ${f}tmp.txt
${bin}/delete_emptylines.sed ${f}tmp.txt > ${f}
rm -f ${f}tmp.txt
done
# create xml-representation of the source-code
echo '### create xml-representation of the source-code files'
for f in `find . -type f \( -name "*.h" -o -name "*.c" \)`; do
echo "create representation for ${invest}/${f}"
$s2sml --language=C ${f} -o ${f}.xml || rm ${f}.xml
done
IFS=$SAVEIFS