minor refactoring, moved a function

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@178 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-05-19 14:33:51 +00:00
parent 768c80219b
commit 5b0989ac31
3 changed files with 15 additions and 32 deletions

View File

@ -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);
}

View File

@ -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.

View File

@ -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);