blob: 1fe9ac23c1166650bb008dd37423c5a3c626e0c6 [file] [log] [blame]
Jack Jansenda6a9711996-04-12 16:25:30 +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
6# NOTE: the scrap include file is so bad that the bgen output has to be
7# massaged by hand.
8
9import string
10
11# Declarations that change for each manager
12MACHEADERFILE = 'Scrap.h' # The Apple header file
13MODNAME = 'Scrap' # The name of the module
14
15# The following is *usually* unchanged but may still require tuning
16MODPREFIX = MODNAME # The prefix for module-wide routines
17INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
18OUTPUTFILE = '@' + MODNAME + "module.c" # The file generated by this program
19
20from macsupport import *
21
22# Create the type objects
23
24includestuff = includestuff + """
25#include <%s>""" % MACHEADERFILE + """
26
27/*
28** Generate ScrapInfo records
29*/
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000030static PyObject *
31SCRRec_New(itself)
Jack Jansenda6a9711996-04-12 16:25:30 +000032 ScrapStuff *itself;
33{
34
35 return Py_BuildValue("lO&hhO&", itself->scrapSize,
36 ResObj_New, itself->scrapHandle, itself->scrapCount, itself->scrapState,
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000037 PyMac_BuildStr255, itself->scrapName);
Jack Jansenda6a9711996-04-12 16:25:30 +000038}
39"""
40
Jack Jansen7b3cc1f2001-01-24 16:04:01 +000041ScrapStuffPtr = OpaqueByValueType('ScrapStuffPtr', 'SCRRec')
42ScrapFlavorType = OSTypeType('ScrapFlavorType')
Jack Jansenda6a9711996-04-12 16:25:30 +000043putscrapbuffer = FixedInputBufferType('void *')
44
45# Create the generator groups and link them
46module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
47
48# Create the generator classes used to populate the lists
49Function = OSErrFunctionGenerator
50
51# Create and populate the lists
52functions = []
53execfile(INPUTFILE)
54
55# add the populated lists to the generator groups
56# (in a different wordl the scan program would generate this)
57for f in functions: module.add(f)
58
59# generate output (open the output file as late as possible)
60SetOutputFileName(OUTPUTFILE)
61module.generate()
62