File: format

package info (click to toggle)
hydrogen 1.2.2%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: trixie
  • size: 83,860 kB
  • sloc: xml: 75,490; cpp: 75,443; sh: 871; python: 238; ruby: 219; makefile: 158; javascript: 130; php: 90; ansic: 26
file content (26 lines) | stat: -rwxr-xr-x 640 bytes parent folder | download | duplicates (4)
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
#! /bin/bash

if [ $# -eq 0 ]; then
	echo "usage : $0 [git] [FILE] [DIR]"
	echo
	echo "    git  : will format all modified files"
	echo "    DIR  : will recursively format .h and .cpp files within the given directory"
	echo "    FILE : will format the given file"
	exit 1
fi

ASTYLEOPTS="--indent=tab=4 --style=linux --suffix=none --indent-classes"

for path in $@
do
	if [ "$path" == "git" ]
	then
		git status --porcelain src/ | awk 'match($1, "M"){print $2}' | while read file
		do
			astyle $ASTYLEOPTS $file
		done
	else
		[ -f "$path" ] && astyle $ASTYLEOPTS $path
		[ -d "$path" ] && astyle $ASTYLEOPTS -R "$path/*.h,*.cpp"
	fi
done