| ... | ... |
@@ -191,147 +191,147 @@ |
| 191 | 191 |
) >$TMP_FILE |
| 192 | 192 |
|
| 193 | 193 |
"$ACTION"_action "$TMP_FILE" "$1" header |
| 194 | 194 |
} |
| 195 | 195 |
|
| 196 | 196 |
function tabs_check() {
|
| 197 | 197 |
if echo $1 | grep -q -v -E 'Makefile\.am$' |
| 198 | 198 |
then |
| 199 | 199 |
OLD_PATTERN=$(echo -e '\t') |
| 200 | 200 |
NEW_PATTERN=' ' |
| 201 | 201 |
else |
| 202 | 202 |
OLD_PATTERN=' ' |
| 203 | 203 |
NEW_PATTERN=$(echo -e '\t') |
| 204 | 204 |
fi |
| 205 | 205 |
TMP_FILE=`mktemp` |
| 206 | 206 |
cat $1 | sed -e "s/$OLD_PATTERN/$NEW_PATTERN/g" >$TMP_FILE |
| 207 | 207 |
|
| 208 | 208 |
"$ACTION"_action "$TMP_FILE" "$1" 'tabs' |
| 209 | 209 |
} |
| 210 | 210 |
|
| 211 | 211 |
function spaces_check() {
|
| 212 | 212 |
TMP_FILE=`mktemp` |
| 213 | 213 |
cat $1 | sed -e 's/ \+$//g' >$TMP_FILE |
| 214 | 214 |
|
| 215 |
"$ACTION"_action "$TMP_FILE" "$1" 'spaces' |
|
| 215 |
"$ACTION"_action "$TMP_FILE" "$1" 'trailing spaces' |
|
| 216 | 216 |
} |
| 217 | 217 |
|
| 218 | 218 |
function long_lines_check() {
|
| 219 | 219 |
if cat $1 | grep -q -E '.{81,}'
|
| 220 | 220 |
then |
| 221 | 221 |
"$ACTION"_warning $1 'long lines' |
| 222 | 222 |
fi |
| 223 | 223 |
} |
| 224 | 224 |
|
| 225 | 225 |
# process the file |
| 226 | 226 |
|
| 227 | 227 |
function process_file() {
|
| 228 |
echo -n " $ACTION |
|
| 228 |
echo -n " $ACTION $1..." |
|
| 229 | 229 |
|
| 230 | 230 |
CHECKING="header tabs spaces long_lines" |
| 231 | 231 |
|
| 232 | 232 |
"$ACTION"_begin $1 |
| 233 | 233 |
for check in $CHECKING |
| 234 | 234 |
do |
| 235 | 235 |
"$check"_check $1 |
| 236 | 236 |
done |
| 237 | 237 |
"$ACTION"_end $1 |
| 238 | 238 |
echo |
| 239 | 239 |
} |
| 240 | 240 |
|
| 241 | 241 |
function process_all {
|
| 242 | 242 |
"$ACTION"_init |
| 243 | 243 |
while read file |
| 244 | 244 |
do |
| 245 | 245 |
process_file $file |
| 246 | 246 |
done < <($FILES) |
| 247 | 247 |
"$ACTION"_done |
| 248 | 248 |
} |
| 249 | 249 |
|
| 250 | 250 |
while [ $# -gt 0 ] |
| 251 | 251 |
do |
| 252 | 252 |
|
| 253 | 253 |
if [ "$1" == '--help' ] || [ "$1" == '-h' ] |
| 254 | 254 |
then |
| 255 | 255 |
echo -n \ |
| 256 | 256 |
"Usage: |
| 257 | 257 |
$0 [OPTIONS] [files] |
| 258 | 258 |
Options: |
| 259 | 259 |
--dry-run|-n |
| 260 | 260 |
Check the given files, but do not modify them. |
| 261 | 261 |
--interactive|-i |
| 262 |
If --dry-run is specified and files are warned then a message is |
|
| 262 |
If --dry-run is specified and files are warned, then a message is |
|
| 263 | 263 |
prompted whether the warnings should be turned to errors. |
| 264 | 264 |
--werror|-w |
| 265 |
If --dry-run is specified |
|
| 265 |
If --dry-run is specified, the warnings are turned to errors. |
|
| 266 | 266 |
--all|-a |
| 267 |
|
|
| 267 |
Check all source files in the repository. |
|
| 268 | 268 |
--modified|-m |
| 269 | 269 |
Check only the modified source files. This option is proper to |
| 270 | 270 |
use before a commit. E.g. all files which are modified or added |
| 271 | 271 |
into the repository will be updated. |
| 272 | 272 |
--changed|-c |
| 273 | 273 |
Check only the changed source files compared to the parent(s) of |
| 274 | 274 |
the current hg node. This option is proper to use as hg hook |
| 275 | 275 |
script. E.g. to check all your commited source files with this |
| 276 | 276 |
script add the following section to the appropriate .hg/hgrc |
| 277 | 277 |
file. |
| 278 | 278 |
|
| 279 | 279 |
[hooks] |
| 280 | 280 |
pretxncommit.checksources = scripts/unify-sources.sh -c -n -i |
| 281 | 281 |
|
| 282 | 282 |
--help|-h |
| 283 | 283 |
Print this help message. |
| 284 | 284 |
files |
| 285 |
The files to check/unify. If no file names are given, the |
|
| 286 |
modified source will be checked/unified |
|
| 287 |
|
|
| 285 |
The files to check/unify. If no file names are given, the modified |
|
| 286 |
source files will be checked/unified (just like using the |
|
| 287 |
--modified|-m option). |
|
| 288 | 288 |
" |
| 289 | 289 |
exit 0 |
| 290 | 290 |
elif [ "$1" == '--dry-run' ] || [ "$1" == '-n' ] |
| 291 | 291 |
then |
| 292 |
[ -n "$ACTION" ] && echo " |
|
| 292 |
[ -n "$ACTION" ] && echo "Conflicting action options" >&2 && exit 1 |
|
| 293 | 293 |
ACTION=check |
| 294 | 294 |
elif [ "$1" == "--all" ] || [ "$1" == '-a' ] |
| 295 | 295 |
then |
| 296 |
[ -n "$FILES" ] && echo " |
|
| 296 |
[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1 |
|
| 297 | 297 |
FILES=all_files |
| 298 | 298 |
elif [ "$1" == "--changed" ] || [ "$1" == '-c' ] |
| 299 | 299 |
then |
| 300 |
[ -n "$FILES" ] && echo " |
|
| 300 |
[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1 |
|
| 301 | 301 |
FILES=changed_files |
| 302 | 302 |
elif [ "$1" == "--modified" ] || [ "$1" == '-m' ] |
| 303 | 303 |
then |
| 304 |
[ -n "$FILES" ] && echo " |
|
| 304 |
[ -n "$FILES" ] && echo "Conflicting target options" >&2 && exit 1 |
|
| 305 | 305 |
FILES=modified_files |
| 306 | 306 |
elif [ "$1" == "--interactive" ] || [ "$1" == "-i" ] |
| 307 | 307 |
then |
| 308 |
[ -n "$WARNING" ] && echo " |
|
| 308 |
[ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1 |
|
| 309 | 309 |
WARNING='INTERACTIVE' |
| 310 | 310 |
elif [ "$1" == "--werror" ] || [ "$1" == "-w" ] |
| 311 | 311 |
then |
| 312 |
[ -n "$WARNING" ] && echo " |
|
| 312 |
[ -n "$WARNING" ] && echo "Conflicting warning options" >&2 && exit 1 |
|
| 313 | 313 |
WARNING='WERROR' |
| 314 |
elif [ $(echo $1 | cut -c |
|
| 314 |
elif [ $(echo x$1 | cut -c 2) == '-' ] |
|
| 315 | 315 |
then |
| 316 | 316 |
echo "Invalid option $1" >&2 && exit 1 |
| 317 | 317 |
else |
| 318 | 318 |
[ -n "$FILES" ] && echo "Invalid option $1" >&2 && exit 1 |
| 319 | 319 |
GIVEN_FILES=$@ |
| 320 | 320 |
FILES=given_files |
| 321 | 321 |
break |
| 322 | 322 |
fi |
| 323 | 323 |
|
| 324 | 324 |
shift |
| 325 | 325 |
done |
| 326 | 326 |
|
| 327 | 327 |
if [ -z $FILES ] |
| 328 | 328 |
then |
| 329 | 329 |
FILES=modified_files |
| 330 | 330 |
fi |
| 331 | 331 |
|
| 332 | 332 |
if [ -z $ACTION ] |
| 333 | 333 |
then |
| 334 | 334 |
ACTION=update |
| 335 | 335 |
fi |
| 336 | 336 |
|
| 337 | 337 |
process_all |
0 comments (0 inline)