diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 1998-08-18 14:54:11 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 1998-08-18 14:54:11 (GMT) |
commit | 7cc5735ef26a60df9d1bc3554c1912f951a90308 (patch) | |
tree | 5c391a5a9b8e4f6d1932205d9d8ff1283542caef /Mac/Contrib/BBPy | |
parent | 1d6a6ea1a819a645a3a8841205b10cf33eb04493 (diff) | |
download | cpython-7cc5735ef26a60df9d1bc3554c1912f951a90308.zip cpython-7cc5735ef26a60df9d1bc3554c1912f951a90308.tar.gz cpython-7cc5735ef26a60df9d1bc3554c1912f951a90308.tar.bz2 |
Initial revision
Diffstat (limited to 'Mac/Contrib/BBPy')
-rw-r--r-- | Mac/Contrib/BBPy/PythonSlave.py | 129 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/README | 41 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BB stuff/ExternalInterface.h | 716 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BB-stuff/ExternalInterface.h | 716 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BBPy.h | 17 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BBPy.rsrc.hqx | 15 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BBPy_lauch.c | 94 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BBPy_launch.c | 94 | ||||
-rw-r--r-- | Mac/Contrib/BBPy/source/BBPy_main.c | 104 |
9 files changed, 1926 insertions, 0 deletions
diff --git a/Mac/Contrib/BBPy/PythonSlave.py b/Mac/Contrib/BBPy/PythonSlave.py new file mode 100644 index 0000000..cc63e1d --- /dev/null +++ b/Mac/Contrib/BBPy/PythonSlave.py @@ -0,0 +1,129 @@ +"""PythonSlave.py +An application that responds to three types of apple event: + 'pyth'/'EXEC': execute direct parameter as Python + 'aevt', 'quit': quit + 'aevt', 'odoc': perform python scripts + +Copyright © 1996, Just van Rossum, Letterror +""" + +__version__ = "0.1.3" + +import FrameWork +import sys +import traceback +import aetools +import string +import AE +import EasyDialogs +import os +import Qd +from Types import * +from Events import charCodeMask, cmdKey +import MacOS +import Evt + +def dummyfunc(): pass + +modulefilename = dummyfunc.func_code.co_filename + +def Interact(timeout = 50000000): # timeout after 10 days... + AE.AEInteractWithUser(timeout) + + +class PythonSlave(FrameWork.Application): + def __init__(self): + FrameWork.Application.__init__(self) + AE.AEInstallEventHandler('pyth', 'EXEC', ExecHandler) + AE.AEInstallEventHandler('aevt', 'quit', QuitHandler) + AE.AEInstallEventHandler('aevt', 'odoc', OpenDocumentHandler) + + def makeusermenus(self): + self.filemenu = m = FrameWork.Menu(self.menubar, "File") + self._quititem = FrameWork.MenuItem(m, "Quit", "Q", self._quit) + + def do_kHighLevelEvent(self, event): + (what, message, when, where, modifiers) = event + try: + AE.AEProcessAppleEvent(event) + except AE.Error, detail: + print "Apple Event was not handled, error:", detail + + def do_key(self, event): + (what, message, when, where, modifiers) = event + c = chr(message & charCodeMask) + if modifiers & cmdKey and c == '.': + return + FrameWork.Application.do_key(self, event) + + def idle(self, event): + Qd.InitCursor() + + def quit(self, *args): + raise self + + def getabouttext(self): + return "About PythonSlaveŠ" + + def do_about(self, id, item, window, event): + EasyDialogs.Message("PythonSlave " + __version__ + "\rCopyright © 1996, Letterror, JvR") + + +def ExecHandler(theAppleEvent, theReply): + parameters, args = aetools.unpackevent(theAppleEvent) + if parameters.has_key('----'): + if parameters.has_key('NAME'): + print '--- executing "' + parameters['NAME'] + '" ---' + else: + print '--- executing "<unknown>" ---' + stuff = parameters['----'] + MyExec(stuff + "\n") # execute input + print '--- done ---' + return 0 + +def MyExec(stuff): + stuff = string.splitfields(stuff, '\r') # convert return chars + stuff = string.joinfields(stuff, '\n') # to newline chars + Interact() + saveyield = MacOS.EnableAppswitch(1) + try: + exec stuff in {} + except: + MacOS.EnableAppswitch(saveyield) + traceback.print_exc() + MacOS.EnableAppswitch(saveyield) + +def OpenDocumentHandler(theAppleEvent, theReply): + parameters, args = aetools.unpackevent(theAppleEvent) + docs = parameters['----'] + if type(docs) <> ListType: + docs = [docs] + for doc in docs: + fss, a = doc.Resolve() + path = fss.as_pathname() + if path <> modulefilename: + MyExecFile(path) + return 0 + +def MyExecFile(path): + saveyield = MacOS.EnableAppswitch(1) + savewd = os.getcwd() + os.chdir(os.path.split(path)[0]) + print '--- Executing file "' + os.path.split(path)[1] + '"' + try: + execfile(path, {"__name__": "__main__"}) + except: + traceback.print_exc() + MacOS.EnableAppswitch(saveyield) + MacOS.EnableAppswitch(saveyield) + os.chdir(savewd) + print "--- done ---" + +def QuitHandler(theAppleEvent, theReply): + slave.quit() + return 0 + + +slave = PythonSlave() +print "PythonSlave", __version__, "ready." +slave.mainloop() diff --git a/Mac/Contrib/BBPy/README b/Mac/Contrib/BBPy/README new file mode 100644 index 0000000..6f0a2a0 --- /dev/null +++ b/Mac/Contrib/BBPy/README @@ -0,0 +1,41 @@ +"Run as Python" -- a BBEdit extension to make the Python interpreter execute the +contents of the current window. + +version 0.2.3, 18 september 1996 + +contents: +- "Run as Python" -- the extension +- PythonSlave.py -- the "slave" script that handles the AppleEvents + +- source -- source code & CW9 project for the extension + +quickstart: +- drop "Run as Python" in BBEdit extensions folder +- double-click PythonSlave.py +- start BBEdit +- type some code +- go to Extensions menu: "Run as Python" +- be happy + +warning: + since PythonSlave.py runs its own event loop and we have no interface + to SIOUX you *cannot* copy from the console. Duh. + +extra feature: + while PythonSlave.py is running you can still double-click Python + documents, they will get executed as if Python was not already running. + +bugs: + perhaps + +acknowledgements: +- Thanks to Joseph Strout for valuable input and beta testing. +- Thanks to Mark Roseman for providing code that can launch + PythonSlave.py from BBEdit. + + +Have fun with it! +Please report bugs, or fix 'em. Suggestions are always welcome. + +Just van Rossum, Letterror +<just@knoware.nl> diff --git a/Mac/Contrib/BBPy/source/BB stuff/ExternalInterface.h b/Mac/Contrib/BBPy/source/BB stuff/ExternalInterface.h new file mode 100644 index 0000000..51d206d --- /dev/null +++ b/Mac/Contrib/BBPy/source/BB stuff/ExternalInterface.h @@ -0,0 +1,716 @@ +#pragma once + +#include <MixedMode.h> +#include <Dialogs.h> +#include <Files.h> +#include <Windows.h> +#include <AppleEvents.h> +#include <StandardFile.h> + +#if defined(powerc) || defined (__powerc) +#pragma options align=mac68k +#endif + +typedef struct +{ + FSSpec spec; // designates file on disk + long key; // reserved for future expansion + + char tree; // 0 for absolute, 1 for project, 2 for system + Boolean found; // FALSE if file couldn't be located; if so, all other info is moot + + OSType type; // file type of found file + OSType crtr; // signature of found file's creator + + short spare0; // reserved for future expansion + long spare1; +} ProjectEntry; + +enum +{ + kNeitherTree, + kProjectTree, + kSystemTree +}; + +enum +{ + kTHINKCProject, + kTHINKPascalProject, + kCodeWarriorProject +}; + +// masks for the "flags" argument to new-convention interfaces + +#define xfWindowOpen 0x00000001 +#define xfWindowChangeable 0x00000002 +#define xfHasSelection 0x00000004 +#define xfUseDefaults 0x00000008 +#define xfIsBBEditLite 0x00000040 +#define xfIsBBEditDemo 0x00000080 + +typedef struct +{ + FSSpec spec; + OSType key; + + short error_kind; + long line_number; + + Str255 message; +} ErrorEntry; + +typedef enum +{ + kNote = 0, + kError, + kWarning +} ErrorKind; + +#define kCurrentExternalVersion 5 // current version of callbacks + +// Universal callback interfaces + +#if USESROUTINEDESCRIPTORS + +#define ExtensionUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ExternalCallbackBlock *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr)))) + +#define NewExtensionUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ExternalCallbackBlock *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(AppleEvent *))) \ + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(AppleEvent *)))) + +#define GetWindowContentsUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))) + +#define GetSelectionUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long *)))) + +#define SetSelectionUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))) + +#define GetDocInfoUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long *)))) + +#define GetModDateUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))) + +#define CopyUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle)))) + +#define PasteUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))) + +#define GetLastLineUPPInfo (kPascalStackBased | RESULT_SIZE(SIZE_CODE(sizeof(long)))) + +#define GetLineNumberUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define GetLineStartUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define GetLineEndUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define GetLinePosUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define InsertUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))) + +#define DeleteUPPInfo (kPascalStackBased) + +#define SetWindowContentsUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))) + +#define ContentsChangedUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))) + +#define GetFileTextUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(Boolean *)))) + +#define GetFolderUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long *)))) + +#define OpenSeveralUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(StandardFileReply ***)))) + +#define CenterDialogUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(DialogPtr))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))) + +#define StandardFilterUPPInfo uppModalFilterProcInfo + +#define FrameDialogItemUPPInfo uppUserItemProcInfo + +#define NewDocumentUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))) + +#define OpenDocumentUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))) + +#define AllocateUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Boolean)))) + +#define FindPatternUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(char *))) \ + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(Boolean)))) + +#define ReportOSErrorUPPInfo (kPascalStackBased) + +#define GetPreferenceUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ResType))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short *)))) + +#define SetPreferenceUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ResType))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short *)))) + +#define StartProgressUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean)))) + +#define DoProgressUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define DoneProgressUPPInfo (kPascalStackBased) + +#define GetProjectListUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpec *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(ProjectEntry***)))) + +#define ProjectTextListUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpec *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle *)))) + +#define PresetUndoUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))) + +#define SetUndoUPPInfo (kPascalStackBased) + +#define OpenFileUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpec *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr *)))) + +#define PrepareUndoUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))) + +#define CommitUndoUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define CreateResultsUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(WindowPtr *)))) + +typedef UniversalProcPtr GetWindowContentsProc; +typedef UniversalProcPtr GetSelectionProc; +typedef UniversalProcPtr SetSelectionProc; +typedef UniversalProcPtr GetDocInfoProc; +typedef UniversalProcPtr GetModDateProc; +typedef UniversalProcPtr CopyProc; +typedef UniversalProcPtr PasteProc; + +typedef UniversalProcPtr GetLastLineProc; +typedef UniversalProcPtr GetLineNumberProc; +typedef UniversalProcPtr GetLineStartProc; +typedef UniversalProcPtr GetLineEndProc; +typedef UniversalProcPtr GetLinePosProc; + +typedef UniversalProcPtr InsertProc; +typedef UniversalProcPtr DeleteProc; + +typedef UniversalProcPtr SetWindowContentsProc; +typedef UniversalProcPtr ContentsChangedProc; + +typedef UniversalProcPtr GetFileTextProc; + +typedef UniversalProcPtr GetFolderProc; +typedef UniversalProcPtr OpenSeveralProc; + +typedef UniversalProcPtr CenterDialogProc; +typedef UniversalProcPtr StandardFilterProc; +typedef UniversalProcPtr FrameDialogItemProc; + +typedef UniversalProcPtr NewDocumentProc; +typedef UniversalProcPtr OpenDocumentProc; + +typedef UniversalProcPtr AllocateProc; +typedef UniversalProcPtr FindPatternProc; + +typedef UniversalProcPtr ReportOSErrorProc; + +typedef UniversalProcPtr GetPreferenceProc; +typedef UniversalProcPtr SetPreferenceProc; + +typedef UniversalProcPtr StartProgressProc; +typedef UniversalProcPtr DoProgressProc; +typedef UniversalProcPtr DoneProgressProc; + +typedef UniversalProcPtr GetProjectListProc; +typedef UniversalProcPtr ProjectTextListProc; + +typedef UniversalProcPtr PresetUndoProc; +typedef UniversalProcPtr SetUndoProc; + +typedef UniversalProcPtr OpenFileProc; + +typedef UniversalProcPtr PrepareUndoProc; +typedef UniversalProcPtr CommitUndoProc; + +typedef UniversalProcPtr CreateResultsProc; + +#define CallGetWindowContents(proc, w) \ + (Handle)(CallUniversalProc(proc, GetWindowContentsUPPInfo, (w))) + +#define CallGetSelection(proc, selStart, selEnd, firstChar) \ + (CallUniversalProc(proc, GetSelectionUPPInfo, (selStart), (selEnd), (firstChar))) + +#define CallSetSelection(proc, selStart, selEnd, firstChar) \ + (CallUniversalProc(proc, SetSelectionUPPInfo, (selStart), (selEnd), (firstChar))) + +#define CallGetDocInfo(proc, w, name, vRefNum, dirID) \ + (CallUniversalProc(proc, GetDocInfoUPPInfo, (w), (name), (vRefNum), (dirID))) + +#define CallGetModDate(proc, w) \ + (CallUniversalProc(proc, GetModDateUPPInfo, (w))) + +#define CallCopy(proc) \ + (Handle)(CallUniversalProc(proc, CopyUPPInfo)) + +#define CallPaste(proc, h) \ + (CallUniversalProc(proc, PasteUPPInfo, (h))) + +#define CallGetLastLine(proc) \ + (CallUniversalProc(proc, GetLastLineUPPInfo)) + +#define CallGetLineNumber(proc, sel) \ + (CallUniversalProc(proc, GetLineNumberUPPInfo, (sel))) + +#define CallGetLineStart(proc, sel) \ + (CallUniversalProc(proc, GetLineStartUPPInfo, (sel))) + +#define CallGetLineEnd(proc, sel) \ + (CallUniversalProc(proc, GetLineEndUPPInfo, (sel))) + +#define CallGetLinePos(proc, sel) \ + (CallUniversalProc(proc, GetLinePosUPPInfo, (sel))) + +#define CallInsert(proc, text, len) \ + (CallUniversalProc(proc, InsertUPPInfo, (text), (len))) + +#define CallDelete(proc) \ + (CallUniversalProc(proc, DeleteUPPInfo)) + +#define CallSetWindowContents(proc, w, h) \ + (CallUniversalProc(proc, SetWindowContentsUPPInfo, (w), (h))) + +#define CallContentsChanged(proc, w) \ + (CallUniversalProc(proc, ContentsChangedUPPInfo, (w))) + +#define CallGetFileText(proc, vRefNum, dirID, name, canDispose) \ + (Handle)(CallUniversalProc(proc, GetFileTextUPPInfo, (vRefNum), (dirID), (name), (canDispose))) + +#define CallGetFolder(proc, prompt, vRefNum, dirID) \ + (Boolean)(CallUniversalProc(proc, GetFolderUPPInfo, (prompt), (vRefNum), (dirID))) + +#define CallOpenSeveral(proc, sort, file_count, files) \ + (Boolean)(CallUniversalProc(proc, OpenSeveralUPPInfo, (sort), (file_count), (files))) + +#define CallCenterDialog(proc, dialogID) \ + (DialogPtr)(CallUniversalProc(proc, CenterDialogUPPInfo, (dialogID))) + +#define CallStandardFilter(proc, d, event, item) \ + CallModalFilterProc(proc, (d), (event), (item)) + +#define CallFrameDialogItem(proc, d, item) \ + CallUserItemProc(proc, (d), (item)) + +#define CallNewDocument(proc) \ + (WindowPtr)(CallUniversalProc(proc, NewDocumentUPPInfo)) + +#define CallOpenDocument(proc) \ + (WindowPtr)(CallUniversalProc(proc, OpenDocumentUPPInfo)) + +#define CallAllocate(proc, size, clear) \ + (Handle)(CallUniversalProc(proc, AllocateUPPInfo, (size), (clear))) + +#define CallFindPattern(proc, text, text_len, text_offset, pat, pat_len, case_sens) \ + (CallUniversalProc(proc, FindPatternUPPInfo, (text), (text_len), (text_offset), \ + (pat), (pat_len), (case_sens))) + +#define CallReportOSError(proc, code) \ + (CallUniversalProc(proc, ReportOSErrorUPPInfo, (code))) + +#define CallGetPreference(proc, prefType, req_len, buffer, act_len) \ + (CallUniversalProc(proc, GetPreferenceUPPInfo, (prefType), (req_len), (buffer), (act_len))) + +#define CallSetPreference(proc, prefType, req_len, buffer, act_len) \ + (CallUniversalProc(proc, SetPreferenceUPPInfo, (prefType), (req_len), (buffer), (act_len))) + +#define CallStartProgress(proc, str, total, cancel_allowed) \ + (CallUniversalProc(proc, StartProgressUPPInfo, (str), (total), (cancel_allowed))) + +#define CallDoProgress(proc, done) \ + (Boolean)(CallUniversalProc(proc, DoProgressUPPInfo, (done))) + +#define CallDoneProgress(proc) \ + (CallUniversalProc(proc, DoneProgressUPPInfo)) + +#define CallGetProjectList(proc, spec, kind, count, entries) \ + (Boolean)(CallUniversalProc(proc, GetProjectListUPPInfo, (spec), (kind), (count), (entries))) + +#define CallProjectTextList(proc, spec, text) \ + (Boolean)(CallUniversalProc(proc, ProjectTextListUPPInfo, (spec), (text))) + +#define CallPresetUndo(proc) \ + (Boolean)(CallUniversalProc(proc, PresetUndoUPPInfo)) + +#define CallSetUndo(proc) \ + (CallUniversalProc(proc, SetUndoUPPInfo)) + +#define CallOpenFile(proc, spec, w) \ + (Boolean)(CallUniversalProc(proc, OpenFileUPPInfo, (spec), (w))) + +#define CallPrepareUndo(proc, undo_start, undo_end, sel_start, sel_end) \ + (Boolean)(CallUniversalProc(proc, PrepareUndoUPPInfo, (undo_start), (undo_end), \ + (sel_start), (sel_end))) + +#define CallCommitUndo(proc, new_end) \ + (CallUniversalProc(proc, CommitUndoUPPInfo, (new_end))) + +#define CallCreateResults(proc, title, count, results, w) \ + (Boolean)(CallUniversalProc(proc, CreateResultsUPPInfo, (title), (count), (results), (w))) + +#else + +typedef pascal Handle (*GetWindowContentsProc)(WindowPtr w); +typedef pascal void (*GetSelectionProc)(long *selStart, long *selEnd, long *firstChar); +typedef pascal void (*SetSelectionProc)(long selStart, long selEnd, long firstChar); +typedef pascal void (*GetDocInfoProc)(WindowPtr w, Str255 fName, short *vRefNum, long *dirID); +typedef pascal long (*GetModDateProc)(WindowPtr w); +typedef pascal Handle (*CopyProc)(void); +typedef pascal void (*PasteProc)(Handle pasteText); + +typedef pascal long (*GetLastLineProc)(void); +typedef pascal long (*GetLineNumberProc)(long selection); +typedef pascal long (*GetLineStartProc)(long selection); +typedef pascal long (*GetLineEndProc)(long selection); +typedef pascal long (*GetLinePosProc)(long line); + +typedef pascal void (*InsertProc)(char *text, long len); +typedef pascal void (*DeleteProc)(void); + +typedef pascal void (*SetWindowContentsProc)(WindowPtr w, Handle h); +typedef pascal void (*ContentsChangedProc)(WindowPtr w); + +typedef pascal Handle (*GetFileTextProc)(short vRefNum, long dirID, Str255 fName, Boolean *canDispose); + +typedef pascal Boolean (*GetFolderProc)(Str255 prompt, short *vRefNum, long *dirID); +typedef pascal Boolean (*OpenSeveralProc)(Boolean sort, short *file_count, StandardFileReply ***files); + +typedef pascal DialogPtr (*CenterDialogProc)(short dialogID); +typedef pascal Boolean (*StandardFilterProc)(DialogPtr d, EventRecord *event, short *item); +typedef pascal void (*FrameDialogItemProc)(DialogPtr d, short item); + +typedef pascal WindowPtr (*NewDocumentProc)(void); +typedef pascal WindowPtr (*OpenDocumentProc)(void); + +typedef pascal Handle (*AllocateProc)(long size, Boolean clear); +typedef pascal long (*FindPatternProc)(char *text, long text_len, long text_offset, + char *pat, long pat_len, + Boolean case_sensitive); + +typedef pascal void (*ReportOSErrorProc)(short code); + +typedef pascal void (*GetPreferenceProc)(ResType prefType, short req_len, void *buffer, short *act_len); +typedef pascal void (*SetPreferenceProc)(ResType prefType, short req_len, void *buffer, short *act_len); + +typedef pascal void (*StartProgressProc)(Str255 str, long total, Boolean cancel_allowed); +typedef pascal Boolean (*DoProgressProc)(long done); +typedef pascal void (*DoneProgressProc)(void); + +typedef pascal Boolean (*GetProjectListProc)(FSSpec *spec, short *kind, short *count, ProjectEntry ***entries); +typedef pascal Boolean (*ProjectTextListProc)(FSSpec *spec, Handle *text); + +typedef pascal Boolean (*PresetUndoProc)(void); +typedef pascal void (*SetUndoProc)(void); + +typedef pascal Boolean (*OpenFileProc)(FSSpec *spec, WindowPtr *w); + +typedef pascal Boolean (*PrepareUndoProc)(long undo_start, long undo_end, + long sel_start, long sel_end); +typedef pascal void (*CommitUndoProc)(long new_end); + +typedef pascal Boolean (*CreateResultsProc)(Str255 title, short count, Handle results, WindowPtr *w); + +#define CallGetWindowContents(proc, w) \ + ((proc))((w)) + +#define CallGetSelection(proc, selStart, selEnd, firstChar) \ + ((proc))((selStart), (selEnd), (firstChar)) + +#define CallSetSelection(proc, selStart, selEnd, firstChar) \ + ((proc))((selStart), (selEnd), (firstChar)) + +#define CallGetDocInfo(proc, w, name, vRefNum, dirID) \ + ((proc))((w), (name), (vRefNum), (dirID)) + +#define CallGetModDate(proc, w) \ + ((proc))((w)) + +#define CallCopy(proc) \ + ((proc))() + +#define CallPaste(proc, h) \ + ((proc))((h)) + +#define CallGetLastLine(proc) \ + ((proc))() + +#define CallGetLineNumber(proc, sel) \ + ((proc))((sel)) + +#define CallGetLineStart(proc, sel) \ + ((proc))((sel)) + +#define CallGetLineEnd(proc, sel) \ + ((proc))((sel)) + +#define CallGetLinePos(proc, sel) \ + ((proc))((sel)) + +#define CallInsert(proc, text, len) \ + ((proc))((text), (len)) + +#define CallDelete(proc) \ + ((proc))() + +#define CallSetWindowContents(proc, w, h) \ + ((proc))((w), (h)) + +#define CallContentsChanged(proc, w) \ + ((proc))((w)) + +#define CallGetFileText(proc, vRefNum, dirID, name, canDispose) \ + ((proc))((vRefNum), (dirID), (name), (canDispose)) + +#define CallGetFolder(proc, prompt, vRefNum, dirID) \ + ((proc))((prompt), (vRefNum), (dirID)) + +#define CallOpenSeveral(proc, sort, file_count, files) \ + ((proc))((sort), (file_count), (files)) + +#define CallCenterDialog(proc, dialogID) \ + ((proc))((dialogID)) + +#define CallStandardFilter(proc, d, event, item) \ + ((proc))((d), (event), (item)) + +#define CallFrameDialogItem(proc, d, item) \ + ((proc))((d), (item)) + +#define CallNewDocument(proc) \ + ((proc))() + +#define CallOpenDocument(proc) \ + ((proc))() + +#define CallAllocate(proc, size, clear) \ + ((proc))((size), (clear)) + +#define CallFindPattern(proc, text, text_len, text_offset, pat, pat_len, case_sens) \ + ((proc))((text), (text_len), (text_offset), (pat), (pat_len), (case_sens)) + +#define CallReportOSError(proc, code) \ + ((proc))((code)) + +#define CallGetPreference(proc, prefType, req_len, buffer, act_len) \ + ((proc))((prefType), (req_len), (buffer), (act_len)) + +#define CallSetPreference(proc, prefType, req_len, buffer, act_len) \ + ((proc))((prefType), (req_len), (buffer), (act_len)) + +#define CallStartProgress(proc, str, total, cancel_allowed) \ + ((proc))((str), (total), (cancel_allowed)) + +#define CallDoProgress(proc, done) \ + ((proc))((done)) + +#define CallDoneProgress(proc) \ + ((proc))() + +#define CallGetProjectList(proc, spec, kind, count, entries) \ + ((proc))((spec), (kind), (count), (entries)) + +#define CallProjectTextList(proc, spec, text) \ + ((proc))((spec), (text)) + +#define CallPresetUndo(proc) \ + ((proc))() + +#define CallSetUndo(proc) \ + ((proc))() + +#define CallOpenFile(proc, spec, w) \ + ((proc))((spec), (w)) + +#define CallPrepareUndo(proc, undo_start, undo_end, sel_start, sel_end) \ + ((proc))((undo_start), (undo_end), (sel_start), (sel_end)) + +#define CallCommitUndo(proc, new_end) \ + ((proc))((new_end)) + +#define CallCreateResults(proc, title, count, results, w) \ + ((proc))((title), (count), (results), (w)) + +#endif + + +typedef struct +{ + short version; + + // version 1 callbacks + + GetWindowContentsProc GetWindowContents; + GetSelectionProc GetSelection; + SetSelectionProc SetSelection; + GetDocInfoProc GetDocInfo; + GetModDateProc GetModDate; + CopyProc Copy; + PasteProc Paste; + + // version 2 callbacks + + /* Text-Editing stuff */ + GetLastLineProc GetLastLine; + GetLineNumberProc GetLineNumber; + GetLineStartProc GetLineStart; + GetLineEndProc GetLineEnd; + GetLinePosProc GetLinePos; + + InsertProc Insert; + DeleteProc Delete; + + /* Getting and Setting window text */ + SetWindowContentsProc SetWindowContents; + ContentsChangedProc ContentsChanged; + + /* Reading file text */ + GetFileTextProc GetFileText; + + /* Direct user-interface calls */ + GetFolderProc GetFolder; + OpenSeveralProc OpenSeveral; + + CenterDialogProc CenterDialog; + StandardFilterProc StandardFilter; + FrameDialogItemProc FrameDialogItem; + + NewDocumentProc NewDocument; + OpenDocumentProc OpenDocument; + + /* Utility Routines */ + AllocateProc Allocate; + FindPatternProc FindPattern; + + ReportOSErrorProc ReportOSError; + + /* Preference routines */ + GetPreferenceProc GetPreference; + SetPreferenceProc SetPreference; + + /* Progress routines */ + StartProgressProc StartProgress; + DoProgressProc DoProgress; + DoneProgressProc DoneProgress; + + // Version 3 callbacks + GetProjectListProc GetProjectList; + ProjectTextListProc ProjectTextList; + + // version 4 callbacks + + PresetUndoProc PresetUndo; + SetUndoProc SetUndo; + + OpenFileProc OpenFile; + + // version 5 callbacks + + PrepareUndoProc PrepareUndo; + CommitUndoProc CommitUndo; + + CreateResultsProc CreateResults; + +} ExternalCallbackBlock; + +#if defined(powerc) || defined (__powerc) +#pragma options align=reset +#endif + +/* + 'main' for a BBXT is declared: + +pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w); [C] + + The 'new' calling convention, which passes more information + and allows scriptability, is this: + +pascal OSErr main(ExternalCallbackBlock *callbacks, WindowPtr w, long flags, AppleEvent *event, AppleEvent *reply); +*/ diff --git a/Mac/Contrib/BBPy/source/BB-stuff/ExternalInterface.h b/Mac/Contrib/BBPy/source/BB-stuff/ExternalInterface.h new file mode 100644 index 0000000..51d206d --- /dev/null +++ b/Mac/Contrib/BBPy/source/BB-stuff/ExternalInterface.h @@ -0,0 +1,716 @@ +#pragma once + +#include <MixedMode.h> +#include <Dialogs.h> +#include <Files.h> +#include <Windows.h> +#include <AppleEvents.h> +#include <StandardFile.h> + +#if defined(powerc) || defined (__powerc) +#pragma options align=mac68k +#endif + +typedef struct +{ + FSSpec spec; // designates file on disk + long key; // reserved for future expansion + + char tree; // 0 for absolute, 1 for project, 2 for system + Boolean found; // FALSE if file couldn't be located; if so, all other info is moot + + OSType type; // file type of found file + OSType crtr; // signature of found file's creator + + short spare0; // reserved for future expansion + long spare1; +} ProjectEntry; + +enum +{ + kNeitherTree, + kProjectTree, + kSystemTree +}; + +enum +{ + kTHINKCProject, + kTHINKPascalProject, + kCodeWarriorProject +}; + +// masks for the "flags" argument to new-convention interfaces + +#define xfWindowOpen 0x00000001 +#define xfWindowChangeable 0x00000002 +#define xfHasSelection 0x00000004 +#define xfUseDefaults 0x00000008 +#define xfIsBBEditLite 0x00000040 +#define xfIsBBEditDemo 0x00000080 + +typedef struct +{ + FSSpec spec; + OSType key; + + short error_kind; + long line_number; + + Str255 message; +} ErrorEntry; + +typedef enum +{ + kNote = 0, + kError, + kWarning +} ErrorKind; + +#define kCurrentExternalVersion 5 // current version of callbacks + +// Universal callback interfaces + +#if USESROUTINEDESCRIPTORS + +#define ExtensionUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ExternalCallbackBlock *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr)))) + +#define NewExtensionUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(OSErr))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ExternalCallbackBlock *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(AppleEvent *))) \ + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(AppleEvent *)))) + +#define GetWindowContentsUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))) + +#define GetSelectionUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long *)))) + +#define SetSelectionUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long)))) + +#define GetDocInfoUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long *)))) + +#define GetModDateUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))) + +#define CopyUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle)))) + +#define PasteUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Handle)))) + +#define GetLastLineUPPInfo (kPascalStackBased | RESULT_SIZE(SIZE_CODE(sizeof(long)))) + +#define GetLineNumberUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define GetLineStartUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define GetLineEndUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define GetLinePosUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define InsertUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long)))) + +#define DeleteUPPInfo (kPascalStackBased) + +#define SetWindowContentsUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle)))) + +#define ContentsChangedUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(WindowPtr)))) + +#define GetFileTextUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(Boolean *)))) + +#define GetFolderUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long *)))) + +#define OpenSeveralUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(StandardFileReply ***)))) + +#define CenterDialogUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(DialogPtr))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(short)))) + +#define StandardFilterUPPInfo uppModalFilterProcInfo + +#define FrameDialogItemUPPInfo uppUserItemProcInfo + +#define NewDocumentUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))) + +#define OpenDocumentUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(WindowPtr)))) + +#define AllocateUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Boolean)))) + +#define FindPatternUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(char *))) \ + | STACK_ROUTINE_PARAMETER(5, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(6, SIZE_CODE(sizeof(Boolean)))) + +#define ReportOSErrorUPPInfo (kPascalStackBased) + +#define GetPreferenceUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ResType))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short *)))) + +#define SetPreferenceUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(ResType))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(void *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(short *)))) + +#define StartProgressUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Boolean)))) + +#define DoProgressUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define DoneProgressUPPInfo (kPascalStackBased) + +#define GetProjectListUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpec *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(short *))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(ProjectEntry***)))) + +#define ProjectTextListUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpec *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(Handle *)))) + +#define PresetUndoUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean)))) + +#define SetUndoUPPInfo (kPascalStackBased) + +#define OpenFileUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(FSSpec *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(WindowPtr *)))) + +#define PrepareUndoUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(long))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(long)))) + +#define CommitUndoUPPInfo (kPascalStackBased \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(long)))) + +#define CreateResultsUPPInfo (kPascalStackBased \ + | RESULT_SIZE(SIZE_CODE(sizeof(Boolean))) \ + | STACK_ROUTINE_PARAMETER(1, SIZE_CODE(sizeof(unsigned char *))) \ + | STACK_ROUTINE_PARAMETER(2, SIZE_CODE(sizeof(short))) \ + | STACK_ROUTINE_PARAMETER(3, SIZE_CODE(sizeof(Handle))) \ + | STACK_ROUTINE_PARAMETER(4, SIZE_CODE(sizeof(WindowPtr *)))) + +typedef UniversalProcPtr GetWindowContentsProc; +typedef UniversalProcPtr GetSelectionProc; +typedef UniversalProcPtr SetSelectionProc; +typedef UniversalProcPtr GetDocInfoProc; +typedef UniversalProcPtr GetModDateProc; +typedef UniversalProcPtr CopyProc; +typedef UniversalProcPtr PasteProc; + +typedef UniversalProcPtr GetLastLineProc; +typedef UniversalProcPtr GetLineNumberProc; +typedef UniversalProcPtr GetLineStartProc; +typedef UniversalProcPtr GetLineEndProc; +typedef UniversalProcPtr GetLinePosProc; + +typedef UniversalProcPtr InsertProc; +typedef UniversalProcPtr DeleteProc; + +typedef UniversalProcPtr SetWindowContentsProc; +typedef UniversalProcPtr ContentsChangedProc; + +typedef UniversalProcPtr GetFileTextProc; + +typedef UniversalProcPtr GetFolderProc; +typedef UniversalProcPtr OpenSeveralProc; + +typedef UniversalProcPtr CenterDialogProc; +typedef UniversalProcPtr StandardFilterProc; +typedef UniversalProcPtr FrameDialogItemProc; + +typedef UniversalProcPtr NewDocumentProc; +typedef UniversalProcPtr OpenDocumentProc; + +typedef UniversalProcPtr AllocateProc; +typedef UniversalProcPtr FindPatternProc; + +typedef UniversalProcPtr ReportOSErrorProc; + +typedef UniversalProcPtr GetPreferenceProc; +typedef UniversalProcPtr SetPreferenceProc; + +typedef UniversalProcPtr StartProgressProc; +typedef UniversalProcPtr DoProgressProc; +typedef UniversalProcPtr DoneProgressProc; + +typedef UniversalProcPtr GetProjectListProc; +typedef UniversalProcPtr ProjectTextListProc; + +typedef UniversalProcPtr PresetUndoProc; +typedef UniversalProcPtr SetUndoProc; + +typedef UniversalProcPtr OpenFileProc; + +typedef UniversalProcPtr PrepareUndoProc; +typedef UniversalProcPtr CommitUndoProc; + +typedef UniversalProcPtr CreateResultsProc; + +#define CallGetWindowContents(proc, w) \ + (Handle)(CallUniversalProc(proc, GetWindowContentsUPPInfo, (w))) + +#define CallGetSelection(proc, selStart, selEnd, firstChar) \ + (CallUniversalProc(proc, GetSelectionUPPInfo, (selStart), (selEnd), (firstChar))) + +#define CallSetSelection(proc, selStart, selEnd, firstChar) \ + (CallUniversalProc(proc, SetSelectionUPPInfo, (selStart), (selEnd), (firstChar))) + +#define CallGetDocInfo(proc, w, name, vRefNum, dirID) \ + (CallUniversalProc(proc, GetDocInfoUPPInfo, (w), (name), (vRefNum), (dirID))) + +#define CallGetModDate(proc, w) \ + (CallUniversalProc(proc, GetModDateUPPInfo, (w))) + +#define CallCopy(proc) \ + (Handle)(CallUniversalProc(proc, CopyUPPInfo)) + +#define CallPaste(proc, h) \ + (CallUniversalProc(proc, PasteUPPInfo, (h))) + +#define CallGetLastLine(proc) \ + (CallUniversalProc(proc, GetLastLineUPPInfo)) + +#define CallGetLineNumber(proc, sel) \ + (CallUniversalProc(proc, GetLineNumberUPPInfo, (sel))) + +#define CallGetLineStart(proc, sel) \ + (CallUniversalProc(proc, GetLineStartUPPInfo, (sel))) + +#define CallGetLineEnd(proc, sel) \ + (CallUniversalProc(proc, GetLineEndUPPInfo, (sel))) + +#define CallGetLinePos(proc, sel) \ + (CallUniversalProc(proc, GetLinePosUPPInfo, (sel))) + +#define CallInsert(proc, text, len) \ + (CallUniversalProc(proc, InsertUPPInfo, (text), (len))) + +#define CallDelete(proc) \ + (CallUniversalProc(proc, DeleteUPPInfo)) + +#define CallSetWindowContents(proc, w, h) \ + (CallUniversalProc(proc, SetWindowContentsUPPInfo, (w), (h))) + +#define CallContentsChanged(proc, w) \ + (CallUniversalProc(proc, ContentsChangedUPPInfo, (w))) + +#define CallGetFileText(proc, vRefNum, dirID, name, canDispose) \ + (Handle)(CallUniversalProc(proc, GetFileTextUPPInfo, (vRefNum), (dirID), (name), (canDispose))) + +#define CallGetFolder(proc, prompt, vRefNum, dirID) \ + (Boolean)(CallUniversalProc(proc, GetFolderUPPInfo, (prompt), (vRefNum), (dirID))) + +#define CallOpenSeveral(proc, sort, file_count, files) \ + (Boolean)(CallUniversalProc(proc, OpenSeveralUPPInfo, (sort), (file_count), (files))) + +#define CallCenterDialog(proc, dialogID) \ + (DialogPtr)(CallUniversalProc(proc, CenterDialogUPPInfo, (dialogID))) + +#define CallStandardFilter(proc, d, event, item) \ + CallModalFilterProc(proc, (d), (event), (item)) + +#define CallFrameDialogItem(proc, d, item) \ + CallUserItemProc(proc, (d), (item)) + +#define CallNewDocument(proc) \ + (WindowPtr)(CallUniversalProc(proc, NewDocumentUPPInfo)) + +#define CallOpenDocument(proc) \ + (WindowPtr)(CallUniversalProc(proc, OpenDocumentUPPInfo)) + +#define CallAllocate(proc, size, clear) \ + (Handle)(CallUniversalProc(proc, AllocateUPPInfo, (size), (clear))) + +#define CallFindPattern(proc, text, text_len, text_offset, pat, pat_len, case_sens) \ + (CallUniversalProc(proc, FindPatternUPPInfo, (text), (text_len), (text_offset), \ + (pat), (pat_len), (case_sens))) + +#define CallReportOSError(proc, code) \ + (CallUniversalProc(proc, ReportOSErrorUPPInfo, (code))) + +#define CallGetPreference(proc, prefType, req_len, buffer, act_len) \ + (CallUniversalProc(proc, GetPreferenceUPPInfo, (prefType), (req_len), (buffer), (act_len))) + +#define CallSetPreference(proc, prefType, req_len, buffer, act_len) \ + (CallUniversalProc(proc, SetPreferenceUPPInfo, (prefType), (req_len), (buffer), (act_len))) + +#define CallStartProgress(proc, str, total, cancel_allowed) \ + (CallUniversalProc(proc, StartProgressUPPInfo, (str), (total), (cancel_allowed))) + +#define CallDoProgress(proc, done) \ + (Boolean)(CallUniversalProc(proc, DoProgressUPPInfo, (done))) + +#define CallDoneProgress(proc) \ + (CallUniversalProc(proc, DoneProgressUPPInfo)) + +#define CallGetProjectList(proc, spec, kind, count, entries) \ + (Boolean)(CallUniversalProc(proc, GetProjectListUPPInfo, (spec), (kind), (count), (entries))) + +#define CallProjectTextList(proc, spec, text) \ + (Boolean)(CallUniversalProc(proc, ProjectTextListUPPInfo, (spec), (text))) + +#define CallPresetUndo(proc) \ + (Boolean)(CallUniversalProc(proc, PresetUndoUPPInfo)) + +#define CallSetUndo(proc) \ + (CallUniversalProc(proc, SetUndoUPPInfo)) + +#define CallOpenFile(proc, spec, w) \ + (Boolean)(CallUniversalProc(proc, OpenFileUPPInfo, (spec), (w))) + +#define CallPrepareUndo(proc, undo_start, undo_end, sel_start, sel_end) \ + (Boolean)(CallUniversalProc(proc, PrepareUndoUPPInfo, (undo_start), (undo_end), \ + (sel_start), (sel_end))) + +#define CallCommitUndo(proc, new_end) \ + (CallUniversalProc(proc, CommitUndoUPPInfo, (new_end))) + +#define CallCreateResults(proc, title, count, results, w) \ + (Boolean)(CallUniversalProc(proc, CreateResultsUPPInfo, (title), (count), (results), (w))) + +#else + +typedef pascal Handle (*GetWindowContentsProc)(WindowPtr w); +typedef pascal void (*GetSelectionProc)(long *selStart, long *selEnd, long *firstChar); +typedef pascal void (*SetSelectionProc)(long selStart, long selEnd, long firstChar); +typedef pascal void (*GetDocInfoProc)(WindowPtr w, Str255 fName, short *vRefNum, long *dirID); +typedef pascal long (*GetModDateProc)(WindowPtr w); +typedef pascal Handle (*CopyProc)(void); +typedef pascal void (*PasteProc)(Handle pasteText); + +typedef pascal long (*GetLastLineProc)(void); +typedef pascal long (*GetLineNumberProc)(long selection); +typedef pascal long (*GetLineStartProc)(long selection); +typedef pascal long (*GetLineEndProc)(long selection); +typedef pascal long (*GetLinePosProc)(long line); + +typedef pascal void (*InsertProc)(char *text, long len); +typedef pascal void (*DeleteProc)(void); + +typedef pascal void (*SetWindowContentsProc)(WindowPtr w, Handle h); +typedef pascal void (*ContentsChangedProc)(WindowPtr w); + +typedef pascal Handle (*GetFileTextProc)(short vRefNum, long dirID, Str255 fName, Boolean *canDispose); + +typedef pascal Boolean (*GetFolderProc)(Str255 prompt, short *vRefNum, long *dirID); +typedef pascal Boolean (*OpenSeveralProc)(Boolean sort, short *file_count, StandardFileReply ***files); + +typedef pascal DialogPtr (*CenterDialogProc)(short dialogID); +typedef pascal Boolean (*StandardFilterProc)(DialogPtr d, EventRecord *event, short *item); +typedef pascal void (*FrameDialogItemProc)(DialogPtr d, short item); + +typedef pascal WindowPtr (*NewDocumentProc)(void); +typedef pascal WindowPtr (*OpenDocumentProc)(void); + +typedef pascal Handle (*AllocateProc)(long size, Boolean clear); +typedef pascal long (*FindPatternProc)(char *text, long text_len, long text_offset, + char *pat, long pat_len, + Boolean case_sensitive); + +typedef pascal void (*ReportOSErrorProc)(short code); + +typedef pascal void (*GetPreferenceProc)(ResType prefType, short req_len, void *buffer, short *act_len); +typedef pascal void (*SetPreferenceProc)(ResType prefType, short req_len, void *buffer, short *act_len); + +typedef pascal void (*StartProgressProc)(Str255 str, long total, Boolean cancel_allowed); +typedef pascal Boolean (*DoProgressProc)(long done); +typedef pascal void (*DoneProgressProc)(void); + +typedef pascal Boolean (*GetProjectListProc)(FSSpec *spec, short *kind, short *count, ProjectEntry ***entries); +typedef pascal Boolean (*ProjectTextListProc)(FSSpec *spec, Handle *text); + +typedef pascal Boolean (*PresetUndoProc)(void); +typedef pascal void (*SetUndoProc)(void); + +typedef pascal Boolean (*OpenFileProc)(FSSpec *spec, WindowPtr *w); + +typedef pascal Boolean (*PrepareUndoProc)(long undo_start, long undo_end, + long sel_start, long sel_end); +typedef pascal void (*CommitUndoProc)(long new_end); + +typedef pascal Boolean (*CreateResultsProc)(Str255 title, short count, Handle results, WindowPtr *w); + +#define CallGetWindowContents(proc, w) \ + ((proc))((w)) + +#define CallGetSelection(proc, selStart, selEnd, firstChar) \ + ((proc))((selStart), (selEnd), (firstChar)) + +#define CallSetSelection(proc, selStart, selEnd, firstChar) \ + ((proc))((selStart), (selEnd), (firstChar)) + +#define CallGetDocInfo(proc, w, name, vRefNum, dirID) \ + ((proc))((w), (name), (vRefNum), (dirID)) + +#define CallGetModDate(proc, w) \ + ((proc))((w)) + +#define CallCopy(proc) \ + ((proc))() + +#define CallPaste(proc, h) \ + ((proc))((h)) + +#define CallGetLastLine(proc) \ + ((proc))() + +#define CallGetLineNumber(proc, sel) \ + ((proc))((sel)) + +#define CallGetLineStart(proc, sel) \ + ((proc))((sel)) + +#define CallGetLineEnd(proc, sel) \ + ((proc))((sel)) + +#define CallGetLinePos(proc, sel) \ + ((proc))((sel)) + +#define CallInsert(proc, text, len) \ + ((proc))((text), (len)) + +#define CallDelete(proc) \ + ((proc))() + +#define CallSetWindowContents(proc, w, h) \ + ((proc))((w), (h)) + +#define CallContentsChanged(proc, w) \ + ((proc))((w)) + +#define CallGetFileText(proc, vRefNum, dirID, name, canDispose) \ + ((proc))((vRefNum), (dirID), (name), (canDispose)) + +#define CallGetFolder(proc, prompt, vRefNum, dirID) \ + ((proc))((prompt), (vRefNum), (dirID)) + +#define CallOpenSeveral(proc, sort, file_count, files) \ + ((proc))((sort), (file_count), (files)) + +#define CallCenterDialog(proc, dialogID) \ + ((proc))((dialogID)) + +#define CallStandardFilter(proc, d, event, item) \ + ((proc))((d), (event), (item)) + +#define CallFrameDialogItem(proc, d, item) \ + ((proc))((d), (item)) + +#define CallNewDocument(proc) \ + ((proc))() + +#define CallOpenDocument(proc) \ + ((proc))() + +#define CallAllocate(proc, size, clear) \ + ((proc))((size), (clear)) + +#define CallFindPattern(proc, text, text_len, text_offset, pat, pat_len, case_sens) \ + ((proc))((text), (text_len), (text_offset), (pat), (pat_len), (case_sens)) + +#define CallReportOSError(proc, code) \ + ((proc))((code)) + +#define CallGetPreference(proc, prefType, req_len, buffer, act_len) \ + ((proc))((prefType), (req_len), (buffer), (act_len)) + +#define CallSetPreference(proc, prefType, req_len, buffer, act_len) \ + ((proc))((prefType), (req_len), (buffer), (act_len)) + +#define CallStartProgress(proc, str, total, cancel_allowed) \ + ((proc))((str), (total), (cancel_allowed)) + +#define CallDoProgress(proc, done) \ + ((proc))((done)) + +#define CallDoneProgress(proc) \ + ((proc))() + +#define CallGetProjectList(proc, spec, kind, count, entries) \ + ((proc))((spec), (kind), (count), (entries)) + +#define CallProjectTextList(proc, spec, text) \ + ((proc))((spec), (text)) + +#define CallPresetUndo(proc) \ + ((proc))() + +#define CallSetUndo(proc) \ + ((proc))() + +#define CallOpenFile(proc, spec, w) \ + ((proc))((spec), (w)) + +#define CallPrepareUndo(proc, undo_start, undo_end, sel_start, sel_end) \ + ((proc))((undo_start), (undo_end), (sel_start), (sel_end)) + +#define CallCommitUndo(proc, new_end) \ + ((proc))((new_end)) + +#define CallCreateResults(proc, title, count, results, w) \ + ((proc))((title), (count), (results), (w)) + +#endif + + +typedef struct +{ + short version; + + // version 1 callbacks + + GetWindowContentsProc GetWindowContents; + GetSelectionProc GetSelection; + SetSelectionProc SetSelection; + GetDocInfoProc GetDocInfo; + GetModDateProc GetModDate; + CopyProc Copy; + PasteProc Paste; + + // version 2 callbacks + + /* Text-Editing stuff */ + GetLastLineProc GetLastLine; + GetLineNumberProc GetLineNumber; + GetLineStartProc GetLineStart; + GetLineEndProc GetLineEnd; + GetLinePosProc GetLinePos; + + InsertProc Insert; + DeleteProc Delete; + + /* Getting and Setting window text */ + SetWindowContentsProc SetWindowContents; + ContentsChangedProc ContentsChanged; + + /* Reading file text */ + GetFileTextProc GetFileText; + + /* Direct user-interface calls */ + GetFolderProc GetFolder; + OpenSeveralProc OpenSeveral; + + CenterDialogProc CenterDialog; + StandardFilterProc StandardFilter; + FrameDialogItemProc FrameDialogItem; + + NewDocumentProc NewDocument; + OpenDocumentProc OpenDocument; + + /* Utility Routines */ + AllocateProc Allocate; + FindPatternProc FindPattern; + + ReportOSErrorProc ReportOSError; + + /* Preference routines */ + GetPreferenceProc GetPreference; + SetPreferenceProc SetPreference; + + /* Progress routines */ + StartProgressProc StartProgress; + DoProgressProc DoProgress; + DoneProgressProc DoneProgress; + + // Version 3 callbacks + GetProjectListProc GetProjectList; + ProjectTextListProc ProjectTextList; + + // version 4 callbacks + + PresetUndoProc PresetUndo; + SetUndoProc SetUndo; + + OpenFileProc OpenFile; + + // version 5 callbacks + + PrepareUndoProc PrepareUndo; + CommitUndoProc CommitUndo; + + CreateResultsProc CreateResults; + +} ExternalCallbackBlock; + +#if defined(powerc) || defined (__powerc) +#pragma options align=reset +#endif + +/* + 'main' for a BBXT is declared: + +pascal void main(ExternalCallbackBlock *callbacks, WindowPtr w); [C] + + The 'new' calling convention, which passes more information + and allows scriptability, is this: + +pascal OSErr main(ExternalCallbackBlock *callbacks, WindowPtr w, long flags, AppleEvent *event, AppleEvent *reply); +*/ diff --git a/Mac/Contrib/BBPy/source/BBPy.h b/Mac/Contrib/BBPy/source/BBPy.h new file mode 100644 index 0000000..22974ea --- /dev/null +++ b/Mac/Contrib/BBPy/source/BBPy.h @@ -0,0 +1,17 @@ +/* BBPython + A simple menu command to send the contents of a window to the Python interpreter + + copyright © 1996 Just van Rossum, Letterror: just@knoware.nl + + All Rights Reserved +*/ + +#include <MacHeaders68K> +#include <A4Stuff.h> +#include <SetUpA4.h> // for global variables, multiple segments, etc. +#include "ExternalInterface.h" +#include <Memory.h> + +extern OSErr SendTextAsAE(ExternalCallbackBlock *callbacks, Ptr theText, long theSize, Str255 windowTitle); +extern OSErr LaunchPythonSlave(FSSpec * docSpec); +extern Boolean GetPythonSlaveSpec(FSSpec * docSpec); diff --git a/Mac/Contrib/BBPy/source/BBPy.rsrc.hqx b/Mac/Contrib/BBPy/source/BBPy.rsrc.hqx new file mode 100644 index 0000000..33e0d1a --- /dev/null +++ b/Mac/Contrib/BBPy/source/BBPy.rsrc.hqx @@ -0,0 +1,15 @@ +(This file must be converted with BinHex 4.0) + +:#8*#8(NZFR0bB`"bFh*M8P0&4!#3#!*eepN!N!3"!!!!!I-!!!$c!!!!JJ$l!&` +"6F!#!!X!N!@N!$3!a!"N"J#3"U3!I!P#3P"j,R*cFQ0ZG'9bCQ&MC5jSF(*U,QK +aH(PiHA0X!!"3BA*d8dP8)3#3',&VJKm!N!B#G@jMC@`!N!8j!%i!63#H"!T%Efl +9G#"6BACP!*!&$!"1!#`"GBJh8f&fC5"MD'&ZCf9c)(4[)(4SC5"0CA4bEhGPFQY +c)%4[Bh9YC@jd)0*H-0-JBQ9QEh*P)&ia2`)!N!8-!"F!,!!hS!)!!J#3$)%%!!% +!!!!1!#J!+!#-!C!!!)"996!+!!!!"!!!!N%!!!#!!!-!N!9!!33!9!&8"!0CCA- +!N!C!!+S!9!$k"!*1E`#3"3J!2!!f!95)2Y*3HA4SEfj6E'&fC5j`HG-JDA-JEQp +d)(*eEQjTEQFX)!ehEh9XC#"jEh8JE'PVC5"dEb"XEf0KG'8JDA3r!*!&#!!+!#J +!+U!#!!%!!!!'!3!!8J#3"8F!)b!!!!!'GM!Z-Lic1AB`,M)Z-b#T)%TeFh3JGQ& +Z)&*[Fh0eE5![)%aPG(4PFR*[FL`J2'TeFh4!E'9dG'9bFQpb,QjX2J!!!3!!!!( +c!!!!m`!!!)))r"0%*d`!!!!F!))!"(CPFR-!!!!U4%P86!!!!$C"6&*8!!!!3N* +#@%B!!!"13N*B5`!!!&S!!Irr!!!!U!Mm%I`!J2rr!!!!'J#3"B$rr`#3#B$rr`! +!!")!N!@!rrm!!!#H!*!%red: diff --git a/Mac/Contrib/BBPy/source/BBPy_lauch.c b/Mac/Contrib/BBPy/source/BBPy_lauch.c new file mode 100644 index 0000000..f9b964c --- /dev/null +++ b/Mac/Contrib/BBPy/source/BBPy_lauch.c @@ -0,0 +1,94 @@ +/* + * Launch the PythonSlave.py script. + * This works exactly as if you'd double clicked on the file in the Finder, which + * not surprisingly is how its implemented (via the AppleEvents route of course). + * + * Largely based on code submitted by Mark Roseman <roseman@cpsc.ucalgary.ca> + * Thanks! + */ + +#include "BBPy.h" + +pascal Boolean MyFileFilter(CInfoPBPtr PB); +FileFilterUPP gMyFileFilterUPP = NULL; + +Boolean GetPythonSlaveSpec(FSSpec * docSpec) { + StandardFileReply reply; + SFTypeList typeList; + + typeList[0] = 'TEXT'; + + //if (!gMyFileFilterUPP) + gMyFileFilterUPP = NewFileFilterProc( MyFileFilter ); + + StandardGetFile(gMyFileFilterUPP, 0, typeList, &reply); + + DisposePtr((Ptr)gMyFileFilterUPP); + + if(!reply.sfGood) + return 0; /* user cancelled */ + + docSpec->vRefNum = reply.sfFile.vRefNum; + docSpec->parID = reply.sfFile.parID; + BlockMove(reply.sfFile.name, docSpec->name, 64); + return 1; +} + +pascal Boolean MyFileFilter(CInfoPBPtr PB) { + OSType fType; /* file type */ + OSType fCreator; /* file creator */ + + fType =((HParmBlkPtr)PB)->fileParam.ioFlFndrInfo.fdType; + fCreator = ((HParmBlkPtr)PB)->fileParam.ioFlFndrInfo.fdCreator; + + if (fType == 'TEXT' && + fCreator == 'Pyth') + return 0; + return 1; +} + +OSErr LaunchPythonSlave(FSSpec * docSpec) { + OSErr err; + FSSpec dirSpec; + AEAddressDesc finderAddress; + AppleEvent theEvent, theReply; + OSType finderSig = 'MACS'; + AliasHandle DirAlias, FileAlias; + AEDesc fileList; + AEDesc aeDirDesc, listElem; + + err = AECreateDesc(typeApplSignature, (Ptr)&finderSig, 4, &finderAddress); + if(err != noErr) return err; + + err = AECreateAppleEvent('FNDR', 'sope', &finderAddress, + kAutoGenerateReturnID, kAnyTransactionID, &theEvent); + if(err != noErr) return err; + + FSMakeFSSpec(docSpec->vRefNum, docSpec->parID, NULL, &dirSpec); + NewAlias(NULL, &dirSpec, &DirAlias); + NewAlias(NULL, docSpec, &FileAlias); + err = AECreateList(NULL, 0, 0, &fileList); + HLock((Handle)DirAlias); + AECreateDesc(typeAlias, (Ptr)*DirAlias, GetHandleSize((Handle)DirAlias), &aeDirDesc); + HUnlock((Handle)DirAlias); + if ((err = AEPutParamDesc(&theEvent, keyDirectObject, &aeDirDesc)) == noErr) { + AEDisposeDesc(&aeDirDesc); + HLock((Handle)FileAlias); + AECreateDesc(typeAlias, (Ptr)*FileAlias, GetHandleSize((Handle)FileAlias), &listElem); + HLock((Handle)FileAlias); + err = AEPutDesc(&fileList, 0, &listElem); + } + AEDisposeDesc(&listElem); + err = AEPutParamDesc(&theEvent, 'fsel', &fileList); + AEDisposeDesc(&fileList); + + err = AESend(&theEvent, &theReply, kAENoReply+kAENeverInteract, + kAENormalPriority, kAEDefaultTimeout, 0L, 0L); + if(err != noErr) return err; + + err = AEDisposeDesc(&theEvent); + if(err != noErr) return err; + + err = AEDisposeDesc(&theReply); + return err; +} diff --git a/Mac/Contrib/BBPy/source/BBPy_launch.c b/Mac/Contrib/BBPy/source/BBPy_launch.c new file mode 100644 index 0000000..f9b964c --- /dev/null +++ b/Mac/Contrib/BBPy/source/BBPy_launch.c @@ -0,0 +1,94 @@ +/* + * Launch the PythonSlave.py script. + * This works exactly as if you'd double clicked on the file in the Finder, which + * not surprisingly is how its implemented (via the AppleEvents route of course). + * + * Largely based on code submitted by Mark Roseman <roseman@cpsc.ucalgary.ca> + * Thanks! + */ + +#include "BBPy.h" + +pascal Boolean MyFileFilter(CInfoPBPtr PB); +FileFilterUPP gMyFileFilterUPP = NULL; + +Boolean GetPythonSlaveSpec(FSSpec * docSpec) { + StandardFileReply reply; + SFTypeList typeList; + + typeList[0] = 'TEXT'; + + //if (!gMyFileFilterUPP) + gMyFileFilterUPP = NewFileFilterProc( MyFileFilter ); + + StandardGetFile(gMyFileFilterUPP, 0, typeList, &reply); + + DisposePtr((Ptr)gMyFileFilterUPP); + + if(!reply.sfGood) + return 0; /* user cancelled */ + + docSpec->vRefNum = reply.sfFile.vRefNum; + docSpec->parID = reply.sfFile.parID; + BlockMove(reply.sfFile.name, docSpec->name, 64); + return 1; +} + +pascal Boolean MyFileFilter(CInfoPBPtr PB) { + OSType fType; /* file type */ + OSType fCreator; /* file creator */ + + fType =((HParmBlkPtr)PB)->fileParam.ioFlFndrInfo.fdType; + fCreator = ((HParmBlkPtr)PB)->fileParam.ioFlFndrInfo.fdCreator; + + if (fType == 'TEXT' && + fCreator == 'Pyth') + return 0; + return 1; +} + +OSErr LaunchPythonSlave(FSSpec * docSpec) { + OSErr err; + FSSpec dirSpec; + AEAddressDesc finderAddress; + AppleEvent theEvent, theReply; + OSType finderSig = 'MACS'; + AliasHandle DirAlias, FileAlias; + AEDesc fileList; + AEDesc aeDirDesc, listElem; + + err = AECreateDesc(typeApplSignature, (Ptr)&finderSig, 4, &finderAddress); + if(err != noErr) return err; + + err = AECreateAppleEvent('FNDR', 'sope', &finderAddress, + kAutoGenerateReturnID, kAnyTransactionID, &theEvent); + if(err != noErr) return err; + + FSMakeFSSpec(docSpec->vRefNum, docSpec->parID, NULL, &dirSpec); + NewAlias(NULL, &dirSpec, &DirAlias); + NewAlias(NULL, docSpec, &FileAlias); + err = AECreateList(NULL, 0, 0, &fileList); + HLock((Handle)DirAlias); + AECreateDesc(typeAlias, (Ptr)*DirAlias, GetHandleSize((Handle)DirAlias), &aeDirDesc); + HUnlock((Handle)DirAlias); + if ((err = AEPutParamDesc(&theEvent, keyDirectObject, &aeDirDesc)) == noErr) { + AEDisposeDesc(&aeDirDesc); + HLock((Handle)FileAlias); + AECreateDesc(typeAlias, (Ptr)*FileAlias, GetHandleSize((Handle)FileAlias), &listElem); + HLock((Handle)FileAlias); + err = AEPutDesc(&fileList, 0, &listElem); + } + AEDisposeDesc(&listElem); + err = AEPutParamDesc(&theEvent, 'fsel', &fileList); + AEDisposeDesc(&fileList); + + err = AESend(&theEvent, &theReply, kAENoReply+kAENeverInteract, + kAENormalPriority, kAEDefaultTimeout, 0L, 0L); + if(err != noErr) return err; + + err = AEDisposeDesc(&theEvent); + if(err != noErr) return err; + + err = AEDisposeDesc(&theReply); + return err; +} diff --git a/Mac/Contrib/BBPy/source/BBPy_main.c b/Mac/Contrib/BBPy/source/BBPy_main.c new file mode 100644 index 0000000..a96b271 --- /dev/null +++ b/Mac/Contrib/BBPy/source/BBPy_main.c @@ -0,0 +1,104 @@ +/* BBPython + A simple menu command to send the contents of a window to the Python interpreter + + copyright © 1996 Just van Rossum, Letterror: just@knoware.nl + + All Rights Reserved +*/ + +#include "BBPy.h" + +OSErr SendTextAsAE(ExternalCallbackBlock *callbacks, Ptr theText, long theSize, Str255 windowTitle) +{ + OSErr err; + AEDesc theEvent; + AEAddressDesc theTarget; + AppleEvent theReply; + AEDesc theTextDesc; + AEDesc theNameDesc; + OSType pythonSig = 'Pyth'; + FSSpec docSpec; + short itemHit; + long time; + EventRecord theDummyEvent; + + /* initialize AE descriptor for python's signature */ + err = AECreateDesc (typeApplSignature, &pythonSig, sizeof(OSType), &theTarget); + if(err != noErr) return err; + + /* initialize AE descriptor for the title of our window */ + err = AECreateDesc (typeChar, &windowTitle[1], windowTitle[0], &theNameDesc); + if(err != noErr) return err; + + /* initialize AE descriptor for the content of our window */ + err = AECreateDesc ('TEXT', theText, theSize, &theTextDesc); + if(err != noErr) return err; + + /* initialize AppleEvent */ + err = AECreateAppleEvent ('pyth', 'EXEC', &theTarget, kAutoGenerateReturnID, kAnyTransactionID, &theEvent); + if(err != noErr) return err; + + /* add the content of our window to the AppleEvent */ + err = AEPutParamDesc (&theEvent, keyDirectObject, &theTextDesc); + if(err != noErr) return err; + + /* add the title of our window to the AppleEvent */ + err = AEPutParamDesc (&theEvent, 'NAME', &theNameDesc); + if(err != noErr) return err; + + /* send the AppleEvent */ + err = AESend (&theEvent, &theReply, kAEWaitReply, kAEHighPriority, kNoTimeOut, NULL, NULL); + if(err == connectionInvalid) { + // launch PythonSlave.py + itemHit = Alert(128, NULL); + if(itemHit == 2) return noErr; /* user cancelled */ + + if( ! GetPythonSlaveSpec(&docSpec) ) + return noErr; /* user cancelled */ + + err = LaunchPythonSlave(&docSpec); + if(err != noErr) return err; + } else if(err != noErr) + return err; + + /* clean up */ + err = AEDisposeDesc (&theTarget); + if(err != noErr) return err; + + err = AEDisposeDesc (&theNameDesc); + if(err != noErr) return err; + + err = AEDisposeDesc (&theTextDesc); + if(err != noErr) return err; + + err = AEDisposeDesc (&theEvent); + if(err != noErr) return err; + + err = AEDisposeDesc (&theReply); + if(err != noErr) return err; + + /* everything is cool */ + return noErr; +} + +pascal void main(ExternalCallbackBlock *callbacks, WindowPtr theWindow) +{ + long oldA4; + OSErr err; + Handle windowContents; + Str255 windowTitle; + + //RememberA0(); /* Can't find header file for this. Seems to work anyway. */ + + oldA4 = SetUpA4(); + + GetWTitle(theWindow, windowTitle); + windowContents = callbacks->GetWindowContents(theWindow); + + HLock(windowContents); + err = SendTextAsAE(callbacks, *windowContents, GetHandleSize(windowContents), windowTitle); + if(err != noErr) callbacks->ReportOSError(err); + HUnlock(windowContents); + + RestoreA4(oldA4); +} |