9 if [ "$1" = "-n" ]; then
10 echo "# Dry run mode!" >&2
20 Add new load-balancing algorithm \`name'.
22 -n dry-run mode (no file created, nor modified)
27 name=$(echo $1 | tr A-Z a-z)
28 if ! echo "$name" | grep -q '^[a-z][a-z0-9_]*$' \
29 || ! [ $(echo "$name" | wc -l) = 1 ]; then
30 echo "ERROR: invalid name -- \"$name\"" >&2
34 uname=$(echo $name | tr a-z A-Z)
35 h_file=$(printf "loba_%s.h" $name)
36 cpp_file=$(printf "loba_%s.cpp" $name)
38 if [ -e "$h_file" -o -e "$cpp_file" ]; then
39 echo "ERROR: file $h_file or $cpp_file already exists!" >&2
43 echo "# Creating files for algorithm $name ($uname)..."
44 echo "# Creating file $h_file... "
45 if [ "$create_files" = "1" ]; then
47 #ifndef LOBA_${uname}_H
48 #define LOBA_${uname}_H
52 class loba_${name}: public process {
54 loba_${name}(int argc, char* argv[]): process(argc, argv) { }
61 #endif //!LOBA_${uname}_H
69 echo "# Creating file $cpp_file..."
70 if [ "$create_files" = "1" ]; then
71 cat > "$cpp_file" <<EOF
74 XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
76 #include "loba_${name}.h"
78 void loba_${name}::load_balance()
81 xbt_die("Load-balancing algorithm \\"${name}\\" not implemented!");
90 echo "# Updating options.cpp..."
91 tmp="options.cpp.new.$$"
92 trap "rm -f $tmp" EXIT
94 awk -vname="${name}" '
97 h_file = "\"loba_" name ".h\"";
98 include_line = "#include " h_file;
100 if (!included && $2 >= h_file) {
102 print "#include " h_file;
109 !included && include_line {
114 /loba_algorithms_type::loba_algorithms_type\(\)/ {
115 nol_compare = "NOL_INSERT(\"" name "\","
116 nol_string = " " nol_compare " \"describe your algorithm here...\",\n";
117 nol_string = nol_string " loba_" name ");"
121 nol_insert && $1 ~ /\}/ {
127 nol_insert && !nol_inserted && /NOL_INSERT/ {
128 if ($1 > nol_compare) {
137 if [ "$create_files" = "1" ]; then
138 mv options.cpp options.cpp~
141 if type colordiff &> /dev/null; then
142 diff -u options.cpp $tmp | colordiff
144 diff -u options.cpp $tmp
151 Check for differences, update algorithm description in "options.cpp",
152 write your code in "${cpp_file}", and do not forget to add new files
153 in SCM repository, for example with:
154 \$ git add options.cpp ${h_file} ${cpp_file}
155 \$ git commit -m 'Add algorithm ${name}."