初始化版本

This commit is contained in:
冯佳
2025-12-23 08:29:44 +08:00
parent 0ec8a5b380
commit cc9f363ff8
22 changed files with 1370 additions and 50 deletions

50
src/core/menu_stack.c Normal file
View File

@ -0,0 +1,50 @@
#include "menu_stack.h"
#include <string.h>
MenuErrCode menu_stack_init(MenuStack* stack) {
if (!stack) return MENU_ERR_INVALID_PARAM;
memset(stack, 0, sizeof(MenuStack));
stack->top = 0;
return MENU_ERR_OK;
}
MenuErrCode menu_stack_push(MenuStack* stack, MenuNodeId id) {
if (!stack) return MENU_ERR_INVALID_PARAM;
if (stack->top >= MENU_CONFIG_STACK_DEPTH) {
return MENU_ERR_STACK_OVERFLOW;
}
stack->path[stack->top++] = id;
return MENU_ERR_OK;
}
MenuErrCode menu_stack_pop(MenuStack* stack, MenuNodeId* id) {
if (!stack) return MENU_ERR_INVALID_PARAM;
if (stack->top == 0) {
return MENU_ERR_STACK_UNDERFLOW;
}
if (id) {
*id = stack->path[--stack->top];
} else {
stack->top--;
}
return MENU_ERR_OK;
}
MenuErrCode menu_stack_peek(const MenuStack* stack, MenuNodeId* id) {
if (!stack || !id) return MENU_ERR_INVALID_PARAM;
if (stack->top == 0) {
return MENU_ERR_STACK_UNDERFLOW;
}
*id = stack->path[stack->top - 1];
return MENU_ERR_OK;
}
bool menu_stack_is_empty(const MenuStack* stack) {
return (stack == NULL) || (stack->top == 0);
}
void menu_stack_clear(MenuStack* stack) {
if (stack) {
stack->top = 0;
}
}