Annotation of embedaddon/quagga/lib/memtypes.awk, revision 1.1.1.1
1.1 misho 1: # $Id: memtypes.awk,v 1.4 2006/03/30 14:30:19 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: # struct memory_list's must be declared as:
8: # '\nstruct memory_list memory_list_<name>[] .....'
9: #
10: # Each MTYPE_ within the definition must the second token on the line,
11: # tokens being delineated by whitespace. It may only consist of the set of
12: # characters [[:upper:]_[:digit:]]. Eg:
13: #
14: # '\n { MTYPE_AWESOME_IPV8 , "Amazing new protocol, says genius" {}..boo'
15: #
16: # We try to ignore lines whose first token is /* or *, ie C comment lines.
17: # So the following should work fine:
18: #
19: # '/* This is the best memory_list ever!
20: # ' * It's got all my MTYPE's */
21: # '
22: # 'struct memory_list memory_list_my_amazing_mlist[] = =
23: # '{
24: # ' { MTYPE_DONGLE, "Dongle widget" }
25: # ' { MTYPE_FROB, "Frobulator" },
26: # '{ MTYPE_WIPPLE, "Wipple combombulator"}
27: # '}}}
28: #
29: # Even if it isn't quite a valid C declaration.
30: #
31:
32: BEGIN {
33: mlistregex = "memory_list_(.*)\\[\\]";
34: mtyperegex = "^(MTYPE_[[:upper:]_[:digit:]]+).*";
35: header = "/* Auto-generated from memtypes.c by " ARGV[0] ". */\n";
36: header = header "/* Do not edit! */\n";
37: header = header "\n#ifndef _QUAGGA_MEMTYPES_H\n";
38: header = header "#define _QUAGGA_MEMTYPES_H\n";
39: footer = "\n#endif /* _QUAGGA_MEMTYPES_H */\n\n";
40: mlistformat = "extern struct memory_list memory_list_%s[];";
41: printf ("%s\n", header);
42: }
43:
44: # catch lines beginning with 'struct memory list ' and try snag the
45: # memory_list name. Has to be 3rd field.
46: ($0 ~ /^struct memory_list /) && (NF >= 3) {
47: mlists[lcount++] = gensub(mlistregex, "\\1", "g",$3);
48: }
49:
50: # snag the MTYPE, it must self-standing and the second field,
51: # though we do manage to tolerate the , C seperator being appended
52: ($1 !~ /^\/?\*/) && ($2 ~ /^MTYPE_/) {
53: mtype[tcount++] = gensub(mtyperegex, "\\1", "g", $2);
54: }
55:
56: END {
57: printf("enum\n{\n MTYPE_TMP = 1,\n");
58: for (i = 0; i < tcount; i++) {
59: if (mtype[i] != "" && mtype[i] != "MTYPE_TMP")
60: printf (" %s,\n", mtype[i]);
61: }
62: printf (" MTYPE_MAX,\n};\n\n");
63: for (i = 0; i < lcount; i++) {
64: if (mlists[i] != "")
65: printf (mlistformat "\n", mlists[i]);
66: }
67: printf (footer);
68: }
FreeBSD-CVSweb <freebsd-cvsweb@FreeBSD.org>