1#  $Id: ddiffdrv.pl 0.04 2000/01/12 00:00:04 tom Exp $
2#
3#  ddiffdrv.pl:  Processes the ZONE file `zone.tab' and creates
4#                  Gcal location response files.
5#
6#  Any but default configuration could confuse this script.
7#  It comes along with a UN*X script `ddiffdrv' and a DOS batch `ddiffdrv.bat'
8#  which supports the correct usage.
9#
10#  It is *not* guaranteed that this script works for any other call than
11#  the one given above but it could easily be modified and extended for
12#  using other special modes of operation.
13#
14#  If you modify this script you have to rename the modified version.
15#
16#  If you make any improvements I would like to hear from you.
17#  But I do not promise any support.
18#
19#  Copyright (c) 2000  Thomas Esken      <esken@uni-muenster.de>
20#                      Im Hagenfeld 84
21#                      D-48147 M"unster
22#                      GERMANY
23#
24#  This software doesn't claim completeness, correctness or usability.
25#  On principle I will not be liable for ANY damages or losses (implicit
26#  or explicit), which result from using or handling my software.
27#  If you use this software, you agree without any exception to this
28#  agreement, which binds you LEGALLY !!
29#
30#  This program is free software; you can redistribute it and/or modify
31#  it under the terms of the `GNU General Public License' as published by
32#  the `Free Software Foundation'; either version 3, or (at your option)
33#  any later version.
34#
35#  You should have received a copy of the `GNU General Public License'
36#  along with this program; if not, write to the:
37#
38#
39#
40$[ = 1;			# set array base to 1
41
42#
43# Define the default return values of this process.
44#
45$EXIT_SUCCESS = 0;
46$EXIT_FATAL = 2;
47#
48# Get possibly given command line arguments.
49#
50for ($i = 1; $i < ($#ARGV+1); $i++) {
51    if (substr($ARGV[$i], 1, 1) eq '-') {
52	if (substr($ARGV[$i], 2, 1) eq 'a') {
53	    $a = substr($ARGV[$i], 3, 999999);
54	}
55	elsif (substr($ARGV[$i], 2, 1) eq 'b') {
56	    $b = substr($ARGV[$i], 3, 999999);
57	}
58	elsif (substr($ARGV[$i], 2, 1) eq 'c') {
59	    $c = substr($ARGV[$i], 3, 999999);
60	}
61	else {
62	    exit $EXIT_FATAL;
63	}
64    }
65    else {
66	last;
67    }
68    shift;
69    $i--;
70}
71printf "; %s, location names and coordinates for Gcal-2.20 or newer\n;\n", $b;
72printf "; The line template.\n;\n";
73if ($a == 0) {
74    printf "\$x=0 %s: Gcal location response file `\$<1l*l' created...%%!echo -r'\\\$c=\$c:\\\$l=\$l' > \$<1l*l\n", $c;
75}
76else {
77    printf "\$x=0 %s: Gcal location response file `\$<8l#l' created...%%!echo -r\\\$c=\$c:\\\$l=\$l> \$<8l#l\n", $c;
78}
79printf ";\n; The locations.\n";
80
81#
82# Main block.
83#
84line: while (<>) {
85    chop;	# strip record separator
86    @Fld = split(' ', $_, 9999);
87
88    if (substr($_, 1, 1) ne '#' && $_ ne '') {
89	$location = $Fld[3];
90	$len = length($location);
91	for ($i = 1; $i <= $len; $i++) {
92	    if (substr($location, $i, 1) eq '/') {
93		$len -= $i;
94		$location = substr($location, $i + 1, $len);
95		$i = 1;
96	    }
97	}
98	$loc = '';
99	$len = length($location);
100	for ($i = 1; $i <= $len; $i++) {
101	    if (substr($location, $i, 1) eq '_') {
102		$loc = $loc . "\\";
103	    }
104	    $loc = $loc . substr($location, $i, 1);
105	}
106	printf ";\n; Location %s, %s\n;\n\$l=%s-%s\n\$c=%s\n\$x\n",
107	    $location, $Fld[1], $Fld[1], $loc, $Fld[2];
108    }
109}
110
111exit $EXIT_SUCCESS;
112