]> git.proxmox.com Git - mirror_frr.git/blame - tools/gen_yang_deviations.c
Merge pull request #3362 from pacovn/Coverity_1475469_null_check
[mirror_frr.git] / tools / gen_yang_deviations.c
CommitLineData
1c2facd1
RW
1/*
2 * Copyright (C) 2018 NetDEF, Inc.
3 * Renato Westphal
4 *
5 * This program is free software; you can redistribute it and/or modify it
6 * under the terms of the GNU General Public License as published by the Free
7 * Software Foundation; either version 2 of the License, or (at your option)
8 * any later version.
9 *
10 * This program is distributed in the hope that it will be useful, but WITHOUT
11 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or
12 * FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for
13 * more details.
14 *
15 * You should have received a copy of the GNU General Public License along
16 * with this program; see the file COPYING; if not, write to the Free Software
17 * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
18 */
19
20#define REALLY_NEED_PLAIN_GETOPT 1
21
22#include <zebra.h>
23
24#include <unistd.h>
25
26#include "yang.h"
27#include "northbound.h"
28
29static void __attribute__((noreturn)) usage(int status)
30{
31 fprintf(stderr, "usage: gen_yang_deviations [-h] MODULE\n");
32 exit(status);
33}
34
35static void generate_yang_deviation(const struct lys_node *snode, void *arg1,
36 void *arg2)
37{
38 char xpath[XPATH_MAXLEN];
39
40 yang_snode_get_path(snode, YANG_PATH_SCHEMA, xpath, sizeof(xpath));
41
42 printf(" deviation \"%s\" {\n", xpath);
43 printf(" deviate not-supported;\n");
44 printf(" }\n\n");
45}
46
47int main(int argc, char *argv[])
48{
49 struct yang_module *module;
50 int opt;
51
52 while ((opt = getopt(argc, argv, "h")) != -1) {
53 switch (opt) {
54 case 'h':
55 usage(EXIT_SUCCESS);
56 /* NOTREACHED */
57 default:
58 usage(EXIT_FAILURE);
59 /* NOTREACHED */
60 }
61 }
62 argc -= optind;
63 argv += optind;
64 if (argc != 1)
65 usage(EXIT_FAILURE);
66
67 yang_init();
68
69 /* Load YANG module. */
70 module = yang_module_load(argv[0]);
71
72 /* Generate deviations. */
73 yang_module_snodes_iterate(module->info, generate_yang_deviation,
74 YANG_ITER_FILTER_IMPLICIT, NULL, NULL);
75
76 /* Cleanup and exit. */
77 yang_terminate();
78
79 return 0;
80}