[Python-checkins] CVS: python/dist/src/Mac/Demo/embed demo.c,1.2,1.3

Jack Jansen jackjansen@users.sourceforge.net
Tue, 09 Oct 2001 16:08:46 -0700


Update of /cvsroot/python/python/dist/src/Mac/Demo/embed
In directory usw-pr-cvs1:/tmp/cvs-serv7254/Python/Mac/Demo/embed

Modified Files:
	demo.c 
Log Message:
Fixed the embedding demo to correctly show the use of
overriding the console writer.

Index: demo.c
===================================================================
RCS file: /cvsroot/python/python/dist/src/Mac/Demo/embed/demo.c,v
retrieving revision 1.2
retrieving revision 1.3
diff -C2 -d -r1.2 -r1.3
*** demo.c	2001/10/08 15:32:17	1.2
--- demo.c	2001/10/09 23:08:44	1.3
***************
*** 2,34 ****
  
  #include "Python.h"
- #ifdef macintosh
  #include "macglue.h"
- #endif /* macintosh */
  
  static char *argv0;
  
  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); */
! 	}
  	PyMac_Initialize();
- #else
- 	Py_Initialize();
- #endif
  
  	/* Define sys.argv.  It is up to the application if you
--- 2,42 ----
  
  #include "Python.h"
  #include "macglue.h"
  
  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;
  {
  	/* So the user can set argc/argv to something interesting */
  	argc = ccommand(&argv);
  	/* Save a copy of argv0 */
  	argv0 = argv[0];
  
  	/* 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);
! 	} else
! 	if ( argc > 1 && strcmp(argv[1], "-d") == 0 )  {
! 		PyMac_SetConsoleHandler(PyMac_DummyReadHandler, my_writehandler,
! 			my_writehandler);
! 	} 
! 	/* Initialize the Python interpreter.  Required. */
  	PyMac_Initialize();
  
  	/* Define sys.argv.  It is up to the application if you