It compiles. It runs. Nothing works, but it also doesn't crash. Victory!

This commit is contained in:
Simon Brooke 2026-04-23 11:50:30 +01:00
parent 8d2acbeb0f
commit aa0d60bbed
20 changed files with 390 additions and 244 deletions

View file

@ -8,7 +8,8 @@
*/
#include <stdint.h>
#include <stdlib.h>
#include <string.h>
/*
* wide characters
*/
@ -143,7 +144,7 @@ struct pso_pointer make_symbol( struct pso_pointer frame_pointer, wint_t c,
* Return a lisp string representation of this wide character string.
*/
struct pso_pointer c_string_to_lisp_string( struct pso_pointer frame_pointer,
char32_t *string ) {
wchar_t *string ) {
struct pso_pointer result = nil;
for ( int i = wcslen( string ) - 1; i >= 0; i-- ) {
@ -159,6 +160,53 @@ struct pso_pointer c_string_to_lisp_string( struct pso_pointer frame_pointer,
return result;
}
/**
* Convert this lisp string-like-thing (also works for symbols, and, later
* keywords) into a UTF-8 string. NOTE that the returned value has been
* malloced and must be freed. TODO: candidate to moving into a utilities
* file.
*
* @param s the lisp string or symbol;
* @return the c string.
*/
char *lisp_string_to_c_string( struct pso_pointer s ) {
char *result = NULL;
if ( stringp( s ) || symbolp( s ) ) {
int len = 1;
for ( struct pso_pointer c = s; !c_nilp( c ); c = c_cdr( c ) ) {
len++;
}
wchar_t *buffer = calloc( len, sizeof( char32_t ) );
int i = 0;
for ( struct pso_pointer c = s; !c_nilp( c ); c = c_cdr( c ) ) {
buffer[i++] =
( wchar_t ) ( pointer_to_object( c )->payload.string.
character );
}
mbstate_t ps;
const wchar_t *src = buffer;
memset( &ps, 0, sizeof( ps ) );
result =
calloc( wcsrtombs( NULL, &src, len, &ps ) + 1, sizeof( char ) );
src = buffer;
memset( &ps, 0, sizeof( ps ) );
wcsrtombs( result, &src, len, &ps );
free( buffer );
// mbstate_t ps = mbstate_t();
//
// result = calloc( wcsrtombs( NULL, &buffer, len, &ps) + 1 );
// wcsrtombs( result, &buffer, len, &ps);
// free( buffer );
}
debug_print( L"lisp_string_to_c_string( ", DEBUG_IO, 0 );
debug_print_object( s, DEBUG_IO, 0 );
debug_printf( DEBUG_IO, 0, L") => '%s'\n", result );
return result;
}
/**
* Return a lisp symbol representation of this wide character string. In