Revision: 41426
          http://brlcad.svn.sourceforge.net/brlcad/?rev=41426&view=rev
Author:   brlcad
Date:     2010-11-22 23:50:57 +0000 (Mon, 22 Nov 2010)

Log Message:
-----------
wrap a slew of boilerplate infrastructure similar to the benchmark suite so 
that we have nice argument process, verbose/quiet options, help & instructions, 
and clean formatted output.  some basic adjustments made to use printf instead 
of echo

Modified Paths:
--------------
    brlcad/trunk/sh/conversion.sh

Modified: brlcad/trunk/sh/conversion.sh
===================================================================
--- brlcad/trunk/sh/conversion.sh       2010-11-22 23:44:44 UTC (rev 41425)
+++ brlcad/trunk/sh/conversion.sh       2010-11-22 23:50:57 UTC (rev 41426)
@@ -41,6 +41,25 @@
 # Ensure /bin/sh
 export PATH || (echo "This isn't sh."; sh $0 $*; kill $$)
 
+# save the precious args
+ARGS="$*"
+NAME_OF_THIS=`basename $0`
+PATH_TO_THIS=`dirname $0`
+THIS="$PATH_TO_THIS/$NAME_OF_THIS"
+
+# sanity check
+if test ! -f "$THIS" ; then
+    echo "INTERNAL ERROR: $THIS does not exist"
+    if test ! "x$0" = "x$THIS" ; then
+       echo "INTERNAL ERROR: dirname/basename inconsistency: $0 != $THIS"
+    fi
+    exit 1
+fi
+
+# force locale setting to C so things like date output as expected
+LC_ALL=C
+
+# commands that this script expects
 MGED="`which mged`"
 if test ! -f "$MGED" ; then
     echo "Unable to find mged, aborting"
@@ -53,6 +72,219 @@
     exit 2
 fi
 
+#######################
+# log to tty and file #
+#######################
+log ( ) {
+
+    # this routine writes the provided argument(s) to a log file as
+    # well as echoing them to stdout if we're not in quiet mode.
+
+    format="$1"
+    shift
+
+    if test ! "x$LOGFILE" = "x" ; then
+       action="printf \"$format\n\" $* >> \"$LOGFILE\""
+       eval "$action"
+    fi
+    if test ! "x$QUIET" = "x1" ; then
+       action="printf \"$format\n\" $*"
+       eval "$action"
+    fi
+}
+
+
+##############################
+# ensure a 0|1 boolean value #
+##############################
+booleanize ( ) {
+
+    # this routine examines the value of the specified variable and
+    # converts it to a simple zero or one value in order to simplify
+    # checks later on
+
+    for var in $* ; do
+
+       VAR="$var"
+       VALCMD="echo \$$VAR"
+       VAL="`eval $VALCMD`"
+
+       CMD=__UNSET__
+       case "x$VAL" in
+           x)
+               CMD="$VAR=0"
+               ;;
+           x0)
+               CMD="$VAR=0"
+               ;;
+           x[nN]*)
+               CMD="$VAR=0"
+               ;;
+           x*)
+               CMD="$VAR=1"
+               ;;
+       esac
+
+       if test ! "x$CMD" = "x__UNSET__" ; then
+           eval $CMD
+           export $VAR
+       fi
+
+    done
+}
+
+
+####################
+# handle arguments #
+####################
+
+# process the argument list for commands
+for arg in $ARGS ; do
+    case "x$arg" in
+       x*[hH])
+           HELP=1
+           shift
+           ;;
+       x*[hH][eE][lL][pP])
+           HELP=1
+           shift
+           ;;
+       x*[iI][nN][sS][tT][rR][uU][cC][tT]*)
+           INSTRUCTIONS=1
+           shift
+           ;;
+       x*[qQ][uU][iI][eE][tT])
+           QUIET=1
+           shift
+           ;;
+       x*[vV][eE][rR][bB][oO][sS][eE])
+           VERBOSE=1
+           shift
+           ;;
+       x*)
+           ;;
+    esac
+done
+
+# validate and clean up options (all default to 0)
+booleanize HELP INSTRUCTIONS VERBOSE
+
+###
+# handle help before main processing
+###
+if test "x$HELP" = "x1" ; then
+    echo "Usage: $0 [command(s)] [OPTION=value] file1.g [file2.g ...]"
+    echo ""
+    echo "Available commands:"
+    echo "  help          (this is what you are reading right now)"
+    echo "  instructions"
+    echo "  quiet"
+    echo "  verbose"
+    echo ""
+    echo "Available options:"
+    echo "  MAXTIME=#seconds (default 30)"
+    echo ""
+    echo "BRL-CAD is a powerful cross-platform open source solid modeling 
system."
+    echo "For more information about BRL-CAD, see http://brlcad.org";
+    echo ""
+    echo "Run '$0 instructions' for additional information."
+    exit 1
+fi
+
+
+###
+# handle instructions before main processing
+###
+if test "x$INSTRUCTIONS" = "x1" ; then
+    cat <<EOF
+
+This script is used to test BRL-CAD's explicit surface polygonal
+conversion capabilities.  It takes a list of one or more geometry
+files and for every geometry object in the file, it facetizes the
+object into NMG and BoT format.  The script times, tabulates, and
+reports conversion results.
+
+The script is useful for a variety of purposes including for
+developers to perform regression testing as BRL-CAD's conversion
+capabilities are modified and improved.  It's also useful for users to
+get a report of which objects in a given BRL-CAD geometry database
+will convert, what percentage, and how long the conversion will take.
+
+There are several environment variables that will modify how this
+script behaves:
+
+  MAXTIME - maximum number of seconds allowed for each conversion
+  VERBOSE - turn on extra debug output for testing/development
+  QUIET - turn off all printing output (writes results to log file)
+  INSTRUCTIONS - display these more detailed instructions
+
+The MAXTIME option specifies how many seconds are allowed to elapse
+before the conversion is aborted.  Some conversions can take days or
+months (or infinite in the case of a bug), so this places an upper
+bound on the per-object conversion time.
+EOF
+    exit 0
+fi
+
+
+#############
+# B E G I N #
+#############
+
+# where to write results
+LOGFILE=conversion-$$-run.log
+touch "$LOGFILE"
+if test ! -w "$LOGFILE" ; then
+    if test ! "x$LOGFILE" = "x/dev/null" ; then
+       echo "ERROR: Unable to log to $LOGFILE"
+    fi
+    LOGFILE=/dev/null
+fi
+
+VERBOSE_ECHO=:
+ECHO=log
+if test "x$QUIET" = "x1" ; then
+    if test "x$VERBOSE" = "x1" ; then
+       echo "Verbose output quelled by quiet option.  Further output disabled."
+    fi
+else
+    if test "x$VERBOSE" = "x1" ; then
+       VERBOSE_ECHO=printf
+       echo "Verbose output enabled"
+    fi
+fi
+
+###
+# ensure variable is set to something #
+###
+set_if_unset ( ) {
+    set_if_unset_name="$1" ; shift
+    set_if_unset_val="$1" ; shift
+
+    set_if_unset_var="echo \"\$$set_if_unset_name\""
+    set_if_unset_var_val="`eval ${set_if_unset_var}`"
+    if test "x${set_if_unset_var_val}" = "x" ; then
+       set_if_unset_var="${set_if_unset_name}=\"${set_if_unset_val}\""
+       eval $set_if_unset_var
+       export $set_if_unset_name
+    fi
+
+    set_if_unset_var="echo \"\$$set_if_unset_name\""
+    set_if_unset_val="`eval ${set_if_unset_var}`"
+    $ECHO "Using [${set_if_unset_val}] for $set_if_unset_name"
+}
+
+
+$ECHO "B R L - C A D   C O N V E R S I O N"
+$ECHO "==================================="
+$ECHO "Running $THIS on `date`"
+$ECHO "Logging output to $LOGFILE"
+$ECHO "`uname -a 2>&1`"
+
+# approximate maximum time in seconds that a given conversion is allowed to 
take
+set_if_unset MAXTIME 30
+
+$ECHO
 FILES=""
 while test $# -gt 0 ; do
     FILE="$1"
@@ -75,20 +307,20 @@
        fi
 
        nmg=fail
-       $MGED -c "$WORK" facetize -n \"${obj}.nmg\" \"${obj}\"
+       $MGED -c "$WORK" facetize -n \"${obj}.nmg\" \"${obj}\" >/dev/null 2>&1 
| grep -v Using
        found=`$MGED -c "$WORK" search . -name \"${obj}.nmg\" 2>&1 | grep -v 
Using`
        if test "x$found" = "x${object}.nmg" ; then
            nmg=pass
        fi
        
        bot=fail
-       $MGED -c "$WORK" facetize \"${obj}.bot\" \"${obj}\"
+       $MGED -c "$WORK" facetize \"${obj}.bot\" \"${obj}\" >/dev/null 2>&1 | 
grep -v Using
        found=`$MGED -c "$WORK" search . -name \"${obj}.bot\" 2>&1 | grep -v 
Using`
        if test "x$found" = "x${object}.bot" ; then
            bot=pass
        fi
        
-       printf "nmg:%s bot:%s %s:%s\n" $nmg $bot "$FILE" "$object"
+       $ECHO "nmg:%s bot:%s %s:%s" $nmg $bot "$FILE" "$object"
     done
 
     rm -f "$WORK"


This was sent by the SourceForge.net collaborative development platform, the 
world's largest Open Source development site.

------------------------------------------------------------------------------
Increase Visibility of Your 3D Game App & Earn a Chance To Win $500!
Tap into the largest installed PC base & get more eyes on your game by
optimizing for Intel(R) Graphics Technology. Get started today with the
Intel(R) Software Partner Program. Five $500 cash prizes are up for grabs.
http://p.sf.net/sfu/intelisp-dev2dev
_______________________________________________
BRL-CAD Source Commits mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/brlcad-commits

Reply via email to