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

Private GIT Repository
New parameter: "-k value", to specify divisor for algorithms *best*.
[loba.git] / new_loba.sh
index f564a5ceb5a481fd29748a38cbd783147cc8d9a1..ba076fb753f1ee4f64d873ea29a9917526bb233c 100755 (executable)
@@ -1,5 +1,11 @@
 #!/bin/bash
 
 #!/bin/bash
 
+# Local variables:
+# mode: sh
+# End:
+
+set -e
+
 if [ "$1" = "-n" ]; then
     echo "# Dry run mode!" >&2
     create_files=0
 if [ "$1" = "-n" ]; then
     echo "# Dry run mode!" >&2
     create_files=0
@@ -9,13 +15,17 @@ else
 fi
 
 if [ $# -ne 1 ]; then
 fi
 
 if [ $# -ne 1 ]; then
-    echo "Usage: $0 name" >&2
-    echo "    Create files loba_name.h and loba_name.cpp."
+    cat >&2 <<EOF
+Usage: $0 [-n] name
+    Add new load-balancing algorithm \`name'.
+Options:
+    -n  dry-run mode (no file created, nor modified)
+EOF
     exit 1
 fi
 
 name=$(echo $1 | tr A-Z a-z)
     exit 1
 fi
 
 name=$(echo $1 | tr A-Z a-z)
-if ! echo "$name" | grep -q '^[a-z][a-z0-9_]*$' \
+if ! echo "$name" | grep -q '^[a-z0-9_]\+$' \
     || ! [ $(echo "$name" | wc -l) = 1 ]; then
     echo "ERROR: invalid name -- \"$name\"" >&2
     exit 1
     || ! [ $(echo "$name" | wc -l) = 1 ]; then
     echo "ERROR: invalid name -- \"$name\"" >&2
     exit 1
@@ -68,7 +78,7 @@ XBT_LOG_EXTERNAL_DEFAULT_CATEGORY(loba);
 void loba_${name}::load_balance()
 {
     // write code here...
 void loba_${name}::load_balance()
 {
     // write code here...
-    xbt_die("Load-balancing algorithm ${name} not implemented!");
+    xbt_die("Load-balancing algorithm \\"${name}\\" not implemented!");
 }
 
 // Local variables:
 }
 
 // Local variables:
@@ -77,16 +87,71 @@ void loba_${name}::load_balance()
 EOF
 fi
 
 EOF
 fi
 
+echo "# Updating options.cpp..."
+tmp="options.cpp.new.$$"
+trap "rm -f $tmp" EXIT
+
+awk -vname="${name}" '
+/^#include "loba_/ {
+    if (!include_line) {
+        h_file = "\"loba_" name ".h\"";
+        include_line = "#include " h_file;
+    }
+    if (!included && $2 >= h_file) {
+        if ($2 != h_file)
+            print "#include " h_file;
+        included = 1;
+    }
+    print;
+    next;
+}
+
+!included && include_line {
+    print include_line;
+    included = 1;
+}
+
+/loba_algorithms_type::loba_algorithms_type\(\)/ {
+    nol_compare = "NOL_INSERT(\"" name "\","
+    nol_string = "        " nol_compare " \"describe your algorithm here...\",\n";
+    nol_string = nol_string "                   loba_" name ");"
+    nol_insert = 1;
+}
+
+nol_insert && $1 ~ /\}/ {
+    if (!nol_inserted)
+        print nol_string;
+    nol_insert = 0;
+}
+
+nol_insert && !nol_inserted && /NOL_INSERT/ {
+    if ($1 >= nol_compare) {
+        if ($1 > nol_compare)
+            print nol_string;
+        nol_inserted = 1;
+    }
+}
+
+{ print }
+' options.cpp > $tmp
+
+if [ "$create_files" = "1" ]; then
+    mv options.cpp options.cpp~
+    mv $tmp options.cpp
+else
+    if type colordiff &> /dev/null; then
+        diff -u options.cpp $tmp | colordiff
+    else
+        diff -u options.cpp $tmp
+    fi
+fi
+
 cat >&2 <<EOF
 # Done.
 cat >&2 <<EOF
 # Done.
-Do not forget to:
-* update file "options.cpp":
-  - add following include line
-        #include "${h_file}"
-  - add following line in loba_algorithms_type::loba_algorithms_type()
-        NOL_INSERT("${name}", "description...",
-                   loba_${name});
-* add new files in SCM repository, for example with:
+
+Check for differences, update algorithm description in "options.cpp",
+write your code in "${cpp_file}", and do not forget to add new files
+in SCM repository, for example with:
         \$ git add options.cpp ${h_file} ${cpp_file}
         \$ git commit -m 'Add algorithm ${name}."
 EOF
         \$ git add options.cpp ${h_file} ${cpp_file}
         \$ git commit -m 'Add algorithm ${name}."
 EOF