'release21-maint'.
--- /dev/null
+# A minimal text editor using MLTE. Based on wed.py.
+#
+# To be done:
+# - Functionality: find, etc.
+
+from Menu import DrawMenuBar
+from FrameWork import *
+import Win
+import Ctl
+import Qd
+import Res
+import Scrap
+import os
+import macfs
+import MacTextEditor
+import Mlte
+
+UNDOLABELS = [ # Indexed by MLTECanUndo() value
+ "Typing", "Cut", "Paste", "Clear", "Font Change", "Color Change", "Size Change",
+ "Style Change", "Align Left", "Align Center", "Align Right", "Drop", "Move"]
+
+class MlteWindow(Window):
+ def open(self, path, name, data):
+ self.path = path
+ self.name = name
+ r = windowbounds(400, 400)
+ w = Win.NewWindow(r, name, 1, 0, -1, 1, 0x55555555)
+ self.wid = w
+ flags = MacTextEditor.kTXNDrawGrowIconMask|MacTextEditor.kTXNWantHScrollBarMask| \
+ MacTextEditor.kTXNWantVScrollBarMask
+ self.ted, self.frameid = Mlte.TXNNewObject(None, w, None, flags, MacTextEditor.kTXNTextEditStyleFrameType,
+ MacTextEditor.kTXNTextFile, MacTextEditor.kTXNMacOSEncoding)
+ self.ted.TXNSetData(MacTextEditor.kTXNTextData, data, 0, 0x7fffffff)
+ self.changed = 0
+ self.do_postopen()
+ self.do_activate(1, None)
+
+ def do_idle(self, event):
+ self.ted.TXNIdle()
+ self.ted.TXNAdjustCursor(None)
+
+
+
+ def do_activate(self, onoff, evt):
+ if onoff:
+## self.ted.TXNActivate(self.frameid, 0)
+ self.ted.TXNFocus(1)
+ self.parent.active = self
+ else:
+ self.ted.TXNFocus(0)
+ self.parent.active = None
+ self.parent.updatemenubar()
+
+ def do_update(self, wid, event):
+ self.ted.TXNDraw(None)
+
+ def do_postresize(self, width, height, window):
+ self.ted.TXNResizeFrame(width, height, self.frameid)
+
+ def do_contentclick(self, local, modifiers, evt):
+ self.ted.TXNClick(evt)
+ self.parent.updatemenubar()
+
+ def do_char(self, ch, event):
+ self.ted.TXNKeyDown(event)
+ self.parent.updatemenubar()
+
+ def close(self):
+ if self.changed:
+ save = EasyDialogs.AskYesNoCancel('Save window "%s" before closing?'%self.name, 1)
+ if save > 0:
+ self.menu_save()
+ elif save < 0:
+ return
+ if self.parent.active == self:
+ self.parent.active = None
+ self.ted.TXNDeleteObject()
+ del self.ted
+## del self.tedtexthandle
+ self.do_postclose()
+
+ def menu_save(self):
+ if not self.path:
+ self.menu_save_as()
+ return # Will call us recursively
+ dhandle = self.ted.TXNGetData(0, 0x7fffffff)
+ data = dhandle.data
+ fp = open(self.path, 'wb') # NOTE: wb, because data has CR for end-of-line
+ fp.write(data)
+ if data[-1] <> '\r': fp.write('\r')
+ fp.close()
+ self.changed = 0
+
+ def menu_save_as(self):
+ fss, ok = macfs.StandardPutFile('Save as:')
+ if not ok: return
+ self.path = fss.as_pathname()
+ self.name = os.path.split(self.path)[-1]
+ self.wid.SetWTitle(self.name)
+ self.menu_save()
+
+ def menu_cut(self):
+## self.ted.WESelView()
+ self.ted.TXNCut()
+### Mlte.ConvertToPublicScrap()
+## Scrap.ZeroScrap()
+## self.ted.WECut()
+## self.updatescrollbars()
+ self.parent.updatemenubar()
+ self.changed = 1
+
+ def menu_copy(self):
+## Scrap.ZeroScrap()
+ self.ted.TXNCopy()
+### Mlte.ConvertToPublicScrap()
+## self.updatescrollbars()
+ self.parent.updatemenubar()
+
+ def menu_paste(self):
+### Mlte.ConvertFromPublicScrap()
+ self.ted.TXNPaste()
+## self.updatescrollbars()
+ self.parent.updatemenubar()
+ self.changed = 1
+
+ def menu_clear(self):
+## self.ted.WESelView()
+ self.ted.TXNClear()
+## self.updatescrollbars()
+ self.parent.updatemenubar()
+ self.changed = 1
+
+ def menu_undo(self):
+ self.ted.TXNUndo()
+## self.updatescrollbars()
+ self.parent.updatemenubar()
+
+ def menu_redo(self):
+ self.ted.TXNRedo()
+## self.updatescrollbars()
+ self.parent.updatemenubar()
+
+ def have_selection(self):
+ start, stop = self.ted.TXNGetSelection()
+ return start < stop
+
+ def can_paste(self):
+ return Mlte.TXNIsScrapPastable()
+
+ def can_undo(self):
+ can, which = self.ted.TXNCanUndo()
+ if not can:
+ return None
+ if which >= len(UNDOLABELS):
+ # Unspecified undo
+ return "Undo"
+ which = UNDOLABELS[which]
+
+ return "Undo "+which
+
+ def can_redo(self):
+ can, which = self.ted.TXNCanRedo()
+ if not can:
+ return None
+ if which >= len(UNDOLABELS):
+ # Unspecified undo
+ return "Redo"
+ which = UNDOLABELS[which]
+
+ return "Redo "+which
+
+class Mlted(Application):
+ def __init__(self):
+ Application.__init__(self)
+ self.num = 0
+ self.active = None
+ self.updatemenubar()
+
+ def makeusermenus(self):
+ self.filemenu = m = Menu(self.menubar, "File")
+ self.newitem = MenuItem(m, "New window", "N", self.open)
+ self.openitem = MenuItem(m, "Open...", "O", self.openfile)
+ self.closeitem = MenuItem(m, "Close", "W", self.closewin)
+ m.addseparator()
+ self.saveitem = MenuItem(m, "Save", "S", self.save)
+ self.saveasitem = MenuItem(m, "Save as...", "", self.saveas)
+ m.addseparator()
+ self.quititem = MenuItem(m, "Quit", "Q", self.quit)
+
+ self.editmenu = m = Menu(self.menubar, "Edit")
+ self.undoitem = MenuItem(m, "Undo", "Z", self.undo)
+ self.redoitem = MenuItem(m, "Redo", None, self.redo)
+ m.addseparator()
+ self.cutitem = MenuItem(m, "Cut", "X", self.cut)
+ self.copyitem = MenuItem(m, "Copy", "C", self.copy)
+ self.pasteitem = MenuItem(m, "Paste", "V", self.paste)
+ self.clearitem = MenuItem(m, "Clear", "", self.clear)
+
+ # Groups of items enabled together:
+ self.windowgroup = [self.closeitem, self.saveitem, self.saveasitem, self.editmenu]
+ self.focusgroup = [self.cutitem, self.copyitem, self.clearitem]
+ self.windowgroup_on = -1
+ self.focusgroup_on = -1
+ self.pastegroup_on = -1
+ self.undo_label = "never"
+ self.redo_label = "never"
+
+ def updatemenubar(self):
+ changed = 0
+ on = (self.active <> None)
+ if on <> self.windowgroup_on:
+ for m in self.windowgroup:
+ m.enable(on)
+ self.windowgroup_on = on
+ changed = 1
+ if on:
+ # only if we have an edit menu
+ on = self.active.have_selection()
+ if on <> self.focusgroup_on:
+ for m in self.focusgroup:
+ m.enable(on)
+ self.focusgroup_on = on
+ changed = 1
+ on = self.active.can_paste()
+ if on <> self.pastegroup_on:
+ self.pasteitem.enable(on)
+ self.pastegroup_on = on
+ changed = 1
+ on = self.active.can_undo()
+ if on <> self.undo_label:
+ if on:
+ self.undoitem.enable(1)
+ self.undoitem.settext(on)
+ self.undo_label = on
+ else:
+ self.undoitem.settext("Nothing to undo")
+ self.undoitem.enable(0)
+ changed = 1
+ on = self.active.can_redo()
+ if on <> self.redo_label:
+ if on:
+ self.redoitem.enable(1)
+ self.redoitem.settext(on)
+ self.redo_label = on
+ else:
+ self.redoitem.settext("Nothing to redo")
+ self.redoitem.enable(0)
+ changed = 1
+ if changed:
+ DrawMenuBar()
+
+ #
+ # Apple menu
+ #
+
+ def do_about(self, id, item, window, event):
+ EasyDialogs.Message("A simple single-font text editor based on MacTextEditor")
+
+ #
+ # File menu
+ #
+
+ def open(self, *args):
+ self._open(0)
+
+ def openfile(self, *args):
+ self._open(1)
+
+ def _open(self, askfile):
+ if askfile:
+ fss, ok = macfs.StandardGetFile('TEXT')
+ if not ok:
+ return
+ path = fss.as_pathname()
+ name = os.path.split(path)[-1]
+ try:
+ fp = open(path, 'rb') # NOTE binary, we need cr as end-of-line
+ data = fp.read()
+ fp.close()
+ except IOError, arg:
+ EasyDialogs.Message("IOERROR: "+`arg`)
+ return
+ else:
+ path = None
+ name = "Untitled %d"%self.num
+ data = ''
+ w = MlteWindow(self)
+ w.open(path, name, data)
+ self.num = self.num + 1
+
+ def closewin(self, *args):
+ if self.active:
+ self.active.close()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def save(self, *args):
+ if self.active:
+ self.active.menu_save()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def saveas(self, *args):
+ if self.active:
+ self.active.menu_save_as()
+ else:
+ EasyDialogs.Message("No active window?")
+
+
+ def quit(self, *args):
+ for w in self._windows.values():
+ w.close()
+ if self._windows:
+ return
+ self._quit()
+
+ #
+ # Edit menu
+ #
+
+ def undo(self, *args):
+ if self.active:
+ self.active.menu_undo()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def redo(self, *args):
+ if self.active:
+ self.active.menu_redo()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def cut(self, *args):
+ if self.active:
+ self.active.menu_cut()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def copy(self, *args):
+ if self.active:
+ self.active.menu_copy()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def paste(self, *args):
+ if self.active:
+ self.active.menu_paste()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ def clear(self, *args):
+ if self.active:
+ self.active.menu_clear()
+ else:
+ EasyDialogs.Message("No active window?")
+
+ #
+ # Other stuff
+ #
+
+ def idle(self, event):
+ if self.active:
+ self.active.do_idle(event)
+
+def main():
+ Mlte.TXNInitTextension(0)
+ try:
+ App = Mlted()
+ App.mainloop()
+ finally:
+ Mlte.TXNTerminateTextension()
+
+if __name__ == '__main__':
+ main()
+
--- /dev/null
+# Generated from 'MacTextEditor.h'
+
+
+def FOUR_CHAR_CODE(x): return x
+false = 0
+true = 1
+kTXNClearThisControl = 0xFFFFFFFF
+kTXNClearTheseFontFeatures = 0x80000000
+kTXNDontCareTypeSize = 0xFFFFFFFF
+kTXNDecrementTypeSize = 0x80000000
+kTXNUseCurrentSelection = 0xFFFFFFFF
+kTXNStartOffset = 0
+kTXNEndOffset = 0x7FFFFFFF
+MovieFileType = FOUR_CHAR_CODE('moov')
+kTXNWillDefaultToATSUIBit = 0
+kTXNWillDefaultToATSUIMask = 1L << kTXNWillDefaultToATSUIBit
+kTXNWantMoviesBit = 0
+kTXNWantSoundBit = 1
+kTXNWantGraphicsBit = 2
+kTXNAlwaysUseQuickDrawTextBit = 3
+kTXNUseTemporaryMemoryBit = 4
+kTXNWantMoviesMask = 1L << kTXNWantMoviesBit
+kTXNWantSoundMask = 1L << kTXNWantSoundBit
+kTXNWantGraphicsMask = 1L << kTXNWantGraphicsBit
+kTXNAlwaysUseQuickDrawTextMask = 1L << kTXNAlwaysUseQuickDrawTextBit
+kTXNUseTemporaryMemoryMask = 1L << kTXNUseTemporaryMemoryBit
+kTXNDrawGrowIconBit = 0
+kTXNShowWindowBit = 1
+kTXNWantHScrollBarBit = 2
+kTXNWantVScrollBarBit = 3
+kTXNNoTSMEverBit = 4
+kTXNReadOnlyBit = 5
+kTXNNoKeyboardSyncBit = 6
+kTXNNoSelectionBit = 7
+kTXNSaveStylesAsSTYLResourceBit = 8
+kOutputTextInUnicodeEncodingBit = 9
+kTXNDoNotInstallDragProcsBit = 10
+kTXNAlwaysWrapAtViewEdgeBit = 11
+kTXNDrawGrowIconMask = 1L << kTXNDrawGrowIconBit
+kTXNShowWindowMask = 1L << kTXNShowWindowBit
+kTXNWantHScrollBarMask = 1L << kTXNWantHScrollBarBit
+kTXNWantVScrollBarMask = 1L << kTXNWantVScrollBarBit
+kTXNNoTSMEverMask = 1L << kTXNNoTSMEverBit
+kTXNReadOnlyMask = 1L << kTXNReadOnlyBit
+kTXNNoKeyboardSyncMask = 1L << kTXNNoKeyboardSyncBit
+kTXNNoSelectionMask = 1L << kTXNNoSelectionBit
+kTXNSaveStylesAsSTYLResourceMask = 1L << kTXNSaveStylesAsSTYLResourceBit
+kOutputTextInUnicodeEncodingMask = 1L << kOutputTextInUnicodeEncodingBit
+kTXNDoNotInstallDragProcsMask = 1L << kTXNDoNotInstallDragProcsBit
+kTXNAlwaysWrapAtViewEdgeMask = 1L << kTXNAlwaysWrapAtViewEdgeBit
+kTXNFontContinuousBit = 0
+kTXNSizeContinuousBit = 1
+kTXNStyleContinuousBit = 2
+kTXNColorContinuousBit = 3
+kTXNFontContinuousMask = 1L << kTXNFontContinuousBit
+kTXNSizeContinuousMask = 1L << kTXNSizeContinuousBit
+kTXNStyleContinuousMask = 1L << kTXNStyleContinuousBit
+kTXNColorContinuousMask = 1L << kTXNColorContinuousBit
+kTXNIgnoreCaseBit = 0
+kTXNEntireWordBit = 1
+kTXNUseEncodingWordRulesBit = 31
+kTXNIgnoreCaseMask = 1L << kTXNIgnoreCaseBit
+kTXNEntireWordMask = 1L << kTXNEntireWordBit
+kTXNUseEncodingWordRulesMask = 1L << kTXNUseEncodingWordRulesBit
+kTXNTextensionFile = FOUR_CHAR_CODE('txtn')
+kTXNTextFile = FOUR_CHAR_CODE('TEXT')
+kTXNPictureFile = FOUR_CHAR_CODE('PICT')
+kTXNMovieFile = MovieFileType
+kTXNSoundFile = FOUR_CHAR_CODE('sfil')
+kTXNAIFFFile = FOUR_CHAR_CODE('AIFF')
+kTXNTextEditStyleFrameType = 1
+kTXNPageFrameType = 2
+kTXNMultipleFrameType = 3
+kTXNTextData = FOUR_CHAR_CODE('TEXT')
+kTXNPictureData = FOUR_CHAR_CODE('PICT')
+kTXNMovieData = FOUR_CHAR_CODE('moov')
+kTXNSoundData = FOUR_CHAR_CODE('snd ')
+kTXNUnicodeTextData = FOUR_CHAR_CODE('utxt')
+kTXNLineDirectionTag = FOUR_CHAR_CODE('lndr')
+kTXNJustificationTag = FOUR_CHAR_CODE('just')
+kTXNIOPrivilegesTag = FOUR_CHAR_CODE('iopv')
+kTXNSelectionStateTag = FOUR_CHAR_CODE('slst')
+kTXNInlineStateTag = FOUR_CHAR_CODE('inst')
+kTXNWordWrapStateTag = FOUR_CHAR_CODE('wwrs')
+kTXNKeyboardSyncStateTag = FOUR_CHAR_CODE('kbsy')
+kTXNAutoIndentStateTag = FOUR_CHAR_CODE('auin')
+kTXNTabSettingsTag = FOUR_CHAR_CODE('tabs')
+kTXNRefConTag = FOUR_CHAR_CODE('rfcn')
+kTXNMarginsTag = FOUR_CHAR_CODE('marg')
+kTXNNoUserIOTag = FOUR_CHAR_CODE('nuio')
+kTXNTypingAction = 0
+kTXNCutAction = 1
+kTXNPasteAction = 2
+kTXNClearAction = 3
+kTXNChangeFontAction = 4
+kTXNChangeFontColorAction = 5
+kTXNChangeFontSizeAction = 6
+kTXNChangeStyleAction = 7
+kTXNAlignLeftAction = 8
+kTXNAlignCenterAction = 9
+kTXNAlignRightAction = 10
+kTXNDropAction = 11
+kTXNMoveAction = 12
+kTXNFontFeatureAction = 13
+kTXNFontVariationAction = 14
+kTXNUndoLastAction = 1024
+# kTXNClearThisControl = (long)0xFFFFFFFF
+# kTXNClearTheseFontFeatures = (long)0x80000000
+kTXNReadWrite = false
+kTXNReadOnly = true
+kTXNSelectionOn = true
+kTXNSelectionOff = false
+kTXNUseInline = false
+kTXNUseBottomline = true
+kTXNAutoWrap = false
+kTXNNoAutoWrap = true
+kTXNSyncKeyboard = false
+kTXNNoSyncKeyboard = true
+kTXNAutoIndentOff = false
+kTXNAutoIndentOn = true
+kTXNRightTab = -1
+kTXNLeftTab = 0
+kTXNCenterTab = 1
+kTXNLeftToRight = 0
+kTXNRightToLeft = 1
+kTXNFlushDefault = 0
+kTXNFlushLeft = 1
+kTXNFlushRight = 2
+kTXNCenter = 4
+kTXNFullJust = 8
+kTXNForceFullJust = 16
+kScrollBarsAlwaysActive = true
+kScrollBarsSyncWithFocus = false
+# kTXNDontCareTypeSize = (long)0xFFFFFFFF
+kTXNDontCareTypeStyle = 0xFF
+kTXNIncrementTypeSize = 0x00000001
+# kTXNDecrementTypeSize = (long)0x80000000
+# kTXNUseCurrentSelection = 0xFFFFFFFFUL
+# kTXNStartOffset = 0UL
+# kTXNEndOffset = 0x7FFFFFFFUL
+kTXNSingleStylePerTextDocumentResType = FOUR_CHAR_CODE('MPSR')
+kTXNMultipleStylesPerTextDocumentResType = FOUR_CHAR_CODE('styl')
+kTXNShowStart = false
+kTXNShowEnd = true
+kTXNQDFontNameAttribute = FOUR_CHAR_CODE('fntn')
+kTXNQDFontFamilyIDAttribute = FOUR_CHAR_CODE('font')
+kTXNQDFontSizeAttribute = FOUR_CHAR_CODE('size')
+kTXNQDFontStyleAttribute = FOUR_CHAR_CODE('face')
+kTXNQDFontColorAttribute = FOUR_CHAR_CODE('klor')
+kTXNTextEncodingAttribute = FOUR_CHAR_CODE('encd')
+kTXNATSUIFontFeaturesAttribute = FOUR_CHAR_CODE('atfe')
+kTXNATSUIFontVariationsAttribute = FOUR_CHAR_CODE('atva')
+# kTXNQDFontNameAttributeSize = sizeof(Str255)
+# kTXNQDFontFamilyIDAttributeSize = sizeof(SInt16)
+# kTXNQDFontSizeAttributeSize = sizeof(SInt16)
+# kTXNQDFontStyleAttributeSize = sizeof(Style)
+# kTXNQDFontColorAttributeSize = sizeof(RGBColor)
+# kTXNTextEncodingAttributeSize = sizeof(TextEncoding)
+kTXNSystemDefaultEncoding = 0
+kTXNMacOSEncoding = 1
+kTXNUnicodeEncoding = 2
+kTXNBackgroundTypeRGB = 1
+# status = TXNInitTextension( &defaults
+# justification = LMTESysJust
--- /dev/null
+
+/* =========================== Module CF ============================ */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+/* Macro to test whether a weak-loaded CFM function exists */
+#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
+ }} while(0)
+
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <CFBase.h>
+#include <CFArray.h>
+#include <CFData.h>
+#include <CFDictionary.h>
+#include <CFString.h>
+#include <CFURL.h>
+#else
+#include <CoreFoundation.h>
+#endif
+
+/* For now we declare them forward here. They'll go to mactoolbox later */
+staticforward PyObject *CFTypeRefObj_New(CFTypeRef);
+staticforward int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
+staticforward PyObject *CFStringRefObj_New(CFStringRef);
+staticforward int CFStringRefObj_Convert(PyObject *, CFStringRef *);
+staticforward PyObject *CFURLRefObj_New(CFURLRef);
+staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
+
+staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
+
+// ADD declarations
+#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
+//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
+//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
+
+//#define CFTypeRefObj_New _CFTypeRefObj_New
+//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
+#endif
+
+/*
+** Parse/generate CFRange records
+*/
+PyObject *CFRange_New(CFRange *itself)
+{
+
+ return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
+}
+
+CFRange_Convert(PyObject *v, CFRange *p_itself)
+{
+ long location, length;
+
+ if( !PyArg_ParseTuple(v, "ll", &location, &length) )
+ return 0;
+ p_itself->location = (CFIndex)location;
+ p_itself->length = (CFIndex)length;
+ return 1;
+}
+
+/* Optional CFURL argument or None (passed as NULL) */
+int
+OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
+{
+ if ( v == Py_None ) {
+ p_itself = NULL;
+ return 1;
+ }
+ return CFURLRefObj_Convert(v, p_itself);
+}
+
+
+static PyObject *CF_Error;
+
+/* --------------------- Object type CFTypeRef ---------------------- */
+
+PyTypeObject CFTypeRef_Type;
+
+#define CFTypeRefObj_Check(x) ((x)->ob_type == &CFTypeRef_Type)
+
+typedef struct CFTypeRefObject {
+ PyObject_HEAD
+ CFTypeRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFTypeRefObject;
+
+PyObject *CFTypeRefObj_New(CFTypeRef itself)
+{
+ CFTypeRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFTypeRefObject, &CFTypeRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFTypeRefObj_Convert(PyObject *v, CFTypeRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFTypeRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFTypeRef required");
+ return 0;
+ }
+ *p_itself = ((CFTypeRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFTypeRefObj_dealloc(CFTypeRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFTypeRefObj_CFGetTypeID(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFGetTypeID(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFRetain(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeRef _rv;
+ PyMac_PRECHECK(CFRetain);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFRetain(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFTypeRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFRelease(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(CFRelease);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CFRelease(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFGetRetainCount(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ PyMac_PRECHECK(CFGetRetainCount);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFGetRetainCount(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFEqual(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CFTypeRef cf2;
+ PyMac_PRECHECK(CFEqual);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFTypeRefObj_Convert, &cf2))
+ return NULL;
+ _rv = CFEqual(_self->ob_itself,
+ cf2);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFHash(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFHashCode _rv;
+ PyMac_PRECHECK(CFHash);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFHash(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFCopyDescription(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFCopyDescription);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFCopyDescription(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFTypeRefObj_CFShow(CFTypeRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(CFShow);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CFShow(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef CFTypeRefObj_methods[] = {
+ {"CFGetTypeID", (PyCFunction)CFTypeRefObj_CFGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFRetain", (PyCFunction)CFTypeRefObj_CFRetain, 1,
+ "() -> (CFTypeRef _rv)"},
+ {"CFRelease", (PyCFunction)CFTypeRefObj_CFRelease, 1,
+ "() -> None"},
+ {"CFGetRetainCount", (PyCFunction)CFTypeRefObj_CFGetRetainCount, 1,
+ "() -> (CFIndex _rv)"},
+ {"CFEqual", (PyCFunction)CFTypeRefObj_CFEqual, 1,
+ "(CFTypeRef cf2) -> (Boolean _rv)"},
+ {"CFHash", (PyCFunction)CFTypeRefObj_CFHash, 1,
+ "() -> (CFHashCode _rv)"},
+ {"CFCopyDescription", (PyCFunction)CFTypeRefObj_CFCopyDescription, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFShow", (PyCFunction)CFTypeRefObj_CFShow, 1,
+ "() -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFTypeRefObj_chain = { CFTypeRefObj_methods, NULL };
+
+static PyObject *CFTypeRefObj_getattr(CFTypeRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFTypeRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFTypeRefObj_setattr NULL
+
+static int CFTypeRefObj_compare(CFTypeRefObject *self, CFTypeRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFTypeRefObj_repr(CFTypeRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFTypeRef type-%d object at 0x%08.8x for 0x%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFTypeRefObj_hash(CFTypeRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFTypeRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFTypeRef", /*tp_name*/
+ sizeof(CFTypeRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFTypeRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFTypeRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFTypeRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFTypeRefObj_compare, /*tp_compare*/
+ (reprfunc) CFTypeRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFTypeRefObj_hash, /*tp_hash*/
+};
+
+/* ------------------- End object type CFTypeRef -------------------- */
+
+
+/* --------------------- Object type CFArrayRef --------------------- */
+
+PyTypeObject CFArrayRef_Type;
+
+#define CFArrayRefObj_Check(x) ((x)->ob_type == &CFArrayRef_Type)
+
+typedef struct CFArrayRefObject {
+ PyObject_HEAD
+ CFArrayRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFArrayRefObject;
+
+PyObject *CFArrayRefObj_New(CFArrayRef itself)
+{
+ CFArrayRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFArrayRefObject, &CFArrayRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFArrayRefObj_Convert(PyObject *v, CFArrayRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFArrayRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFArrayRef required");
+ return 0;
+ }
+ *p_itself = ((CFArrayRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFArrayRefObj_dealloc(CFArrayRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFArrayRefObj_CFArrayCreateCopy(CFArrayRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFArrayRef _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFArrayCreateCopy((CFAllocatorRef)NULL,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFArrayRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFArrayRefObj_CFArrayGetCount(CFArrayRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ PyMac_PRECHECK(CFArrayGetCount);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFArrayGetCount(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFArrayRefObj_CFStringCreateByCombiningStrings(CFArrayRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringRef separatorString;
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &separatorString))
+ return NULL;
+ _rv = CFStringCreateByCombiningStrings((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ separatorString);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyMethodDef CFArrayRefObj_methods[] = {
+ {"CFArrayCreateCopy", (PyCFunction)CFArrayRefObj_CFArrayCreateCopy, 1,
+ "() -> (CFArrayRef _rv)"},
+ {"CFArrayGetCount", (PyCFunction)CFArrayRefObj_CFArrayGetCount, 1,
+ "() -> (CFIndex _rv)"},
+ {"CFStringCreateByCombiningStrings", (PyCFunction)CFArrayRefObj_CFStringCreateByCombiningStrings, 1,
+ "(CFStringRef separatorString) -> (CFStringRef _rv)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFArrayRefObj_chain = { CFArrayRefObj_methods, &CFTypeRefObj_chain };
+
+static PyObject *CFArrayRefObj_getattr(CFArrayRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFArrayRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFArrayRefObj_setattr NULL
+
+static int CFArrayRefObj_compare(CFArrayRefObject *self, CFArrayRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFArrayRefObj_repr(CFArrayRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFArrayRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFArrayRefObj_hash(CFArrayRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFArrayRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFArrayRef", /*tp_name*/
+ sizeof(CFArrayRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFArrayRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFArrayRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFArrayRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFArrayRefObj_compare, /*tp_compare*/
+ (reprfunc) CFArrayRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFArrayRefObj_hash, /*tp_hash*/
+};
+
+/* ------------------- End object type CFArrayRef ------------------- */
+
+
+/* ----------------- Object type CFMutableArrayRef ------------------ */
+
+PyTypeObject CFMutableArrayRef_Type;
+
+#define CFMutableArrayRefObj_Check(x) ((x)->ob_type == &CFMutableArrayRef_Type)
+
+typedef struct CFMutableArrayRefObject {
+ PyObject_HEAD
+ CFMutableArrayRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFMutableArrayRefObject;
+
+PyObject *CFMutableArrayRefObj_New(CFMutableArrayRef itself)
+{
+ CFMutableArrayRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFMutableArrayRefObject, &CFMutableArrayRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFMutableArrayRefObj_Convert(PyObject *v, CFMutableArrayRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFMutableArrayRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFMutableArrayRef required");
+ return 0;
+ }
+ *p_itself = ((CFMutableArrayRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFMutableArrayRefObj_dealloc(CFMutableArrayRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFMutableArrayRefObj_CFArrayRemoveValueAtIndex(CFMutableArrayRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex idx;
+ PyMac_PRECHECK(CFArrayRemoveValueAtIndex);
+ if (!PyArg_ParseTuple(_args, "l",
+ &idx))
+ return NULL;
+ CFArrayRemoveValueAtIndex(_self->ob_itself,
+ idx);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableArrayRefObj_CFArrayRemoveAllValues(CFMutableArrayRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(CFArrayRemoveAllValues);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CFArrayRemoveAllValues(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices(CFMutableArrayRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex idx1;
+ CFIndex idx2;
+ PyMac_PRECHECK(CFArrayExchangeValuesAtIndices);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &idx1,
+ &idx2))
+ return NULL;
+ CFArrayExchangeValuesAtIndices(_self->ob_itself,
+ idx1,
+ idx2);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef CFMutableArrayRefObj_methods[] = {
+ {"CFArrayRemoveValueAtIndex", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveValueAtIndex, 1,
+ "(CFIndex idx) -> None"},
+ {"CFArrayRemoveAllValues", (PyCFunction)CFMutableArrayRefObj_CFArrayRemoveAllValues, 1,
+ "() -> None"},
+ {"CFArrayExchangeValuesAtIndices", (PyCFunction)CFMutableArrayRefObj_CFArrayExchangeValuesAtIndices, 1,
+ "(CFIndex idx1, CFIndex idx2) -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFMutableArrayRefObj_chain = { CFMutableArrayRefObj_methods, &CFArrayRefObj_chain };
+
+static PyObject *CFMutableArrayRefObj_getattr(CFMutableArrayRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFMutableArrayRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFMutableArrayRefObj_setattr NULL
+
+static int CFMutableArrayRefObj_compare(CFMutableArrayRefObject *self, CFMutableArrayRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFMutableArrayRefObj_repr(CFMutableArrayRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFMutableArrayRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFMutableArrayRefObj_hash(CFMutableArrayRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFMutableArrayRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFMutableArrayRef", /*tp_name*/
+ sizeof(CFMutableArrayRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFMutableArrayRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFMutableArrayRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFMutableArrayRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFMutableArrayRefObj_compare, /*tp_compare*/
+ (reprfunc) CFMutableArrayRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFMutableArrayRefObj_hash, /*tp_hash*/
+};
+
+/* --------------- End object type CFMutableArrayRef ---------------- */
+
+
+/* ------------------ Object type CFDictionaryRef ------------------- */
+
+PyTypeObject CFDictionaryRef_Type;
+
+#define CFDictionaryRefObj_Check(x) ((x)->ob_type == &CFDictionaryRef_Type)
+
+typedef struct CFDictionaryRefObject {
+ PyObject_HEAD
+ CFDictionaryRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFDictionaryRefObject;
+
+PyObject *CFDictionaryRefObj_New(CFDictionaryRef itself)
+{
+ CFDictionaryRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFDictionaryRefObject, &CFDictionaryRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFDictionaryRefObj_Convert(PyObject *v, CFDictionaryRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFDictionaryRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFDictionaryRef required");
+ return 0;
+ }
+ *p_itself = ((CFDictionaryRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFDictionaryRefObj_dealloc(CFDictionaryRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFDictionaryRefObj_CFDictionaryCreateCopy(CFDictionaryRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFDictionaryRef _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFDictionaryCreateCopy((CFAllocatorRef)NULL,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFDictionaryRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFDictionaryRefObj_CFDictionaryGetCount(CFDictionaryRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ PyMac_PRECHECK(CFDictionaryGetCount);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFDictionaryGetCount(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyMethodDef CFDictionaryRefObj_methods[] = {
+ {"CFDictionaryCreateCopy", (PyCFunction)CFDictionaryRefObj_CFDictionaryCreateCopy, 1,
+ "() -> (CFDictionaryRef _rv)"},
+ {"CFDictionaryGetCount", (PyCFunction)CFDictionaryRefObj_CFDictionaryGetCount, 1,
+ "() -> (CFIndex _rv)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFDictionaryRefObj_chain = { CFDictionaryRefObj_methods, &CFTypeRefObj_chain };
+
+static PyObject *CFDictionaryRefObj_getattr(CFDictionaryRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFDictionaryRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFDictionaryRefObj_setattr NULL
+
+static int CFDictionaryRefObj_compare(CFDictionaryRefObject *self, CFDictionaryRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFDictionaryRefObj_repr(CFDictionaryRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFDictionaryRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFDictionaryRefObj_hash(CFDictionaryRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFDictionaryRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFDictionaryRef", /*tp_name*/
+ sizeof(CFDictionaryRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFDictionaryRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFDictionaryRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFDictionaryRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFDictionaryRefObj_compare, /*tp_compare*/
+ (reprfunc) CFDictionaryRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFDictionaryRefObj_hash, /*tp_hash*/
+};
+
+/* ---------------- End object type CFDictionaryRef ----------------- */
+
+
+/* --------------- Object type CFMutableDictionaryRef --------------- */
+
+PyTypeObject CFMutableDictionaryRef_Type;
+
+#define CFMutableDictionaryRefObj_Check(x) ((x)->ob_type == &CFMutableDictionaryRef_Type)
+
+typedef struct CFMutableDictionaryRefObject {
+ PyObject_HEAD
+ CFMutableDictionaryRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFMutableDictionaryRefObject;
+
+PyObject *CFMutableDictionaryRefObj_New(CFMutableDictionaryRef itself)
+{
+ CFMutableDictionaryRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFMutableDictionaryRefObject, &CFMutableDictionaryRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFMutableDictionaryRefObj_Convert(PyObject *v, CFMutableDictionaryRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFMutableDictionaryRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFMutableDictionaryRef required");
+ return 0;
+ }
+ *p_itself = ((CFMutableDictionaryRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFMutableDictionaryRefObj_dealloc(CFMutableDictionaryRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues(CFMutableDictionaryRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(CFDictionaryRemoveAllValues);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CFDictionaryRemoveAllValues(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef CFMutableDictionaryRefObj_methods[] = {
+ {"CFDictionaryRemoveAllValues", (PyCFunction)CFMutableDictionaryRefObj_CFDictionaryRemoveAllValues, 1,
+ "() -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFMutableDictionaryRefObj_chain = { CFMutableDictionaryRefObj_methods, &CFDictionaryRefObj_chain };
+
+static PyObject *CFMutableDictionaryRefObj_getattr(CFMutableDictionaryRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFMutableDictionaryRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFMutableDictionaryRefObj_setattr NULL
+
+static int CFMutableDictionaryRefObj_compare(CFMutableDictionaryRefObject *self, CFMutableDictionaryRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFMutableDictionaryRefObj_repr(CFMutableDictionaryRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFMutableDictionaryRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFMutableDictionaryRefObj_hash(CFMutableDictionaryRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFMutableDictionaryRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFMutableDictionaryRef", /*tp_name*/
+ sizeof(CFMutableDictionaryRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFMutableDictionaryRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFMutableDictionaryRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFMutableDictionaryRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFMutableDictionaryRefObj_compare, /*tp_compare*/
+ (reprfunc) CFMutableDictionaryRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFMutableDictionaryRefObj_hash, /*tp_hash*/
+};
+
+/* ------------- End object type CFMutableDictionaryRef ------------- */
+
+
+/* --------------------- Object type CFDataRef ---------------------- */
+
+PyTypeObject CFDataRef_Type;
+
+#define CFDataRefObj_Check(x) ((x)->ob_type == &CFDataRef_Type)
+
+typedef struct CFDataRefObject {
+ PyObject_HEAD
+ CFDataRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFDataRefObject;
+
+PyObject *CFDataRefObj_New(CFDataRef itself)
+{
+ CFDataRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFDataRefObject, &CFDataRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFDataRefObj_Convert(PyObject *v, CFDataRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFDataRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFDataRef required");
+ return 0;
+ }
+ *p_itself = ((CFDataRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFDataRefObj_dealloc(CFDataRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFDataRefObj_CFDataCreateCopy(CFDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFDataRef _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFDataCreateCopy((CFAllocatorRef)NULL,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFDataRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFDataRefObj_CFDataGetLength(CFDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ PyMac_PRECHECK(CFDataGetLength);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFDataGetLength(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFDataRefObj_CFStringCreateFromExternalRepresentation(CFDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringEncoding encoding;
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringCreateFromExternalRepresentation((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ encoding);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyMethodDef CFDataRefObj_methods[] = {
+ {"CFDataCreateCopy", (PyCFunction)CFDataRefObj_CFDataCreateCopy, 1,
+ "() -> (CFDataRef _rv)"},
+ {"CFDataGetLength", (PyCFunction)CFDataRefObj_CFDataGetLength, 1,
+ "() -> (CFIndex _rv)"},
+ {"CFStringCreateFromExternalRepresentation", (PyCFunction)CFDataRefObj_CFStringCreateFromExternalRepresentation, 1,
+ "(CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFDataRefObj_chain = { CFDataRefObj_methods, &CFTypeRefObj_chain };
+
+static PyObject *CFDataRefObj_getattr(CFDataRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFDataRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFDataRefObj_setattr NULL
+
+static int CFDataRefObj_compare(CFDataRefObject *self, CFDataRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFDataRefObj_repr(CFDataRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFDataRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFDataRefObj_hash(CFDataRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFDataRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFDataRef", /*tp_name*/
+ sizeof(CFDataRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFDataRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFDataRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFDataRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFDataRefObj_compare, /*tp_compare*/
+ (reprfunc) CFDataRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFDataRefObj_hash, /*tp_hash*/
+};
+
+/* ------------------- End object type CFDataRef -------------------- */
+
+
+/* ------------------ Object type CFMutableDataRef ------------------ */
+
+PyTypeObject CFMutableDataRef_Type;
+
+#define CFMutableDataRefObj_Check(x) ((x)->ob_type == &CFMutableDataRef_Type)
+
+typedef struct CFMutableDataRefObject {
+ PyObject_HEAD
+ CFMutableDataRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFMutableDataRefObject;
+
+PyObject *CFMutableDataRefObj_New(CFMutableDataRef itself)
+{
+ CFMutableDataRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFMutableDataRefObject, &CFMutableDataRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFMutableDataRefObj_Convert(PyObject *v, CFMutableDataRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFMutableDataRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFMutableDataRef required");
+ return 0;
+ }
+ *p_itself = ((CFMutableDataRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFMutableDataRefObj_dealloc(CFMutableDataRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFMutableDataRefObj_CFDataSetLength(CFMutableDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex length;
+ PyMac_PRECHECK(CFDataSetLength);
+ if (!PyArg_ParseTuple(_args, "l",
+ &length))
+ return NULL;
+ CFDataSetLength(_self->ob_itself,
+ length);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableDataRefObj_CFDataIncreaseLength(CFMutableDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex extraLength;
+ PyMac_PRECHECK(CFDataIncreaseLength);
+ if (!PyArg_ParseTuple(_args, "l",
+ &extraLength))
+ return NULL;
+ CFDataIncreaseLength(_self->ob_itself,
+ extraLength);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableDataRefObj_CFDataAppendBytes(CFMutableDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ unsigned char *bytes__in__;
+ long bytes__len__;
+ int bytes__in_len__;
+ PyMac_PRECHECK(CFDataAppendBytes);
+ if (!PyArg_ParseTuple(_args, "s#",
+ &bytes__in__, &bytes__in_len__))
+ return NULL;
+ bytes__len__ = bytes__in_len__;
+ CFDataAppendBytes(_self->ob_itself,
+ bytes__in__, bytes__len__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ bytes__error__: ;
+ return _res;
+}
+
+static PyObject *CFMutableDataRefObj_CFDataReplaceBytes(CFMutableDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFRange range;
+ unsigned char *newBytes__in__;
+ long newBytes__len__;
+ int newBytes__in_len__;
+ PyMac_PRECHECK(CFDataReplaceBytes);
+ if (!PyArg_ParseTuple(_args, "O&s#",
+ CFRange_Convert, &range,
+ &newBytes__in__, &newBytes__in_len__))
+ return NULL;
+ newBytes__len__ = newBytes__in_len__;
+ CFDataReplaceBytes(_self->ob_itself,
+ range,
+ newBytes__in__, newBytes__len__);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ newBytes__error__: ;
+ return _res;
+}
+
+static PyObject *CFMutableDataRefObj_CFDataDeleteBytes(CFMutableDataRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFRange range;
+ PyMac_PRECHECK(CFDataDeleteBytes);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFRange_Convert, &range))
+ return NULL;
+ CFDataDeleteBytes(_self->ob_itself,
+ range);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef CFMutableDataRefObj_methods[] = {
+ {"CFDataSetLength", (PyCFunction)CFMutableDataRefObj_CFDataSetLength, 1,
+ "(CFIndex length) -> None"},
+ {"CFDataIncreaseLength", (PyCFunction)CFMutableDataRefObj_CFDataIncreaseLength, 1,
+ "(CFIndex extraLength) -> None"},
+ {"CFDataAppendBytes", (PyCFunction)CFMutableDataRefObj_CFDataAppendBytes, 1,
+ "(Buffer bytes) -> None"},
+ {"CFDataReplaceBytes", (PyCFunction)CFMutableDataRefObj_CFDataReplaceBytes, 1,
+ "(CFRange range, Buffer newBytes) -> None"},
+ {"CFDataDeleteBytes", (PyCFunction)CFMutableDataRefObj_CFDataDeleteBytes, 1,
+ "(CFRange range) -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFMutableDataRefObj_chain = { CFMutableDataRefObj_methods, &CFDataRefObj_chain };
+
+static PyObject *CFMutableDataRefObj_getattr(CFMutableDataRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFMutableDataRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFMutableDataRefObj_setattr NULL
+
+static int CFMutableDataRefObj_compare(CFMutableDataRefObject *self, CFMutableDataRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFMutableDataRefObj_repr(CFMutableDataRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFMutableDataRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFMutableDataRefObj_hash(CFMutableDataRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFMutableDataRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFMutableDataRef", /*tp_name*/
+ sizeof(CFMutableDataRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFMutableDataRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFMutableDataRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFMutableDataRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFMutableDataRefObj_compare, /*tp_compare*/
+ (reprfunc) CFMutableDataRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFMutableDataRefObj_hash, /*tp_hash*/
+};
+
+/* ---------------- End object type CFMutableDataRef ---------------- */
+
+
+/* -------------------- Object type CFStringRef --------------------- */
+
+PyTypeObject CFStringRef_Type;
+
+#define CFStringRefObj_Check(x) ((x)->ob_type == &CFStringRef_Type)
+
+typedef struct CFStringRefObject {
+ PyObject_HEAD
+ CFStringRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFStringRefObject;
+
+PyObject *CFStringRefObj_New(CFStringRef itself)
+{
+ CFStringRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFStringRefObject, &CFStringRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFStringRefObj_Convert(PyObject *v, CFStringRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ if (PyString_Check(v)) {
+ char *cStr = PyString_AsString(v);
+ *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
+ return 1;
+ }
+ if (PyUnicode_Check(v)) {
+ /* We use the CF types here, if Python was configured differently that will give an error */
+ CFIndex size = PyUnicode_GetSize(v);
+ UniChar *unichars = PyUnicode_AsUnicode(v);
+ if (!unichars) return 0;
+ *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
+ return 1;
+ }
+
+
+ if (!CFStringRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFStringRef required");
+ return 0;
+ }
+ *p_itself = ((CFStringRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFStringRefObj_dealloc(CFStringRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFStringRefObj_CFStringCreateWithSubstring(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFRange range;
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFRange_Convert, &range))
+ return NULL;
+ _rv = CFStringCreateWithSubstring((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ range);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringCreateCopy(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringCreateCopy((CFAllocatorRef)NULL,
+ _self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetLength(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ PyMac_PRECHECK(CFStringGetLength);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetLength(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetBytes(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ CFRange range;
+ CFStringEncoding encoding;
+ UInt8 lossByte;
+ Boolean isExternalRepresentation;
+ UInt8 buffer;
+ CFIndex maxBufLen;
+ CFIndex usedBufLen;
+ PyMac_PRECHECK(CFStringGetBytes);
+ if (!PyArg_ParseTuple(_args, "O&lbll",
+ CFRange_Convert, &range,
+ &encoding,
+ &lossByte,
+ &isExternalRepresentation,
+ &maxBufLen))
+ return NULL;
+ _rv = CFStringGetBytes(_self->ob_itself,
+ range,
+ encoding,
+ lossByte,
+ isExternalRepresentation,
+ &buffer,
+ maxBufLen,
+ &usedBufLen);
+ _res = Py_BuildValue("lbl",
+ _rv,
+ buffer,
+ usedBufLen);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringCreateExternalRepresentation(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFDataRef _rv;
+ CFStringEncoding encoding;
+ UInt8 lossByte;
+ if (!PyArg_ParseTuple(_args, "lb",
+ &encoding,
+ &lossByte))
+ return NULL;
+ _rv = CFStringCreateExternalRepresentation((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ encoding,
+ lossByte);
+ _res = Py_BuildValue("O&",
+ CFDataRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetSmallestEncoding(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringEncoding _rv;
+ PyMac_PRECHECK(CFStringGetSmallestEncoding);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetSmallestEncoding(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetFastestEncoding(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringEncoding _rv;
+ PyMac_PRECHECK(CFStringGetFastestEncoding);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetFastestEncoding(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringCompareWithOptions(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFComparisonResult _rv;
+ CFStringRef string2;
+ CFRange rangeToCompare;
+ CFOptionFlags compareOptions;
+ PyMac_PRECHECK(CFStringCompareWithOptions);
+ if (!PyArg_ParseTuple(_args, "O&O&l",
+ CFStringRefObj_Convert, &string2,
+ CFRange_Convert, &rangeToCompare,
+ &compareOptions))
+ return NULL;
+ _rv = CFStringCompareWithOptions(_self->ob_itself,
+ string2,
+ rangeToCompare,
+ compareOptions);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringCompare(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFComparisonResult _rv;
+ CFStringRef string2;
+ CFOptionFlags compareOptions;
+ PyMac_PRECHECK(CFStringCompare);
+ if (!PyArg_ParseTuple(_args, "O&l",
+ CFStringRefObj_Convert, &string2,
+ &compareOptions))
+ return NULL;
+ _rv = CFStringCompare(_self->ob_itself,
+ string2,
+ compareOptions);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringFindWithOptions(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CFStringRef stringToFind;
+ CFRange rangeToSearch;
+ CFOptionFlags searchOptions;
+ CFRange result;
+ PyMac_PRECHECK(CFStringFindWithOptions);
+ if (!PyArg_ParseTuple(_args, "O&O&l",
+ CFStringRefObj_Convert, &stringToFind,
+ CFRange_Convert, &rangeToSearch,
+ &searchOptions))
+ return NULL;
+ _rv = CFStringFindWithOptions(_self->ob_itself,
+ stringToFind,
+ rangeToSearch,
+ searchOptions,
+ &result);
+ _res = Py_BuildValue("lO&",
+ _rv,
+ CFRange_New, result);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringCreateArrayWithFindResults(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFArrayRef _rv;
+ CFStringRef stringToFind;
+ CFRange rangeToSearch;
+ CFOptionFlags compareOptions;
+ if (!PyArg_ParseTuple(_args, "O&O&l",
+ CFStringRefObj_Convert, &stringToFind,
+ CFRange_Convert, &rangeToSearch,
+ &compareOptions))
+ return NULL;
+ _rv = CFStringCreateArrayWithFindResults((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ stringToFind,
+ rangeToSearch,
+ compareOptions);
+ _res = Py_BuildValue("O&",
+ CFArrayRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringFind(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFRange _rv;
+ CFStringRef stringToFind;
+ CFOptionFlags compareOptions;
+ PyMac_PRECHECK(CFStringFind);
+ if (!PyArg_ParseTuple(_args, "O&l",
+ CFStringRefObj_Convert, &stringToFind,
+ &compareOptions))
+ return NULL;
+ _rv = CFStringFind(_self->ob_itself,
+ stringToFind,
+ compareOptions);
+ _res = Py_BuildValue("O&",
+ CFRange_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringHasPrefix(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CFStringRef prefix;
+ PyMac_PRECHECK(CFStringHasPrefix);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &prefix))
+ return NULL;
+ _rv = CFStringHasPrefix(_self->ob_itself,
+ prefix);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringHasSuffix(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CFStringRef suffix;
+ PyMac_PRECHECK(CFStringHasSuffix);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &suffix))
+ return NULL;
+ _rv = CFStringHasSuffix(_self->ob_itself,
+ suffix);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetLineBounds(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFRange range;
+ CFIndex lineBeginIndex;
+ CFIndex lineEndIndex;
+ CFIndex contentsEndIndex;
+ PyMac_PRECHECK(CFStringGetLineBounds);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFRange_Convert, &range))
+ return NULL;
+ CFStringGetLineBounds(_self->ob_itself,
+ range,
+ &lineBeginIndex,
+ &lineEndIndex,
+ &contentsEndIndex);
+ _res = Py_BuildValue("lll",
+ lineBeginIndex,
+ lineEndIndex,
+ contentsEndIndex);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringCreateArrayBySeparatingStrings(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFArrayRef _rv;
+ CFStringRef separatorString;
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &separatorString))
+ return NULL;
+ _rv = CFStringCreateArrayBySeparatingStrings((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ separatorString);
+ _res = Py_BuildValue("O&",
+ CFArrayRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetIntValue(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ PyMac_PRECHECK(CFStringGetIntValue);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetIntValue(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetDoubleValue(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ double _rv;
+ PyMac_PRECHECK(CFStringGetDoubleValue);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetDoubleValue(_self->ob_itself);
+ _res = Py_BuildValue("d",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringConvertIANACharSetNameToEncoding(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringEncoding _rv;
+ PyMac_PRECHECK(CFStringConvertIANACharSetNameToEncoding);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringConvertIANACharSetNameToEncoding(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFShowStr(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(CFShowStr);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CFShowStr(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFURLCreateWithString(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFURLRef _rv;
+ CFURLRef baseURL;
+ if (!PyArg_ParseTuple(_args, "O&",
+ OptionalCFURLRefObj_Convert, &baseURL))
+ return NULL;
+ _rv = CFURLCreateWithString((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ baseURL);
+ _res = Py_BuildValue("O&",
+ CFURLRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFURLCreateWithFileSystemPath(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFURLRef _rv;
+ CFURLPathStyle pathStyle;
+ Boolean isDirectory;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &pathStyle,
+ &isDirectory))
+ return NULL;
+ _rv = CFURLCreateWithFileSystemPath((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ pathStyle,
+ isDirectory);
+ _res = Py_BuildValue("O&",
+ CFURLRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringRef charactersToLeaveEscaped;
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &charactersToLeaveEscaped))
+ return NULL;
+ _rv = CFURLCreateStringByReplacingPercentEscapes((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ charactersToLeaveEscaped);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFStringRefObj_CFStringGetString(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ int size = CFStringGetLength(_self->ob_itself)+1;
+ char *data = malloc(size);
+
+ if( data == NULL ) return PyErr_NoMemory();
+ if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
+ _res = (PyObject *)PyString_FromString(data);
+ } else {
+ PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
+ _res = NULL;
+ }
+ free(data);
+ return _res;
+
+}
+
+static PyObject *CFStringRefObj_CFStringGetUnicode(CFStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ int size = CFStringGetLength(_self->ob_itself)+1;
+ Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
+ CFRange range;
+
+ range.location = 0;
+ range.length = size;
+ if( data == NULL ) return PyErr_NoMemory();
+ CFStringGetCharacters(_self->ob_itself, range, data);
+ _res = (PyObject *)PyUnicode_FromUnicode(data, size);
+ free(data);
+ return _res;
+
+}
+
+static PyMethodDef CFStringRefObj_methods[] = {
+ {"CFStringCreateWithSubstring", (PyCFunction)CFStringRefObj_CFStringCreateWithSubstring, 1,
+ "(CFRange range) -> (CFStringRef _rv)"},
+ {"CFStringCreateCopy", (PyCFunction)CFStringRefObj_CFStringCreateCopy, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFStringGetLength", (PyCFunction)CFStringRefObj_CFStringGetLength, 1,
+ "() -> (CFIndex _rv)"},
+ {"CFStringGetBytes", (PyCFunction)CFStringRefObj_CFStringGetBytes, 1,
+ "(CFRange range, CFStringEncoding encoding, UInt8 lossByte, Boolean isExternalRepresentation, CFIndex maxBufLen) -> (CFIndex _rv, UInt8 buffer, CFIndex usedBufLen)"},
+ {"CFStringCreateExternalRepresentation", (PyCFunction)CFStringRefObj_CFStringCreateExternalRepresentation, 1,
+ "(CFStringEncoding encoding, UInt8 lossByte) -> (CFDataRef _rv)"},
+ {"CFStringGetSmallestEncoding", (PyCFunction)CFStringRefObj_CFStringGetSmallestEncoding, 1,
+ "() -> (CFStringEncoding _rv)"},
+ {"CFStringGetFastestEncoding", (PyCFunction)CFStringRefObj_CFStringGetFastestEncoding, 1,
+ "() -> (CFStringEncoding _rv)"},
+ {"CFStringCompareWithOptions", (PyCFunction)CFStringRefObj_CFStringCompareWithOptions, 1,
+ "(CFStringRef string2, CFRange rangeToCompare, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"},
+ {"CFStringCompare", (PyCFunction)CFStringRefObj_CFStringCompare, 1,
+ "(CFStringRef string2, CFOptionFlags compareOptions) -> (CFComparisonResult _rv)"},
+ {"CFStringFindWithOptions", (PyCFunction)CFStringRefObj_CFStringFindWithOptions, 1,
+ "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags searchOptions) -> (Boolean _rv, CFRange result)"},
+ {"CFStringCreateArrayWithFindResults", (PyCFunction)CFStringRefObj_CFStringCreateArrayWithFindResults, 1,
+ "(CFStringRef stringToFind, CFRange rangeToSearch, CFOptionFlags compareOptions) -> (CFArrayRef _rv)"},
+ {"CFStringFind", (PyCFunction)CFStringRefObj_CFStringFind, 1,
+ "(CFStringRef stringToFind, CFOptionFlags compareOptions) -> (CFRange _rv)"},
+ {"CFStringHasPrefix", (PyCFunction)CFStringRefObj_CFStringHasPrefix, 1,
+ "(CFStringRef prefix) -> (Boolean _rv)"},
+ {"CFStringHasSuffix", (PyCFunction)CFStringRefObj_CFStringHasSuffix, 1,
+ "(CFStringRef suffix) -> (Boolean _rv)"},
+ {"CFStringGetLineBounds", (PyCFunction)CFStringRefObj_CFStringGetLineBounds, 1,
+ "(CFRange range) -> (CFIndex lineBeginIndex, CFIndex lineEndIndex, CFIndex contentsEndIndex)"},
+ {"CFStringCreateArrayBySeparatingStrings", (PyCFunction)CFStringRefObj_CFStringCreateArrayBySeparatingStrings, 1,
+ "(CFStringRef separatorString) -> (CFArrayRef _rv)"},
+ {"CFStringGetIntValue", (PyCFunction)CFStringRefObj_CFStringGetIntValue, 1,
+ "() -> (SInt32 _rv)"},
+ {"CFStringGetDoubleValue", (PyCFunction)CFStringRefObj_CFStringGetDoubleValue, 1,
+ "() -> (double _rv)"},
+ {"CFStringConvertIANACharSetNameToEncoding", (PyCFunction)CFStringRefObj_CFStringConvertIANACharSetNameToEncoding, 1,
+ "() -> (CFStringEncoding _rv)"},
+ {"CFShowStr", (PyCFunction)CFStringRefObj_CFShowStr, 1,
+ "() -> None"},
+ {"CFURLCreateWithString", (PyCFunction)CFStringRefObj_CFURLCreateWithString, 1,
+ "(CFURLRef baseURL) -> (CFURLRef _rv)"},
+ {"CFURLCreateWithFileSystemPath", (PyCFunction)CFStringRefObj_CFURLCreateWithFileSystemPath, 1,
+ "(CFURLPathStyle pathStyle, Boolean isDirectory) -> (CFURLRef _rv)"},
+ {"CFURLCreateStringByReplacingPercentEscapes", (PyCFunction)CFStringRefObj_CFURLCreateStringByReplacingPercentEscapes, 1,
+ "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
+ {"CFStringGetString", (PyCFunction)CFStringRefObj_CFStringGetString, 1,
+ "() -> (string _rv)"},
+ {"CFStringGetUnicode", (PyCFunction)CFStringRefObj_CFStringGetUnicode, 1,
+ "() -> (unicode _rv)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFStringRefObj_chain = { CFStringRefObj_methods, &CFTypeRefObj_chain };
+
+static PyObject *CFStringRefObj_getattr(CFStringRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFStringRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFStringRefObj_setattr NULL
+
+static int CFStringRefObj_compare(CFStringRefObject *self, CFStringRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFStringRefObj_repr(CFStringRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFStringRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFStringRefObj_hash(CFStringRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFStringRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFStringRef", /*tp_name*/
+ sizeof(CFStringRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFStringRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFStringRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFStringRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFStringRefObj_compare, /*tp_compare*/
+ (reprfunc) CFStringRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFStringRefObj_hash, /*tp_hash*/
+};
+
+/* ------------------ End object type CFStringRef ------------------- */
+
+
+/* ----------------- Object type CFMutableStringRef ----------------- */
+
+PyTypeObject CFMutableStringRef_Type;
+
+#define CFMutableStringRefObj_Check(x) ((x)->ob_type == &CFMutableStringRef_Type)
+
+typedef struct CFMutableStringRefObject {
+ PyObject_HEAD
+ CFMutableStringRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFMutableStringRefObject;
+
+PyObject *CFMutableStringRefObj_New(CFMutableStringRef itself)
+{
+ CFMutableStringRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFMutableStringRefObject, &CFMutableStringRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFMutableStringRefObj_Convert(PyObject *v, CFMutableStringRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFMutableStringRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFMutableStringRef required");
+ return 0;
+ }
+ *p_itself = ((CFMutableStringRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFMutableStringRefObj_dealloc(CFMutableStringRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFMutableStringRefObj_CFStringAppend(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef appendedString;
+ PyMac_PRECHECK(CFStringAppend);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &appendedString))
+ return NULL;
+ CFStringAppend(_self->ob_itself,
+ appendedString);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringAppendPascalString(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ StringPtr pStr;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringAppendPascalString);
+ if (!PyArg_ParseTuple(_args, "O&l",
+ PyMac_GetStr255, &pStr,
+ &encoding))
+ return NULL;
+ CFStringAppendPascalString(_self->ob_itself,
+ pStr,
+ encoding);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringAppendCString(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ char* cStr;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringAppendCString);
+ if (!PyArg_ParseTuple(_args, "sl",
+ &cStr,
+ &encoding))
+ return NULL;
+ CFStringAppendCString(_self->ob_itself,
+ cStr,
+ encoding);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringInsert(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex idx;
+ CFStringRef insertedStr;
+ PyMac_PRECHECK(CFStringInsert);
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &idx,
+ CFStringRefObj_Convert, &insertedStr))
+ return NULL;
+ CFStringInsert(_self->ob_itself,
+ idx,
+ insertedStr);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringDelete(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFRange range;
+ PyMac_PRECHECK(CFStringDelete);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFRange_Convert, &range))
+ return NULL;
+ CFStringDelete(_self->ob_itself,
+ range);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringReplace(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFRange range;
+ CFStringRef replacement;
+ PyMac_PRECHECK(CFStringReplace);
+ if (!PyArg_ParseTuple(_args, "O&O&",
+ CFRange_Convert, &range,
+ CFStringRefObj_Convert, &replacement))
+ return NULL;
+ CFStringReplace(_self->ob_itself,
+ range,
+ replacement);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringReplaceAll(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef replacement;
+ PyMac_PRECHECK(CFStringReplaceAll);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &replacement))
+ return NULL;
+ CFStringReplaceAll(_self->ob_itself,
+ replacement);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringPad(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef padString;
+ CFIndex length;
+ CFIndex indexIntoPad;
+ PyMac_PRECHECK(CFStringPad);
+ if (!PyArg_ParseTuple(_args, "O&ll",
+ CFStringRefObj_Convert, &padString,
+ &length,
+ &indexIntoPad))
+ return NULL;
+ CFStringPad(_self->ob_itself,
+ padString,
+ length,
+ indexIntoPad);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringTrim(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef trimString;
+ PyMac_PRECHECK(CFStringTrim);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &trimString))
+ return NULL;
+ CFStringTrim(_self->ob_itself,
+ trimString);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *CFMutableStringRefObj_CFStringTrimWhitespace(CFMutableStringRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(CFStringTrimWhitespace);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ CFStringTrimWhitespace(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef CFMutableStringRefObj_methods[] = {
+ {"CFStringAppend", (PyCFunction)CFMutableStringRefObj_CFStringAppend, 1,
+ "(CFStringRef appendedString) -> None"},
+ {"CFStringAppendPascalString", (PyCFunction)CFMutableStringRefObj_CFStringAppendPascalString, 1,
+ "(StringPtr pStr, CFStringEncoding encoding) -> None"},
+ {"CFStringAppendCString", (PyCFunction)CFMutableStringRefObj_CFStringAppendCString, 1,
+ "(char* cStr, CFStringEncoding encoding) -> None"},
+ {"CFStringInsert", (PyCFunction)CFMutableStringRefObj_CFStringInsert, 1,
+ "(CFIndex idx, CFStringRef insertedStr) -> None"},
+ {"CFStringDelete", (PyCFunction)CFMutableStringRefObj_CFStringDelete, 1,
+ "(CFRange range) -> None"},
+ {"CFStringReplace", (PyCFunction)CFMutableStringRefObj_CFStringReplace, 1,
+ "(CFRange range, CFStringRef replacement) -> None"},
+ {"CFStringReplaceAll", (PyCFunction)CFMutableStringRefObj_CFStringReplaceAll, 1,
+ "(CFStringRef replacement) -> None"},
+ {"CFStringPad", (PyCFunction)CFMutableStringRefObj_CFStringPad, 1,
+ "(CFStringRef padString, CFIndex length, CFIndex indexIntoPad) -> None"},
+ {"CFStringTrim", (PyCFunction)CFMutableStringRefObj_CFStringTrim, 1,
+ "(CFStringRef trimString) -> None"},
+ {"CFStringTrimWhitespace", (PyCFunction)CFMutableStringRefObj_CFStringTrimWhitespace, 1,
+ "() -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFMutableStringRefObj_chain = { CFMutableStringRefObj_methods, &CFStringRefObj_chain };
+
+static PyObject *CFMutableStringRefObj_getattr(CFMutableStringRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFMutableStringRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFMutableStringRefObj_setattr NULL
+
+static int CFMutableStringRefObj_compare(CFMutableStringRefObject *self, CFMutableStringRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFMutableStringRefObj_repr(CFMutableStringRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFMutableStringRef object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFMutableStringRefObj_hash(CFMutableStringRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFMutableStringRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFMutableStringRef", /*tp_name*/
+ sizeof(CFMutableStringRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFMutableStringRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFMutableStringRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFMutableStringRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFMutableStringRefObj_compare, /*tp_compare*/
+ (reprfunc) CFMutableStringRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFMutableStringRefObj_hash, /*tp_hash*/
+};
+
+/* --------------- End object type CFMutableStringRef --------------- */
+
+
+/* ---------------------- Object type CFURLRef ---------------------- */
+
+PyTypeObject CFURLRef_Type;
+
+#define CFURLRefObj_Check(x) ((x)->ob_type == &CFURLRef_Type)
+
+typedef struct CFURLRefObject {
+ PyObject_HEAD
+ CFURLRef ob_itself;
+ void (*ob_freeit)(CFTypeRef ptr);
+} CFURLRefObject;
+
+PyObject *CFURLRefObj_New(CFURLRef itself)
+{
+ CFURLRefObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(CFURLRefObject, &CFURLRef_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ it->ob_freeit = CFRelease;
+ return (PyObject *)it;
+}
+CFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
+{
+
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+
+ if (!CFURLRefObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "CFURLRef required");
+ return 0;
+ }
+ *p_itself = ((CFURLRefObject *)v)->ob_itself;
+ return 1;
+}
+
+static void CFURLRefObj_dealloc(CFURLRefObject *self)
+{
+ if (self->ob_freeit && self->ob_itself)
+ {
+ self->ob_freeit((CFTypeRef)self->ob_itself);
+ }
+ PyMem_DEL(self);
+}
+
+static PyObject *CFURLRefObj_CFURLCreateData(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFDataRef _rv;
+ CFStringEncoding encoding;
+ Boolean escapeWhitespace;
+ if (!PyArg_ParseTuple(_args, "ll",
+ &encoding,
+ &escapeWhitespace))
+ return NULL;
+ _rv = CFURLCreateData((CFAllocatorRef)NULL,
+ _self->ob_itself,
+ encoding,
+ escapeWhitespace);
+ _res = Py_BuildValue("O&",
+ CFDataRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyAbsoluteURL(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFURLRef _rv;
+ PyMac_PRECHECK(CFURLCopyAbsoluteURL);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyAbsoluteURL(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFURLRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLGetString(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLGetString);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLGetString(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLGetBaseURL(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFURLRef _rv;
+ PyMac_PRECHECK(CFURLGetBaseURL);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLGetBaseURL(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFURLRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCanBeDecomposed(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ PyMac_PRECHECK(CFURLCanBeDecomposed);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCanBeDecomposed(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyScheme(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyScheme);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyScheme(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyNetLocation(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyNetLocation);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyNetLocation(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyPath(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyPath);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyPath(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLHasDirectoryPath(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ PyMac_PRECHECK(CFURLHasDirectoryPath);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLHasDirectoryPath(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyResourceSpecifier(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyResourceSpecifier);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyResourceSpecifier(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyHostName(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyHostName);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyHostName(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLGetPortNumber(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 _rv;
+ PyMac_PRECHECK(CFURLGetPortNumber);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLGetPortNumber(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyUserName(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyUserName);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyUserName(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyPassword(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ PyMac_PRECHECK(CFURLCopyPassword);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLCopyPassword(_self->ob_itself);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyParameterString(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringRef charactersToLeaveEscaped;
+ PyMac_PRECHECK(CFURLCopyParameterString);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &charactersToLeaveEscaped))
+ return NULL;
+ _rv = CFURLCopyParameterString(_self->ob_itself,
+ charactersToLeaveEscaped);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyQueryString(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringRef charactersToLeaveEscaped;
+ PyMac_PRECHECK(CFURLCopyQueryString);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &charactersToLeaveEscaped))
+ return NULL;
+ _rv = CFURLCopyQueryString(_self->ob_itself,
+ charactersToLeaveEscaped);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CFURLRefObj_CFURLCopyFragment(CFURLRefObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringRef charactersToLeaveEscaped;
+ PyMac_PRECHECK(CFURLCopyFragment);
+ if (!PyArg_ParseTuple(_args, "O&",
+ CFStringRefObj_Convert, &charactersToLeaveEscaped))
+ return NULL;
+ _rv = CFURLCopyFragment(_self->ob_itself,
+ charactersToLeaveEscaped);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyMethodDef CFURLRefObj_methods[] = {
+ {"CFURLCreateData", (PyCFunction)CFURLRefObj_CFURLCreateData, 1,
+ "(CFStringEncoding encoding, Boolean escapeWhitespace) -> (CFDataRef _rv)"},
+ {"CFURLCopyAbsoluteURL", (PyCFunction)CFURLRefObj_CFURLCopyAbsoluteURL, 1,
+ "() -> (CFURLRef _rv)"},
+ {"CFURLGetString", (PyCFunction)CFURLRefObj_CFURLGetString, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLGetBaseURL", (PyCFunction)CFURLRefObj_CFURLGetBaseURL, 1,
+ "() -> (CFURLRef _rv)"},
+ {"CFURLCanBeDecomposed", (PyCFunction)CFURLRefObj_CFURLCanBeDecomposed, 1,
+ "() -> (Boolean _rv)"},
+ {"CFURLCopyScheme", (PyCFunction)CFURLRefObj_CFURLCopyScheme, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLCopyNetLocation", (PyCFunction)CFURLRefObj_CFURLCopyNetLocation, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLCopyPath", (PyCFunction)CFURLRefObj_CFURLCopyPath, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLHasDirectoryPath", (PyCFunction)CFURLRefObj_CFURLHasDirectoryPath, 1,
+ "() -> (Boolean _rv)"},
+ {"CFURLCopyResourceSpecifier", (PyCFunction)CFURLRefObj_CFURLCopyResourceSpecifier, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLCopyHostName", (PyCFunction)CFURLRefObj_CFURLCopyHostName, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLGetPortNumber", (PyCFunction)CFURLRefObj_CFURLGetPortNumber, 1,
+ "() -> (SInt32 _rv)"},
+ {"CFURLCopyUserName", (PyCFunction)CFURLRefObj_CFURLCopyUserName, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLCopyPassword", (PyCFunction)CFURLRefObj_CFURLCopyPassword, 1,
+ "() -> (CFStringRef _rv)"},
+ {"CFURLCopyParameterString", (PyCFunction)CFURLRefObj_CFURLCopyParameterString, 1,
+ "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
+ {"CFURLCopyQueryString", (PyCFunction)CFURLRefObj_CFURLCopyQueryString, 1,
+ "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
+ {"CFURLCopyFragment", (PyCFunction)CFURLRefObj_CFURLCopyFragment, 1,
+ "(CFStringRef charactersToLeaveEscaped) -> (CFStringRef _rv)"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain CFURLRefObj_chain = { CFURLRefObj_methods, &CFTypeRefObj_chain };
+
+static PyObject *CFURLRefObj_getattr(CFURLRefObject *self, char *name)
+{
+ return Py_FindMethodInChain(&CFURLRefObj_chain, (PyObject *)self, name);
+}
+
+#define CFURLRefObj_setattr NULL
+
+static int CFURLRefObj_compare(CFURLRefObject *self, CFURLRefObject *other)
+{
+ /* XXXX Or should we use CFEqual?? */
+ if ( self->ob_itself > other->ob_itself ) return 1;
+ if ( self->ob_itself < other->ob_itself ) return -1;
+ return 0;
+}
+
+static PyObject * CFURLRefObj_repr(CFURLRefObject *self)
+{
+ char buf[100];
+ sprintf(buf, "<CFURL object at 0x%08.8x for 0x%08.8x>", self, self->ob_itself);
+ return PyString_FromString(buf);
+}
+
+static int CFURLRefObj_hash(CFURLRefObject *self)
+{
+ /* XXXX Or should we use CFHash?? */
+ return (int)self->ob_itself;
+}
+
+PyTypeObject CFURLRef_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "CFURLRef", /*tp_name*/
+ sizeof(CFURLRefObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) CFURLRefObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) CFURLRefObj_getattr, /*tp_getattr*/
+ (setattrfunc) CFURLRefObj_setattr, /*tp_setattr*/
+ (cmpfunc) CFURLRefObj_compare, /*tp_compare*/
+ (reprfunc) CFURLRefObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) CFURLRefObj_hash, /*tp_hash*/
+};
+
+/* -------------------- End object type CFURLRef -------------------- */
+
+
+static PyObject *CF_CFAllocatorGetTypeID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFAllocatorGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFAllocatorGetTypeID();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFAllocatorGetPreferredSizeForSize(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ CFIndex size;
+ CFOptionFlags hint;
+ PyMac_PRECHECK(CFAllocatorGetPreferredSizeForSize);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &size,
+ &hint))
+ return NULL;
+ _rv = CFAllocatorGetPreferredSizeForSize((CFAllocatorRef)NULL,
+ size,
+ hint);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFCopyTypeIDDescription(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFTypeID theType;
+ PyMac_PRECHECK(CFCopyTypeIDDescription);
+ if (!PyArg_ParseTuple(_args, "l",
+ &theType))
+ return NULL;
+ _rv = CFCopyTypeIDDescription(theType);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFArrayGetTypeID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFArrayGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFArrayGetTypeID();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFArrayCreateMutable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableArrayRef _rv;
+ CFIndex capacity;
+ PyMac_PRECHECK(CFArrayCreateMutable);
+ if (!PyArg_ParseTuple(_args, "l",
+ &capacity))
+ return NULL;
+ _rv = CFArrayCreateMutable((CFAllocatorRef)NULL,
+ capacity,
+ &kCFTypeArrayCallBacks);
+ _res = Py_BuildValue("O&",
+ CFMutableArrayRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFArrayCreateMutableCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableArrayRef _rv;
+ CFIndex capacity;
+ CFArrayRef srcArray;
+ PyMac_PRECHECK(CFArrayCreateMutableCopy);
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &capacity,
+ CFArrayRefObj_Convert, &srcArray))
+ return NULL;
+ _rv = CFArrayCreateMutableCopy((CFAllocatorRef)NULL,
+ capacity,
+ srcArray);
+ _res = Py_BuildValue("O&",
+ CFMutableArrayRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFDataGetTypeID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFDataGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFDataGetTypeID();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFDataCreate(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFDataRef _rv;
+ unsigned char *bytes__in__;
+ long bytes__len__;
+ int bytes__in_len__;
+ PyMac_PRECHECK(CFDataCreate);
+ if (!PyArg_ParseTuple(_args, "s#",
+ &bytes__in__, &bytes__in_len__))
+ return NULL;
+ bytes__len__ = bytes__in_len__;
+ _rv = CFDataCreate((CFAllocatorRef)NULL,
+ bytes__in__, bytes__len__);
+ _res = Py_BuildValue("O&",
+ CFDataRefObj_New, _rv);
+ bytes__error__: ;
+ return _res;
+}
+
+static PyObject *CF_CFDataCreateWithBytesNoCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFDataRef _rv;
+ unsigned char *bytes__in__;
+ long bytes__len__;
+ int bytes__in_len__;
+ PyMac_PRECHECK(CFDataCreateWithBytesNoCopy);
+ if (!PyArg_ParseTuple(_args, "s#",
+ &bytes__in__, &bytes__in_len__))
+ return NULL;
+ bytes__len__ = bytes__in_len__;
+ _rv = CFDataCreateWithBytesNoCopy((CFAllocatorRef)NULL,
+ bytes__in__, bytes__len__,
+ (CFAllocatorRef)NULL);
+ _res = Py_BuildValue("O&",
+ CFDataRefObj_New, _rv);
+ bytes__error__: ;
+ return _res;
+}
+
+static PyObject *CF_CFDataCreateMutable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableDataRef _rv;
+ CFIndex capacity;
+ PyMac_PRECHECK(CFDataCreateMutable);
+ if (!PyArg_ParseTuple(_args, "l",
+ &capacity))
+ return NULL;
+ _rv = CFDataCreateMutable((CFAllocatorRef)NULL,
+ capacity);
+ _res = Py_BuildValue("O&",
+ CFMutableDataRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFDataCreateMutableCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableDataRef _rv;
+ CFIndex capacity;
+ CFDataRef data;
+ PyMac_PRECHECK(CFDataCreateMutableCopy);
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &capacity,
+ CFDataRefObj_Convert, &data))
+ return NULL;
+ _rv = CFDataCreateMutableCopy((CFAllocatorRef)NULL,
+ capacity,
+ data);
+ _res = Py_BuildValue("O&",
+ CFMutableDataRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFDictionaryGetTypeID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFDictionaryGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFDictionaryGetTypeID();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFDictionaryCreateMutable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableDictionaryRef _rv;
+ CFIndex capacity;
+ PyMac_PRECHECK(CFDictionaryCreateMutable);
+ if (!PyArg_ParseTuple(_args, "l",
+ &capacity))
+ return NULL;
+ _rv = CFDictionaryCreateMutable((CFAllocatorRef)NULL,
+ capacity,
+ &kCFTypeDictionaryKeyCallBacks,
+ &kCFTypeDictionaryValueCallBacks);
+ _res = Py_BuildValue("O&",
+ CFMutableDictionaryRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFDictionaryCreateMutableCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableDictionaryRef _rv;
+ CFIndex capacity;
+ CFDictionaryRef dict;
+ PyMac_PRECHECK(CFDictionaryCreateMutableCopy);
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &capacity,
+ CFDictionaryRefObj_Convert, &dict))
+ return NULL;
+ _rv = CFDictionaryCreateMutableCopy((CFAllocatorRef)NULL,
+ capacity,
+ dict);
+ _res = Py_BuildValue("O&",
+ CFMutableDictionaryRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringGetTypeID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFStringGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetTypeID();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateWithPascalString(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ StringPtr pStr;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringCreateWithPascalString);
+ if (!PyArg_ParseTuple(_args, "O&l",
+ PyMac_GetStr255, &pStr,
+ &encoding))
+ return NULL;
+ _rv = CFStringCreateWithPascalString((CFAllocatorRef)NULL,
+ pStr,
+ encoding);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateWithCString(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ char* cStr;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringCreateWithCString);
+ if (!PyArg_ParseTuple(_args, "sl",
+ &cStr,
+ &encoding))
+ return NULL;
+ _rv = CFStringCreateWithCString((CFAllocatorRef)NULL,
+ cStr,
+ encoding);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateWithPascalStringNoCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ StringPtr pStr;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringCreateWithPascalStringNoCopy);
+ if (!PyArg_ParseTuple(_args, "O&l",
+ PyMac_GetStr255, &pStr,
+ &encoding))
+ return NULL;
+ _rv = CFStringCreateWithPascalStringNoCopy((CFAllocatorRef)NULL,
+ pStr,
+ encoding,
+ (CFAllocatorRef)NULL);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateWithCStringNoCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ char* cStr;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringCreateWithCStringNoCopy);
+ if (!PyArg_ParseTuple(_args, "sl",
+ &cStr,
+ &encoding))
+ return NULL;
+ _rv = CFStringCreateWithCStringNoCopy((CFAllocatorRef)NULL,
+ cStr,
+ encoding,
+ (CFAllocatorRef)NULL);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateMutable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableStringRef _rv;
+ CFIndex maxLength;
+ PyMac_PRECHECK(CFStringCreateMutable);
+ if (!PyArg_ParseTuple(_args, "l",
+ &maxLength))
+ return NULL;
+ _rv = CFStringCreateMutable((CFAllocatorRef)NULL,
+ maxLength);
+ _res = Py_BuildValue("O&",
+ CFMutableStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateMutableCopy(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFMutableStringRef _rv;
+ CFIndex maxLength;
+ CFStringRef theString;
+ PyMac_PRECHECK(CFStringCreateMutableCopy);
+ if (!PyArg_ParseTuple(_args, "lO&",
+ &maxLength,
+ CFStringRefObj_Convert, &theString))
+ return NULL;
+ _rv = CFStringCreateMutableCopy((CFAllocatorRef)NULL,
+ maxLength,
+ theString);
+ _res = Py_BuildValue("O&",
+ CFMutableStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringCreateWithBytes(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ unsigned char *bytes__in__;
+ long bytes__len__;
+ int bytes__in_len__;
+ CFStringEncoding encoding;
+ Boolean isExternalRepresentation;
+ PyMac_PRECHECK(CFStringCreateWithBytes);
+ if (!PyArg_ParseTuple(_args, "s#ll",
+ &bytes__in__, &bytes__in_len__,
+ &encoding,
+ &isExternalRepresentation))
+ return NULL;
+ bytes__len__ = bytes__in_len__;
+ _rv = CFStringCreateWithBytes((CFAllocatorRef)NULL,
+ bytes__in__, bytes__len__,
+ encoding,
+ isExternalRepresentation);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ bytes__error__: ;
+ return _res;
+}
+
+static PyObject *CF_CFStringGetSystemEncoding(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringEncoding _rv;
+ PyMac_PRECHECK(CFStringGetSystemEncoding);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFStringGetSystemEncoding();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringGetMaximumSizeForEncoding(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFIndex _rv;
+ CFIndex length;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringGetMaximumSizeForEncoding);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &length,
+ &encoding))
+ return NULL;
+ _rv = CFStringGetMaximumSizeForEncoding(length,
+ encoding);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringIsEncodingAvailable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringIsEncodingAvailable);
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringIsEncodingAvailable(encoding);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringGetNameOfEncoding(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringGetNameOfEncoding);
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringGetNameOfEncoding(encoding);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringConvertEncodingToNSStringEncoding(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt32 _rv;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringConvertEncodingToNSStringEncoding);
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringConvertEncodingToNSStringEncoding(encoding);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringConvertNSStringEncodingToEncoding(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringEncoding _rv;
+ UInt32 encoding;
+ PyMac_PRECHECK(CFStringConvertNSStringEncodingToEncoding);
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringConvertNSStringEncodingToEncoding(encoding);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringConvertEncodingToWindowsCodepage(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt32 _rv;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringConvertEncodingToWindowsCodepage);
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringConvertEncodingToWindowsCodepage(encoding);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringConvertWindowsCodepageToEncoding(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringEncoding _rv;
+ UInt32 codepage;
+ PyMac_PRECHECK(CFStringConvertWindowsCodepageToEncoding);
+ if (!PyArg_ParseTuple(_args, "l",
+ &codepage))
+ return NULL;
+ _rv = CFStringConvertWindowsCodepageToEncoding(codepage);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFStringConvertEncodingToIANACharSetName(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ CFStringEncoding encoding;
+ PyMac_PRECHECK(CFStringConvertEncodingToIANACharSetName);
+ if (!PyArg_ParseTuple(_args, "l",
+ &encoding))
+ return NULL;
+ _rv = CFStringConvertEncodingToIANACharSetName(encoding);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF___CFStringMakeConstantString(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFStringRef _rv;
+ char* cStr;
+ PyMac_PRECHECK(__CFStringMakeConstantString);
+ if (!PyArg_ParseTuple(_args, "s",
+ &cStr))
+ return NULL;
+ _rv = __CFStringMakeConstantString(cStr);
+ _res = Py_BuildValue("O&",
+ CFStringRefObj_New, _rv);
+ return _res;
+}
+
+static PyObject *CF_CFURLGetTypeID(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFTypeID _rv;
+ PyMac_PRECHECK(CFURLGetTypeID);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = CFURLGetTypeID();
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *CF_CFURLCreateWithBytes(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ CFURLRef _rv;
+ unsigned char *URLBytes__in__;
+ long URLBytes__len__;
+ int URLBytes__in_len__;
+ CFStringEncoding encoding;
+ CFURLRef baseURL;
+ PyMac_PRECHECK(CFURLCreateWithBytes);
+ if (!PyArg_ParseTuple(_args, "s#lO&",
+ &URLBytes__in__, &URLBytes__in_len__,
+ &encoding,
+ OptionalCFURLRefObj_Convert, &baseURL))
+ return NULL;
+ URLBytes__len__ = URLBytes__in_len__;
+ _rv = CFURLCreateWithBytes((CFAllocatorRef)NULL,
+ URLBytes__in__, URLBytes__len__,
+ encoding,
+ baseURL);
+ _res = Py_BuildValue("O&",
+ CFURLRefObj_New, _rv);
+ URLBytes__error__: ;
+ return _res;
+}
+
+static PyMethodDef CF_methods[] = {
+ {"CFAllocatorGetTypeID", (PyCFunction)CF_CFAllocatorGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFAllocatorGetPreferredSizeForSize", (PyCFunction)CF_CFAllocatorGetPreferredSizeForSize, 1,
+ "(CFIndex size, CFOptionFlags hint) -> (CFIndex _rv)"},
+ {"CFCopyTypeIDDescription", (PyCFunction)CF_CFCopyTypeIDDescription, 1,
+ "(CFTypeID theType) -> (CFStringRef _rv)"},
+ {"CFArrayGetTypeID", (PyCFunction)CF_CFArrayGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFArrayCreateMutable", (PyCFunction)CF_CFArrayCreateMutable, 1,
+ "(CFIndex capacity) -> (CFMutableArrayRef _rv)"},
+ {"CFArrayCreateMutableCopy", (PyCFunction)CF_CFArrayCreateMutableCopy, 1,
+ "(CFIndex capacity, CFArrayRef srcArray) -> (CFMutableArrayRef _rv)"},
+ {"CFDataGetTypeID", (PyCFunction)CF_CFDataGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFDataCreate", (PyCFunction)CF_CFDataCreate, 1,
+ "(Buffer bytes) -> (CFDataRef _rv)"},
+ {"CFDataCreateWithBytesNoCopy", (PyCFunction)CF_CFDataCreateWithBytesNoCopy, 1,
+ "(Buffer bytes) -> (CFDataRef _rv)"},
+ {"CFDataCreateMutable", (PyCFunction)CF_CFDataCreateMutable, 1,
+ "(CFIndex capacity) -> (CFMutableDataRef _rv)"},
+ {"CFDataCreateMutableCopy", (PyCFunction)CF_CFDataCreateMutableCopy, 1,
+ "(CFIndex capacity, CFDataRef data) -> (CFMutableDataRef _rv)"},
+ {"CFDictionaryGetTypeID", (PyCFunction)CF_CFDictionaryGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFDictionaryCreateMutable", (PyCFunction)CF_CFDictionaryCreateMutable, 1,
+ "(CFIndex capacity) -> (CFMutableDictionaryRef _rv)"},
+ {"CFDictionaryCreateMutableCopy", (PyCFunction)CF_CFDictionaryCreateMutableCopy, 1,
+ "(CFIndex capacity, CFDictionaryRef dict) -> (CFMutableDictionaryRef _rv)"},
+ {"CFStringGetTypeID", (PyCFunction)CF_CFStringGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFStringCreateWithPascalString", (PyCFunction)CF_CFStringCreateWithPascalString, 1,
+ "(StringPtr pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {"CFStringCreateWithCString", (PyCFunction)CF_CFStringCreateWithCString, 1,
+ "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {"CFStringCreateWithPascalStringNoCopy", (PyCFunction)CF_CFStringCreateWithPascalStringNoCopy, 1,
+ "(StringPtr pStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {"CFStringCreateWithCStringNoCopy", (PyCFunction)CF_CFStringCreateWithCStringNoCopy, 1,
+ "(char* cStr, CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {"CFStringCreateMutable", (PyCFunction)CF_CFStringCreateMutable, 1,
+ "(CFIndex maxLength) -> (CFMutableStringRef _rv)"},
+ {"CFStringCreateMutableCopy", (PyCFunction)CF_CFStringCreateMutableCopy, 1,
+ "(CFIndex maxLength, CFStringRef theString) -> (CFMutableStringRef _rv)"},
+ {"CFStringCreateWithBytes", (PyCFunction)CF_CFStringCreateWithBytes, 1,
+ "(Buffer bytes, CFStringEncoding encoding, Boolean isExternalRepresentation) -> (CFStringRef _rv)"},
+ {"CFStringGetSystemEncoding", (PyCFunction)CF_CFStringGetSystemEncoding, 1,
+ "() -> (CFStringEncoding _rv)"},
+ {"CFStringGetMaximumSizeForEncoding", (PyCFunction)CF_CFStringGetMaximumSizeForEncoding, 1,
+ "(CFIndex length, CFStringEncoding encoding) -> (CFIndex _rv)"},
+ {"CFStringIsEncodingAvailable", (PyCFunction)CF_CFStringIsEncodingAvailable, 1,
+ "(CFStringEncoding encoding) -> (Boolean _rv)"},
+ {"CFStringGetNameOfEncoding", (PyCFunction)CF_CFStringGetNameOfEncoding, 1,
+ "(CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {"CFStringConvertEncodingToNSStringEncoding", (PyCFunction)CF_CFStringConvertEncodingToNSStringEncoding, 1,
+ "(CFStringEncoding encoding) -> (UInt32 _rv)"},
+ {"CFStringConvertNSStringEncodingToEncoding", (PyCFunction)CF_CFStringConvertNSStringEncodingToEncoding, 1,
+ "(UInt32 encoding) -> (CFStringEncoding _rv)"},
+ {"CFStringConvertEncodingToWindowsCodepage", (PyCFunction)CF_CFStringConvertEncodingToWindowsCodepage, 1,
+ "(CFStringEncoding encoding) -> (UInt32 _rv)"},
+ {"CFStringConvertWindowsCodepageToEncoding", (PyCFunction)CF_CFStringConvertWindowsCodepageToEncoding, 1,
+ "(UInt32 codepage) -> (CFStringEncoding _rv)"},
+ {"CFStringConvertEncodingToIANACharSetName", (PyCFunction)CF_CFStringConvertEncodingToIANACharSetName, 1,
+ "(CFStringEncoding encoding) -> (CFStringRef _rv)"},
+ {"__CFStringMakeConstantString", (PyCFunction)CF___CFStringMakeConstantString, 1,
+ "(char* cStr) -> (CFStringRef _rv)"},
+ {"CFURLGetTypeID", (PyCFunction)CF_CFURLGetTypeID, 1,
+ "() -> (CFTypeID _rv)"},
+ {"CFURLCreateWithBytes", (PyCFunction)CF_CFURLCreateWithBytes, 1,
+ "(Buffer URLBytes, CFStringEncoding encoding, CFURLRef baseURL) -> (CFURLRef _rv)"},
+ {NULL, NULL, 0}
+};
+
+
+
+
+void initCF(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+ // PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
+ // PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
+
+
+ m = Py_InitModule("CF", CF_methods);
+ d = PyModule_GetDict(m);
+ CF_Error = PyMac_GetOSErrException();
+ if (CF_Error == NULL ||
+ PyDict_SetItemString(d, "Error", CF_Error) != 0)
+ return;
+ CFTypeRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFTypeRef_Type);
+ if (PyDict_SetItemString(d, "CFTypeRefType", (PyObject *)&CFTypeRef_Type) != 0)
+ Py_FatalError("can't initialize CFTypeRefType");
+ CFArrayRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFArrayRef_Type);
+ if (PyDict_SetItemString(d, "CFArrayRefType", (PyObject *)&CFArrayRef_Type) != 0)
+ Py_FatalError("can't initialize CFArrayRefType");
+ CFMutableArrayRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFMutableArrayRef_Type);
+ if (PyDict_SetItemString(d, "CFMutableArrayRefType", (PyObject *)&CFMutableArrayRef_Type) != 0)
+ Py_FatalError("can't initialize CFMutableArrayRefType");
+ CFDictionaryRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFDictionaryRef_Type);
+ if (PyDict_SetItemString(d, "CFDictionaryRefType", (PyObject *)&CFDictionaryRef_Type) != 0)
+ Py_FatalError("can't initialize CFDictionaryRefType");
+ CFMutableDictionaryRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFMutableDictionaryRef_Type);
+ if (PyDict_SetItemString(d, "CFMutableDictionaryRefType", (PyObject *)&CFMutableDictionaryRef_Type) != 0)
+ Py_FatalError("can't initialize CFMutableDictionaryRefType");
+ CFDataRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFDataRef_Type);
+ if (PyDict_SetItemString(d, "CFDataRefType", (PyObject *)&CFDataRef_Type) != 0)
+ Py_FatalError("can't initialize CFDataRefType");
+ CFMutableDataRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFMutableDataRef_Type);
+ if (PyDict_SetItemString(d, "CFMutableDataRefType", (PyObject *)&CFMutableDataRef_Type) != 0)
+ Py_FatalError("can't initialize CFMutableDataRefType");
+ CFStringRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFStringRef_Type);
+ if (PyDict_SetItemString(d, "CFStringRefType", (PyObject *)&CFStringRef_Type) != 0)
+ Py_FatalError("can't initialize CFStringRefType");
+ CFMutableStringRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFMutableStringRef_Type);
+ if (PyDict_SetItemString(d, "CFMutableStringRefType", (PyObject *)&CFMutableStringRef_Type) != 0)
+ Py_FatalError("can't initialize CFMutableStringRefType");
+ CFURLRef_Type.ob_type = &PyType_Type;
+ Py_INCREF(&CFURLRef_Type);
+ if (PyDict_SetItemString(d, "CFURLRefType", (PyObject *)&CFURLRef_Type) != 0)
+ Py_FatalError("can't initialize CFURLRefType");
+}
+
+/* ========================= End module CF ========================== */
+
--- /dev/null
+# Scan an Apple header file, generating a Python file of generator calls.
+
+import sys
+import os
+BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
+sys.path.append(BGENDIR)
+from scantools import Scanner_OSX
+from bgenlocations import TOOLBOXDIR
+
+LONG = "CoreFoundation"
+SHORT = "cf"
+OBJECTS = ("CFTypeRef",
+ "CFArrayRef", "CFMutableArrayRef",
+ "CFDataRef", "CFMutableDataRef",
+ "CFDictionaryRef", "CFMutableDictionaryRef",
+ "CFStringRef", "CFMutableStringRef",
+ "CFURLRef",
+ )
+# ADD object typenames here
+
+def main():
+ input = [
+ "CFBase.h",
+ "CFArray.h",
+## "CFBag.h",
+## "CFBundle.h",
+## "CFCharacterSet.h",
+ "CFData.h",
+## "CFDate.h",
+ "CFDictionary.h",
+## "CFNumber.h",
+## "CFPlugIn.h",
+## "CFPreferences.h",
+## "CFPropertyList.h",
+## "CFSet.h",
+ "CFString.h",
+## "CFStringEncodingExt.h",
+## "CFTimeZone.h",
+ "CFURL.h",
+ ]
+ output = SHORT + "gen.py"
+ defsoutput = TOOLBOXDIR + LONG + ".py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.gentypetest(SHORT+"typetest.py")
+ scanner.close()
+ 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]
+ if t in OBJECTS and m == "InMode":
+ classname = "Method"
+ listname = t + "_methods"
+ # Special case for the silly first AllocatorRef argument
+ if t == 'CFAllocatorRef' and m == 'InMode' and len(arglist) > 1:
+ t, n, m = arglist[1]
+ if t in OBJECTS and m == "InMode":
+ classname = "MethodSkipArg1"
+ listname = t + "_methods"
+ return classname, listname
+
+ def writeinitialdefs(self):
+ self.defsfile.write("def FOUR_CHAR_CODE(x): return x\n")
+
+ def makeblacklistnames(self):
+ return [
+ # Memory allocator functions
+ "CFAllocatorGetDefault",
+ "CFAllocatorSetDefault",
+ "CFAllocatorAllocate",
+ "CFAllocatorReallocate",
+ "CFAllocatorDeallocate",
+ "CFGetAllocator",
+ # Array functions we skip for now.
+ "CFArrayGetValueAtIndex",
+ # Data pointer functions. Skip for now.
+ "CFDataGetBytePtr",
+ "CFDataGetMutableBytePtr",
+ "CFDataGetBytes", # XXXX Should support this one
+ # String functions
+ "CFStringGetPascalString", # Use the C-string methods.
+ "CFStringGetPascalStringPtr", # TBD automatically
+ "CFStringGetCStringPtr",
+ "CFStringGetCharactersPtr",
+ "CFStringGetCString",
+ "CFStringGetCharacters",
+ "CFURLCreateStringWithFileSystemPath", # Gone in later releases
+ ]
+
+ def makegreylist(self):
+ return []
+
+ def makeblacklisttypes(self):
+ return [
+ "CFComparatorFunction", # Callback function pointer
+ "CFAllocatorContext", # Not interested in providing our own allocator
+ "void_ptr_ptr", # Tricky. This is the initializer for arrays...
+ "void_ptr", # Ditto for various array lookup methods
+ "CFArrayApplierFunction", # Callback function pointer
+ "CFDictionaryApplierFunction", # Callback function pointer
+ "UniChar_ptr", # XXXX To be done
+ "const_UniChar_ptr", # XXXX To be done
+ "UniChar", # XXXX To be done
+ "va_list", # For printf-to-a-cfstring. Use Python.
+ "const_CFStringEncoding_ptr", # To be done, I guess
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ # Buffers in CF seem to be passed as UInt8 * normally.
+ ([("UInt8_ptr", "*", "InMode"), ("CFIndex", "*", "InMode")],
+ [("UcharInBuffer", "*", "*")]),
+
+ # Some functions return a const char *. Don't worry, we won't modify it.
+ ([("const_char_ptr", "*", "ReturnMode")],
+ [("return_stringptr", "*", "*")]),
+
+ # base URLs are optional (pass None for NULL)
+ ([("CFURLRef", "baseURL", "InMode")],
+ [("OptionalCFURLRef", "*", "*")]),
+
+ ]
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+# 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).
+
+#error missing SetActionFilter
+
+import string
+
+# Declarations that change for each manager
+MODNAME = 'CF' # The name of the module
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # 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 *
+
+# Special case generator for the functions that have an AllocatorRef first argument,
+# which we skip anyway, and the object as the second arg.
+class MethodSkipArg1(MethodGenerator):
+ """Similar to MethodGenerator, but has self as last argument"""
+
+ def parseArgumentList(self, args):
+ if len(args) < 2:
+ raise ValueError, "MethodSkipArg1 expects at least 2 args"
+ a0, a1, args = args[0], args[1], args[2:]
+ t0, n0, m0 = a0
+ if t0 != "CFAllocatorRef" and m0 != InMode:
+ raise ValueError, "MethodSkipArg1 should have dummy AllocatorRef first arg"
+ t1, n1, m1 = a1
+ if m1 != InMode:
+ raise ValueError, "method's 'self' must be 'InMode'"
+ dummy = Variable(t0, n0, m0)
+ self.argumentList.append(dummy)
+ self.itself = Variable(t1, "_self->ob_itself", SelfMode)
+ self.argumentList.append(self.itself)
+ FunctionGenerator.parseArgumentList(self, args)
+
+
+# Create the type objects
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <CFBase.h>
+#include <CFArray.h>
+#include <CFData.h>
+#include <CFDictionary.h>
+#include <CFString.h>
+#include <CFURL.h>
+#else
+#include <CoreFoundation.h>
+#endif
+
+/* For now we declare them forward here. They'll go to mactoolbox later */
+staticforward PyObject *CFTypeRefObj_New(CFTypeRef);
+staticforward int CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
+staticforward PyObject *CFStringRefObj_New(CFStringRef);
+staticforward int CFStringRefObj_Convert(PyObject *, CFStringRef *);
+staticforward PyObject *CFURLRefObj_New(CFURLRef);
+staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
+
+staticforward int CFURLRefObj_Convert(PyObject *, CFURLRef *);
+
+// ADD declarations
+#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
+//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
+//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
+
+//#define CFTypeRefObj_New _CFTypeRefObj_New
+//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
+#endif
+
+/*
+** Parse/generate CFRange records
+*/
+PyObject *CFRange_New(CFRange *itself)
+{
+
+ return Py_BuildValue("ll", (long)itself->location, (long)itself->length);
+}
+
+CFRange_Convert(PyObject *v, CFRange *p_itself)
+{
+ long location, length;
+
+ if( !PyArg_ParseTuple(v, "ll", &location, &length) )
+ return 0;
+ p_itself->location = (CFIndex)location;
+ p_itself->length = (CFIndex)length;
+ return 1;
+}
+
+/* Optional CFURL argument or None (passed as NULL) */
+int
+OptionalCFURLRefObj_Convert(PyObject *v, CFURLRef *p_itself)
+{
+ if ( v == Py_None ) {
+ p_itself = NULL;
+ return 1;
+ }
+ return CFURLRefObj_Convert(v, p_itself);
+}
+
+"""
+
+initstuff = initstuff + """
+// PyMac_INIT_TOOLBOX_OBJECT_NEW(Track, TrackObj_New);
+// PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Track, TrackObj_Convert);
+"""
+
+Boolean = Type("Boolean", "l")
+CFTypeID = Type("CFTypeID", "l") # XXXX a guess, seems better than OSTypeType.
+CFHashCode = Type("CFHashCode", "l")
+CFIndex = Type("CFIndex", "l")
+CFRange = OpaqueByValueType('CFRange', 'CFRange')
+CFOptionFlags = Type("CFOptionFlags", "l")
+CFStringEncoding = Type("CFStringEncoding", "l")
+CFComparisonResult = Type("CFComparisonResult", "l") # a bit dangerous, it's an enum
+CFURLPathStyle = Type("CFURLPathStyle", "l") # a bit dangerous, it's an enum
+
+char_ptr = stringptr
+return_stringptr = Type("char *", "s") # ONLY FOR RETURN VALUES!!
+
+CFAllocatorRef = FakeType("(CFAllocatorRef)NULL")
+CFArrayCallBacks_ptr = FakeType("&kCFTypeArrayCallBacks")
+CFDictionaryKeyCallBacks_ptr = FakeType("&kCFTypeDictionaryKeyCallBacks")
+CFDictionaryValueCallBacks_ptr = FakeType("&kCFTypeDictionaryValueCallBacks")
+# The real objects
+CFTypeRef = OpaqueByValueType("CFTypeRef", "CFTypeRefObj")
+CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")
+CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")
+CFArrayRef = OpaqueByValueType("CFArrayRef", "CFArrayRefObj")
+CFMutableArrayRef = OpaqueByValueType("CFMutableArrayRef", "CFMutableArrayRefObj")
+CFDataRef = OpaqueByValueType("CFDataRef", "CFDataRefObj")
+CFMutableDataRef = OpaqueByValueType("CFMutableDataRef", "CFMutableDataRefObj")
+CFDictionaryRef = OpaqueByValueType("CFDictionaryRef", "CFDictionaryRefObj")
+CFMutableDictionaryRef = OpaqueByValueType("CFMutableDictionaryRef", "CFMutableDictionaryRefObj")
+CFStringRef = OpaqueByValueType("CFStringRef", "CFStringRefObj")
+CFMutableStringRef = OpaqueByValueType("CFMutableStringRef", "CFMutableStringRefObj")
+CFURLRef = OpaqueByValueType("CFURLRef", "CFURLRefObj")
+OptionalCFURLRef = OpaqueByValueType("CFURLRef", "OptionalCFURLRefObj")
+# ADD object type here
+
+# Our (opaque) objects
+
+class MyGlobalObjectDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+ def outputStructMembers(self):
+ GlobalObjectDefinition.outputStructMembers(self)
+ Output("void (*ob_freeit)(CFTypeRef ptr);")
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+## Output("it->ob_freeit = NULL;")
+ Output("it->ob_freeit = CFRelease;")
+ def outputCheckConvertArg(self):
+ Out("""
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ /* Check for other CF objects here */
+ """)
+ def outputCleanupStructMembers(self):
+ Output("if (self->ob_freeit && self->ob_itself)")
+ OutLbrace()
+ Output("self->ob_freeit((CFTypeRef)self->ob_itself);")
+ OutRbrace()
+
+ def outputCompare(self):
+ Output()
+ Output("static int %s_compare(%s *self, %s *other)", self.prefix, self.objecttype, self.objecttype)
+ OutLbrace()
+ Output("/* XXXX Or should we use CFEqual?? */")
+ Output("if ( self->ob_itself > other->ob_itself ) return 1;")
+ Output("if ( self->ob_itself < other->ob_itself ) return -1;")
+ Output("return 0;")
+ OutRbrace()
+
+ def outputHash(self):
+ Output()
+ Output("static int %s_hash(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("/* XXXX Or should we use CFHash?? */")
+ Output("return (int)self->ob_itself;")
+ OutRbrace()
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFTypeRef type-%%d object at 0x%%08.8x for 0x%%08.8x>", CFGetTypeID(self->ob_itself), self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFTypeRefObjectDefinition(MyGlobalObjectDefinition):
+ pass
+
+class CFArrayRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFTypeRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFArrayRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFMutableArrayRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFArrayRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFMutableArrayRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFTypeRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFMutableDictionaryRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFDictionaryRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFMutableDictionaryRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFDataRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFTypeRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFDataRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFMutableDataRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFDataRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFMutableDataRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFStringRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFTypeRefObj_chain"
+
+ def outputCheckConvertArg(self):
+ Out("""
+ if (v == Py_None) { *p_itself = NULL; return 1; }
+ if (PyString_Check(v)) {
+ char *cStr = PyString_AsString(v);
+ *p_itself = CFStringCreateWithCString((CFAllocatorRef)NULL, cStr, 0);
+ return 1;
+ }
+ if (PyUnicode_Check(v)) {
+ /* We use the CF types here, if Python was configured differently that will give an error */
+ CFIndex size = PyUnicode_GetSize(v);
+ UniChar *unichars = PyUnicode_AsUnicode(v);
+ if (!unichars) return 0;
+ *p_itself = CFStringCreateWithCharacters((CFAllocatorRef)NULL, unichars, size);
+ return 1;
+ }
+
+ """)
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFStringRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFMutableStringRefObjectDefinition(CFStringRefObjectDefinition):
+ basechain = "&CFStringRefObj_chain"
+
+ def outputCheckConvertArg(self):
+ # Mutable, don't allow Python strings
+ return MyGlobalObjectDefinition.outputCheckConvertArg(self)
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFMutableStringRef object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+class CFURLRefObjectDefinition(MyGlobalObjectDefinition):
+ basechain = "&CFTypeRefObj_chain"
+
+ def outputRepr(self):
+ Output()
+ Output("static PyObject * %s_repr(%s *self)", self.prefix, self.objecttype)
+ OutLbrace()
+ Output("char buf[100];")
+ Output("""sprintf(buf, "<CFURL object at 0x%%08.8x for 0x%%08.8x>", self, self->ob_itself);""")
+ Output("return PyString_FromString(buf);")
+ OutRbrace()
+
+
+# ADD object class here
+
+# From here on it's basically all boiler plate...
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+CFTypeRef_object = CFTypeRefObjectDefinition('CFTypeRef', 'CFTypeRefObj', 'CFTypeRef')
+CFArrayRef_object = CFArrayRefObjectDefinition('CFArrayRef', 'CFArrayRefObj', 'CFArrayRef')
+CFMutableArrayRef_object = CFMutableArrayRefObjectDefinition('CFMutableArrayRef', 'CFMutableArrayRefObj', 'CFMutableArrayRef')
+CFDictionaryRef_object = CFDictionaryRefObjectDefinition('CFDictionaryRef', 'CFDictionaryRefObj', 'CFDictionaryRef')
+CFMutableDictionaryRef_object = CFMutableDictionaryRefObjectDefinition('CFMutableDictionaryRef', 'CFMutableDictionaryRefObj', 'CFMutableDictionaryRef')
+CFDataRef_object = CFDataRefObjectDefinition('CFDataRef', 'CFDataRefObj', 'CFDataRef')
+CFMutableDataRef_object = CFMutableDataRefObjectDefinition('CFMutableDataRef', 'CFMutableDataRefObj', 'CFMutableDataRef')
+CFStringRef_object = CFStringRefObjectDefinition('CFStringRef', 'CFStringRefObj', 'CFStringRef')
+CFMutableStringRef_object = CFMutableStringRefObjectDefinition('CFMutableStringRef', 'CFMutableStringRefObj', 'CFMutableStringRef')
+CFURLRef_object = CFURLRefObjectDefinition('CFURLRef', 'CFURLRefObj', 'CFURLRef')
+
+# ADD object here
+
+module.addobject(CFTypeRef_object)
+module.addobject(CFArrayRef_object)
+module.addobject(CFMutableArrayRef_object)
+module.addobject(CFDictionaryRef_object)
+module.addobject(CFMutableDictionaryRef_object)
+module.addobject(CFDataRef_object)
+module.addobject(CFMutableDataRef_object)
+module.addobject(CFStringRef_object)
+module.addobject(CFMutableStringRef_object)
+module.addobject(CFURLRef_object)
+# ADD addobject call here
+
+# Create the generator classes used to populate the lists
+Function = OSErrWeakLinkFunctionGenerator
+Method = OSErrWeakLinkMethodGenerator
+
+# Create and populate the lists
+functions = []
+CFTypeRef_methods = []
+CFArrayRef_methods = []
+CFMutableArrayRef_methods = []
+CFDictionaryRef_methods = []
+CFMutableDictionaryRef_methods = []
+CFDataRef_methods = []
+CFMutableDataRef_methods = []
+CFStringRef_methods = []
+CFMutableStringRef_methods = []
+CFURLRef_methods = []
+
+# ADD _methods initializer here
+execfile(INPUTFILE)
+
+
+# add the populated lists to the generator groups
+# (in a different wordl the scan program would generate this)
+for f in functions: module.add(f)
+for f in CFTypeRef_methods: CFTypeRef_object.add(f)
+for f in CFArrayRef_methods: CFArrayRef_object.add(f)
+for f in CFMutableArrayRef_methods: CFMutableArrayRef_object.add(f)
+for f in CFDictionaryRef_methods: CFDictionaryRef_object.add(f)
+for f in CFMutableDictionaryRef_methods: CFMutableDictionaryRef_object.add(f)
+for f in CFDataRef_methods: CFDataRef_object.add(f)
+for f in CFMutableDataRef_methods: CFMutableDataRef_object.add(f)
+for f in CFStringRef_methods: CFStringRef_object.add(f)
+for f in CFMutableStringRef_methods: CFMutableStringRef_object.add(f)
+for f in CFURLRef_methods: CFURLRef_object.add(f)
+
+# Manual generators for getting data out of strings
+
+getasstring_body = """
+int size = CFStringGetLength(_self->ob_itself)+1;
+char *data = malloc(size);
+
+if( data == NULL ) return PyErr_NoMemory();
+if ( CFStringGetCString(_self->ob_itself, data, size, 0) ) {
+ _res = (PyObject *)PyString_FromString(data);
+} else {
+ PyErr_SetString(PyExc_RuntimeError, "CFStringGetCString could not fit the string");
+ _res = NULL;
+}
+free(data);
+return _res;
+"""
+
+f = ManualGenerator("CFStringGetString", getasstring_body);
+f.docstring = lambda: "() -> (string _rv)"
+CFStringRef_object.add(f)
+
+getasunicode_body = """
+int size = CFStringGetLength(_self->ob_itself)+1;
+Py_UNICODE *data = malloc(size*sizeof(Py_UNICODE));
+CFRange range;
+
+range.location = 0;
+range.length = size;
+if( data == NULL ) return PyErr_NoMemory();
+CFStringGetCharacters(_self->ob_itself, range, data);
+_res = (PyObject *)PyUnicode_FromUnicode(data, size);
+free(data);
+return _res;
+"""
+
+f = ManualGenerator("CFStringGetUnicode", getasunicode_body);
+f.docstring = lambda: "() -> (unicode _rv)"
+CFStringRef_object.add(f)
+
+# ADD add forloop here
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
+
--- /dev/null
+
+/* ========================== Module Mlte =========================== */
+
+#include "Python.h"
+
+
+
+#include "macglue.h"
+#include "pymactoolbox.h"
+
+/* Macro to test whether a weak-loaded CFM function exists */
+#define PyMac_PRECHECK(rtn) do { if ( &rtn == NULL ) {\
+ PyErr_SetString(PyExc_NotImplementedError, \
+ "Not available in this shared library/OS version"); \
+ return NULL; \
+ }} while(0)
+
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <MacTextEditor.h>
+#else
+#include <xxxx.h>
+#endif
+
+/* For now we declare them forward here. They'll go to mactoolbox later */
+staticforward PyObject *TXNObj_New(TXNObject);
+staticforward int TXNObj_Convert(PyObject *, TXNObject *);
+staticforward PyObject *TXNFontMenuObj_New(TXNFontMenuObject);
+staticforward int TXNFontMenuObj_Convert(PyObject *, TXNFontMenuObject *);
+
+// ADD declarations
+#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
+//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
+//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
+
+//#define CFTypeRefObj_New _CFTypeRefObj_New
+//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
+#endif
+
+/*
+** Parse an optional fsspec
+*/
+static int
+OptFSSpecPtr_Convert(PyObject *v, FSSpec **p_itself)
+{
+ static FSSpec fss;
+ if (v == Py_None)
+ {
+ *p_itself = NULL;
+ return 1;
+ }
+ *p_itself = &fss;
+ return PyMac_GetFSSpec(v, *p_itself);
+}
+
+/*
+** Parse an optional rect
+*/
+static int
+OptRectPtr_Convert(PyObject *v, Rect **p_itself)
+{
+ static Rect r;
+
+ if (v == Py_None)
+ {
+ *p_itself = NULL;
+ return 1;
+ }
+ *p_itself = &r;
+ return PyMac_GetRect(v, *p_itself);
+}
+
+/*
+** Parse an optional GWorld
+*/
+static int
+OptGWorldObj_Convert(PyObject *v, GWorldPtr *p_itself)
+{
+ if (v == Py_None)
+ {
+ *p_itself = NULL;
+ return 1;
+ }
+ return GWorldObj_Convert(v, p_itself);
+}
+
+
+static PyObject *Mlte_Error;
+
+/* --------------------- Object type TXNObject ---------------------- */
+
+PyTypeObject TXNObject_Type;
+
+#define TXNObj_Check(x) ((x)->ob_type == &TXNObject_Type)
+
+typedef struct TXNObjectObject {
+ PyObject_HEAD
+ TXNObject ob_itself;
+} TXNObjectObject;
+
+PyObject *TXNObj_New(TXNObject itself)
+{
+ TXNObjectObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(TXNObjectObject, &TXNObject_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ return (PyObject *)it;
+}
+TXNObj_Convert(PyObject *v, TXNObject *p_itself)
+{
+ if (!TXNObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "TXNObject required");
+ return 0;
+ }
+ *p_itself = ((TXNObjectObject *)v)->ob_itself;
+ return 1;
+}
+
+static void TXNObj_dealloc(TXNObjectObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyMem_DEL(self);
+}
+
+static PyObject *TXNObj_TXNDeleteObject(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNDeleteObject);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNDeleteObject(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNResizeFrame(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt32 iWidth;
+ UInt32 iHeight;
+ TXNFrameID iTXNFrameID;
+ PyMac_PRECHECK(TXNResizeFrame);
+ if (!PyArg_ParseTuple(_args, "lll",
+ &iWidth,
+ &iHeight,
+ &iTXNFrameID))
+ return NULL;
+ TXNResizeFrame(_self->ob_itself,
+ iWidth,
+ iHeight,
+ iTXNFrameID);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNSetFrameBounds(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ SInt32 iTop;
+ SInt32 iLeft;
+ SInt32 iBottom;
+ SInt32 iRight;
+ TXNFrameID iTXNFrameID;
+ PyMac_PRECHECK(TXNSetFrameBounds);
+ if (!PyArg_ParseTuple(_args, "lllll",
+ &iTop,
+ &iLeft,
+ &iBottom,
+ &iRight,
+ &iTXNFrameID))
+ return NULL;
+ TXNSetFrameBounds(_self->ob_itself,
+ iTop,
+ iLeft,
+ iBottom,
+ iRight,
+ iTXNFrameID);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNKeyDown(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ EventRecord iEvent;
+ PyMac_PRECHECK(TXNKeyDown);
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetEventRecord, &iEvent))
+ return NULL;
+ TXNKeyDown(_self->ob_itself,
+ &iEvent);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNAdjustCursor(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ RgnHandle ioCursorRgn;
+ PyMac_PRECHECK(TXNAdjustCursor);
+ if (!PyArg_ParseTuple(_args, "O&",
+ OptResObj_Convert, &ioCursorRgn))
+ return NULL;
+ TXNAdjustCursor(_self->ob_itself,
+ ioCursorRgn);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNClick(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ EventRecord iEvent;
+ PyMac_PRECHECK(TXNClick);
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetEventRecord, &iEvent))
+ return NULL;
+ TXNClick(_self->ob_itself,
+ &iEvent);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNTSMCheck(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ EventRecord iEvent;
+ PyMac_PRECHECK(TXNTSMCheck);
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetEventRecord, &iEvent))
+ return NULL;
+ _rv = TXNTSMCheck(_self->ob_itself,
+ &iEvent);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNSelectAll(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNSelectAll);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNSelectAll(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNFocus(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean iBecomingFocused;
+ PyMac_PRECHECK(TXNFocus);
+ if (!PyArg_ParseTuple(_args, "b",
+ &iBecomingFocused))
+ return NULL;
+ TXNFocus(_self->ob_itself,
+ iBecomingFocused);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNUpdate(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNUpdate);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNUpdate(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNDraw(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ GWorldPtr iDrawPort;
+ PyMac_PRECHECK(TXNDraw);
+ if (!PyArg_ParseTuple(_args, "O&",
+ OptGWorldObj_Convert, &iDrawPort))
+ return NULL;
+ TXNDraw(_self->ob_itself,
+ iDrawPort);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNForceUpdate(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNForceUpdate);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNForceUpdate(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGetSleepTicks(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ UInt32 _rv;
+ PyMac_PRECHECK(TXNGetSleepTicks);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNGetSleepTicks(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNIdle(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNIdle);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNIdle(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGrowWindow(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ EventRecord iEvent;
+ PyMac_PRECHECK(TXNGrowWindow);
+ if (!PyArg_ParseTuple(_args, "O&",
+ PyMac_GetEventRecord, &iEvent))
+ return NULL;
+ TXNGrowWindow(_self->ob_itself,
+ &iEvent);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNZoomWindow(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ short iPart;
+ PyMac_PRECHECK(TXNZoomWindow);
+ if (!PyArg_ParseTuple(_args, "h",
+ &iPart))
+ return NULL;
+ TXNZoomWindow(_self->ob_itself,
+ iPart);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNCanUndo(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ TXNActionKey oTXNActionKey;
+ PyMac_PRECHECK(TXNCanUndo);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNCanUndo(_self->ob_itself,
+ &oTXNActionKey);
+ _res = Py_BuildValue("bl",
+ _rv,
+ oTXNActionKey);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNUndo(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNUndo);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNUndo(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNCanRedo(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ TXNActionKey oTXNActionKey;
+ PyMac_PRECHECK(TXNCanRedo);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNCanRedo(_self->ob_itself,
+ &oTXNActionKey);
+ _res = Py_BuildValue("bl",
+ _rv,
+ oTXNActionKey);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNRedo(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNRedo);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNRedo(_self->ob_itself);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNCut(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNCut);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNCut(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNCopy(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNCopy);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNCopy(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNPaste(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNPaste);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNPaste(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNClear(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNClear);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNClear(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGetSelection(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ TXNOffset oStartOffset;
+ TXNOffset oEndOffset;
+ PyMac_PRECHECK(TXNGetSelection);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNGetSelection(_self->ob_itself,
+ &oStartOffset,
+ &oEndOffset);
+ _res = Py_BuildValue("ll",
+ oStartOffset,
+ oEndOffset);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNShowSelection(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean iShowEnd;
+ PyMac_PRECHECK(TXNShowSelection);
+ if (!PyArg_ParseTuple(_args, "b",
+ &iShowEnd))
+ return NULL;
+ TXNShowSelection(_self->ob_itself,
+ iShowEnd);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNIsSelectionEmpty(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ PyMac_PRECHECK(TXNIsSelectionEmpty);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNIsSelectionEmpty(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNSetSelection(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNOffset iStartOffset;
+ TXNOffset iEndOffset;
+ PyMac_PRECHECK(TXNSetSelection);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &iStartOffset,
+ &iEndOffset))
+ return NULL;
+ _err = TXNSetSelection(_self->ob_itself,
+ iStartOffset,
+ iEndOffset);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNCountRunsInRange(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ UInt32 iStartOffset;
+ UInt32 iEndOffset;
+ ItemCount oRunCount;
+ PyMac_PRECHECK(TXNCountRunsInRange);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &iStartOffset,
+ &iEndOffset))
+ return NULL;
+ _err = TXNCountRunsInRange(_self->ob_itself,
+ iStartOffset,
+ iEndOffset,
+ &oRunCount);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("l",
+ oRunCount);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNDataSize(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ByteCount _rv;
+ PyMac_PRECHECK(TXNDataSize);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNDataSize(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGetData(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNOffset iStartOffset;
+ TXNOffset iEndOffset;
+ Handle oDataHandle;
+ PyMac_PRECHECK(TXNGetData);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &iStartOffset,
+ &iEndOffset))
+ return NULL;
+ _err = TXNGetData(_self->ob_itself,
+ iStartOffset,
+ iEndOffset,
+ &oDataHandle);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ ResObj_New, oDataHandle);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGetDataEncoded(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNOffset iStartOffset;
+ TXNOffset iEndOffset;
+ Handle oDataHandle;
+ TXNDataType iEncoding;
+ PyMac_PRECHECK(TXNGetDataEncoded);
+ if (!PyArg_ParseTuple(_args, "llO&",
+ &iStartOffset,
+ &iEndOffset,
+ PyMac_GetOSType, &iEncoding))
+ return NULL;
+ _err = TXNGetDataEncoded(_self->ob_itself,
+ iStartOffset,
+ iEndOffset,
+ &oDataHandle,
+ iEncoding);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ ResObj_New, oDataHandle);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNSetDataFromFile(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ SInt16 iFileRefNum;
+ OSType iFileType;
+ ByteCount iFileLength;
+ TXNOffset iStartOffset;
+ TXNOffset iEndOffset;
+ PyMac_PRECHECK(TXNSetDataFromFile);
+ if (!PyArg_ParseTuple(_args, "hO&lll",
+ &iFileRefNum,
+ PyMac_GetOSType, &iFileType,
+ &iFileLength,
+ &iStartOffset,
+ &iEndOffset))
+ return NULL;
+ _err = TXNSetDataFromFile(_self->ob_itself,
+ iFileRefNum,
+ iFileType,
+ iFileLength,
+ iStartOffset,
+ iEndOffset);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNSetData(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNDataType iDataType;
+ void * *iDataPtr__in__;
+ ByteCount iDataPtr__len__;
+ int iDataPtr__in_len__;
+ TXNOffset iStartOffset;
+ TXNOffset iEndOffset;
+ PyMac_PRECHECK(TXNSetData);
+ if (!PyArg_ParseTuple(_args, "O&s#ll",
+ PyMac_GetOSType, &iDataType,
+ &iDataPtr__in__, &iDataPtr__in_len__,
+ &iStartOffset,
+ &iEndOffset))
+ return NULL;
+ iDataPtr__len__ = iDataPtr__in_len__;
+ _err = TXNSetData(_self->ob_itself,
+ iDataType,
+ iDataPtr__in__, iDataPtr__len__,
+ iStartOffset,
+ iEndOffset);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ iDataPtr__error__: ;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGetChangeCount(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ ItemCount _rv;
+ PyMac_PRECHECK(TXNGetChangeCount);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNGetChangeCount(_self->ob_itself);
+ _res = Py_BuildValue("l",
+ _rv);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNSave(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ OSType iType;
+ OSType iResType;
+ TXNPermanentTextEncodingType iPermanentEncoding;
+ FSSpec iFileSpecification;
+ SInt16 iDataReference;
+ SInt16 iResourceReference;
+ PyMac_PRECHECK(TXNSave);
+ if (!PyArg_ParseTuple(_args, "O&O&lO&hh",
+ PyMac_GetOSType, &iType,
+ PyMac_GetOSType, &iResType,
+ &iPermanentEncoding,
+ PyMac_GetFSSpec, &iFileSpecification,
+ &iDataReference,
+ &iResourceReference))
+ return NULL;
+ _err = TXNSave(_self->ob_itself,
+ iType,
+ iResType,
+ iPermanentEncoding,
+ &iFileSpecification,
+ iDataReference,
+ iResourceReference);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNRevert(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNRevert);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNRevert(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNPageSetup(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNPageSetup);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNPageSetup(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNPrint(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNPrint);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNPrint(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNGetViewRect(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Rect oViewRect;
+ PyMac_PRECHECK(TXNGetViewRect);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNGetViewRect(_self->ob_itself,
+ &oViewRect);
+ _res = Py_BuildValue("O&",
+ PyMac_BuildRect, &oViewRect);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNAttachObjectToWindow(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ GWorldPtr iWindow;
+ Boolean iIsActualWindow;
+ PyMac_PRECHECK(TXNAttachObjectToWindow);
+ if (!PyArg_ParseTuple(_args, "O&b",
+ GWorldObj_Convert, &iWindow,
+ &iIsActualWindow))
+ return NULL;
+ _err = TXNAttachObjectToWindow(_self->ob_itself,
+ iWindow,
+ iIsActualWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNIsObjectAttachedToWindow(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ PyMac_PRECHECK(TXNIsObjectAttachedToWindow);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNIsObjectAttachedToWindow(_self->ob_itself);
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *TXNObj_TXNDragTracker(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ TXNFrameID iTXNFrameID;
+ DragTrackingMessage iMessage;
+ WindowPtr iWindow;
+ DragReference iDragReference;
+ Boolean iDifferentObjectSameWindow;
+ PyMac_PRECHECK(TXNDragTracker);
+ if (!PyArg_ParseTuple(_args, "lhO&O&b",
+ &iTXNFrameID,
+ &iMessage,
+ WinObj_Convert, &iWindow,
+ DragObj_Convert, &iDragReference,
+ &iDifferentObjectSameWindow))
+ return NULL;
+ _err = TXNDragTracker(_self->ob_itself,
+ iTXNFrameID,
+ iMessage,
+ iWindow,
+ iDragReference,
+ iDifferentObjectSameWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNDragReceiver(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSErr _err;
+ TXNFrameID iTXNFrameID;
+ WindowPtr iWindow;
+ DragReference iDragReference;
+ Boolean iDifferentObjectSameWindow;
+ PyMac_PRECHECK(TXNDragReceiver);
+ if (!PyArg_ParseTuple(_args, "lO&O&b",
+ &iTXNFrameID,
+ WinObj_Convert, &iWindow,
+ DragObj_Convert, &iDragReference,
+ &iDifferentObjectSameWindow))
+ return NULL;
+ _err = TXNDragReceiver(_self->ob_itself,
+ iTXNFrameID,
+ iWindow,
+ iDragReference,
+ iDifferentObjectSameWindow);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNActivate(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNFrameID iTXNFrameID;
+ TXNScrollBarState iActiveState;
+ PyMac_PRECHECK(TXNActivate);
+ if (!PyArg_ParseTuple(_args, "ll",
+ &iTXNFrameID,
+ &iActiveState))
+ return NULL;
+ _err = TXNActivate(_self->ob_itself,
+ iTXNFrameID,
+ iActiveState);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNDoFontMenuSelection(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNFontMenuObject iTXNFontMenuObject;
+ SInt16 iMenuID;
+ SInt16 iMenuItem;
+ PyMac_PRECHECK(TXNDoFontMenuSelection);
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ TXNFontMenuObj_Convert, &iTXNFontMenuObject,
+ &iMenuID,
+ &iMenuItem))
+ return NULL;
+ _err = TXNDoFontMenuSelection(_self->ob_itself,
+ iTXNFontMenuObject,
+ iMenuID,
+ iMenuItem);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *TXNObj_TXNPrepareFontMenu(TXNObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ TXNFontMenuObject iTXNFontMenuObject;
+ PyMac_PRECHECK(TXNPrepareFontMenu);
+ if (!PyArg_ParseTuple(_args, "O&",
+ TXNFontMenuObj_Convert, &iTXNFontMenuObject))
+ return NULL;
+ _err = TXNPrepareFontMenu(_self->ob_itself,
+ iTXNFontMenuObject);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef TXNObj_methods[] = {
+ {"TXNDeleteObject", (PyCFunction)TXNObj_TXNDeleteObject, 1,
+ "() -> None"},
+ {"TXNResizeFrame", (PyCFunction)TXNObj_TXNResizeFrame, 1,
+ "(UInt32 iWidth, UInt32 iHeight, TXNFrameID iTXNFrameID) -> None"},
+ {"TXNSetFrameBounds", (PyCFunction)TXNObj_TXNSetFrameBounds, 1,
+ "(SInt32 iTop, SInt32 iLeft, SInt32 iBottom, SInt32 iRight, TXNFrameID iTXNFrameID) -> None"},
+ {"TXNKeyDown", (PyCFunction)TXNObj_TXNKeyDown, 1,
+ "(EventRecord iEvent) -> None"},
+ {"TXNAdjustCursor", (PyCFunction)TXNObj_TXNAdjustCursor, 1,
+ "(RgnHandle ioCursorRgn) -> None"},
+ {"TXNClick", (PyCFunction)TXNObj_TXNClick, 1,
+ "(EventRecord iEvent) -> None"},
+ {"TXNTSMCheck", (PyCFunction)TXNObj_TXNTSMCheck, 1,
+ "(EventRecord iEvent) -> (Boolean _rv)"},
+ {"TXNSelectAll", (PyCFunction)TXNObj_TXNSelectAll, 1,
+ "() -> None"},
+ {"TXNFocus", (PyCFunction)TXNObj_TXNFocus, 1,
+ "(Boolean iBecomingFocused) -> None"},
+ {"TXNUpdate", (PyCFunction)TXNObj_TXNUpdate, 1,
+ "() -> None"},
+ {"TXNDraw", (PyCFunction)TXNObj_TXNDraw, 1,
+ "(GWorldPtr iDrawPort) -> None"},
+ {"TXNForceUpdate", (PyCFunction)TXNObj_TXNForceUpdate, 1,
+ "() -> None"},
+ {"TXNGetSleepTicks", (PyCFunction)TXNObj_TXNGetSleepTicks, 1,
+ "() -> (UInt32 _rv)"},
+ {"TXNIdle", (PyCFunction)TXNObj_TXNIdle, 1,
+ "() -> None"},
+ {"TXNGrowWindow", (PyCFunction)TXNObj_TXNGrowWindow, 1,
+ "(EventRecord iEvent) -> None"},
+ {"TXNZoomWindow", (PyCFunction)TXNObj_TXNZoomWindow, 1,
+ "(short iPart) -> None"},
+ {"TXNCanUndo", (PyCFunction)TXNObj_TXNCanUndo, 1,
+ "() -> (Boolean _rv, TXNActionKey oTXNActionKey)"},
+ {"TXNUndo", (PyCFunction)TXNObj_TXNUndo, 1,
+ "() -> None"},
+ {"TXNCanRedo", (PyCFunction)TXNObj_TXNCanRedo, 1,
+ "() -> (Boolean _rv, TXNActionKey oTXNActionKey)"},
+ {"TXNRedo", (PyCFunction)TXNObj_TXNRedo, 1,
+ "() -> None"},
+ {"TXNCut", (PyCFunction)TXNObj_TXNCut, 1,
+ "() -> None"},
+ {"TXNCopy", (PyCFunction)TXNObj_TXNCopy, 1,
+ "() -> None"},
+ {"TXNPaste", (PyCFunction)TXNObj_TXNPaste, 1,
+ "() -> None"},
+ {"TXNClear", (PyCFunction)TXNObj_TXNClear, 1,
+ "() -> None"},
+ {"TXNGetSelection", (PyCFunction)TXNObj_TXNGetSelection, 1,
+ "() -> (TXNOffset oStartOffset, TXNOffset oEndOffset)"},
+ {"TXNShowSelection", (PyCFunction)TXNObj_TXNShowSelection, 1,
+ "(Boolean iShowEnd) -> None"},
+ {"TXNIsSelectionEmpty", (PyCFunction)TXNObj_TXNIsSelectionEmpty, 1,
+ "() -> (Boolean _rv)"},
+ {"TXNSetSelection", (PyCFunction)TXNObj_TXNSetSelection, 1,
+ "(TXNOffset iStartOffset, TXNOffset iEndOffset) -> None"},
+ {"TXNCountRunsInRange", (PyCFunction)TXNObj_TXNCountRunsInRange, 1,
+ "(UInt32 iStartOffset, UInt32 iEndOffset) -> (ItemCount oRunCount)"},
+ {"TXNDataSize", (PyCFunction)TXNObj_TXNDataSize, 1,
+ "() -> (ByteCount _rv)"},
+ {"TXNGetData", (PyCFunction)TXNObj_TXNGetData, 1,
+ "(TXNOffset iStartOffset, TXNOffset iEndOffset) -> (Handle oDataHandle)"},
+ {"TXNGetDataEncoded", (PyCFunction)TXNObj_TXNGetDataEncoded, 1,
+ "(TXNOffset iStartOffset, TXNOffset iEndOffset, TXNDataType iEncoding) -> (Handle oDataHandle)"},
+ {"TXNSetDataFromFile", (PyCFunction)TXNObj_TXNSetDataFromFile, 1,
+ "(SInt16 iFileRefNum, OSType iFileType, ByteCount iFileLength, TXNOffset iStartOffset, TXNOffset iEndOffset) -> None"},
+ {"TXNSetData", (PyCFunction)TXNObj_TXNSetData, 1,
+ "(TXNDataType iDataType, Buffer iDataPtr, TXNOffset iStartOffset, TXNOffset iEndOffset) -> None"},
+ {"TXNGetChangeCount", (PyCFunction)TXNObj_TXNGetChangeCount, 1,
+ "() -> (ItemCount _rv)"},
+ {"TXNSave", (PyCFunction)TXNObj_TXNSave, 1,
+ "(OSType iType, OSType iResType, TXNPermanentTextEncodingType iPermanentEncoding, FSSpec iFileSpecification, SInt16 iDataReference, SInt16 iResourceReference) -> None"},
+ {"TXNRevert", (PyCFunction)TXNObj_TXNRevert, 1,
+ "() -> None"},
+ {"TXNPageSetup", (PyCFunction)TXNObj_TXNPageSetup, 1,
+ "() -> None"},
+ {"TXNPrint", (PyCFunction)TXNObj_TXNPrint, 1,
+ "() -> None"},
+ {"TXNGetViewRect", (PyCFunction)TXNObj_TXNGetViewRect, 1,
+ "() -> (Rect oViewRect)"},
+ {"TXNAttachObjectToWindow", (PyCFunction)TXNObj_TXNAttachObjectToWindow, 1,
+ "(GWorldPtr iWindow, Boolean iIsActualWindow) -> None"},
+ {"TXNIsObjectAttachedToWindow", (PyCFunction)TXNObj_TXNIsObjectAttachedToWindow, 1,
+ "() -> (Boolean _rv)"},
+ {"TXNDragTracker", (PyCFunction)TXNObj_TXNDragTracker, 1,
+ "(TXNFrameID iTXNFrameID, DragTrackingMessage iMessage, WindowPtr iWindow, DragReference iDragReference, Boolean iDifferentObjectSameWindow) -> None"},
+ {"TXNDragReceiver", (PyCFunction)TXNObj_TXNDragReceiver, 1,
+ "(TXNFrameID iTXNFrameID, WindowPtr iWindow, DragReference iDragReference, Boolean iDifferentObjectSameWindow) -> None"},
+ {"TXNActivate", (PyCFunction)TXNObj_TXNActivate, 1,
+ "(TXNFrameID iTXNFrameID, TXNScrollBarState iActiveState) -> None"},
+ {"TXNDoFontMenuSelection", (PyCFunction)TXNObj_TXNDoFontMenuSelection, 1,
+ "(TXNFontMenuObject iTXNFontMenuObject, SInt16 iMenuID, SInt16 iMenuItem) -> None"},
+ {"TXNPrepareFontMenu", (PyCFunction)TXNObj_TXNPrepareFontMenu, 1,
+ "(TXNFontMenuObject iTXNFontMenuObject) -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain TXNObj_chain = { TXNObj_methods, NULL };
+
+static PyObject *TXNObj_getattr(TXNObjectObject *self, char *name)
+{
+ return Py_FindMethodInChain(&TXNObj_chain, (PyObject *)self, name);
+}
+
+#define TXNObj_setattr NULL
+
+#define TXNObj_compare NULL
+
+#define TXNObj_repr NULL
+
+#define TXNObj_hash NULL
+
+PyTypeObject TXNObject_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "TXNObject", /*tp_name*/
+ sizeof(TXNObjectObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) TXNObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) TXNObj_getattr, /*tp_getattr*/
+ (setattrfunc) TXNObj_setattr, /*tp_setattr*/
+ (cmpfunc) TXNObj_compare, /*tp_compare*/
+ (reprfunc) TXNObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) TXNObj_hash, /*tp_hash*/
+};
+
+/* ------------------- End object type TXNObject -------------------- */
+
+
+/* ----------------- Object type TXNFontMenuObject ------------------ */
+
+PyTypeObject TXNFontMenuObject_Type;
+
+#define TXNFontMenuObj_Check(x) ((x)->ob_type == &TXNFontMenuObject_Type)
+
+typedef struct TXNFontMenuObjectObject {
+ PyObject_HEAD
+ TXNFontMenuObject ob_itself;
+} TXNFontMenuObjectObject;
+
+PyObject *TXNFontMenuObj_New(TXNFontMenuObject itself)
+{
+ TXNFontMenuObjectObject *it;
+ if (itself == NULL) return PyMac_Error(resNotFound);
+ it = PyObject_NEW(TXNFontMenuObjectObject, &TXNFontMenuObject_Type);
+ if (it == NULL) return NULL;
+ it->ob_itself = itself;
+ return (PyObject *)it;
+}
+TXNFontMenuObj_Convert(PyObject *v, TXNFontMenuObject *p_itself)
+{
+ if (!TXNFontMenuObj_Check(v))
+ {
+ PyErr_SetString(PyExc_TypeError, "TXNFontMenuObject required");
+ return 0;
+ }
+ *p_itself = ((TXNFontMenuObjectObject *)v)->ob_itself;
+ return 1;
+}
+
+static void TXNFontMenuObj_dealloc(TXNFontMenuObjectObject *self)
+{
+ /* Cleanup of self->ob_itself goes here */
+ PyMem_DEL(self);
+}
+
+static PyObject *TXNFontMenuObj_TXNGetFontMenuHandle(TXNFontMenuObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ MenuHandle oFontMenuHandle;
+ PyMac_PRECHECK(TXNGetFontMenuHandle);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNGetFontMenuHandle(_self->ob_itself,
+ &oFontMenuHandle);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ MenuObj_New, oFontMenuHandle);
+ return _res;
+}
+
+static PyObject *TXNFontMenuObj_TXNDisposeFontMenuObject(TXNFontMenuObjectObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNDisposeFontMenuObject);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNDisposeFontMenuObject(_self->ob_itself);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyMethodDef TXNFontMenuObj_methods[] = {
+ {"TXNGetFontMenuHandle", (PyCFunction)TXNFontMenuObj_TXNGetFontMenuHandle, 1,
+ "() -> (MenuHandle oFontMenuHandle)"},
+ {"TXNDisposeFontMenuObject", (PyCFunction)TXNFontMenuObj_TXNDisposeFontMenuObject, 1,
+ "() -> None"},
+ {NULL, NULL, 0}
+};
+
+PyMethodChain TXNFontMenuObj_chain = { TXNFontMenuObj_methods, NULL };
+
+static PyObject *TXNFontMenuObj_getattr(TXNFontMenuObjectObject *self, char *name)
+{
+ return Py_FindMethodInChain(&TXNFontMenuObj_chain, (PyObject *)self, name);
+}
+
+#define TXNFontMenuObj_setattr NULL
+
+#define TXNFontMenuObj_compare NULL
+
+#define TXNFontMenuObj_repr NULL
+
+#define TXNFontMenuObj_hash NULL
+
+PyTypeObject TXNFontMenuObject_Type = {
+ PyObject_HEAD_INIT(&PyType_Type)
+ 0, /*ob_size*/
+ "TXNFontMenuObject", /*tp_name*/
+ sizeof(TXNFontMenuObjectObject), /*tp_basicsize*/
+ 0, /*tp_itemsize*/
+ /* methods */
+ (destructor) TXNFontMenuObj_dealloc, /*tp_dealloc*/
+ 0, /*tp_print*/
+ (getattrfunc) TXNFontMenuObj_getattr, /*tp_getattr*/
+ (setattrfunc) TXNFontMenuObj_setattr, /*tp_setattr*/
+ (cmpfunc) TXNFontMenuObj_compare, /*tp_compare*/
+ (reprfunc) TXNFontMenuObj_repr, /*tp_repr*/
+ (PyNumberMethods *)0, /* tp_as_number */
+ (PySequenceMethods *)0, /* tp_as_sequence */
+ (PyMappingMethods *)0, /* tp_as_mapping */
+ (hashfunc) TXNFontMenuObj_hash, /*tp_hash*/
+};
+
+/* --------------- End object type TXNFontMenuObject ---------------- */
+
+
+static PyObject *Mlte_TXNNewObject(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ FSSpec * iFileSpec;
+ WindowPtr iWindow;
+ Rect * iFrame;
+ TXNFrameOptions iFrameOptions;
+ TXNFrameType iFrameType;
+ TXNFileType iFileType;
+ TXNPermanentTextEncodingType iPermanentEncoding;
+ TXNObject oTXNObject;
+ TXNFrameID oTXNFrameID;
+ PyMac_PRECHECK(TXNNewObject);
+ if (!PyArg_ParseTuple(_args, "O&O&O&llO&l",
+ OptFSSpecPtr_Convert, &iFileSpec,
+ WinObj_Convert, &iWindow,
+ OptRectPtr_Convert, &iFrame,
+ &iFrameOptions,
+ &iFrameType,
+ PyMac_GetOSType, &iFileType,
+ &iPermanentEncoding))
+ return NULL;
+ _err = TXNNewObject(iFileSpec,
+ iWindow,
+ iFrame,
+ iFrameOptions,
+ iFrameType,
+ iFileType,
+ iPermanentEncoding,
+ &oTXNObject,
+ &oTXNFrameID,
+ (TXNObjectRefcon)0);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&l",
+ TXNObj_New, oTXNObject,
+ oTXNFrameID);
+ return _res;
+}
+
+static PyObject *Mlte_TXNTerminateTextension(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ PyMac_PRECHECK(TXNTerminateTextension);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ TXNTerminateTextension();
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Mlte_TXNIsScrapPastable(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ Boolean _rv;
+ PyMac_PRECHECK(TXNIsScrapPastable);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNIsScrapPastable();
+ _res = Py_BuildValue("b",
+ _rv);
+ return _res;
+}
+
+static PyObject *Mlte_TXNConvertToPublicScrap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNConvertToPublicScrap);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNConvertToPublicScrap();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Mlte_TXNConvertFromPublicScrap(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ PyMac_PRECHECK(TXNConvertFromPublicScrap);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _err = TXNConvertFromPublicScrap();
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+}
+
+static PyObject *Mlte_TXNNewFontMenuObject(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ OSStatus _err;
+ MenuHandle iFontMenuHandle;
+ SInt16 iMenuID;
+ SInt16 iStartHierMenuID;
+ TXNFontMenuObject oTXNFontMenuObject;
+ PyMac_PRECHECK(TXNNewFontMenuObject);
+ if (!PyArg_ParseTuple(_args, "O&hh",
+ MenuObj_Convert, &iFontMenuHandle,
+ &iMenuID,
+ &iStartHierMenuID))
+ return NULL;
+ _err = TXNNewFontMenuObject(iFontMenuHandle,
+ iMenuID,
+ iStartHierMenuID,
+ &oTXNFontMenuObject);
+ if (_err != noErr) return PyMac_Error(_err);
+ _res = Py_BuildValue("O&",
+ TXNFontMenuObj_New, oTXNFontMenuObject);
+ return _res;
+}
+
+static PyObject *Mlte_TXNVersionInformation(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+ TXNVersionValue _rv;
+ TXNFeatureBits oFeatureFlags;
+ PyMac_PRECHECK(TXNVersionInformation);
+ if (!PyArg_ParseTuple(_args, ""))
+ return NULL;
+ _rv = TXNVersionInformation(&oFeatureFlags);
+ _res = Py_BuildValue("ll",
+ _rv,
+ oFeatureFlags);
+ return _res;
+}
+
+static PyObject *Mlte_TXNInitTextension(PyObject *_self, PyObject *_args)
+{
+ PyObject *_res = NULL;
+
+ OSStatus _err;
+ TXNMacOSPreferredFontDescription * iDefaultFonts = NULL;
+ ItemCount iCountDefaultFonts = 0;
+ TXNInitOptions iUsageFlags;
+ PyMac_PRECHECK(TXNInitTextension);
+ if (!PyArg_ParseTuple(_args, "l", &iUsageFlags))
+ return NULL;
+ _err = TXNInitTextension(iDefaultFonts,
+ iCountDefaultFonts,
+ iUsageFlags);
+ if (_err != noErr) return PyMac_Error(_err);
+ Py_INCREF(Py_None);
+ _res = Py_None;
+ return _res;
+
+}
+
+static PyMethodDef Mlte_methods[] = {
+ {"TXNNewObject", (PyCFunction)Mlte_TXNNewObject, 1,
+ "(FSSpec * iFileSpec, WindowPtr iWindow, Rect * iFrame, TXNFrameOptions iFrameOptions, TXNFrameType iFrameType, TXNFileType iFileType, TXNPermanentTextEncodingType iPermanentEncoding) -> (TXNObject oTXNObject, TXNFrameID oTXNFrameID)"},
+ {"TXNTerminateTextension", (PyCFunction)Mlte_TXNTerminateTextension, 1,
+ "() -> None"},
+ {"TXNIsScrapPastable", (PyCFunction)Mlte_TXNIsScrapPastable, 1,
+ "() -> (Boolean _rv)"},
+ {"TXNConvertToPublicScrap", (PyCFunction)Mlte_TXNConvertToPublicScrap, 1,
+ "() -> None"},
+ {"TXNConvertFromPublicScrap", (PyCFunction)Mlte_TXNConvertFromPublicScrap, 1,
+ "() -> None"},
+ {"TXNNewFontMenuObject", (PyCFunction)Mlte_TXNNewFontMenuObject, 1,
+ "(MenuHandle iFontMenuHandle, SInt16 iMenuID, SInt16 iStartHierMenuID) -> (TXNFontMenuObject oTXNFontMenuObject)"},
+ {"TXNVersionInformation", (PyCFunction)Mlte_TXNVersionInformation, 1,
+ "() -> (TXNVersionValue _rv, TXNFeatureBits oFeatureFlags)"},
+ {"TXNInitTextension", (PyCFunction)Mlte_TXNInitTextension, 1,
+ "(TXNInitOptions) -> None"},
+ {NULL, NULL, 0}
+};
+
+
+
+
+void initMlte(void)
+{
+ PyObject *m;
+ PyObject *d;
+
+
+
+ // PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
+
+
+ m = Py_InitModule("Mlte", Mlte_methods);
+ d = PyModule_GetDict(m);
+ Mlte_Error = PyMac_GetOSErrException();
+ if (Mlte_Error == NULL ||
+ PyDict_SetItemString(d, "Error", Mlte_Error) != 0)
+ return;
+ TXNObject_Type.ob_type = &PyType_Type;
+ Py_INCREF(&TXNObject_Type);
+ if (PyDict_SetItemString(d, "TXNObjectType", (PyObject *)&TXNObject_Type) != 0)
+ Py_FatalError("can't initialize TXNObjectType");
+ TXNFontMenuObject_Type.ob_type = &PyType_Type;
+ Py_INCREF(&TXNFontMenuObject_Type);
+ if (PyDict_SetItemString(d, "TXNFontMenuObjectType", (PyObject *)&TXNFontMenuObject_Type) != 0)
+ Py_FatalError("can't initialize TXNFontMenuObjectType");
+}
+
+/* ======================== End module Mlte ========================= */
+
--- /dev/null
+# Scan an Apple header file, generating a Python file of generator calls.
+
+import sys
+import os
+BGENDIR=os.path.join(sys.prefix, ':Tools:bgen:bgen')
+sys.path.append(BGENDIR)
+from scantools import Scanner_OSX
+from bgenlocations import TOOLBOXDIR
+
+LONG = "MacTextEditor"
+SHORT = "mlte"
+OBJECTS = ("TXNObject", "TXNFontMenuObject")
+# ADD object typenames here
+
+def main():
+ input = "MacTextEditor.h"
+ output = SHORT + "gen.py"
+ defsoutput = TOOLBOXDIR + LONG + ".py"
+ scanner = MyScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.gentypetest(SHORT+"typetest.py")
+ scanner.close()
+ 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]
+ if t in OBJECTS and m == "InMode":
+ classname = "Method"
+ listname = t + "_methods"
+ return classname, listname
+
+ def writeinitialdefs(self):
+ self.defsfile.write("""
+def FOUR_CHAR_CODE(x): return x
+false = 0
+true = 1
+kTXNClearThisControl = 0xFFFFFFFF
+kTXNClearTheseFontFeatures = 0x80000000
+kTXNDontCareTypeSize = 0xFFFFFFFF
+kTXNDecrementTypeSize = 0x80000000
+kTXNUseCurrentSelection = 0xFFFFFFFF
+kTXNStartOffset = 0
+kTXNEndOffset = 0x7FFFFFFF
+MovieFileType = FOUR_CHAR_CODE('moov')
+""")
+
+ def makeblacklistnames(self):
+ return [
+ "TXNGetFontDefaults", # Arg is too difficult
+ "TXNSetFontDefaults", # Arg is too difficult
+ "TXNInitTextension", # done manually
+
+ # Constants with funny definitions
+ "kTXNClearThisControl",
+ "kTXNClearTheseFontFeatures",
+ "kTXNDontCareTypeSize",
+ "kTXNDecrementTypeSize",
+ "kTXNUseCurrentSelection",
+ "kTXNStartOffset",
+ "kTXNEndOffset",
+ "kTXNQDFontNameAttributeSize",
+ "kTXNQDFontFamilyIDAttributeSize",
+ "kTXNQDFontSizeAttributeSize",
+ "kTXNQDFontStyleAttributeSize",
+ "kTXNQDFontColorAttributeSize",
+ "kTXNTextEncodingAttributeSize",
+ "status",
+ "justification",
+ ]
+
+ def makegreylist(self):
+ return []
+
+ def makeblacklisttypes(self):
+ return [
+ "TXNTab", # TBD
+ "TXNMargins", # TBD
+ "TXNControlData", #TBD
+ "TXNATSUIFeatures", #TBD
+ "TXNATSUIVariations", #TBD
+ "TXNAttributeData", #TBD
+ "TXNTypeAttributes", #TBD
+ "TXNMatchTextRecord", #TBD
+ "TXNBackground", #TBD
+ "UniChar", #TBD
+ "TXNFindUPP",
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ # TXNNewObject has a lot of optional parameters
+ ([("FSSpec_ptr", "iFileSpec", "InMode")],
+ [("OptFSSpecPtr", "*", "*")]),
+ ([("Rect", "iFrame", "OutMode")],
+ [("OptRectPtr", "*", "InMode")]),
+
+ # In UH 332 some of the "const" are missing for input parameters passed
+ # by reference. We fix that up here.
+ ([("EventRecord", "iEvent", "OutMode")],
+ [("EventRecord_ptr", "*", "InMode")]),
+ ([("FSSpec", "iFileSpecification", "OutMode")],
+ [("FSSpec_ptr", "*", "InMode")]),
+ ([("TXNMacOSPreferredFontDescription", "iFontDefaults", "OutMode")],
+ [("TXNMacOSPreferredFontDescription_ptr", "*", "InMode")]),
+
+ # In buffers are passed as void *
+ ([("void", "*", "OutMode"), ("ByteCount", "*", "InMode")],
+ [("MlteInBuffer", "*", "InMode")]),
+
+ # The AdjustCursor region handle is optional
+ ([("RgnHandle", "ioCursorRgn", "InMode")],
+ [("OptRgnHandle", "*", "*")]),
+
+ # The GWorld for TXNDraw is optional
+ ([('GWorldPtr', 'iDrawPort', 'InMode')],
+ [('OptGWorldPtr', '*', '*')]),
+ ]
+
+if __name__ == "__main__":
+ main()
--- /dev/null
+# 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).
+
+#error missing SetActionFilter
+
+import string
+
+# Declarations that change for each manager
+MODNAME = 'Mlte' # The name of the module
+
+# The following is *usually* unchanged but may still require tuning
+MODPREFIX = MODNAME # 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
+
+includestuff = includestuff + """
+#ifdef WITHOUT_FRAMEWORKS
+#include <MacTextEditor.h>
+#else
+#include <xxxx.h>
+#endif
+
+/* For now we declare them forward here. They'll go to mactoolbox later */
+staticforward PyObject *TXNObj_New(TXNObject);
+staticforward int TXNObj_Convert(PyObject *, TXNObject *);
+staticforward PyObject *TXNFontMenuObj_New(TXNFontMenuObject);
+staticforward int TXNFontMenuObj_Convert(PyObject *, TXNFontMenuObject *);
+
+// ADD declarations
+#ifdef NOTYET_USE_TOOLBOX_OBJECT_GLUE
+//extern PyObject *_CFTypeRefObj_New(CFTypeRef);
+//extern int _CFTypeRefObj_Convert(PyObject *, CFTypeRef *);
+
+//#define CFTypeRefObj_New _CFTypeRefObj_New
+//#define CFTypeRefObj_Convert _CFTypeRefObj_Convert
+#endif
+
+/*
+** Parse an optional fsspec
+*/
+static int
+OptFSSpecPtr_Convert(PyObject *v, FSSpec **p_itself)
+{
+ static FSSpec fss;
+ if (v == Py_None)
+ {
+ *p_itself = NULL;
+ return 1;
+ }
+ *p_itself = &fss;
+ return PyMac_GetFSSpec(v, *p_itself);
+}
+
+/*
+** Parse an optional rect
+*/
+static int
+OptRectPtr_Convert(PyObject *v, Rect **p_itself)
+{
+ static Rect r;
+
+ if (v == Py_None)
+ {
+ *p_itself = NULL;
+ return 1;
+ }
+ *p_itself = &r;
+ return PyMac_GetRect(v, *p_itself);
+}
+
+/*
+** Parse an optional GWorld
+*/
+static int
+OptGWorldObj_Convert(PyObject *v, GWorldPtr *p_itself)
+{
+ if (v == Py_None)
+ {
+ *p_itself = NULL;
+ return 1;
+ }
+ return GWorldObj_Convert(v, p_itself);
+}
+
+"""
+
+initstuff = initstuff + """
+// PyMac_INIT_TOOLBOX_OBJECT_NEW(xxxx);
+"""
+TXNObject = OpaqueByValueType("TXNObject", "TXNObj")
+TXNFontMenuObject = OpaqueByValueType("TXNFontMenuObject", "TXNFontMenuObj")
+
+TXNFrameID = Type("TXNFrameID", "l")
+TXNVersionValue = Type("TXNVersionValue", "l")
+TXNFeatureBits = Type("TXNFeatureBits", "l")
+TXNInitOptions = Type("TXNInitOptions", "l")
+TXNFrameOptions = Type("TXNFrameOptions", "l")
+TXNContinuousFlags = Type("TXNContinuousFlags", "l")
+TXNMatchOptions = Type("TXNMatchOptions", "l")
+TXNFileType = OSTypeType("TXNFileType")
+TXNFrameType = Type("TXNFrameType", "l")
+TXNDataType = OSTypeType("TXNDataType")
+TXNControlTag = OSTypeType("TXNControlTag")
+TXNActionKey = Type("TXNActionKey", "l")
+TXNTabType = Type("TXNTabType", "b")
+TXNScrollBarState = Type("TXNScrollBarState", "l")
+TXNOffset = Type("TXNOffset", "l")
+TXNObjectRefcon = FakeType("(TXNObjectRefcon)0") # XXXX For now...
+TXNErrors = OSErrType("TXNErrors", "l")
+TXNTypeRunAttributes = OSTypeType("TXNTypeRunAttributes")
+TXNTypeRunAttributeSizes = Type("TXNTypeRunAttributeSizes", "l")
+TXNPermanentTextEncodingType = Type("TXNPermanentTextEncodingType", "l")
+TXTNTag = OSTypeType("TXTNTag")
+TXNBackgroundType = Type("TXNBackgroundType", "l")
+DragReference = OpaqueByValueType("DragReference", "DragObj")
+DragTrackingMessage = Type("DragTrackingMessage", "h")
+RgnHandle = OpaqueByValueType("RgnHandle", "ResObj")
+OptRgnHandle = OpaqueByValueType("RgnHandle", "OptResObj")
+GWorldPtr = OpaqueByValueType("GWorldPtr", "GWorldObj")
+OptGWorldPtr = OpaqueByValueType("GWorldPtr", "OptGWorldObj")
+MlteInBuffer = VarInputBufferType('void *', 'ByteCount', 'l')
+
+OptFSSpecPtr = OpaqueByValueType("FSSpec *", "OptFSSpecPtr")
+OptRectPtr = OpaqueByValueType("Rect *", "OptRectPtr")
+# ADD object type here
+
+execfile("mltetypetest.py")
+
+# Our (opaque) objects
+
+class TXNObjDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+class TXNFontMenuObjDefinition(GlobalObjectDefinition):
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+
+# ADD object class here
+
+# From here on it's basically all boiler plate...
+
+# Create the generator groups and link them
+module = MacModule(MODNAME, MODPREFIX, includestuff, finalstuff, initstuff)
+TXNObject_object = TXNObjDefinition("TXNObject", "TXNObj", "TXNObject")
+TXNFontMenuObject_object = TXNFontMenuObjDefinition("TXNFontMenuObject", "TXNFontMenuObj", "TXNFontMenuObject")
+
+# ADD object here
+
+module.addobject(TXNObject_object)
+module.addobject(TXNFontMenuObject_object)
+# ADD addobject call here
+
+# Create the generator classes used to populate the lists
+Function = OSErrWeakLinkFunctionGenerator
+Method = OSErrWeakLinkMethodGenerator
+
+# Create and populate the lists
+functions = []
+TXNObject_methods = []
+TXNFontMenuObject_methods = []
+
+# ADD _methods initializer here
+execfile(INPUTFILE)
+
+
+# add the populated lists to the generator groups
+# (in a different wordl the scan program would generate this)
+for f in functions: module.add(f)
+for f in TXNObject_methods: TXNObject_object.add(f)
+for f in TXNFontMenuObject_methods: TXNFontMenuObject_object.add(f)
+
+# ADD Manual generators here
+inittextension_body = """
+OSStatus _err;
+TXNMacOSPreferredFontDescription * iDefaultFonts = NULL;
+ItemCount iCountDefaultFonts = 0;
+TXNInitOptions iUsageFlags;
+PyMac_PRECHECK(TXNInitTextension);
+if (!PyArg_ParseTuple(_args, "l", &iUsageFlags))
+ return NULL;
+_err = TXNInitTextension(iDefaultFonts,
+ iCountDefaultFonts,
+ iUsageFlags);
+if (_err != noErr) return PyMac_Error(_err);
+Py_INCREF(Py_None);
+_res = Py_None;
+return _res;
+"""
+
+f = ManualGenerator("TXNInitTextension", inittextension_body);
+f.docstring = lambda: "(TXNInitOptions) -> None"
+module.add(f)
+
+# generate output (open the output file as late as possible)
+SetOutputFileName(OUTPUTFILE)
+module.generate()
+
--- /dev/null
+/***********************************************************
+Copyright 1991-1997 by Stichting Mathematisch Centrum, Amsterdam,
+The Netherlands.
+
+ All Rights Reserved
+
+Permission to use, copy, modify, and distribute this software and its
+documentation for any purpose and without fee is hereby granted,
+provided that the above copyright notice appear in all copies and that
+both that copyright notice and this permission notice appear in
+supporting documentation, and that the names of Stichting Mathematisch
+Centrum or CWI not be used in advertising or publicity pertaining to
+distribution of the software without specific, written prior permission.
+
+STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
+THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
+FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
+FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
+WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
+ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
+OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
+
+******************************************************************/
+
+
+#include "Python.h"
+
+#include "macglue.h"
+#include "marshal.h"
+#include "import.h"
+#include "importdl.h"
+#include "pymactoolbox.h"
+
+#include "pythonresources.h"
+
+#ifdef WITHOUT_FRAMEWORKS
+#include <OSUtils.h> /* for Set(Current)A5 */
+#include <Files.h>
+#include <StandardFile.h>
+#include <Resources.h>
+#include <Memory.h>
+#include <Windows.h>
+#include <Traps.h>
+#include <Processes.h>
+#include <Fonts.h>
+#include <Menus.h>
+#include <TextUtils.h>
+#include <LowMem.h>
+#ifdef __CFM68K__
+/* cfm68k InterfaceLib exports GetEventQueue, but Events.h doesn't know this
+** and defines it as GetEvQHdr (which is correct for PPC). This fix is for
+** CW9, check that the workaround is still needed for the next release.
+*/
+#define GetEvQHdr GetEventQueue
+#endif /* __CFM68K__ */
+
+#include <Events.h>
+
+#ifdef __CFM68K__
+#undef GetEventQueue
+#endif /* __CFM68K__ */
+#else
+#include <Carbon/Carbon.h>
+#endif
+
+#if !TARGET_API_MAC_OS8
+/* Unfortunately this call is probably slower... */
+#define LMGetTicks() TickCount()
+#endif
+
+#ifdef __MWERKS__
+#include <SIOUX.h>
+extern void SIOUXSetupMenus(void);
+extern void SIOUXDoAboutBox(void);
+#endif
+#ifdef USE_GUSI
+/* Functions we redefine because they're in obscure libraries */
+extern void SpinCursor(short x);
+extern void RotateCursor(short x);
+extern pascal void PLstrcpy(unsigned char *, unsigned char *);
+extern pascal int PLstrcmp(unsigned char *, unsigned char *);
+extern pascal unsigned char *PLstrrchr(unsigned char *, unsigned char);
+
+#endif
+
+#ifdef USE_GUSI1
+#include <TFileSpec.h> /* For Path2FSSpec */
+#include <GUSI.h>
+#endif
+
+/* The ID of the Sioux apple menu */
+#define SIOUX_APPLEID 32000
+
+#include <signal.h>
+#include <stdio.h>
+
+/*
+** When less than this amount of stackspace is left we
+** raise a MemoryError.
+*/
+#ifndef MINIMUM_STACK_SIZE
+#ifdef __powerc
+#define MINIMUM_STACK_SIZE 8192
+#else
+#define MINIMUM_STACK_SIZE 4096
+#endif
+#endif
+
+#if TARGET_API_MAC_CARBON
+/*
+** On MacOSX StackSpace() lies: it gives the distance from heap end to stack pointer,
+** but the stack cannot grow that far due to rlimit values. We cannot get at this value
+** from Carbon, so we set a maximum to the stack here that is based on the default
+** stack limit of 512K.
+*/
+#define MAXIMUM_STACK_SIZE (256*1024)
+#endif
+
+/*
+** We have to be careful, since we can't handle
+** things like updates (and they'll keep coming back if we don't
+** handle them). Note that we don't know who has windows open, so
+** even handing updates off to SIOUX under MW isn't going to work.
+*/
+#define MAINLOOP_EVENTMASK (mDownMask|keyDownMask|osMask|activMask)
+
+#include <signal.h>
+
+/* XXX We should include Errors.h here, but it has a name conflict
+** with the python errors.h. */
+#define fnfErr -43
+
+/* Interrupt code variables: */
+static int interrupted; /* Set to true when cmd-. seen */
+static RETSIGTYPE intcatcher(int);
+
+#if !TARGET_API_MAC_OSX
+static int PyMac_Yield(void);
+#endif
+
+/*
+** These are the real scheduling parameters that control what we check
+** in the event loop, and how often we check. The values are initialized
+** from pyMac_SchedParamStruct.
+*/
+
+struct real_sched_param_struct {
+ int check_interrupt; /* if true check for command-dot */
+ int process_events; /* if nonzero enable evt processing, this mask */
+ int besocial; /* if nonzero be a little social with CPU */
+ unsigned long check_interval; /* how often to check, in ticks */
+ unsigned long bg_yield; /* yield so long when in background */
+ /* these are computed from previous and clock and such */
+ int enabled; /* check_interrupt OR process_event OR yield */
+ unsigned long next_check; /* when to check/yield next, in ticks */
+};
+
+static struct real_sched_param_struct schedparams =
+ { 1, MAINLOOP_EVENTMASK, 1, 15, 15, 1, 0};
+
+/*
+** Workaround for sioux/gusi combo: set when we are exiting
+*/
+int PyMac_ConsoleIsDead;
+
+/*
+** Sioux menu bar, saved early so we can restore it
+*/
+static MenuBarHandle sioux_mbar;
+
+/*
+** Some stuff for our GetDirectory and PromptGetFile routines
+*/
+struct hook_args {
+ int selectcur_hit; /* Set to true when "select current" selected */
+ char *prompt; /* The prompt */
+};
+#if !TARGET_API_MAC_OS8
+/* The StandardFile hooks don't exist in Carbon. This breaks GetDirectory,
+** but the macfsn code will replace it by a NavServices version anyway.
+*/
+#define myhook_upp NULL
+#else
+static DlgHookYDUPP myhook_upp;
+static int upp_inited = 0;
+#endif
+
+/*
+** The python-code event handler
+*/
+static PyObject *python_event_handler;
+
+/*
+** Set to true if we're appearance-compliant
+*/
+int PyMac_AppearanceCompliant;
+
+/*
+** Find out what the current script is.
+** Donated by Fredrik Lund.
+*/
+char *PyMac_getscript()
+{
+ int font, script, lang;
+ font = 0;
+ font = GetSysFont();
+ script = FontToScript(font);
+ switch (script) {
+ case smRoman:
+ lang = GetScriptVariable(script, smScriptLang);
+ if (lang == langIcelandic)
+ return "mac-iceland";
+ else if (lang == langTurkish)
+ return "mac-turkish";
+ else if (lang == langGreek)
+ return "mac-greek";
+ else
+ return "mac-roman";
+ break;
+#if 0
+ /* We don't have a codec for this, so don't return it */
+ case smJapanese:
+ return "mac-japan";
+#endif
+ case smGreek:
+ return "mac-greek";
+ case smCyrillic:
+ return "mac-cyrillic";
+ default:
+ return "mac-roman"; /* better than nothing */
+ }
+}
+
+/* Given an FSSpec, return the FSSpec of the parent folder */
+
+static OSErr
+get_folder_parent (FSSpec * fss, FSSpec * parent)
+{
+ CInfoPBRec rec;
+ short err;
+
+ * parent = * fss;
+ rec.hFileInfo.ioNamePtr = parent->name;
+ rec.hFileInfo.ioVRefNum = parent->vRefNum;
+ rec.hFileInfo.ioDirID = parent->parID;
+ rec.hFileInfo.ioFDirIndex = -1;
+ rec.hFileInfo.ioFVersNum = 0;
+ if (err = PBGetCatInfoSync (& rec))
+ return err;
+ parent->parID = rec.dirInfo.ioDrParID;
+/* parent->name[0] = 0; */
+ return 0;
+}
+
+/* Given an FSSpec return a full, colon-separated pathname */
+
+OSErr
+PyMac_GetFullPath (FSSpec *fss, char *buf)
+{
+ short err;
+ FSSpec fss_parent, fss_current;
+ char tmpbuf[1024];
+ int plen;
+
+ fss_current = *fss;
+ plen = fss_current.name[0];
+ memcpy(buf, &fss_current.name[1], plen);
+ buf[plen] = 0;
+ /* Special case for disk names */
+ if ( fss_current.parID <= 1 ) {
+ buf[plen++] = ':';
+ buf[plen] = 0;
+ return 0;
+ }
+ while (fss_current.parID > 1) {
+ /* Get parent folder name */
+ if (err = get_folder_parent(&fss_current, &fss_parent))
+ return err;
+ fss_current = fss_parent;
+ /* Prepend path component just found to buf */
+ plen = fss_current.name[0];
+ if (strlen(buf) + plen + 1 > 1024) {
+ /* Oops... Not enough space (shouldn't happen) */
+ *buf = 0;
+ return -1;
+ }
+ memcpy(tmpbuf, &fss_current.name[1], plen);
+ tmpbuf[plen] = ':';
+ strcpy(&tmpbuf[plen+1], buf);
+ strcpy(buf, tmpbuf);
+ }
+ return 0;
+}
+
+#ifdef USE_GUSI1
+/*
+** GUSI (1.6.0 and earlier, at the least) do not set the MacOS idea of
+** the working directory. Hence, we call this routine after each call
+** to chdir() to rectify things.
+*/
+void
+PyMac_FixGUSIcd()
+{
+ WDPBRec pb;
+ FSSpec curdirfss;
+
+ if ( Path2FSSpec(":x", &curdirfss) != noErr )
+ return;
+
+ /* Set MacOS "working directory" */
+ pb.ioNamePtr= "\p";
+ pb.ioVRefNum= curdirfss.vRefNum;
+ pb.ioWDDirID= curdirfss.parID;
+ if (PBHSetVolSync(&pb) != noErr)
+ return;
+}
+#endif
+
+#ifdef USE_GUSI
+/*
+** SpinCursor (needed by GUSI) drags in heaps of stuff, so we
+** provide a dummy here.
+*/
+void SpinCursor(short x) { /* Dummy */ }
+void RotateCursor(short x) { /* Dummy */ }
+
+/*
+** Replacement GUSI Spin function
+*/
+#ifdef USE_GUSI1
+static int
+PyMac_GUSISpin(spin_msg msg, long arg)
+{
+ static Boolean inForeground = true;
+ int maxsleep = 6; /* 6 ticks is "normal" sleeptime */
+
+ if (PyMac_ConsoleIsDead) return 0;
+#if 0
+ if (inForeground)
+ SpinCursor(msg == SP_AUTO_SPIN ? short(arg) : 1);
+#endif
+
+ if (interrupted) return -1;
+
+ if ( msg == SP_AUTO_SPIN )
+ maxsleep = 0;
+ if ( msg==SP_SLEEP||msg==SP_SELECT )
+ maxsleep = arg;
+
+ PyMac_DoYield(maxsleep, 0); /* XXXX or is it safe to call python here? */
+
+ return 0;
+}
+
+void
+PyMac_SetGUSISpin() {
+ GUSISetHook(GUSI_SpinHook, (GUSIHook)PyMac_GUSISpin);
+}
+#endif
+
+/* Called at exit() time thru atexit(), to stop event processing */
+void
+PyMac_StopGUSISpin() {
+ PyMac_ConsoleIsDead = 1;
+}
+
+#if TARGET_API_MAC_OS8
+/*
+** Replacement routines for the PLstr... functions so we don't need
+** StdCLib.
+*/
+pascal void
+PLstrcpy(unsigned char *to, unsigned char *fr)
+{
+ memcpy(to, fr, fr[0]+1);
+}
+
+pascal int
+PLstrcmp(unsigned char *s1, unsigned char *s2)
+{
+ int res;
+ int l = s1[0] < s2[0] ? s1[0] : s2[0];
+
+ res = memcmp(s1+1, s2+1, l);
+ if ( res != 0 )
+ return res;
+
+ if ( s1[0] < s2[0] )
+ return -1;
+ else if ( s1[0] > s2[0] )
+ return 1;
+ else
+ return 0;
+}
+
+pascal unsigned char *
+PLstrrchr(unsigned char *str, unsigned char chr)
+{
+ unsigned char *ptr = 0;
+ unsigned char *p;
+
+ for(p=str+1; p<str+str[0]; p++)
+ if ( *p == chr )
+ ptr = p;
+ return ptr;
+}
+
+#endif /* TARGET_API_MAC_OS8 */
+#endif /* USE_GUSI */
+
+
+/* Convert C to Pascal string. Returns pointer to static buffer. */
+unsigned char *
+Pstring(char *str)
+{
+ static Str255 buf;
+ int len;
+
+ len = strlen(str);
+ if (len > 255)
+ len = 255;
+ buf[0] = (unsigned char)len;
+ strncpy((char *)buf+1, str, len);
+ return buf;
+}
+
+#if TARGET_API_MAC_OS8
+void
+c2pstrcpy(unsigned char *dst, const char *src)
+{
+ int len;
+
+ len = strlen(src);
+ if ( len > 255 ) len = 255;
+ strncpy((char *)dst+1, src, len);
+ dst[0] = len;
+}
+#endif /* TARGET_API_MAC_OS8 */
+
+/* Like strerror() but for Mac OS error numbers */
+char *PyMac_StrError(int err)
+{
+ static char buf[256];
+ Handle h;
+ char *str;
+
+ h = GetResource('Estr', err);
+ if ( h ) {
+ HLock(h);
+ str = (char *)*h;
+ memcpy(buf, str+1, (unsigned char)str[0]);
+ buf[(unsigned char)str[0]] = '\0';
+ HUnlock(h);
+ ReleaseResource(h);
+ } else {
+ sprintf(buf, "Mac OS error code %d", err);
+ }
+ return buf;
+}
+
+/* Exception object shared by all Mac specific modules for Mac OS errors */
+PyObject *PyMac_OSErrException;
+
+/* Initialize and return PyMac_OSErrException */
+PyObject *
+PyMac_GetOSErrException()
+{
+ if (PyMac_OSErrException == NULL)
+ PyMac_OSErrException = PyString_FromString("MacOS.Error");
+ return PyMac_OSErrException;
+}
+
+/* Set a MAC-specific error from errno, and return NULL; return None if no error */
+PyObject *
+PyErr_Mac(PyObject *eobj, int err)
+{
+ char *msg;
+ PyObject *v;
+
+ if (err == 0 && !PyErr_Occurred()) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ if (err == -1 && PyErr_Occurred())
+ return NULL;
+ msg = PyMac_StrError(err);
+ v = Py_BuildValue("(is)", err, msg);
+ PyErr_SetObject(eobj, v);
+ Py_DECREF(v);
+ return NULL;
+}
+
+/* Call PyErr_Mac with PyMac_OSErrException */
+PyObject *
+PyMac_Error(OSErr err)
+{
+ return PyErr_Mac(PyMac_GetOSErrException(), err);
+}
+
+#ifdef USE_STACKCHECK
+/* Check for stack overflow */
+int
+PyOS_CheckStack()
+{
+ char here;
+ static char *sentinel = 0;
+ static PyThreadState *thread_for_sentinel = 0;
+
+ if ( sentinel == 0 ) {
+ unsigned long stackspace = StackSpace();
+
+#ifdef MAXIMUM_STACK_SIZE
+ /* See the comment at the definition */
+ if ( stackspace > MAXIMUM_STACK_SIZE )
+ stackspace = MAXIMUM_STACK_SIZE;
+#endif
+ sentinel = &here - stackspace + MINIMUM_STACK_SIZE;
+ }
+ if ( thread_for_sentinel == 0 ) {
+ thread_for_sentinel = PyThreadState_Get();
+ }
+ if ( &here < sentinel ) {
+ if (thread_for_sentinel == PyThreadState_Get()) {
+ return -1;
+#if 0
+ } else {
+ /* Else we are unsure... */
+ fprintf(stderr, "Stackcheck in other thread (was %x now %x)\n", thread_for_sentinel,PyThreadState_Get());
+#endif
+ }
+ }
+ return 0;
+}
+#endif /* USE_STACKCHECK */
+
+#if !TARGET_API_MAC_OSX
+/* The catcher routine (which may not be used for all compilers) */
+static RETSIGTYPE
+intcatcher(sig)
+ int sig;
+{
+ interrupted = 1;
+ signal(SIGINT, intcatcher);
+}
+
+void
+PyOS_InitInterrupts()
+{
+ if (signal(SIGINT, SIG_IGN) != SIG_IGN)
+ signal(SIGINT, intcatcher);
+}
+
+void
+PyOS_FiniInterrupts()
+{
+}
+
+/*
+** This routine scans the event queue looking for cmd-.
+** This is the only way to get an interrupt under THINK (since it
+** doesn't do SIGINT handling), but is also used under MW, when
+** the full-fledged event loop is disabled. This way, we can at least
+** interrupt a runaway python program.
+*/
+static void
+scan_event_queue(flush)
+ int flush;
+{
+#if !TARGET_API_MAC_OS8
+ if ( CheckEventQueueForUserCancel() )
+ interrupted = 1;
+#else
+ register EvQElPtr q;
+
+ q = (EvQElPtr) LMGetEventQueue()->qHead;
+
+ for (; q; q = (EvQElPtr)q->qLink) {
+ if (q->evtQWhat == keyDown &&
+ (char)q->evtQMessage == '.' &&
+ (q->evtQModifiers & cmdKey) != 0) {
+ if ( flush )
+ FlushEvents(keyDownMask, 0);
+ interrupted = 1;
+ break;
+ }
+ }
+#endif
+}
+
+int
+PyErr_CheckSignals()
+{
+ if (schedparams.enabled) {
+ if ( (unsigned long)LMGetTicks() > schedparams.next_check ) {
+ if ( PyMac_Yield() < 0)
+ return -1;
+ schedparams.next_check = (unsigned long)LMGetTicks()
+ + schedparams.check_interval;
+ if (interrupted) {
+ scan_event_queue(1); /* Eat events up to cmd-. */
+ interrupted = 0;
+ PyErr_SetNone(PyExc_KeyboardInterrupt);
+ return -1;
+ }
+ }
+ }
+ return 0;
+}
+
+int
+PyOS_InterruptOccurred()
+{
+ scan_event_queue(1);
+ return interrupted;
+}
+
+/* Check whether we are in the foreground */
+static int
+PyMac_InForeground(void)
+{
+ static ProcessSerialNumber ours;
+ static inited;
+ ProcessSerialNumber curfg;
+ Boolean eq;
+
+ if ( inited == 0 ) {
+ (void)GetCurrentProcess(&ours);
+ inited = 1;
+ }
+ if ( GetFrontProcess(&curfg) < 0 )
+ eq = 1;
+ else if ( SameProcess(&ours, &curfg, &eq) < 0 )
+ eq = 1;
+ return (int)eq;
+}
+#endif
+
+int
+PyMac_SetEventHandler(PyObject *evh)
+{
+ if ( evh && python_event_handler ) {
+ PyErr_SetString(PyExc_RuntimeError, "Python event handler already set");
+ return 0;
+ }
+ if ( python_event_handler )
+ Py_DECREF(python_event_handler);
+ if ( evh )
+ Py_INCREF(evh);
+ python_event_handler = evh;
+ return 1;
+}
+
+/*
+** Handle an event, either one found in the mainloop eventhandler or
+** one passed back from the python program.
+*/
+void
+PyMac_HandleEventIntern(evp)
+ EventRecord *evp;
+{
+#if TARGET_API_MAC_OS8
+ if ( evp->what == mouseDown ) {
+ WindowPtr wp;
+
+ if ( FindWindow(evp->where, &wp) == inSysWindow ) {
+ SystemClick(evp, wp);
+ return;
+ }
+ }
+#endif
+#ifdef __MWERKS__
+ {
+ int siouxdidit;
+
+ /* If SIOUX wants it we're done */
+ siouxdidit = SIOUXHandleOneEvent(evp);
+ if ( siouxdidit )
+ return;
+ }
+#else
+ /* Other compilers are just unlucky... */
+#endif /* !__MWERKS__ */
+}
+
+/*
+** Handle an event, either through HandleEvent or by passing it to the Python
+** event handler.
+*/
+int
+PyMac_HandleEvent(evp)
+ EventRecord *evp;
+{
+ PyObject *rv;
+
+ if ( python_event_handler ) {
+ rv = PyObject_CallFunction(python_event_handler, "(O&)",
+ PyMac_BuildEventRecord, evp);
+ if ( rv )
+ Py_DECREF(rv);
+ else
+ return -1; /* Propagate exception */
+ } else {
+ PyMac_HandleEventIntern(evp);
+ }
+ return 0;
+}
+
+#if !TARGET_API_MAC_OSX
+/*
+** Yield the CPU to other tasks without processing events.
+*/
+int
+PyMac_DoYield(int maxsleep, int maycallpython)
+{
+ EventRecord ev;
+ int gotone;
+ long latest_time_ready;
+ static int in_here = 0;
+
+ in_here++;
+ /*
+ ** First check for interrupts, if wanted.
+ ** This sets a flag that will be picked up at an appropriate
+ ** moment in the mainloop.
+ */
+ if (schedparams.check_interrupt)
+ scan_event_queue(0);
+
+ /* XXXX Implementing an idle routine goes here */
+
+ /*
+ ** Check which of the eventloop cases we have:
+ ** - process events
+ ** - don't process events but do yield
+ ** - do neither
+ */
+ if( in_here > 1 || !schedparams.process_events ||
+ (python_event_handler && !maycallpython) ) {
+ if ( maxsleep >= 0 ) {
+#if TARGET_API_MAC_OS8
+ SystemTask();
+#else
+ int xxx = 0;
+#endif
+ }
+ } else {
+ latest_time_ready = LMGetTicks() + maxsleep;
+ do {
+ /* XXXX Hack by Jack.
+ ** In time.sleep() you can click to another application
+ ** once only. If you come back to Python you cannot get away
+ ** again.
+ **/
+ gotone = WaitNextEvent(schedparams.process_events, &ev, maxsleep, NULL);
+ /* Get out quickly if nothing interesting is happening */
+ if ( !gotone || ev.what == nullEvent )
+ break;
+ if ( PyMac_HandleEvent(&ev) < 0 ) {
+ in_here--;
+ return -1;
+ }
+ maxsleep = latest_time_ready - LMGetTicks();
+ } while ( maxsleep > 0 );
+ }
+ in_here--;
+ return 0;
+}
+
+/*
+** Process events and/or yield the CPU to other tasks if opportune
+*/
+int
+PyMac_Yield() {
+ unsigned long maxsleep;
+
+ if( PyMac_InForeground() )
+ maxsleep = 0;
+ else
+ maxsleep = schedparams.bg_yield;
+
+ return PyMac_DoYield(maxsleep, 1);
+}
+
+/*
+** Return current scheduler parameters
+*/
+void
+PyMac_GetSchedParams(PyMacSchedParams *sp)
+{
+ sp->check_interrupt = schedparams.check_interrupt;
+ sp->process_events = schedparams.process_events;
+ sp->besocial = schedparams.besocial;
+ sp->check_interval = schedparams.check_interval / 60.0;
+ sp->bg_yield = schedparams.bg_yield / 60.0;
+}
+
+/*
+** Set current scheduler parameters
+*/
+void
+PyMac_SetSchedParams(PyMacSchedParams *sp)
+{
+ schedparams.check_interrupt = sp->check_interrupt;
+ schedparams.process_events = sp->process_events;
+ schedparams.besocial = sp->besocial;
+ schedparams.check_interval = (unsigned long)(sp->check_interval*60);
+ schedparams.bg_yield = (unsigned long)(sp->bg_yield*60);
+ if ( schedparams.check_interrupt || schedparams.process_events ||
+ schedparams.besocial )
+ schedparams.enabled = 1;
+ else
+ schedparams.enabled = 0;
+ schedparams.next_check = 0; /* Check immedeately */
+}
+
+/*
+** Install our menu bar.
+*/
+void
+PyMac_InitMenuBar()
+{
+ MenuHandle applemenu;
+
+ if ( sioux_mbar ) return;
+ if ( (sioux_mbar=GetMenuBar()) == NULL ) {
+ /* Sioux menu not installed yet. Do so */
+ SIOUXSetupMenus();
+ if ( (sioux_mbar=GetMenuBar()) == NULL )
+ return;
+ }
+ if ( (applemenu=GetMenuHandle(SIOUX_APPLEID)) == NULL ) return;
+ SetMenuItemText(applemenu, 1, "\pAbout Python...");
+}
+
+/*
+** Restore sioux menu bar
+*/
+void
+PyMac_RestoreMenuBar()
+{
+#if 1
+ /* This doesn't seem to work anymore? Or only for Carbon? */
+ MenuBarHandle curmenubar;
+
+ curmenubar = GetMenuBar();
+ if ( sioux_mbar ) {
+ SetMenuBar(sioux_mbar);
+ DrawMenuBar();
+ } else {
+ PyMac_InitMenuBar();
+ DrawMenuBar();
+ }
+#endif
+}
+
+void
+PyMac_RaiseConsoleWindow()
+{
+ /* Note: this is a hack. SIOUXTextWindow is SIOUX's internal structure
+ ** and we happen to know that the first entry is the window pointer.
+ */
+ extern WindowRef *SIOUXTextWindow;
+
+ if ( SIOUXTextWindow == NULL || *SIOUXTextWindow == NULL )
+ return;
+ if ( FrontWindow() != *SIOUXTextWindow )
+ BringToFront(*SIOUXTextWindow);
+}
+
+/*
+** Our replacement about box
+*/
+
+#include "patchlevel.h"
+
+void
+SIOUXDoAboutBox(void)
+{
+ DialogPtr theDialog;
+ WindowPtr theWindow;
+ short item;
+ short fontID;
+
+ if( (theDialog = GetNewDialog(ABOUT_ID, NULL, (WindowPtr)-1)) == NULL )
+ return;
+ theWindow = GetDialogWindow(theDialog);
+ SetPortWindowPort(theWindow);
+ GetFNum("\pPython-Sans", &fontID);
+ if (fontID == 0)
+ fontID = kFontIDGeneva;
+ TextFont(fontID);
+ TextSize(9);
+ ParamText(Pstring(PATCHLEVEL), "\p", "\p", "\p");
+ ShowWindow(theWindow);
+ ModalDialog(NULL, &item);
+ DisposeDialog(theDialog);
+}
+
+#endif /* !TARGET_API_MAC_OSX */
+
+#if TARGET_API_MAC_OS8
+/*
+** Helper routine for GetDirectory
+*/
+static pascal short
+myhook_proc(short item, DialogPtr theDialog, struct hook_args *dataptr)
+{
+ if ( item == sfHookFirstCall && dataptr->prompt) {
+ Handle prompth;
+ short type;
+ Rect rect;
+
+ GetDialogItem(theDialog, PROMPT_ITEM, &type, &prompth, &rect);
+ if ( prompth )
+ SetDialogItemText(prompth, (unsigned char *)dataptr->prompt);
+ } else
+ if ( item == SELECTCUR_ITEM ) {
+ item = sfItemCancelButton;
+ dataptr->selectcur_hit = 1;
+ }
+ return item;
+}
+
+/*
+** Ask the user for a directory. I still can't understand
+** why Apple doesn't provide a standard solution for this...
+*/
+int
+PyMac_GetDirectory(dirfss, prompt)
+ FSSpec *dirfss;
+ char *prompt;
+{
+ static SFTypeList list = {'fldr', 0, 0, 0};
+ static Point where = {-1, -1};
+ StandardFileReply reply;
+ struct hook_args hook_args;
+
+ if ( !upp_inited ) {
+ myhook_upp = NewDlgHookYDProc(myhook_proc);
+ upp_inited = 1;
+ }
+ if ( prompt && *prompt )
+ hook_args.prompt = (char *)Pstring(prompt);
+ else
+ hook_args.prompt = NULL;
+ hook_args.selectcur_hit = 0;
+ CustomGetFile((FileFilterYDUPP)0, 1, list, &reply, GETDIR_ID, where, myhook_upp,
+ NULL, NULL, NULL, (void *)&hook_args);
+
+ reply.sfFile.name[0] = 0;
+ if( FSMakeFSSpec(reply.sfFile.vRefNum, reply.sfFile.parID, reply.sfFile.name, dirfss) )
+ return 0;
+ return hook_args.selectcur_hit;
+}
+
+/*
+** Slightly extended StandardGetFile: accepts a prompt */
+void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList,
+ StandardFileReply *reply, char *prompt)
+{
+ static Point where = {-1, -1};
+ struct hook_args hook_args;
+
+ if ( !upp_inited ) {
+ myhook_upp = NewDlgHookYDProc(myhook_proc);
+ upp_inited = 1;
+ }
+ if ( prompt && *prompt )
+ hook_args.prompt = (char *)Pstring(prompt);
+ else
+ hook_args.prompt = NULL;
+ hook_args.selectcur_hit = 0;
+ CustomGetFile((FileFilterYDUPP)0, numTypes, typeList, reply, GETFILEPROMPT_ID, where,
+ myhook_upp, NULL, NULL, NULL, (void *)&hook_args);
+}
+#endif /* TARGET_API_MAC_OS8 */
+
+/* Convert a 4-char string object argument to an OSType value */
+int
+PyMac_GetOSType(PyObject *v, OSType *pr)
+{
+ if (!PyString_Check(v) || PyString_Size(v) != 4) {
+ PyErr_SetString(PyExc_TypeError,
+ "OSType arg must be string of 4 chars");
+ return 0;
+ }
+ memcpy((char *)pr, PyString_AsString(v), 4);
+ return 1;
+}
+
+/* Convert an OSType value to a 4-char string object */
+PyObject *
+PyMac_BuildOSType(OSType t)
+{
+ return PyString_FromStringAndSize((char *)&t, 4);
+}
+
+/* Convert an NumVersion value to a 4-element tuple */
+PyObject *
+PyMac_BuildNumVersion(NumVersion t)
+{
+ return Py_BuildValue("(hhhh)", t.majorRev, t.minorAndBugRev, t.stage, t.nonRelRev);
+}
+
+
+/* Convert a Python string object to a Str255 */
+int
+PyMac_GetStr255(PyObject *v, Str255 pbuf)
+{
+ int len;
+ if (!PyString_Check(v) || (len = PyString_Size(v)) > 255) {
+ PyErr_SetString(PyExc_TypeError,
+ "Str255 arg must be string of at most 255 chars");
+ return 0;
+ }
+ pbuf[0] = len;
+ memcpy((char *)(pbuf+1), PyString_AsString(v), len);
+ return 1;
+}
+
+/* Convert a Str255 to a Python string object */
+PyObject *
+PyMac_BuildStr255(Str255 s)
+{
+ if ( s == NULL ) {
+ PyErr_SetString(PyExc_SystemError, "Str255 pointer is NULL");
+ return NULL;
+ }
+ return PyString_FromStringAndSize((char *)&s[1], (int)s[0]);
+}
+
+PyObject *
+PyMac_BuildOptStr255(Str255 s)
+{
+ if ( s == NULL ) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return PyString_FromStringAndSize((char *)&s[1], (int)s[0]);
+}
+
+
+
+/* Convert a Python object to a Rect.
+ The object must be a (left, top, right, bottom) tuple.
+ (This differs from the order in the struct but is consistent with
+ the arguments to SetRect(), and also with STDWIN). */
+int
+PyMac_GetRect(PyObject *v, Rect *r)
+{
+ return PyArg_Parse(v, "(hhhh)", &r->left, &r->top, &r->right, &r->bottom);
+}
+
+/* Convert a Rect to a Python object */
+PyObject *
+PyMac_BuildRect(Rect *r)
+{
+ return Py_BuildValue("(hhhh)", r->left, r->top, r->right, r->bottom);
+}
+
+
+/* Convert a Python object to a Point.
+ The object must be a (h, v) tuple.
+ (This differs from the order in the struct but is consistent with
+ the arguments to SetPoint(), and also with STDWIN). */
+int
+PyMac_GetPoint(PyObject *v, Point *p)
+{
+ return PyArg_Parse(v, "(hh)", &p->h, &p->v);
+}
+
+/* Convert a Point to a Python object */
+PyObject *
+PyMac_BuildPoint(Point p)
+{
+ return Py_BuildValue("(hh)", p.h, p.v);
+}
+
+
+/* Convert a Python object to an EventRecord.
+ The object must be a (what, message, when, (v, h), modifiers) tuple. */
+int
+PyMac_GetEventRecord(PyObject *v, EventRecord *e)
+{
+ return PyArg_Parse(v, "(Hll(hh)H)",
+ &e->what,
+ &e->message,
+ &e->when,
+ &e->where.h,
+ &e->where.v,
+ &e->modifiers);
+}
+
+/* Convert a Rect to an EventRecord object */
+PyObject *
+PyMac_BuildEventRecord(EventRecord *e)
+{
+ return Py_BuildValue("(hll(hh)h)",
+ e->what,
+ e->message,
+ e->when,
+ e->where.h,
+ e->where.v,
+ e->modifiers);
+}
+
+/* Convert Python object to Fixed */
+int
+PyMac_GetFixed(PyObject *v, Fixed *f)
+{
+ double d;
+
+ if( !PyArg_Parse(v, "d", &d))
+ return 0;
+ *f = (Fixed)(d * 0x10000);
+ return 1;
+}
+
+/* Convert a Point to a Python object */
+PyObject *
+PyMac_BuildFixed(Fixed f)
+{
+ double d;
+
+ d = f;
+ d = d / 0x10000;
+ return Py_BuildValue("d", d);
+}
+
+/* Convert wide to/from Python int or (hi, lo) tuple. XXXX Should use Python longs */
+int
+PyMac_Getwide(PyObject *v, wide *rv)
+{
+ if (PyInt_Check(v)) {
+ rv->hi = 0;
+ rv->lo = PyInt_AsLong(v);
+ if( rv->lo & 0x80000000 )
+ rv->hi = -1;
+ return 1;
+ }
+ return PyArg_Parse(v, "(ll)", &rv->hi, &rv->lo);
+}
+
+
+PyObject *
+PyMac_Buildwide(wide *w)
+{
+ if ( (w->hi == 0 && (w->lo & 0x80000000) == 0) ||
+ (w->hi == -1 && (w->lo & 0x80000000) ) )
+ return PyInt_FromLong(w->lo);
+ return Py_BuildValue("(ll)", w->hi, w->lo);
+}
+
+#ifdef USE_TOOLBOX_OBJECT_GLUE
+/*
+** Glue together the toolbox objects.
+**
+** Because toolbox modules interdepend on each other, they use each others
+** object types, on MacOSX/MachO this leads to the situation that they
+** cannot be dynamically loaded (or they would all have to be lumped into
+** a single .so, but this would be bad for extensibility).
+**
+** This file defines wrappers for all the _New and _Convert functions,
+** which are the Py_BuildValue and PyArg_ParseTuple helpers. The wrappers
+** check an indirection function pointer, and if it isn't filled in yet
+** they import the appropriate module, whose init routine should fill in
+** the pointer.
+*/
+
+#define GLUE_NEW(object, routinename, module) \
+PyObject *(*PyMacGluePtr_##routinename)(object); \
+\
+PyObject *routinename(object cobj) { \
+ if (!PyMacGluePtr_##routinename) { \
+ if (!PyImport_ImportModule(module)) return NULL; \
+ if (!PyMacGluePtr_##routinename) { \
+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
+ return NULL; \
+ } \
+ } \
+ return (*PyMacGluePtr_##routinename)(cobj); \
+}
+
+#define GLUE_CONVERT(object, routinename, module) \
+int (*PyMacGluePtr_##routinename)(PyObject *, object *); \
+\
+int routinename(PyObject *pyobj, object *cobj) { \
+ if (!PyMacGluePtr_##routinename) { \
+ if (!PyImport_ImportModule(module)) return NULL; \
+ if (!PyMacGluePtr_##routinename) { \
+ PyErr_SetString(PyExc_ImportError, "Module did not provide routine: " module ": " #routinename); \
+ return NULL; \
+ } \
+ } \
+ return (*PyMacGluePtr_##routinename)(pyobj, cobj); \
+}
+
+GLUE_NEW(AppleEvent *, AEDesc_New, "AE") /* XXXX Why by address? */
+GLUE_CONVERT(AppleEvent, AEDesc_Convert, "AE")
+
+GLUE_NEW(Component, CmpObj_New, "Cm")
+GLUE_CONVERT(Component, CmpObj_Convert, "Cm")
+GLUE_NEW(ComponentInstance, CmpInstObj_New, "Cm")
+GLUE_CONVERT(ComponentInstance, CmpInstObj_Convert, "Cm")
+
+GLUE_NEW(ControlHandle, CtlObj_New, "Ctl")
+GLUE_CONVERT(ControlHandle, CtlObj_Convert, "Ctl")
+
+GLUE_NEW(DialogPtr, DlgObj_New, "Dlg")
+GLUE_CONVERT(DialogPtr, DlgObj_Convert, "Dlg")
+GLUE_NEW(DialogPtr, DlgObj_WhichDialog, "Dlg")
+
+GLUE_NEW(DragReference, DragObj_New, "Drag")
+GLUE_CONVERT(DragReference, DragObj_Convert, "Drag")
+
+GLUE_NEW(ListHandle, ListObj_New, "List")
+GLUE_CONVERT(ListHandle, ListObj_Convert, "List")
+
+GLUE_NEW(MenuHandle, MenuObj_New, "Menu")
+GLUE_CONVERT(MenuHandle, MenuObj_Convert, "Menu")
+
+GLUE_NEW(GrafPtr, GrafObj_New, "Qd")
+GLUE_CONVERT(GrafPtr, GrafObj_Convert, "Qd")
+GLUE_NEW(BitMapPtr, BMObj_New, "Qd")
+GLUE_CONVERT(BitMapPtr, BMObj_Convert, "Qd")
+GLUE_NEW(RGBColor *, QdRGB_New, "Qd") /* XXXX Why? */
+GLUE_CONVERT(RGBColor, QdRGB_Convert, "Qd")
+
+GLUE_NEW(GWorldPtr, GWorldObj_New, "Qdoffs")
+GLUE_CONVERT(GWorldPtr, GWorldObj_Convert, "Qdoffs")
+
+GLUE_NEW(Track, TrackObj_New, "Qt")
+GLUE_CONVERT(Track, TrackObj_Convert, "Qt")
+GLUE_NEW(Movie, MovieObj_New, "Qt")
+GLUE_CONVERT(Movie, MovieObj_Convert, "Qt")
+GLUE_NEW(MovieController, MovieCtlObj_New, "Qt")
+GLUE_CONVERT(MovieController, MovieCtlObj_Convert, "Qt")
+GLUE_NEW(TimeBase, TimeBaseObj_New, "Qt")
+GLUE_CONVERT(TimeBase, TimeBaseObj_Convert, "Qt")
+GLUE_NEW(UserData, UserDataObj_New, "Qt")
+GLUE_CONVERT(UserData, UserDataObj_Convert, "Qt")
+GLUE_NEW(Media, MediaObj_New, "Qt")
+GLUE_CONVERT(Media, MediaObj_Convert, "Qt")
+
+GLUE_NEW(Handle, ResObj_New, "Res")
+GLUE_CONVERT(Handle, ResObj_Convert, "Res")
+GLUE_NEW(Handle, OptResObj_New, "Res")
+GLUE_CONVERT(Handle, OptResObj_Convert, "Res")
+
+GLUE_NEW(TEHandle, TEObj_New, "TE")
+GLUE_CONVERT(TEHandle, TEObj_Convert, "TE")
+
+GLUE_NEW(WindowPtr, WinObj_New, "Win")
+GLUE_CONVERT(WindowPtr, WinObj_Convert, "Win")
+GLUE_NEW(WindowPtr, WinObj_WhichWindow, "Win")
+
+#endif /* USE_TOOLBOX_OBJECT_GLUE */
\ No newline at end of file
--- /dev/null
+#
+# fullbuild creates everything that needs to be created before a
+# distribution can be made, and puts it all in the right place.
+#
+# It expects the projects to be in the places where Jack likes them:
+# in directories named like 'build.mac'. That is fixable,
+# however.
+#
+# NOTE: You should proably make a copy of python with which to execute this
+# script, rebuilding running programs does not work...
+
+MACBUILDNO=":Mac:Include:macbuildno.h"
+
+import os
+import sys
+import macfs
+import MacOS
+import EasyDialogs
+import re
+import string
+
+import aetools
+import AppleEvents
+
+OLDAESUPPORT = 0
+
+if OLDAESUPPORT:
+ from Metrowerks_Shell_Suite import Metrowerks_Shell_Suite
+ from CodeWarrior_suite import CodeWarrior_suite
+ from Metrowerks_Standard_Suite import Metrowerks_Standard_Suite
+ from Required_Suite import Required_Suite
+else:
+ import CodeWarrior
+
+import Res
+import Dlg
+
+import buildtools
+import cfmfile
+
+# Dialog resource. Note that the item numbers should correspond
+# to those in the DITL resource. Also note that the order is important:
+# things are built in this order, so there should be no forward dependencies.
+DIALOG_ID = 512
+
+I_OK=1
+I_CANCEL=2
+# label 3
+I_PPC_EXTLIBS=4
+I_GEN_PROJECTS=5
+I_GEN_PROJECTS_FORCE=6
+I_GEN_IMGPROJECTS=7
+I_GEN_IMGPROJECTS_FORCE=8
+I_INC_BUILDNO=9
+# label 10
+I_PPC_CORE=11
+I_PPC_PLUGINS=12
+I_PPC_EXTENSIONS=13
+# label 14
+I_CARBON_CORE=15
+I_CARBON_PLUGINS=16
+I_CARBON_EXTENSIONS=17
+I_INTERPRETER=18
+# label 19
+I_PPC_FULL=20
+I_PPC_SMALL=21
+# label 22
+I_CARBON_FULL=23
+I_CARBON_SMALL=24
+# label 25
+I_APPLETS=26
+
+N_BUTTONS=27
+
+if OLDAESUPPORT:
+ class MwShell(Metrowerks_Shell_Suite, CodeWarrior_suite, Metrowerks_Standard_Suite,
+ Required_Suite, aetools.TalkTo):
+ pass
+else:
+ MwShell = CodeWarrior.CodeWarrior
+
+RUNNING=[]
+
+def buildmwproject(top, creator, projects):
+ """Build projects with an MW compiler"""
+ mgr = MwShell(creator, start=1)
+ mgr.send_timeout = AppleEvents.kNoTimeOut
+
+ failed = []
+ for file in projects:
+ if type(file) == type(()):
+ file, target = file
+ else:
+ target = ''
+ file = os.path.join(top, file)
+ try:
+ fss = macfs.FSSpec(file)
+ except MacOS.Error:
+ print '** file not found:', file
+ continue
+ print 'Building', file, target
+ try:
+ mgr.open(fss)
+ except aetools.Error, detail:
+ print '**', detail, file
+ continue
+ if target:
+ try:
+ mgr.Set_Current_Target(target)
+ except aetools.Error, arg:
+ print '**', file, target, 'Cannot select:', arg
+ try:
+ mgr.Make_Project()
+ except aetools.Error, arg:
+ print '**', file, target, 'Failed:', arg
+ failed.append(fss)
+ mgr.Close_Project()
+ if failed:
+ print 'Open failed projects and exit?',
+ rv = sys.stdin.readline()
+ if rv[0] in ('y', 'Y'):
+ for fss in failed:
+ mgr.open(fss)
+ sys.exit(0)
+## mgr.quit()
+
+def buildapplet(top, dummy, list):
+ """Create python applets"""
+ for src, dst, tmpl in list:
+ template = buildtools.findtemplate(tmpl)
+ if src[-3:] != '.py':
+ raise 'Should end in .py', src
+ base = os.path.basename(src)
+ src = os.path.join(top, src)
+ dst = os.path.join(top, dst)
+ try:
+ os.unlink(dst)
+ except os.error:
+ pass
+ print 'Building applet', dst
+ try:
+ buildtools.process(template, src, dst, 1)
+ except buildtools.BuildError, arg:
+ print '**', dst, arg
+
+def buildprojectfile(top, arg, list):
+ """Create CodeWarrior project files with a script"""
+ for folder, module, routine in list:
+ print "Generating project files with", module
+ sys.path.insert(0, os.path.join(top, folder))
+ m = __import__(module)
+ r = getattr(m, routine)
+ r(arg)
+ del sys.path[0]
+
+def buildfat(top, dummy, list):
+ """Build fat binaries"""
+ for dst, src1, src2 in list:
+ dst = os.path.join(top, dst)
+ src1 = os.path.join(top, src1)
+ src2 = os.path.join(top, src2)
+ print 'Building fat binary', dst
+ cfmfile.mergecfmfiles((src1, src2), dst)
+
+def buildcopy(top, dummy, list):
+ import macostools
+ for src, dst in list:
+ src = os.path.join(top, src)
+ dst = os.path.join(top, dst)
+ macostools.copy(src, dst, forcetype="APPL")
+
+def handle_dialog(filename):
+ """Handle selection dialog, return list of selected items"""
+ d = Dlg.GetNewDialog(DIALOG_ID, -1)
+ d.SetDialogDefaultItem(I_OK)
+ d.SetDialogCancelItem(I_CANCEL)
+ results = [0]*N_BUTTONS
+ while 1:
+ n = Dlg.ModalDialog(None)
+ if n == I_OK:
+ break
+ if n == I_CANCEL:
+ return []
+ if n == I_INC_BUILDNO:
+ incbuildno(filename)
+ continue
+ if n < len(results):
+ results[n] = (not results[n])
+ ctl = d.GetDialogItemAsControl(n)
+ ctl.SetControlValue(results[n])
+ rv = []
+ for i in range(len(results)):
+ if results[i]:
+ rv.append(i)
+ return rv
+
+#
+# The build instructions. Entries are (routine, arg, list-of-files)
+# XXXX We could also include the builds for stdwin and such here...
+BUILD_DICT = {
+I_GEN_PROJECTS : (buildprojectfile, 0, [
+ (":Mac:scripts", "genpluginprojects", "genallprojects")
+ ]),
+
+I_GEN_PROJECTS_FORCE : (buildprojectfile, 1, [
+ (":Mac:scripts", "genpluginprojects", "genallprojects")
+ ]),
+
+I_GEN_IMGPROJECTS : (buildprojectfile, 0, [
+ (":Extensions:img:Mac", "genimgprojects", "genallprojects")
+ ]),
+
+I_GEN_IMGPROJECTS_FORCE : (buildprojectfile, 1, [
+ (":Extensions:img:Mac", "genimgprojects", "genallprojects")
+ ]),
+
+I_INTERPRETER : (buildcopy, None, [
+ ("PythonInterpreterCarbon", "PythonInterpreter"),
+ ]),
+
+I_PPC_CORE : (buildmwproject, "CWIE", [
+ (":Mac:Build:PythonCore.mcp", "PythonCore"),
+ (":Mac:Build:PythonInterpreter.mcp", "PythonInterpreterClassic"),
+ ]),
+
+I_CARBON_CORE : (buildmwproject, "CWIE", [
+ (":Mac:Build:PythonCore.mcp", "PythonCoreCarbon"),
+ (":Mac:Build:PythonInterpreter.mcp", "PythonInterpreterCarbon"),
+ ]),
+
+I_PPC_EXTLIBS : (buildmwproject, "CWIE", [
+## (":Mac:Build:buildlibs.mcp", "buildlibs ppc plus tcl/tk"),
+ (":Mac:Build:buildlibs.mcp", "buildlibs ppc"),
+ ]),
+
+I_PPC_PLUGINS : (buildmwproject, "CWIE", [
+ (":Mac:Build:_weakref.mcp", "_weakref.ppc"),
+ (":Mac:Build:_symtable.mcp", "_symtable.ppc"),
+ (":Mac:Build:_testcapi.mcp", "_testcapi.ppc"),
+ (":Mac:Build:pyexpat.mcp", "pyexpat.ppc"),
+ (":Mac:Build:calldll.mcp", "calldll.ppc"),
+ (":Mac:Build:ctb.mcp", "ctb.ppc"),
+ (":Mac:Build:gdbm.mcp", "gdbm.ppc"),
+ (":Mac:Build:icglue.mcp", "icglue.ppc"),
+ (":Mac:Build:macspeech.mcp", "macspeech.ppc"),
+ (":Mac:Build:waste.mcp", "waste.ppc"),
+ (":Mac:Build:zlib.mcp", "zlib.ppc"),
+## (":Mac:Build:_tkinter.mcp", "_tkinter.ppc"),
+ (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
+ (":Mac:Build:ColorPicker.mcp", "ColorPicker.ppc"),
+ (":Mac:Build:Printing.mcp", "Printing.ppc"),
+ (":Mac:Build:App.mcp", "App.ppc"),
+ (":Mac:Build:Cm.mcp", "Cm.ppc"),
+ (":Mac:Build:Fm.mcp", "Fm.ppc"),
+ (":Mac:Build:Help.mcp", "Help.ppc"),
+ (":Mac:Build:Icn.mcp", "Icn.ppc"),
+ (":Mac:Build:List.mcp", "List.ppc"),
+ (":Mac:Build:Qdoffs.mcp", "Qdoffs.ppc"),
+ (":Mac:Build:Qt.mcp", "Qt.ppc"),
+ (":Mac:Build:Scrap.mcp", "Scrap.ppc"),
+ (":Mac:Build:Snd.mcp", "Snd.ppc"),
+ (":Mac:Build:Sndihooks.mcp", "Sndihooks.ppc"),
+ (":Mac:Build:TE.mcp", "TE.ppc"),
+ (":Mac:Build:Mlte.mcp", "Mlte.ppc"),
+ ]),
+
+I_CARBON_PLUGINS : (buildmwproject, "CWIE", [
+ (":Mac:Build:_weakref.carbon.mcp", "_weakref.carbon"),
+ (":Mac:Build:_symtable.carbon.mcp", "_symtable.carbon"),
+ (":Mac:Build:_testcapi.carbon.mcp", "_testcapi.carbon"),
+ (":Mac:Build:pyexpat.carbon.mcp", "pyexpat.carbon"),
+ (":Mac:Build:calldll.carbon.mcp", "calldll.carbon"),
+ (":Mac:Build:gdbm.carbon.mcp", "gdbm.carbon"),
+ (":Mac:Build:icglue.carbon.mcp", "icglue.carbon"),
+ (":Mac:Build:waste.carbon.mcp", "waste.carbon"),
+ (":Mac:Build:zlib.carbon.mcp", "zlib.carbon"),
+ (":Mac:Build:_dummy_tkinter.mcp", "_tkinter.carbon"),
+## (":Extensions:Imaging:_tkinter.carbon.mcp", "_tkinter.carbon"),
+ (":Mac:Build:ColorPicker.carbon.mcp", "ColorPicker.carbon"),
+ (":Mac:Build:App.carbon.mcp", "App.carbon"),
+ (":Mac:Build:Cm.carbon.mcp", "Cm.carbon"),
+ (":Mac:Build:Fm.carbon.mcp", "Fm.carbon"),
+ (":Mac:Build:Icn.carbon.mcp", "Icn.carbon"),
+ (":Mac:Build:List.carbon.mcp", "List.carbon"),
+ (":Mac:Build:Qdoffs.carbon.mcp", "Qdoffs.carbon"),
+ (":Mac:Build:Qt.carbon.mcp", "Qt.carbon"),
+ (":Mac:Build:Scrap.carbon.mcp", "Scrap.carbon"),
+ (":Mac:Build:Snd.carbon.mcp", "Snd.carbon"),
+ (":Mac:Build:Sndihooks.carbon.mcp", "Sndihooks.carbon"),
+ (":Mac:Build:TE.carbon.mcp", "TE.carbon"),
+
+ (":Mac:Build:CF.carbon.mcp", "CF.carbon"),
+ (":Mac:Build:Mlte.carbon.mcp", "Mlte.carbon"),
+ ]),
+
+I_PPC_FULL : (buildmwproject, "CWIE", [
+ (":Mac:Build:PythonStandalone.mcp", "PythonStandalone"),
+ ]),
+
+I_PPC_SMALL : (buildmwproject, "CWIE", [
+ (":Mac:Build:PythonStandSmall.mcp", "PythonStandSmall"),
+ ]),
+
+I_CARBON_FULL : (buildmwproject, "CWIE", [
+ (":Mac:Build:PythonStandalone.mcp", "PythonCarbonStandalone"),
+ ]),
+
+I_CARBON_SMALL : (buildmwproject, "CWIE", [
+ (":Mac:Build:PythonStandSmall.mcp", "PythonStandSmallCarbon"),
+ ]),
+
+I_PPC_EXTENSIONS : (buildmwproject, "CWIE", [
+ (":Extensions:Imaging:_imaging.mcp", "_imaging.ppc"),
+## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.ppc"),
+ (":Extensions:img:Mac:imgmodules.mcp", "imgmodules.ppc"),
+ ]),
+
+I_CARBON_EXTENSIONS : (buildmwproject, "CWIE", [
+ (":Extensions:Imaging:_imaging.mcp", "_imaging.carbon"),
+## (":Extensions:Imaging:_tkinter.mcp", "_tkinter.carbon"),
+ (":Extensions:img:Mac:imgmodules.mcp", "imgmodules.carbon"),
+ ]),
+
+I_APPLETS : (buildapplet, None, [
+ (":Mac:scripts:EditPythonPrefs.py", "EditPythonPrefs", None),
+ (":Mac:scripts:BuildApplet.py", "BuildApplet", None),
+ (":Mac:scripts:BuildApplication.py", "BuildApplication", None),
+ (":Mac:scripts:ConfigurePython.py", "ConfigurePython", None),
+ (":Mac:scripts:ConfigurePython.py", "ConfigurePythonCarbon", "PythonInterpreterCarbon"),
+ (":Mac:scripts:ConfigurePython.py", "ConfigurePythonClassic", "PythonInterpreterClassic"),
+ (":Mac:Tools:IDE:PythonIDE.py", "Python IDE", None),
+ (":Mac:Tools:CGI:PythonCGISlave.py", ":Mac:Tools:CGI:PythonCGISlave", None),
+ (":Mac:Tools:CGI:BuildCGIApplet.py", ":Mac:Tools:CGI:BuildCGIApplet", None),
+ ]),
+}
+
+def incbuildno(filename):
+ fp = open(filename)
+ line = fp.readline()
+ fp.close()
+
+ pat = re.compile('#define BUILD ([0-9]+)')
+ m = pat.search(line)
+ if not m or not m.group(1):
+ raise 'Incorrect macbuildno.h line', line
+ buildno = m.group(1)
+ new = string.atoi(buildno) + 1
+ fp = open(filename, 'w')
+ fp.write('#define BUILD %d\n'%new)
+ fp.close()
+
+def main():
+ try:
+ h = Res.FSpOpenResFile('fullbuild.rsrc', 1)
+ except Res.Error:
+ pass # Assume we already have acces to our own resource
+
+ dir, ok = macfs.GetDirectory('Python source folder:')
+ if not ok:
+ sys.exit(0)
+ dir = dir.as_pathname()
+
+ todo = handle_dialog(os.path.join(dir, MACBUILDNO))
+
+ instructions = []
+ for i in todo:
+ instructions.append(BUILD_DICT[i])
+
+ for routine, arg, list in instructions:
+ routine(dir, arg, list)
+
+ if todo:
+ print "All done!"
+
+if __name__ == '__main__':
+ main()
+
--- /dev/null
+import mkcwproject
+import sys
+import os
+import string
+
+PROJECTDIR = os.path.join(sys.prefix, ":Mac:Build")
+MODULEDIRS = [ # Relative to projectdirs
+ "::Modules:%s",
+ "::Modules",
+ ":::Modules",
+]
+
+# Global variable to control forced rebuild (otherwise the project is only rebuilt
+# when it is changed)
+FORCEREBUILD=0
+
+def relpath(base, path):
+ """Turn abs path into path relative to another. Only works for 2 abs paths
+ both pointing to folders"""
+ if not os.path.isabs(base) or not os.path.isabs(path):
+ raise 'Absolute paths only'
+ if base[-1] == ':':
+ base = base[:-1]
+ basefields = string.split(base, os.sep)
+ pathfields = string.split(path, os.sep)
+ commonfields = len(os.path.commonprefix((basefields, pathfields)))
+ basefields = basefields[commonfields:]
+ pathfields = pathfields[commonfields:]
+ pathfields = ['']*(len(basefields)+1) + pathfields
+ rv = string.join(pathfields, os.sep)
+ return rv
+
+def genpluginproject(architecture, module,
+ project=None, projectdir=None,
+ sources=[], sourcedirs=[],
+ libraries=[], extradirs=[],
+ extraexportsymbols=[]):
+ if architecture == "all":
+ # For the time being we generate two project files. Not as nice as
+ # a single multitarget project, but easier to implement for now.
+ genpluginproject("ppc", module, project, projectdir, sources, sourcedirs,
+ libraries, extradirs, extraexportsymbols)
+ genpluginproject("carbon", module, project, projectdir, sources, sourcedirs,
+ libraries, extradirs, extraexportsymbols)
+ return
+ templatename = "template-%s" % architecture
+ targetname = "%s.%s" % (module, architecture)
+ dllname = "%s.%s.slb" % (module, architecture)
+ if not project:
+ if architecture != "ppc":
+ project = "%s.%s.mcp"%(module, architecture)
+ else:
+ project = "%s.mcp"%module
+ if not projectdir:
+ projectdir = PROJECTDIR
+ if not sources:
+ sources = [module + 'module.c']
+ if not sourcedirs:
+ for moduledir in MODULEDIRS:
+ if '%' in moduledir:
+ moduledir = moduledir % module
+ fn = os.path.join(projectdir, os.path.join(moduledir, sources[0]))
+ if os.path.exists(fn):
+ moduledir, sourcefile = os.path.split(fn)
+ sourcedirs = [relpath(projectdir, moduledir)]
+ sources[0] = sourcefile
+ break
+ else:
+ print "Warning: %s: sourcefile not found: %s"%(module, sources[0])
+ sourcedirs = []
+ if architecture == "carbon":
+ prefixname = "mwerks_carbonplugin_config.h"
+ else:
+ prefixname = "mwerks_plugin_config.h"
+ dict = {
+ "sysprefix" : relpath(projectdir, sys.prefix),
+ "sources" : sources,
+ "extrasearchdirs" : sourcedirs + extradirs,
+ "libraries": libraries,
+ "mac_outputdir" : "::Plugins",
+ "extraexportsymbols" : extraexportsymbols,
+ "mac_targetname" : targetname,
+ "mac_dllname" : dllname,
+ "prefixname" : prefixname,
+ }
+ mkcwproject.mkproject(os.path.join(projectdir, project), module, dict,
+ force=FORCEREBUILD, templatename=templatename)
+
+def genallprojects(force=0):
+ global FORCEREBUILD
+ FORCEREBUILD = force
+ # Standard Python modules
+ genpluginproject("all", "pyexpat",
+ sources=["pyexpat.c"],
+ libraries=["libexpat.ppc.lib"],
+ extradirs=["::::expat:*"])
+ genpluginproject("all", "zlib",
+ libraries=["zlib.ppc.Lib"],
+ extradirs=["::::imglibs:zlib:mac", "::::imglibs:zlib"])
+ genpluginproject("all", "gdbm",
+ libraries=["gdbm.ppc.gusi.lib"],
+ extradirs=["::::gdbm:mac", "::::gdbm"])
+ genpluginproject("all", "_weakref", sources=["_weakref.c"])
+ genpluginproject("all", "_symtable", sources=["symtablemodule.c"])
+ genpluginproject("all", "_testcapi")
+
+ # bgen-generated Toolbox modules
+ genpluginproject("ppc", "App", libraries=["AppearanceLib"])
+ genpluginproject("carbon", "App")
+## genpluginproject("ppc", "Cm",
+## libraries=["QuickTimeLib"],
+## extraexportsymbols=[
+## "CmpObj_New",
+## "CmpObj_Convert",
+## "CmpInstObj_New",
+## "CmpInstObj_Convert",
+## ])
+## genpluginproject("carbon", "Cm",
+## extraexportsymbols=[
+## "CmpObj_New",
+## "CmpObj_Convert",
+## "CmpInstObj_New",
+## "CmpInstObj_Convert",
+## ])
+ genpluginproject("ppc", "Cm", libraries=["QuickTimeLib"])
+ genpluginproject("carbon", "Cm")
+ genpluginproject("all", "Fm")
+ genpluginproject("ppc", "Help")
+ genpluginproject("ppc", "Icn", libraries=["IconServicesLib"])
+ genpluginproject("carbon", "Icn")
+ genpluginproject("all", "List")
+## genpluginproject("ppc", "Qt", libraries=["QuickTimeLib", "Cm.ppc.slb", "Qdoffs.ppc.slb"],
+## extradirs=["::Plugins"])
+ genpluginproject("ppc", "Qt", libraries=["QuickTimeLib"])
+## genpluginproject("carbon", "Qt", libraries=["Cm.carbon.slb", "Qdoffs.carbon.slb"],
+## extradirs=["::Plugins"])
+ genpluginproject("carbon", "Qt")
+## genpluginproject("all", "Qdoffs",
+## extraexportsymbols=["GWorldObj_New", "GWorldObj_Convert"])
+ genpluginproject("all", "Qdoffs")
+ genpluginproject("all", "Scrap")
+ genpluginproject("ppc", "Snd", libraries=["SoundLib"])
+ genpluginproject("carbon", "Snd")
+ genpluginproject("all", "Sndihooks", sources=[":snd:Sndihooks.c"])
+ genpluginproject("ppc", "TE", libraries=["DragLib"])
+ genpluginproject("carbon", "TE")
+ genpluginproject("ppc", "Mlte", libraries=["Textension"])
+ genpluginproject("carbon", "Mlte")
+
+ # Carbon Only?
+ genpluginproject("carbon", "CF")
+
+ # Other Mac modules
+ genpluginproject("all", "calldll", sources=["calldll.c"])
+ genpluginproject("all", "ColorPicker")
+ genpluginproject("ppc", "Printing")
+ genpluginproject("ppc", "waste",
+ sources=[
+ "wastemodule.c",
+ 'WEAccessors.c', 'WEBirthDeath.c', 'WEDebug.c',
+ 'WEDrawing.c', 'WEFontTables.c', 'WEHighLevelEditing.c',
+ 'WEICGlue.c', 'WEInlineInput.c', 'WELineLayout.c', 'WELongCoords.c',
+ 'WELowLevelEditing.c', 'WEMouse.c', 'WEObjects.c', 'WEScraps.c',
+ 'WESelecting.c', 'WESelectors.c', 'WEUserSelectors.c', 'WEUtilities.c',
+ 'WEObjectHandlers.c',
+ 'WETabs.c',
+ 'WETabHooks.c'],
+ libraries=['DragLib'],
+ extradirs=[
+ '::::Waste 1.3 Distribution:*',
+ '::::ICProgKit1.4:APIs']
+ )
+ # This is a hack, combining parts of Waste 2.0 with parts of 1.3
+ genpluginproject("carbon", "waste",
+ sources=[
+ "wastemodule.c",
+ "WEObjectHandlers.c",
+ "WETabs.c", "WETabHooks.c"],
+ libraries=["WASTE.Carbon.lib"],
+ extradirs=[
+ '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:C_C++ Headers',
+ '{Compiler}:MacOS Support:(Third Party Support):Waste 2.0 Distribution:Static Libraries',
+ '::::Waste 1.3 Distribution:Extras:Sample Object Handlers',
+ '::::Waste 1.3 Distribution:Extras:Waste Tabs 1.3.2']
+ )
+ genpluginproject("ppc", "ctb")
+ genpluginproject("ppc", "icglue", sources=["icgluemodule.c"],
+ libraries=["ICGlueCFM-PPC.lib"],
+ extradirs=["::::ICProgKit1.4:APIs"])
+ genpluginproject("carbon", "icglue", sources=["icgluemodule.c"],
+ extradirs=["::::ICProgKit1.4:APIs"])
+ genpluginproject("ppc", "macspeech", libraries=["SpeechLib"])
+
+if __name__ == '__main__':
+ genallprojects()
+
+