]> git.proxmox.com Git - mirror_frr.git/blob - tools/gen_yang_deviations.c
*: auto-convert to SPDX License IDs
[mirror_frr.git] / tools / gen_yang_deviations.c
1 // SPDX-License-Identifier: GPL-2.0-or-later
2 /*
3 * Copyright (C) 2018 NetDEF, Inc.
4 * Renato Westphal
5 */
6
7 #define REALLY_NEED_PLAIN_GETOPT 1
8
9 #include <zebra.h>
10
11 #include <unistd.h>
12
13 #include "yang.h"
14 #include "northbound.h"
15
16 static void __attribute__((noreturn)) usage(int status)
17 {
18 fprintf(stderr, "usage: gen_yang_deviations [-h] MODULE\n");
19 exit(status);
20 }
21
22 static int generate_yang_deviation(const struct lysc_node *snode, void *arg)
23 {
24 char xpath[XPATH_MAXLEN];
25
26 yang_snode_get_path(snode, YANG_PATH_SCHEMA, xpath, sizeof(xpath));
27
28 printf(" deviation \"%s\" {\n", xpath);
29 printf(" deviate not-supported;\n");
30 printf(" }\n\n");
31
32 return YANG_ITER_CONTINUE;
33 }
34
35 int main(int argc, char *argv[])
36 {
37 struct yang_module *module;
38 int opt;
39
40 while ((opt = getopt(argc, argv, "h")) != -1) {
41 switch (opt) {
42 case 'h':
43 usage(EXIT_SUCCESS);
44 /* NOTREACHED */
45 default:
46 usage(EXIT_FAILURE);
47 /* NOTREACHED */
48 }
49 }
50 argc -= optind;
51 argv += optind;
52 if (argc != 1)
53 usage(EXIT_FAILURE);
54
55 yang_init(false, false);
56
57 /* Load YANG module. */
58 module = yang_module_load(argv[0]);
59
60 /* Generate deviations. */
61 yang_snodes_iterate(module->info, generate_yang_deviation, 0, NULL);
62
63 /* Cleanup and exit. */
64 yang_terminate();
65
66 return 0;
67 }