forked from ilpincy/argos3
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathsource_task
executable file
·230 lines (213 loc) · 6.12 KB
/
source_task
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
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
#!/bin/bash
CWD=$(pwd)
#
# Open all editable files
#
function open() {
EDITOR=${EDITOR:-emacs}
${EDITOR} $(find src -type f \( -name '*.h' -o -name '*.cpp' -o -name '*.c' -o -name CMakeLists.txt -o -name '*.xml' -o -name '*.argos' \) ) $(find src/scripts/ -type f) src/core/config.h.in src/cmake/* src/source_task doc/Doxyfile_*.in doc/api_embedded_* doc/argos3.1 README.asciidoc TODO
}
#
# Count lines of code
#
function count_lines() {
find src -type f \( -name '*.h' -o -name '*.cpp' -o -name '*.c' \) | xargs wc -l
}
#
# Create TAGS file
#
function tags() {
EDITOR=${EDITOR:-emacs}
case ${EDITOR} in
"emacs")
TAGSCMD=$(which etags)
;;
"xemacs")
TAGSCMD=$(which etags)
;;
"vi")
TAGSCMD=$(which ctags)
;;
"vim")
TAGSCMD=$(which ctags)
;;
*)
esac
OUTPUT=build/TAGS
rm -f ${OUTPUT}
find src -type f \( -name '*.h' -o -name '*.cpp' -o -name '*.c' \) -print | ${TAGSCMD} -o ${OUTPUT} --declarations -I -
}
#
# Build code
#
function build {
( cd ../build && make -j2 )
}
#
# Install stuff in local repository
#
function install {
rm -rf ../install
mkdir ../install
( cd ../build && make DESTDIR=../install install )
}
#
# Dump headers in specified file
#
function dump_headers {
OUTFILE=$1
find . -type f -name '*.h' | sort > ${OUTFILE}
}
#
# Compare the lists of source and installed headers
#
function check_headers {
echo "Checking headers..."
build > /dev/null
install > /dev/null
dump_headers source_headers
( cd ../install/usr/include/argos3 && dump_headers ${CWD}/installed_headers )
echo "source <, installed >"
diff source_headers installed_headers
rm -f source_headers installed_headers
}
#
# Prints the list of files that still have the license as header
#
function check_license {
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e "This program is free software"
}
#
# Fixes for @file statements in all source files
# Common errors:
# 1. Files without the @file statement
# 2. Files without the <...> parentheses
# 3. Files with the wrong path in them
#
function fix_file_doxy {
for ORIGPATH in $(find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0)
do
# Exclude files coming from external sources
echo ${ORIGPATH} | grep -q -e "tinyxml" -e "chipmunk"
if [ $? -ne 0 ]; then
DOXYPATH="$(echo ${ORIGPATH} | sed 's|^./|argos3/|')"
FILELINE="$(grep -e '@file' ${ORIGPATH})"
if [ $? -ne 0 ]; then
# No @file statement found
cat <<EOF > tmpfile
/**
* @file <${DOXYPATH}>
*
* @author Carlo Pinciroli <[email protected]>
*/
EOF
cat ${ORIGPATH} >> tmpfile
mv tmpfile ${ORIGPATH}
else
# Wrong path
echo "${FILELINE}" | grep -qe "${DOXYPATH}"
if [ $? -ne 0 ]; then
sed -i "s|${FILELINE}| @file <${DOXYPATH}>|g" ${ORIGPATH}
fi
fi
fi
done
rm -f tmpfile
}
#
# Fix all mentions of argos2
#
function fix_argos2 {
echo "Creating list of files to change..."
LIST=fix_argos2_list.txt
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e argos2 > ${LIST}
echo "Changing argos2 in argos3..."
sed -i -e 's|argos2|argos3|g' $(cat ${LIST})
echo "Checking once more:"
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e argos2
rm -f ${LIST}
}
#
# Fix
# - "argos3/common" into "argos3/core"
# - "argos3/simulator" into "argos3/core/simulator"
#
function fix_includes {
echo "Creating list of files to change..."
LIST=fix_includes_list.txt
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e argos3/common -e argos3/simulator > ${LIST}
echo "Changing includes..."
sed -i -e 's|argos3/common|argos3/core|g' -e 's|argos3/simulator|argos3/core/simulator|g' $(cat ${LIST})
echo "Checking once more:"
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e argos3/common -e argos3/simulator
rm -f ${LIST}
}
#
# Fix bullet header include style
# - #include "LinearMath/btVector3.h" becomes #include <argos3/plugins/simulator/physics_engines/dynamics3d/bullet/LinearMath/btVector3.h>
# - #include "btVector3.h" is unchanged
#
function fix_bullet_includes {
BULLET_PATH=argos3/plugins/simulator/physics_engines/dynamics3d/bullet
find $BULLET_PATH -type f \( -name '*.h' -o -name '*.cpp' \) |
while read TARGET_PATH
do
sed -i -e "/[[:alnum:]]\/[[:alnum:]]/ s+#include \"\(.*\)\"+#include <$BULLET_PATH/\1>+g ; " $TARGET_PATH
done
}
function fix_email {
echo "Creating list of files to change..."
LIST=fix_email_list.txt
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e cpinciro > ${LIST}
echo "Changing email..."
sed -i -e 's|[email protected]|[email protected]|g' -e 's|[email protected]|[email protected]|g' -e 's|[email protected]|[email protected]|g' $(cat ${LIST})
echo "Checking once more:"
find . -type f \( -name '*.h' -o -name '*.cpp' \) -print0 | xargs -0 -e grep -l -e cpinciro > ${LIST}
rm -f ${LIST}
}
#
# Check command line parameters
#
if [ $# -ne 1 ]; then
echo "Usage:"
echo " $0 { open | check_headers | check_license | fix_file_doxy | fix_argos2 | fix_includes | fix_bullet_includes | fix_email }"
exit 1
fi
#
# Execute wanted operation
#
case $1 in
"open")
open
;;
"count_lines")
count_lines
;;
"tags")
tags
;;
"check_headers")
check_headers
;;
"check_license")
check_license
;;
"fix_file_doxy")
fix_file_doxy
;;
"fix_argos2")
fix_argos2
;;
"fix_includes")
fix_includes
;;
"fix_bullet_includes")
fix_bullet_includes
;;
"fix_email")
fix_email
;;
*)
echo "Unrecognized operation \"${OP}\""
;;
esac