diff --git a/src/sandbox.c b/src/sandbox.c index c52a8d0..e2c8e12 100755 --- a/src/sandbox.c +++ b/src/sandbox.c @@ -7,6 +7,36 @@ #include #include +#define ALIAS(...) \ + (const char*[]) { __VA_ARGS__, NULL } + +#define ALIASES(...) \ + (const char**[]) { __VA_ARGS__, NULL } + +#define ARGUMENTS(...) \ + (const Argument[]) { \ + __VA_ARGS__, {} \ + } + +#define OPTIONS(...) \ + (const Option[]) { \ + __VA_ARGS__, {} \ + } + +Command COMMANDS[] = { + // Help + { + .handler = command_help, + .description = "Display help information.", + .details = "Display help information about the available commands and their options.", + .aliases = ALIASES(ALIAS("help")), + .arguments = ARGUMENTS({.name = "command", .required = false, .description = "The command to display help information for."}, + {.name = "test", .required = false, .description = "Test."}), + .options = OPTIONS({.aliases = ALIASES(ALIAS("--help"), ALIAS("-h")), .arguments = NULL, .description = "Display help information."}, + {.aliases = ALIASES(ALIAS("--test")), .arguments = NULL, .description = "Test."}), + }, +}; + int main(int argc, char** argv) { // Ensure the sandbox user exists struct passwd* pw = getpwnam(SANDBOX_USER); @@ -35,4 +65,8 @@ int main(int argc, char** argv) { } // TODO: Parse commands from the command line -} \ No newline at end of file +} + +int command_help(int argc, char* argv[]) { + return EXIT_SUCCESS; +} diff --git a/src/sandbox.h b/src/sandbox.h index 422c737..8e8152d 100755 --- a/src/sandbox.h +++ b/src/sandbox.h @@ -5,4 +5,29 @@ #define SANDBOX_VERSION "0.1.4" #define SANDBOX_USER "sandbox" +typedef struct { + const char* name; + const bool required; + const char* description; +} Argument; + +typedef struct { + const char*** aliases; + const Argument* arguments; + const char* description; +} Option; + +typedef struct { + int (*const handler)(int argc, char* argv[]); + const char*** aliases; + const Argument* arguments; + const Option* options; + const char* description; + const char* details; +} Command; + +extern Command COMMANDS[]; + int main(int argc, char** argv); + +int command_help(int argc, char* argv[]); \ No newline at end of file diff --git a/src/utils.c b/src/utils.c index 19a8a85..43fd00b 100755 --- a/src/utils.c +++ b/src/utils.c @@ -12,7 +12,7 @@ #include #include -char _error_buffer[ERROR_BUFFER_SIZE]; +char ERROR_BUFFER[ERROR_BUFFER_SIZE]; result_t success(void) { return EXIT_SUCCESS; @@ -23,7 +23,7 @@ result_t failure(const char* format, ...) { va_start(args, format); // Print the error message into the error buffer - vsnprintf(_error_buffer, ERROR_BUFFER_SIZE, format, args); + vsnprintf(ERROR_BUFFER, ERROR_BUFFER_SIZE, format, args); va_end(args); @@ -31,7 +31,7 @@ result_t failure(const char* format, ...) { } const char* error(void) { - return _error_buffer; + return ERROR_BUFFER; } result_t format(char** _str, const char* format, ...) { diff --git a/src/utils.h b/src/utils.h index 1bbd2b3..a4c90b6 100755 --- a/src/utils.h +++ b/src/utils.h @@ -6,7 +6,7 @@ #define ERROR_BUFFER_SIZE 4096 -extern char _error_buffer[]; +extern char ERROR_BUFFER[]; typedef int result_t;