Jeroen Demeyer on Tue, 12 Jan 2016 15:46:58 +0100 |
[Date Prev] [Date Next] [Thread Prev] [Thread Next] [Date Index] [Thread Index]
Support trailing semicolon in gp_read_str_multiline() |
Dear pari-dev,Attached patch changes gp_read_str_multiline() to look at trailing a semicolon. If there is, the output is silenced (i.e. gnil is returned).
In other words, gp_read_str_multiline("a = 1") will return a t_INT 1 while gp_read_str_multiline("a = 1;") will return gnil.
Cheers, Jeroen.
commit fa8256f515c94b953430bf2944a10bf62f312151 Author: Jeroen Demeyer <jdemeyer@cage.ugent.be> Date: Tue Jan 12 15:30:48 2016 +0100 Support final semicolon to silence output in gp_read_str_multiline() diff --git a/src/language/es.c b/src/language/es.c index 3c7a5e9..2e56178 100644 --- a/src/language/es.c +++ b/src/language/es.c @@ -214,6 +214,10 @@ init_filtre(filtre_t *F, Buffer *buf) /** INPUT METHODS **/ /** **/ /********************************************************************/ + +static int +is_silent(char *s) {return s[strlen(s) - 1] == ';';} + /* create */ Buffer * new_buffer(void) @@ -261,17 +265,28 @@ gp_read_stream(FILE *fi) delete_buffer(b); return x; } +/* flags for gp_read_from_input */ +#define READ_LOOP 1 +#define READ_ALWAYS_RETURN 2 + static GEN -gp_read_from_input(input_method* IM, int loop) +gp_read_from_input(input_method* IM, unsigned int flags) { Buffer *b = new_buffer(); GEN x = gnil; filtre_t F; do { + char *s; init_filtre(&F, b); if (!input_loop(&F, IM)) break; - if (*(b->buf)) x = readseq(b->buf); - } while (loop); + s = b->buf; + if (s[0]) + { + x = readseq(s); + if ((flags & READ_ALWAYS_RETURN) == 0 && x != gnil && is_silent(s)) + x = gnil; + } + } while (flags & READ_LOOP); delete_buffer(b); return x; } @@ -330,7 +345,7 @@ gp_read_str_multiline(const char *s) IM.getline = &file_input; IM.free = 0; - return gp_read_from_input(&IM, 1); + return gp_read_from_input(&IM, READ_LOOP); } GEN