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-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) {
129 if ($1 > nol_compare)
138 if [ "$create_files" = "1" ]; then
139 mv options.cpp options.cpp~
142 if type colordiff &> /dev/null; then
143 diff -u options.cpp $tmp | colordiff
145 diff -u options.cpp $tmp
152 Check for differences, update algorithm description in "options.cpp",
153 write your code in "${cpp_file}", and do not forget to add new files
154 in SCM repository, for example with:
155 \$ git add options.cpp ${h_file} ${cpp_file}
156 \$ git commit -m 'Add algorithm ${name}."