mirror of
https://git.rwth-aachen.de/acs/public/villas/node/
synced 2025-03-09 00:00:00 +01:00
refactor: json_foreach: index -> i
This commit is contained in:
parent
a8bda29430
commit
0240d5b2c4
11 changed files with 38 additions and 36 deletions
|
@ -224,9 +224,9 @@ int hook_parse_list(struct list *list, json_t *cfg, struct path *o, struct node
|
|||
if (!json_is_array(cfg))
|
||||
error("Hooks must be configured as a list of objects");
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_hook;
|
||||
json_array_foreach(cfg, index, json_hook) {
|
||||
json_array_foreach(cfg, i, json_hook) {
|
||||
int ret;
|
||||
const char *type;
|
||||
struct hook_type *ht;
|
||||
|
|
|
@ -21,7 +21,7 @@ int cbuilder_parse(struct node *n, json_t *cfg)
|
|||
const char *model;
|
||||
|
||||
int ret;
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_error_t err;
|
||||
|
||||
ret = json_unpack_ex(cfg, &err, 0, "{ s: F, s: s, s: b }",
|
||||
|
@ -43,11 +43,11 @@ int cbuilder_parse(struct node *n, json_t *cfg)
|
|||
cb->paramlen = json_array_size(json_params);
|
||||
cb->params = alloc(cb->paramlen * sizeof(double));
|
||||
|
||||
json_array_foreach(json_params, index, json_param) {
|
||||
json_array_foreach(json_params, i, json_param) {
|
||||
if (json_is_number(json_param))
|
||||
error("Setting 'parameters' of node %s must be an JSON array of numbers!", node_name(n));
|
||||
|
||||
cb->params[index] = json_number_value(json_params);
|
||||
cb->params[i] = json_number_value(json_params);
|
||||
|
||||
}
|
||||
}
|
||||
|
|
|
@ -109,9 +109,9 @@ int iec61850_parse_mapping(json_t *json_mapping, struct list *mapping)
|
|||
|
||||
if (json_is_array(json_mapping)) {
|
||||
json_t *json_field;
|
||||
size_t index;
|
||||
size_t i;
|
||||
|
||||
json_array_foreach(json_mapping, index, json_field) {
|
||||
json_array_foreach(json_mapping, i, json_field) {
|
||||
const struct iec61850_type_descriptor *m;
|
||||
const char *type = json_string_value(json_field);
|
||||
|
||||
|
|
|
@ -50,12 +50,12 @@ static int nanomsg_parse_endpoints(struct list *l, json_t *cfg)
|
|||
{
|
||||
const char *ep;
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_val;
|
||||
|
||||
switch (json_typeof(cfg)) {
|
||||
case JSON_ARRAY:
|
||||
json_array_foreach(cfg, index, json_val) {
|
||||
json_array_foreach(cfg, i, json_val) {
|
||||
ep = json_string_value(json_val);
|
||||
if (!ep)
|
||||
return -1;
|
||||
|
|
|
@ -124,7 +124,7 @@ static int ngsi_parse_entity(json_t *entity, struct ngsi *i, struct sample *smps
|
|||
int ret;
|
||||
const char *id, *name, *type;
|
||||
|
||||
size_t index;
|
||||
size_t l;
|
||||
json_t *attribute, *attributes;
|
||||
|
||||
ret = json_unpack(entity, "{ s: s, s: s, s: o }",
|
||||
|
@ -141,7 +141,7 @@ static int ngsi_parse_entity(json_t *entity, struct ngsi *i, struct sample *smps
|
|||
for (int k = 0; k < cnt; k++)
|
||||
smps[k]->length = json_array_size(attributes);
|
||||
|
||||
json_array_foreach(attributes, index, attribute) {
|
||||
json_array_foreach(attributes, l, attribute) {
|
||||
struct ngsi_attribute *map;
|
||||
json_t *metadata, *values, *tuple;
|
||||
|
||||
|
@ -203,10 +203,10 @@ static int ngsi_parse_mapping(struct list *mapping, json_t *cfg)
|
|||
|
||||
list_init(mapping);
|
||||
|
||||
size_t index;
|
||||
size_t j;
|
||||
json_t *json_token;
|
||||
|
||||
json_array_foreach(cfg, index, json_token) {
|
||||
json_array_foreach(cfg, j, json_token) {
|
||||
const char *token;
|
||||
|
||||
token = json_string_value(json_token);
|
||||
|
@ -215,7 +215,7 @@ static int ngsi_parse_mapping(struct list *mapping, json_t *cfg)
|
|||
|
||||
struct ngsi_attribute *a = (struct ngsi_attribute *) alloc(sizeof(struct ngsi_attribute));
|
||||
|
||||
a->index = index;
|
||||
a->index = j;
|
||||
|
||||
/* Parse Attribute: AttributeName(AttributeType) */
|
||||
int bytes;
|
||||
|
@ -245,7 +245,7 @@ static int ngsi_parse_mapping(struct list *mapping, json_t *cfg)
|
|||
.name = "index",
|
||||
.type = "integer"
|
||||
};
|
||||
assert(asprintf(&i.value, "%zu", index));
|
||||
assert(asprintf(&i.value, "%zu", j));
|
||||
|
||||
list_push(&a->metadata, memdup(&s, sizeof(s)));
|
||||
list_push(&a->metadata, memdup(&i, sizeof(i)));
|
||||
|
|
|
@ -67,17 +67,17 @@ int shmem_parse(struct node *n, json_t *cfg)
|
|||
|
||||
shm->exec = alloc(sizeof(char *) * (json_array_size(json_exec) + 1));
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_val;
|
||||
json_array_foreach(json_exec, index, json_val) {
|
||||
json_array_foreach(json_exec, i, json_val) {
|
||||
val = json_string_value(json_val);
|
||||
if (!val)
|
||||
error("Setting 'exec' of node %s must be an array of strings", node_name(n));
|
||||
|
||||
shm->exec[index] = strdup(val);
|
||||
shm->exec[i] = strdup(val);
|
||||
}
|
||||
|
||||
shm->exec[index] = NULL;
|
||||
shm->exec[i] = NULL;
|
||||
}
|
||||
|
||||
return 0;
|
||||
|
|
|
@ -83,7 +83,7 @@ int test_rtt_parse(struct node *n, json_t *cfg)
|
|||
int numrates = 0;
|
||||
int numvalues = 0;
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_cases, *json_case, *json_val;
|
||||
json_t *json_rates = NULL, *json_values = NULL;
|
||||
json_error_t err;
|
||||
|
@ -116,7 +116,7 @@ int test_rtt_parse(struct node *n, json_t *cfg)
|
|||
if (!json_is_array(json_cases))
|
||||
error("The 'cases' setting of node %s must be an array.", node_name(n));
|
||||
|
||||
json_array_foreach(json_cases, index, json_case) {
|
||||
json_array_foreach(json_cases, i, json_case) {
|
||||
int limit = -1;
|
||||
double duration = -1; /* in secs */
|
||||
|
||||
|
@ -148,23 +148,25 @@ int test_rtt_parse(struct node *n, json_t *cfg)
|
|||
values = realloc(values, sizeof(values[0]) * numvalues);
|
||||
|
||||
if (json_is_array(json_rates)) {
|
||||
json_array_foreach(json_rates, index, json_val) {
|
||||
size_t j;
|
||||
json_array_foreach(json_rates, j, json_val) {
|
||||
if (!json_is_number(json_val))
|
||||
error("The 'rates' setting of node %s must be an array of real numbers", node_name(n));
|
||||
|
||||
rates[index] = json_integer_value(json_val);
|
||||
rates[i] = json_integer_value(json_val);
|
||||
}
|
||||
}
|
||||
else
|
||||
rates[0] = json_number_value(json_rates);
|
||||
|
||||
if (json_is_array(json_values)) {
|
||||
json_array_foreach(json_values, index, json_val) {
|
||||
size_t j;
|
||||
json_array_foreach(json_values, j, json_val) {
|
||||
if (!json_is_integer(json_val))
|
||||
error("The 'values' setting of node %s must be an array of integers", node_name(n));
|
||||
|
||||
values[index] = json_integer_value(json_val);
|
||||
if (values[index] < 2)
|
||||
values[j] = json_integer_value(json_val);
|
||||
if (values[j] < 2)
|
||||
error("Each 'values' entry must be at least 2 or larger");
|
||||
}
|
||||
}
|
||||
|
|
|
@ -517,7 +517,7 @@ int websocket_parse(struct node *n, json_t *cfg)
|
|||
struct websocket *w = (struct websocket *) n->_vd;
|
||||
int ret;
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_dests = NULL;
|
||||
json_t *json_dest;
|
||||
json_error_t err;
|
||||
|
@ -532,7 +532,7 @@ int websocket_parse(struct node *n, json_t *cfg)
|
|||
if (!json_is_array(json_dests))
|
||||
error("The 'destinations' setting of node %s must be an array of URLs", node_name(n));
|
||||
|
||||
json_array_foreach(json_dests, index, json_dest) {
|
||||
json_array_foreach(json_dests, i, json_dest) {
|
||||
const char *uri, *prot, *ads, *path;
|
||||
|
||||
uri = json_string_value(json_dest);
|
||||
|
|
|
@ -101,7 +101,7 @@ int zeromq_parse(struct node *n, json_t *cfg)
|
|||
const char *filter = NULL;
|
||||
const char *format = "villas.human";
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_pub = NULL;
|
||||
json_t *json_curve = NULL;
|
||||
json_t *json_val;
|
||||
|
@ -134,7 +134,7 @@ int zeromq_parse(struct node *n, json_t *cfg)
|
|||
if (json_pub) {
|
||||
switch (json_typeof(json_pub)) {
|
||||
case JSON_ARRAY:
|
||||
json_array_foreach(json_pub, index, json_val) {
|
||||
json_array_foreach(json_pub, i, json_val) {
|
||||
ep = json_string_value(json_pub);
|
||||
if (!ep)
|
||||
error("All 'publish' settings must be strings");
|
||||
|
|
|
@ -149,9 +149,9 @@ int signal_parse_list(struct list *list, json_t *cfg)
|
|||
if (!json_is_array(cfg))
|
||||
return -1;
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_signal;
|
||||
json_array_foreach(cfg, index, json_signal) {
|
||||
json_array_foreach(cfg, i, json_signal) {
|
||||
s = alloc(sizeof(struct signal));
|
||||
if (!s)
|
||||
return -1;
|
||||
|
|
|
@ -220,9 +220,9 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
|
|||
if (!json_is_array(json_plugins))
|
||||
error("Setting 'plugins' must be a list of strings");
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_plugin;
|
||||
json_array_foreach(json_plugins, index, json_plugin) {
|
||||
json_array_foreach(json_plugins, i, json_plugin) {
|
||||
struct plugin *p = (struct plugin *) alloc(sizeof(struct plugin));
|
||||
|
||||
ret = plugin_init(p);
|
||||
|
@ -275,9 +275,9 @@ int super_node_parse_json(struct super_node *sn, json_t *cfg)
|
|||
if (!json_is_array(json_paths))
|
||||
warn("Setting 'paths' must be a list.");
|
||||
|
||||
size_t index;
|
||||
size_t i;
|
||||
json_t *json_path;
|
||||
json_array_foreach(json_paths, index, json_path) {
|
||||
json_array_foreach(json_paths, i, json_path) {
|
||||
struct path *p = (struct path *) alloc(sizeof(struct path));
|
||||
|
||||
ret = path_init(p);
|
||||
|
|
Loading…
Add table
Reference in a new issue