forked from ElementsProject/lightning
-
Notifications
You must be signed in to change notification settings - Fork 0
/
rune.c
81 lines (76 loc) · 2.25 KB
/
rune.c
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
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
/* Decodes a rune. */
#include "config.h"
#include <ccan/err/err.h>
#include <ccan/opt/opt.h>
#include <ccan/rune/rune.h>
#include <common/configdir.h>
#include <common/setup.h>
#include <common/utils.h>
#include <common/version.h>
#include <stdio.h>
int main(int argc, char *argv[])
{
struct rune *rune;
common_setup(argv[0]);
opt_register_noarg("--help|-h", opt_usage_and_exit,
"<rune>", "Show this message");
opt_register_version();
opt_early_parse(argc, argv, opt_log_stderr_exit);
opt_parse(&argc, argv, opt_log_stderr_exit);
if (argc != 2)
opt_usage_exit_fail("needs rune");
rune = rune_from_base64(NULL, argv[1]);
if (!rune)
opt_usage_exit_fail("invalid rune");
printf("string encoding: %s\n", rune_to_string(rune, rune));
for (size_t i = 0; i < tal_count(rune->restrs); i++) {
const struct rune_restr *restr = rune->restrs[i];
const char *sep = "- ";
for (size_t j = 0; j < tal_count(restr->alterns); j++) {
const struct rune_altern *alt = restr->alterns[j];
if (streq(alt->fieldname, "")) {
printf("Unique id is %s", alt->value);
} else {
printf("%s", sep);
switch (alt->condition) {
case RUNE_COND_IF_MISSING:
printf("%s is missing", alt->fieldname);
break;
case RUNE_COND_EQUAL:
printf("%s equal to %s", alt->fieldname, alt->value);
break;
case RUNE_COND_NOT_EQUAL:
printf("%s unequal to %s", alt->fieldname, alt->value);
break;
case RUNE_COND_BEGINS:
printf("%s starts with %s", alt->fieldname, alt->value);
break;
case RUNE_COND_ENDS:
printf("%s ends with %s", alt->fieldname, alt->value);
break;
case RUNE_COND_CONTAINS:
printf("%s contains %s", alt->fieldname, alt->value);
break;
case RUNE_COND_INT_LESS:
printf("%s < %s", alt->fieldname, alt->value);
break;
case RUNE_COND_INT_GREATER:
printf("%s > %s", alt->fieldname, alt->value);
break;
case RUNE_COND_LEXO_BEFORE:
printf("%s sorts before %s", alt->fieldname, alt->value);
break;
case RUNE_COND_LEXO_AFTER:
printf("%s sorts after %s", alt->fieldname, alt->value);
break;
case RUNE_COND_COMMENT:
printf("comment: %s%s", alt->fieldname, alt->value);
break;
}
sep = " OR ";
}
}
printf("\n");
}
common_shutdown();
}