diff --git a/lib/init/grass-xterm-mac b/lib/init/grass-xterm-mac index cb9b60ef213..6183d69587a 100755 --- a/lib/init/grass-xterm-mac +++ b/lib/init/grass-xterm-mac @@ -4,13 +4,13 @@ # -William Kyngesburye # just in case accidentally called on another system -SYSTEMOSX=`uname -s | grep "Darwin"` +SYSTEMOSX=$(uname -s | grep "Darwin") -if [ "$SYSTEMOSX" ] ; then +if [ "$SYSTEMOSX" ]; then # manually transfer the necessary env vars TMPSCRIPT="/tmp/grassxterm_$$" ( - cat <<-EOF + cat <<- EOF #!/bin/sh DISPLAY="$DISPLAY" PATH="$PATH" @@ -25,32 +25,32 @@ if [ "$SYSTEMOSX" ] ; then export DISPLAY PATH GIS_LOCK GISRC GISBASE GRASS_VERSION GRASS_PAGER DYLD_LIBRARY_PATH GRASS_LD_LIBRARY_PATH GRASS_HTML_BROWSER GRASS_HTML_BROWSER_MACOSX EOF - if [ "$GRASS_ADDON_PATH" ] ; then - echo "GRASS_ADDON_PATH=\"$GRASS_ADDON_PATH\"" - echo "export GRASS_ADDON_PATH" - fi + if [ "$GRASS_ADDON_PATH" ]; then + echo "GRASS_ADDON_PATH=\"$GRASS_ADDON_PATH\"" + echo "export GRASS_ADDON_PATH" + fi - if [ -z "$MANPATH" ] ; then - echo "MANPATH=\"$GISBASE/docs/man:`manpath`\"" - else - echo "MANPATH=\"$GISBASE/docs/man:$MANPATH\"" - fi - echo "export MANPATH" + if [ -z "$MANPATH" ]; then + echo "MANPATH=\"$GISBASE/docs/man:$(manpath)\"" + else + echo "MANPATH=\"$GISBASE/docs/man:$MANPATH\"" + fi + echo "export MANPATH" - # get command, ignore all other xterm flags - while true ; do - if [ "$1" = "-e" ] ; then break ; fi - shift - done - shift - # and add it to end of script - echo "$@" + # get command, ignore all other xterm flags + while true; do + if [ "$1" = "-e" ]; then break; fi + shift + done + shift + # and add it to end of script + echo "$@" ) > "$TMPSCRIPT.sh" chmod +x "$TMPSCRIPT.sh" # execute # save current active app/window, return to it when script finishes. - osascript - < /dev/null) || (echo "error"; return 1) || exit 1 +(./cr_large_graph -g A > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "read 'A'; unflatten ; flatten back again and save it to 'B'" -(./unflatten -g A -o B > /dev/null) || (echo "error"; return 1) || exit 1 +(./unflatten -g A -o B > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'A' to 'A.txt'" -(./view -g A > A.txt) || (echo "error"; return 1) || exit 1 +(./view -g A > A.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'B' to 'B.txt'" -(./view -g B > B.txt) || (echo "error"; return 1) || exit 1 +(./view -g B > B.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "compare 'A.txt' with 'B.txt'" -(diff -q A.txt B.txt && \ - echo "'A.txt' and 'B.txt' are identical") || - (echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1 +(diff -q A.txt B.txt \ + && echo "'A.txt' and 'B.txt' are identical") \ + || ( + echo "'A.txt' and 'B.txt' differ" + exit 1 + ) || exit 1 rm -f A B A.txt B.txt echo "create a version-2 digraph and save it to 'A'" -(./cr_large_graph -g A -v 2 > /dev/null) || (echo "error"; return 1) || exit 1 +(./cr_large_graph -g A -v 2 > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "read 'A'; unflatten ; flatten back again and save it to 'B'" -(./unflatten -g A -o B > /dev/null) || (echo "error"; return 1) || exit 1 +(./unflatten -g A -o B > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'A' to 'A.txt'" -(./view -g A > A.txt) || (echo "error"; return 1) || exit 1 +(./view -g A > A.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'B' to 'B.txt'" -(./view -g B > B.txt) || (echo "error"; return 1) || exit 1 +(./view -g B > B.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "compare 'A.txt' with 'B.txt'" -(diff -q A.txt B.txt && \ - echo "'A.txt' and 'B.txt' are identical") || - (echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1 +(diff -q A.txt B.txt \ + && echo "'A.txt' and 'B.txt' are identical") \ + || ( + echo "'A.txt' and 'B.txt' differ" + exit 1 + ) || exit 1 rm -f A B A.txt B.txt echo "create a version-3 graph and save it to 'A'" -(./cr_large_graph -g A -v 2 > /dev/null) || (echo "error"; return 1) || exit 1 +(./cr_large_graph -g A -v 2 > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "read 'A'; unflatten ; flatten back again and save it to 'B'" -(./unflatten -g A -o B > /dev/null) || (echo "error"; return 1) || exit 1 +(./unflatten -g A -o B > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'A' to 'A.txt'" -(./view -g A > A.txt) || (echo "error"; return 1) || exit 1 +(./view -g A > A.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'B' to 'B.txt'" -(./view -g B > B.txt) || (echo "error"; return 1) || exit 1 +(./view -g B > B.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "compare 'A.txt' with 'B.txt'" -(diff -q A.txt B.txt && \ - echo "'A.txt' and 'B.txt' are identical") || - (echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1 +(diff -q A.txt B.txt \ + && echo "'A.txt' and 'B.txt' are identical") \ + || ( + echo "'A.txt' and 'B.txt' differ" + exit 1 + ) || exit 1 rm -f A B A.txt B.txt diff --git a/lib/vector/dglib/examples/rtest02.sh b/lib/vector/dglib/examples/rtest02.sh index 25adc25c359..23293ddf3ab 100755 --- a/lib/vector/dglib/examples/rtest02.sh +++ b/lib/vector/dglib/examples/rtest02.sh @@ -11,23 +11,38 @@ rm -f A A.txt B B.txt echo "create a large graph and save it to 'A'" -(./cr_large_graph -g A > /dev/null) || (echo "error"; return 1) || exit 1 +(./cr_large_graph -g A > /dev/null) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'A' to 'A.txt'" -(./view -g A > A.txt) || (echo "error"; return 1) || exit 1 +(./view -g A > A.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "import 'A.txt' to 'B'" -(./parse -i A.txt -o B) || (echo "error"; return 1) || exit 1 +(./parse -i A.txt -o B) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "convert 'B' to 'B.txt'" -(./view -g B > B.txt) || (echo "error"; return 1) || exit 1 +(./view -g B > B.txt) || ( + echo "error" + return 1 +) || exit 1 echo "done" echo "compare 'A.txt' with 'B.txt'" -(diff -q A.txt B.txt && \ - echo "'A.txt' and 'B.txt' are identical") || - (echo "'A.txt' and 'B.txt' differ"; exit 1) || exit 1 +(diff -q A.txt B.txt \ + && echo "'A.txt' and 'B.txt' are identical") \ + || ( + echo "'A.txt' and 'B.txt' differ" + exit 1 + ) || exit 1 exit 0 diff --git a/lib/vector/dglib/examples/rtest03.sh b/lib/vector/dglib/examples/rtest03.sh index f571bc92af0..2ac7de54fae 100755 --- a/lib/vector/dglib/examples/rtest03.sh +++ b/lib/vector/dglib/examples/rtest03.sh @@ -1,6 +1,5 @@ #!/bin/bash - rm -f X1 X2 X3 X1.txt X2.txt X3.txt cat > X1.txt << EOF @@ -81,61 +80,73 @@ A 40 60 10 4060 A 60 50 10 6050 EOF -function check_path () { - fromNode=$1 - toNode=$2 - totDistance=$3 - nLinks=$4 - nodeList=($5) - file=$6 - - echo "check_path $fromNode -> $toNode - tot. distance $totDistance - n. links $nLinks" - - vlist=(`./shortest_path -g $file -f $fromNode -t $toNode`) || { echo "compute shortest path: command execution failed."; exit 1; } - - test "${vlist[10]}" = "unreachable" && { - echo "node $toNode is unreachable - test failed"; exit 1 - } - test "${vlist[12]}" = "$nLinks" || { - echo "link count is ${vlist[12]} instead of $nLinks - test failed"; exit 1 - } - test "${vlist[16]}" = "$totDistance" || { - echo "total distance is ${vlist[16]} instead of $totDistance - test failed"; exit 1 - } - - i=19 - iNodeList=0 - - for (( iLink=0 ; iLink < $nLinks ; iLink++ )) - do - test ! "${vlist[$i]}" == "${nodeList[$iNodeList]}" && { - echo "wrong link $iLink head (${vlist[$i]}, ${nodeList[$iNodeList]}) - test failed"; exit 1 - } - let i=i+2 - let iNodeList=iNodeList+1 - test ! "${vlist[$i]}" == "${nodeList[$iNodeList]}" && { - echo "wrong link $iLink tail (${vlist[$i]}, ${nodeList[$iNodeList]}) - test failed"; exit 1 - } - let i=i+17 - let iNodeList=iNodeList+1 - done - - echo "done" +function check_path() { + fromNode=$1 + toNode=$2 + totDistance=$3 + nLinks=$4 + nodeList=($5) + file=$6 + + echo "check_path $fromNode -> $toNode - tot. distance $totDistance - n. links $nLinks" + + vlist=($(./shortest_path -g "$file" -f "$fromNode" -t "$toNode")) || { + echo "compute shortest path: command execution failed." + exit 1 + } + + test "${vlist[10]}" = "unreachable" && { + echo "node $toNode is unreachable - test failed" + exit 1 + } + test "${vlist[12]}" = "$nLinks" || { + echo "link count is ${vlist[12]} instead of $nLinks - test failed" + exit 1 + } + test "${vlist[16]}" = "$totDistance" || { + echo "total distance is ${vlist[16]} instead of $totDistance - test failed" + exit 1 + } + + i=19 + iNodeList=0 + + for ((iLink = 0; iLink < nLinks; iLink++)); do + test ! "${vlist[$i]}" == "${nodeList[$iNodeList]}" && { + echo "wrong link $iLink head (${vlist[$i]}, ${nodeList[$iNodeList]}) - test failed" + exit 1 + } + let i=i+2 + let iNodeList=iNodeList+1 + test ! "${vlist[$i]}" == "${nodeList[$iNodeList]}" && { + echo "wrong link $iLink tail (${vlist[$i]}, ${nodeList[$iNodeList]}) - test failed" + exit 1 + } + let i=i+17 + let iNodeList=iNodeList+1 + done + + echo "done" } - # # # echo "script rtest03.sh: test shortest path computations..." -./cr_from_a -f X1.txt -g X1 || { echo "create test graph: command execution failed."; exit 1; } +./cr_from_a -f X1.txt -g X1 || { + echo "create test graph: command execution failed." + exit 1 +} check_path 1 80 30 2 "1 3 3 80" X1 || exit 1 check_path 3 1 22 1 "3 1" X1 || exit 1 -./cr_from_a -f X2.txt -g X2 || { echo "create test graph: command execution failed."; exit 1; } +./cr_from_a -f X2.txt -g X2 || { + echo "create test graph: command execution failed." + exit 1 +} check_path 1 80 30 2 "1 3 3 80" X2 || exit 1 check_path 3 1 22 1 "3 1" X2 || exit 1