From: Chris Hanson Date: Wed, 7 Apr 1999 04:01:55 +0000 (+0000) Subject: Implement primitive to decode unix time to UTC. X-Git-Tag: 20090517-FFI~4570 X-Git-Url: https://birchwood-abbey.net/git?a=commitdiff_plain;h=4b2d0823d389b3c40866ddeec29535c163d08d4e;p=mit-scheme.git Implement primitive to decode unix time to UTC. --- diff --git a/v7/src/microcode/ntapi.h b/v7/src/microcode/ntapi.h index 74219c42b..240a3d198 100644 --- a/v7/src/microcode/ntapi.h +++ b/v7/src/microcode/ntapi.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntapi.h,v 1.10 1999/03/09 05:39:03 cph Exp $ +$Id: ntapi.h,v 1.11 1999/04/07 04:01:43 cph Exp $ Copyright (c) 1997, 1999 Massachusetts Institute of Technology @@ -90,6 +90,7 @@ enum syscall_names syscall_close, syscall_fstat, syscall_getcwd, + syscall_gmtime, syscall_localtime, syscall_lseek, syscall_malloc, @@ -947,6 +948,7 @@ static char * syscall_names_table [] = "CLOSE", "FSTAT", "GETCWD", + "GMTIME", "LOCALTIME", "LSEEK", "MALLOC", diff --git a/v7/src/microcode/ntenv.c b/v7/src/microcode/ntenv.c index ee80c80c2..b1e3968be 100644 --- a/v7/src/microcode/ntenv.c +++ b/v7/src/microcode/ntenv.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ntenv.c,v 1.17 1999/01/02 06:11:34 cph Exp $ +$Id: ntenv.c,v 1.18 1999/04/07 04:01:44 cph Exp $ Copyright (c) 1992-1999 Massachusetts Institute of Technology @@ -75,6 +75,26 @@ OS_decode_time (time_t t, struct time_structure * buffer) } } +void +OS_decode_utc (time_t t, struct time_structure * buffer) +{ + struct tm * ts; + STD_PTR_UNIX_CALL (ts, gmtime, (&t)); + (buffer -> year) = ((ts -> tm_year) + 1900); + (buffer -> month) = ((ts -> tm_mon) + 1); + (buffer -> day) = (ts -> tm_mday); + (buffer -> hour) = (ts -> tm_hour); + (buffer -> minute) = (ts -> tm_min); + (buffer -> second) = (ts -> tm_sec); + (buffer -> daylight_savings_time) = (ts -> tm_isdst); + (buffer -> time_zone) = 0; + { + /* In gmtime() encoding, 0 is Sunday; in ours, it's Monday. */ + int wday = (ts -> tm_wday); + (buffer -> day_of_week) = ((wday == 0) ? 6 : (wday - 1)); + } +} + #if 0 /* This nice implementation can't be used because it only works under Windows NT. */ diff --git a/v7/src/microcode/os2api.h b/v7/src/microcode/os2api.h index d7b8fbd15..5166246a3 100644 --- a/v7/src/microcode/os2api.h +++ b/v7/src/microcode/os2api.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2api.h,v 1.11 1999/01/02 06:11:34 cph Exp $ +$Id: os2api.h,v 1.12 1999/04/07 04:01:45 cph Exp $ Copyright (c) 1994-1999 Massachusetts Institute of Technology @@ -92,6 +92,7 @@ enum syscall_names syscall_dos_write, syscall_dos_write_queue, syscall_beginthread, + syscall_gmtime, syscall_kbd_char_in, syscall_localtime, syscall_malloc, @@ -948,6 +949,7 @@ static char * syscall_names_table [] = "dos-write", "dos-write-queue", "beginthread", + "gmtime", "kbd-char-in", "localtime", "malloc", diff --git a/v7/src/microcode/os2env.c b/v7/src/microcode/os2env.c index e0d7bbb9d..631cae7fc 100644 --- a/v7/src/microcode/os2env.c +++ b/v7/src/microcode/os2env.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: os2env.c,v 1.11 1999/01/02 06:11:34 cph Exp $ +$Id: os2env.c,v 1.12 1999/04/07 04:01:45 cph Exp $ Copyright (c) 1994-1999 Massachusetts Institute of Technology @@ -92,6 +92,27 @@ OS_decode_time (time_t t, struct time_structure * buffer) } } +void +OS_decode_utc (time_t t, struct time_structure * buffer) +{ + struct tm * ts = (gmtime (&t)); + if (ts == 0) + OS2_error_system_call (errno, syscall_gmtime); + (buffer -> year) = ((ts -> tm_year) + 1900); + (buffer -> month) = ((ts -> tm_mon) + 1); + (buffer -> day) = (ts -> tm_mday); + (buffer -> hour) = (ts -> tm_hour); + (buffer -> minute) = (ts -> tm_min); + (buffer -> second) = (ts -> tm_sec); + (buffer -> daylight_savings_time) = (ts -> tm_isdst); + (buffer -> time_zone) = 0; + { + /* In gmtime() encoding, 0 is Sunday; in ours, it's Monday. */ + int wday = (ts -> tm_wday); + (buffer -> day_of_week) = ((wday == 0) ? 6 : (wday - 1)); + } +} + time_t OS_encode_time (struct time_structure * buffer) { diff --git a/v7/src/microcode/prosenv.c b/v7/src/microcode/prosenv.c index 20f0f498f..0ac6cce4f 100644 --- a/v7/src/microcode/prosenv.c +++ b/v7/src/microcode/prosenv.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: prosenv.c,v 1.15 1999/01/02 06:11:34 cph Exp $ +$Id: prosenv.c,v 1.16 1999/04/07 04:01:46 cph Exp $ Copyright (c) 1987-1999 Massachusetts Institute of Technology @@ -33,38 +33,45 @@ DEFINE_PRIMITIVE ("ENCODED-TIME", Prim_encoded_time, 0, 0, PRIMITIVE_RETURN (ulong_to_integer ((unsigned long) (OS_encoded_time ()))); } +#define DECODE_TIME_BODY(proc) \ +{ \ + PRIMITIVE_HEADER (2); \ + { \ + SCHEME_OBJECT vec = (VECTOR_ARG (1)); \ + unsigned int len = (VECTOR_LENGTH (vec)); \ + struct time_structure ts; \ + if (! (len >= 10)) \ + error_bad_range_arg (1); \ + proc (((time_t) (arg_ulong_integer (2))), &ts); \ + FAST_VECTOR_SET (vec, 1, (ulong_to_integer (ts . second))); \ + FAST_VECTOR_SET (vec, 2, (ulong_to_integer (ts . minute))); \ + FAST_VECTOR_SET (vec, 3, (ulong_to_integer (ts . hour))); \ + FAST_VECTOR_SET (vec, 4, (ulong_to_integer (ts . day))); \ + FAST_VECTOR_SET (vec, 5, (ulong_to_integer (ts . month))); \ + FAST_VECTOR_SET (vec, 6, (ulong_to_integer (ts . year))); \ + FAST_VECTOR_SET (vec, 7, (ulong_to_integer (ts . day_of_week))); \ + FAST_VECTOR_SET \ + (vec, 8, (ulong_to_integer (ts . daylight_savings_time))); \ + FAST_VECTOR_SET \ + (vec, 9, \ + (((ts . time_zone) == INT_MAX) \ + ? SHARP_F \ + : (ulong_to_integer (ts . time_zone)))); \ + } \ + PRIMITIVE_RETURN (UNSPECIFIC); \ +} + 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 dst zone)") -{ - SCHEME_OBJECT vec; - unsigned int len; - struct time_structure ts; - PRIMITIVE_HEADER (1); +DECODE_TIME_BODY (OS_decode_time) - vec = (VECTOR_ARG (1)); - len = (VECTOR_LENGTH (vec)); - if (! (len >= 8)) - error_bad_range_arg (1); - OS_decode_time (((time_t) (arg_ulong_integer (2))), &ts); - FAST_VECTOR_SET (vec, 1, (ulong_to_integer (ts . second))); - FAST_VECTOR_SET (vec, 2, (ulong_to_integer (ts . minute))); - FAST_VECTOR_SET (vec, 3, (ulong_to_integer (ts . hour))); - FAST_VECTOR_SET (vec, 4, (ulong_to_integer (ts . day))); - FAST_VECTOR_SET (vec, 5, (ulong_to_integer (ts . month))); - FAST_VECTOR_SET (vec, 6, (ulong_to_integer (ts . year))); - FAST_VECTOR_SET (vec, 7, (ulong_to_integer (ts . day_of_week))); - if (len > 8) - FAST_VECTOR_SET (vec, 8, (ulong_to_integer (ts . daylight_savings_time))); - if (len > 9) - FAST_VECTOR_SET - (vec, 9, - (((ts . time_zone) == INT_MAX) - ? SHARP_F - : (ulong_to_integer (ts . time_zone)))); - PRIMITIVE_RETURN (UNSPECIFIC); -} +DEFINE_PRIMITIVE ("DECODE-UTC", Prim_decode_utc, 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 dst zone)") +DECODE_TIME_BODY (OS_decode_utc) DEFINE_PRIMITIVE ("ENCODE-TIME", Prim_encode_time, 1, 1, "Return the file time corresponding to the time structure given.") diff --git a/v7/src/microcode/syscall.h b/v7/src/microcode/syscall.h index 68b9d0a17..db2166fb3 100644 --- a/v7/src/microcode/syscall.h +++ b/v7/src/microcode/syscall.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: syscall.h,v 1.11 1999/01/02 06:11:34 cph Exp $ +$Id: syscall.h,v 1.12 1999/04/07 04:01:47 cph Exp $ Copyright (c) 1993-1999 Massachusetts Institute of Technology @@ -59,6 +59,7 @@ enum syscall_names syscall_getcwd, syscall_gethostname, syscall_gettimeofday, + syscall_gmtime, syscall_ioctl_TIOCGPGRP, syscall_ioctl_TIOCSIGSEND, syscall_kill, diff --git a/v7/src/microcode/ux.h b/v7/src/microcode/ux.h index d7b167bce..32f89abed 100644 --- a/v7/src/microcode/ux.h +++ b/v7/src/microcode/ux.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: ux.h,v 1.71 1999/01/02 06:11:34 cph Exp $ +$Id: ux.h,v 1.72 1999/04/07 04:01:47 cph Exp $ Copyright (c) 1988-1999 Massachusetts Institute of Technology @@ -734,6 +734,7 @@ extern char * EXFUN (getlogin, (void)); #define UX_getpwnam getpwnam #define UX_getpwuid getpwuid #define UX_getuid getuid +#define UX_gmtime gmtime #define UX_ioctl ioctl #define UX_link link #define UX_localtime localtime diff --git a/v7/src/microcode/uxenv.c b/v7/src/microcode/uxenv.c index b750ef4d5..d716c55a4 100644 --- a/v7/src/microcode/uxenv.c +++ b/v7/src/microcode/uxenv.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxenv.c,v 1.17 1999/01/02 06:11:34 cph Exp $ +$Id: uxenv.c,v 1.18 1999/04/07 04:01:48 cph Exp $ Copyright (c) 1990-1999 Massachusetts Institute of Technology @@ -55,6 +55,26 @@ DEFUN (OS_decode_time, (t, buffer), time_t t AND struct time_structure * buffer) } } +void +DEFUN (OS_decode_utc, (t, buffer), time_t t AND struct time_structure * buffer) +{ + struct tm * ts; + STD_PTR_SYSTEM_CALL (syscall_gmtime, ts, (UX_gmtime (&t))); + (buffer -> year) = ((ts -> tm_year) + 1900); + (buffer -> month) = ((ts -> tm_mon) + 1); + (buffer -> day) = (ts -> tm_mday); + (buffer -> hour) = (ts -> tm_hour); + (buffer -> minute) = (ts -> tm_min); + (buffer -> second) = (ts -> tm_sec); + (buffer -> daylight_savings_time) = (ts -> tm_isdst); + (buffer -> time_zone) = 0; + { + /* In gmtime() encoding, 0 is Sunday; in ours, it's Monday. */ + int wday = (ts -> tm_wday); + (buffer -> day_of_week) = ((wday == 0) ? 6 : (wday - 1)); + } +} + time_t DEFUN (OS_encode_time ,(buffer), struct time_structure * buffer) { diff --git a/v7/src/microcode/uxtop.c b/v7/src/microcode/uxtop.c index e94054087..40871b2d6 100644 --- a/v7/src/microcode/uxtop.c +++ b/v7/src/microcode/uxtop.c @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: uxtop.c,v 1.21 1999/01/02 06:11:34 cph Exp $ +$Id: uxtop.c,v 1.22 1999/04/07 04:01:49 cph Exp $ Copyright (c) 1990-1999 Massachusetts Institute of Technology @@ -316,6 +316,7 @@ static char * syscall_names_table [] = "GETCWD", "GETHOSTNAME", "GETTIMEOFDAY", + "GMTIME", "IOCTL-TIOCGPGRP", "IOCTL-TIOCSIGSEND", "KILL", diff --git a/v7/src/microcode/version.h b/v7/src/microcode/version.h index 6c791db6a..87e997444 100644 --- a/v7/src/microcode/version.h +++ b/v7/src/microcode/version.h @@ -1,6 +1,6 @@ /* -*-C-*- -$Id: version.h,v 11.162 1999/03/03 05:25:28 cph Exp $ +$Id: version.h,v 11.163 1999/04/07 04:01:55 cph Exp $ Copyright (c) 1988-1999 Massachusetts Institute of Technology @@ -33,5 +33,5 @@ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. #define VERSION 11 #endif #ifndef SUBVERSION -#define SUBVERSION 162 +#define SUBVERSION 163 #endif