a bit of cleanup

git-svn-id: https://svn.code.sf.net/p/acme-crossass/code-0/trunk@367 4df02467-bbd4-4a76-a152-e7ce94205b78
This commit is contained in:
marcobaye 2024-03-18 18:25:11 +00:00
parent 1d7fa761d9
commit 242cdad5be
6 changed files with 35 additions and 27 deletions

View File

@ -487,15 +487,11 @@ int input_unescape_dynabuf(void)
return 0; // ok
}
// Skip or store block (starting with next byte, so call directly after
// reading opening brace).
// the block is read into GlobalDynaBuf.
// If "Store" is TRUE, then a copy is made and a pointer to that is returned.
// If "Store" is FALSE, NULL is returned.
// Read block into GlobalDynabuf
// (reading starts with next byte, so call directly after reading opening brace).
// After calling this function, GotByte holds '}'. Unless EOF was found first,
// but then a serious error would have been thrown.
// FIXME - use a struct block *ptr argument!
char *input_skip_or_store_block(boolean store)
static void block_to_dynabuf(void)
{
char byte;
int depth = 1; // to find matching block end
@ -524,11 +520,22 @@ char *input_skip_or_store_block(boolean store)
break;
}
} while (depth);
// in case of skip, return now
if (!store)
return NULL;
// otherwise, prepare to return copy of block
}
// Skip block (starting with next byte, so call directly after reading opening brace).
// After calling this function, GotByte holds '}'. Unless EOF was found first,
// but then a serious error would have been thrown.
void input_block_skip(void)
{
block_to_dynabuf();
}
// Read block into GlobalDynabuf, make a copy and return a pointer to that
// (reading starts with next byte, so call directly after reading opening brace).
// After calling this function, GotByte holds '}'. Unless EOF was found first,
// but then a serious error would have been thrown.
char *input_block_getcopy(void)
{
block_to_dynabuf();
// prepare to return copy of block
// add EOF, just to make sure block is never read too far
dynabuf_append(GlobalDynaBuf, CHAR_EOS);
dynabuf_append(GlobalDynaBuf, CHAR_EOF);

View File

@ -94,14 +94,15 @@ extern int input_quoted_to_dynabuf(char closing_quote);
// returns 1 on errors (escaping errors)
extern int input_unescape_dynabuf(void);
// Skip or store block (starting with next byte, so call directly after
// reading opening brace).
// the block is read into GlobalDynaBuf.
// If "Store" is TRUE, then a copy is made and a pointer to that is returned.
// If "Store" is FALSE, NULL is returned.
// Skip block (starting with next byte, so call directly after reading opening brace).
// 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);
extern void input_block_skip(void);
// Read block into GlobalDynabuf, make a copy and return a pointer to that
// (reading starts with next byte, so call directly after reading opening brace).
// After calling this function, GotByte holds '}'. Unless EOF was found first,
// but then a serious error would have been thrown.
extern char *input_block_getcopy(void);
// append optional '.'/'@' prefix to GlobalDynaBuf, then keep
// appending while characters are legal for keywords.

View File

@ -169,7 +169,7 @@ void macro_parse_definition(void) // Now GotByte = illegal char after "!macro"
new_macro->definition = input_now->location;
new_macro->original_name = dynabuf_get_copy(user_macro_name);
new_macro->parameter_list = formal_parameters;
new_macro->body = input_skip_or_store_block(TRUE); // changes LineNumber
new_macro->body = input_block_getcopy(); // changes line number!
macro_node->body = new_macro; // link macro struct to tree node
// and that about sums it up
}

View File

@ -84,7 +84,7 @@ extern int pseudopc_unpseudo(struct number *target, struct pseudopc *context, un
extern struct pseudopc *pseudopc_get_context(void);
// returns nonzero if "!pseudopc" is in effect, zero otherwise
int pseudopc_isactive(void);
extern int pseudopc_isactive(void);
#endif

View File

@ -1006,7 +1006,7 @@ static enum eos ifelse(enum ifmode mode)
}
} else {
if (GotByte == CHAR_SOB) {
input_skip_or_store_block(FALSE); // skip block
input_block_skip(); // skip block
} else {
return SKIP_REMAINDER; // skip line (only for ifdef/ifndef)
}
@ -1182,8 +1182,8 @@ does not fail. */
// remember line number of loop pseudo opcode
loop.block.start = input_now->location.line_number;
// read loop body into DynaBuf and get copy
loop.block.body = input_skip_or_store_block(TRUE); // changes line number!
// reading block changes line number!
loop.block.body = input_block_getcopy(); // must be freed!
flow_forloop(&loop);
// free memory
free(loop.block.body);
@ -1208,7 +1208,7 @@ static enum eos po_do(void) // now GotByte = illegal char
// then read block and get copy
loop.block.start = input_now->location.line_number;
// reading block changes line number!
loop.block.body = input_skip_or_store_block(TRUE); // must be freed!
loop.block.body = input_block_getcopy(); // must be freed!
// now GotByte = '}'
NEXTANDSKIPSPACE(); // now GotByte = first non-blank char after block
// read tail condition to buffer
@ -1237,7 +1237,7 @@ static enum eos po_while(void) // now GotByte = illegal char
// then read block and get copy
loop.block.start = input_now->location.line_number;
// reading block changes line number!
loop.block.body = input_skip_or_store_block(TRUE); // must be freed!
loop.block.body = input_block_getcopy(); // must be freed!
// clear tail condition
loop.tail_cond.body = NULL;
flow_do_while(&loop);
@ -1263,7 +1263,7 @@ static enum eos po_macro(void) // now GotByte = illegal char
// for the same reason, there is no need to check for quotes.
while (GotByte != CHAR_SOB)
GetByte();
input_skip_or_store_block(FALSE); // now GotByte = '}'
input_block_skip(); // now GotByte = '}'
}
GetByte(); // Proceed with next character
return ENSURE_EOS;

View File

@ -9,7 +9,7 @@
#define RELEASE "0.97" // update before release FIXME
#define CODENAME "Zem" // update before release
#define CHANGE_DATE "9 Mar" // update before release FIXME
#define CHANGE_DATE "10 Mar" // update before release FIXME
#define CHANGE_YEAR "2024" // update before release
//#define HOME_PAGE "http://home.pages.de/~mac_bacon/smorbrod/acme/"
#define HOME_PAGE "http://sourceforge.net/p/acme-crossass/" // FIXME