X-Git-Url: http://gitweb.michael.orlitzky.com/?a=blobdiff_plain;f=jsroute%2Fjsroute;fp=jsroute%2Fjsroute;h=5997e11b5330cf2d27439e131b4aab75860afdde;hb=960093578d2b188e3b756fa97a3517cf7e333c09;hp=0000000000000000000000000000000000000000;hpb=3a0515adc9b37f185f5454c16127e1425c0d36d1;p=dead%2Fcensus-tools.git diff --git a/jsroute/jsroute b/jsroute/jsroute new file mode 100755 index 0000000..5997e11 --- /dev/null +++ b/jsroute/jsroute @@ -0,0 +1,82 @@ +#!/bin/bash +# +# jsroute, a utility to route via Google Maps using Envjs. +# +# We take a starting point and a destination as arguments, and +# pass them off to a Javascript file (route.js) which is compiled +# on-the-fly using Mozilla's Rhino Javascript compiler. Then, magic +# occurs, and the JSON results are output to the command line. +# +# Soon the output will be piped through a Python script to convert +# it to (usable) KML. +# + +# Some exit codes. +EXIT_MISSING_START=1 +EXIT_MISSING_DESTINATION=2 +EXIT_HELP=3 +EXIT_GETOPT_UNHAPPY=4 +EXIT_TOO_MANY_ARGS=5 + + +# Empty by default. +ROUTENAME="" + +# A function which just displays the usage information. +function usage { + echo "" + echo "Usage: $0 [-h] [-n \"name\"] \"\" \"\"" + echo "" + echo "ARGUMENTS" + echo " , Your starting location. Use quotes." + echo " , Your destination. Use quotes." + echo "" + echo "OPTIONS" + echo " -h, Show the usage information and bail." + echo " -n , Give the route a meaningful name. Use quotes." + echo "" +} + + +while getopts "hn:" option; do + case $option in + n ) ROUTENAME="$OPTARG"; + # Shift the number of remaining arguments down by two, + # so that the non-option parameters are accessible via + # $1, $2, etc. + shift $((OPTIND-1));; + h ) usage; + exit $EXIT_HELP;; + * ) usage; + exit $EXIT_GETOPT_UNHAPPY;; + esac +done + + +# The non-option parameters. +START=$1 +DESTINATION=$2 + +# Dollarsign-octothorpe contains the number of parameter arguments. +if [ "$#" -gt 2 ]; then + echo "Error: too many arguments. Maybe you forgot to place the source and destination in quotes?" + usage; + exit $EXIT_TOO_MANY_ARGS +fi + +if [ "$START" == "" ]; then + usage; + exit $EXIT_MISSING_START +fi + +if [ "$DESTINATION" == "" ]; then + usage; + exit $EXIT_MISSING_DESTINATION +fi + +if [ "$ROUTENAME" == "" ]; then + # Set it to a default of " to ". + ROUTENAME="$START to $DESTINATION" +fi + +java -jar ../lib/env-js/rhino/js.jar -opt -1 route.js "$1" "$2"