Parse commandline strings, move away from old env vars
This commit is contained in:
@@ -1,3 +1,4 @@
|
||||
#include <cmdline_parser.h>
|
||||
#include <device_info.h>
|
||||
#include <devices.h>
|
||||
#include <malloc.h>
|
||||
@@ -7,6 +8,13 @@
|
||||
#include <string.h>
|
||||
#include <system.h>
|
||||
|
||||
static bool cmdline_list_all = false;
|
||||
|
||||
static struct cmdline_opt cmdline_opts[] = {
|
||||
CMDLINE_OPT("la", "list-all", CMDLINE_OPT_VALUE_BOOL, false, &cmdline_list_all),
|
||||
CMDLINE_END(),
|
||||
};
|
||||
|
||||
static const char* device_types_str[] = {
|
||||
[DEVICE_TYPE_DEBUGCONSOLE] = "Debug console", [DEVICE_TYPE_TERMINAL] = "System terminal",
|
||||
[DEVICE_TYPE_KEYBOARD] = "Keyboard", [DEVICE_TYPE_DRIVE] = "Drive",
|
||||
@@ -28,21 +36,12 @@ static void list_all_devices(void) {
|
||||
}
|
||||
|
||||
void app_main(void) {
|
||||
char commandbuf[32];
|
||||
memset(commandbuf, 0, sizeof(commandbuf));
|
||||
|
||||
if (env_get(process_get_pgid(), "help", (void*)commandbuf, sizeof(commandbuf)) == ST_OK) {
|
||||
mprintf("devices -C command\n");
|
||||
mprintf("commands: list_all\n");
|
||||
if (cmdline_parse(get_cmdline(), cmdline_opts) < 0) {
|
||||
mprintf("Failed to parse commandline arguments\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (env_get(process_get_pgid(), "C", (void*)commandbuf, sizeof(commandbuf)) != ST_OK) {
|
||||
mprintf("ERROR C=???. No command provided\n");
|
||||
return;
|
||||
}
|
||||
|
||||
if (strcmp(commandbuf, "list_all") == 0) {
|
||||
if (cmdline_list_all) {
|
||||
list_all_devices();
|
||||
}
|
||||
}
|
||||
|
||||
Reference in New Issue
Block a user