Redo time primitives to provide conversion between decoded and encoded
authorGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Tue, 12 Jan 1993 19:52:14 +0000 (19:52 +0000)
committerGuillermo J. Rozas <edu/mit/csail/zurich/gjr>
Tue, 12 Jan 1993 19:52:14 +0000 (19:52 +0000)
times.

v7/src/microcode/dosenv.c
v7/src/microcode/osenv.h
v7/src/microcode/prosenv.c
v7/src/microcode/uxenv.c
v7/src/microcode/version.h
v7/src/runtime/datime.scm
v8/src/microcode/version.h

index b26d926088ea6c99f72bde5a2eaa73892922ce26..bec22c8848ea7e0cdd1be3faef182a6358459ef5 100644 (file)
@@ -1,8 +1,8 @@
 /* -*-C-*-
 
-$Id: dosenv.c,v 1.2 1992/10/21 00:02:44 jinx Exp $
+$Id: dosenv.c,v 1.3 1993/01/12 19:48:36 gjr Exp $
 
-Copyright (c) 1992 Massachusetts Institute of Technology
+Copyright (c) 1992-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -36,12 +36,18 @@ MIT in each case. */
 #include "osenv.h"
 #include <stdlib.h>
 \f
-void
-DEFUN (OS_current_time, (buffer), struct time_structure * buffer)
+time_t
+DEFUN_VOID (OS_encoded_time)
 {
   time_t t;
-  struct tm * ts;
   STD_UINT_SYSTEM_CALL (syscall_time, t, (DOS_time (0)));
+  return (t);
+}
+
+void
+DEFUN (OS_decode_time, (t, buffer), time_t t AND struct time_structure * buffer)
+{
+  struct tm * ts;
   STD_PTR_SYSTEM_CALL (syscall_localtime, ts, (DOS_localtime (&t)));
   (buffer -> year) = ((ts -> tm_year) + 1900);
   (buffer -> month) = ((ts -> tm_mon) + 1);
@@ -56,6 +62,27 @@ DEFUN (OS_current_time, (buffer), struct time_structure * buffer)
   }
 }
 
+time_t
+DEFUN (OS_encode_time ,(buffer), struct time_structure * buffer)
+{
+  time_t t;
+  struct tm ts_s, * ts;
+  ts = &ts_s;
+  (ts -> tm_year) = ((buffer -> year) - 1900);
+  (ts -> tm_mon) = ((buffer -> month) - 1);
+  (ts -> tm_mday) = (buffer -> day);
+  (ts -> tm_hour) = (buffer -> hour);
+  (ts -> tm_min) = (buffer -> minute);
+  (ts -> tm_sec) = (buffer -> second);
+  {
+    /* In localtime() encoding, 0 is Sunday; in ours, it's Monday. */
+    int wday = (buffer -> day_of_week);
+    (ts -> tm_wday) = ((wday == 6) ? 0 : (wday + 1));
+  }
+  STD_UINT_SYSTEM_CALL (syscall_mktime, t, (DOS_mktime (ts)));
+  return (t);
+}
+
 clock_t
 DEFUN_VOID (OS_process_clock)
 {
@@ -64,15 +91,11 @@ DEFUN_VOID (OS_process_clock)
   return (clock()*((clock_t) (1000/CLOCKS_PER_SEC)));
 }
 
-\f
-
 clock_t
 DEFUN_VOID (OS_real_time_clock)
 {
   return (clock()*((clock_t) (1000/CLOCKS_PER_SEC)));
 }
-
-
 \f
 /* Timer adjustments */
 #define PC_TIMER_TICKS_PER_SECOND      (18.2)
index b202fc5477aa23858cb66d2d2b87ae7e367b37d5..dd6edc2c2ed58d8e0ece14227b6ebe9602cd3176 100644 (file)
@@ -1,8 +1,8 @@
 /* -*-C-*-
 
-$Id: osenv.h,v 1.2 1992/10/20 23:57:09 jinx Exp $
+$Id: osenv.h,v 1.3 1993/01/12 19:48:12 gjr Exp $
 
-Copyright (c) 1990-1992 Massachusetts Institute of Technology
+Copyright (c) 1990-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -48,7 +48,9 @@ struct time_structure
   unsigned int day_of_week;
 };
 
-extern void EXFUN (OS_current_time, (struct time_structure * ts));
+extern time_t EXFUN (OS_encoded_time, ());
+extern void EXFUN (OS_decode_time, (time_t, struct time_structure * ts));
+extern time_t EXFUN (OS_encode_time, (struct time_structure * ts));
 extern clock_t EXFUN (OS_process_clock, (void));
 extern clock_t EXFUN (OS_real_time_clock, (void));
 extern void EXFUN (OS_process_timer_set, (clock_t first, clock_t interval));
index f7610f5a435718766bee4f6bd2942b22ebde0c81..33098fe41b067ce17341c75c257618c8e8f5115a 100644 (file)
@@ -1,8 +1,8 @@
 /* -*-C-*-
 
-$Id: prosenv.c,v 1.7 1992/10/20 23:59:33 jinx Exp $
+$Id: prosenv.c,v 1.8 1993/01/12 19:48:19 gjr Exp $
 
-Copyright (c) 1987-1992 Massachusetts Institute of Technology
+Copyright (c) 1987-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -39,15 +39,22 @@ MIT in each case. */
 #include "osenv.h"
 #include "ostop.h"
 \f
+/* This primitive is obsolete.
+   Left here for a while for compatibility purposes (booting old bands).
+ */
+
 DEFINE_PRIMITIVE ("GET-DECODED-TIME", Prim_get_decoded_time, 1, 1,
   "Return a vector with the current decoded time;\n\
 arg TAG is used to tag the vector.\n\
 The vector's elements are:\n\
   #(TAG second minute hour day month year day-of-week)")
 {
+  time_t t;
   struct time_structure ts;
   PRIMITIVE_HEADER (1);
-  OS_current_time (&ts);
+
+  t = (OS_encoded_time ());
+  OS_decode_time (t, &ts);
   {
     SCHEME_OBJECT result = (allocate_marked_vector (TC_VECTOR, 8, 1));
     FAST_VECTOR_SET (result, 0, (ARG_REF (1)));
@@ -61,43 +68,56 @@ The vector's elements are:\n\
     PRIMITIVE_RETURN (result);
   }
 }
+\f
+DEFINE_PRIMITIVE ("ENCODED-TIME", Prim_encoded_time, 0, 0,
+  "Return the current time as an integer.")
+{
+  PRIMITIVE_RETURN (long_to_integer ((long) (OS_encoded_time ())));
+}
 
-DEFINE_PRIMITIVE ("CURRENT-YEAR", Prim_current_year, 0, 0,
-  "This is an obsolete primitive; use `get-decoded-time' instead.")
+DEFINE_PRIMITIVE ("DECODE-TIME", Prim_decode_time, 2, 2,
+  "Fill a vector with the second argument decoded.\n\
+The vector's elements are:\n\
+  #(TAG second minute hour day month year day-of-week)")
 {
+  SCHEME_OBJECT vec;
   struct time_structure ts;
-  PRIMITIVE_HEADER (0);
-  OS_current_time (&ts);
-  PRIMITIVE_RETURN (long_to_integer ((ts . year) - 1900));
-}
+  PRIMITIVE_HEADER (1);
 
-#define DATE_PRIMITIVE(element)                                                \
-{                                                                      \
-  struct time_structure ts;                                            \
-  PRIMITIVE_HEADER (0);                                                        \
-  OS_current_time (&ts);                                               \
-  PRIMITIVE_RETURN (long_to_integer (ts . element));                   \
+  vec = (VECTOR_ARG (1));
+  if ((VECTOR_LENGTH (vec)) != 8)
+    error_bad_range_arg (1);
+  OS_decode_time (((time_t) (arg_integer (2))), &ts);
+  FAST_VECTOR_SET (vec, 1, (long_to_integer (ts . second)));
+  FAST_VECTOR_SET (vec, 2, (long_to_integer (ts . minute)));
+  FAST_VECTOR_SET (vec, 3, (long_to_integer (ts . hour)));
+  FAST_VECTOR_SET (vec, 4, (long_to_integer (ts . day)));
+  FAST_VECTOR_SET (vec, 5, (long_to_integer (ts . month)));
+  FAST_VECTOR_SET (vec, 6, (long_to_integer (ts . year)));
+  FAST_VECTOR_SET (vec, 7, (long_to_integer (ts . day_of_week)));
+  PRIMITIVE_RETURN (UNSPECIFIC);
 }
 
-DEFINE_PRIMITIVE ("CURRENT-MONTH", Prim_current_month, 0, 0,
-  "This is an obsolete primitive; use `get-decoded-time' instead.")
-     DATE_PRIMITIVE (month)
-
-DEFINE_PRIMITIVE ("CURRENT-DAY", Prim_current_day, 0, 0,
-  "This is an obsolete primitive; use `get-decoded-time' instead.")
-     DATE_PRIMITIVE (day)
-
-DEFINE_PRIMITIVE ("CURRENT-HOUR", Prim_current_hour, 0, 0,
-  "This is an obsolete primitive; use `get-decoded-time' instead.")
-     DATE_PRIMITIVE (hour)
-
-DEFINE_PRIMITIVE ("CURRENT-MINUTE", Prim_current_minute, 0, 0,
-  "This is an obsolete primitive; use `get-decoded-time' instead.")
-     DATE_PRIMITIVE (minute)
+DEFINE_PRIMITIVE ("ENCODE-TIME", Prim_encode_time, 1, 1,
+  "Return the file time corresponding to the time structure given.")
+{
+  SCHEME_OBJECT vec;
+  struct time_structure ts;
+  PRIMITIVE_HEADER (1);
 
-DEFINE_PRIMITIVE ("CURRENT-SECOND", Prim_current_second, 0, 0,
-  "This is an obsolete primitive; use `get-decoded-time' instead.")
-     DATE_PRIMITIVE (second)
+  vec = (VECTOR_ARG (1));
+  if ((VECTOR_LENGTH (vec)) != 8)
+    error_bad_range_arg (1);
+
+  ts.second = (integer_to_long (FAST_VECTOR_REF (vec, 1)));
+  ts.minute = (integer_to_long (FAST_VECTOR_REF (vec, 2)));
+  ts.hour = (integer_to_long (FAST_VECTOR_REF (vec, 3)));
+  ts.day = (integer_to_long (FAST_VECTOR_REF (vec, 4)));
+  ts.month = (integer_to_long (FAST_VECTOR_REF (vec, 5)));
+  ts.year = (integer_to_long (FAST_VECTOR_REF (vec, 6)));
+  ts.day_of_week = (integer_to_long (FAST_VECTOR_REF (vec, 7)));
+  PRIMITIVE_RETURN (long_to_integer ((long) (OS_encode_time (&ts))));
+}
 \f
 DEFINE_PRIMITIVE ("SYSTEM-CLOCK", Prim_system_clock, 0, 0,
   "Return the current process time in units of milliseconds.")
index 95e265923eeceb46af275e035570ceac7c348c01..0823a9464e8973f1a9fbb2afe310b48fab029784 100644 (file)
@@ -1,8 +1,8 @@
 /* -*-C-*-
 
-$Id: uxenv.c,v 1.8 1992/10/21 00:06:14 jinx Exp $
+$Id: uxenv.c,v 1.9 1993/01/12 19:48:31 gjr Exp $
 
-Copyright (c) 1990-1992 Massachusetts Institute of Technology
+Copyright (c) 1990-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -35,12 +35,18 @@ MIT in each case. */
 #include "ux.h"
 #include "osenv.h"
 \f
-void
-DEFUN (OS_current_time, (buffer), struct time_structure * buffer)
+time_t
+DEFUN_VOID (OS_encoded_time)
 {
   time_t t;
-  struct tm * ts;
   STD_UINT_SYSTEM_CALL (syscall_time, t, (UX_time (0)));
+  return (t);
+}
+
+void
+DEFUN (OS_decode_time, (t, buffer), time_t t AND struct time_structure * buffer)
+{
+  struct tm * ts;
   STD_PTR_SYSTEM_CALL (syscall_localtime, ts, (UX_localtime (&t)));
   (buffer -> year) = ((ts -> tm_year) + 1900);
   (buffer -> month) = ((ts -> tm_mon) + 1);
@@ -55,6 +61,33 @@ DEFUN (OS_current_time, (buffer), struct time_structure * buffer)
   }
 }
 
+time_t
+DEFUN (OS_encode_time ,(buffer), struct time_structure * buffer)
+{
+  time_t t;
+  struct tm ts_s, * ts;
+  ts = &ts_s;
+  (ts -> tm_year) = ((buffer -> year) - 1900);
+  (ts -> tm_mon) = ((buffer -> month) - 1);
+  (ts -> tm_mday) = (buffer -> day);
+  (ts -> tm_hour) = (buffer -> hour);
+  (ts -> tm_min) = (buffer -> minute);
+  (ts -> tm_sec) = (buffer -> second);
+#if 0
+  {
+    /* In localtime() encoding, 0 is Sunday; in ours, it's Monday. */
+    int wday = (buffer -> day_of_week);
+    (ts -> tm_wday) = ((wday == 6) ? 0 : (wday + 1));
+  }
+#else
+  (ts -> tm_wday) = 0;
+#endif
+  (ts -> tm_yday) = 0;
+  (ts -> tm_isdst) = -1;       /* Let mktime figure it out */
+  STD_UINT_SYSTEM_CALL (syscall_mktime, t, (UX_mktime (ts)));
+  return (t);
+}
+\f
 #ifdef HAVE_TIMES
 
 static clock_t initial_process_clock;
index 63338618fc91332b8be3b956b1a7fe6fcbd7c8cb..ee6b9cd5a7ef97cde8a253e369b02abe0e5d36d1 100644 (file)
@@ -1,8 +1,8 @@
 /* -*-C-*-
 
-$Id: version.h,v 11.126 1993/01/12 10:43:22 cph Exp $
+$Id: version.h,v 11.127 1993/01/12 19:49:50 gjr Exp $
 
-Copyright (c) 1988-1992 Massachusetts Institute of Technology
+Copyright (c) 1988-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -46,5 +46,5 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     126
+#define SUBVERSION     127
 #endif
index 80f4189749419971dbc2c8b3486711517a293cf3..1f7e129d8a3fde73e1889ee0b72aecc580d173ba 100644 (file)
@@ -1,8 +1,8 @@
 #| -*-Scheme-*-
 
-$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/datime.scm,v 14.3 1990/06/21 23:19:39 cph Rel $
+$Header: /Users/cph/tmp/foo/mit-scheme/mit-scheme/v7/src/runtime/datime.scm,v 14.4 1993/01/12 19:52:14 gjr Exp $
 
-Copyright (c) 1988, 1990 Massachusetts Institute of Technology
+Copyright (c) 1988-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -48,7 +48,7 @@ MIT in each case. |#
                   (type vector)
                   (named decoded-time-structure-tag)
                   (conc-name decoded-time/)
-                  (constructor false))
+                  (constructor make-decoded-time ()))
   (second false read-only true)
   (minute false read-only true)
   (hour false read-only true)
@@ -57,8 +57,19 @@ MIT in each case. |#
   (year false read-only true)
   (day-of-week false read-only true))
 
+(define (decode-time time)
+  (let ((result (make-decoded-time)))
+    ((ucode-primitive decode-time 2) result time)
+    result))
+
+(define (encode-time dt)
+  ((ucode-primitive encode-time 1) dt))
+
+(define (get-time)
+  ((ucode-primitive encoded-time 0)))
+
 (define (get-decoded-time)
-  ((ucode-primitive get-decoded-time 1) decoded-time-structure-tag))
+  (decode-time (get-time)))
 
 (define (decoded-time/date-string time)
   (string-append
index 63338618fc91332b8be3b956b1a7fe6fcbd7c8cb..ee6b9cd5a7ef97cde8a253e369b02abe0e5d36d1 100644 (file)
@@ -1,8 +1,8 @@
 /* -*-C-*-
 
-$Id: version.h,v 11.126 1993/01/12 10:43:22 cph Exp $
+$Id: version.h,v 11.127 1993/01/12 19:49:50 gjr Exp $
 
-Copyright (c) 1988-1992 Massachusetts Institute of Technology
+Copyright (c) 1988-1993 Massachusetts Institute of Technology
 
 This material was developed by the Scheme project at the Massachusetts
 Institute of Technology, Department of Electrical Engineering and
@@ -46,5 +46,5 @@ MIT in each case. */
 #define VERSION                11
 #endif
 #ifndef SUBVERSION
-#define SUBVERSION     126
+#define SUBVERSION     127
 #endif