1#! /bin/sh 2# 3# misc/ddiff/ddiffdrv. Generated from ddiffdrv.in by configure. 4# 5# $Id: ddiffdrv.in 0.06 2000/03/24 00:00:06 tom Exp $ 6# 7# ddiffdrv.in: First step: 8# Uses `ddiffdrv.rc' or any other Gcal location pool 9# resource file for creating all Gcal location response 10# files which can be generated from that file. 11# If no Gcal location pool resource file exists, this 12# script tries to create the `ddiffdrv.rc' file by 13# processing the ZONE file `zone.tab' by means of 14# AWK/Perl and the `ddiffdrv[.awk|.pl]' script. 15# A Gcal location response file is a Gcal response file 16# consisting of one line, which passes the location name 17# LOC, its country code CC, and the ISO-6709-co-ordinate 18# COORD via text variables to Gcal. The line template of 19# a Gcal location response file is: 20# -r$l=CC-LOC:$c=COORD 21# Second step (only if the `--create' option is given): 22# Creation of all Gcal location resource files, which 23# contain the day/night lengths and differences for all 24# days of the year YYYY for the location. 25# Third step (also only if the `--create' option is given): 26# Creation of the Gcal include file `ddiff.rc', which 27# contains include statements of all Gcal location 28# resource files created. 29# 30# Usage: ddiffdrv --help | --version 31# Usage: ddiffdrv [--debug] [--create] 32# [--precise] [--year=YYYY] 33# [LOCATION-POOL-RESOURCE-FILE without `.rc' suffix] 34# 35# `--debug': Turn on shell debugging. 36# `--create': Automatical creation of all Gcal location 37# resource files and the `ddiff.rc' include 38# file. 39# `--precise': Use more precise time values. 40# `--year=YYYY': Create all Gcal location resource files for 41# the year YYYY, otherwise for the actual year. 42# 43# UN*X solution. 44# 45# Needs `test', `echo', `expr', `eval', `/bin/sh', `set', `sed', `rm', `gcal', 46# and `perl' or `awk' for processing! 47# 48# Returns 0 if processing was successfully. 49# Returns 1 in case an error occured while processing. 50# Returns 2 if neither Perl nor AWK are present for further processing. 51# 52# Copyright (c) 2000 Thomas Esken <esken@uni-muenster.de> 53# Im Hagenfeld 84 54# D-48147 M"unster 55# GERMANY 56# 57# This software doesn't claim completeness, correctness or usability. 58# On principle I will not be liable for ANY damages or losses (implicit 59# or explicit), which result from using or handling my software. 60# If you use this software, you agree without any exception to this 61# agreement, which binds you LEGALLY !! 62# 63# This program is free software; you can redistribute it and/or modify 64# it under the terms of the `GNU General Public License' as published by 65# the `Free Software Foundation'; either version 3, or (at your option) 66# any later version. 67# 68# You should have received a copy of the `GNU General Public License' 69# along with this program; if not, write to the: 70# 71# 72# 73 74# 75# Basically used programs. 76# 77Shell=/bin/sh 78Rm=rm 79Sed=sed 80Set=set 81Test=test 82Echo=echo 83Expr=expr 84 85# 86# Basically used texts. 87# 88packagedatamiscdir=. 89# 90PACKAGE=gcal 91VERSION=4.1 92transform=s,x,x, 93# 94mydefaultname=ddiffdrv 95# 96myname=`$Echo "$0" | $Sed -e 's,.*/,,' -e "$transform"` 97myversion=0.06 98myinternalname="$myname ($PACKAGE $VERSION) $myversion" 99# 100pool=$packagedatamiscdir/zone.tab 101runscriptname=ddiff 102gcal_resource_file_suffix=.rc 103outfile1_created=no 104outfile1=$mydefaultname""$gcal_resource_file_suffix 105outfile2=$runscriptname""$gcal_resource_file_suffix 106# 107info01="$myname: Creates all Gcal location response files which can be generated" 108info02="$myname: from the Gcal location pool resource file \`./$outfile1'." 109info03="$myname: By definition, a Gcal location response file is a text file of" 110info04="$myname: one line with a \`-r\$l=CC-LOCATION:\$c=COORDINATE' contents." 111info05="$myname: If no Gcal location pool resource file exists, this script tries" 112info06="$myname: to create the \`./$outfile1' file by processing the ZONE file" 113info07="$myname: \`$pool'." 114info08="$myname: Then, all Gcal location resource files are created, which " 115info09="$myname: contain the day/night lengths and differences for all days" 116info10="$myname: of the year YYYY for the location. At last, the Gcal include" 117info11="$myname: file \`$outfile2' is created, which contains include statements" 118info12="$myname: of all Gcal location resource files. These last two steps are" 119info13="$myname: done only if the \`--create' option is given!" 120info14="$myname:" 121usage1="usage: $myname --help | --version" 122usage2="usage: $myname [--debug] [--create] [--precise] [--year=YYYY] [LOCATION-POOL-RESOURCE-FILE]" 123usage3="usage: $myname without LOCATION-POOL-RESOURCE-FILE uses file \`./$outfile1' by default" 124 125# 126# Some constant values (EXIT_SUCCESS(==0) and EXIT_FATAL(==2) 127# are also returned by the processed AWK/Perl script. 128# 129EXIT_SUCCESS=0 130EXIT_FAILURE=1 131EXIT_FATAL=2 132 133# 134# The used programs. 135# 136Eval=eval 137ThisGcal=../../src/gcal 138# 139Awk=gawk 140Awk_script=$mydefaultname"".awk 141# 142Perl=perl 143Perl_script=$mydefaultname"".pl 144 145# 146# Let's check for command line arguments. 147# 148debug="" 149create=no 150precise="" 151commands="" 152previous="" 153for option in $* 154do 155 # 156 # If the previous option needs an argument, assign it. 157 # 158 if $Test -n "$previous"; 159 then 160 $Eval "$previous=\$option" 161 previous="" 162 continue 163 fi 164 165 case "$option" in 166 -*=) optarg="###error###" ;; 167 -*=*) optarg=`$Echo "$option" | $Sed 's/[-_a-zA-Z0-9]*=//'` ;; 168 *) optarg="" ;; 169 esac 170 171 # 172 # Manage the options. 173 # 174 case "$option" in 175 -help=* | -hel=* | -he=* | -h=* | -help | -hel | -he | -h | \ 176 --help=* | --hel=* | --he=* | --h=* | --help | --hel | --he | --h) 177 if $Test -n "$optarg"; 178 then 179 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 180 exit $EXIT_FAILURE 181 fi 182 $Echo "$info01" 183 $Echo "$info02" 184 $Echo "$info03" 185 $Echo "$info04" 186 $Echo "$info05" 187 $Echo "$info06" 188 $Echo "$info07" 189 $Echo "$info08" 190 $Echo "$info09" 191 $Echo "$info10" 192 $Echo "$info11" 193 $Echo "$info12" 194 $Echo "$info13" 195 $Echo "$info14" 196 $Echo "$usage1" 197 $Echo "$usage2" 198 $Echo "$usage3" 199 exit $EXIT_SUCCESS ;; 200 201 -version=* | -versio=* | -versi=* | -vers=* | -ver=* | -ve=* | -v=* | \ 202 -version | -versio | -versi | -vers | -ver | -ve | -v | \ 203 --version=* | --versio=* | --versi=* | --vers=* | --ver=* | --ve=* | --v=* | \ 204 --version | --versio | --versi | --vers | --ver | --ve | --v) 205 if $Test -n "$optarg"; 206 then 207 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 208 exit $EXIT_FAILURE 209 fi 210 $Echo "$myinternalname" 211 exit $EXIT_SUCCESS ;; 212 213 -debug=* | -debu=* | -deb=* | -de=* | -d=* | \ 214 -debug | -debu | -deb | -de | -d | \ 215 --debug=* | --debu=* | --deb=* | --de=* | --d=* | \ 216 --debug | --debu | --deb | --de | --d) 217 if $Test -n "$optarg"; 218 then 219 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 220 exit $EXIT_FAILURE 221 fi 222 debug="$optarg" 223 shift ;; 224 225 -create=* | -creat=* | -crea=* | -cre=* | -cr=* | -c=* | \ 226 -create | -creat | -crea | -cre | -cr | -c | \ 227 --create=* | --creat=* | --crea=* | --cre=* | --cr=* | --c=* | \ 228 --create | --creat | --crea | --cre | --cr | --c) 229 if $Test -n "$optarg"; 230 then 231 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 232 exit $EXIT_FAILURE 233 fi 234 create=yes 235 shift ;; 236 237 -precise=* | -precis=* | -preci=* | -prec=* | -pre=* | -pr=* | -p=* | \ 238 -precise | -precis | -preci | -prec | -pre | -pr | -p | \ 239 --precise=* | --precis=* | --preci=* | --prec=* | --pre=* | --pr=* | --p=* | \ 240 --precise | --precis | --preci | --prec | --pre | --pr | --p) 241 if $Test -n "$optarg"; 242 then 243 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2 244 exit $EXIT_FAILURE 245 fi 246 precise="$optarg" 247 shift ;; 248 249 -year | -yea | -ye | -y | --year | --yea | --ye | --y) 250 previous=year ;; 251 -year=* | -yea=* | -ye=* | -y=* | --year=* | --yea=* | --ye=* | --y=*) 252 if $Test -z "$optarg" || $Test "$optarg" = "###error###"; 253 then 254 $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=//g'`' requires an argument" 1>&2 255 exit $EXIT_FAILURE 256 fi 257 opt_year="$optarg" 258 shift ;; 259 260 -* | /*) 261 $Echo "$myname: error: $option: invalid option, use --help to show usage" 1>&2 262 exit $EXIT_FAILURE ;; 263 264 *) 265 if $Test -z "$commands"; 266 then 267 commands="$option" 268 else 269 commands="$commands $option" 270 fi 271 esac 272done 273 274if $Test -n "$previous"; 275then 276 $Echo "$myname: error: missing argument to --$previous" 1>&2 277 exit $EXIT_FAILURE 278fi 279 280# 281# Get the number of commands given and assign them to the local variables. 282# 283cmd_number=0 284cmd_1="" 285for cmd in $commands 286do 287 if $Test -z "$cmd_1"; 288 then 289 cmd_1="$cmd" 290 fi 291 cmd_number=`$Expr $cmd_number + 1` 292done 293 294# 295# Enable tracing. 296# 297if $Test -n "$debug"; 298then 299 $Set -x 300else 301 trap "$Rm -f $outfile1 $outfile2;exit $EXIT_FAILURE" 1 2 15 302fi 303 304# 305# Let's start processing now. 306# 307if $Test -n "$Awk" || $Test -n "$Perl"; 308then 309 if $Test "$#" -gt 1; 310 then 311 $Echo "$info01" 312 $Echo "$info02" 313 $Echo "$info03" 314 $Echo "$info04" 315 $Echo "$info05" 316 $Echo "$info06" 317 $Echo "$info07" 318 $Echo "$info08" 319 $Echo "$info09" 320 $Echo "$info10" 321 $Echo "$info11" 322 $Echo "$info12" 323 $Echo "$info13" 324 $Echo "$info14" 325 $Echo "$usage1" 326 $Echo "$usage2" 327 $Echo "$usage3" 328 exit $EXIT_FAILURE 329 else 330 gcal_year="" 331 if $Test -n "$opt_year"; 332 then 333 arg=`$Echo "$opt_year" | $Sed -e 's/[0-9]//g'` 334 if $Test -n "$arg"; 335 then 336 $Echo "$myname: error: invalid option argument \`$opt_year' specified" 1>&2 337 $Echo "$myname: use --help to show usage" 1>&2 338 exit $EXIT_FAILURE 339 else 340 gcal_year="--year=$opt_year" 341 fi 342 fi 343 if $Test "$cmd_number" -eq 1 && $Test -s "$cmd_1"; 344 then 345 outfile1="$cmd_1" 346 else 347 if $Test ! -s "$outfile1"; 348 then 349 # 350 if $Test ! -s "$pool"; 351 then 352 $Echo "$myname: error: file \`$pool' is missing" 1>&2 353 exit $EXIT_FAILURE 354 fi 355 # 356 # We prefer the use of Perl. 357 # 358 if $Test -n "$Perl"; 359 then 360 if $Test ! -s "$packagedatamiscdir/$Perl_script"; 361 then 362 $Echo "$myname: error: file \`$packagedatamiscdir/$Perl_script' is missing" 1>&2 363 exit $EXIT_FAILURE 364 fi 365 $Echo "$myname: creating the Gcal location pool resource file \`$outfile1', please wait..." 366 $Perl -- $packagedatamiscdir/$Perl_script -a0 -b$outfile1 -c$myname $pool > $outfile1 367 else 368 if $Test ! -s "$packagedatamiscdir/$Awk_script"; 369 then 370 $Echo "$myname: error: file \`$packagedatamiscdir/$Awk_script' is missing" 1>&2 371 exit $EXIT_FAILURE 372 fi 373 $Echo "$myname: creating the Gcal location pool resource file \`$outfile1', please wait..." 374 $Awk -f $packagedatamiscdir/$Awk_script -- -a0 -b$outfile1 -c$myname $pool > $outfile1 375 fi 376 status=$? 377 if $Test "$status" -eq "$EXIT_FATAL"; 378 then 379 if $Test -n "$Perl"; 380 then 381 $Echo "$myinternalname: error: invalid option to \`$Perl' given" 1>&2 382 else 383 $Echo "$myinternalname: error: invalid option to \`$Awk' given" 1>&2 384 fi 385 if $Test -z "$debug"; 386 then 387 $Rm -f $outfile1 388 fi 389 exit $status 390 else 391 outfile1_created=yes 392 fi 393 fi 394 fi 395 fi 396 # 397 $Echo "$myname: generating all Gcal location response files, please wait..." 398 if $Test "$outfile1_created" = yes; 399 then 400 $ThisGcal --execute -f ./$outfile1 -QUx --translate-string=\\_ 401 else 402 $ThisGcal --execute -f $outfile1 -QUx --translate-string=\\_ 403 fi 404 if $Test "$create" = yes; 405 then 406 # 407 # Create all Gcal location resource files. 408 # 409 for file in ??-*; 410 do 411 $Shell $runscriptname $debug $precise $gcal_year ./$file 412 done 413 # 414 # Create the Gcal include file. 415 # 416 $Echo "$myname: creating the Gcal include file \`$outfile2', please wait..." 417 $Echo "; $outfile2, includes the locations for Gcal-2.20 or newer" > $outfile2 418 $Echo ";" >> $outfile2 419 for file in ??-*$gcal_resource_file_suffix; 420 do 421 $Echo "#include \"$file\"" >> $outfile2 422 done 423 fi 424 exit $EXIT_SUCCESS 425else 426 $Echo "$myinternalname: error: neither \`perl' nor \`awk' available" 1>&2 427 exit $EXIT_FATAL 428fi 429