summaryrefslogtreecommitdiff
path: root/src/uci/command.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/uci/command.c')
-rw-r--r--src/uci/command.c52
1 files changed, 26 insertions, 26 deletions
diff --git a/src/uci/command.c b/src/uci/command.c
index 02d6e0f..c64fee2 100644
--- a/src/uci/command.c
+++ b/src/uci/command.c
@@ -1,10 +1,10 @@
#include <assert.h>
#include <string.h>
#include <stdlib.h>
-#include "command.h"
+#include "uci/internals/command.h"
-ucicmd ucicmd_init() {
- ucicmd output = {0};
+uci_cmd_t uci_cmd_init() {
+ uci_cmd_t output = {0};
output.empty = true;
output.args_capacity = 32;
@@ -37,16 +37,16 @@ bool is_valid_cmd(const char *token) {
(strcmp(token, "option") == 0);
}
-void ucicmd_add(ucicmd* cmd, const char* token) {
+void uci_cmd_add(uci_cmd_t* cmd, const char* token) {
if (!cmd->empty) {
- ucicmd_append_arg(cmd, token);
+ uci_cmd_append_arg(cmd, token);
return;
}
if (is_valid_cmd(token) == 0) return;
- ucicmd_set_root(cmd, token);
+ uci_cmd_set_root(cmd, token);
}
-void ucicmd_set_root(ucicmd* cmd, const char* token) {
+void uci_cmd_set_root(uci_cmd_t* cmd, const char* token) {
cmd->empty = false;
int i = 0;
for (; token[i] != 0; i++) {
@@ -56,7 +56,7 @@ void ucicmd_set_root(ucicmd* cmd, const char* token) {
if (i < MAX_TOKEN_SIZE) cmd->root[i] = 0;
}
-void ucicmd_append_arg(ucicmd* cmd, const char* token) {
+void uci_cmd_append_arg(uci_cmd_t* cmd, const char* token) {
if (cmd->args_count + 1 > cmd->args_capacity) {
cmd->args_capacity += 32;
// does realloc set all zeros, like calloc???
@@ -66,7 +66,7 @@ void ucicmd_append_arg(ucicmd* cmd, const char* token) {
sizeof(char) * MAX_TOKEN_SIZE * cmd->args_capacity
);
memset(
- ucicmd_get_arg(*cmd, cmd->args_capacity - 32),
+ uci_cmd_get_arg(*cmd, cmd->args_capacity - 32),
0,
32 * MAX_TOKEN_SIZE
);
@@ -81,11 +81,11 @@ void ucicmd_append_arg(ucicmd* cmd, const char* token) {
if (i < MAX_TOKEN_SIZE) cmd->args[shift + i] = 0;
}
-char* ucicmd_get_arg(ucicmd cmd, int i) {
+char* uci_cmd_get_arg(uci_cmd_t cmd, int i) {
return cmd.args + i * MAX_TOKEN_SIZE;
}
-void ucicmd_deinit(ucicmd cmd) {
+void uci_cmd_deinit(uci_cmd_t cmd) {
free(cmd.args);
}
@@ -94,31 +94,31 @@ void ucicmd_deinit(ucicmd cmd) {
#include <stdbool.h>
#include <string.h>
-bool test_ucicmd() {
- ucicmd cmd = ucicmd_init();
- ucicmd_set_root(&cmd, "root");
- ucicmd_append_arg(&cmd, "arg1");
- ucicmd_append_arg(&cmd, "arg2");
- ucicmd_append_arg(&cmd, "arg3");
+bool test_uci_cmd_t() {
+ uci_cmd_t cmd = uci_cmd_init();
+ uci_cmd_set_root(&cmd, "root");
+ uci_cmd_append_arg(&cmd, "arg1");
+ uci_cmd_append_arg(&cmd, "arg2");
+ uci_cmd_append_arg(&cmd, "arg3");
if (strncmp(cmd.root, "root", MAX_TOKEN_SIZE) != 0) return false;
- if (strncmp(ucicmd_get_arg(cmd, 0), "arg1", MAX_TOKEN_SIZE) != 0)
+ if (strncmp(uci_cmd_get_arg(cmd, 0), "arg1", MAX_TOKEN_SIZE) != 0)
return false;
- if (strncmp(ucicmd_get_arg(cmd, 1), "arg2", MAX_TOKEN_SIZE) != 0)
+ if (strncmp(uci_cmd_get_arg(cmd, 1), "arg2", MAX_TOKEN_SIZE) != 0)
return false;
- if (strncmp(ucicmd_get_arg(cmd, 2), "arg3", MAX_TOKEN_SIZE) != 0)
+ if (strncmp(uci_cmd_get_arg(cmd, 2), "arg3", MAX_TOKEN_SIZE) != 0)
return false;
return true;
}
-bool test_invalid_cmd_ucicmd() {
- ucicmd cmd = ucicmd_init();
- ucicmd_add(&cmd, "john");
- ucicmd_add(&cmd, "debug");
- ucicmd_add(&cmd, "on");
+bool test_invalid_cmd_uci_cmd_t() {
+ uci_cmd_t cmd = uci_cmd_t_init();
+ uci_cmd_add(&cmd, "john");
+ uci_cmd_add(&cmd, "debug");
+ uci_cmd_add(&cmd, "on");
if (strncmp(cmd.root, "debug", MAX_TOKEN_SIZE) != 0) return false;
- if (strncmp(ucicmd_get_arg(cmd, 0), "on", MAX_TOKEN_SIZE) != 0)
+ if (strncmp(uci_cmd_t_get_arg(cmd, 0), "on", MAX_TOKEN_SIZE) != 0)
return false;
return true;
}