Libecoli  0.11.3
Extensible COmmand LIne library
gen-node-schema.c
1 /* SPDX-License-Identifier: BSD-3-Clause
2  * Copyright 2025, Olivier MATZ <zer0@droids-corp.org>
3  */
4 
5 #include <err.h>
6 #include <stdio.h>
7 #include <stdlib.h>
8 #include <string.h>
9 
10 #include <ecoli.h>
11 
12 /* Map node type names to doxygen group names when they differ. */
13 static const char *type_to_group(const char *name)
14 {
15  if (strcmp(name, "uint") == 0)
16  return "int";
17  return name;
18 }
19 
20 static void dump_schema(FILE *f, const struct ec_node_type *type)
21 {
22  fprintf(f, "@addtogroup ecoli_node_%s\n", type_to_group(type->name));
23  fprintf(f, "@{\n\n");
24  fprintf(f, "<b>Configuration Schema</b>\n\n");
25 
26  if (type->schema == NULL) {
27  fprintf(f, "No configuration schema.\n");
28  } else {
29  fprintf(f, "```c\n");
30  ec_config_schema_dump(f, type->schema, type->name);
31  fprintf(f, "```\n");
32  }
33 
34  fprintf(f, "\n@}\n");
35 }
36 
37 int main(int argc, char **argv)
38 {
39  struct ec_node_type *type;
40  const char *dir, *stamp;
41  char fname[PATH_MAX];
42  FILE *f;
43 
44  if (argc != 3)
45  errx(EXIT_FAILURE, "invalid arguments. usage: %s DIR STAMP_FILE", argv[0]);
46 
47  dir = argv[1];
48  stamp = argv[2];
49 
50  TAILQ_FOREACH (type, &node_type_list, next) {
51  snprintf(fname, sizeof(fname), "%s/node-%s-schema.md", dir, type->name);
52  printf("generating %s ...\n", fname);
53  f = fopen(fname, "w");
54  if (f == NULL)
55  errx(EXIT_FAILURE, "failed to create file: %s", fname);
56  dump_schema(f, type);
57  fclose(f);
58  }
59 
60  f = fopen(stamp, "w");
61  if (f == NULL)
62  errx(EXIT_FAILURE, "failed to created stamp file: %s", stamp);
63  fclose(f);
64 
65  return 0;
66 }
void ec_config_schema_dump(FILE *out, const struct ec_config_schema *schema, const char *name)
struct ec_node_type_list node_type_list