diff options
author | Jack Jansen <jack.jansen@cwi.nl> | 2001-10-09 23:09:00 (GMT) |
---|---|---|
committer | Jack Jansen <jack.jansen@cwi.nl> | 2001-10-09 23:09:00 (GMT) |
commit | 893b0ab9886744db52ec4ab3238567b4a67dfeb0 (patch) | |
tree | 56198e0d8293eea21e07084b800cf7782eca03ba | |
parent | 04cf1d31d9748d6b2075abbd6c3c0729b5cbf348 (diff) | |
download | cpython-893b0ab9886744db52ec4ab3238567b4a67dfeb0.zip cpython-893b0ab9886744db52ec4ab3238567b4a67dfeb0.tar.gz cpython-893b0ab9886744db52ec4ab3238567b4a67dfeb0.tar.bz2 |
Fixed the embedding demo to correctly show the use of
overriding the console writer.
-rw-r--r-- | Mac/Demo/embed/demo.c | 30 | ||||
-rw-r--r-- | Mac/Demo/embed/embeddemo.prj | bin | 51653 -> 78479 bytes |
2 files changed, 19 insertions, 11 deletions
diff --git a/Mac/Demo/embed/demo.c b/Mac/Demo/embed/demo.c index 7d450f1..a022f94 100644 --- a/Mac/Demo/embed/demo.c +++ b/Mac/Demo/embed/demo.c @@ -1,35 +1,43 @@ /* Example of embedding Python in another program */ #include "Python.h" -#ifdef macintosh #include "macglue.h" -#endif /* macintosh */ static char *argv0; +long my_writehandler(char *buf, long count) +{ + long mycount; + unsigned char mybuf[255]; + + mycount = count; + if (mycount > 255 ) mycount = 255; + mybuf[0] = (unsigned char)mycount; + strncpy((char *)mybuf+1, buf, mycount); + DebugStr(mybuf); + return count; +} + main(argc, argv) int argc; char **argv; { -#ifdef macintosh /* So the user can set argc/argv to something interesting */ argc = ccommand(&argv); -#endif /* Save a copy of argv0 */ argv0 = argv[0]; - /* Initialize the Python interpreter. Required. */ -#ifdef macintosh /* If the first option is "-q" we don't open a console */ if ( argc > 1 && strcmp(argv[1], "-q") == 0 ) { PyMac_SetConsoleHandler(PyMac_DummyReadHandler, PyMac_DummyWriteHandler, PyMac_DummyWriteHandler); -/* freopen("demo output", "w", stdout); */ - } + } else + if ( argc > 1 && strcmp(argv[1], "-d") == 0 ) { + PyMac_SetConsoleHandler(PyMac_DummyReadHandler, my_writehandler, + my_writehandler); + } + /* Initialize the Python interpreter. Required. */ PyMac_Initialize(); -#else - Py_Initialize(); -#endif /* Define sys.argv. It is up to the application if you want this; you can also let it undefined (since the Python diff --git a/Mac/Demo/embed/embeddemo.prj b/Mac/Demo/embed/embeddemo.prj Binary files differindex e519b5c..778755a 100644 --- a/Mac/Demo/embed/embeddemo.prj +++ b/Mac/Demo/embed/embeddemo.prj |