minor fixes for clang++
[senf.git] / tools / add.sh
1 #!/bin/sh -e
2
3 if [ -z "$1" ]; then
4     cat <<EOF
5 Usage: 
6     $0 [-f] <name>.<ext> [<author>]
7     $0 [-f] SConscript [<author>]
8
9 Will add the file with that name to the current directory by copying
10 the appropriate template and replacing the @NAME@ placeholders
11 appropriately.
12
13 <ext> needs to be one of
14
15   hh   header
16   ih   internal header
17   cc   non-inline non-template code
18   cci  inline non-template code
19   ct   non-inline template code
20   cti  inline template code
21   mpp  special Boost.Preprocessor sourcefile (external iteration)
22   dox  additional doxygen documentation file
23
24 If <author> is given, it is also set correctly replaced. If <author>
25 is unset but the environment variable SENF_AUTHOR is set, it's value
26 is used. Otherwise, the @AUTHOR@ placeholder will need to be replaced
27 manually.
28
29 $0 will refrain from overwriting existing files except when the '-f'
30 option is specified.
31 EOF
32     exit 1
33 fi
34
35 base="`dirname "$0"`"; base="`cd "$base/_templates"; pwd`"
36 root="`cd "$base/../.."; pwd`"
37
38 if [ "$1" = "-f" ]; then
39     force=1
40     shift
41 fi
42
43 name="`basename "$1"`"
44 case "$name" in
45     *.*) type=".${name#*.}"; name="${name%.$type}" ;;
46     *) type=".$name" ;;
47 esac
48
49 if [ ! -r "$base/Example$type" ] ; then
50     echo "Don't know about file type '$type'"
51     exit 1
52 fi
53
54 [ -z "$2" ] || SENF_AUTHOR="$2"
55
56 if [ -z "$force" -a -r "$1" ] ; then
57     echo "Target file '$1' exists."
58     exit 1
59 fi
60
61 path="`dirname "$1"`"; path="`cd "$path"; pwd`"
62 path="$path/${name%%.*}"
63 path="${path#$root}"
64 path="$(echo "${path#/}" | tr / _)"
65
66 sed -e "s/@NAME@/$name/g" \
67     -e "s/@PATH@/$path/g" \
68     -e "s/@AUTHOR@/${SENF_AUTHOR:-@AUTHOR@}/g" \
69     < "$base/Example$type" \
70     > "$1"
71
72 svn add "$1"
73 svn propset svn:keywords "Author Date Id Revision" "$1"