When parsing a macro, store its offset and number of actions

This commit is contained in:
Eric Tang
2017-08-09 09:49:30 -07:00
parent 1c91a7d5d9
commit c983e58d8e
5 changed files with 36 additions and 3 deletions

View File

@@ -38,7 +38,7 @@ parser_error_t ParseConfig(config_buffer_t *buffer)
}
macroCount = readCompactLength(buffer);
for (uint16_t macroIdx = 0; macroIdx < macroCount; macroIdx++) {
errorCode = ParseMacro(buffer);
errorCode = ParseMacro(buffer, macroIdx);
if (errorCode != ParserError_Success) {
return errorCode;
}

View File

@@ -1,4 +1,6 @@
#include "parse_macro.h"
#include "config_globals.h"
#include "macros.h"
parser_error_t parseKeyMacroAction(config_buffer_t *buffer, serialized_macro_action_type_t macroActionType) {
uint8_t keyMacroType = macroActionType - SerializedMacroActionType_KeyMacroAction;
@@ -85,7 +87,8 @@ parser_error_t parseMacroAction(config_buffer_t *buffer) {
return ParserError_InvalidSerializedMacroActionType;
}
parser_error_t ParseMacro(config_buffer_t *buffer) {
parser_error_t ParseMacro(config_buffer_t *buffer, uint16_t macroIdx) {
uint16_t offset = buffer->offset;
parser_error_t errorCode;
uint16_t nameLen;
bool isLooped = readBool(buffer);
@@ -96,6 +99,10 @@ parser_error_t ParseMacro(config_buffer_t *buffer) {
(void)isLooped;
(void)isPrivate;
(void)name;
if (!ParserRunDry) {
AllMacros[macroIdx].offset = offset;
AllMacros[macroIdx].macroActionsCount = macroActionsCount;
}
for (uint16_t i = 0; i < macroActionsCount; i++) {
errorCode = parseMacroAction(buffer);
if (errorCode != ParserError_Success) {

View File

@@ -20,6 +20,6 @@
// Functions:
parser_error_t ParseMacro(config_buffer_t *buffer);
parser_error_t ParseMacro(config_buffer_t *buffer, uint16_t macroIdx);
#endif

3
right/src/macros.c Normal file
View File

@@ -0,0 +1,3 @@
#include "macros.h"
macro_reference_t AllMacros[MAX_MACRO_NUM];

23
right/src/macros.h Normal file
View File

@@ -0,0 +1,23 @@
#ifndef __MACROS_H__
#define __MACROS_H__
// Includes:
#include <stdint.h>
// Macros:
#define MAX_MACRO_NUM 1024
// Typedefs:
typedef struct {
uint16_t offset;
uint16_t macroActionsCount;
} macro_reference_t;
// Variables:
extern macro_reference_t AllMacros[MAX_MACRO_NUM];
#endif