/* * VAS_EBOOT -- GRand Unified Bootloader * Copyright (C) 2009 Free Software Foundation, Inc. * * VAS_EBOOT is free software: you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation, either version 3 of the License, or * (at your option) any later version. * * VAS_EBOOT is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * * You should have received a copy of the GNU General Public License * along with VAS_EBOOT. If not, see . */ #ifndef VAS_EBOOT_COMMAND_HEADER #define VAS_EBOOT_COMMAND_HEADER 1 #include #include #include #include typedef enum VasEBoot_command_flags { /* This is an extended command. */ VAS_EBOOT_COMMAND_FLAG_EXTCMD = 0x10, /* This is an dynamic command. */ VAS_EBOOT_COMMAND_FLAG_DYNCMD = 0x20, /* This command accepts block arguments. */ VAS_EBOOT_COMMAND_FLAG_BLOCKS = 0x40, /* This command accepts unknown arguments as direct parameters. */ VAS_EBOOT_COMMAND_ACCEPT_DASH = 0x80, /* This command accepts only options preceding direct arguments. */ VAS_EBOOT_COMMAND_OPTIONS_AT_START = 0x100, /* Can be executed in an entries extractor. */ VAS_EBOOT_COMMAND_FLAG_EXTRACTOR = 0x200 } VasEBoot_command_flags_t; struct VasEBoot_command; typedef VasEBoot_err_t (*VasEBoot_command_func_t) (struct VasEBoot_command *cmd, int argc, char **argv); #define VAS_EBOOT_COMMAND_PRIO_MASK 0xff #define VAS_EBOOT_COMMAND_FLAG_ACTIVE 0x100 /* The command description. */ struct VasEBoot_command { /* The next element. */ struct VasEBoot_command *next; struct VasEBoot_command **prev; /* The name. */ const char *name; /* The priority. */ int prio; /* The callback function. */ VasEBoot_command_func_t func; /* The flags. */ VasEBoot_command_flags_t flags; /* The summary of the command usage. */ const char *summary; /* The description of the command. */ const char *description; /* Arbitrary data. */ void *data; }; typedef struct VasEBoot_command *VasEBoot_command_t; extern VasEBoot_command_t EXPORT_VAR(VasEBoot_command_list); VasEBoot_command_t EXPORT_FUNC(VasEBoot_register_command_prio) (const char *name, VasEBoot_command_func_t func, const char *summary, const char *description, int prio); VasEBoot_command_t EXPORT_FUNC(VasEBoot_register_command_lockdown) (const char *name, VasEBoot_command_func_t func, const char *summary, const char *description); void EXPORT_FUNC(VasEBoot_unregister_command) (VasEBoot_command_t cmd); static inline VasEBoot_command_t VasEBoot_register_command (const char *name, VasEBoot_command_func_t func, const char *summary, const char *description) { return VasEBoot_register_command_prio (name, func, summary, description, 0); } static inline VasEBoot_command_t VasEBoot_register_command_p1 (const char *name, VasEBoot_command_func_t func, const char *summary, const char *description) { return VasEBoot_register_command_prio (name, func, summary, description, 1); } static inline VasEBoot_command_t VasEBoot_command_find (const char *name) { return VasEBoot_named_list_find (VAS_EBOOT_AS_NAMED_LIST (VasEBoot_command_list), name); } static inline VasEBoot_err_t VasEBoot_command_execute (const char *name, int argc, char **argv) { VasEBoot_command_t cmd; cmd = VasEBoot_command_find (name); return (cmd) ? cmd->func (cmd, argc, argv) : VAS_EBOOT_ERR_FILE_NOT_FOUND; } #define FOR_COMMANDS(var) FOR_LIST_ELEMENTS((var), VasEBoot_command_list) #define FOR_COMMANDS_SAFE(var, next) FOR_LIST_ELEMENTS_SAFE((var), (next), VasEBoot_command_list) void VasEBoot_register_core_commands (void); #endif /* ! VAS_EBOOT_COMMAND_HEADER */