From f5d9838807caaad87ed88cb209df7d2e5fe47940 Mon Sep 17 00:00:00 2001 From: Philipp Jungkamp Date: Mon, 26 Jan 2026 16:08:19 +0100 Subject: [PATCH] fix(clang-format): Proper formatting for libjansson macros Signed-off-by: Philipp Jungkamp --- .clang-format | 8 ++++++++ common/lib/log.cpp | 4 ++-- fpga/include/villas/fpga/card_parser.hpp | 2 +- fpga/lib/card.cpp | 2 +- fpga/lib/core.cpp | 10 +++++----- fpga/lib/ips/pcie.cpp | 2 +- fpga/lib/node.cpp | 2 +- fpga/lib/pcie_card.cpp | 2 +- fpga/lib/utils.cpp | 2 +- lib/api/universal.cpp | 4 ++-- lib/config.cpp | 4 ++-- lib/config_helper.cpp | 6 +++--- lib/formats/json.cpp | 6 +++--- lib/formats/json_edgeflex.cpp | 2 +- lib/formats/json_reserve.cpp | 2 +- lib/hook.cpp | 2 +- lib/hook_list.cpp | 2 +- lib/hooks/dp.cpp | 2 +- lib/hooks/ebm.cpp | 2 +- lib/hooks/lua.cpp | 8 ++++---- lib/hooks/power.cpp | 2 +- lib/kernel/tc_netem.cpp | 2 +- lib/mapping_list.cpp | 2 +- lib/node_list.cpp | 2 +- lib/nodes/can.cpp | 4 ++-- lib/nodes/comedi.cpp | 2 +- lib/nodes/exec.cpp | 4 ++-- lib/nodes/iec60870.cpp | 2 +- lib/nodes/iec61850.cpp | 2 +- lib/nodes/iec61850_goose.cpp | 12 ++++++------ lib/nodes/modbus.cpp | 2 +- lib/nodes/nanomsg.cpp | 2 +- lib/nodes/ngsi.cpp | 10 +++++----- lib/nodes/opal_orchestra.cpp | 2 +- lib/nodes/opendss.cpp | 4 ++-- lib/nodes/shmem.cpp | 2 +- lib/nodes/signal.cpp | 2 +- lib/nodes/signal_v1.cpp | 4 ++-- lib/nodes/stats.cpp | 2 +- lib/nodes/test_rtt.cpp | 6 +++--- lib/nodes/uldaq.cpp | 2 +- lib/nodes/webrtc.cpp | 2 +- lib/nodes/webrtc/signaling_message.cpp | 5 +++-- lib/nodes/websocket.cpp | 2 +- lib/nodes/zeromq.cpp | 2 +- lib/path.cpp | 2 +- lib/signal_list.cpp | 2 +- lib/super_node.cpp | 4 ++-- 48 files changed, 87 insertions(+), 78 deletions(-) diff --git a/.clang-format b/.clang-format index c3fc99edb..8d6cab8f7 100644 --- a/.clang-format +++ b/.clang-format @@ -22,3 +22,11 @@ IncludeCategories: Priority: 2 - Regex: '^".*"$' Priority: 4 + +# Add libjansson foreach macros +ForEachMacros: + - 'json_array_foreach' + - 'json_object_foreach' + - 'json_object_foreach_safe' + - 'json_object_keylen_foreach' + - 'json_object_keylen_foreach_safe' diff --git a/common/lib/log.cpp b/common/lib/log.cpp index b59f5c715..e9c653517 100644 --- a/common/lib/log.cpp +++ b/common/lib/log.cpp @@ -141,8 +141,8 @@ void Log::parse(json_t *json) { json_t *json_expression; // cppcheck-suppress unknownMacro - json_array_foreach(json_expressions, i, json_expression) - expressions.emplace_back(json_expression); + json_array_foreach (json_expressions, i, json_expression) + expressions.emplace_back(json_expression); } } diff --git a/fpga/include/villas/fpga/card_parser.hpp b/fpga/include/villas/fpga/card_parser.hpp index 20e8925ea..cef55c744 100644 --- a/fpga/include/villas/fpga/card_parser.hpp +++ b/fpga/include/villas/fpga/card_parser.hpp @@ -44,7 +44,7 @@ class CardParser { // Parse ignored ip names to list size_t index; json_t *value; - json_array_foreach(ignored_ips_array, index, value) { + json_array_foreach (ignored_ips_array, index, value) { ignored_ip_names.push_back(json_string_value(value)); } diff --git a/fpga/lib/card.cpp b/fpga/lib/card.cpp index 936e7e787..91d6e9c4d 100644 --- a/fpga/lib/card.cpp +++ b/fpga/lib/card.cpp @@ -179,7 +179,7 @@ void CardFactory::loadSwitch(std::shared_ptr card, json_t *json_paths) { size_t i; json_t *json_path; - json_array_foreach(json_paths, i, json_path) { + json_array_foreach (json_paths, i, json_path) { const char *from, *to; int reverse = 0; diff --git a/fpga/lib/core.cpp b/fpga/lib/core.cpp index 70f17c131..40678c260 100644 --- a/fpga/lib/core.cpp +++ b/fpga/lib/core.cpp @@ -44,7 +44,7 @@ std::list CoreFactory::parseIpIdentifier(json_t *json_ips) { const char *ipName; json_t *json_ip; - json_object_foreach(json_ips, ipName, json_ip) { + json_object_foreach (json_ips, ipName, json_ip) { const char *vlnv; json_error_t err; @@ -168,7 +168,7 @@ CoreFactory::configureIps(std::list orderedIps, json_t *json_ips, const char *irqName; json_t *json_irq; - json_object_foreach(json_irqs, irqName, json_irq) { + json_object_foreach (json_irqs, irqName, json_irq) { const char *irqEntry = json_string_value(json_irq); auto tokens = utils::tokenize(irqEntry, ":"); @@ -223,7 +223,7 @@ CoreFactory::configureIps(std::list orderedIps, json_t *json_ips, // Now find all slave address spaces this master can access const char *bus_name; json_t *json_bus; - json_object_foreach(json_memory_view, bus_name, json_bus) { + json_object_foreach (json_memory_view, bus_name, json_bus) { // This IP has a memory view => it is a bus master somewhere @@ -239,11 +239,11 @@ CoreFactory::configureIps(std::list orderedIps, json_t *json_ips, const char *instance_name; json_t *json_instance; - json_object_foreach(json_bus, instance_name, json_instance) { + json_object_foreach (json_bus, instance_name, json_instance) { const char *block_name; json_t *json_block; - json_object_foreach(json_instance, block_name, json_block) { + json_object_foreach (json_instance, block_name, json_block) { json_int_t base, high, size; json_error_t err; diff --git a/fpga/lib/ips/pcie.cpp b/fpga/lib/ips/pcie.cpp index 0d158f22b..c3e6b3067 100644 --- a/fpga/lib/ips/pcie.cpp +++ b/fpga/lib/ips/pcie.cpp @@ -111,7 +111,7 @@ void AxiPciExpressBridgeFactory::parse(Core &ip, json_t *cfg) { json_t *json_bar; const char *bar_name; - json_object_foreach(json_bars, bar_name, json_bar) { + json_object_foreach (json_bars, bar_name, json_bar) { unsigned int translation; json_error_t err; diff --git a/fpga/lib/node.cpp b/fpga/lib/node.cpp index e0785e23a..2ee211249 100644 --- a/fpga/lib/node.cpp +++ b/fpga/lib/node.cpp @@ -30,7 +30,7 @@ void NodeFactory::parse(Core &ip, json_t *cfg) { if (json_ports && json_is_array(json_ports)) { size_t index; json_t *json_port; - json_array_foreach(json_ports, index, json_port) { + json_array_foreach (json_ports, index, json_port) { if (not json_is_object(json_port)) throw ConfigError(json_port, "", "Port {} is not an object", index); diff --git a/fpga/lib/pcie_card.cpp b/fpga/lib/pcie_card.cpp index 54007a709..8da4a6eaf 100644 --- a/fpga/lib/pcie_card.cpp +++ b/fpga/lib/pcie_card.cpp @@ -70,7 +70,7 @@ PCIeCardFactory::make(json_t *json_card, std::string card_name, // Parse ignored ip names to list size_t index; json_t *value; - json_array_foreach(ignored_ips_array, index, value) { + json_array_foreach (ignored_ips_array, index, value) { card->ignored_ip_names.push_back(json_string_value(value)); } diff --git a/fpga/lib/utils.cpp b/fpga/lib/utils.cpp index 039325eb5..619f2e632 100644 --- a/fpga/lib/utils.cpp +++ b/fpga/lib/utils.cpp @@ -280,7 +280,7 @@ int fpga::createCards(json_t *config, const char *card_name; json_t *json_card; std::shared_ptr card; - json_object_foreach(fpgas, card_name, json_card) { + json_object_foreach (fpgas, card_name, json_card) { card = createCard(json_card, searchPath, vfioContainer, card_name); if (card != nullptr) { cards.push_back(card); diff --git a/lib/api/universal.cpp b/lib/api/universal.cpp index bae23be14..83d99e7c3 100644 --- a/lib/api/universal.cpp +++ b/lib/api/universal.cpp @@ -22,7 +22,7 @@ void ChannelList::parse(json_t *json, bool readable, bool writable) { size_t i; json_t *json_channel; - json_array_foreach(json, i, json_channel) { + json_array_foreach (json, i, json_channel) { auto channel = std::make_shared(); channel->parse(json_channel); @@ -73,7 +73,7 @@ void Channel::parse(json_t *json) { range_options.clear(); - json_array_foreach(json_range, i, json_option) { + json_array_foreach (json_range, i, json_option) { if (!json_is_string(json_option)) throw ConfigError(json, err, "node-config-node-api-signals-range", "Channel range options must be strings"); diff --git a/lib/config.cpp b/lib/config.cpp index 37aac542d..0bab007ef 100644 --- a/lib/config.cpp +++ b/lib/config.cpp @@ -287,7 +287,7 @@ json_t *Config::walkStrings(json_t *root, str_walk_fcn_t cb) { case JSON_OBJECT: new_root = json_object(); - json_object_foreach(root, key, val) { + json_object_foreach (root, key, val) { new_val = walkStrings(val, cb); json_object_set_new(new_root, key, new_val); @@ -298,7 +298,7 @@ json_t *Config::walkStrings(json_t *root, str_walk_fcn_t cb) { case JSON_ARRAY: new_root = json_array(); - json_array_foreach(root, index, val) { + json_array_foreach (root, index, val) { new_val = walkStrings(val, cb); json_array_append_new(new_root, new_val); diff --git a/lib/config_helper.cpp b/lib/config_helper.cpp index cc36c5dab..5488ffd8e 100644 --- a/lib/config_helper.cpp +++ b/lib/config_helper.cpp @@ -98,7 +98,7 @@ int villas::node::json_to_config(json_t *json, config_setting_t *parent) { const char *key; json_t *json_value; - json_object_foreach(json, key, json_value) { + json_object_foreach (json, key, json_value) { type = json_to_config_type(json_typeof(json_value)); cfg = config_setting_add(parent, key, type); @@ -113,7 +113,7 @@ int villas::node::json_to_config(json_t *json, config_setting_t *parent) { size_t i; json_t *json_value; - json_array_foreach(json, i, json_value) { + json_array_foreach (json, i, json_value) { type = json_to_config_type(json_typeof(json_value)); cfg = config_setting_add(parent, nullptr, type); @@ -305,7 +305,7 @@ int villas::node::json_object_extend(json_t *obj, json_t *merge) { if (!json_is_object(obj) || !json_is_object(merge)) return -1; - json_object_foreach(merge, key, merge_value) { + json_object_foreach (merge, key, merge_value) { obj_value = json_object_get(obj, key); if (obj_value && json_is_object(obj_value)) ret = json_object_extend(obj_value, merge_value); diff --git a/lib/formats/json.cpp b/lib/formats/json.cpp index 795c0c129..ff3c13577 100644 --- a/lib/formats/json.cpp +++ b/lib/formats/json.cpp @@ -66,7 +66,7 @@ int JsonFormat::unpackFlags(json_t *json_flags, struct Sample *smp) { size_t i; json_t *json_flag; - json_array_foreach(json_flags, i, json_flag) { + json_array_foreach (json_flags, i, json_flag) { char *flag; json_error_t err; if (auto ret = json_unpack_ex(json_flag, &err, 0, "s", &flag)) @@ -239,7 +239,7 @@ int JsonFormat::unpackSample(json_t *json_smp, struct Sample *smp) { smp->flags |= (int)SampleFlags::HAS_SEQUENCE; } - json_array_foreach(json_data, i, json_value) { + json_array_foreach (json_data, i, json_value) { if (i >= smp->capacity) break; @@ -276,7 +276,7 @@ int JsonFormat::unpackSamples(json_t *json_smps, struct Sample *const smps[], if (!json_is_array(json_smps)) return -1; - json_array_foreach(json_smps, i, json_smp) { + json_array_foreach (json_smps, i, json_smp) { if (i >= cnt) break; diff --git a/lib/formats/json_edgeflex.cpp b/lib/formats/json_edgeflex.cpp index 861a2314c..2da98b1a3 100644 --- a/lib/formats/json_edgeflex.cpp +++ b/lib/formats/json_edgeflex.cpp @@ -51,7 +51,7 @@ int JsonEdgeflexFormat::unpackSample(json_t *json_smp, struct Sample *smp) { if (json_typeof(json_smp) != JSON_OBJECT) return -1; - json_object_foreach(json_smp, key, json_value) { + json_object_foreach (json_smp, key, json_value) { if (!strcmp(key, "created")) json_created = json_incref(json_value); else { diff --git a/lib/formats/json_reserve.cpp b/lib/formats/json_reserve.cpp index 42e91c5ac..854f98f65 100644 --- a/lib/formats/json_reserve.cpp +++ b/lib/formats/json_reserve.cpp @@ -143,7 +143,7 @@ int JsonReserveFormat::unpackSample(json_t *json_smp, struct Sample *smp) { smp->flags = 0; smp->length = 0; - json_array_foreach(json_data, i, json_value) { + json_array_foreach (json_data, i, json_value) { const char *name, *unit = nullptr; double value; diff --git a/lib/hook.cpp b/lib/hook.cpp index feb61efa2..18a758c12 100644 --- a/lib/hook.cpp +++ b/lib/hook.cpp @@ -116,7 +116,7 @@ void MultiSignalHook::parse(json_t *json) { throw ConfigError(json_signals, "node-config-hook-signals", "Setting 'signals' must be a list of signal names"); - json_array_foreach(json_signals, i, json_signal) { + json_array_foreach (json_signals, i, json_signal) { if (!json_is_string(json_signal)) throw ConfigError(json_signal, "node-config-hook-signals", "Invalid value for setting 'signals'"); diff --git a/lib/hook_list.cpp b/lib/hook_list.cpp index c0f31bb1c..4fcdceca7 100644 --- a/lib/hook_list.cpp +++ b/lib/hook_list.cpp @@ -22,7 +22,7 @@ void HookList::parse(json_t *json, int mask, Path *o, Node *n) { size_t i; json_t *json_hook; - json_array_foreach(json, i, json_hook) { + json_array_foreach (json, i, json_hook) { int ret; const char *type; Hook::Ptr h; diff --git a/lib/hooks/dp.cpp b/lib/hooks/dp.cpp index 5038ae1f5..1146edfd8 100644 --- a/lib/hooks/dp.cpp +++ b/lib/hooks/dp.cpp @@ -179,7 +179,7 @@ class DPHook : public Hook { if (!fharmonics || !coeffs) throw MemoryAllocationError(); - json_array_foreach(json_harmonics, i, json_harmonic) { + json_array_foreach (json_harmonics, i, json_harmonic) { if (!json_is_integer(json_harmonic)) throw ConfigError(json_harmonic, "node-config-hook-dp-harmonics", "Setting 'harmonics' must be a list of integers"); diff --git a/lib/hooks/ebm.cpp b/lib/hooks/ebm.cpp index a9289c9ae..049f92b1e 100644 --- a/lib/hooks/ebm.cpp +++ b/lib/hooks/ebm.cpp @@ -42,7 +42,7 @@ class EBMHook : public Hook { if (!json_is_array(json_phases)) throw ConfigError(json_phases, "node-config-hook-ebm-phases"); - json_array_foreach(json_phases, i, json_phase) { + json_array_foreach (json_phases, i, json_phase) { int voltage, current; ret = json_unpack_ex(json_phase, &err, 0, "[ i, i ]", &voltage, ¤t); diff --git a/lib/hooks/lua.cpp b/lib/hooks/lua.cpp index 877d859e4..02f3c6698 100644 --- a/lib/hooks/lua.cpp +++ b/lib/hooks/lua.cpp @@ -251,7 +251,7 @@ static void lua_pushjson(lua_State *L, json_t *json) { switch (json_typeof(json)) { case JSON_OBJECT: lua_newtable(L); - json_object_foreach(json, key, json_value) { + json_object_foreach (json, key, json_value) { lua_pushjson(L, json_value); lua_setfield(L, -2, key); } @@ -259,7 +259,7 @@ static void lua_pushjson(lua_State *L, json_t *json) { case JSON_ARRAY: lua_newtable(L); - json_array_foreach(json, i, json_value) { + json_array_foreach (json, i, json_value) { lua_pushjson(L, json_value); lua_rawseti(L, -2, i); } @@ -359,8 +359,8 @@ void LuaHook::parseExpressions(json_t *json_sigs) { "Setting 'signals' must be a list of dicts"); // cppcheck-suppress unknownMacro - json_array_foreach(json_sigs, i, json_sig) - expressions.emplace_back(L, json_sig); + json_array_foreach (json_sigs, i, json_sig) + expressions.emplace_back(L, json_sig); hasExpressions = true; } diff --git a/lib/hooks/power.cpp b/lib/hooks/power.cpp index 50e449a2b..33a567af3 100644 --- a/lib/hooks/power.cpp +++ b/lib/hooks/power.cpp @@ -225,7 +225,7 @@ class PowerHook : public MultiSignalHook { size_t i = 0; json_t *json_pairings_value; - json_array_foreach(json_pairings, i, json_pairings_value) { + json_array_foreach (json_pairings, i, json_pairings_value) { const char *voltageNameC = nullptr; const char *currentNameC = nullptr; diff --git a/lib/kernel/tc_netem.cpp b/lib/kernel/tc_netem.cpp index 1a539ee10..1884fb4da 100644 --- a/lib/kernel/tc_netem.cpp +++ b/lib/kernel/tc_netem.cpp @@ -66,7 +66,7 @@ static int set_delay_distribution(struct rtnl_qdisc *qdisc, json_t *json) { if (!data) throw MemoryAllocationError(); - json_array_foreach(json, idx, elm) { + json_array_foreach (json, idx, elm) { if (!json_is_integer(elm)) return -1; diff --git a/lib/mapping_list.cpp b/lib/mapping_list.cpp index 82a62cd35..db7cdaf4c 100644 --- a/lib/mapping_list.cpp +++ b/lib/mapping_list.cpp @@ -26,7 +26,7 @@ int MappingList::parse(json_t *json) { else return -1; - json_array_foreach(json_mapping, i, json_entry) { + json_array_foreach (json_mapping, i, json_entry) { auto me = std::make_shared(); if (!me) throw MemoryAllocationError(); diff --git a/lib/node_list.cpp b/lib/node_list.cpp index 0859cb788..a7aa3930d 100644 --- a/lib/node_list.cpp +++ b/lib/node_list.cpp @@ -50,7 +50,7 @@ int NodeList::parse(json_t *json, NodeList &all) { break; case JSON_ARRAY: - json_array_foreach(json, index, elm) { + json_array_foreach (json, index, elm) { if (!json_is_string(elm)) goto invalid; diff --git a/lib/nodes/can.cpp b/lib/nodes/can.cpp index 784691ccf..7191f36f5 100644 --- a/lib/nodes/can.cpp +++ b/lib/nodes/can.cpp @@ -135,13 +135,13 @@ int villas::node::can_parse(NodeCompat *n, json_t *json) { if (!c->out) throw MemoryAllocationError(); - json_array_foreach(json_in_signals, i, json_signal) { + json_array_foreach (json_in_signals, i, json_signal) { ret = can_parse_signal(json_signal, n->in.signals, c->in, i); if (ret) throw RuntimeError("at signal {}.", i); } - json_array_foreach(json_out_signals, i, json_signal) { + json_array_foreach (json_out_signals, i, json_signal) { ret = can_parse_signal(json_signal, n->out.signals, c->out, i); if (ret) throw RuntimeError("at signal {}.", i); diff --git a/lib/nodes/comedi.cpp b/lib/nodes/comedi.cpp index 5248b8334..4a8ebe1e0 100644 --- a/lib/nodes/comedi.cpp +++ b/lib/nodes/comedi.cpp @@ -65,7 +65,7 @@ static int comedi_parse_direction(struct comedi *c, struct comedi_direction *d, if (!d->chanspecs) throw MemoryAllocationError(); - json_array_foreach(json_chans, i, json_chan) { + json_array_foreach (json_chans, i, json_chan) { int num, range, aref; ret = json_unpack_ex(json_chan, &err, 0, "{ s: i, s: i, s: i }", "channel", &num, "range", &range, "aref", &aref); diff --git a/lib/nodes/exec.cpp b/lib/nodes/exec.cpp index 6fe0cbde8..908d10c96 100644 --- a/lib/nodes/exec.cpp +++ b/lib/nodes/exec.cpp @@ -73,7 +73,7 @@ int ExecNode::parse(json_t *json) { size_t i; json_t *json_arg; - json_array_foreach(json_exec, i, json_arg) { + json_array_foreach (json_exec, i, json_arg) { if (!json_is_string(json_arg)) throw ConfigError(json_arg, "node-config-node-exec-exec", "All arguments must be of string type"); @@ -90,7 +90,7 @@ int ExecNode::parse(json_t *json) { const char *key; json_t *json_value; - json_object_foreach(json_env, key, json_value) { + json_object_foreach (json_env, key, json_value) { if (!json_is_string(json_value)) throw ConfigError(json_value, "node-config-node-exec-environment", "Environment variables must be of string type"); diff --git a/lib/nodes/iec60870.cpp b/lib/nodes/iec60870.cpp index e28f1d952..55f62f180 100644 --- a/lib/nodes/iec60870.cpp +++ b/lib/nodes/iec60870.cpp @@ -744,7 +744,7 @@ int SlaveNode::parse(json_t *json) { size_t i; std::optional last_data = std::nullopt; - json_array_foreach(json_signals, i, json_signal) { + json_array_foreach (json_signals, i, json_signal) { auto signal = signals ? signals->getByIndex(i) : Signal::Ptr{}; auto asdu_data = ASDUData::parse(json_signal, last_data, duplicate_ioa_is_sequence); diff --git a/lib/nodes/iec61850.cpp b/lib/nodes/iec61850.cpp index 57938f9af..70989a29c 100644 --- a/lib/nodes/iec61850.cpp +++ b/lib/nodes/iec61850.cpp @@ -85,7 +85,7 @@ int villas::node::iec61850_parse_signals(json_t *json_signals, if (json_is_array(json_signals)) { json_t *json_signal; size_t i; - json_array_foreach(json_signals, i, json_signal) { + json_array_foreach (json_signals, i, json_signal) { json_unpack_ex(json_signal, &err, 0, "{ s?: s }", "iec_type", &iec_type); // Try to deduct the IEC 61850 data type from VILLAS signal format diff --git a/lib/nodes/iec61850_goose.cpp b/lib/nodes/iec61850_goose.cpp index 45003a1c3..9c99c2a57 100644 --- a/lib/nodes/iec61850_goose.cpp +++ b/lib/nodes/iec61850_goose.cpp @@ -645,7 +645,7 @@ int GooseNode::parse(json_t *json) { json_t *json_key; assert(json_is_array(json_keys)); keys.reserve(json_array_size(json_keys)); - json_array_foreach(json_keys, index, json_key) { + json_array_foreach (json_keys, index, json_key) { assert(json_is_object(json_key)); parseSessionKey(json_key); } @@ -694,7 +694,7 @@ void GooseNode::parseInput(json_t *json) { json_t *json_multicast_group; assert(json_is_array(json_multicast_groups)); input.multicast_groups.reserve(json_array_size(json_multicast_groups)); - json_array_foreach(json_multicast_groups, index, json_multicast_group) { + json_array_foreach (json_multicast_groups, index, json_multicast_group) { assert(json_is_string(json_multicast_group)); input.multicast_groups.emplace_back( json_string_value(json_multicast_group)); @@ -830,7 +830,7 @@ void GooseNode::parseSubscribers( if (!json_is_object(json)) throw RuntimeError("subscribers is not an object"); - json_object_foreach(json, key, json_subscriber) { + json_object_foreach (json, key, json_subscriber) { SubscriberConfig sc; parseSubscriber(json_subscriber, sc); @@ -848,7 +848,7 @@ void GooseNode::parseInputSignals( mappings.clear(); - json_array_foreach(json, index, value) { + json_array_foreach (json, index, value) { char *mapping_subscriber; unsigned int mapping_index; char *mapping_type_name; @@ -941,7 +941,7 @@ void GooseNode::parsePublisherData(json_t *json, if (!json_is_array(json)) throw RuntimeError("publisher data is not an array"); - json_array_foreach(json, index, json_signal_or_value) { + json_array_foreach (json, index, json_signal_or_value) { char const *mms_type = nullptr; char const *signal_str = nullptr; json_t *json_value = nullptr; @@ -1034,7 +1034,7 @@ void GooseNode::parsePublishers(json_t *json, std::vector &ctx) { int index; json_t *json_publisher; - json_array_foreach(json, index, json_publisher) { + json_array_foreach (json, index, json_publisher) { PublisherConfig pc; parsePublisher(json_publisher, pc); diff --git a/lib/nodes/modbus.cpp b/lib/nodes/modbus.cpp index 90ee4a5a5..a31ca27c5 100644 --- a/lib/nodes/modbus.cpp +++ b/lib/nodes/modbus.cpp @@ -808,7 +808,7 @@ unsigned int ModbusNode::parseMappings(std::vector &mappings, json_t *signal_json; auto signals = getInputSignals(false); - json_array_foreach(json, i, signal_json) { + json_array_foreach (json, i, signal_json) { auto signal = signals->getByIndex(i); mappings.push_back(RegisterMappingSingle::parse(i, signal, signal_json)); diff --git a/lib/nodes/nanomsg.cpp b/lib/nodes/nanomsg.cpp index 15ad6076a..95e4dacab 100644 --- a/lib/nodes/nanomsg.cpp +++ b/lib/nodes/nanomsg.cpp @@ -59,7 +59,7 @@ static int nanomsg_parse_endpoints(struct List *l, json_t *json) { switch (json_typeof(json)) { case JSON_ARRAY: - json_array_foreach(json, i, json_val) { + json_array_foreach (json, i, json_val) { ep = json_string_value(json_val); if (!ep) return -1; diff --git a/lib/nodes/ngsi.cpp b/lib/nodes/ngsi.cpp index 833f9e12c..e80f0091e 100644 --- a/lib/nodes/ngsi.cpp +++ b/lib/nodes/ngsi.cpp @@ -149,8 +149,8 @@ class NgsiAttribute { json_t *json_metadata; // cppcheck-suppress unknownMacro - json_array_foreach(json_metadatas, j, json_metadata) - metadata.emplace_back(json_metadata); + json_array_foreach (json_metadatas, j, json_metadata) + metadata.emplace_back(json_metadata); } // Metadata: index(integer)=j @@ -264,7 +264,7 @@ static int ngsi_parse_entity(NodeCompat *n, json_t *json_entity, if (strcmp(id, i->entity_id) || strcmp(type, i->entity_type)) return -2; - json_array_foreach(json_attrs, l, json_attr) { + json_array_foreach (json_attrs, l, json_attr) { NgsiAttribute *attr; json_error_t err; json_t *json_metadata, *json_value; @@ -299,7 +299,7 @@ static int ngsi_parse_entity(NodeCompat *n, json_t *json_entity, return -6; size_t k; - json_array_foreach(json_value, k, json_tuple) { + json_array_foreach (json_value, k, json_tuple) { struct Sample *smp = smps[k]; // Check sample format @@ -379,7 +379,7 @@ static int ngsi_parse_signals(json_t *json_signals, struct List *ngsi_signals, if (!json_is_array(json_signals)) return -1; - json_array_foreach(json_signals, j, json_signal) { + json_array_foreach (json_signals, j, json_signal) { auto s = node_signals->getByIndex(j); auto *a = new NgsiAttribute(json_signal, j, s); if (!a) diff --git a/lib/nodes/opal_orchestra.cpp b/lib/nodes/opal_orchestra.cpp index cba9a456e..5d86388de 100644 --- a/lib/nodes/opal_orchestra.cpp +++ b/lib/nodes/opal_orchestra.cpp @@ -363,7 +363,7 @@ class OpalOrchestraNode : public Node { json_t *json_signal; json_error_t err; - json_array_foreach(json, i, json_signal) { + json_array_foreach (json, i, json_signal) { auto signal = signals->getByIndex(i); const char *nme = nullptr; diff --git a/lib/nodes/opendss.cpp b/lib/nodes/opendss.cpp index b9fcb107e..4dcffe5f9 100644 --- a/lib/nodes/opendss.cpp +++ b/lib/nodes/opendss.cpp @@ -52,7 +52,7 @@ void OpenDSS::parseData(json_t *json, bool in) { json_t *json_data; json_error_t err; - json_array_foreach(json, i, json_data) { + json_array_foreach (json, i, json_data) { if (in) { const char *name; const char *type; @@ -82,7 +82,7 @@ void OpenDSS::parseData(json_t *json, bool in) { size_t n; json_t *json_mode; - json_array_foreach(a_mode, n, json_mode) { + json_array_foreach (a_mode, n, json_mode) { const char *mode = json_string_value(json_mode); // Assign mode according to the OpenDSS function mode. switch (ele.type) { diff --git a/lib/nodes/shmem.cpp b/lib/nodes/shmem.cpp index c502ddb02..e3b818a3d 100644 --- a/lib/nodes/shmem.cpp +++ b/lib/nodes/shmem.cpp @@ -72,7 +72,7 @@ int villas::node::shmem_parse(NodeCompat *n, json_t *json) { size_t i; json_t *json_val; - json_array_foreach(json_exec, i, json_val) { + json_array_foreach (json_exec, i, json_val) { val = json_string_value(json_val); if (!val) throw SystemError("Setting 'exec' must be an array of strings"); diff --git a/lib/nodes/signal.cpp b/lib/nodes/signal.cpp index d5ce3fb24..11f9e4391 100644 --- a/lib/nodes/signal.cpp +++ b/lib/nodes/signal.cpp @@ -219,7 +219,7 @@ int SignalNode::parse(json_t *json) { signals.clear(); unsigned j = 0; - json_array_foreach(json_signals, i, json_signal) { + json_array_foreach (json_signals, i, json_signal) { auto sig = SignalNodeSignal(json_signal); if (sig.type == SignalNodeSignal::Type::MIXED) diff --git a/lib/nodes/signal_v1.cpp b/lib/nodes/signal_v1.cpp index 728f80ce4..0d9b993c2 100644 --- a/lib/nodes/signal_v1.cpp +++ b/lib/nodes/signal_v1.cpp @@ -208,7 +208,7 @@ int villas::node::signal_node_parse(NodeCompat *n, json_t *json) { throw ConfigError(json_type, "node-config-node-signal", "Length of values must match"); - json_array_foreach(json_type, i, json_value) { + json_array_foreach (json_type, i, json_value) { type_str = json_string_value(json_value); if (!type_str) throw ConfigError(json_value, "node-config-node-signal", @@ -249,7 +249,7 @@ int villas::node::signal_node_parse(NodeCompat *n, json_t *json) { size_t i; json_t *json_value; - json_array_foreach(a.json, i, json_value) { + json_array_foreach (a.json, i, json_value) { if (!json_is_number(json_value)) throw ConfigError( json_value, "node-config-node-signal", diff --git a/lib/nodes/stats.cpp b/lib/nodes/stats.cpp index 2aa01983a..a5a60a8aa 100644 --- a/lib/nodes/stats.cpp +++ b/lib/nodes/stats.cpp @@ -180,7 +180,7 @@ int villas::node::stats_node_parse(NodeCompat *n, json_t *json) { throw ConfigError(json, "node-config-node-stats-in-signals", "Setting 'in.signals' must be an array"); - json_array_foreach(json_signals, i, json_signal) { + json_array_foreach (json_signals, i, json_signal) { auto *stats_sig = new struct stats_node_signal; if (!stats_sig) throw MemoryAllocationError(); diff --git a/lib/nodes/test_rtt.cpp b/lib/nodes/test_rtt.cpp index 2059a61f9..6cb95ef28 100644 --- a/lib/nodes/test_rtt.cpp +++ b/lib/nodes/test_rtt.cpp @@ -203,7 +203,7 @@ int TestRTT::parse(json_t *json) { "The 'cases' setting must be an array."); int id = 0; - json_array_foreach(json_cases, i, json_case) { + json_array_foreach (json_cases, i, json_case) { const char *mode_str = nullptr; int count = count_default; // in no of samples @@ -242,7 +242,7 @@ int TestRTT::parse(json_t *json) { if (json_is_array(json_rates)) { size_t j; - json_array_foreach(json_rates, j, json_val) { + json_array_foreach (json_rates, j, json_val) { if (!json_is_number(json_val)) throw ConfigError( json_val, "node-config-node-test-rtt-rates", @@ -255,7 +255,7 @@ int TestRTT::parse(json_t *json) { if (json_is_array(json_values)) { size_t j; - json_array_foreach(json_values, j, json_val) { + json_array_foreach (json_values, j, json_val) { if (!json_is_integer(json_val)) throw ConfigError( json_val, "node-config-node-test-rtt-values", diff --git a/lib/nodes/uldaq.cpp b/lib/nodes/uldaq.cpp index 8a9c6189b..d82ca79dd 100644 --- a/lib/nodes/uldaq.cpp +++ b/lib/nodes/uldaq.cpp @@ -311,7 +311,7 @@ int villas::node::uldaq_parse(NodeCompat *n, json_t *json) { if (!u->in.queues) throw MemoryAllocationError(); - json_array_foreach(json_signals, i, json_signal) { + json_array_foreach (json_signals, i, json_signal) { const char *range_str = nullptr, *input_mode_str = nullptr; int channel = -1, input_mode, range; diff --git a/lib/nodes/webrtc.cpp b/lib/nodes/webrtc.cpp index 3fe4a2f82..1ae565473 100644 --- a/lib/nodes/webrtc.cpp +++ b/lib/nodes/webrtc.cpp @@ -100,7 +100,7 @@ int WebRTCNode::parse(json_t *json) { size_t i; json_t *json_server; - json_array_foreach(json_servers, i, json_server) { + json_array_foreach (json_servers, i, json_server) { if (!json_is_string(json_server)) throw ConfigError(json_server, "node-config-node-webrtc-ice-server", "ICE servers must be provided as STUN/TURN url."); diff --git a/lib/nodes/webrtc/signaling_message.cpp b/lib/nodes/webrtc/signaling_message.cpp index 71aaac5cf..2a3bf119a 100644 --- a/lib/nodes/webrtc/signaling_message.cpp +++ b/lib/nodes/webrtc/signaling_message.cpp @@ -62,7 +62,7 @@ RelayMessage::RelayMessage(json_t *json) { char *expires; json_t *json_server; size_t i; - json_array_foreach(json, i, json_server) { + json_array_foreach (json, i, json_server) { ret = json_unpack(json_server, "{ s: s, s: s, s: s, s: s, s: s }", "url", &url, "user", &user, "pass", &pass, "realm", &realm, "expires", &expires); @@ -106,7 +106,8 @@ ControlMessage::ControlMessage(json_t *j) { json_t *json_peer; size_t i; // cppcheck-suppress unknownMacro - json_array_foreach(json_peers, i, json_peer) peers.emplace_back(json_peer); + json_array_foreach (json_peers, i, json_peer) + peers.emplace_back(json_peer); } json_t *SignalingMessage::toJson() const { diff --git a/lib/nodes/websocket.cpp b/lib/nodes/websocket.cpp index 82a833a51..aa0f21d8f 100644 --- a/lib/nodes/websocket.cpp +++ b/lib/nodes/websocket.cpp @@ -570,7 +570,7 @@ int villas::node::websocket_parse(NodeCompat *n, json_t *json) { "node-config-node-websocket-destinations", "The 'destinations' setting must be an array of URLs"); - json_array_foreach(json_dests, i, json_dest) { + json_array_foreach (json_dests, i, json_dest) { const char *uri, *prot, *ads, *path; uri = json_string_value(json_dest); diff --git a/lib/nodes/zeromq.cpp b/lib/nodes/zeromq.cpp index a1225f112..d0009cb45 100644 --- a/lib/nodes/zeromq.cpp +++ b/lib/nodes/zeromq.cpp @@ -110,7 +110,7 @@ static int zeromq_parse_endpoints(json_t *json_ep, struct List *epl) { switch (json_typeof(json_ep)) { case JSON_ARRAY: - json_array_foreach(json_ep, i, json_val) { + json_array_foreach (json_ep, i, json_val) { ep = json_string_value(json_val); if (!ep) throw ConfigError(json_val, "node-config-node-publish", diff --git a/lib/path.cpp b/lib/path.cpp index a72b99737..c15234f6d 100644 --- a/lib/path.cpp +++ b/lib/path.cpp @@ -418,7 +418,7 @@ void Path::parseMask(json_t *json_mask, NodeList &nodes) { throw ConfigError(json_mask, "node-config-path-mask", "The 'mask' setting must be a list of node names"); - json_array_foreach(json_mask, i, json_entry) { + json_array_foreach (json_mask, i, json_entry) { const char *name; Node *node; diff --git a/lib/signal_list.cpp b/lib/signal_list.cpp index dd1359973..a549a767f 100644 --- a/lib/signal_list.cpp +++ b/lib/signal_list.cpp @@ -25,7 +25,7 @@ int SignalList::parse(json_t *json) { size_t i; json_t *json_signal; - json_array_foreach(json, i, json_signal) { + json_array_foreach (json, i, json_signal) { auto sig = std::make_shared(); if (!sig) throw MemoryAllocationError(); diff --git a/lib/super_node.cpp b/lib/super_node.cpp index 4f374dacf..110d194c3 100644 --- a/lib/super_node.cpp +++ b/lib/super_node.cpp @@ -123,7 +123,7 @@ void SuperNode::parse(json_t *root) { const char *node_name; json_t *json_node; - json_object_foreach(json_nodes, node_name, json_node) { + json_object_foreach (json_nodes, node_name, json_node) { uuid_t node_uuid; const char *node_type; const char *node_uuid_str = nullptr; @@ -172,7 +172,7 @@ void SuperNode::parse(json_t *root) { size_t i; json_t *json_path; - json_array_foreach(json_paths, i, json_path) { + json_array_foreach (json_paths, i, json_path) { parse: auto *p = new Path(); if (!p)