3 # Scan a file of route-type definitions (see eg route_types.txt) and
4 # generate a corresponding header file with:
6 # - enum of Zserv route-types
7 # - redistribute strings for the various Quagga daemons
9 # See route_types.txt for the format.
22 redist_def_fmt =
"#define QUAGGA_REDIST_STR_%s \\\n";
23 ## DEFUN/vty route-type argument
24 redist_str_fmt =
"\"(%s)\"\n";
25 redist_help_def_fmt =
"#define QUAGGA_REDIST_HELP_STR_%s";
26 redist_help_str_fmt =
" \\\n \"%s\\n\"";
29 header =
"/* Auto-generated from route_types.txt by " ARGV[0] ". */\n";
30 header = header
"/* Do not edit! */\n";
31 header = header
"\n#ifndef _QUAGGA_ROUTE_TYPES_H\n";
32 header = header
"#define _QUAGGA_ROUTE_TYPES_H\n";
33 footer =
"#endif /* _QUAGGA_ROUTE_TYPES_H */\n";
34 printf ("%s\n", header
);
42 # get rid of the commas, leading/trailling whitespace and
45 for (i =
1; i
<=
NF; i
++) {
47 $i = gensub
(/^
[[:blank
:]]*(.
*)[,]*.
*/, "\\1", "g",$i
);
48 $i = gensub
(/^
["](.*)["]$
/, "\\1", "g", $i
);
54 # type cname daemon C 4 6 short help
59 print "error: attempt to redefine", $
1;
64 typesbynum
[tcount
] = $
1;
65 types
[$
1,"num"] = tcount
++;
66 types
[$
1,"cname"] = $
2;
67 types
[$
1,"daemon"] = $
3;
69 types
[$
1,"4"] = strtonum
($
5);
70 types
[$
1,"6"] = strtonum
($
6);
71 types
[$
1,"shelp"] = $
7;
73 #print "num :", types[$1,"num"]
74 #print "cname :", types[$1,"cname"]
75 #print "daemon:", types[$1,"daemon"];
76 #print "char :", types[$1,"C"];
79 # 2 field: type "long description"
83 if (!
(($
1 SUBSEP
"num") in types
)) {
84 print "error: type", $
1, "must be defined before help str";
89 types
[$
1,"lhelp"] = $
2;
99 #for (i = 0; i < tcount; i++) {
100 # type = typesbynum[i];
101 # if (type != "" && types[type,"num"] == i)
102 # printf (" %s,\n", type);
104 #printf (" ZEBRA_ROUTE_MAX,\n};\n\n");
106 # the redistribute defines
107 for (i =
0; i
< tcount
; i
++) {
108 type = typesbynum
[i
];
110 # must be a type, and must cross-check against recorded type
111 if (type ==
"" || types
[type
,"num"] != i
)
114 # ignore route types that can't be redistributed
115 if (!
(types
[type
,"4"] || types
[type
,"6"]))
118 # must have a daemon name
119 if (!
((type SUBSEP
"daemon") in types
))
121 if (!
(daemon = types
[type
,"daemon"]))
124 # might have done this daemon already?
125 if (daemon in seen_daemons
)
128 cname = types
[type
,"cname"];
133 # add it to the others
134 for (j =
0; j
< tcount
; j
++) {
139 type2 = typesbynum
[j
];
141 # type2 must be valid, and self-check.
142 if (type2 ==
"" || types
[type2
,"num"] != j
)
145 # ignore different route types for the same daemon
146 # (eg system/kernel/connected)
147 if (types
[type2
,"daemon"] == daemon
)
150 if ((types
[type2
,"4"] && types
[type
,"4"]) \
151 || (types
[type2
,"6"] && types
[type
,"6"])) {
154 rstr = types
[type2
,"cname"];
156 rstr = rstr
"|" types
[type2
,"cname"];
158 if ((type2 SUBSEP
"lhelp") in types
)
159 hstr2 = types
[type2
,"lhelp"];
160 else if ((type2 SUBSEP
"shelp") in types
)
161 hstr2 = types
[type2
,"shelp"];
163 hstr2 = types
[type2
,"cname"];
165 hstr = hstr
sprintf(redist_help_str_fmt
, hstr2
);
169 # dont double-process daemons.
170 seen_daemons
[daemon
] =
1;
172 printf("/* %s */\n", daemon
);
173 printf(redist_def_fmt
, toupper(daemon
));
174 printf(redist_str_fmt
, rstr
);
175 printf(redist_help_def_fmt
, toupper(daemon
));
180 #printf("#define QUAGGA_REDIST_STR_ALL %s\n",all);
182 # for (i = 0; i < lcount; i++) {
183 # if (mlists[i] != "")
184 # printf (mlistformat "\n", mlists[i]);