summaryrefslogtreecommitdiffstats
path: root/Mac
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2001-10-08 15:35:38 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2001-10-08 15:35:38 (GMT)
commita0472f73e6f0a0abfae1b3358410fa442471c87a (patch)
treeef4c5e93e84e04c34873681ed59441189223efb5 /Mac
parent509ad42470b5faef7ff96b886b5a9ef224c60357 (diff)
downloadcpython-a0472f73e6f0a0abfae1b3358410fa442471c87a.zip
cpython-a0472f73e6f0a0abfae1b3358410fa442471c87a.tar.gz
cpython-a0472f73e6f0a0abfae1b3358410fa442471c87a.tar.bz2
Mods by Alexandre Parenteau to allow embedding programs to disable the MacPython console window completely, and optionally route console output (and input) to routines provided by the embedding app.
Things don't fully work yet, but at least it doesn't break anything.
Diffstat (limited to 'Mac')
-rw-r--r--Mac/Build/PythonCore.exp9
-rw-r--r--Mac/Build/PythonCoreCarbon.exp9
-rw-r--r--Mac/Python/pyGUSISIOUX.cp117
3 files changed, 90 insertions, 45 deletions
diff --git a/Mac/Build/PythonCore.exp b/Mac/Build/PythonCore.exp
index fa70117..1d16cce 100644
--- a/Mac/Build/PythonCore.exp
+++ b/Mac/Build/PythonCore.exp
@@ -5,8 +5,11 @@ GUSISetupFactories
__vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt
__vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt
sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance
-sInstance__15GUSISIOUXSocket # GUSISIOUXSocket::sInstance
+initialized__15GUSISIOUXSocket # GUSISIOUXSocket::initialized
__dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice()
+PyMac_DummyWriteHandler
+PyMac_DummyReadHandler
+PyMac_SetConsoleHandler
GUSISetupConsoleDescriptors
open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int)
Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&)
@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa
read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&)
__dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket()
Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize()
-__ct__15GUSISIOUXSocketFv # GUSISIOUXSocket::GUSISIOUXSocket()
-Instance__15GUSISIOUXSocketFv # GUSISIOUXSocket::Instance()
+__ct__15GUSISIOUXSocketFi # GUSISIOUXSocket::GUSISIOUXSocket(int)
+Instance__15GUSISIOUXSocketFi # GUSISIOUXSocket::Instance(int)
Py_FileSystemDefaultEncoding
_PyBuiltin_Init
_PyEval_SliceIndex
diff --git a/Mac/Build/PythonCoreCarbon.exp b/Mac/Build/PythonCoreCarbon.exp
index a7d02ff..ab1cbe6 100644
--- a/Mac/Build/PythonCoreCarbon.exp
+++ b/Mac/Build/PythonCoreCarbon.exp
@@ -5,8 +5,11 @@ GUSISetupFactories
__vt__15GUSISIOUXDevice # GUSISIOUXDevice::__vt
__vt__15GUSISIOUXSocket # GUSISIOUXSocket::__vt
sInstance__15GUSISIOUXDevice # GUSISIOUXDevice::sInstance
-sInstance__15GUSISIOUXSocket # GUSISIOUXSocket::sInstance
+initialized__15GUSISIOUXSocket # GUSISIOUXSocket::initialized
__dt__15GUSISIOUXDeviceFv # GUSISIOUXDevice::~GUSISIOUXDevice()
+PyMac_DummyWriteHandler
+PyMac_DummyReadHandler
+PyMac_SetConsoleHandler
GUSISetupConsoleDescriptors
open__15GUSISIOUXDeviceFR13GUSIFileTokeni # GUSISIOUXDevice::open(GUSIFileToken&,int)
Want__15GUSISIOUXDeviceFR13GUSIFileToken # GUSISIOUXDevice::Want(GUSIFileToken&)
@@ -20,8 +23,8 @@ write__15GUSISIOUXSocketFRC12GUSIGatherer # GUSISIOUXSocket::write(const GUSIGa
read__15GUSISIOUXSocketFRC13GUSIScatterer # GUSISIOUXSocket::read(const GUSIScatterer&)
__dt__15GUSISIOUXSocketFv # GUSISIOUXSocket::~GUSISIOUXSocket()
Initialize__15GUSISIOUXSocketFv # GUSISIOUXSocket::Initialize()
-__ct__15GUSISIOUXSocketFv # GUSISIOUXSocket::GUSISIOUXSocket()
-Instance__15GUSISIOUXSocketFv # GUSISIOUXSocket::Instance()
+__ct__15GUSISIOUXSocketFi # GUSISIOUXSocket::GUSISIOUXSocket(int)
+Instance__15GUSISIOUXSocketFi # GUSISIOUXSocket::Instance(int)
Py_FileSystemDefaultEncoding
_PyBuiltin_Init
_PyEval_SliceIndex
diff --git a/Mac/Python/pyGUSISIOUX.cp b/Mac/Python/pyGUSISIOUX.cp
index f26216b..40670d8 100644
--- a/Mac/Python/pyGUSISIOUX.cp
+++ b/Mac/Python/pyGUSISIOUX.cp
@@ -30,6 +30,12 @@
#include "macglue.h"
extern Boolean SIOUXUseWaitNextEvent;
+static PyReadHandler sInConsole = 0L;
+static PyWriteHandler sOutConsole = 0L;
+static PyWriteHandler sErrConsole = 0L;
+
+inline bool hasCustomConsole(void) { return sInConsole != 0L; }
+
class GUSISIOUXSocket : public GUSISocket {
public:
~GUSISIOUXSocket();
@@ -42,14 +48,12 @@ virtual int fstat(struct stat * buf);
virtual int isatty();
bool select(bool * canRead, bool * canWrite, bool *);
- static GUSISIOUXSocket * Instance();
-private:
- static GUSISIOUXSocket * sInstance;
-
- GUSISIOUXSocket();
- bool initialized;
- void Initialize();
- bool fDelayConsole;
+ static GUSISIOUXSocket * Instance(int fd);
+private:
+ GUSISIOUXSocket(int fd);
+ static bool initialized;
+ static void Initialize();
+ int fFd;
};
class GUSISIOUXDevice : public GUSIDevice {
public:
@@ -63,28 +67,19 @@ private:
static GUSISIOUXDevice * sInstance;
};
-GUSISIOUXSocket * GUSISIOUXSocket::sInstance;
-GUSISIOUXSocket * GUSISIOUXSocket::Instance()
+GUSISIOUXSocket * GUSISIOUXSocket::Instance(int fd)
{
- if (!sInstance)
- if (sInstance = new GUSISIOUXSocket)
- sInstance->AddReference();
-
- return sInstance;
+ return new GUSISIOUXSocket(fd);
}
// This declaration lies about the return type
extern "C" void SIOUXHandleOneEvent(EventRecord *userevent);
-GUSISIOUXSocket::GUSISIOUXSocket()
+bool GUSISIOUXSocket::initialized = false;
+
+GUSISIOUXSocket::GUSISIOUXSocket(int fd) : fFd(fd)
{
- if (PyMac_GetDelayConsoleFlag())
- fDelayConsole = true;
- else
- fDelayConsole = false;
- if ( fDelayConsole )
- initialized = 0;
- else
+ if (!PyMac_GetDelayConsoleFlag() && !hasCustomConsole() && !initialized)
Initialize();
/* Tell the upper layers there's no unseen output */
PyMac_OutputSeen();
@@ -93,24 +88,39 @@ GUSISIOUXSocket::GUSISIOUXSocket()
void
GUSISIOUXSocket::Initialize()
{
- initialized = 1;
- InstallConsole(0);
- GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent);
- GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent);
- GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent);
- GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent);
- GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent);
- GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent);
- GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent);
- PyMac_InitMenuBar();
+ if(!initialized && !hasCustomConsole())
+ {
+ initialized = true;
+ InstallConsole(0);
+ GUSISetHook(GUSI_EventHook+nullEvent, (GUSIHook)SIOUXHandleOneEvent);
+ GUSISetHook(GUSI_EventHook+mouseDown, (GUSIHook)SIOUXHandleOneEvent);
+ GUSISetHook(GUSI_EventHook+mouseUp, (GUSIHook)SIOUXHandleOneEvent);
+ GUSISetHook(GUSI_EventHook+updateEvt, (GUSIHook)SIOUXHandleOneEvent);
+ GUSISetHook(GUSI_EventHook+diskEvt, (GUSIHook)SIOUXHandleOneEvent);
+ GUSISetHook(GUSI_EventHook+activateEvt, (GUSIHook)SIOUXHandleOneEvent);
+ GUSISetHook(GUSI_EventHook+osEvt, (GUSIHook)SIOUXHandleOneEvent);
+ PyMac_InitMenuBar();
+ }
}
GUSISIOUXSocket::~GUSISIOUXSocket()
{
- if ( !initialized ) return;
+ if ( !initialized || hasCustomConsole() )
+ return;
+
+ initialized = false;
RemoveConsole();
}
ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer)
{
+ if(hasCustomConsole())
+ {
+ if(fFd == 0)
+ return buffer.SetLength(
+ sInConsole((char *) buffer.Buffer(), (int)buffer.Length()));
+
+ return 0;
+ }
+
if ( !initialized ) Initialize();
GUSIStdioFlush();
PyMac_OutputSeen();
@@ -121,6 +131,16 @@ ssize_t GUSISIOUXSocket::read(const GUSIScatterer & buffer)
}
ssize_t GUSISIOUXSocket::write(const GUSIGatherer & buffer)
{
+ if(hasCustomConsole())
+ {
+ if(fFd == 1)
+ return sOutConsole((char *) buffer.Buffer(), (int)buffer.Length());
+ else if(fFd == 2)
+ return sErrConsole((char *) buffer.Buffer(), (int)buffer.Length());
+
+ return 0;
+ }
+
ssize_t rv;
if ( !initialized ) Initialize();
@@ -198,14 +218,33 @@ bool GUSISIOUXDevice::Want(GUSIFileToken & file)
}
GUSISocket * GUSISIOUXDevice::open(GUSIFileToken &, int)
{
- return GUSISIOUXSocket::Instance();
+ return GUSISIOUXSocket::Instance(1);
}
void GUSISetupConsoleDescriptors()
{
GUSIDescriptorTable * table = GUSIDescriptorTable::Instance();
- GUSISIOUXSocket * SIOUX = GUSISIOUXSocket::Instance();
- table->InstallSocket(SIOUX);
- table->InstallSocket(SIOUX);
- table->InstallSocket(SIOUX);
+ table->InstallSocket(GUSISIOUXSocket::Instance(0));
+ table->InstallSocket(GUSISIOUXSocket::Instance(1));
+ table->InstallSocket(GUSISIOUXSocket::Instance(2));
+}
+
+void PyMac_SetConsoleHandler(PyReadHandler stdinH, PyWriteHandler stdoutH, PyWriteHandler stderrH)
+{
+ if(stdinH && stdoutH && stderrH)
+ {
+ sInConsole = stdinH;
+ sOutConsole = stdoutH;
+ sErrConsole = stderrH;
+ }
+}
+
+long PyMac_DummyReadHandler(char *buffer, long n)
+{
+ return 0;
+}
+
+long PyMac_DummyWriteHandler(char *buffer, long n)
+{
+ return 0;
}