forked from caomw/gopro-lib-node.gl
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathgen_specs.c
96 lines (85 loc) · 3.06 KB
/
gen_specs.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
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
/*
* Copyright 2016-2022 GoPro Inc.
*
* Licensed to the Apache Software Foundation (ASF) under one
* or more contributor license agreements. See the NOTICE file
* distributed with this work for additional information
* regarding copyright ownership. The ASF licenses this file
* to you under the Apache License, Version 2.0 (the
* "License"); you may not use this file except in compliance
* with the License. You may obtain a copy of the License at
*
* http://www.apache.org/licenses/LICENSE-2.0
*
* Unless required by applicable law or agreed to in writing,
* software distributed under the License is distributed on an
* "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
* KIND, either express or implied. See the License for the
* specific language governing permissions and limitations
* under the License.
*/
#include "hmap.h"
#include "memory.h"
#include "nodegl.h"
#include "internal.h"
#include "nodes_register.h"
#define CLASS_LIST(type_name, cls) extern const struct node_class cls;
NODE_MAP_TYPE2CLASS(CLASS_LIST)
extern const struct node_param ngli_base_node_params[];
extern const struct param_specs ngli_params_specs[];
static void print_node_params(const char *name, const struct node_param *p)
{
printf(" \"%s\": [\n", name);
if (p) {
while (p->key) {
printf(" [\"%s\", \"%s\", \"%s%s%s\"]%s\n", p->key, ngli_params_specs[p->type].name,
(p->flags & NGLI_PARAM_FLAG_ALLOW_LIVE_CHANGE) ? "L" : "", /* [L]ive */
(p->flags & NGLI_PARAM_FLAG_ALLOW_NODE) ? "N" : "", /* [N]ode */
(p->flags & NGLI_PARAM_FLAG_NON_NULL) ? "M" : "", /* [M]andatory */
(p + 1)->key ? "," : ""
);
p++;
}
}
printf(" ]");
}
#define CLASS_COMMALIST(type_name, cls) &cls,
int main(void)
{
printf("{\n");
print_node_params("_Node", ngli_base_node_params);
static const struct node_class *node_classes[] = {
NODE_MAP_TYPE2CLASS(CLASS_COMMALIST)
};
struct hmap *params_map = ngli_hmap_create();
if (!params_map)
return -1;
for (int i = 0; i < NGLI_ARRAY_NB(node_classes); i++) {
const struct node_class *c = node_classes[i];
const struct node_param *p = &c->params[0];
if (c->params_id) {
void *mapped_param = ngli_hmap_get(params_map, c->params_id);
char *pname = ngli_asprintf("_%s", c->params_id);
if (!pname) {
ngli_free(pname);
return -1;
}
if (mapped_param) {
ngli_assert(mapped_param == p);
} else {
printf(",\n");
print_node_params(pname, p);
ngli_hmap_set(params_map, c->params_id, (void *)p);
}
printf(",\n");
printf(" \"%s\": \"%s\"", c->name, pname);
ngli_free(pname);
} else {
printf(",\n");
print_node_params(c->name, p);
}
}
ngli_hmap_freep(¶ms_map);
printf("\n}\n");
return 0;
}