Added _template folder and 'add.sh' helper script
[senf.git] / _templates / add.sh
1 #!/bin/sh -e
2
3 if [ -z "$1" ]; then
4     cat <<EOF
5 Usage: $0 <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 EOF
27     exit 1
28 fi
29
30 base="`dirname "$0"`"; base="`cd "$base"; pwd`"
31
32 type="${1##*.}"
33 name="`basename "$1" ".$type"`"
34
35 if [ ! -r "$base/Example.$type" ] ; then
36     echo "Don't know about file type '$type'"
37     exit 1
38 fi
39
40 [ -z "$2" ] || SENF_AUTHOR="$2"
41
42 if [ -r "$1" ] ; then
43     echo "Target file '$1' exists."
44     exit 1
45 fi
46
47 sed -e "s/@NAME@/$name/g" -e "s/@AUTHOR@/${SENF_AUTHOR:-@AUTHOR@}/g" \
48     < "$base/Example.$type" \
49     > "$1"