blob: 2da6547bff5106a914ed8234e8be67579bcd898b [file] [log] [blame]
paul2fd2fd52005-04-15 11:47:15 +00001# $Id: memtypes.awk,v 1.1 2005/04/15 11:47:15 paul Exp $
2#
3# Scan a file of memory definitions (see eg memtypes.c) and generate
4# a corresponding header file with an enum of the MTYPE's and declarations
5# for the struct memory_list arrays
6#
7
8BEGIN {
9 mlistregex = "memory_list_(.*)\\[\\]";
10 mtyperegex = "^.*(MTYPE_[A-Z_0-9]+).*$";
11 header = "/* Auto-generated from memtypes.c by " ARGV[0] ". */\n";
12 header = header "/* Do not edit! */\n";
13 header = header "\n#ifndef _QUAGGA_MEMTYPES_H\n";
14 header = header "#define _QUAGGA_MEMTYPES_H\n";
15 footer = "\n#endif /* _QUAGGA_MEMTYPES_H */\n\n";
16 mlistformat = "extern struct memory_list memory_list_%s[];";
17 printf ("%s\n", header);
18}
19
20($0 ~ /^struct memory_list /) && (NF >= 3) {
21 mlists[lcount++] = gensub(mlistregex,"\\1",g,$3);
22}
23
24($1 != "/*") && ($1 != "*") && ($2 ~ /MTYPE_/) {
25 mtype[tcount++] = gensub(mtyperegex,"\\1",1, $0);
26}
27
28END {
29 printf("enum\n{\n MTYPE_TMP = 1,\n");
30 for (i = 0; i < tcount; i++) {
31 if (mtype[i] != "" && mtype[i] != "MTYPE_TMP")
32 printf (" %s,\n", mtype[i]);
33 }
34 printf (" MTYPE_MAX,\n};\n\n");
35 for (i = 0; i < lcount; i++) {
36 if (mlists[i] != "")
37 printf (mlistformat "\n", mlists[i]);
38 }
39 printf (footer);
40}