]> AND Private Git Repository - loba.git/blob - new_loba.sh
Logo AND Algorithmique Numérique Distribuée

Private GIT Repository
Cosmetics: reorder includes.
[loba.git] / new_loba.sh
1 #!/bin/bash
2
3 if [ "$1" = "-n" ]; then
4     echo "# Dry run mode!" >&2
5     create_files=0
6     shift
7 else
8     create_files=1
9 fi
10
11 if [ $# -ne 1 ]; then
12     echo "Usage: $0 name" >&2
13     echo "    Create files loba_name.h and loba_name.cpp."
14     exit 1
15 fi
16
17 name=$(echo $1 | tr A-Z a-z)
18 if ! echo "$name" | grep -q '^[a-z][a-z0-9_]*$' \
19     || ! [ $(echo "$name" | wc -l) = 1 ]; then
20     echo "ERROR: invalid name -- \"$name\"" >&2
21     exit 1
22 fi
23
24 uname=$(echo $name | tr a-z A-Z)
25 h_file=$(printf "loba_%s.h" $name)
26 cpp_file=$(printf "loba_%s.cpp" $name)
27
28 if [ -e "$h_file" -o -e "$cpp_file" ]; then
29     echo "ERROR: file $h_file or $cpp_file already exists!" >&2
30     exit 1
31 fi
32
33 echo "# Creating files for algorithm $name ($uname)..."
34 echo "# Creating file $h_file... "
35 if [ "$create_files" = "1" ]; then
36     cat > "$h_file" <<EOF
37 #ifndef LOBA_${uname}_H
38 #define LOBA_${uname}_H
39
40 #include "process.h"
41
42 class loba_${name}: public process {
43 public:
44     loba_${name}(int argc, char* argv[]): process(argc, argv) { }
45     ~loba_${name}()                                           { }
46
47 private:
48     void load_balance();
49 };
50
51 #endif //!LOBA_${uname}_H
52
53 // Local variables:
54 // mode: c++
55 // End:
56 EOF
57 fi
58
59 echo "# Creating file $cpp_file..."
60 if [ "$create_files" = "1" ]; then
61     cat > "$cpp_file" <<EOF
62 #include <xbt/log.h>
63
64 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
65
66 #include "loba_${name}.h"
67
68 void loba_${name}::load_balance()
69 {
70     // write code here...
71     xbt_die("Load-balancing algorithm ${name} not implemented!");
72 }
73
74 // Local variables:
75 // mode: c++
76 // End:
77 EOF
78 fi
79
80 cat >&2 <<EOF
81 # Done.
82 Do not forget to:
83 * update file "options.cpp":
84   - add following include line
85         #include "${h_file}"
86   - add following line in loba_algorithms_type::loba_algorithms_type()
87         NOL_INSERT("${name}", "description...",
88                    loba_${name});
89 * add new files in SCM repository, for example with:
90         \$ git add options.cpp ${h_file} ${cpp_file}
91         \$ git commit -m 'Add algorithm ${name}."
92 EOF