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