summaryrefslogtreecommitdiff
path: root/lib/memtypes.awk
diff options
context:
space:
mode:
authorpaul <paul>2005-04-15 11:47:15 +0000
committerpaul <paul>2005-04-15 11:47:15 +0000
commit2fd2fd5d4c0e5a67f1b84abe18b54417237b20ab (patch)
tree106e9f02a377c796ce41f3033beea2404c6e0e58 /lib/memtypes.awk
parentd98b74b504554d851d1281017724984069340cad (diff)
2005-04-15 Paul Jakma <paul@dishone.st>
* memtypes.c: The new, unified location for memory type definitions. The memtype enum and declarations for memory_lists are built from this automatically and put into memtypes.h. * memtypes.awk: New script to generate memtypes.h from memtypes.c * memory.h: Finally, the enum can banished! * memory.c: Finally, the seperate mtype memory_list definitions can be banished! (log_memstats) Increase width of fields (show_memory_zebra_cmd) display zebra specific memory types. Increase width of fields. * Makefile.am: Add memtypes.{c,h}, add BUILT_SOURCES for memtypes.h Add a rule to build memtypes.h using memtypes.awk. Add memtypes.awk to EXTRA_DIST.
Diffstat (limited to 'lib/memtypes.awk')
-rw-r--r--lib/memtypes.awk40
1 files changed, 40 insertions, 0 deletions
diff --git a/lib/memtypes.awk b/lib/memtypes.awk
new file mode 100644
index 00000000..2da6547b
--- /dev/null
+++ b/lib/memtypes.awk
@@ -0,0 +1,40 @@
+# $Id: memtypes.awk,v 1.1 2005/04/15 11:47:15 paul Exp $
+#
+# Scan a file of memory definitions (see eg memtypes.c) and generate
+# a corresponding header file with an enum of the MTYPE's and declarations
+# for the struct memory_list arrays
+#
+
+BEGIN {
+ mlistregex = "memory_list_(.*)\\[\\]";
+ mtyperegex = "^.*(MTYPE_[A-Z_0-9]+).*$";
+ header = "/* Auto-generated from memtypes.c by " ARGV[0] ". */\n";
+ header = header "/* Do not edit! */\n";
+ header = header "\n#ifndef _QUAGGA_MEMTYPES_H\n";
+ header = header "#define _QUAGGA_MEMTYPES_H\n";
+ footer = "\n#endif /* _QUAGGA_MEMTYPES_H */\n\n";
+ mlistformat = "extern struct memory_list memory_list_%s[];";
+ printf ("%s\n", header);
+}
+
+($0 ~ /^struct memory_list /) && (NF >= 3) {
+ mlists[lcount++] = gensub(mlistregex,"\\1",g,$3);
+}
+
+($1 != "/*") && ($1 != "*") && ($2 ~ /MTYPE_/) {
+ mtype[tcount++] = gensub(mtyperegex,"\\1",1, $0);
+}
+
+END {
+ printf("enum\n{\n MTYPE_TMP = 1,\n");
+ for (i = 0; i < tcount; i++) {
+ if (mtype[i] != "" && mtype[i] != "MTYPE_TMP")
+ printf (" %s,\n", mtype[i]);
+ }
+ printf (" MTYPE_MAX,\n};\n\n");
+ for (i = 0; i < lcount; i++) {
+ if (mlists[i] != "")
+ printf (mlistformat "\n", mlists[i]);
+ }
+ printf (footer);
+}