Return a string field from a node by property name. NULL-safe. */
| 2334 | |
| 2335 | /* Return a string field from a node by property name. NULL-safe. */ |
| 2336 | static const char *node_string_field(const cbm_node_t *n, const char *prop) { |
| 2337 | static const struct { |
| 2338 | const char *key; |
| 2339 | size_t offset; |
| 2340 | } fields[] = { |
| 2341 | {"name", offsetof(cbm_node_t, name)}, |
| 2342 | {"qualified_name", offsetof(cbm_node_t, qualified_name)}, |
| 2343 | /* Aliases: field-eval agents reach for the short names, and a miss |
| 2344 | * used to return a silent empty column costing a round-trip. */ |
| 2345 | {"qn", offsetof(cbm_node_t, qualified_name)}, |
| 2346 | {"label", offsetof(cbm_node_t, label)}, |
| 2347 | {"file_path", offsetof(cbm_node_t, file_path)}, |
| 2348 | {"file", offsetof(cbm_node_t, file_path)}, |
| 2349 | {"path", offsetof(cbm_node_t, file_path)}, |
| 2350 | }; |
| 2351 | for (size_t i = 0; i < sizeof(fields) / sizeof(fields[0]); i++) { |
| 2352 | if (strcmp(prop, fields[i].key) == 0) { |
| 2353 | const char *val = *(const char **)((const char *)n + fields[i].offset); |
| 2354 | return val ? val : ""; |
| 2355 | } |
| 2356 | } |
| 2357 | return NULL; |
| 2358 | } |
| 2359 | |
| 2360 | /* Get node property by name. |
| 2361 | * store may be NULL; only needed for virtual degree properties. */ |