Tactical commit
This commit is contained in:
parent
8334e2bf1f
commit
b15c0e8f89
4 changed files with 167 additions and 124 deletions
103
src/io/fopen.c
103
src/io/fopen.c
|
|
@ -53,6 +53,8 @@
|
|||
/* we use a global one for convenience */
|
||||
static CURLM *multi_handle;
|
||||
|
||||
wint_t ungotten = 0;
|
||||
|
||||
/* curl calls this routine to get more data */
|
||||
static size_t write_callback( char *buffer,
|
||||
size_t size, size_t nitems, void *userp ) {
|
||||
|
|
@ -452,27 +454,69 @@ URL_FILE *file_to_url_file( FILE * f ) {
|
|||
wint_t url_fgetwc( URL_FILE * input ) {
|
||||
wint_t result = -1;
|
||||
|
||||
switch ( input->type ) {
|
||||
case CFTYPE_FILE:
|
||||
fwide( input->handle.file, 1 ); /* wide characters */
|
||||
result = fgetwc( input->handle.file ); /* passthrough */
|
||||
break;
|
||||
debug_printf( DEBUG_IO, L"url_fgetwc: ungotten = %d\n", ungotten );
|
||||
|
||||
case CFTYPE_CURL:{
|
||||
wchar_t *wbuff = calloc( 2, sizeof( wchar_t ) );
|
||||
if ( ungotten != 0 ) {
|
||||
/* TODO: not thread safe */
|
||||
result = ungotten;
|
||||
ungotten = 0;
|
||||
} else {
|
||||
switch ( input->type ) {
|
||||
case CFTYPE_FILE:
|
||||
fwide( input->handle.file, 1 ); /* wide characters */
|
||||
result = fgetwc( input->handle.file ); /* passthrough */
|
||||
break;
|
||||
|
||||
mbstowcs( wbuff, (char *)&input->buffer[input->buffer_pos], 1 );
|
||||
result = wbuff[0];
|
||||
use_one_wide( input );
|
||||
case CFTYPE_CURL:{
|
||||
debug_print( L"url_fgetwc: stream is URL\n", DEBUG_IO );
|
||||
|
||||
free( wbuff );
|
||||
}
|
||||
break;
|
||||
case CFTYPE_NONE:
|
||||
break;
|
||||
char *cbuff =
|
||||
calloc( sizeof( wchar_t ) + 1, sizeof( char ) );
|
||||
wchar_t *wbuff = calloc( 2, sizeof( wchar_t ) );
|
||||
|
||||
size_t count = 0;
|
||||
|
||||
debug_print( L"url_fgetwc: about to call url_fgets\n", DEBUG_IO );
|
||||
url_fgets( cbuff, 1, input );
|
||||
debug_print( L"url_fgetwc: back from url_fgets\n", DEBUG_IO );
|
||||
int c = ( int ) cbuff[0];
|
||||
debug_printf( DEBUG_IO, L"url_fgetwc: (first) character = %d (%c)\n", c, c & 0xf7 );
|
||||
/* The value of each individual byte indicates its UTF-8 function, as follows:
|
||||
*
|
||||
* 00 to 7F hex (0 to 127): first and only byte of a sequence.
|
||||
* 80 to BF hex (128 to 191): continuing byte in a multi-byte sequence.
|
||||
* C2 to DF hex (194 to 223): first byte of a two-byte sequence.
|
||||
* E0 to EF hex (224 to 239): first byte of a three-byte sequence.
|
||||
* F0 to FF hex (240 to 255): first byte of a four-byte sequence.
|
||||
*/
|
||||
if ( c <= 0x07 ) {
|
||||
count = 1;
|
||||
} else if ( c >= '0xc2' && c <= '0xdf' ) {
|
||||
count = 2;
|
||||
} else if ( c >= '0xe0' && c <= '0xef' ) {
|
||||
count = 3;
|
||||
} else if ( c >= '0xf0' && c <= '0xff' ) {
|
||||
count = 4;
|
||||
}
|
||||
|
||||
if ( count > 1 ) {
|
||||
url_fgets( cbuff, --count, input );
|
||||
}
|
||||
mbstowcs( wbuff, cbuff, 1 ); //(char *)(&input->buffer[input->buffer_pos]), 1 );
|
||||
result = wbuff[0];
|
||||
use_one_wide( input );
|
||||
|
||||
free( wbuff );
|
||||
free( cbuff );
|
||||
}
|
||||
break;
|
||||
case CFTYPE_NONE:
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
debug_printf( DEBUG_IO, L"url_fgetwc returning %d (%C)\n", result, result);
|
||||
debug_printf( DEBUG_IO, L"url_fgetwc returning %d (%C)\n", result,
|
||||
result );
|
||||
return result;
|
||||
}
|
||||
|
||||
|
|
@ -482,22 +526,23 @@ wint_t url_ungetwc( wint_t wc, URL_FILE * input ) {
|
|||
switch ( input->type ) {
|
||||
case CFTYPE_FILE:
|
||||
fwide( input->handle.file, 1 ); /* wide characters */
|
||||
result = ungetwc( wc, input->handle.file ); /* passthrough */
|
||||
result = ungetwc( wc, input->handle.file ); /* passthrough */
|
||||
break;
|
||||
|
||||
case CFTYPE_CURL:{
|
||||
wchar_t *wbuff = calloc( 2, sizeof( wchar_t ) );
|
||||
char *cbuff = calloc( 5, sizeof( char ) );
|
||||
|
||||
wbuff[0] = wc;
|
||||
result = wcstombs( cbuff, wbuff, 1 );
|
||||
|
||||
input->buffer_pos -= strlen( cbuff );
|
||||
|
||||
free( cbuff );
|
||||
free( wbuff );
|
||||
|
||||
result = result > 0 ? wc : result;
|
||||
ungotten = wc;
|
||||
// wchar_t *wbuff = calloc( 2, sizeof( wchar_t ) );
|
||||
// char *cbuff = calloc( 5, sizeof( char ) );
|
||||
//
|
||||
// wbuff[0] = wc;
|
||||
// result = wcstombs( cbuff, wbuff, 1 );
|
||||
//
|
||||
// input->buffer_pos -= strlen( cbuff );
|
||||
//
|
||||
// free( cbuff );
|
||||
// free( wbuff );
|
||||
//
|
||||
// result = result > 0 ? wc : result;
|
||||
break;
|
||||
case CFTYPE_NONE:
|
||||
break;
|
||||
|
|
|
|||
28
src/io/io.c
28
src/io/io.c
|
|
@ -31,7 +31,7 @@ char *lisp_string_to_c_string( struct cons_pointer s ) {
|
|||
int len = 0;
|
||||
|
||||
for ( struct cons_pointer c = s; !nilp( c );
|
||||
c = pointer2cell( c ).payload.string.cdr ) {
|
||||
c = pointer2cell( c ).payload.string.cdr ) {
|
||||
len++;
|
||||
}
|
||||
|
||||
|
|
@ -49,9 +49,9 @@ char *lisp_string_to_c_string( struct cons_pointer s ) {
|
|||
free( buffer );
|
||||
}
|
||||
|
||||
debug_print(L"lisp_string_to_c_string( ", DEBUG_IO);
|
||||
debug_print_object( s, DEBUG_IO);
|
||||
debug_printf( DEBUG_IO, L") => '%s'\n", result);
|
||||
debug_print( L"lisp_string_to_c_string( ", DEBUG_IO );
|
||||
debug_print_object( s, DEBUG_IO );
|
||||
debug_printf( DEBUG_IO, L") => '%s'\n", result );
|
||||
|
||||
return result;
|
||||
}
|
||||
|
|
@ -115,7 +115,7 @@ lisp_open( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
|||
|
||||
free( url );
|
||||
|
||||
if ( pointer2cell(result).payload.stream.stream == NULL) {
|
||||
if ( pointer2cell( result ).payload.stream.stream == NULL ) {
|
||||
result = NIL;
|
||||
}
|
||||
}
|
||||
|
|
@ -169,19 +169,19 @@ lisp_slurp( struct stack_frame *frame, struct cons_pointer frame_pointer,
|
|||
|
||||
if ( readp( frame->arg[0] ) ) {
|
||||
URL_FILE *stream = pointer2cell( frame->arg[0] ).payload.stream.stream;
|
||||
struct cons_pointer cursor = make_string( url_fgetwc( stream ), NIL);
|
||||
struct cons_pointer cursor = make_string( url_fgetwc( stream ), NIL );
|
||||
result = cursor;
|
||||
|
||||
for ( wint_t c = url_fgetwc( stream ); !url_feof(stream);
|
||||
for ( wint_t c = url_fgetwc( stream ); !url_feof( stream );
|
||||
c = url_fgetwc( stream ) ) {
|
||||
debug_print(L"slurp: cursor is: ", DEBUG_IO);
|
||||
debug_dump_object( cursor, DEBUG_IO);
|
||||
debug_print(L"; result is: ", DEBUG_IO);
|
||||
debug_dump_object( result, DEBUG_IO);
|
||||
debug_println( DEBUG_IO);
|
||||
debug_print( L"slurp: cursor is: ", DEBUG_IO );
|
||||
debug_dump_object( cursor, DEBUG_IO );
|
||||
debug_print( L"; result is: ", DEBUG_IO );
|
||||
debug_dump_object( result, DEBUG_IO );
|
||||
debug_println( DEBUG_IO );
|
||||
|
||||
struct cons_space_object * cell = &pointer2cell(cursor);
|
||||
cursor = make_string( ( wchar_t ) c , NIL);
|
||||
struct cons_space_object *cell = &pointer2cell( cursor );
|
||||
cursor = make_string( ( wchar_t ) c, NIL );
|
||||
cell->payload.string.cdr = cursor;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue