Further work on print; still not working properly.
This commit is contained in:
parent
9a0f186f29
commit
0e8712a076
1 changed files with 142 additions and 123 deletions
|
|
@ -11,8 +11,8 @@
|
|||
* Licensed under GPL version 2.0, or, at your option, any later version.
|
||||
*/
|
||||
|
||||
#include <stdbool.h>
|
||||
#include <ctype.h>
|
||||
#include <stdbool.h>
|
||||
#include <stdint.h>
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
|
|
@ -46,6 +46,24 @@
|
|||
struct pso_pointer in_write(struct pso_pointer p, URL_FILE *output,
|
||||
bool escape);
|
||||
|
||||
/**
|
||||
* @brief write this character `wc` to this `output` stream, escaping it if
|
||||
* 1. `escape` is true; and
|
||||
* 2. it is a character which the reader would otherwise not cope with.
|
||||
*
|
||||
* TODO: this does not yet even nearly cope with all the possible special
|
||||
* cases.
|
||||
*/
|
||||
void write_char( wchar_t wc, URL_FILE * output, bool escape) {
|
||||
if (escape && !iswprint(wc)) {
|
||||
url_fwprintf(output, L"\\%04x", wc);
|
||||
// url_fputwc(L'\\', output);
|
||||
} else {
|
||||
url_fputwc(wc, output);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
struct pso_pointer print_string_like_thing(struct pso_pointer p,
|
||||
URL_FILE *output, bool escape) {
|
||||
switch (get_tag_value(p)) {
|
||||
|
|
@ -53,7 +71,7 @@ struct pso_pointer print_string_like_thing( struct pso_pointer p,
|
|||
url_fputwc(L':', output);
|
||||
break;
|
||||
case STRINGTV:
|
||||
if ( !escape )
|
||||
if (escape)
|
||||
url_fputwc(L'"', output);
|
||||
break;
|
||||
}
|
||||
|
|
@ -61,18 +79,21 @@ struct pso_pointer print_string_like_thing( struct pso_pointer p,
|
|||
if (keywordp(p) || stringp(p) || symbolp(p)) {
|
||||
for (struct pso_pointer cursor = p; !nilp(cursor);
|
||||
cursor = pointer_to_object(cursor)->payload.string.cdr) {
|
||||
url_fputwc( pointer_to_object( cursor )->payload.character.
|
||||
character, output );
|
||||
wchar_t wc = pointer_to_object(cursor)->payload.string.character;
|
||||
|
||||
write_char( wc, output, escape);
|
||||
}
|
||||
}
|
||||
|
||||
if (stringp(p)) {
|
||||
if ( !escape )
|
||||
if (escape)
|
||||
url_fputwc(L'"', output);
|
||||
}
|
||||
|
||||
return p;
|
||||
}
|
||||
|
||||
struct pso_pointer print_list_content( struct pso_pointer p, URL_FILE *output,
|
||||
struct pso_pointer write_list_content(struct pso_pointer p, URL_FILE *output,
|
||||
bool escape) {
|
||||
struct pso_pointer result = nil;
|
||||
|
||||
|
|
@ -93,8 +114,7 @@ struct pso_pointer print_list_content( struct pso_pointer p, URL_FILE *output,
|
|||
break;
|
||||
default:
|
||||
url_fputws(L" . ", output);
|
||||
result =
|
||||
in_write( object->payload.cons.cdr, output, escape );
|
||||
result = in_write(object->payload.cons.cdr, output, escape);
|
||||
}
|
||||
}
|
||||
} else {
|
||||
|
|
@ -123,11 +143,11 @@ struct pso_pointer in_write( struct pso_pointer p, URL_FILE *output,
|
|||
uint32_t v = get_tag_value(p);
|
||||
switch (v) {
|
||||
case CHARACTERTV:
|
||||
url_fputwc( object->payload.character.character, output );
|
||||
write_char(object->payload.character.character, output, escape);
|
||||
break;
|
||||
case CONSTV:
|
||||
url_fputwc(L'(', output);
|
||||
result = print_list_content( p, output, escape );
|
||||
result = write_list_content(p, output, escape);
|
||||
url_fputwc(L')', output);
|
||||
break;
|
||||
case INTEGERTV:
|
||||
|
|
@ -193,10 +213,9 @@ struct pso_pointer write( struct pso_pointer p, struct pso_pointer stream,
|
|||
|
||||
dec_ref(stream);
|
||||
} else {
|
||||
result =
|
||||
make_exception( c_string_to_lisp_string
|
||||
( L"Bad write stream passed to write." ), nil, nil,
|
||||
nil );
|
||||
result = make_exception(
|
||||
c_string_to_lisp_string(L"Bad write stream passed to write."), nil,
|
||||
nil, nil);
|
||||
}
|
||||
|
||||
return result;
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue