Get the "getdate" routine working. Created suitable Makefile.in and
authorTheodore Tso <tytso@mit.edu>
Fri, 7 Oct 1994 01:36:11 +0000 (01:36 +0000)
committerTheodore Tso <tytso@mit.edu>
Fri, 7 Oct 1994 01:36:11 +0000 (01:36 +0000)
configure.in scripts for this purpose.

git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@4465 dc483132-0cff-0310-8789-dd5450dbe970

src/kadmin.new/client/Makefile.in [new file with mode: 0644]
src/kadmin.new/client/configure.in [new file with mode: 0644]
src/kadmin.new/client/getdate.y

diff --git a/src/kadmin.new/client/Makefile.in b/src/kadmin.new/client/Makefile.in
new file mode 100644 (file)
index 0000000..41b81c8
--- /dev/null
@@ -0,0 +1,32 @@
+CFLAGS = $(CCOPTS) $(DEFS) $(LOCALINCLUDE)
+LDFLAGS = -g
+
+ISODELIB=@ISODELIB@
+COMERRLIB=$(BUILDTOP)/util/et/libcom_err.a
+SSLIB=$(BUILDTOP)/util/ss/libss.a
+DBMLIB=
+KDBLIB=$(TOPLIBD)/libkdb5.a 
+
+all::
+
+KLIB = $(TOPLIBD)/libkrb5.a $(TOPLIBD)/libcrypto.a $(ISODELIB) $(SSLIB) $(COMERRLIB) $(DBMLIB)
+DEPKLIB = $(TOPLIBD)/libkrb5.a $(TOPLIBD)/libcrypto.a $(SSLIB) $(COMERRLIB) $(DBMLIB)
+
+SRCS = 
+
+OBJS = getdate.o
+
+all::  getdate
+
+getdate.c getdate.h: getdate.y
+       $(RM) getdate.c getdate.h y.tab.*
+       $(YACC) -d $(srcdir)/getdate.y
+       $(MV) y.tab.c getdate.c
+       $(MV) y.tab.h getdate.h
+
+getdate: getdate.c
+       $(CC) -o getdate $(CFLAGS) -DTEST getdate.c
+
+clean::
+       $(RM) getdate getdate.c getdate.h y.tab.c y.tab.h
+
diff --git a/src/kadmin.new/client/configure.in b/src/kadmin.new/client/configure.in
new file mode 100644 (file)
index 0000000..4ade062
--- /dev/null
@@ -0,0 +1,12 @@
+AC_INIT(getdate.y)
+WITH_CCOPTS
+CONFIG_RULES
+AC_SET_BUILDTOP
+AC_PROG_INSTALL
+AC_PROG_YACC
+AC_HAVE_HEADERS(unistd.h sys/timeb.h alloca.h)
+AC_HAVE_FUNCS(ftime timezone)
+KRB_INCLUDE
+ISODE_INCLUDE
+WITH_KRB5ROOT
+AC_OUTPUT(Makefile,[EXTRA_RULES])
index d010cb6e078f82f7da1e9de82c65f1e2404aa7fe..6b03e73bb79af6c52b9507d1979c3b8b4a09399d 100644 (file)
 %{
-/* 1.8
-** @(#)getdate.y 1.8 92/03/03
-**
+/*
 **  Originally written by Steven M. Bellovin <smb@research.att.com> while
 **  at the University of North Carolina at Chapel Hill.  Later tweaked by
 **  a couple of people on Usenet.  Completely overhauled by Rich $alz
 **  <rsalz@bbn.com> and Jim Berets <jberets@bbn.com> in August, 1990;
 **  send any email to Rich.
 **
-**  This grammar has eight shift/reduce conflicts.
+**  This grammar has nine shift/reduce conflicts.
 **
 **  This code is in the public domain and has no copyright.
 */
-/* SUPPRESS 287 on yaccpar_sccsid *//* Unused static variable */
+/* SUPPRESS 287 on yaccpar_sccsid *//* Unusd static variable */
 /* SUPPRESS 288 on yyerrlab *//* Label unused */
 
-#include "system.h"
-#include <ctype.h>
+#ifdef HAVE_CONFIG_H
+#if defined (emacs) || defined (CONFIG_BROKETS)
+#include <config.h>
+#else
+#include "config.h"
+#endif
+#endif
+
+/* Since the code of getdate.y is not included in the Emacs executable
+   itself, there is no need to #define static in this file.  Even if
+   the code were included in the Emacs executable, it probably
+   wouldn't do any harm to #undef it here; this will only cause
+   problems if we try to write to a static variable, which I don't
+   think this code needs to do.  */
+#ifdef emacs
+#undef static
+#endif
+
+/* The following block of alloca-related preprocessor directives is here
+   solely to allow compilation by non GNU-C compilers of the C parser
+   produced from this file by old versions of bison.  Newer versions of
+   bison include a block similar to this one in bison.simple.  */
 
-#if (!defined (__STDC__) && defined (sparc)) || defined (__sparc__)
 #ifdef __GNUC__
-#undef alloca                  /* might get redefined below */
+#undef alloca
+#define alloca __builtin_alloca
+#else
+#ifdef HAVE_ALLOCA_H
+#include <alloca.h>
+#else
+#ifdef _AIX /* for Bison */
+ #pragma alloca
+#else
+void *alloca ();
+#endif
+#endif
+#endif
+
+#include <stdio.h>
+#include <ctype.h>
+
+/* The code at the top of get_date which figures out the offset of the
+   current time zone checks various CPP symbols to see if special
+   tricks are need, but defaults to using the gettimeofday system call.
+   Include <sys/time.h> if that will be used.  */
+
+#if    defined(vms)
+
+#include <types.h>
+#include <time.h>
+
+#else
+
+#include <sys/types.h>
+
+#ifdef TIME_WITH_SYS_TIME
+#include <sys/time.h>
+#include <time.h>
+#else
+#ifdef HAVE_SYS_TIME_H
+#include <sys/time.h>
+#else
+#include <time.h>
+#endif
+#endif
+
+#ifdef timezone
+#undef timezone /* needed for sgi */
 #endif
+
+#if defined(HAVE_SYS_TIMEB_H)
+#include <sys/timeb.h>
+#else
+/*
+** We use the obsolete `struct timeb' as part of our interface!
+** Since the system doesn't have it, we define it here;
+** our callers must do likewise.
+*/
+struct timeb {
+    time_t             time;           /* Seconds since the epoch      */
+    unsigned short     millitm;        /* Field not used               */
+    short              timezone;       /* Minutes west of GMT          */
+    short              dstflag;        /* Field not used               */
+};
+#endif /* defined(HAVE_SYS_TIMEB_H) */
+
+#endif /* defined(vms) */
+
+#if defined (STDC_HEADERS) || defined (USG)
+#include <string.h>
 #endif
 
-extern struct tm *localtime();
+/* Some old versions of bison generate parsers that use bcopy.
+   That loses on systems that don't provide the function, so we have
+   to redefine it here.  */
+#if !defined (HAVE_BCOPY) && defined (HAVE_MEMCPY) && !defined (bcopy)
+#define bcopy(from, to, len) memcpy ((to), (from), (len))
+#endif
+
+extern struct tm       *gmtime();
+extern struct tm       *localtime();
 
 #define yyparse getdate_yyparse
 #define yylex getdate_yylex
 #define yyerror getdate_yyerror
 
+static int yylex ();
+static int yyerror ();
+
 #if    !defined(lint) && !defined(SABER)
-static char RCS[] = "@(#)getdate.y 1.8 92/03/03";
+static char RCS[] =
+       "$Header$";
 #endif /* !defined(lint) && !defined(SABER) */
 
 
@@ -202,6 +295,18 @@ date       : tUNUMBER '/' tUNUMBER {
            yyDay = $3;
            yyYear = $5;
        }
+       | tUNUMBER tSNUMBER tSNUMBER {
+           /* ISO 8601 format.  yyyy-mm-dd.  */
+           yyYear = $1;
+           yyMonth = -$2;
+           yyDay = -$3;
+       }
+       | tUNUMBER tMONTH tSNUMBER {
+           /* e.g. 17-JUN-1992.  */
+           yyDay = $1;
+           yyMonth = $2;
+           yyYear = -$3;
+       }
        | tMONTH tUNUMBER {
            yyMonth = $1;
            yyDay = $2;
@@ -263,25 +368,24 @@ number    : tUNUMBER {
                yyYear = $1;
            else {
                if($1>10000) {
-                   time_t date_part;
-
-                   date_part= $1/10000;
                    yyHaveDate++;
-                   yyDay= (date_part)%100;
-                   yyMonth= (date_part/100)%100;
-                   yyYear = date_part/10000;
-               } 
-               yyHaveTime++;
-               if ($1 < 100) {
-                   yyHour = $1;
-                   yyMinutes = 0;
+                   yyDay= ($1)%100;
+                   yyMonth= ($1/100)%100;
+                   yyYear = $1/10000;
                }
                else {
-                   yyHour = $1 / 100;
-                   yyMinutes = $1 % 100;
-               }
-               yySeconds = 0;
-               yyMeridian = MER24;
+                   yyHaveTime++;
+                   if ($1 < 100) {
+                       yyHour = $1;
+                       yyMinutes = 0;
+                   }
+                   else {
+                       yyHour = $1 / 100;
+                       yyMinutes = $1 % 100;
+                   }
+                   yySeconds = 0;
+                   yyMeridian = MER24;
+               }
            }
        }
        ;
@@ -297,7 +401,7 @@ o_merid     : /* NULL */ {
 %%
 
 /* Month and day table. */
-static TABLE   MonthDayTable[] = {
+static TABLE const MonthDayTable[] = {
     { "january",       tMONTH,  1 },
     { "february",      tMONTH,  2 },
     { "march",         tMONTH,  3 },
@@ -326,7 +430,7 @@ static TABLE        MonthDayTable[] = {
 };
 
 /* Time units table. */
-static TABLE   UnitsTable[] = {
+static TABLE const UnitsTable[] = {
     { "year",          tMONTH_UNIT,    12 },
     { "month",         tMONTH_UNIT,    1 },
     { "fortnight",     tMINUTE_UNIT,   14 * 24 * 60 },
@@ -341,7 +445,7 @@ static TABLE        UnitsTable[] = {
 };
 
 /* Assorted relative-time words. */
-static TABLE   OtherTable[] = {
+static TABLE const OtherTable[] = {
     { "tomorrow",      tMINUTE_UNIT,   1 * 24 * 60 },
     { "yesterday",     tMINUTE_UNIT,   -1 * 24 * 60 },
     { "today",         tMINUTE_UNIT,   0 },
@@ -367,7 +471,7 @@ static TABLE        OtherTable[] = {
 
 /* The timezone table. */
 /* Some of these are commented out because a time_t can't store a float. */
-static TABLE   TimezoneTable[] = {
+static TABLE const TimezoneTable[] = {
     { "gmt",   tZONE,     HOUR( 0) },  /* Greenwich Mean */
     { "ut",    tZONE,     HOUR( 0) },  /* Universal (Coordinated) */
     { "utc",   tZONE,     HOUR( 0) },
@@ -451,7 +555,7 @@ static TABLE        TimezoneTable[] = {
 };
 
 /* Military timezone table. */
-static TABLE   MilitaryTable[] = {
+static TABLE const MilitaryTable[] = {
     { "a",     tZONE,  HOUR(  1) },
     { "b",     tZONE,  HOUR(  2) },
     { "c",     tZONE,  HOUR(  3) },
@@ -484,7 +588,7 @@ static TABLE        MilitaryTable[] = {
 
 
 /* ARGSUSED */
-int
+static int
 yyerror(s)
     char       *s;
 {
@@ -514,6 +618,8 @@ ToSeconds(Hours, Minutes, Seconds, Meridian)
        if (Hours < 1 || Hours > 12)
            return -1;
        return ((Hours + 12) * 60L + Minutes) * 60L + Seconds;
+    default:
+       abort ();
     }
     /* NOTREACHED */
 }
@@ -530,7 +636,7 @@ Convert(Month, Day, Year, Hours, Minutes, Seconds, Meridian, DSTmode)
     MERIDIAN   Meridian;
     DSTMODE    DSTmode;
 {
-    static int DaysInMonth[12] = {
+    static int DaysInMonth[12] = {
        31, 0, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31
     };
     time_t     tod;
@@ -624,7 +730,7 @@ LookupWord(buff)
 {
     register char      *p;
     register char      *q;
-    register TABLE     *tp;
+    register const TABLE       *tp;
     int                        i;
     int                        abbrev;
 
@@ -725,7 +831,7 @@ LookupWord(buff)
 }
 
 
-int
+static int
 yylex()
 {
     register char      c;
@@ -778,47 +884,58 @@ yylex()
 }
 
 
+#define TM_YEAR_ORIGIN 1900
+
+/* Yield A - B, measured in seconds.  */
+static time_t
+difftm(a, b)
+     struct tm *a, *b;
+{
+  int ay = a->tm_year + (TM_YEAR_ORIGIN - 1);
+  int by = b->tm_year + (TM_YEAR_ORIGIN - 1);
+  return
+    (
+     (
+      (
+       /* difference in day of year */
+       a->tm_yday - b->tm_yday
+       /* + intervening leap days */
+       +  ((ay >> 2) - (by >> 2))
+       -  (ay/100 - by/100)
+       +  ((ay/100 >> 2) - (by/100 >> 2))
+       /* + difference in years * 365 */
+       +  (time_t)(ay-by) * 365
+       )*24 + (a->tm_hour - b->tm_hour)
+      )*60 + (a->tm_min - b->tm_min)
+     )*60 + (a->tm_sec - b->tm_sec);
+}
+
 time_t
 get_date(p, now)
     char               *p;
     struct timeb       *now;
 {
-    struct tm          *tm;
+    struct tm          *tm, gmt;
     struct timeb       ftz;
     time_t             Start;
     time_t             tod;
 
     yyInput = p;
     if (now == NULL) {
-       now = &ftz;
-#if    defined(FTIME_MISSING)
+        now = &ftz;
        (void)time(&ftz.time);
-       /* Set the timezone global. */
-       tzset();
-#if    defined(HAVE_TIMEZONE)
-       tm = localtime(&ftz.time);
-       ftz.timezone = tm->tm_gmtoff / 60;
-#else
-#if    defined(timezone)
-       ftz.tzone = (int) timezone / 60;
-#else
-       ftz.timezone = (int) timezone / 60;
-#endif /* defined(timezone) */
-#endif /* defined(HAVE_TIMEZONE) */
-#else
-       (void)ftime(&ftz);
-#endif /* defined(FTIME_MISSING) */
+
+       if (! (tm = gmtime (&ftz.time)))
+           return -1;
+       gmt = *tm;      /* Make a copy, in case localtime modifies *tm.  */
+       ftz.timezone = difftm (&gmt, localtime (&ftz.time)) / 60;
     }
 
     tm = localtime(&now->time);
     yyYear = tm->tm_year;
     yyMonth = tm->tm_mon + 1;
     yyDay = tm->tm_mday;
-#if    defined(timezone)
-    yyTimezone = now->tzone;
-#else
     yyTimezone = now->timezone;
-#endif /* defined(timezone) */
     yyDSTmode = DSTmaybe;
     yyHour = 0;
     yyMinutes = 0;