more refactoring to prepare for backslash escaping

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@176 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2020-05-19 13:04:39 +00:00
parent beaf86da5b
commit 101c04e413

View File

@ -367,24 +367,25 @@ static enum eos po_convtab(void)
static enum eos encode_string(const struct encoder *inner_encoder, char xor) static enum eos encode_string(const struct encoder *inner_encoder, char xor)
{ {
const struct encoder *outer_encoder = encoder_current; // buffer encoder const struct encoder *outer_encoder = encoder_current; // buffer encoder
int offset;
// make given encoder the current one (for ALU-parsed values) // make given encoder the current one (for ALU-parsed values)
encoder_current = inner_encoder; encoder_current = inner_encoder;
do { do {
if (GotByte == '"') { if (GotByte == '"') {
// read initial character DYNABUF_CLEAR(GlobalDynaBuf);
GetQuotedByte(); if (Input_quoted_to_dynabuf('"'))
// FIXME - this will fail with backslash escaping! return SKIP_REMAINDER; // unterminated or escaping error
// send characters until closing quote is reached
while (GotByte && (GotByte != '"')) {
output_8(xor ^ encoding_encode_char(GotByte));
GetQuotedByte();
}
if (GotByte == CHAR_EOS)
return AT_EOS_ANYWAY;
// after closing quote, proceed with next char // eat closing quote
GetByte(); GetByte();
// now convert to unescaped version
if (Input_unescape_dynabuf())
return SKIP_REMAINDER; // escaping error
// send characters
for (offset = 0; offset < GlobalDynaBuf->size; ++offset)
output_8(xor ^ encoding_encode_char(GLOBALDYNABUF_CURRENT[offset]));
} else { } else {
// Parse value. No problems with single characters // Parse value. No problems with single characters
// because the current encoding is // because the current encoding is
@ -1200,18 +1201,18 @@ static enum eos throw_string(const char prefix[], void (*fn)(const char *))
DynaBuf_add_string(user_message, prefix); DynaBuf_add_string(user_message, prefix);
do { do {
if (GotByte == '"') { if (GotByte == '"') {
// parse string DYNABUF_CLEAR(GlobalDynaBuf);
GetQuotedByte(); // read initial character if (Input_quoted_to_dynabuf('"'))
// FIXME - this will fail with backslash escaping! return SKIP_REMAINDER; // unterminated or escaping error
// send characters until closing quote is reached
while (GotByte && (GotByte != '"')) { // eat closing quote
DYNABUF_APPEND(user_message, GotByte);
GetQuotedByte();
}
if (GotByte == CHAR_EOS)
return AT_EOS_ANYWAY;
// after closing quote, proceed with next char
GetByte(); GetByte();
// now convert to unescaped version
if (Input_unescape_dynabuf())
return SKIP_REMAINDER; // escaping error
DynaBuf_append(GlobalDynaBuf, '\0'); // terminate string
DynaBuf_add_string(user_message, GLOBALDYNABUF_CURRENT); // add to message
} else { } else {
// parse value // parse value
ALU_any_result(&object); ALU_any_result(&object);