Switch from LOOKUP() to lookup() for rtm_type (see bug #401 for details).
[jleu-quagga.git] / lib / route_types.awk
blobeb3d382a99e792e5c8c358f7222c7148681afa33
1 # $Id$
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.
13 BEGIN {
14 FS="[,]";
16 # globals
17 exitret = 0;
18 tcount = 0;
20 # formats for output
21 ## the define 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\"";
28 # header
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);
37 # Chomp comment lines
38 ($0 ~ /^#/) {
39 next;
42 # get rid of the commas, leading/trailling whitespace and
43 # quotes
45 for (i = 1; i <= NF; i++) {
46 #print "before:" $i;
47 $i = gensub(/^[[:blank:]]*(.*)[,]*.*/, "\\1", "g",$i);
48 $i = gensub(/^["](.*)["]$/, "\\1", "g", $i);
49 #print "after :" $i;
53 # 7 field format:
54 # type cname daemon C 4 6 short help
55 (NF >= 7) {
56 #print "7", $1, $0;
58 if ($1 in types) {
59 print "error: attempt to redefine", $1;
60 exitret = 1;
61 exit exitret;
64 typesbynum[tcount] = $1;
65 types[$1,"num"] = tcount++;
66 types[$1,"cname"] = $2;
67 types[$1,"daemon"] = $3;
68 types[$1,"C"] = $4;
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"
80 (NF == 2) {
81 #print "2", $1, $2;
83 if (!(($1 SUBSEP "num") in types)) {
84 print "error: type", $1, "must be defined before help str";
85 exitret = 2;
86 exit exitret;
89 types[$1,"lhelp"] = $2;
92 END {
93 if (exitret)
94 exit exitret;
96 # The enums
97 # not yet...
98 #printf("enum\n{\n");
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)
112 continue;
114 # ignore route types that can't be redistributed
115 if (!(types[type,"4"] || types[type,"6"]))
116 continue;
118 # must have a daemon name
119 if (!((type SUBSEP "daemon") in types))
120 continue;
121 if (!(daemon = types[type,"daemon"]))
122 continue;
124 # might have done this daemon already?
125 if (daemon in seen_daemons)
126 continue;
128 cname = types[type,"cname"];
129 all = all "|" cname;
130 rstr = "";
131 hstr = "";
133 # add it to the others
134 for (j = 0; j < tcount; j++) {
135 # ignore self
136 if (i == j)
137 continue;
139 type2 = typesbynum[j];
141 # type2 must be valid, and self-check.
142 if (type2 == "" || types[type2,"num"] != j)
143 continue;
145 # ignore different route types for the same daemon
146 # (eg system/kernel/connected)
147 if (types[type2,"daemon"] == daemon)
148 continue;
150 if ((types[type2,"4"] && types[type,"4"]) \
151 || (types[type2,"6"] && types[type,"6"])) {
153 if (rstr == "")
154 rstr = types[type2,"cname"];
155 else
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"];
162 else
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));
176 printf("%s", hstr);
177 printf("\n\n");
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]);
186 printf (footer);