#include "utils.h" #include #include #include /* * Macros */ #define MAX_CLI_ARGS (20) /* * Type definitions */ typedef struct { const char *key; char *value; } cli_arg_t; /* * Data */ static cli_arg_t _cli_args[MAX_CLI_ARGS]; /* * Public API */ void print_usage_text() { printf("ipoim -M -A
-P -C ...\n"); printf(" --- MANDATORY ARGUMENTS ---\n"); printf(" -M - operation mode ('provider' or 'last-mile')\n"); printf(" -A
- IPv4 to listen on/connect to\n"); printf(" -P - port to listen on/connect to\n"); printf(" -E - extension to use, one of:\n"); printf(" * pipe - use STDIN and STDOUT\n"); printf(" --- OPTIONAL ARGUMENTS ---\n"); printf(" +V - be verbose\n"); } bool cli_arg_set(const char *key, char *value) { int index_to_use = -1; for (int i = 0; i < MAX_CLI_ARGS; ++i) { // empty entry if (_cli_args[i].key == NULL) { // update index only if no place is found yet if (index_to_use == -1) index_to_use = i; } // entry with the same name else if (!strcmp(_cli_args[i].key, key)) { index_to_use = i; break; } } // no space for the argument if (index_to_use == -1) { return false; } _cli_args[index_to_use].key = key; _cli_args[index_to_use].value = value; return true; } const char *cli_arg_get(const char *key) { for (int i = 0; i < MAX_CLI_ARGS; ++i) { if (_cli_args[i].key == NULL) { continue; } if (strcmp(_cli_args[i].key, key)) { continue; } return _cli_args[i].value; } return NULL; }