Commit d0e59fb6 authored by Jack Jansen's avatar Jack Jansen

Added the alias manager too. The interface isn't perfect yet: the alias

manager doesn't always have the alias as the first argument, so things
become functions in stead of methods.
parent e2ba8739
from _Alias import *
# Generated from 'Aliases.h'
def FOUR_CHAR_CODE(x): return x
true = True
false = False
rAliasType = FOUR_CHAR_CODE('alis')
kARMMountVol = 0x00000001
kARMNoUI = 0x00000002
kARMMultVols = 0x00000008
kARMSearch = 0x00000100
kARMSearchMore = 0x00000200
kARMSearchRelFirst = 0x00000400
asiZoneName = -3
asiServerName = -2
asiVolumeName = -1
asiAliasName = 0
asiParentName = 1
kResolveAliasFileNoUI = 0x00000001
This diff is collapsed.
# Scan an Apple header file, generating a Python file of generator calls.
import sys
import os
from bgenlocations import TOOLBOXDIR, BGENDIR
sys.path.append(BGENDIR)
from scantools import Scanner_OSX
LONG = "Aliases"
SHORT = "alias"
OBJECT = "AliasHandle"
def main():
input = LONG + ".h"
output = SHORT + "gen.py"
defsoutput = TOOLBOXDIR + LONG + ".py"
scanner = MyScanner(input, output, defsoutput)
scanner.scan()
scanner.close()
scanner.gentypetest(SHORT+"typetest.py")
print "=== Testing definitions output code ==="
execfile(defsoutput, {}, {})
print "=== Done scanning and generating, now importing the generated code... ==="
exec "import " + SHORT + "support"
print "=== Done. It's up to you to compile it now! ==="
class MyScanner(Scanner_OSX):
def destination(self, type, name, arglist):
classname = "Function"
listname = "functions"
if arglist:
t, n, m = arglist[0]
# This is non-functional today
if t == OBJECT and m == "InMode":
classname = "Method"
listname = "methods"
return classname, listname
def makeblacklistnames(self):
return [
# Constants with incompatible definitions
]
def makeblacklisttypes(self):
return [
"AliasFilterProcPtr",
"AliasFilterUPP",
"CInfoPBPtr",
]
def makerepairinstructions(self):
return [
([('Str63', 'theString', 'InMode')],
[('Str63', 'theString', 'OutMode')]),
([('short', 'fullPathLength', 'InMode'),
('void_ptr', 'fullPath', 'InMode')],
[('FullPathName', 'fullPath', 'InMode')]),
]
def writeinitialdefs(self):
self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
self.defsfile.write("true = True\n")
self.defsfile.write("false = False\n")
if __name__ == "__main__":
main()
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).
import string
# Declarations that change for each manager
MACHEADERFILE = 'Aliases.h' # The Apple header file
MODNAME = '_Alias' # The name of the module
# The following is *usually* unchanged but may still require tuning
MODPREFIX = 'Alias' # The prefix for module-wide routines
INPUTFILE = string.lower(MODPREFIX) + 'gen.py' # The file generated by the scanner
OUTPUTFILE = MODNAME + "module.c" # The file generated by this program
from macsupport import *
# Create the type objects
class VarReverseInputBufferType(ReverseInputBufferMixin, VarInputBufferType):
pass
FullPathName = VarReverseInputBufferType()
AliasHandle = OpaqueByValueType("AliasHandle", "AliasObj")
AliasInfoType = Type("AliasInfoType", "h")
ConstStr31Param = OpaqueArrayType("Str31", "PyMac_BuildStr255", "PyMac_GetStr255")
ConstStr32Param = OpaqueArrayType("Str32", "PyMac_BuildStr255", "PyMac_GetStr255")
#FSSpecArrayPtr
#Ptr
Str63 = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
#void_ptr
# class UniCharCountBuffer(InputOnlyType):
# pass
#
# #CatPositionRec
# ConstStr63Param = OpaqueArrayType("Str63", "PyMac_BuildStr255", "PyMac_GetStr255")
# FInfo = OpaqueByValueStructType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
# FInfo_ptr = OpaqueType("FInfo", "PyMac_BuildFInfo", "PyMac_GetFInfo")
# FNMessage = Type("FNMessage", "l")
# FSAllocationFlags = Type("FSAllocationFlags", "H")
# #FSCatalogInfo
# FSCatalogInfoBitmap = Type("FSCatalogInfoBitmap", "l")
# #FSForkInfo
# #FSIterator
# FSIteratorFlags = Type("FSIteratorFlags", "l")
# #FSVolumeInfo
# FSVolumeRefNum = Type("FSVolumeRefNum", "h")
# HFSUniStr255 = OpaqueType("HFSUniStr255", "PyMac_BuildHFSUniStr255", "PyMac_GetHFSUniStr255")
# SInt64 = Type("SInt64", "L")
# UInt64 = Type("UInt64", "L")
# #UInt8_ptr
# #UniCharCount
# #char_ptr
# #void_ptr
includestuff = includestuff + """
#ifdef WITHOUT_FRAMEWORKS
#include <Files.h>
#else
#include <Carbon/Carbon.h>
#endif
"""
execfile(string.lower(MODPREFIX) + 'typetest.py')
# From here on it's basically all boiler plate...
# Create the generator groups and link them
module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
class AliasDefinition(GlobalObjectDefinition):
def outputCheckNewArg(self):
Output("if (itself == NULL) return PyMac_Error(resNotFound);")
def outputStructMembers(self):
GlobalObjectDefinition.outputStructMembers(self)
Output("void (*ob_freeit)(%s ptr);", self.itselftype)
def outputInitStructMembers(self):
GlobalObjectDefinition.outputInitStructMembers(self)
Output("it->ob_freeit = NULL;")
def outputCleanupStructMembers(self):
Output("if (self->ob_freeit && self->ob_itself)")
OutLbrace()
Output("self->ob_freeit(self->ob_itself);")
OutRbrace()
Output("self->ob_itself = NULL;")
aliasobject = AliasDefinition('Alias', 'AliasObj', 'AliasHandle')
module.addobject(aliasobject)
# Create the generator classes used to populate the lists
Function = OSErrFunctionGenerator
Method = OSErrMethodGenerator
# Create and populate the lists
functions = []
methods = []
execfile(INPUTFILE)
# Manual generators:
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for f in methods: aliasobject.add(f)
for f in functions: module.add(f)
# generate output (open the output file as late as possible)
SetOutputFileName(OUTPUTFILE)
module.generate()
...@@ -728,6 +728,8 @@ class PyBuildExt(build_ext): ...@@ -728,6 +728,8 @@ class PyBuildExt(build_ext):
extra_link_args=['-framework', 'Carbon']) ) extra_link_args=['-framework', 'Carbon']) )
exts.append( Extension('_AH', ['ah/_AHmodule.c'], exts.append( Extension('_AH', ['ah/_AHmodule.c'],
extra_link_args=['-framework', 'Carbon']) ) extra_link_args=['-framework', 'Carbon']) )
exts.append( Extension('_Alias', ['alias/_Aliasmodule.c'],
extra_link_args=['-framework', 'Carbon']) )
exts.append( Extension('_App', ['app/_Appmodule.c'], exts.append( Extension('_App', ['app/_Appmodule.c'],
extra_link_args=['-framework', 'Carbon']) ) extra_link_args=['-framework', 'Carbon']) )
exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'], exts.append( Extension('_CarbonEvt', ['carbonevt/_CarbonEvtmodule.c'],
......
Markdown is supported
0%
or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment