-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathsplinter_cli_cmd_orders.c
More file actions
65 lines (54 loc) · 1.75 KB
/
splinter_cli_cmd_orders.c
File metadata and controls
65 lines (54 loc) · 1.75 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
/**
* Copyright 2025 Tim Post
* License: Apache 2 (MIT available upon request to timthepost@protonmail.com)
*
* @file splinter_cli_cmd_orders.c
* @brief Implements the CLI 'orders' command.
*/
#include <stdio.h>
#include <unistd.h>
#include <stdlib.h>
#include <string.h>
#include <errno.h>
#include "splinter_cli.h"
static const char *modname = "orders";
void help_cmd_orders(unsigned int level) {
(void) level;
printf("%s manages standard orders of a key for coupled vector storage.\n", modname);
printf("Usage: %s <set|unset> <key> <count>\n", modname);
return;
}
int cmd_orders(int argc, char *argv[]) {
if (argc < 4) {
help_cmd_orders(1);
return 1;
}
const char *mode = argv[1];
const char *key = argv[2];
uint8_t count = (uint8_t)atoi(argv[3]);
if (strcmp(mode, "set") == 0) {
char val_buf[1024];
const void *vals[count];
size_t lens[count];
for (int i = 0; i < count; i++) {
snprintf(val_buf, sizeof(val_buf), "%s_%d", SPL_ORDER_ACCESSOR, i);
vals[i] = strdup(val_buf);
lens[i] = strlen(val_buf);
}
int ret = splinter_client_set_tandem(key, vals, lens, count);
printf("Tandem set for %s with %d orders: %s\n", key, count, ret == 0 ? "OK" : "FAIL");
for (int i = 0; i < count; i++) {
if (vals[i] && strlen(vals[i])) {
free((void *)vals[i]);
}
}
}
else if (strcmp(mode, "unset") == 0) {
splinter_client_unset_tandem(key, count);
printf("Tandem unset for %s (%d orders) executed.\n", key, count);
} else {
fprintf(stderr,"Unsupported mode: %s ('set' or 'unset' are supported)\n", mode);
return 1;
}
return 0;
}