Paul Jakma | 010ebbb | 2014-09-16 11:53:49 +0100 | [diff] [blame] | 1 | ### |
| 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 | ### |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame] | 21 | # |
| 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 | # |
paul | dc830cb | 2005-04-16 15:51:05 +0000 | [diff] [blame] | 26 | # 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 |
paul | d5c9253 | 2005-05-23 12:33:58 +0000 | [diff] [blame] | 31 | # characters [[:upper:]_[:digit:]]. Eg: |
paul | dc830cb | 2005-04-16 15:51:05 +0000 | [diff] [blame] | 32 | # |
| 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 | # |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame] | 50 | |
| 51 | BEGIN { |
| 52 | mlistregex = "memory_list_(.*)\\[\\]"; |
paul | d5c9253 | 2005-05-23 12:33:58 +0000 | [diff] [blame] | 53 | mtyperegex = "^(MTYPE_[[:upper:]_[:digit:]]+).*"; |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame] | 54 | 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 | |
paul | dc830cb | 2005-04-16 15:51:05 +0000 | [diff] [blame] | 63 | # catch lines beginning with 'struct memory list ' and try snag the |
| 64 | # memory_list name. Has to be 3rd field. |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame] | 65 | ($0 ~ /^struct memory_list /) && (NF >= 3) { |
Paul Jakma | d4ce4f6 | 2006-03-30 14:30:19 +0000 | [diff] [blame] | 66 | mlists[lcount++] = gensub(mlistregex, "\\1", "g",$3); |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame] | 67 | } |
| 68 | |
paul | dc830cb | 2005-04-16 15:51:05 +0000 | [diff] [blame] | 69 | # 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 Jakma | d4ce4f6 | 2006-03-30 14:30:19 +0000 | [diff] [blame] | 72 | mtype[tcount++] = gensub(mtyperegex, "\\1", "g", $2); |
paul | 2fd2fd5 | 2005-04-15 11:47:15 +0000 | [diff] [blame] | 73 | } |
| 74 | |
| 75 | END { |
| 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 | } |