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.
|
* Licensed under GPL version 2.0, or, at your option, any later version.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#include <stdbool.h>
|
|
||||||
#include <ctype.h>
|
#include <ctype.h>
|
||||||
|
#include <stdbool.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
@ -46,6 +46,24 @@
|
||||||
struct pso_pointer in_write(struct pso_pointer p, URL_FILE *output,
|
struct pso_pointer in_write(struct pso_pointer p, URL_FILE *output,
|
||||||
bool escape);
|
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,
|
struct pso_pointer print_string_like_thing(struct pso_pointer p,
|
||||||
URL_FILE *output, bool escape) {
|
URL_FILE *output, bool escape) {
|
||||||
switch (get_tag_value(p)) {
|
switch (get_tag_value(p)) {
|
||||||
|
|
@ -53,7 +71,7 @@ struct pso_pointer print_string_like_thing( struct pso_pointer p,
|
||||||
url_fputwc(L':', output);
|
url_fputwc(L':', output);
|
||||||
break;
|
break;
|
||||||
case STRINGTV:
|
case STRINGTV:
|
||||||
if ( !escape )
|
if (escape)
|
||||||
url_fputwc(L'"', output);
|
url_fputwc(L'"', output);
|
||||||
break;
|
break;
|
||||||
}
|
}
|
||||||
|
|
@ -61,18 +79,21 @@ struct pso_pointer print_string_like_thing( struct pso_pointer p,
|
||||||
if (keywordp(p) || stringp(p) || symbolp(p)) {
|
if (keywordp(p) || stringp(p) || symbolp(p)) {
|
||||||
for (struct pso_pointer cursor = p; !nilp(cursor);
|
for (struct pso_pointer cursor = p; !nilp(cursor);
|
||||||
cursor = pointer_to_object(cursor)->payload.string.cdr) {
|
cursor = pointer_to_object(cursor)->payload.string.cdr) {
|
||||||
url_fputwc( pointer_to_object( cursor )->payload.character.
|
wchar_t wc = pointer_to_object(cursor)->payload.string.character;
|
||||||
character, output );
|
|
||||||
|
write_char( wc, output, escape);
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if (stringp(p)) {
|
if (stringp(p)) {
|
||||||
if ( !escape )
|
if (escape)
|
||||||
url_fputwc(L'"', output);
|
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) {
|
bool escape) {
|
||||||
struct pso_pointer result = nil;
|
struct pso_pointer result = nil;
|
||||||
|
|
||||||
|
|
@ -93,8 +114,7 @@ struct pso_pointer print_list_content( struct pso_pointer p, URL_FILE *output,
|
||||||
break;
|
break;
|
||||||
default:
|
default:
|
||||||
url_fputws(L" . ", output);
|
url_fputws(L" . ", output);
|
||||||
result =
|
result = in_write(object->payload.cons.cdr, output, escape);
|
||||||
in_write( object->payload.cons.cdr, output, escape );
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
} else {
|
} else {
|
||||||
|
|
@ -123,11 +143,11 @@ struct pso_pointer in_write( struct pso_pointer p, URL_FILE *output,
|
||||||
uint32_t v = get_tag_value(p);
|
uint32_t v = get_tag_value(p);
|
||||||
switch (v) {
|
switch (v) {
|
||||||
case CHARACTERTV:
|
case CHARACTERTV:
|
||||||
url_fputwc( object->payload.character.character, output );
|
write_char(object->payload.character.character, output, escape);
|
||||||
break;
|
break;
|
||||||
case CONSTV:
|
case CONSTV:
|
||||||
url_fputwc(L'(', output);
|
url_fputwc(L'(', output);
|
||||||
result = print_list_content( p, output, escape );
|
result = write_list_content(p, output, escape);
|
||||||
url_fputwc(L')', output);
|
url_fputwc(L')', output);
|
||||||
break;
|
break;
|
||||||
case INTEGERTV:
|
case INTEGERTV:
|
||||||
|
|
@ -193,10 +213,9 @@ struct pso_pointer write( struct pso_pointer p, struct pso_pointer stream,
|
||||||
|
|
||||||
dec_ref(stream);
|
dec_ref(stream);
|
||||||
} else {
|
} else {
|
||||||
result =
|
result = make_exception(
|
||||||
make_exception( c_string_to_lisp_string
|
c_string_to_lisp_string(L"Bad write stream passed to write."), nil,
|
||||||
( L"Bad write stream passed to write." ), nil, nil,
|
nil, nil);
|
||||||
nil );
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return result;
|
return result;
|
||||||
|
|
|
||||||
Loading…
Add table
Add a link
Reference in a new issue