#include "../include/commands.hpp" #include CMD commands[]{ {CMD_HELP, "help", "show help"}, {CMD_STATUS, "status", "query status of IP"}, {CMD_DISCONNECT, "disconnect", "disconnect from IP"}, {CMD_PUT , "put", "upload file to IP and add to queue"}, {CMD_GET , "get", "retrieve file from deamon"}, {CMD_LIST , "list", "list files that are downloadable from deamon"} /* TODO {CMD_REMOVE , "remove", "remove file from IP and queue (stops xfer if required)"}, {CMD_SETUP , "setup", "configure server at IP"}, {CMD_LOG , "log", "show log from IP"} */ }; COMMANDID getCmdIdFromString(const char *str) { COMMANDID ret = CMD_UNKNOWN; char temp[COMMANDLEN + 1] = {0}; int len = COMMANDLEN; if (std::strlen(str) > COMMANDLEN) { return ret; } else len = std::strlen(str); for (int i = 0; i < len; i++) temp[i] = std::tolower(str[i]); for (int i = 0; i < sizeofarr(commands); i++) { if (!std::strncmp(temp, commands[i].name, COMMANDLEN)) ret = commands[i].cmd; } return ret; } const char *getCmdStringFromId(COMMANDID id) { const char *ret = NULL; for (int i = 0; i < sizeofarr(commands); i++) { if (commands[i].cmd == id) ret = commands[i].name; } return ret; } void printCmds(void) { for(CMD command : commands) { printf("%-12s - %s\n", command.name, command.desc); } }