playing with linux fmemopen

This commit is contained in:
Alex Shinn 2009-04-03 02:23:07 +09:00
parent 2983b10af1
commit 26c7d669b2
3 changed files with 34 additions and 11 deletions

View file

@ -14,6 +14,9 @@
/* uncomment this to disable huffman-coded immediate symbols */
/* #define USE_HUFF_SYMS 0 */
/* uncomment this to just use a single list for hash tables */
/* #define USE_HASH_SYMS 0 */
/* uncomment this to disable string ports */
/* #define USE_STRING_STREAMS 0 */

2
main.c
View file

@ -43,6 +43,7 @@ void run_main (int argc, char **argv) {
/* parse options */
for (i=1; i < argc && argv[i][0] == '-'; i++) {
switch (argv[i][1]) {
#if USE_STRING_STREAMS
case 'e':
case 'p':
if (! init_loaded) {
@ -60,6 +61,7 @@ void run_main (int argc, char **argv) {
quit=1;
i++;
break;
#endif
case 'q':
init_loaded = 1;
break;

22
sexp.c
View file

@ -385,9 +385,8 @@ sexp sexp_make_vector(sexp len, sexp dflt) {
if (! clen) return the_empty_vector;
v = sexp_alloc_type(vector, SEXP_VECTOR);
x = (sexp*) sexp_alloc(clen*sizeof(sexp));
for (i=0; i<clen; i++) {
for (i=0; i<clen; i++)
x[i] = dflt;
}
sexp_vector_length(v) = clen;
sexp_vector_data(v) = x;
return v;
@ -507,6 +506,23 @@ sexp sexp_make_input_string_port(sexp str) {
return sexp_make_input_port(in);
}
sexp sexp_make_output_string_port () {
FILE *out;
sexp buf = sexp_alloc_type(string, SEXP_STRING), res;
out = open_memstream(&sexp_string_data(str), &sexp_string_length(buf));
res = sexp_make_input_port(in);
sexp_port_cookie(res) = buf;
return res;
}
sexp sexp_get_output_string (sexp port) {
sexp cookie = sexp_port_cookie(port);
fflush(sexp_port_stream(port));
return sexp_substring(cookie,
sexp_make_integer(0),
sexp_string_length(cookie));
}
#endif
#endif
@ -1015,6 +1031,7 @@ sexp sexp_read (sexp in) {
return res;
}
#if USE_STRING_STREAMS
sexp sexp_read_from_string(char *str) {
sexp s = sexp_c_string(str);
sexp in = sexp_make_input_string_port(s);
@ -1023,6 +1040,7 @@ sexp sexp_read_from_string(char *str) {
sexp_deep_free(in);
return res;
}
#endif
void sexp_init() {
int i;