#8: Done
I'm now of the opinion that this is done at the wrong level in the stack and needs to be redone later; but it works for now. There's a regression in `open`, but I can't see why.
This commit is contained in:
parent
0687b0baeb
commit
f36436a9e1
12 changed files with 134 additions and 41 deletions
|
|
@ -15,6 +15,7 @@
|
|||
#include <pwd.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#include <time.h>
|
||||
#include <sys/stat.h>
|
||||
#include <sys/types.h>
|
||||
#include <unistd.h>
|
||||
|
|
@ -277,9 +278,11 @@ struct cons_pointer add_meta_time( struct cons_pointer meta, wchar_t *key,
|
|||
/* I don't yet have a concept of a date-time object, which is a
|
||||
* bit of an oversight! */
|
||||
char datestring[256];
|
||||
struct tm *tm = localtime( value );
|
||||
|
||||
strftime( datestring, sizeof( datestring ), nl_langinfo( D_T_FMT ), tm );
|
||||
strftime( datestring,
|
||||
sizeof( datestring ),
|
||||
nl_langinfo( D_T_FMT ),
|
||||
localtime( value ) );
|
||||
|
||||
return add_meta_string( meta, key, datestring );
|
||||
}
|
||||
|
|
|
|||
|
|
@ -104,18 +104,18 @@ void print_list( URL_FILE * output, struct cons_pointer pointer ) {
|
|||
}
|
||||
|
||||
|
||||
void print_map( URL_FILE * output, struct cons_pointer pointer) {
|
||||
if ( vectorpointp( pointer)) {
|
||||
struct vector_space_object *vso = pointer_to_vso( pointer);
|
||||
void print_map( URL_FILE * output, struct cons_pointer map) {
|
||||
if ( vectorpointp( map)) {
|
||||
struct vector_space_object *vso = pointer_to_vso( map);
|
||||
|
||||
if ( mapp( vso ) ) {
|
||||
url_fputwc( btowc( '{' ), output );
|
||||
|
||||
for ( struct cons_pointer ks = keys(pointer);
|
||||
!nilp(ks); ks = c_cdr(ks)) {
|
||||
print( output, c_car(ks));
|
||||
for ( struct cons_pointer ks = keys( map);
|
||||
!nilp( ks); ks = c_cdr( ks)) {
|
||||
print( output, c_car( ks));
|
||||
url_fputwc( btowc( ' ' ), output );
|
||||
print( output, c_assoc( pointer, c_car(ks)));
|
||||
print( output, c_assoc( c_car( ks), map));
|
||||
|
||||
if ( !nilp( c_cdr( ks))) {
|
||||
url_fputws( L", ", output );
|
||||
|
|
@ -162,7 +162,9 @@ struct cons_pointer print( URL_FILE * output, struct cons_pointer pointer ) {
|
|||
dump_stack_trace( output, pointer );
|
||||
break;
|
||||
case FUNCTIONTV:
|
||||
url_fwprintf( output, L"<Function>" );
|
||||
url_fputws( L"<Function: ", output);
|
||||
print( output, cell.payload.function.meta);
|
||||
url_fputwc( L'>', output);
|
||||
break;
|
||||
case INTEGERTV:{
|
||||
struct cons_pointer s = integer_to_string( pointer, 10 );
|
||||
|
|
@ -214,7 +216,9 @@ struct cons_pointer print( URL_FILE * output, struct cons_pointer pointer ) {
|
|||
print( output, cell.payload.ratio.divisor );
|
||||
break;
|
||||
case READTV:
|
||||
url_fwprintf( output, L"<Input stream>" );
|
||||
url_fwprintf( output, L"<Input stream: " );
|
||||
print( output, cell.payload.stream.meta);
|
||||
url_fputwc( L'>', output);
|
||||
break;
|
||||
case REALTV:
|
||||
/* \todo using the C heap is a bad plan because it will fragment.
|
||||
|
|
@ -248,7 +252,9 @@ struct cons_pointer print( URL_FILE * output, struct cons_pointer pointer ) {
|
|||
print_string_contents( output, pointer );
|
||||
break;
|
||||
case SPECIALTV:
|
||||
url_fwprintf( output, L"<Special form>" );
|
||||
url_fwprintf( output, L"<Special form: " );
|
||||
print( output, cell.payload.special.meta);
|
||||
url_fputwc( L'>', output);
|
||||
break;
|
||||
case TIMETV:
|
||||
print_string(output, time_to_string( pointer));
|
||||
|
|
@ -260,7 +266,9 @@ struct cons_pointer print( URL_FILE * output, struct cons_pointer pointer ) {
|
|||
print_vso( output, pointer);
|
||||
break;
|
||||
case WRITETV:
|
||||
url_fwprintf( output, L"<Output stream>" );
|
||||
url_fwprintf( output, L"<Output stream: " );
|
||||
print( output, cell.payload.stream.meta);
|
||||
url_fputwc( L'>', output);
|
||||
break;
|
||||
default:
|
||||
fwprintf( stderr,
|
||||
|
|
|
|||
|
|
@ -24,6 +24,7 @@
|
|||
#include "intern.h"
|
||||
#include "io.h"
|
||||
#include "lispops.h"
|
||||
#include "map.h"
|
||||
#include "peano.h"
|
||||
#include "print.h"
|
||||
#include "ratio.h"
|
||||
|
|
@ -44,6 +45,9 @@ struct cons_pointer read_number( struct stack_frame *frame,
|
|||
struct cons_pointer read_list( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
URL_FILE * input, wint_t initial );
|
||||
struct cons_pointer read_map( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
URL_FILE * input, wint_t initial );
|
||||
struct cons_pointer read_string( URL_FILE * input, wint_t initial );
|
||||
struct cons_pointer read_symbol_or_key( URL_FILE * input, char *tag,
|
||||
wint_t initial );
|
||||
|
|
@ -100,6 +104,10 @@ struct cons_pointer read_continuation( struct stack_frame *frame,
|
|||
read_list( frame, frame_pointer, input,
|
||||
url_fgetwc( input ) );
|
||||
break;
|
||||
case '{':
|
||||
result = read_map( frame, frame_pointer, input,
|
||||
url_fgetwc( input ) );
|
||||
break;
|
||||
case '"':
|
||||
result = read_string( input, url_fgetwc( input ) );
|
||||
break;
|
||||
|
|
@ -126,9 +134,10 @@ struct cons_pointer read_continuation( struct stack_frame *frame,
|
|||
} else if ( iswblank( next ) ) {
|
||||
/* dotted pair. \todo this isn't right, we
|
||||
* really need to backtrack up a level. */
|
||||
result =
|
||||
read_continuation( frame, frame_pointer, input,
|
||||
result = read_continuation( frame, frame_pointer, input,
|
||||
url_fgetwc( input ) );
|
||||
debug_print( L"read_continuation: dotted pair; read cdr ",
|
||||
DEBUG_IO);
|
||||
} else {
|
||||
read_symbol_or_key( input, SYMBOLTAG, c );
|
||||
}
|
||||
|
|
@ -275,19 +284,38 @@ struct cons_pointer read_number( struct stack_frame *frame,
|
|||
* left parenthesis.
|
||||
*/
|
||||
struct cons_pointer read_list( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
URL_FILE * input, wint_t initial ) {
|
||||
struct cons_pointer frame_pointer,
|
||||
URL_FILE * input, wint_t initial ) {
|
||||
struct cons_pointer result = NIL;
|
||||
wint_t c;
|
||||
|
||||
if ( initial != ')' ) {
|
||||
debug_printf( DEBUG_IO,
|
||||
L"read_list starting '%C' (%d)\n", initial, initial );
|
||||
L"read_list starting '%C' (%d)\n", initial, initial );
|
||||
struct cons_pointer car =
|
||||
read_continuation( frame, frame_pointer, input,
|
||||
initial );
|
||||
result =
|
||||
make_cons( car,
|
||||
read_list( frame, frame_pointer, input,
|
||||
url_fgetwc( input ) ) );
|
||||
initial );
|
||||
|
||||
/* skip whitespace */
|
||||
for (c = url_fgetwc( input );
|
||||
iswblank( c ) || iswcntrl( c );
|
||||
c = url_fgetwc( input ));
|
||||
|
||||
if ( c == L'.') {
|
||||
/* might be a dotted pair; indeed, if we rule out numbers with
|
||||
* initial periods, it must be a dotted pair. \todo Ought to check,
|
||||
* howerver, that there's only one form after the period. */
|
||||
result =
|
||||
make_cons( car,
|
||||
c_car( read_list( frame,
|
||||
frame_pointer,
|
||||
input,
|
||||
url_fgetwc( input ) ) ) );
|
||||
} else {
|
||||
result =
|
||||
make_cons( car,
|
||||
read_list( frame, frame_pointer, input, c ) );
|
||||
}
|
||||
} else {
|
||||
debug_print( L"End of list detected\n", DEBUG_IO );
|
||||
}
|
||||
|
|
@ -295,6 +323,37 @@ struct cons_pointer read_list( struct stack_frame *frame,
|
|||
return result;
|
||||
}
|
||||
|
||||
|
||||
struct cons_pointer read_map( struct stack_frame *frame,
|
||||
struct cons_pointer frame_pointer,
|
||||
URL_FILE * input, wint_t initial ) {
|
||||
struct cons_pointer result = make_empty_map( NIL);
|
||||
wint_t c = initial;
|
||||
|
||||
while ( c != L'}' ) {
|
||||
struct cons_pointer key =
|
||||
read_continuation( frame, frame_pointer, input, c );
|
||||
|
||||
/* skip whitespace */
|
||||
for (c = url_fgetwc( input );
|
||||
iswblank( c ) || iswcntrl( c );
|
||||
c = url_fgetwc( input ));
|
||||
|
||||
struct cons_pointer value =
|
||||
read_continuation( frame, frame_pointer, input, c );
|
||||
|
||||
/* skip commaa and whitespace at this point. */
|
||||
for (c = url_fgetwc( input );
|
||||
c == L',' || iswblank( c ) || iswcntrl( c );
|
||||
c = url_fgetwc( input ));
|
||||
|
||||
result = merge_into_map( result, make_cons( make_cons( key, value), NIL));
|
||||
}
|
||||
|
||||
return result;
|
||||
}
|
||||
|
||||
|
||||
/**
|
||||
* Read a string. This means either a string delimited by double quotes
|
||||
* (is_quoted == true), in which case it may contain whitespace but may
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue