From Masashi Honma:
[obnox/wireshark/wip.git] / epan / wslua / make-reg.pl
1 #!/usr/bin/perl
2 #
3 # make-reg.pl
4 # Registration Macros Generator
5 #
6 # (c) 2006, Luis E. Garcia Onatnon <luis.ontanon@gmail.com>
7 #
8 # $Id$
9 #
10 # Wireshark - Network traffic analyzer
11 # By Gerald Combs <gerald@wireshark.org>
12 # Copyright 1998 Gerald Combs
13
14 # This program is free software; you can redistribute it and/or
15 # modify it under the terms of the GNU General Public License
16 # as published by the Free Software Foundation; either version 2
17 # of the License, or (at your option) any later version.
18
19 # This program is distributed in the hope that it will be useful,
20 # but WITHOUT ANY WARRANTY; without even the implied warranty of
21 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
22 # GNU General Public License for more details.
23
24 # You should have received a copy of the GNU General Public License
25 # along with this program; if not, write to the Free Software
26 # Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
27
28 use strict;
29
30 my @classes = ();
31 my @functions = ();
32
33 while (<>) {
34         push @classes, $1 if /WSLUA_CLASS_DEFINE\050\s*([A-Za-z0-9]+)/;
35         push @functions, $1 if  /WSLUA_FUNCTION\s+wslua_([a-z_0-9]+)/;
36 }
37
38 open C, ">register_wslua.c";
39 open H, ">declare_wslua.h";
40
41 print H "/* This file is automatically genrated by make-reg.pl do not edit */\n\n";
42 print C "/* This file is automatically genrated by make-reg.pl do not edit */\n\n";
43
44 print H "#define WSLUA_DECLARE_CLASSES() \\\n"; 
45 for (@classes) {
46         print H "\tWSLUA_CLASS_DECLARE($_);\\\n"
47 }
48 print H "\n\n";
49
50 print H "#define WSLUA_DECLARE_FUNCTIONS() \\\n"; 
51 for (@functions) {
52         print H "\tWSLUA_FUNCTION wslua_$_(lua_State* L);\\\n"
53 }
54 print H "\n\n";
55 print H "extern void wslua_register_classes(lua_State* L);\n"; 
56 print H "extern void wslua_register_functions(lua_State* L);\n"; 
57 print H "\n\n";
58
59
60 print C '#include "wslua.h"' . "\n\n"; 
61 print C "void wslua_register_classes(lua_State* L) { \n"; 
62 for (@classes) {
63         print C "\t${_}_register(L);\n"
64 }
65 print C "\tluaopen_bit(L);\n";
66 print C "}\n\n";
67
68
69 print C "void wslua_register_functions(lua_State* L) {\n"; 
70 for (@functions) {
71         print C "\tWSLUA_REGISTER_FUNCTION($_); \n"
72 }
73 print C "}\n\n";
74
75 close H;
76 close C;