From: Guillermo J. Rozas Date: Tue, 12 Jan 1993 19:52:14 +0000 (+0000) Subject: Redo time primitives to provide conversion between decoded and encoded X-Git-Tag: 20090517-FFI~8598 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=5e438c0af69f480ae38f47a29764aebf2a8c8ee1;p=mit-scheme.git Redo time primitives to provide conversion between decoded and encoded times. --- diff --git a/v7/src/microcode/dosenv.c b/v7/src/microcode/dosenv.c index b26d92608..bec22c884 100644 --- a/v7/src/microcode/dosenv.c +++ b/v7/src/microcode/dosenv.c @@ -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 -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))); } - - clock_t DEFUN_VOID (OS_real_time_clock) { return (clock()*((clock_t) (1000/CLOCKS_PER_SEC))); } - - /* Timer adjustments */ #define PC_TIMER_TICKS_PER_SECOND (18.2) diff --git a/v7/src/microcode/osenv.h b/v7/src/microcode/osenv.h index b202fc547..dd6edc2c2 100644 --- a/v7/src/microcode/osenv.h +++ b/v7/src/microcode/osenv.h @@ -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)); diff --git a/v7/src/microcode/prosenv.c b/v7/src/microcode/prosenv.c index f7610f5a4..33098fe41 100644 --- a/v7/src/microcode/prosenv.c +++ b/v7/src/microcode/prosenv.c @@ -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" +/* 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); } } + +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)))); +} DEFINE_PRIMITIVE ("SYSTEM-CLOCK", Prim_system_clock, 0, 0, "Return the current process time in units of milliseconds.") diff --git a/v7/src/microcode/uxenv.c b/v7/src/microcode/uxenv.c index 95e265923..0823a9464 100644 --- a/v7/src/microcode/uxenv.c +++ b/v7/src/microcode/uxenv.c @@ -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" -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); +} + #ifdef HAVE_TIMES static clock_t initial_process_clock; diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index 63338618f..ee6b9cd5a 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -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 diff --git a/v7/src/runtime/datime.scm b/v7/src/runtime/datime.scm index 80f418974..1f7e129d8 100644 --- a/v7/src/runtime/datime.scm +++ b/v7/src/runtime/datime.scm @@ -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 diff --git a/v8/src/microcode/version.h b/v8/src/microcode/version.h index 63338618f..ee6b9cd5a 100644 --- a/v8/src/microcode/version.h +++ b/v8/src/microcode/version.h @@ -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