blob: bd13327db547f6b7dd3dbef7472efdafc4bc3748 [file] [log] [blame]
Paul Jakma010ebbb2014-09-16 11:53:49 +01001###
2# Copyright (C) Paul Jakma 2005
3#
4# This file is part of Quagga.
5#
6# Quagga is free software; you can redistribute it and/or modify it
7# under the terms of the GNU General Public License as published by the
8# Free Software Foundation; either version 2, or (at your option) any
9# later version.
10#
11# Quagga is distributed in the hope that it will be useful, but
12# WITHOUT ANY WARRANTY; without even the implied warranty of
13# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14# General Public License for more details.
15#
16# You should have received a copy of the GNU General Public License
17# along with Quagga; see the file COPYING. If not, write to the Free
18# Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA
19# 02111-1307, USA.
20###
paul2fd2fd52005-04-15 11:47:15 +000021#
22# Scan a file of memory definitions (see eg memtypes.c) and generate
23# a corresponding header file with an enum of the MTYPE's and declarations
24# for the struct memory_list arrays
25#
pauldc830cb2005-04-16 15:51:05 +000026# struct memory_list's must be declared as:
27# '\nstruct memory_list memory_list_<name>[] .....'
28#
29# Each MTYPE_ within the definition must the second token on the line,
30# tokens being delineated by whitespace. It may only consist of the set of
pauld5c92532005-05-23 12:33:58 +000031# characters [[:upper:]_[:digit:]]. Eg:
pauldc830cb2005-04-16 15:51:05 +000032#
33# '\n { MTYPE_AWESOME_IPV8 , "Amazing new protocol, says genius" {}..boo'
34#
35# We try to ignore lines whose first token is /* or *, ie C comment lines.
36# So the following should work fine:
37#
38# '/* This is the best memory_list ever!
39# ' * It's got all my MTYPE's */
40# '
41# 'struct memory_list memory_list_my_amazing_mlist[] = =
42# '{
43# ' { MTYPE_DONGLE, "Dongle widget" }
44# ' { MTYPE_FROB, "Frobulator" },
45# '{ MTYPE_WIPPLE, "Wipple combombulator"}
46# '}}}
47#
48# Even if it isn't quite a valid C declaration.
49#
paul2fd2fd52005-04-15 11:47:15 +000050
51BEGIN {
52 mlistregex = "memory_list_(.*)\\[\\]";
pauld5c92532005-05-23 12:33:58 +000053 mtyperegex = "^(MTYPE_[[:upper:]_[:digit:]]+).*";
paul2fd2fd52005-04-15 11:47:15 +000054 header = "/* Auto-generated from memtypes.c by " ARGV[0] ". */\n";
55 header = header "/* Do not edit! */\n";
56 header = header "\n#ifndef _QUAGGA_MEMTYPES_H\n";
57 header = header "#define _QUAGGA_MEMTYPES_H\n";
58 footer = "\n#endif /* _QUAGGA_MEMTYPES_H */\n\n";
59 mlistformat = "extern struct memory_list memory_list_%s[];";
60 printf ("%s\n", header);
61}
62
pauldc830cb2005-04-16 15:51:05 +000063# catch lines beginning with 'struct memory list ' and try snag the
64# memory_list name. Has to be 3rd field.
paul2fd2fd52005-04-15 11:47:15 +000065($0 ~ /^struct memory_list /) && (NF >= 3) {
Paul Jakmad4ce4f62006-03-30 14:30:19 +000066 mlists[lcount++] = gensub(mlistregex, "\\1", "g",$3);
paul2fd2fd52005-04-15 11:47:15 +000067}
68
pauldc830cb2005-04-16 15:51:05 +000069# snag the MTYPE, it must self-standing and the second field,
70# though we do manage to tolerate the , C seperator being appended
71($1 !~ /^\/?\*/) && ($2 ~ /^MTYPE_/) {
Paul Jakmad4ce4f62006-03-30 14:30:19 +000072 mtype[tcount++] = gensub(mtyperegex, "\\1", "g", $2);
paul2fd2fd52005-04-15 11:47:15 +000073}
74
75END {
76 printf("enum\n{\n MTYPE_TMP = 1,\n");
77 for (i = 0; i < tcount; i++) {
78 if (mtype[i] != "" && mtype[i] != "MTYPE_TMP")
79 printf (" %s,\n", mtype[i]);
80 }
81 printf (" MTYPE_MAX,\n};\n\n");
82 for (i = 0; i < lcount; i++) {
83 if (mlists[i] != "")
84 printf (mlistformat "\n", mlists[i]);
85 }
86 printf (footer);
87}