2003-07-18 03:02:12 +00:00
|
|
|
#! /usr/bin/python
|
|
|
|
# -*- python -*-
|
|
|
|
#
|
2003-08-18 20:17:55 +00:00
|
|
|
# $Id: plugin_gen.py,v 1.2 2003/08/18 20:17:55 guy Exp $
|
|
|
|
#
|
2003-07-18 03:02:12 +00:00
|
|
|
# mmelchior@xs4all.nl
|
|
|
|
#
|
2003-08-18 20:17:55 +00:00
|
|
|
# generate files for the windows plugin interface from a file with declarations
|
2003-07-18 03:02:12 +00:00
|
|
|
#
|
2003-08-18 20:17:55 +00:00
|
|
|
# The input for this script is generated by gcc using the following command:
|
2003-07-18 03:02:12 +00:00
|
|
|
#
|
|
|
|
# gcc -aux-info xyzzy $(pkg-config --cflags glib-2.0) -I ethereal-0.9.13 -c plugin_api_list.c
|
|
|
|
#
|
|
|
|
# this gives one declaration per line, with consistent spacing.
|
|
|
|
#
|
|
|
|
# with a much more elaborate parser than the one RE we have now, we could do without gcc.
|
|
|
|
#
|
|
|
|
|
|
|
|
"""Ethereal Windows interface generator."""
|
|
|
|
|
|
|
|
import sys, string, os, re
|
|
|
|
from string import strip, replace
|
|
|
|
|
|
|
|
pattFile = re.compile('.*plugin_api_list.* extern (.*)') # match filename and select declaration
|
|
|
|
pattName = re.compile('\w* .*?(\w*) \(.*') # select function name
|
|
|
|
|
|
|
|
if len(sys.argv) > 1:
|
|
|
|
file = open(sys.argv[1], 'r') # input name on command line
|
|
|
|
else:
|
|
|
|
file = sys.stdin # read from a stream
|
|
|
|
|
2003-08-18 20:17:55 +00:00
|
|
|
f2 = open("Xplugin_api.h", 'w') # defines to hide indirection
|
|
|
|
f3 = open("Xplugin_api.c", 'w') # statements to copy addresses from structure
|
|
|
|
f4 = open("Xplugin_api_decls.h", 'w') # pointer definitions
|
|
|
|
f5 = open("Xplugin_table.h", 'w') # type definitions
|
|
|
|
f6 = open("Xass-list", 'w'); # exported structure initialization
|
|
|
|
|
|
|
|
comment = "/* This file is generated by %s, do not edit. */\n\n" % sys.argv[0]
|
|
|
|
f2.write(comment)
|
|
|
|
f3.write(comment)
|
|
|
|
f4.write(comment)
|
|
|
|
f5.write(comment)
|
|
|
|
f6.write(comment)
|
2003-07-18 03:02:12 +00:00
|
|
|
|
2003-08-18 20:17:55 +00:00
|
|
|
pos = 0
|
|
|
|
count = 0
|
2003-07-18 03:02:12 +00:00
|
|
|
while 1:
|
|
|
|
line = file.readline()
|
|
|
|
if not line: break
|
|
|
|
matchobj = pattFile.match(line)
|
|
|
|
if matchobj:
|
|
|
|
# print "+", count, " ", strip(line)
|
|
|
|
decl = matchobj.group(1)
|
|
|
|
# print "= ", decl
|
|
|
|
matchobj = pattName.match(decl)
|
|
|
|
if matchobj:
|
2003-08-18 20:17:55 +00:00
|
|
|
count += 1
|
2003-07-18 03:02:12 +00:00
|
|
|
name = matchobj.group(1)
|
|
|
|
# print " ", name
|
|
|
|
f2.write("#define %s (*p_%s)\n" % (name, name))
|
|
|
|
f3.write("p_%s = pat->p_%s;\n" % (name, name))
|
|
|
|
f4.write("addr_%s p_%s;\n" % (name, name))
|
|
|
|
f5.write(replace("typedef %s\n" % decl, name, "(*addr_%s)" % name))
|
2003-08-18 20:17:55 +00:00
|
|
|
f6.write(name)
|
|
|
|
pos += len(name) + 2
|
|
|
|
if pos > 60:
|
|
|
|
pos = 0
|
|
|
|
f6.write(",\n")
|
|
|
|
else:
|
|
|
|
f6.write(", ")
|
2003-07-18 03:02:12 +00:00
|
|
|
else:
|
|
|
|
print '**** function name not fount in "%s"' % decl
|
|
|
|
|
|
|
|
f6.write('\n')
|
2003-08-18 20:17:55 +00:00
|
|
|
|
|
|
|
print "%d symbols exported" % count
|
2003-07-18 03:02:12 +00:00
|
|
|
|
|
|
|
file.close()
|
|
|
|
f2.close()
|
|
|
|
f3.close()
|
|
|
|
f4.close()
|
|
|
|
f5.close()
|
2003-08-18 20:17:55 +00:00
|
|
|
f6.close()
|