diff --git a/src/flow.c b/src/flow.c index 9c4455e..d965b73 100644 --- a/src/flow.c +++ b/src/flow.c @@ -86,9 +86,22 @@ void flow_forloop(struct for_loop *loop) // read condition, make copy, link to struct static void copy_condition(struct condition *condition, char terminator) { + int err; + SKIPSPACE(); DYNABUF_CLEAR(GlobalDynaBuf); - Input_until_terminator(terminator); + while ((GotByte != terminator) && (GotByte != CHAR_EOS)) { + // append to GlobalDynaBuf and check for quotes + DYNABUF_APPEND(GlobalDynaBuf, GotByte); + if ((GotByte == '"') || (GotByte == '\'')) { + err = Input_quoted_to_dynabuf(GotByte); + // here GotByte changes, it might become CHAR_EOS + DYNABUF_APPEND(GlobalDynaBuf, GotByte); // add closing quotes (or CHAR_EOS) as well + if (err) + break; // on error, exit before eating CHAR_EOS via GetByte() + } + GetByte(); + } DynaBuf_append(GlobalDynaBuf, CHAR_EOS); // ensure terminator condition->body = DynaBuf_get_copy(GlobalDynaBuf); } diff --git a/src/input.c b/src/input.c index bdd2b91..1863122 100644 --- a/src/input.c +++ b/src/input.c @@ -427,33 +427,6 @@ char *Input_skip_or_store_block(boolean store) return DynaBuf_get_copy(GlobalDynaBuf); } -// Read bytes and add to GlobalDynaBuf until the given terminator (or CHAR_EOS) -// is found. Act upon single and double quotes by entering (and leaving) quote -// mode as needed (So the terminator does not terminate when inside quotes). -// TODO - called by ONE fn to read loop conditions, terminator is either SOB or EOS, -// so integrate this fn with its caller! -void Input_until_terminator(char terminator) -{ - int err; - char byte = GotByte; - - for (;;) { - // Terminator? Exit. EndOfStatement? Exit. - if ((byte == terminator) || (byte == CHAR_EOS)) - return; - - // otherwise, append to GlobalDynaBuf and check for quotes - DYNABUF_APPEND(GlobalDynaBuf, byte); - if ((byte == '"') || (byte == '\'')) { - err = Input_quoted_to_dynabuf(byte); - DYNABUF_APPEND(GlobalDynaBuf, GotByte); // add terminating char (quote/EOS) as well - if (err) - return; // on error, exit now, before calling GetByte() - } - byte = GetByte(); - } -} - // Append to GlobalDynaBuf while characters are legal for keywords. // Throws "missing string" error if none. // Returns number of characters added. diff --git a/src/input.h b/src/input.h index 698cf47..c2bb94d 100644 --- a/src/input.h +++ b/src/input.h @@ -86,10 +86,7 @@ extern int Input_unescape_dynabuf(void); // After calling this function, GotByte holds '}'. Unless EOF was found first, // but then a serious error would have been thrown. extern char *Input_skip_or_store_block(boolean store); -// Read bytes and add to GlobalDynaBuf until the given terminator (or CHAR_EOS) -// is found. Act upon single and double quotes by entering (and leaving) quote -// mode as needed (So the terminator does not terminate when inside quotes). -extern void Input_until_terminator(char terminator); + // Append to GlobalDynaBuf while characters are legal for keywords. // Throws "missing string" error if none. Returns number of characters added. extern int Input_append_keyword_to_global_dynabuf(void);