1d89a607192cc6801b4bd61a0af33b340d2a91f5
[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
37 if [ "$1" == "-f" ]; then
38     force=1
39     shift
40 fi
41
42 name="`basename "$1"`"
43 case "$name" in
44     *.*) type=".${name#*.}"; name="${name%.$type}" ;;
45     *) type=".$name" ;;
46 esac
47
48 if [ ! -r "$base/Example$type" ] ; then
49     echo "Don't know about file type '$type'"
50     exit 1
51 fi
52
53 [ -z "$2" ] || SENF_AUTHOR="$2"
54
55 if [ -z "$force" -a -r "$1" ] ; then
56     echo "Target file '$1' exists."
57     exit 1
58 fi
59
60 sed -e "s/@NAME@/$name/g" -e "s/@AUTHOR@/${SENF_AUTHOR:-@AUTHOR@}/g" \
61     < "$base/Example$type" \
62     > "$1"
63
64 svn add "$1"
65 svn propset svn:keywords "Author Date Id Revision" "$1"