Annotation of embedaddon/quagga/lib/route_types.awk, revision 1.1.1.1
1.1 misho 1: # Scan a file of route-type definitions (see eg route_types.txt) and
2: # generate a corresponding header file with:
3: #
4: # - enum of Zserv route-types
5: # - redistribute strings for the various Quagga daemons
6: #
7: # See route_types.txt for the format.
8: #
9: #
10:
11: BEGIN {
12: FS="[,]";
13:
14: # globals
15: exitret = 0;
16: tcount = 0;
17:
18: # formats for output
19: ## the define format
20: redist_def_fmt = "#define QUAGGA_REDIST_STR_%s \\\n";
21: ## DEFUN/vty route-type argument
22: redist_str_fmt = "\"(%s)\"\n";
23: redist_help_def_fmt = "#define QUAGGA_REDIST_HELP_STR_%s";
24: redist_help_str_fmt = " \\\n \"%s\\n\"";
25:
26: # header
27: header = "/* Auto-generated from route_types.txt by " ARGV[0] ". */\n";
28: header = header "/* Do not edit! */\n";
29: header = header "\n#ifndef _QUAGGA_ROUTE_TYPES_H\n";
30: header = header "#define _QUAGGA_ROUTE_TYPES_H\n";
31: footer = "#endif /* _QUAGGA_ROUTE_TYPES_H */\n";
32: printf ("%s\n", header);
33: }
34:
35: # Chomp comment lines
36: ($0 ~ /^#/) {
37: next;
38: }
39:
40: # get rid of the commas, leading/trailling whitespace and
41: # quotes
42: {
43: for (i = 1; i <= NF; i++) {
44: #print "before:" $i;
45: $i = gensub(/^[[:blank:]]*(.*)[,]*.*/, "\\1", "g",$i);
46: $i = gensub(/^["](.*)["]$/, "\\1", "g", $i);
47: #print "after :" $i;
48: }
49: }
50:
51: # 7 field format:
52: # type cname daemon C 4 6 short help
53: (NF >= 7) {
54: #print "7", $1, $0;
55:
56: if ($1 in types) {
57: print "error: attempt to redefine", $1;
58: exitret = 1;
59: exit exitret;
60: }
61:
62: typesbynum[tcount] = $1;
63: types[$1,"num"] = tcount++;
64: types[$1,"cname"] = $2;
65: types[$1,"daemon"] = $3;
66: types[$1,"C"] = $4;
67: types[$1,"4"] = strtonum($5);
68: types[$1,"6"] = strtonum($6);
69: types[$1,"shelp"] = $7;
70:
71: #print "num :", types[$1,"num"]
72: #print "cname :", types[$1,"cname"]
73: #print "daemon:", types[$1,"daemon"];
74: #print "char :", types[$1,"C"];
75: };
76:
77: # 2 field: type "long description"
78: (NF == 2) {
79: #print "2", $1, $2;
80:
81: if (!(($1 SUBSEP "num") in types)) {
82: print "error: type", $1, "must be defined before help str";
83: exitret = 2;
84: exit exitret;
85: }
86:
87: types[$1,"lhelp"] = $2;
88: }
89:
90: END {
91: if (exitret)
92: exit exitret;
93:
94: # The enums
95: # not yet...
96: #printf("enum\n{\n");
97: #for (i = 0; i < tcount; i++) {
98: # type = typesbynum[i];
99: # if (type != "" && types[type,"num"] == i)
100: # printf (" %s,\n", type);
101: #}
102: #printf (" ZEBRA_ROUTE_MAX,\n};\n\n");
103:
104: # the redistribute defines
105: for (i = 0; i < tcount; i++) {
106: type = typesbynum[i];
107:
108: # must be a type, and must cross-check against recorded type
109: if (type == "" || types[type,"num"] != i)
110: continue;
111:
112: # ignore route types that can't be redistributed
113: if (!(types[type,"4"] || types[type,"6"]))
114: continue;
115:
116: # must have a daemon name
117: if (!((type SUBSEP "daemon") in types))
118: continue;
119: if (!(daemon = types[type,"daemon"]))
120: continue;
121:
122: # might have done this daemon already?
123: if (daemon in seen_daemons)
124: continue;
125:
126: cname = types[type,"cname"];
127: all = all "|" cname;
128: rstr = "";
129: hstr = "";
130:
131: # add it to the others
132: for (j = 0; j < tcount; j++) {
133: # ignore self
134: if (i == j)
135: continue;
136:
137: type2 = typesbynum[j];
138:
139: # type2 must be valid, and self-check.
140: if (type2 == "" || types[type2,"num"] != j)
141: continue;
142:
143: # ignore different route types for the same daemon
144: # (eg system/kernel/connected)
145: if (types[type2,"daemon"] == daemon)
146: continue;
147:
148: if ((types[type2,"4"] && types[type,"4"]) \
149: || (types[type2,"6"] && types[type,"6"])) {
150:
151: if (rstr == "")
152: rstr = types[type2,"cname"];
153: else
154: rstr = rstr "|" types[type2,"cname"];
155:
156: if ((type2 SUBSEP "lhelp") in types)
157: hstr2 = types[type2,"lhelp"];
158: else if ((type2 SUBSEP "shelp") in types)
159: hstr2 = types[type2,"shelp"];
160: else
161: hstr2 = types[type2,"cname"];
162:
163: hstr = hstr sprintf(redist_help_str_fmt, hstr2);
164: }
165: }
166:
167: # dont double-process daemons.
168: seen_daemons[daemon] = 1;
169:
170: printf("/* %s */\n", daemon);
171: printf(redist_def_fmt, toupper(daemon));
172: printf(redist_str_fmt, rstr);
173: printf(redist_help_def_fmt, toupper(daemon));
174: printf("%s", hstr);
175: printf("\n\n");
176: }
177:
178: #printf("#define QUAGGA_REDIST_STR_ALL %s\n",all);
179:
180: # for (i = 0; i < lcount; i++) {
181: # if (mlists[i] != "")
182: # printf (mlistformat "\n", mlists[i]);
183: # }
184: printf (footer);
185: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>