Make macro_reference_t store the offset of the first macro action and expose ParseMacroAction

This commit is contained in:
Eric Tang
2017-08-09 13:13:50 -07:00
parent 22e49c50d1
commit b1fb5f62c1
3 changed files with 7 additions and 5 deletions

View File

@@ -70,7 +70,7 @@ parser_error_t parseTextMacroAction(config_buffer_t *buffer, macro_action_t *mac
return ParserError_Success;
}
parser_error_t parseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction) {
parser_error_t ParseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction) {
uint8_t macroActionType = readUInt8(buffer);
switch (macroActionType) {
@@ -91,24 +91,24 @@ parser_error_t parseMacroAction(config_buffer_t *buffer, macro_action_t *macroAc
}
parser_error_t ParseMacro(config_buffer_t *buffer, uint8_t macroIdx) {
uint16_t offset = buffer->offset;
parser_error_t errorCode;
uint16_t nameLen;
bool isLooped = readBool(buffer);
bool isPrivate = readBool(buffer);
const char *name = readString(buffer, &nameLen);
uint16_t macroActionsCount = readCompactLength(buffer);
uint16_t firstMacroActionOffset = buffer->offset;
macro_action_t dummyMacroAction;
(void)isLooped;
(void)isPrivate;
(void)name;
if (!ParserRunDry) {
AllMacros[macroIdx].offset = offset;
AllMacros[macroIdx].firstMacroActionOffset = firstMacroActionOffset;
AllMacros[macroIdx].macroActionsCount = macroActionsCount;
}
for (uint16_t i = 0; i < macroActionsCount; i++) {
errorCode = parseMacroAction(buffer, &dummyMacroAction);
errorCode = ParseMacroAction(buffer, &dummyMacroAction);
if (errorCode != ParserError_Success) {
return errorCode;
}

View File

@@ -4,6 +4,7 @@
// Includes:
#include "parse_config.h"
#include "macros.h"
// Typedefs:
@@ -20,6 +21,7 @@
// Functions:
parser_error_t ParseMacroAction(config_buffer_t *buffer, macro_action_t *macroAction);
parser_error_t ParseMacro(config_buffer_t *buffer, uint8_t macroIdx);
#endif

View File

@@ -13,7 +13,7 @@
// Typedefs:
typedef struct {
uint16_t offset;
uint16_t firstMacroActionOffset;
uint16_t macroActionsCount;
} macro_reference_t;