1#! /bin/sh 2# 3# @configure_input@ 4# 5# $Id: wlocdrv.in 0.08 2000/06/14 00:00:08 tom Exp $ 6# 7# wlocdrv.in: Uses `wlocdrv1[.awk|.pl]' and `wlocdrv2[.awk|.pl]' 8# for processing the ZONE file `zone.tab' to generate the 9# Gcal resource file `wlocdrv.rc' and the `wloc' script text, 10# which creates location files containing air line distances 11# and course angles between several geographic locations 12# around the world. 13# 14# Usage: wlocdrv --help | --version 15# Usage: wlocdrv [--debug] [--precise] [ZONE-FILE] 16# 17# `--debug': Turn on shell debugging. 18# `--precise': Use more precise values. 19# 20# UN*X solution. 21# 22# Needs `test', `echo', `expr', `eval', `set', `rm', `chmod', `sed' 23# and `perl' or `awk' for processing! 24# 25# Returns 0 if processing was successfully. 26# Returns 1 in case an error occured while processing. 27# Returns 2 if neither Perl nor AWK are present for further processing. 28# 29# Copyright (c) 2000 Thomas Esken <esken@uni-muenster.de> 30# Im Hagenfeld 84 31# D-48147 M"unster 32# GERMANY 33# 34# This software doesn't claim completeness, correctness or usability. 35# On principle I will not be liable for ANY damages or losses (implicit 36# or explicit), which result from using or handling my software. 37# If you use this software, you agree without any exception to this 38# agreement, which binds you LEGALLY !! 39# 40# This program is free software; you can redistribute it and/or modify 41# it under the terms of the `GNU General Public License' as published by 42# the `Free Software Foundation'; either version 3, or (at your option) 43# any later version. 44# 45# You should have received a copy of the `GNU General Public License' 46# along with this program; if not, write to the: 47# 48# 49# 50 51# 52# Basically used programs. 53# 54Rm=rm 55Sed=sed 56Set=set 57Test=test 58Echo=echo 59Expr=expr 60Chmod=chmod 61 62# 63# Basically used texts. 64# 65packagedatamiscdir=/usr/local/share/gcal/misc/wloc 66# 67PACKAGE=@PACKAGE@ 68VERSION=@VERSION@ 69transform=@program_transform_name@ 70# 71mydefaultname=wlocdrv 72# 73myname=`$Echo "$0" | $Sed -e 's,.*/,,' -e "$transform"` 74myversion=0.08 75myinternalname="$myname ($PACKAGE $VERSION) $myversion" 76# 77pool=$packagedatamiscdir/zone.tab 78runscriptname=wloc 79gcal_resource_file_suffix=.rc 80gcal_resource_file=$mydefaultname""$gcal_resource_file_suffix 81# 82info1="$myname: Generates the Gcal resource file \`$gcal_resource_file' and" 83info2="$myname: the \`$runscriptname' script text, which creates location" 84info3="$myname: files containing air line distances and course angles" 85info4="$myname: between several geographic locations around the world." 86info5="$myname:" 87usage1="usage: $myname --help | --version" 88usage2="usage: $myname [--debug] [--precise] [ZONE-FILE]" 89usage3="usage: $myname without ZONE-FILE uses file \`$pool' by default" 90 91# 92# Some constant values (EXIT_SUCCESS(==0) and EXIT_FATAL(==2) 93# are also returned by the processed AWK/Perl script. 94# 95EXIT_SUCCESS=0 96EXIT_FAILURE=1 97EXIT_FATAL=2 98 99# 100# The used programs. 101# 102Eval=eval 103ThisGcal=/usr/local/bin/gcal 104# 105Awk=@AWK@ 106Awk_script1=$mydefaultname""1.awk 107Awk_script2=$mydefaultname""2.awk 108# 109Perl=@PERL@ 110Perl_script1=$mydefaultname""1.pl 111Perl_script2=$mydefaultname""2.pl 112 113# 114# Let's check for command line arguments. 115# 116debug=no 117precise="" 118commands="" 119previous="" 120for option in $* 121do 122 # 123 # If the previous option needs an argument, assign it. 124 # 125 if $Test -n "$previous"; 126 then 127 $Eval "$previous=\$option" 128 previous="" 129 continue 130 fi 131 132 case "$option" in 133 -*=) optarg="###error###" ;; 134 -*=*) optarg=`$Echo "$option" | $Sed 's/[-_a-zA-Z0-9]*=//'` ;; 135 *) optarg="" ;; 136 esac 137 138 # 139 # Manage the options. 140 # 141 case "$option" in 142 -help=* | -hel=* | -he=* | -h=* | -help | -hel | -he | -h | \ 143 --help=* | --hel=* | --he=* | --h=* | --help | --hel | --he | --h) 144 if $Test -n "$optarg"; 145 then 146 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 147 exit $EXIT_FAILURE 148 fi 149 $Echo "$info1" 150 $Echo "$info2" 151 $Echo "$info3" 152 $Echo "$info4" 153 $Echo "$info5" 154 $Echo "$usage1" 155 $Echo "$usage2" 156 $Echo "$usage3" 157 exit $EXIT_SUCCESS ;; 158 159 -version=* | -versio=* | -versi=* | -vers=* | -ver=* | -ve=* | -v=* | \ 160 -version | -versio | -versi | -vers | -ver | -ve | -v | \ 161 --version=* | --versio=* | --versi=* | --vers=* | --ver=* | --ve=* | --v=* | \ 162 --version | --versio | --versi | --vers | --ver | --ve | --v) 163 if $Test -n "$optarg"; 164 then 165 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 166 exit $EXIT_FAILURE 167 fi 168 $Echo "$myinternalname" 169 exit $EXIT_SUCCESS ;; 170 171 -debug=* | -debu=* | -deb=* | -de=* | -d=* | \ 172 -debug | -debu | -deb | -de | -d | \ 173 --debug=* | --debu=* | --deb=* | --de=* | --d=* | \ 174 --debug | --debu | --deb | --de | --d) 175 if $Test -n "$optarg"; 176 then 177 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 178 exit $EXIT_FAILURE 179 fi 180 debug=yes 181 shift ;; 182 183 -precise=* | -precis=* | -preci=* | -prec=* | -pre=* | -pr=* | -p=* | \ 184 -precise | -precis | -preci | -prec | -pre | -pr | -p | \ 185 --precise=* | --precis=* | --preci=* | --prec=* | --pre=* | --pr=* | --p=* | \ 186 --precise | --precis | --preci | --prec | --pre | --pr | --p) 187 if $Test -n "$optarg"; 188 then 189 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 190 exit $EXIT_FAILURE 191 fi 192 precise="--precise" 193 shift ;; 194 195 -*) 196 $Echo "$myname: error: $option: invalid option, use --help to show usage" 1>&2 197 exit $EXIT_FAILURE ;; 198 199 *) 200 if $Test -z "$commands"; 201 then 202 commands="$option" 203 else 204 commands="$commands $option" 205 fi 206 esac 207done 208 209# 210# Get the number of commands given and assign them to the local variables. 211# 212cmd_number=0 213cmd_1="" 214for cmd in $commands 215do 216 if $Test -z "$cmd_1"; 217 then 218 cmd_1="$cmd" 219 fi 220 cmd_number=`$Expr $cmd_number + 1` 221done 222 223# 224# Enable tracing. 225# 226if $Test "$debug" = yes; 227then 228 $Set -x 229else 230 trap "$Rm -f $runscriptname $gcal_resource_file;exit $EXIT_FAILURE" 1 2 15 231fi 232 233# 234# Let's start processing now. 235# 236if $Test -n "$Awk" || $Test -n "$Perl"; 237then 238 if $Test "$cmd_number" -gt 1; 239 then 240 $Echo "$info1" 241 $Echo "$info2" 242 $Echo "$info3" 243 $Echo "$info4" 244 $Echo "$info5" 245 $Echo "$usage1" 246 $Echo "$usage2" 247 $Echo "$usage3" 248 exit $EXIT_FAILURE 249 else 250 if $Test "$cmd_number" -eq 1; 251 then 252 pool="$cmd_1" 253 fi 254 if $Test ! -s "$pool"; 255 then 256 $Echo "$myname: error: ZONE-FILE \`$pool' not found" 1>&2 257 exit $EXIT_FAILURE 258 fi 259 # 260 # We prefer the use of Perl. 261 # 262 if $Test -n "$Perl"; 263 then 264 if $Test ! -s "$packagedatamiscdir/$Perl_script1"; 265 then 266 $Echo "$myname: error: file \`$packagedatamiscdir/$Perl_script1' is missing" 1>&2 267 exit $EXIT_FAILURE 268 fi 269 if $Test ! -s "$packagedatamiscdir/$Perl_script2"; 270 then 271 $Echo "$myname: error: file \`$packagedatamiscdir/$Perl_script2' is missing" 1>&2 272 exit $EXIT_FAILURE 273 fi 274 $Echo "$myname: generating the script text \`$runscriptname', please wait..." 275 $Perl -- $packagedatamiscdir/$Perl_script1 -a1 -b./$gcal_resource_file -c$ThisGcal -d$precise $pool > $runscriptname 276 status=$? 277 if $Test "$status" -eq "$EXIT_FATAL"; 278 then 279 $Echo "$myinternalname: error: invalid option to \`$Perl' given" 1>&2 280 if $Test "$debug" = no; 281 then 282 $Rm -f $runscriptname 283 fi 284 exit $status 285 else 286 if $Test -s "$runscriptname"; 287 then 288 $Chmod u+x $runscriptname 289 fi 290 fi 291 $Echo "$myname: generating the Gcal resource file \`$gcal_resource_file', please wait..." 292 $Perl -- $packagedatamiscdir/$Perl_script2 -a1 -b$gcal_resource_file $pool > $gcal_resource_file 293 status=$? 294 if $Test "$status" -eq "$EXIT_FATAL"; 295 then 296 $Echo "$myinternalname: error: invalid option to \`$Perl' given" 1>&2 297 if $Test "$debug" = no; 298 then 299 $Rm -f $gcal_resource_file 300 fi 301 exit $status 302 fi 303 else 304 if $Test ! -s "$packagedatamiscdir/$Awk_script1"; 305 then 306 $Echo "$myname: error: file \`$packagedatamiscdir/$Awk_script1' is missing" 1>&2 307 exit $EXIT_FAILURE 308 fi 309 if $Test ! -s "$packagedatamiscdir/$Awk_script2"; 310 then 311 $Echo "$myname: error: file \`$packagedatamiscdir/$Awk_script2' is missing" 1>&2 312 exit $EXIT_FAILURE 313 fi 314 $Echo "$myname: generating the script text \`$runscriptname', please wait..." 315 $Awk -f $packagedatamiscdir/$Awk_script1 -- -a1 -b./$gcal_resource_file -c$ThisGcal -d$precise $pool > $runscriptname 316 status=$? 317 if $Test "$status" -eq "$EXIT_FATAL"; 318 then 319 $Echo "$myinternalname: error: invalid option to \`$Awk' given" 1>&2 320 if $Test "$debug" = no; 321 then 322 $Rm -f $runscriptname 323 fi 324 exit $status 325 else 326 if $Test -s "$runscriptname"; 327 then 328 $Chmod u+x $runscriptname 329 fi 330 fi 331 $Echo "$myname: generating the Gcal resource file \`$gcal_resource_file', please wait..." 332 $Awk -f $packagedatamiscdir/$Awk_script2 -- -a1 -b$gcal_resource_file $pool > $gcal_resource_file 333 status=$? 334 if $Test "$status" -eq "$EXIT_FATAL"; 335 then 336 $Echo "$myinternalname: error: invalid option to \`$Awk' given" 1>&2 337 if $Test "$debug" = no; 338 then 339 $Rm -f $gcal_resource_file 340 fi 341 exit $status 342 fi 343 fi 344 fi 345 exit $EXIT_SUCCESS 346else 347 $Echo "$myinternalname: error: neither \`perl' nor \`awk' available" 1>&2 348 exit $EXIT_FATAL 349fi 350