From: Ralf J. <jue...@cs...> - 2005-11-26 17:24:30
|
The patch I sent yesterday didn't really work in non-interactive mode. Here's what I have now: --- orig/src/io.c +++ mod/src/io.c @@ -46,6 +46,7 @@ int line_flush_stdout; char *print_buffer; char *pname_buffer; +int read_string_p; unsigned char char_map[256]; @@ -232,7 +233,10 @@ read_char(void) { int c = EOF; - if (context->input_file==stdin && prompt_string) { + if (read_string_p) { + if (*line_pos) + c = *line_pos++; + } else if (context->input_file==stdin && prompt_string) { fill_line_buffer(); c = *line_pos++; } else if (context->input_file) { @@ -297,7 +301,10 @@ next_char(void) { int c = EOF; - if (context->input_file==stdin && prompt_string) { + if (read_string_p) { + if (*line_pos) + c = *line_pos; + } else if (context->input_file==stdin && prompt_string) { fill_line_buffer(); c = *line_pos; } else if (context->input_file) { @@ -464,7 +471,7 @@ map[255] = false; map['\r'] |= map['\n']; - if (context->input_file==stdin && prompt_string) + if (read_string_p || (context->input_file==stdin && prompt_string)) { /* Standard implementation */ while (map[(unsigned char)(c = next_char())]) @@ -909,13 +916,29 @@ DX(xread) { - at *answer; + if (arg_number==0) { + at *answer = read_list(); + if (!answer && feof(context->input_file)) + error(NIL, "End of file", NIL); + return answer; - ARG_NUMBER(0); - answer = read_list(); - if (!answer && feof(context->input_file)) - error(NIL, "End of file", NIL); - return answer; + } else if (arg_number==1) { + ARG_EVAL(1); + char *s = ASTRING(1); + if (strlen(s)>LINE_BUFFER-2) + error(NIL, "string too long", NIL); + + line_pos = strcpy(line_buffer, s); + read_string_p = 1; + at *answer = read_list(); + read_string_p = 0; + + return answer; + + } else { + ARG_NUMBER(-1); + return NIL; + } } @@ -1444,6 +1467,7 @@ (pname_buffer = malloc(LINE_BUFFER))) abort("not enough memory"); line_pos = line_buffer; + read_string_p = 0; set_char_map(')', CHAR_SPECIAL); set_char_map('(', CHAR_SPECIAL); On Fri, 25 Nov 2005, Ralf Juengling wrote: > Thanks. I ended up modifying function 'read'. It's a small hack but > it seems to do the trick: > > ? (eval (read "(list 1 2 3)")) > = (1 2 3) > > > here's the patch: > > --- orig/src/io.c > +++ mod/src/io.c > @@ -909,13 +909,24 @@ > > DX(xread) > { > - at *answer; > + if (arg_number==0) { > + at *answer = read_list(); > + if (!answer && feof(context->input_file)) > + error(NIL, "End of file", NIL); > + return answer; > > - ARG_NUMBER(0); > - answer = read_list(); > - if (!answer && feof(context->input_file)) > - error(NIL, "End of file", NIL); > - return answer; > + } else if (arg_number==1) { > + ARG_EVAL(1); > + char *s = ASTRING(1); > + if (strlen(s)>LINE_BUFFER-2) > + error(NIL, "string too long", NIL); > + line_pos = strcpy(line_buffer, s); > + return read_list(); > + > + } else { > + ARG_NUMBER(-1); > + return NIL; > + } > } > > > Happy belated Thanksgiving! > ralf > > > > On Fri, 25 Nov 2005, Yann LeCun wrote: > >> The simplest thing is probably to go through a temp file: >> >> (de string-read (s) >> (let ((tmp (tmpname))) >> (writing tmp (printf "%s\n" s)) >> (prog1 (reading tmp (read)) (rm tmp)))) >> >> There used to be mechanism for directing all IOs to >> a byte stream (this was called pseudo-io) but it was >> somewhat buggy, so we removed it. >> >> -- Yann >> >> On Thursday 24 November 2005 05:16 pm, Ralf Juengling wrote: >>> Hi, >>> >>> I have a string (e.g., "(list 1 2 3)" or "[ 1 2 3]") and want >>> to turn it into the corresponding lisp object, that is, >>> interpret the string as source text. >>> >>> I didn't find a way, any ideas? >>> >>> Thanks, >>> Ralf >>> >>> >>> >>> ------------------------------------------------------- >>> This SF.net email is sponsored by: Splunk Inc. Do you grep through log >>> files for problems? Stop! Download the new AJAX search engine that makes >>> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! >>> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click >>> _______________________________________________ >>> Lush-users mailing list >>> Lus...@li... >>> https://lists.sourceforge.net/lists/listinfo/lush-users >> >> >> >> ------------------------------------------------------- >> This SF.net email is sponsored by: Splunk Inc. Do you grep through log >> files >> for problems? Stop! Download the new AJAX search engine that makes >> searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! >> http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click >> _______________________________________________ >> Lush-users mailing list >> Lus...@li... >> https://lists.sourceforge.net/lists/listinfo/lush-users >> > > > ------------------------------------------------------- > This SF.net email is sponsored by: Splunk Inc. Do you grep through log files > for problems? Stop! Download the new AJAX search engine that makes > searching your log files as easy as surfing the web. DOWNLOAD SPLUNK! > http://ads.osdn.com/?ad_id=7637&alloc_id=16865&op=click > _______________________________________________ > Lush-users mailing list > Lus...@li... > https://lists.sourceforge.net/lists/listinfo/lush-users > |