diff --git a/src/init.c b/src/init.c index 275cc40..538ede3 100644 --- a/src/init.c +++ b/src/init.c @@ -31,7 +31,7 @@ #include "peano.h" #include "print.h" #include "repl.h" -#include "time.h" +#include "psse_time.h" // extern char *optarg; /* defined in unistd.h */ diff --git a/src/io/io.c b/src/io/io.c index e9990e9..5065044 100644 --- a/src/io/io.c +++ b/src/io/io.c @@ -378,9 +378,8 @@ void collect_meta( struct cons_pointer stream, char *url ) { meta = add_meta_integer( meta, L"size", ( intmax_t ) statbuf.st_size ); -/* + meta = add_meta_time( meta, L"modified", &statbuf.st_mtime ); -*/ } break; case CFTYPE_CURL: diff --git a/src/io/print.c b/src/io/print.c index 343160e..dd92606 100644 --- a/src/io/print.c +++ b/src/io/print.c @@ -24,7 +24,7 @@ #include "map.h" #include "stack.h" #include "print.h" -#include "time.h" +#include "psse_time.h" #include "vectorspace.h" /** @@ -140,6 +140,27 @@ void print_vso( URL_FILE * output, struct cons_pointer pointer) { } } +/** + * stolen from https://stackoverflow.com/questions/11656241/how-to-print-uint128-t-number-using-gcc + */ +void print_128bit( URL_FILE * output, __int128_t n ) { + if ( n == 0 ) { + fwprintf( stderr, L"0" ); + } else { + char str[40] = { 0 }; // log10(1 << 128) + '\0' + char *s = str + sizeof( str ) - 1; // start at the end + while ( n != 0 ) { + if ( s == str ) + return; // never happens + + *--s = "0123456789"[n % 10]; // save last digit + n /= 10; // drop it + } + url_fwprintf( output, L"%s", s ); + } +} + + /** * Print the cons-space object indicated by `pointer` to the stream indicated * by `output`. @@ -257,7 +278,11 @@ struct cons_pointer print( URL_FILE * output, struct cons_pointer pointer ) { url_fputwc( L'>', output); break; case TIMETV: - print_string(output, time_to_string( pointer)); + url_fwprintf( output, L"', output); break; case TRUETV: url_fwprintf( output, L"t" ); diff --git a/src/time/time.c b/src/time/psse_time.c similarity index 88% rename from src/time/time.c rename to src/time/psse_time.c index 146f296..76f52a9 100644 --- a/src/time/time.c +++ b/src/time/psse_time.c @@ -1,5 +1,5 @@ /* - * time.h + * psse_time.c * * Bare bones of PSSE time. See issue #16. * @@ -8,6 +8,7 @@ */ #include +#include #include /* * wide characters @@ -18,7 +19,7 @@ #include "conspage.h" #include "consspaceobject.h" #include "integer.h" -#include "time.h" +#include "psse_time.h" #define _GNU_SOURCE #define seconds_per_year 31557600L @@ -90,9 +91,17 @@ struct cons_pointer lisp_time( struct stack_frame *frame, struct cons_pointer fr * This is temporary, for bootstrapping. */ struct cons_pointer time_to_string( struct cons_pointer pointer) { + struct cons_pointer result = NIL; long int t = lisp_time_to_unix_time(pointer); - return c_string_to_lisp_string( t == 0 ? - L"Not yet implemented: cannot print times outside UNIX time\n" : - ctime(&t)); + if ( t != 0) { + char * bytes = ctime(&t); + int l = strlen(bytes) + 1; + wchar_t buffer[ l]; + + mbstowcs( buffer, bytes, l); + result = c_string_to_lisp_string( buffer); + } + + return result; } diff --git a/src/time/time.h b/src/time/psse_time.h similarity index 96% rename from src/time/time.h rename to src/time/psse_time.h index 661decf..af70966 100644 --- a/src/time/time.h +++ b/src/time/psse_time.h @@ -1,5 +1,5 @@ /* - * time.h + * psse_time.h * * Bare bones of PSSE time. See issue #16. *