File: srss

package info (click to toggle)
gcal 4.2.0-3
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid
  • size: 17,952 kB
  • sloc: ansic: 98,660; sh: 8,454; perl: 2,088; awk: 1,531; makefile: 614; sed: 166
file content (438 lines) | stat: -rw-r--r-- 13,030 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
#! /bin/sh
#
#  misc/srss/srss.  Generated from srss.in by configure.
#
#  $Id: srss.in 0.09 2000/03/24 00:00:09 tom Exp $
#
#  srss.in:  Uses `srss[.awk|.pl]' for processing the Gcal `srss.rc' resource
#              file to display the times at which sunrise/sunset has happened
#              in the past respectively will happen in the future, based on
#              the actual local time.  If a Gcal resource file is specified
#              as program option, this resource file is used instead of the
#              default resource file `srss.rc'.
#
#              Usage: srss --help | --version
#              Usage: srss [--debug] [--mail[=ADDRESS]]
#                          [--no-pager] [--mode=rise|set] [--sort=abs|rel]
#                          [RESOURCE-FILE] [more Gcal options...]
#
#              `--debug':          Turn on shell debugging.
#              `--mail[=ADDRESS]': EMail the result to the specified ADDRESS.
#                                    If no ADDRESS is given, eMail it to
#                                    $MAILTO, $USER or $LOGNAME.
#              `--no-pager':       Disable the use of a pager program.
#              `--mode=rise':      Display the sunrise local times of the
#                                    locations.
#              `--mode=set':       Display the sunset local times of the
#                                    locations.  If this option is not given,
#                                    `--mode=rise' is used by default.
#              `--sort=abs':       The sort order of the past times (indicated
#                                    by a `-' sign) respectively future times
#                                    (indicated by a `+' sign) is absolute.
#              `--sort=rel':       The sort order of the past times (indicated
#                                    by a `-' sign) respectively future times
#                                    (indicated by a `+' sign) is relative.
#                                    If this option is not given, `--mode=abs'
#                                    is used by default.
#
#  UN*X solution.
#
#  Needs `test', `echo', `eval', `set', `sed', `date', `mail', `sort',
#  `gcal' and `perl' or `awk' for processing!
#
#  Returns 0 if any fixed dates are created (returned by AWK/Perl script
#            if neither `--help' nor `--version' option was specified).
#  Returns 1 in case no fixed dates are created (returned by AWK/Perl script).
#  Returns 2 if neither Perl nor AWK are present for further processing.
#
#  Copyright (c) 2000  Thomas Esken      <esken@uni-muenster.de>
#                      Im Hagenfeld 84
#                      D-48147 M"unster
#                      GERMANY
#
#  This software doesn't claim completeness, correctness or usability.
#  On principle I will not be liable for ANY damages or losses (implicit
#  or explicit), which result from using or handling my software.
#  If you use this software, you agree without any exception to this
#  agreement, which binds you LEGALLY !!
#
#  This program is free software; you can redistribute it and/or modify
#  it under the terms of the `GNU General Public License' as published by
#  the `Free Software Foundation'; either version 3, or (at your option)
#  any later version.
#
#  You should have received a copy of the `GNU General Public License'
#  along with this program; if not, write to the:
#
#
#

#
# Basically used programs.
#
Sed=sed
Set=set
Test=test
Echo=echo
Sort=sort

#
# Basically used texts.
#
packagedatamiscdir=.
#
PACKAGE=gcal
VERSION=4.2.0
transform=s,x,x,
#
mydefaultname=srss
#
myname=`$Echo "$0" | $Sed -e 's,.*/,,' -e "$transform"`
myversion=0.09
myinternalname="$myname ($PACKAGE $VERSION) $myversion"
#
param1=rise
param2=set
param3=abs
param4=rel
#
gcal_resource_file_suffix=.rc
gcal_resource_file=$mydefaultname""$gcal_resource_file_suffix
#
info1="$myname: Displays the times at which sun""$param1/sun""$param2 has happened in the"
info2="$myname: past respectively will happen in the future, based on the actual"
info3="$myname: local time for several geographic locations around the world."
info4="$myname:"
usage1="usage: $myname  --help | --version"
usage2="usage: $myname  [--debug] [--mail[=ADDRESS]] [--no-pager] [--mode=$param1|$param2]"
usage3="usage:            [--sort=$param3|$param4] [RESOURCE-FILE] [more Gcal options...]"
usage4="usage: $myname  without \`--mode=$param1|$param2' option uses \`--mode=$param1' by default"
usage5="usage: $myname  without \`--sort=$param3|$param4'  option uses \`--sort=$param3'  by default"
usage6="usage: $myname  without RESOURCE-FILE uses file "\
"\`$packagedatamiscdir/$gcal_resource_file' by default"

#
# Some constant values.
#
EXIT_SUCCESS=0
EXIT_FAILURE=1
EXIT_FATAL=2

#
# The used programs.
#
Eval=eval
Date=date
ThisMail=mail
ThisGcal=../../src/gcal
Pager1=less
Pager2=more
Pager3=
#
Awk=mawk
Awk_script=$mydefaultname"".awk
#
Perl=perl
Perl_script=$mydefaultname"".pl

#
# Let's check for command line arguments.
#
debug=no
pager=yes
mail=no
opt_mail=""
opt_mode=""
opt_sort=""
previous=""
for option in $*
do
  #
  # If the previous option needs an argument, assign it.
  #
  if $Test -n "$previous";
  then
    $Eval "$previous=\$option"
    previous=""
    continue
  fi

  case "$option" in
    -*=)  optarg="###error###" ;;
    -*=*) optarg=`$Echo "$option" | $Sed 's/[-_a-zA-Z0-9]*=//'` ;;
    *)    optarg="" ;;
  esac

  #
  # Manage the options.
  #
  case "$option" in
    -help=* | -hel=* | -he=* | -h=* | -help | -hel |-he | -h | \
    --help=* | --hel=* | --he=* | --h=* | --help | --hel | --he | --h)
      if $Test -n "$optarg";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      $Echo "$info1"
      $Echo "$info2"
      $Echo "$info3"
      $Echo "$info4"
      $Echo "$usage1"
      $Echo "$usage2"
      $Echo "$usage3"
      $Echo "$usage4"
      $Echo "$usage5"
      $Echo "$usage6"
      exit $EXIT_SUCCESS ;;

    -version=* | -versio=* | -versi=* | -vers=* | -ver=* | -ve=* | -v=* | \
    -version | -versio | -versi | -vers | -ver | -ve | -v | \
    --version=* | --versio=* | --versi=* | --vers=* | --ver=* | --ve=* | --v=* | \
    --version | --versio | --versi | --vers | --ver | --ve | --v)
      if $Test -n "$optarg";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      $Echo "$myinternalname"
      exit $EXIT_SUCCESS ;;

    -debug=* | -debu=* | -deb=* | -de=* | -d=* | \
    -debug | -debu | -deb | -de | -d | \
    --debug=* | --debu=* | --deb=* | --de=* | --d=* | \
    --debug | --debu | --deb | --de | --d)
      if $Test -n "$optarg";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      debug=yes
      shift ;;

    -no-pager=* | -no-page | -no-pag=* | -no-pa=* | -no-p=* | -no-=* | -no=* | -n=* | \
    -no-pager | -no-page | -no-pag | -no-pa | -no-p | -no- | -no | -n | \
    --no-pager=* | --no-page=* | --no-pag=* | --no-pa=* | --no-p=* | --no-=* | --no=* | --n=* | \
    --no-pager | --no-page | --no-pag | --no-pa | --no-p | --no- | --no | --n)
      if $Test -n "$optarg";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=.*//'`' doesn't allow an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      pager=no
      shift ;;

    -mail | -mai | -ma | --mail | --mai | --ma | \
    -mail=* | -mai=* | -ma=* | --mail=* | --mai=* | --ma=*)
      if $Test "$optarg" = "###error###";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=//g'`' requires an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      opt_mail="$optarg"
      mail=yes
      shift ;;

    -mode | -mod | -mo | --mode | --mod | --mo)
      previous=mode ;;
    -mode=* | -mod=* | -mo=* | --mode=* | --mod=* | --mo=*)
      if $Test -z "$optarg" || $Test "$optarg" = "###error###";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=//g'`' requires an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      opt_mode="$optarg"
      shift ;;

    -sort | -sor | -so | -s | --sort | --sor | --so | --s)
      previous=sort ;;
    -sort=* | -sor=* | -so=* | -s=* | --sort=* | --sor=* | --so=* | --s=*)
      if $Test -z "$optarg" || $Test "$optarg" = "###error###";
      then
        $Echo "$myname: error: option \``$Echo $option | $Sed -e 's/=//g'`' requires an argument" 1>&2
        exit $EXIT_FAILURE
      fi
      opt_sort="$optarg"
      shift ;;
  esac
done

if $Test -n "$previous";
then
  $Echo "$myname: error: missing argument to --$previous" 1>&2
  exit $EXIT_FAILURE
fi

#
# Enable tracing.
#
if $Test "$debug" = yes;
then
  $Set -x
fi

#
# Let's start processing now.
#
if $Test -n "$Awk" || $Test -n "$Perl";
then
  SCRIPT_ARGS=""
  if $Test -n "$opt_mode";
  then
    arg=`$Echo "$opt_mode" | $Sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
    if $Test "$arg" = "$param1" || $Test "$arg" = "$param2";
    then
      SCRIPT_ARGS="-a""$arg"
    else
      $Echo "$myname: error: invalid option argument \`$opt_mode' specified" 1>&2
      $Echo "$myname: use --help to show usage" 1>&2
      exit $EXIT_FAILURE
    fi
  fi
  if $Test -n "$opt_sort";
  then
    arg=`$Echo "$opt_sort" | $Sed -e 'y/ABCDEFGHIJKLMNOPQRSTUVWXYZ/abcdefghijklmnopqrstuvwxyz/'`
    if $Test "$arg" = "$param3" || $Test "$arg" = "$param4";
    then
      SCRIPT_ARGS="$SCRIPT_ARGS -b""$arg"
    else
      $Echo "$myname: error: invalid option argument \`$opt_sort' specified" 1>&2
      $Echo "$myname: use --help to show usage" 1>&2
      exit $EXIT_FAILURE
    fi
  fi
  ARGS=""
  CMDS=""
  FILS=""
  for arg in $*
  do
    case "$arg" in
      -*) ARGS="$ARGS $arg" ;;
      /*) ARGS="$ARGS $arg" ;;
      @*) ARGS="$ARGS $arg" ;;
      %*) ARGS="$ARGS $arg" ;;
      [0-9*]*) CMDS="$CMDS $arg" ;;
      *) if $Test -z "$FILS";
         then
           FILS="$arg"
         else
           FILS="$FILS+$arg"
         fi
    esac
  done
  if $Test -z "$FILS";
  then
    FILS=$packagedatamiscdir/$gcal_resource_file
  fi
  if $Test "$mail" = no;
  then
    ARGS="$ARGS -Hyes"
  fi
  #
  # We prefer the use of Perl.
  #
  if $Test -n "$Perl";
  then
    result=`$ThisGcal $ARGS -QUx -f $FILS $CMDS | \
            $Perl -- $packagedatamiscdir/$Perl_script $SCRIPT_ARGS`
  else
    result=`$ThisGcal $ARGS -QUx -f $FILS $CMDS | \
            $Awk -f $packagedatamiscdir/$Awk_script $SCRIPT_ARGS`
  fi
  status=$?
  if $Test "$status" -eq "$EXIT_SUCCESS";
  then
    if $Test "$mail" = yes;
    then
      #
      # Detect the proper eMail address.
      #
      if $Test -n "$opt_mail";
      then
        MailAddr="$opt_mail"
      else
        if $Test -n "$MAILTO";
        then
          MailAddr="$MAILTO"
        else
          if $Test -n "$USER";
          then
            MailAddr="$USER"
          else
            if $Test -n "$LOGNAME";
            then
              MailAddr="$LOGNAME"
            else
              $Echo "$myname: warning: cannot send mail, address unknown" 1>&2
              $Echo "$result" | $Sort | $Sed -e 's/^\(.......\)//' 1>&2
              exit $EXIT_FAILURE
            fi
          fi
        fi
      fi
      #
      # EMail the result.
      #
      if $Test -n "$MAILPROG";
      then
        ThisMail="$MAILPROG"
      fi
      if $Test "$debug" = no;
      then
        $Echo "$result" | $Sort | $Sed -e 's/^\(.......\)//' | \
          $ThisMail -s "Mail from \`$myname' (`$Date`)" $MailAddr
      fi
      $Echo "$myname: result sent by $ThisMail to \`$MailAddr'"
    else
      #
      # Detect a proper pager.
      #
      ThisPager=""
      if $Test "$pager" = yes;
      then
        if $Test -n "$Pager1";
        then
          ThisPager="$Pager1"
        else
          if $Test -n "$Pager2";
          then
            ThisPager="$Pager2"
          else
            if $Test -n "$Pager3";
            then
              ThisPager="$Pager3"
            fi
          fi
        fi
      fi
      #
      # Display the result.
      #
      if $Test -n "$ThisPager";
      then
        $Echo "$result" | $Sort | $Sed -e 's/^\(.......\)//' | $ThisPager
      else
        $Echo "$result" | $Sort | $Sed -e 's/^\(.......\)//'
      fi
    fi
  else
    if $Test "$status" -eq "$EXIT_FAILURE";
    then
      $Echo "$myname: error: no sunrise/sunset times found" 1>&2
    else
      if $Test "$status" -eq "$EXIT_FATAL";
      then
        if $Test -n "$Perl";
        then
          $Echo "$myinternalname: error: invalid option \`$SCRIPT_ARGS' to \`$Perl' given" 1>&2
        else
          $Echo "$myinternalname: error: invalid option \`$SCRIPT_ARGS' to \`$Awk' given" 1>&2
        fi
      fi
    fi
  fi
  exit $status
else
  $Echo "$myinternalname: error: neither \`perl' nor \`awk' available" 1>&2
  exit $EXIT_FATAL
fi