blob: 20b4f3650d9454622517999a6eef4b26b6191a4e [file] [log] [blame]
Guido van Rossum17448e21995-01-30 11:53:55 +00001# This script generates a Python interface for an Apple Macintosh Manager.
2# It uses the "bgen" package to generate C code.
3# The function specifications are generated by scanning the mamager's header file,
4# using the "scantools" package (customized for this particular manager).
5
6import string
7
8# Declarations that change for each manager
9MACHEADERFILE = 'Menus.h' # The Apple header file
10MODNAME = 'Menu' # The name of the module
11OBJECTNAME = 'Menu' # The basic name of the objects used here
12
13# The following is *usually* unchanged but may still require tuning
14MODPREFIX = MODNAME # The prefix for module-wide routines
15OBJECTTYPE = OBJECTNAME + 'Handle' # The C type used to represent them
16OBJECTPREFIX = MODPREFIX + 'Obj' # The prefix for object methods
17INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
Guido van Rossum86c3af71995-03-19 22:42:51 +000018EXTRAFILE = string.lower(MODPREFIX) + 'edit.py' # A similar file but hand-made
Guido van Rossum17448e21995-01-30 11:53:55 +000019OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
20
21from macsupport import *
22
23# Create the type objects
24
25MenuHandle = OpaqueByValueType(OBJECTTYPE, OBJECTPREFIX)
Jack Jansenb81cf9d1995-06-06 13:08:40 +000026MenuRef = MenuHandle
Jack Jansena1a0fef1999-12-23 14:32:06 +000027Handle = OpaqueByValueType("Handle", "ResObj")
Jack Jansenf7d5aa62000-12-10 23:43:49 +000028MenuBarHandle = OpaqueByValueType("MenuBarHandle", "ResObj")
29MenuID = Type("MenuID", "h")
30MenuItemIndex = Type("MenuItemIndex", "h")
31MenuCommand = Type("MenuCommand", "l")
32MenuAttributes = Type("MenuAttributes", "l")
33MenuItemAttributes = Type("MenuItemAttributes", "l")
Jack Jansenb81cf9d1995-06-06 13:08:40 +000034unsigned_char = Type('unsigned char', 'b')
Jack Jansenf7d5aa62000-12-10 23:43:49 +000035FMFontFamily = Type("FMFontFamily", "h")
36FMFontStyle = Type("FMFontStyle", "h")
Guido van Rossum17448e21995-01-30 11:53:55 +000037
38includestuff = includestuff + """
Guido van Rossum86c3af71995-03-19 22:42:51 +000039#include <Devices.h> /* Defines OpenDeskAcc in universal headers */
Guido van Rossum17448e21995-01-30 11:53:55 +000040#include <%s>""" % MACHEADERFILE + """
41
Jack Jansenf7d5aa62000-12-10 23:43:49 +000042#if !ACCESSOR_CALLS_ARE_FUNCTIONS
43#define GetMenuID(menu) ((*(menu))->menuID)
44#define GetMenuWidth(menu) ((*(menu))->menuWidth)
45#define GetMenuHeight(menu) ((*(menu))->menuHeight)
46
47#define SetMenuID(menu, id) ((*(menu))->menuID = (id))
48#define SetMenuWidth(menu, width) ((*(menu))->menuWidth = (width))
49#define SetMenuHeight(menu, height) ((*(menu))->menuHeight = (height))
50#endif
51
Jack Jansene0581891999-02-07 14:02:03 +000052#define as_Menu(h) ((MenuHandle)h)
Jack Jansena1a0fef1999-12-23 14:32:06 +000053#define as_Resource(h) ((Handle)h)
Guido van Rossum17448e21995-01-30 11:53:55 +000054"""
55
56class MyObjectDefinition(GlobalObjectDefinition):
57 pass
58
59# Create the generator groups and link them
60module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
61object = MyObjectDefinition(OBJECTNAME, OBJECTPREFIX, OBJECTTYPE)
62module.addobject(object)
63
64# Create the generator classes used to populate the lists
65Function = OSErrFunctionGenerator
66Method = OSErrMethodGenerator
67
68# Create and populate the lists
69functions = []
70methods = []
71execfile(INPUTFILE)
Guido van Rossum86c3af71995-03-19 22:42:51 +000072execfile(EXTRAFILE)
Guido van Rossum17448e21995-01-30 11:53:55 +000073
74# add the populated lists to the generator groups
75for f in functions: module.add(f)
76for f in methods: object.add(f)
77
78# generate output (open the output file as late as possible)
79SetOutputFileName(OUTPUTFILE)
80module.generate()