"Fossies" - the Fresh Open Source Software Archive

Member "gcal-4.1/misc/dst/dst" (22 Jan 2017, 9986 Bytes) of package /linux/misc/gcal-4.1.tar.gz:


As a special service "Fossies" has tried to format the requested source page into HTML format using (guessed) Bash source code syntax highlighting (style: standard) with prefixed line numbers. Alternatively you can here view or download the uninterpreted source code file. See also the latest Fossies "Diffs" side-by-side code changes report for "dst": 4_vs_4.1.

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