-v option support

Tim Murphy tpm at hi.com
Thu May 1 18:42:24 UTC 1997


The zic(8) man page describes the -v option as

     -v   Complain if a year that appears in a data file is out-
          side the range of years representable by time(2)
          values.

However this functionality appears to have been removed from the code.
It is not clear whether this description should have been removed from
the man page or whether the functionality was unintentionally removed
from the code.

If the general consensus is that the man page is correct then some
code similar to the following could be added to implement it.  I am
open to issues and alternatives.

>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>>
***************
*** 129,134 ****
--- 263,269 ----
  static void   usage P((void));
  static void   writezone P((const char * name));
  static int    yearistype P((int year, const char * type));
+ static void   year_noise_check P((int year));
  
  #if !(HAVE_STRERROR - 0)
  static char * strerror P((int));

***************
*** 141,148 ****
--- 276,285 ----
  static int            linenum;
  static time_t         max_time;
  static int            max_year;
+ static int            max_year_representable;
  static time_t         min_time;
  static int            min_year;
+ static int            min_year_representable;
  static int            noise;
  static const char *   rfilename;
  static int            rlinenum;

***************
*** 649,654 ****
--- 824,831 ----
        }
        min_year = TM_YEAR_BASE + gmtime(&min_time)->tm_year;
        max_year = TM_YEAR_BASE + gmtime(&max_time)->tm_year;
+       min_year_representable = min_year;
+       max_year_representable = max_year;
  }
  
***************
*** 1278,1288 ****
                rp->r_yrtype = NULL;
        else {
                if (rp->r_loyear == rp->r_hiyear) {
!                       error(_("typed single year"));
                        return;
                }
                rp->r_yrtype = ecpyalloc(typep);
        }
        if (rp->r_loyear < min_year && rp->r_loyear > 0)
                min_year = rp->r_loyear;
        /*
--- 1463,1478 ----
                rp->r_yrtype = NULL;
        else {
                if (rp->r_loyear == rp->r_hiyear) {
!                       error(MSGSTR(ONEYEAR,"typed single year"));
                        return;
                }
                rp->r_yrtype = ecpyalloc(typep);
        }
+       if (noise)
+       {
+               year_noise_check(rp->r_loyear);
+               year_noise_check(rp->r_hiyear);
+       }
        if (rp->r_loyear < min_year && rp->r_loyear > 0)
                min_year = rp->r_loyear;
        /*

***************
*** 2169,2179 ****
        l = i;
        if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) {
                (void) fprintf(stderr,
!                       _("%s: %d did not sign extend correctly\n"),
                        progname, i);
                (void) exit(EXIT_FAILURE);
        }
        return l;
  }
  
  /*
--- 2365,2399 ----
        l = i;
        if ((i < 0 && l >= 0) || (i == 0 && l != 0) || (i > 0 && l <= 0)) {
                (void) fprintf(stderr,
!                       MSGSTR(BADSIGN,"%s: %d did not sign extend correctly.\n"),
                        progname, i);
                (void) exit(EXIT_FAILURE);
        }
        return l;
+ }
+ 
+ static void
+ year_noise_check(year)
+ int year;
+ {
+       if ( ( (year < min_year_representable) ||
+              (year > max_year_representable) ) &&
+              ( (year != INT_MIN) && (year != INT_MAX) ) )
+       {
+               static char *format;
+               static char *message;
+ 
+               if (!format)
+               {
+                       format = MSGSTR(UNREPYEAR, "unrepresentable year: %d");
+               }
+               if (!message)
+               {
+                       message = emalloc(strlen(format) + 32);
+               }
+               (void) sprintf(message, format, year);
+               warning(message);
+       }
  }
  
  /*
<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<<

Note that MSGSTR() is a simple macro that invokes catgets(3) on
systems which support the X/Open interfaces.

----------------------------------------------------------------------
Timothy Patrick Murphy		tpm at hi.com 	Voice: (617) 890-0444	
Hitachi Computer Products                 	  Fax: (617) 890-4998
1601 Trapelo Rd., Waltham, MA 02154, USA
----------------------------------------------------------------------



More information about the tz mailing list