#!/bin/ksh
# gengoogmaphtml - Author: Edwin Arneson - $Revision: 1.2 $ - $Date: 2009/12/04 17:16:34 $
# Script to take a data file with garage sale address information from
# classified.van.net (or any properly formated data) and generate a HTML file
# that will allow the loading of place marks using the Google Maps API.
# Renamed from gengmtest2 to gengoogmaphtml 2009/11/29.
# FORMAT: gengoogmaphtml
# CHANGE HISTORY:
# 070712 EJA 1.1 - Created
# 091128 EJA 1.1 - Base output filename on the name of the input file.
# 091129 EJA 1.1 - Modified the script file gmtest2.1 to number icons.
# 091204 EJA 1.2 - Couple updates to the comment header.
# CALLED BY:
# CALLS:
# SEE ALSO:
# SCRIPTS:
# PERMISSIONS:
# HOSTS THIS FILE IS IDENTICAL ON:
# FILES:
# /Library/Webserver/Documents/gengoogmaphtml.1 - Prefix HTML code including the Google Maps API JavaScript stuff.
# /Library/Webserver/Documents/gengoogmaphtml.2 - Suffix HTML code.
# ENVIRONMENT:
# GLOBALS:
# LOCALS:
# COMMANDS:
# INPUT: a default inputfile file named gmtest2.in or one file specified with the -f flag
# The input file is of the form:
# {CITY= goggle_recognized_city_name, province, country
# {goggle_recognized_address|any text description}+}+
# INPUT GENERATED BY: hand
# OUTPUT:
# OUTPUT USED BY:
# EXAMPLES:
# Inputfile:
# CITY= Surrey, BC, CA
# 9612 152 Street|JHEFC
# CITY= Tsawwassen, BC, CA
# 1220 Pacific Dr|Tsawwassen BIG moving sale Sat July 28th: 9am til gone
# 870 Bayview Drive|Tsawwassen KIDS STUFF ONLY- FRONT yard sale Mabel's Labels
# HINTS:
# NOTES:
# This uses the example script http://www.google.com/apis/maps/documentation/geocoder2.html.
# Code for numbering the icons from http://maps.forum.nu/server_side_clusterer/index2.php.
# RESTRICTIONS:
# BUGS:
# WARNINGS:
# WARNING CODES:
# 40 - The localize script could not be found. Global machine settings can not be set.
# ERROR CODES:
# 51 - An unknown option was passed to the script, or syntax of the parameters is wrong.
# 56 - The USAGE was requested using -z or -?.
# DIAGNOSTICS:
# SECURITY:
# RCS.SH VERSION: 00011
# RCS INFORMATION:
# $Id: gengoogmaphtml,v 1.2 2009/12/04 17:16:34 earneson Exp $
# $Author: earneson $
# $Date: 2009/12/04 17:16:34 $
# $Revision: 1.2 $
# $Source: /Users/cvs/scripts/all/Users/earneson/bin/gengoogmaphtml,v $
# $State: Exp $
#######
####### Initialization
#######
# Special check for first parameter of "-x" to turn on tracing of the script execution
if [[ "$1" = "-x" ]] ; then
set -x
fi
# Find and execute the localization script designed to set common environment variables based name characteristics of the executing computer
binDir=`dirname $0` # get the directory this script is in and check for localize there
if [[ -r "$binDir/localize" ]] ; then
. $binDir/localize
else
echo "$0: WARNING 40 - The localize script could not be found. Global machine settings can not be set."
fi
# Ensure these three are set
if [[ -z "$localhost" ]] ; then localhost="`uname -n`" ; export localhost ; fi
if [[ -z "$awkname" ]] ; then if [[ -x "/usr/bin/nawk" ]] ; then awkname="nawk" ; else awkname="awk" ; export awkname ; fi ; fi
if [[ -z "$OStype" ]] ; then OStype="`uname -s`" ; export OStype ; fi
#######
####### Functions
#######
#######
####### Other variables
#######
basename=`basename $0`
USAGE="$basename
\$Revision: 1.2 $ - \$Date: 2009/12/04 17:16:34 $
usage: $basename [-x]* [-X]*
<-x> does 'set -x' (may be used in functions and external script calls)
<-X> sets debugging level--the number of times -X is specified"
debuglevel=0 # -X: stores the number of times -X is specified (debugging level)
xlevel=0 # -x: stores the number of times -x is specified (for optional "set -x" call in functions) and does 'set -x'
infile=gmtest2.in # -f:
#######
####### Parse parameters.
#######
while getopts :f:xXz optchar ; do
if [[ $debuglevel -ge 1 ]] ; then echo ">optchar=$optchar< >OPTARG=$OPTARG> >OPTIND=$OPTIND<" ; fi
case $optchar in
f) infile="$OPTARG" ;;
x) xcmd="$xcmd -x" ; ${xcmd:+set -x} ; let "xlevel=$xlevel + 1" ;; # xcmd stores any -x parameters for passing to other scripts
X) Xcmd="$Xcmd -X " ; let "debuglevel=$debuglevel + 1" ;; # Xcmd stores any -X parameters for passing to other scripts
\?|z) echo "$USAGE" >&2 ; exit 56 ;;
*) if [[ -z "$OPTARG" ]] ; then
case "$optchar" in
?) errflag="-$optchar" ;;
+?) errflag="$optchar" ;;
*) errflag="unknown1" ;;
esac
else
errflag="$OPTARG"
fi
echo "$basename: ERROR 51 - Unknown option >$errflag<" >&2
echo "$USAGE" >&2
exit 51
;;
esac
done
shift `expr $OPTIND - 1`
#######
####### Additional checks
#######
#######
####### Main processing
#######
case "$infile" in
*.in) outfile=`echo "$infile" | sed 's/.in$//'`.html ;;
*) outfile=${infile}.html ;;
esac
echo "INFILE=$infile"
echo "OUTFILE=$outfile"
cd /Library/WebServer/Documents
cat gengoogmaphtml.1 >$outfile
cat $infile \
| grep -v "^#" \
| awk '
BEGIN{
cnt=0
}
{
pos=index($0, "|")
if($2=="Garage" && $3=="Sales")
i=1
else if($1=="")
i=1
else if($1=="EOF")
exit
else if($1=="CITY=") {
citystr=substr($0, 7)
printf("%s
\n", citystr)
}
else {
cnt++
printf("", 39, 34)
printf("%d -- %s -- %s
\n", cnt, substr($0, 1, pos-1), substr($0, pos+1) )
# printf("%s
\n", 34, 34, 34, 39, $0, 39, 34, $0)
}
}
' >>$outfile
cat gengoogmaphtml.2 >>$outfile
#######
####### Cleanup
#######
#######
####### The end.
#######
exit