From 1a2d894b1320eb3b23bcb35ffbff29591cc190d7 Mon Sep 17 00:00:00 2001 From: cvs2svn Date: Wed, 11 Jul 2001 12:15:15 +0000 Subject: This commit was manufactured by cvs2svn to create branch 'release21-maint'. --- Lib/test/test_socketserver.py | 162 ++++ Mac/Demo/quicktime/VerySimplePlayer.py | 92 +++ Mac/Distributions/readme.txt | 43 ++ Mac/Include/config.h | 740 ++++++++++++++++++ Mac/Include/macglue.h | 160 ++++ Mac/Lib/EasyDialogs.py | 564 ++++++++++++++ Mac/Modules/macfsmodule.c | 1266 +++++++++++++++++++++++++++++++ Mac/Python/macimport.c | 492 ++++++++++++ Mac/Python/macmain.c | 672 ++++++++++++++++ Mac/Resources/dialogs.rsrc | Bin 0 -> 18027 bytes Mac/Tools/IDE/MacPrefs.py | 108 +++ Mac/Tools/IDE/PyBrowser.py | 442 +++++++++++ Mac/Tools/IDE/PyEdit.py | 1305 ++++++++++++++++++++++++++++++++ Mac/Tools/IDE/PyFontify.py | 155 ++++ Mac/Tools/IDE/Wcontrols.py | 393 ++++++++++ Mac/Tools/IDE/Wtraceback.py | 190 +++++ 16 files changed, 6784 insertions(+) create mode 100644 Lib/test/test_socketserver.py create mode 100644 Mac/Demo/quicktime/VerySimplePlayer.py create mode 100644 Mac/Distributions/readme.txt create mode 100644 Mac/Include/config.h create mode 100644 Mac/Include/macglue.h create mode 100644 Mac/Lib/EasyDialogs.py create mode 100644 Mac/Modules/macfsmodule.c create mode 100644 Mac/Python/macimport.c create mode 100644 Mac/Python/macmain.c create mode 100644 Mac/Resources/dialogs.rsrc create mode 100644 Mac/Tools/IDE/MacPrefs.py create mode 100644 Mac/Tools/IDE/PyBrowser.py create mode 100644 Mac/Tools/IDE/PyEdit.py create mode 100644 Mac/Tools/IDE/PyFontify.py create mode 100644 Mac/Tools/IDE/Wcontrols.py create mode 100644 Mac/Tools/IDE/Wtraceback.py diff --git a/Lib/test/test_socketserver.py b/Lib/test/test_socketserver.py new file mode 100644 index 0000000..b2d9661 --- /dev/null +++ b/Lib/test/test_socketserver.py @@ -0,0 +1,162 @@ +# Test suite for SocketServer.py + +# XXX This must be run manually -- somehow the I/O redirection of the +# regression test breaks the test. + +from test_support import verbose, verify, TESTFN +if not verbose: + raise ImportError, "test_socketserver can only be run manually" + +from SocketServer import * +import socket +import select +import time +import threading +import os + +NREQ = 3 +DELAY = 0.5 + +class MyMixinHandler: + def handle(self): + time.sleep(DELAY) + line = self.rfile.readline() + time.sleep(DELAY) + self.wfile.write(line) + +class MyStreamHandler(MyMixinHandler, StreamRequestHandler): + pass + +class MyDatagramHandler(MyMixinHandler, DatagramRequestHandler): + pass + +class MyMixinServer: + def serve_a_few(self): + for i in range(NREQ): + self.handle_request() + def handle_error(self, request, client_address): + self.close_request(request) + self.server_close() + raise + +teststring = "hello world\n" + +def receive(sock, n, timeout=20): + r, w, x = select.select([sock], [], [], timeout) + if sock in r: + return sock.recv(n) + else: + raise RuntimeError, "timed out on %s" % `sock` + +def testdgram(proto, addr): + s = socket.socket(proto, socket.SOCK_DGRAM) + s.sendto(teststring, addr) + buf = data = receive(s, 100) + while data and '\n' not in buf: + data = receive(s, 100) + buf += data + verify(buf == teststring) + s.close() + +def teststream(proto, addr): + s = socket.socket(proto, socket.SOCK_STREAM) + s.connect(addr) + s.send(teststring) + buf = data = receive(s, 100) + while data and '\n' not in buf: + data = receive(s, 100) + buf += data + verify(buf == teststring) + s.close() + +class ServerThread(threading.Thread): + def __init__(self, addr, svrcls, hdlrcls): + threading.Thread.__init__(self) + self.__addr = addr + self.__svrcls = svrcls + self.__hdlrcls = hdlrcls + def run(self): + class svrcls(MyMixinServer, self.__svrcls): + pass + if verbose: print "thread: creating server" + svr = svrcls(self.__addr, self.__hdlrcls) + if verbose: print "thread: serving three times" + svr.serve_a_few() + if verbose: print "thread: done" + +seed = 0 +def pickport(): + global seed + seed += 1 + return 10000 + (os.getpid() % 1000)*10 + seed + +host = "localhost" +testfiles = [] +def pickaddr(proto): + if proto == socket.AF_INET: + return (host, pickport()) + else: + fn = TESTFN + str(pickport()) + testfiles.append(fn) + return fn + +def cleanup(): + for fn in testfiles: + try: + os.remove(fn) + except os.error: + pass + testfiles[:] = [] + +def testloop(proto, servers, hdlrcls, testfunc): + for svrcls in servers: + addr = pickaddr(proto) + if verbose: + print "ADDR =", addr + print "CLASS =", svrcls + t = ServerThread(addr, svrcls, hdlrcls) + if verbose: print "server created" + t.start() + if verbose: print "server running" + for i in range(NREQ): + time.sleep(DELAY) + if verbose: print "test client", i + testfunc(proto, addr) + if verbose: print "waiting for server" + t.join() + if verbose: print "done" + +tcpservers = [TCPServer, ThreadingTCPServer] +if hasattr(os, 'fork'): + tcpservers.append(ForkingTCPServer) +udpservers = [UDPServer, ThreadingUDPServer] +if hasattr(os, 'fork'): + udpservers.append(ForkingUDPServer) + +if not hasattr(socket, 'AF_UNIX'): + streamservers = [] + dgramservers = [] +else: + class ForkingUnixStreamServer(ForkingMixIn, UnixStreamServer): pass + streamservers = [UnixStreamServer, ThreadingUnixStreamServer, + ForkingUnixStreamServer] + class ForkingUnixDatagramServer(ForkingMixIn, UnixDatagramServer): pass + dgramservers = [UnixDatagramServer, ThreadingUnixDatagramServer, + ForkingUnixDatagramServer] + +def testall(): + testloop(socket.AF_INET, tcpservers, MyStreamHandler, teststream) + testloop(socket.AF_INET, udpservers, MyDatagramHandler, testdgram) + if hasattr(socket, 'AF_UNIX'): + testloop(socket.AF_UNIX, streamservers, MyStreamHandler, teststream) + # Alas, on Linux (at least) recvfrom() doesn't return a meaningful + # client address so this cannot work: + ##testloop(socket.AF_UNIX, dgramservers, MyDatagramHandler, testdgram) + +def main(): + try: + testall() + finally: + cleanup() + +main() diff --git a/Mac/Demo/quicktime/VerySimplePlayer.py b/Mac/Demo/quicktime/VerySimplePlayer.py new file mode 100644 index 0000000..3053d33 --- /dev/null +++ b/Mac/Demo/quicktime/VerySimplePlayer.py @@ -0,0 +1,92 @@ +"""VerySimplePlayer converted to python + +Jack Jansen, CWI, December 1995 +""" + +import Qt +import QuickTime +import Qd +import QuickDraw +import Evt +import Events +import Win +import Windows +import macfs +import sys + +# XXXX maxbounds = (40, 40, 1000, 1000) + +def main(): + print 'hello world' # XXXX + # skip the toolbox initializations, already done + # XXXX Should use gestalt here to check for quicktime version + Qt.EnterMovies() + + # Get the movie file + fss, ok = macfs.StandardGetFile(QuickTime.MovieFileType) + if not ok: + sys.exit(0) + + # Open the window + bounds = (175, 75, 175+160, 75+120) + theWindow = Win.NewCWindow(bounds, fss.as_tuple()[2], 0, 0, -1, 1, 0) + # XXXX Needed? SetGWorld((CGrafPtr)theWindow, nil) + Qd.SetPort(theWindow) + + # Get the movie + theMovie = loadMovie(fss) + + # Relocate to (0, 0) + bounds = theMovie.GetMovieBox() + bounds = 0, 0, bounds[2]-bounds[0], bounds[3]-bounds[1] + theMovie.SetMovieBox(bounds) + + # Create a controller + theController = theMovie.NewMovieController(bounds, QuickTime.mcTopLeftMovie) + + # Get movie size and update window parameters + rv, bounds = theController.MCGetControllerBoundsRect() + theWindow.SizeWindow(bounds[2], bounds[3], 0) # XXXX or [3] [2]? + Qt.AlignWindow(theWindow, 0) + theWindow.ShowWindow() + + # XXXX MCDoAction(theController, mcActionSetGrowBoxBounds, &maxBounds) + theController.MCDoAction(QuickTime.mcActionSetKeysEnabled, '1') + + # XXXX MCSetActionFilterWithRefCon(theController, movieControllerEventFilter, (long)theWindow) + + done = 0 + while not done: + gotone, evt = Evt.WaitNextEvent(0xffff, 0) + (what, message, when, where, modifiers) = evt +## print what, message, when, where, modifiers # XXXX + + if theController.MCIsPlayerEvent(evt): + continue + + if what == Events.mouseDown: + part, whichWindow = Win.FindWindow(where) + if part == Windows.inGoAway: + done = whichWindow.TrackGoAway(where) + elif part == Windows.inDrag: + Qt.DragAlignedWindow(whichWindow, where, (0, 0, 4000, 4000)) + elif what == Events.updateEvt: + whichWindow = Win.WhichWindow(message) + if not whichWindow: + # Probably the console window. Print something, hope it helps. + print 'update' + else: + Qd.SetPort(whichWindow) + whichWindow.BeginUpdate() + Qd.EraseRect(whichWindow.GetWindowPort().portRect) + whichWindow.EndUpdate() + +def loadMovie(theFile): + """Load a movie given an fsspec. Return the movie object""" + movieResRef = Qt.OpenMovieFile(theFile, 1) + movie, d1, d2 = Qt.NewMovieFromFile(movieResRef, 0, QuickTime.newMovieActive) + return movie + +if __name__ == '__main__': + main() + diff --git a/Mac/Distributions/readme.txt b/Mac/Distributions/readme.txt new file mode 100644 index 0000000..9aa6a65 --- /dev/null +++ b/Mac/Distributions/readme.txt @@ -0,0 +1,43 @@ +How to make a Python-distribution. +---------------------------------- + +These notes are mainly for myself, or for whoever tries to make a MacPython +distribution when I'm fed up with it. They were last updated for 2.1b2. + +- Increase fragment version number in PythonCore and PythonCoreCarbon. + the fragment number is Python's sys.hexversion, it should be set in the + "PEF" preferences. +- Increase version number in _versioncheck.py +- Build PythonStandSmall, run once in root folder +- Update Relnotes, readme's, Demo:build.html +- Make sure tkresources.rsrc is up-to-date +- fullbuild everything with increase-buildno +- Update Numeric and build/install it both with Classic and with Carbon python +- Run configurepython +- Recompile OSAm and possibly other Contrib stuff +- mkdistr binary.include +- mkdistr dev.include +- make distribution archive with Installer Vise + Things to make sure of: + - Finder icon positions + - Version numbers in "Packages..." window + - Version number in "Installer Settings" -> "Easy Install Text" + - Version number in "Project" -> Attributes + - Version number in "Project" -> PostProcess + - Version number in "Internet" -> "Download Sites" + - Version number in "Internet" -> "File Groups". +- test on virgin systems (OSX, OS9, OS8 without Carbon). Make sure to test + tkinter too. +- Upload +- Update README file in ftp directory +- Change version number in public_html/macpythonversion.txt . +- Update macpython.html +- Send an announcement to: + pythonmac-sig@python.org + python-dev@python.org + python-announce@python.org + archivist@info-mac.org + adcnews@apple.com + http://www.macupdate.com + http://guide.apple.com/usindex.html + http://www.versiontracker.com/ Jack.Jansen@oratrix.com \ No newline at end of file diff --git a/Mac/Include/config.h b/Mac/Include/config.h new file mode 100644 index 0000000..4158873 --- /dev/null +++ b/Mac/Include/config.h @@ -0,0 +1,740 @@ +/*********************************************************** +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. + +******************************************************************/ + +/* config.h for Macintosh. + Valid only for CodeWarrior. + There's no point in giving exact version numbers of the compilers + since we don't update this file as each compiler comes out; + with CodeWarrior, we generally use the most recent version. +*/ + +#define USE_STACKCHECK + +/* Define if on Macintosh (MPW or __MWERKS__ should also be defined) */ +#ifndef macintosh +#define macintosh +#endif + +#if defined(USE_GUSI1) || defined(USE_GUSI2) +#define USE_GUSI +#endif + +#ifndef USE_GUSI +#define DONT_HAVE_SYS_TYPES_H +#define DONT_HAVE_SYS_STAT_H +#define HAVE_STAT_H +#endif + +/* Define if on AIX 3. + System headers sometimes define this. + We just want to avoid a redefinition error message. */ +#ifndef _ALL_SOURCE +#undef _ALL_SOURCE +#endif + +/* Define if type char is unsigned and you are not using gcc. */ +#ifndef __CHAR_UNSIGNED__ +#undef __CHAR_UNSIGNED__ +#endif + +/* Define to empty if the keyword does not work. */ +#undef const + +/* Define to `int' if doesn't define. */ +#undef gid_t + +/* Define if your struct tm has tm_zone. */ +#undef HAVE_TM_ZONE + +/* Define if you don't have tm_zone but do have the external array + tzname. */ +#undef HAVE_TZNAME + +/* Define if on MINIX. */ +#undef _MINIX + +/* Define to `int' if doesn't define. */ +#undef mode_t + +/* Define to `long' if doesn't define. */ +#undef off_t + +/* Define to `int' if doesn't define. */ +#undef pid_t + +/* Define if the system does not provide POSIX.1 features except + with this defined. */ +#undef _POSIX_1_SOURCE + +/* Define if you need to in order for stat and other things to work. */ +#undef _POSIX_SOURCE + +/* Define as the return type of signal handlers (int or void). */ +#define RETSIGTYPE void + +/* Define to `unsigned' if doesn't define. */ +#undef size_t + +/* Define if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + +/* Define if you can safely include both and . */ +#undef TIME_WITH_SYS_TIME + +/* Define if your declares struct tm. */ +#undef TM_IN_SYS_TIME + +/* Define to `int' if doesn't define. */ +#undef uid_t + +/* Define if your processor stores words with the most significant + byte first (like Motorola and SPARC, unlike Intel and VAX). */ +#define WORDS_BIGENDIAN 1 + +/* Define for AIX if your compiler is a genuine IBM xlC/xlC_r + and you want support for AIX C++ shared extension modules. */ +#undef AIX_GENUINE_CPLUSPLUS + +/* Define if your contains bad prototypes for exec*() + (as it does on SGI IRIX 4.x) */ +#undef BAD_EXEC_PROTOTYPES + +/* Define if your compiler botches static forward declarations */ +#define BAD_STATIC_FORWARD + +/* Define this if you have BeOS threads */ +#undef BEOS_THREADS + +/* Define if you have the Mach cthreads package */ +#undef C_THREADS + +/* Defined when case of imported modules are checked against case of file. */ +#define CHECK_IMPORT_CASE + +/* Define to `long' if doesn't define. */ +#undef clock_t + +/* Defined on Solaris to see additional function prototypes. */ +#undef __EXTENSIONS__ + +/* Define if getpgrp() must be called as getpgrp(0). */ +#undef GETPGRP_HAVE_ARG + +/* Define if gettimeofday() does not have second (timezone) argument + This is the case on Motorola V4 (R40V4.2) */ +#undef GETTIMEOFDAY_NO_TZ + +/* Define this if your time.h defines altzone */ +#undef HAVE_ALTZONE + +/* Defined when any dynamic module loading is enabled */ +/* #undef HAVE_DYNAMIC_LOADING */ + +/* Define this if you have flockfile(), getc_unlocked(), and funlockfile() */ +#undef HAVE_GETC_UNLOCKED + +/* Define this if you have some version of gethostbyname_r() */ +#undef HAVE_GETHOSTBYNAME_R + +/* Define this if you have the 3-arg version of gethostbyname_r() */ +#undef HAVE_GETHOSTBYNAME_R_3_ARG + +/* Define this if you have the 5-arg version of gethostbyname_r() */ +#undef HAVE_GETHOSTBYNAME_R_5_ARG + +/* Define this if you have the 6-arg version of gethostbyname_r() */ +#undef HAVE_GETHOSTBYNAME_R_6_ARG + +/* Defined to enable large file support when an off_t is bigger than a long + and long long is available and at least as big as an off_t. You may need + to add some flags for configuration and compilation to enable this mode. + E.g, for Solaris 2.7: + CFLAGS="-D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64" OPT="-O2 $CFLAGS" \ + configure +*/ +#undef HAVE_LARGEFILE_SUPPORT + +/* Define this if you have the type long long */ +#undef HAVE_LONG_LONG + +/* Define if your compiler supports function prototypes */ +#define HAVE_PROTOTYPES 1 + +/* Define if you have GNU PTH threads */ +#undef HAVE_PTH + +/* Define if your compiler supports variable length function prototypes + (e.g. void fprintf(FILE *, char *, ...);) *and* */ +#define HAVE_STDARG_PROTOTYPES + +/* Define this if you have the type uintptr_t */ +#undef HAVE_UINTPTR_T + +/* Define if you have a useable wchar_t type defined in wchar.h; useable + means wchar_t must be 16-bit unsigned type. (see + Include/unicodeobject.h). */ +#define HAVE_USABLE_WCHAR_T 1 + +/* Define if the compiler provides a wchar.h header file. */ +#define HAVE_WCHAR_H 1 + +/* Define if you want to have a Unicode type. */ +#define Py_USING_UNICODE 1 + +/* Define as the integral type used for Unicode representation. */ +#define PY_UNICODE_TYPE wchar_t + +/* Define as the size of the unicode type. */ +#define Py_UNICODE_SIZE 2 + +/* Define if malloc(0) returns a NULL pointer */ +#ifdef USE_MSL_MALLOC +#define MALLOC_ZERO_RETURNS_NULL +#else +#undef MALLOC_ZERO_RETURNS_NULL +#endif + +/* Define if you have POSIX threads */ +#ifdef USE_GUSI2 +#define _POSIX_THREADS +#endif + +/* Define if you want to build an interpreter with many run-time checks */ +#undef Py_DEBUG + +/* Define to force use of thread-safe errno, h_errno, and other functions */ +#undef _REENTRANT + +/* Define if setpgrp() must be called as setpgrp(0, 0). */ +#undef SETPGRP_HAVE_ARG + +/* Define to empty if the keyword does not work. */ +#undef signed + +/* Define if i>>j for signed int i does not extend the sign bit + when i < 0 +*/ +#define SIGNED_RIGHT_SHIFT_ZERO_FILLS + +/* The number of bytes in an off_t. */ +#define SIZEOF_OFF_T 4 + +/* The number of bytes in a time_t. */ +#define SIZEOF_TIME_T 4 + +/* The number of bytes in a pthread_t. */ +#ifdef USE_GUSI2 +#define SIZEOF_PTHREAD_T 4 +#endif + +/* Define to `int' if doesn't define. */ +#undef socklen_t + +/* Define if you can safely include both and + (which you can't on SCO ODT 3.0). */ +#undef SYS_SELECT_WITH_SYS_TIME + +/* Define if a va_list is an array of some kind */ +#undef VA_LIST_IS_ARRAY + +/* Define to empty if the keyword does not work. */ +#undef volatile + +/* Define if you want SIGFPE handled (see Include/pyfpe.h). */ +#undef WANT_SIGFPE_HANDLER + +/* Define if you want wctype.h functions to be used instead of the + one supplied by Python itself. (see Include/unicodectype.h). */ +#undef WANT_WCTYPE_FUNCTIONS + +/* Define if you want to compile in cycle garbage collection */ +#undef WITH_CYCLE_GC + +/* Define if you want to emulate SGI (IRIX 4) dynamic linking. + This is rumoured to work on VAX (Ultrix), Sun3 (SunOS 3.4), + Sequent Symmetry (Dynix), and Atari ST. + This requires the "dl-dld" library, + ftp://ftp.cwi.nl/pub/dynload/dl-dld-1.1.tar.Z, + as well as the "GNU dld" library, + ftp://ftp.cwi.nl/pub/dynload/dld-3.2.3.tar.Z. + Don't bother on SunOS 4 or 5, they already have dynamic linking using + shared libraries */ +#undef WITH_DL_DLD + +/* Define if you want to use the new-style (Openstep, Rhapsody, MacOS) + dynamic linker (dyld) instead of the old-style (NextStep) dynamic + linker (rld). Dyld is necessary to support frameworks. */ +#undef WITH_DYLD + +/* Define if you want to compile in Python-specific mallocs */ +#undef WITH_PYMALLOC + +/* Define if you want to produce an OpenStep/Rhapsody framework + (shared library plus accessory files). */ +#undef WITH_NEXT_FRAMEWORK + +/* Define if you want to use SGI (IRIX 4) dynamic linking. + This requires the "dl" library by Jack Jansen, + ftp://ftp.cwi.nl/pub/dynload/dl-1.6.tar.Z. + Don't bother on IRIX 5, it already has dynamic linking using SunOS + style shared libraries */ +#undef WITH_SGI_DL + +/* Define if you want to compile in rudimentary thread support */ +/* #undef WITH_THREAD */ + +/* The number of bytes in a char. */ +#define SIZEOF_CHAR 1 + +/* The number of bytes in a double. */ +#define SIZEOF_DOUBLE 8 + +/* The number of bytes in a float. */ +#define SIZEOF_FLOAT 4 + +/* The number of bytes in a fpos_t. */ +#define SIZEOF_FPOS_T 4 + +/* The number of bytes in a int. */ +#define SIZEOF_INT 4 + +/* The number of bytes in a long. */ +#define SIZEOF_LONG 4 + +/* The number of bytes in a long long. */ +#undef SIZEOF_LONG_LONG + +/* The number of bytes in a short. */ +#define SIZEOF_SHORT 2 + +/* The number of bytes in a uintptr_t. */ +#define SIZEOF_UINTPTR_T 4 + +/* The number of bytes in a void *. */ +#define SIZEOF_VOID_P 4 + +/* Define if you have the _getpty function. */ +#undef HAVE__GETPTY + +/* Define if you have the alarm function. */ +#undef HAVE_ALARM + +/* Define if you have the chown function. */ +#undef HAVE_CHOWN + +/* Define if you have clock. */ +#define HAVE_CLOCK + +/* Define if you have the confstr function. */ +#undef HAVE_CONFSTR + +/* Define if you have the ctermid function. */ +#undef HAVE_CTERMID + +/* Define if you have the ctermid_r function. */ +#undef HAVE_CTERMID_R + +/* Define if you have the dlopen function. */ +#undef HAVE_DLOPEN + +/* Define if you have the dup2 function. */ +#undef HAVE_DUP2 + +/* Define if you have the execv function. */ +#undef HAVE_EXECV + +/* Define if you have the fdatasync function. */ +#undef HAVE_FDATASYNC + +/* Define if you have the flock function. */ +#undef HAVE_FLOCK + +/* Define if you have the fork function. */ +#undef HAVE_FORK + +/* Define if you have the forkpty function. */ +#undef HAVE_FORKPTY + +/* Define if you have the fpathconf function. */ +#undef HAVE_FPATHCONF + +/* Define if you have the fseek64 function. */ +#undef HAVE_FSEEK64 + +/* Define if you have the fseeko function. */ +#undef HAVE_FSEEKO + +/* Define if you have the fstatvfs function. */ +#undef HAVE_FSTATVFS + +/* Define if you have the fsync function. */ +#define HAVE_FSYNC + +/* Define if you have the ftell64 function. */ +#undef HAVE_FTELL64 + +/* Define if you have the ftello function. */ +#undef HAVE_FTELLO + +/* Define if you have the ftime function. */ +#undef HAVE_FTIME + +/* Define if you have the ftruncate function. */ +#ifdef USE_GUSI +#define HAVE_FTRUNCATE +#endif + +/* Define if you have the getcwd function. */ +#define HAVE_GETCWD + +/* Define if you have the getgroups function. */ +#undef HAVE_GETGROUPS + +/* Define if you have the gethostbyname function. */ +#ifdef USE_GUSI +#define HAVE_GETHOSTBYNAME 1 +#endif + +/* Define if you have the getlogin function. */ +#undef HAVE_GETLOGIN + +/* Define if you have the getpeername function. */ +#ifdef USE_GUSI +#define HAVE_GETPEERNAME +#endif + +/* Define if you have the getpgrp function. */ +#undef HAVE_GETPGRP + +/* Define if you have the getpid function. */ +#undef HAVE_GETPID + +/* Define if you have the getpwent function. */ +#undef HAVE_GETPWENT + +/* Define if you have the gettimeofday function. */ +#ifdef USE_GUSI +#define HAVE_GETTIMEOFDAY +#endif + +/* Define if you have the getwd function. */ +#undef HAVE_GETWD + +/* Define if you have the hypot function. */ +#ifndef __MC68K__ +/* 68K hypot definition (and implementation) are unuseable +** because they use 10-byte floats. +*/ +#define HAVE_HYPOT +#endif + +/* Define if you have the kill function. */ +#undef HAVE_KILL + +/* Define if you have the link function. */ +#undef HAVE_LINK + +/* Define if you have the lstat function. */ +#undef HAVE_LSTAT + +/* Define if you have the memmove function. */ +#define HAVE_MEMMOVE + +/* Define if you have the mkfifo function. */ +#undef HAVE_MKFIFO + +/* Define if you have the mktime function. */ +#define HAVE_MKTIME + +/* Define if you have the mremap function. */ +#undef HAVE_MREMAP + +/* Define if you have the nice function. */ +#undef HAVE_NICE + +/* Define if you have the openpty function. */ +#undef HAVE_OPENPTY + +/* Define if you have the pathconf function. */ +#undef HAVE_PATHCONF + +/* Define if you have the pause function. */ +#undef HAVE_PAUSE + +/* Define if you have the plock function. */ +#undef HAVE_PLOCK + +/* Define if you have the poll function. */ +#undef HAVE_POLL + +/* Define if you have the pthread_init function. */ +#undef HAVE_PTHREAD_INIT + +/* Define if you have the putenv function. */ +#undef HAVE_PUTENV + +/* Define if you have the readlink function. */ +#undef HAVE_READLINK + +/* Define if you have the select function. */ +#ifdef USE_GUSI +#define HAVE_SELECT +#endif + +/* Define if you have the setegid function. */ +#undef HAVE_SETEGID + +/* Define if you have the seteuid function. */ +#undef HAVE_SETEUID + +/* Define if you have the setgid function. */ +#undef HAVE_SETGID + +/* Define if you have the setlocale function. */ +#undef HAVE_SETLOCALE + +/* Define if you have the setpgid function. */ +#undef HAVE_SETPGID + +/* Define if you have the setpgrp function. */ +#undef HAVE_SETPGRP + +/* Define if you have the setregid function. */ +#undef HAVE_SETREGID + +/* Define if you have the setreuid function. */ +#undef HAVE_SETREUID + +/* Define if you have the setsid function. */ +#undef HAVE_SETSID + +/* Define if you have the setuid function. */ +#undef HAVE_SETUID + +/* Define if you have the setvbuf function. */ +#define HAVE_SETVBUF + +/* Define if you have the sigaction function. */ +#undef HAVE_SIGACTION + +/* Define if you have the siginterrupt function. */ +#undef HAVE_SIGINTERRUPT + +/* Define if you have the sigrelse function. */ +#undef HAVE_SIGRELSE + +/* Define if you have the statvfs function. */ +#undef HAVE_STATVFS + +/* Define if you have the strdup function. */ +#undef HAVE_STRDUP + +/* Define if you have the strerror function. */ +#define HAVE_STRERROR + +/* Define if you have the strftime function. */ +#define HAVE_STRFTIME + +/* Define if you have the strptime function. */ +#undef HAVE_STRPTIME + +/* Define if you have the symlink function. */ +#undef HAVE_SYMLINK + +/* Define if you have the sysconf function. */ +#undef HAVE_SYSCONF + +/* Define if you have the tcgetpgrp function. */ +#undef HAVE_TCGETPGRP + +/* Define if you have the tcsetpgrp function. */ +#undef HAVE_TCSETPGRP + +/* Define if you have the tempnam function. */ +#undef HAVE_TEMPNAM + +/* Define if you have the timegm function. */ +#undef HAVE_TIMEGM + +/* Define if you have the times function. */ +#undef HAVE_TIMES + +/* Define if you have the tmpfile function. */ +#define HAVE_TMPFILE + +/* Define if you have the tmpnam function. */ +#define HAVE_TMPNAM + +/* Define if you have the tmpnam_r function. */ +#undef HAVE_TMPNAM_R + +/* Define if you have the truncate function. */ +#define HAVE_TRUNCATE + +/* Define if you have the uname function. */ +#undef HAVE_UNAME + +/* Define if you have the waitpid function. */ +#undef HAVE_WAITPID + +/* Define if you have the header file. */ +#undef HAVE_DB_H + +/* Define if you have the header file. */ +#undef HAVE_DB1_NDBM_H + +/* Define if you have the header file. */ +#undef HAVE_DB_185_H + +/* Define if you have the header file. */ +#ifdef USE_GUSI +#define HAVE_DIRENT_H +#endif + +/* Define if you have the header file. */ +#undef HAVE_DLFCN_H + +/* Define if you have the header file. */ +#define HAVE_FCNTL_H + +/* Define if you have the header file. */ +#undef HAVE_GDBM_NDBM_H + +/* Define if you have the header file. */ +#undef HAVE_LIBUTIL_H + +/* Define if you have the header file. */ +#define HAVE_LIMITS_H + +/* Define if you have the header file. */ +#define HAVE_LOCALE_H + +/* Define if you have the header file. */ +#undef HAVE_NCURSES_H + +/* Define if you have the header file. */ +#undef HAVE_NDBM_H + +/* Define if you have the header file. */ +#undef HAVE_NDIR_H + +/* Define if you have the header file. */ +#undef HAVE_POLL_H + +/* Define if you have the header file. */ +#ifdef USE_GUSI2 +#define HAVE_PTHREAD_H +#endif + +/* Define if you have the header file. */ +#undef HAVE_PTY_H + +/* Define if you have the header file. */ +#define HAVE_SIGNAL_H + +/* Define if you have the header file. */ +#define HAVE_STDARG_H + +/* Define if you have the header file. */ +#define HAVE_STDDEF_H + +/* Define if you have the header file. */ +#define HAVE_STDLIB_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_AUDIOIO_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_DIR_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_FILE_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_LOCK_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_MODEM_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_NDIR_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_PARAM_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_SELECT_H + +/* Define if you have the header file. */ +#ifdef USE_GUSI +#define HAVE_SYS_SOCKET_H +#endif + +/* Define if you have the header file. */ +#ifdef USE_GUSI +#define HAVE_SYS_TIME_H +#endif + +/* Define if you have the header file. */ +#undef HAVE_SYS_TIMES_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_UN_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_UTSNAME_H + +/* Define if you have the header file. */ +#undef HAVE_SYS_WAIT_H + +/* Define if you have the header file. */ +#undef HAVE_TERMIOS_H + +/* Define if you have the header file. */ +#undef HAVE_THREAD_H + +/* Define if you have the header file. */ +#define HAVE_UNISTD_H + +/* Define if you have the header file. */ +#define HAVE_UTIME_H + +/* Define if you have the dl library (-ldl). */ +#undef HAVE_LIBDL + +/* Define if you have the dld library (-ldld). */ +#undef HAVE_LIBDLD + +/* Define if you have the ieee library (-lieee). */ +#undef HAVE_LIBIEEE + +#ifdef __CYGWIN__ +#ifdef USE_DL_IMPORT +#define DL_IMPORT(RTYPE) __declspec(dllimport) RTYPE +#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE +#else +#define DL_IMPORT(RTYPE) __declspec(dllexport) RTYPE +#define DL_EXPORT(RTYPE) __declspec(dllexport) RTYPE +#endif +#endif diff --git a/Mac/Include/macglue.h b/Mac/Include/macglue.h new file mode 100644 index 0000000..e0c0ff5 --- /dev/null +++ b/Mac/Include/macglue.h @@ -0,0 +1,160 @@ +/*********************************************************** +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. + +******************************************************************/ + +#ifdef WITHOUT_FRAMEWORKS +#include +#include +#include +#include +#else +#include +#endif + +#ifdef __cplusplus + extern "C" { +#endif + +/* Scheduler parameters */ +typedef struct { + int check_interrupt; /* if true check for command-dot */ + int process_events; /* if nonzero enable evt processing, this mask */ + int besocial; /* Be social, give up CPU now and again */ + double check_interval; /* how often to check */ + double bg_yield; /* yield at most so long when in background */ +} PyMacSchedParams; + +char *PyMac_getscript(void); /* Get the default encoding for our 8bit character set */ +#ifdef USE_GUSI1 +void PyMac_FixGUSIcd(void); /* Workaround for GUSI chdir() call */ +extern void PyMac_SetGUSISpin(void); /* Install our private GUSI spin routine */ +#endif + +char *PyMac_StrError(int); /* strerror with mac errors */ +PyObject *PyErr_Mac(PyObject *, int); /* Exception with a mac error */ +PyObject *PyMac_Error(OSErr); /* Uses PyMac_GetOSErrException */ +unsigned char *Pstring(char *str); /* Convert c-string to pascal-string in static buffer */ + +#ifdef USE_GUSI +extern int PyMac_ConsoleIsDead; /* True when exiting */ +extern void PyMac_StopGUSISpin(void); /* Stop eventprocessing during exit() */ +#endif + +extern short PyMac_AppRefNum; /* RefNum of application rsrcfork (from macmain.c) */ +extern FSSpec PyMac_ApplicationFSSpec; /* Application location (from macargv.c) */ +extern char PyMac_ApplicationPath[]; /* Application location (from macargv.c) */ +extern OSErr PyMac_init_application_location(void); /* Init the above */ +extern OSErr PyMac_GetFullPath(FSSpec *, char *); /* convert fsspec->path (macargv.c) */ +extern int PyMac_GetArgv(char ***, int); /* Get argc, argv (from macargv.c) */ +extern int PyMac_AppearanceCompliant; /* True if in appearance support mode */ + +extern PyObject *PyMac_OSErrException; /* Exception for OSErr */ +PyObject *PyMac_GetOSErrException(void); /* Initialize & return it */ + +#if !TARGET_API_MAC_OSX +void PyMac_GetSchedParams(PyMacSchedParams *); /* Get schedulers params */ +void PyMac_SetSchedParams(PyMacSchedParams *); /* Set schedulers params */ +int PyMac_DoYield(int, int); /* Yield cpu. First arg is maxtime, second ok to call python */ +#endif +int PyMac_HandleEvent(EventRecord *); /* Handle one event, possibly in Python */ +void PyMac_HandleEventIntern(EventRecord *); /* Handle one event internal only */ +int PyMac_SetEventHandler(PyObject *); /* set python-coded event handler */ + +#if !TARGET_API_MAC_OSX +void PyMac_InitMenuBar(void); /* Setup menu bar as we want it */ +void PyMac_RestoreMenuBar(void); /* Restore menu bar for ease of exiting */ +void PyMac_RaiseConsoleWindow(); /* Bring console window to front, if it exists */ +#endif +int PyMac_FindResourceModule(PyStringObject *, char *, char *); /* Test for 'PYC ' resource in a file */ +PyObject * PyMac_LoadResourceModule(char *, char *); /* Load 'PYC ' resource from file */ +int PyMac_FindCodeResourceModule(PyStringObject *, char *, char *); /* Test for 'PYD ' resource in a file */ +PyObject * PyMac_LoadCodeResourceModule(char *, char *); /* Load 'PYD ' resource from file */ +struct filedescr *PyMac_FindModuleExtension(char *, size_t *, char *); /* Look for module in single folder */ + +#if TARGET_API_MAC_OS8 +int PyMac_GetDirectory(FSSpec *dirfss, char *prompt); /* Ask user for a directory */ +void PyMac_PromptGetFile(short numTypes, ConstSFTypeListPtr typeList, + StandardFileReply *reply, char *prompt); /* Ask user for file, with prompt */ +#endif /* TARGET_API_MAC_OS8 */ + +int PyMac_GetOSType(PyObject *, OSType *); /* argument parser for OSType */ +PyObject *PyMac_BuildOSType(OSType); /* Convert OSType to PyObject */ + +PyObject *PyMac_BuildNumVersion(NumVersion); /* Convert NumVersion to PyObject */ + +int PyMac_GetStr255(PyObject *, Str255); /* argument parser for Str255 */ +PyObject *PyMac_BuildStr255(Str255); /* Convert Str255 to PyObject */ +PyObject *PyMac_BuildOptStr255(Str255); /* Convert Str255 to PyObject, NULL to None */ + +int PyMac_GetRect(PyObject *, Rect *); /* argument parser for Rect */ +PyObject *PyMac_BuildRect(Rect *); /* Convert Rect to PyObject */ + +int PyMac_GetPoint(PyObject *, Point *); /* argument parser for Point */ +PyObject *PyMac_BuildPoint(Point); /* Convert Point to PyObject */ + +int PyMac_GetEventRecord(PyObject *, EventRecord *); /* argument parser for EventRecord */ +PyObject *PyMac_BuildEventRecord(EventRecord *); /* Convert EventRecord to PyObject */ + +int PyMac_GetFixed(PyObject *, Fixed *); /* argument parser for Fixed */ +PyObject *PyMac_BuildFixed(Fixed); /* Convert Fixed to PyObject */ +int PyMac_Getwide(PyObject *, wide *); /* argument parser for wide */ +PyObject *PyMac_Buildwide(wide *); /* Convert wide to PyObject */ +void PyMac_InitApplet(void); /* Initialize and run an Applet */ +void PyMac_Initialize(void); /* Initialize function for embedding Python */ + +#ifdef USE_GUSI2 +short PyMac_OpenPrefFile(void); /* From macgetpath.c, open and return preference file */ +#endif + +/* from macfsmodule.c: */ +int PyMac_GetFSSpec(PyObject *, FSSpec *); /* argument parser for FSSpec */ +PyObject *PyMac_BuildFSSpec(FSSpec *); /* Convert FSSpec to PyObject */ + +int PyMac_GetFSRef(PyObject *, FSRef *); /* argument parser for FSRef */ +PyObject *PyMac_BuildFSRef(FSRef *); /* Convert FSRef to PyObject */ + + +/* From macfiletype.c: */ + +long PyMac_getfiletype(char *); /* Get file type */ +int PyMac_setfiletype(char *, long, long); /* Set file creator and type */ + +/* from macmain.c: */ +void PyMac_Exit(int); +void PyMac_InitApplication(void); +void PyMac_OutputSeen(void); +void PyMac_OutputNotSeen(void); +int PyMac_GetDelayConsoleFlag(void); +#ifdef USE_MAC_APPLET_SUPPORT +void PyMac_InitApplet(void); +#endif + +/* from macgetargv: */ +OSErr PyMac_init_process_location(void); +#ifndef HAVE_STRDUP +char * strdup(const char *str); +#endif + +#ifdef __cplusplus + } +#endif diff --git a/Mac/Lib/EasyDialogs.py b/Mac/Lib/EasyDialogs.py new file mode 100644 index 0000000..a9d3e16 --- /dev/null +++ b/Mac/Lib/EasyDialogs.py @@ -0,0 +1,564 @@ +"""Easy to use dialogs. + +Message(msg) -- display a message and an OK button. +AskString(prompt, default) -- ask for a string, display OK and Cancel buttons. +AskPassword(prompt, default) -- like AskString(), but shows text as bullets. +AskYesNoCancel(question, default) -- display a question and Yes, No and Cancel buttons. +bar = Progress(label, maxvalue) -- Display a progress bar +bar.set(value) -- Set value +bar.inc( *amount ) -- increment value by amount (default=1) +bar.label( *newlabel ) -- get or set text label. + +More documentation in each function. +This module uses DLOG resources 260 and on. +Based upon STDWIN dialogs with the same names and functions. +""" + +from Dlg import GetNewDialog, SetDialogItemText, GetDialogItemText, ModalDialog +import Qd +import QuickDraw +import Dialogs +import Windows +import Dlg,Win,Evt,Events # sdm7g +import Ctl +import Controls +import Menu +import MacOS +import string +from ControlAccessor import * # Also import Controls constants +import macfs + +def cr2lf(text): + if '\r' in text: + text = string.join(string.split(text, '\r'), '\n') + return text + +def lf2cr(text): + if '\n' in text: + text = string.join(string.split(text, '\n'), '\r') + if len(text) > 253: + text = text[:253] + '\311' + return text + +def Message(msg, id=260, ok=None): + """Display a MESSAGE string. + + Return when the user clicks the OK button or presses Return. + + The MESSAGE string can be at most 255 characters long. + """ + + d = GetNewDialog(id, -1) + if not d: + print "Can't get DLOG resource with id =", id + return + h = d.GetDialogItemAsControl(2) + SetDialogItemText(h, lf2cr(msg)) + if ok != None: + h = d.GetDialogItemAsControl(1) + h.SetControlTitle(ok) + d.SetDialogDefaultItem(1) + d.AutoSizeDialog() + d.GetDialogWindow().ShowWindow() + while 1: + n = ModalDialog(None) + if n == 1: + return + + +def AskString(prompt, default = "", id=261, ok=None, cancel=None): + """Display a PROMPT string and a text entry field with a DEFAULT string. + + Return the contents of the text entry field when the user clicks the + OK button or presses Return. + Return None when the user clicks the Cancel button. + + If omitted, DEFAULT is empty. + + The PROMPT and DEFAULT strings, as well as the return value, + can be at most 255 characters long. + """ + + d = GetNewDialog(id, -1) + if not d: + print "Can't get DLOG resource with id =", id + return + h = d.GetDialogItemAsControl(3) + SetDialogItemText(h, lf2cr(prompt)) + h = d.GetDialogItemAsControl(4) + SetDialogItemText(h, lf2cr(default)) + d.SelectDialogItemText(4, 0, 999) +# d.SetDialogItem(4, 0, 255) + if ok != None: + h = d.GetDialogItemAsControl(1) + h.SetControlTitle(ok) + if cancel != None: + h = d.GetDialogItemAsControl(2) + h.SetControlTitle(cancel) + d.SetDialogDefaultItem(1) + d.SetDialogCancelItem(2) + d.AutoSizeDialog() + d.GetDialogWindow().ShowWindow() + while 1: + n = ModalDialog(None) + if n == 1: + h = d.GetDialogItemAsControl(4) + return cr2lf(GetDialogItemText(h)) + if n == 2: return None + +def AskPassword(prompt, default='', id=264, ok=None, cancel=None): + """Display a PROMPT string and a text entry field with a DEFAULT string. + The string is displayed as bullets only. + + Return the contents of the text entry field when the user clicks the + OK button or presses Return. + Return None when the user clicks the Cancel button. + + If omitted, DEFAULT is empty. + + The PROMPT and DEFAULT strings, as well as the return value, + can be at most 255 characters long. + """ + d = GetNewDialog(id, -1) + if not d: + print "Can't get DLOG resource with id =", id + return + h = d.GetDialogItemAsControl(3) + SetDialogItemText(h, lf2cr(prompt)) + pwd = d.GetDialogItemAsControl(4) + bullets = '\245'*len(default) +## SetControlData(pwd, kControlEditTextPart, kControlEditTextTextTag, bullets) + SetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag, default) + d.SelectDialogItemText(4, 0, 999) + Ctl.SetKeyboardFocus(d.GetDialogWindow(), pwd, kControlEditTextPart) + if ok != None: + h = d.GetDialogItemAsControl(1) + h.SetControlTitle(ok) + if cancel != None: + h = d.GetDialogItemAsControl(2) + h.SetControlTitle(cancel) + d.SetDialogDefaultItem(Dialogs.ok) + d.SetDialogCancelItem(Dialogs.cancel) + d.AutoSizeDialog() + d.GetDialogWindow().ShowWindow() + while 1: + n = ModalDialog(None) + if n == 1: + h = d.GetDialogItemAsControl(4) + return cr2lf(GetControlData(pwd, kControlEditTextPart, kControlEditTextPasswordTag)) + if n == 2: return None + +def AskYesNoCancel(question, default = 0, yes=None, no=None, cancel=None, id=262): + """Display a QUESTION string which can be answered with Yes or No. + + Return 1 when the user clicks the Yes button. + Return 0 when the user clicks the No button. + Return -1 when the user clicks the Cancel button. + + When the user presses Return, the DEFAULT value is returned. + If omitted, this is 0 (No). + + The QUESTION string can be at most 255 characters. + """ + + d = GetNewDialog(id, -1) + if not d: + print "Can't get DLOG resource with id =", id + return + # Button assignments: + # 1 = default (invisible) + # 2 = Yes + # 3 = No + # 4 = Cancel + # The question string is item 5 + h = d.GetDialogItemAsControl(5) + SetDialogItemText(h, lf2cr(question)) + if yes != None: + if yes == '': + d.HideDialogItem(2) + else: + h = d.GetDialogItemAsControl(2) + h.SetControlTitle(yes) + if no != None: + if no == '': + d.HideDialogItem(3) + else: + h = d.GetDialogItemAsControl(3) + h.SetControlTitle(no) + if cancel != None: + if cancel == '': + d.HideDialogItem(4) + else: + h = d.GetDialogItemAsControl(4) + h.SetControlTitle(cancel) + d.SetDialogCancelItem(4) + if default == 1: + d.SetDialogDefaultItem(2) + elif default == 0: + d.SetDialogDefaultItem(3) + elif default == -1: + d.SetDialogDefaultItem(4) + d.AutoSizeDialog() + d.GetDialogWindow().ShowWindow() + while 1: + n = ModalDialog(None) + if n == 1: return default + if n == 2: return 1 + if n == 3: return 0 + if n == 4: return -1 + + + + +screenbounds = Qd.qd.screenBits.bounds +screenbounds = screenbounds[0]+4, screenbounds[1]+4, \ + screenbounds[2]-4, screenbounds[3]-4 + + +class ProgressBar: + def __init__(self, title="Working...", maxval=100, label="", id=263): + self.w = None + self.d = None + self.maxval = maxval + self.curval = -1 + self.d = GetNewDialog(id, -1) + self.w = self.d.GetDialogWindow() + self.label(label) + self._update(0) + self.d.AutoSizeDialog() + self.title(title) + self.w.ShowWindow() + self.d.DrawDialog() + + def __del__( self ): + if self.w: + self.w.BringToFront() + self.w.HideWindow() + del self.w + del self.d + + def title(self, newstr=""): + """title(text) - Set title of progress window""" + self.w.BringToFront() + self.w.SetWTitle(newstr) + + def label( self, *newstr ): + """label(text) - Set text in progress box""" + self.w.BringToFront() + if newstr: + self._label = lf2cr(newstr[0]) + text_h = self.d.GetDialogItemAsControl(2) + SetDialogItemText(text_h, self._label) + + def _update(self, value): + maxval = self.maxval + if maxval == 0: + # XXXX Quick fix. Should probably display an unknown duration + value = 0 + maxval = 1 + if maxval > 32767: + value = int(value/(maxval/32767.0)) + maxval = 32767 + progbar = self.d.GetDialogItemAsControl(3) + progbar.SetControlMaximum(maxval) + progbar.SetControlValue(value) + # Test for cancel button + + ready, ev = Evt.WaitNextEvent( Events.mDownMask, 1 ) + if ready : + what,msg,when,where,mod = ev + part = Win.FindWindow(where)[0] + if Dlg.IsDialogEvent(ev): + ds = Dlg.DialogSelect(ev) + if ds[0] and ds[1] == self.d and ds[-1] == 1: + self.w.HideWindow() + self.w = None + self.d = None + raise KeyboardInterrupt, ev + else: + if part == 4: # inDrag + self.d.DragWindow(where, screenbounds) + else: + MacOS.HandleEvent(ev) + + + def set(self, value, max=None): + """set(value) - Set progress bar position""" + if max != None: + self.maxval = max + if value < 0: value = 0 + if value > self.maxval: value = self.maxval + self.curval = value + self._update(value) + + def inc(self, n=1): + """inc(amt) - Increment progress bar position""" + self.set(self.curval + n) + +ARGV_ID=265 +ARGV_ITEM_OK=1 +ARGV_ITEM_CANCEL=2 +ARGV_OPTION_GROUP=3 +ARGV_OPTION_EXPLAIN=4 +ARGV_OPTION_VALUE=5 +ARGV_OPTION_ADD=6 +ARGV_COMMAND_GROUP=7 +ARGV_COMMAND_EXPLAIN=8 +ARGV_COMMAND_ADD=9 +ARGV_ADD_OLDFILE=10 +ARGV_ADD_NEWFILE=11 +ARGV_ADD_FOLDER=12 +ARGV_CMDLINE_GROUP=13 +ARGV_CMDLINE_DATA=14 + +##def _myModalDialog(d): +## while 1: +## ready, ev = Evt.WaitNextEvent(0xffff, -1) +## print 'DBG: WNE', ready, ev +## if ready : +## what,msg,when,where,mod = ev +## part, window = Win.FindWindow(where) +## if Dlg.IsDialogEvent(ev): +## didit, dlgdone, itemdone = Dlg.DialogSelect(ev) +## print 'DBG: DialogSelect', didit, dlgdone, itemdone, d +## if didit and dlgdone == d: +## return itemdone +## elif window == d.GetDialogWindow(): +## d.GetDialogWindow().SelectWindow() +## if part == 4: # inDrag +## d.DragWindow(where, screenbounds) +## else: +## MacOS.HandleEvent(ev) +## else: +## MacOS.HandleEvent(ev) +## +def _setmenu(control, items): + mhandle = control.GetControlData_Handle(Controls.kControlMenuPart, + Controls.kControlPopupButtonMenuHandleTag) + menu = Menu.as_Menu(mhandle) + for item in items: + if type(item) == type(()): + label = item[0] + else: + label = item + if label[-1] == '=' or label[-1] == ':': + label = label[:-1] + menu.AppendMenu(label) +## mhandle, mid = menu.getpopupinfo() +## control.SetControlData_Handle(Controls.kControlMenuPart, +## Controls.kControlPopupButtonMenuHandleTag, mhandle) + control.SetControlMinimum(1) + control.SetControlMaximum(len(items)+1) + +def _selectoption(d, optionlist, idx): + if idx < 0 or idx >= len(optionlist): + MacOS.SysBeep() + return + option = optionlist[idx] + if type(option) == type(()) and \ + len(option) > 1: + help = option[-1] + else: + help = '' + h = d.GetDialogItemAsControl(ARGV_OPTION_EXPLAIN) + Dlg.SetDialogItemText(h, help) + hasvalue = 0 + if type(option) == type(()): + label = option[0] + else: + label = option + if label[-1] == '=' or label[-1] == ':': + hasvalue = 1 + h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE) + Dlg.SetDialogItemText(h, '') + if hasvalue: + d.ShowDialogItem(ARGV_OPTION_VALUE) + d.SelectDialogItemText(ARGV_OPTION_VALUE, 0, 0) + else: + d.HideDialogItem(ARGV_OPTION_VALUE) + + +def GetArgv(optionlist=None, commandlist=None, addoldfile=1, addnewfile=1, addfolder=1, id=ARGV_ID): + d = GetNewDialog(id, -1) + if not d: + print "Can't get DLOG resource with id =", id + return +# h = d.GetDialogItemAsControl(3) +# SetDialogItemText(h, lf2cr(prompt)) +# h = d.GetDialogItemAsControl(4) +# SetDialogItemText(h, lf2cr(default)) +# d.SelectDialogItemText(4, 0, 999) +# d.SetDialogItem(4, 0, 255) + if optionlist: + _setmenu(d.GetDialogItemAsControl(ARGV_OPTION_GROUP), optionlist) + _selectoption(d, optionlist, 0) + else: + d.GetDialogItemAsControl(ARGV_OPTION_GROUP).DeactivateControl() + if commandlist: + _setmenu(d.GetDialogItemAsControl(ARGV_COMMAND_GROUP), commandlist) + if type(commandlist[0]) == type(()) and len(commandlist[0]) > 1: + help = commandlist[0][-1] + h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN) + Dlg.SetDialogItemText(h, help) + else: + d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).DeactivateControl() + if not addoldfile: + d.GetDialogItemAsControl(ARGV_ADD_OLDFILE).DeactivateControl() + if not addnewfile: + d.GetDialogItemAsControl(ARGV_ADD_NEWFILE).DeactivateControl() + if not addfolder: + d.GetDialogItemAsControl(ARGV_ADD_FOLDER).DeactivateControl() + d.SetDialogDefaultItem(ARGV_ITEM_OK) + d.SetDialogCancelItem(ARGV_ITEM_CANCEL) + d.GetDialogWindow().ShowWindow() + d.DrawDialog() + appsw = MacOS.SchedParams(1, 0) + try: + while 1: + stringstoadd = [] + n = ModalDialog(None) + if n == ARGV_ITEM_OK: + break + elif n == ARGV_ITEM_CANCEL: + raise SystemExit + elif n == ARGV_OPTION_GROUP: + idx = d.GetDialogItemAsControl(ARGV_OPTION_GROUP).GetControlValue()-1 + _selectoption(d, optionlist, idx) + elif n == ARGV_OPTION_VALUE: + pass + elif n == ARGV_OPTION_ADD: + idx = d.GetDialogItemAsControl(ARGV_OPTION_GROUP).GetControlValue()-1 + if 0 <= idx < len(optionlist): + option = optionlist[idx] + if type(option) == type(()): + option = option[0] + if option[-1] == '=' or option[-1] == ':': + option = option[:-1] + h = d.GetDialogItemAsControl(ARGV_OPTION_VALUE) + value = Dlg.GetDialogItemText(h) + else: + value = '' + if len(option) == 1: + stringtoadd = '-' + option + else: + stringtoadd = '--' + option + stringstoadd = [stringtoadd] + if value: + stringstoadd.append(value) + else: + MacOS.SysBeep() + elif n == ARGV_COMMAND_GROUP: + idx = d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).GetControlValue()-1 + if 0 <= idx < len(commandlist) and type(commandlist[idx]) == type(()) and \ + len(commandlist[idx]) > 1: + help = commandlist[idx][-1] + h = d.GetDialogItemAsControl(ARGV_COMMAND_EXPLAIN) + Dlg.SetDialogItemText(h, help) + elif n == ARGV_COMMAND_ADD: + idx = d.GetDialogItemAsControl(ARGV_COMMAND_GROUP).GetControlValue()-1 + if 0 <= idx < len(commandlist): + command = commandlist[idx] + if type(command) == type(()): + command = command[0] + stringstoadd = [command] + else: + MacOS.SysBeep() + elif n == ARGV_ADD_OLDFILE: + fss, ok = macfs.StandardGetFile() + if ok: + stringstoadd = [fss.as_pathname()] + elif n == ARGV_ADD_NEWFILE: + fss, ok = macfs.StandardPutFile('') + if ok: + stringstoadd = [fss.as_pathname()] + elif n == ARGV_ADD_FOLDER: + fss, ok = macfs.GetDirectory() + if ok: + stringstoadd = [fss.as_pathname()] + elif n == ARGV_CMDLINE_DATA: + pass # Nothing to do + else: + raise RuntimeError, "Unknown dialog item %d"%n + + for stringtoadd in stringstoadd: + if '"' in stringtoadd or "'" in stringtoadd or " " in stringtoadd: + stringtoadd = `stringtoadd` + h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA) + oldstr = GetDialogItemText(h) + if oldstr and oldstr[-1] != ' ': + oldstr = oldstr + ' ' + oldstr = oldstr + stringtoadd + if oldstr[-1] != ' ': + oldstr = oldstr + ' ' + SetDialogItemText(h, oldstr) + d.SelectDialogItemText(ARGV_CMDLINE_DATA, 0x7fff, 0x7fff) + h = d.GetDialogItemAsControl(ARGV_CMDLINE_DATA) + oldstr = GetDialogItemText(h) + tmplist = string.split(oldstr) + newlist = [] + while tmplist: + item = tmplist[0] + del tmplist[0] + if item[0] == '"': + while item[-1] != '"': + if not tmplist: + raise RuntimeError, "Unterminated quoted argument" + item = item + ' ' + tmplist[0] + del tmplist[0] + item = item[1:-1] + if item[0] == "'": + while item[-1] != "'": + if not tmplist: + raise RuntimeError, "Unterminated quoted argument" + item = item + ' ' + tmplist[0] + del tmplist[0] + item = item[1:-1] + newlist.append(item) + return newlist + finally: + apply(MacOS.SchedParams, appsw) + del d + +def test(): + import time, sys + + Message("Testing EasyDialogs.") + optionlist = (('v', 'Verbose'), ('verbose', 'Verbose as long option'), + ('flags=', 'Valued option'), ('f:', 'Short valued option')) + commandlist = (('start', 'Start something'), ('stop', 'Stop something')) + argv = GetArgv(optionlist=optionlist, commandlist=commandlist, addoldfile=0) + for i in range(len(argv)): + print 'arg[%d] = %s'%(i, `argv[i]`) + print 'Type return to continue - ', + sys.stdin.readline() + ok = AskYesNoCancel("Do you want to proceed?") + ok = AskYesNoCancel("Do you want to identify?", yes="Identify", no="No") + if ok > 0: + s = AskString("Enter your first name", "Joe") + s2 = AskPassword("Okay %s, tell us your nickname"%s, s, cancel="None") + if not s2: + Message("%s has no secret nickname"%s) + else: + Message("Hello everybody!!\nThe secret nickname of %s is %s!!!"%(s, s2)) + text = ( "Working Hard...", "Hardly Working..." , + "So far, so good!", "Keep on truckin'" ) + bar = ProgressBar("Progress, progress...", 100) + try: + appsw = MacOS.SchedParams(1, 0) + for i in range(100): + bar.set(i) + time.sleep(0.1) + if i % 10 == 0: + bar.label(text[(i/10) % 4]) + bar.label("Done.") + time.sleep(0.3) # give'em a chance to see the done. + finally: + del bar + apply(MacOS.SchedParams, appsw) + +if __name__ == '__main__': + try: + test() + except KeyboardInterrupt: + Message("Operation Canceled.") + diff --git a/Mac/Modules/macfsmodule.c b/Mac/Modules/macfsmodule.c new file mode 100644 index 0000000..5e34a64 --- /dev/null +++ b/Mac/Modules/macfsmodule.c @@ -0,0 +1,1266 @@ +/*********************************************************** +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" + +#ifdef WITHOUT_FRAMEWORKS +#include +#include +#include +#include +#include +#include +#else +#include +#endif + +#include "getapplbycreator.h" + + +static PyObject *ErrorObject; + +/* ----------------------------------------------------- */ +/* Declarations for objects of type Alias */ + +typedef struct { + PyObject_HEAD + AliasHandle alias; +} mfsaobject; + +staticforward PyTypeObject Mfsatype; + +#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype) + +/* ---------------------------------------------------------------- */ +/* Declarations for objects of type FSSpec */ + +typedef struct { + PyObject_HEAD + FSSpec fsspec; +} mfssobject; + +staticforward PyTypeObject Mfsstype; + +#define is_mfssobject(v) ((v)->ob_type == &Mfsstype) + +/* ---------------------------------------------------------------- */ +/* Declarations for objects of type FSRef */ + +typedef struct { + PyObject_HEAD + FSRef fsref; +} mfsrobject; + +staticforward PyTypeObject Mfsrtype; + +#define is_mfsrobject(v) ((v)->ob_type == &Mfsrtype) + + +/* ---------------------------------------------------------------- */ +/* Declarations for objects of type FInfo */ + +typedef struct { + PyObject_HEAD + FInfo finfo; +} mfsiobject; + +staticforward PyTypeObject Mfsitype; + +#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype) + + +staticforward mfssobject *newmfssobject(FSSpec *fss); /* Forward */ +staticforward mfsrobject *newmfsrobject(FSRef *fsr); /* Forward */ + +/* ---------------------------------------------------------------- */ + +static PyObject * +mfsa_Resolve(self, args) + mfsaobject *self; + PyObject *args; +{ + FSSpec from, *fromp, result; + Boolean changed; + OSErr err; + + from.name[0] = 0; + if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &from)) + return NULL; + if (from.name[0] ) + fromp = &from; + else + fromp = NULL; + err = ResolveAlias(fromp, self->alias, &result, &changed); + if ( err && err != fnfErr ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return Py_BuildValue("(Oi)", newmfssobject(&result), (int)changed); +} + +static PyObject * +mfsa_GetInfo(self, args) + mfsaobject *self; + PyObject *args; +{ + Str63 value; + int i; + OSErr err; + + if (!PyArg_ParseTuple(args, "i", &i)) + return NULL; + err = GetAliasInfo(self->alias, (AliasInfoType)i, value); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return 0; + } + return PyString_FromStringAndSize((char *)&value[1], value[0]); +} + +static PyObject * +mfsa_Update(self, args) + mfsaobject *self; + PyObject *args; +{ + FSSpec target, fromfile, *fromfilep; + OSErr err; + Boolean changed; + + fromfile.name[0] = 0; + if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetFSSpec, &target, + PyMac_GetFSSpec, &fromfile)) + return NULL; + if ( fromfile.name[0] ) + fromfilep = &fromfile; + else + fromfilep = NULL; + err = UpdateAlias(fromfilep, &target, self->alias, &changed); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return 0; + } + return Py_BuildValue("i", (int)changed); +} + +static struct PyMethodDef mfsa_methods[] = { + {"Resolve", (PyCFunction)mfsa_Resolve, 1}, + {"GetInfo", (PyCFunction)mfsa_GetInfo, 1}, + {"Update", (PyCFunction)mfsa_Update, 1}, + + {NULL, NULL} /* sentinel */ +}; + +/* ---------- */ + +static PyObject * +mfsa_getattr(self, name) + mfsaobject *self; + char *name; +{ + if ( strcmp(name, "data") == 0 ) { + int size; + PyObject *rv; + + size = GetHandleSize((Handle)self->alias); + HLock((Handle)self->alias); + rv = PyString_FromStringAndSize(*(Handle)self->alias, size); + HUnlock((Handle)self->alias); + return rv; + } + return Py_FindMethod(mfsa_methods, (PyObject *)self, name); +} + +static mfsaobject * +newmfsaobject(AliasHandle alias) +{ + mfsaobject *self; + + self = PyObject_NEW(mfsaobject, &Mfsatype); + if (self == NULL) + return NULL; + self->alias = alias; + return self; +} + + +static void +mfsa_dealloc(self) + mfsaobject *self; +{ +#if 0 + if ( self->alias ) { + should we do something here? + } +#endif + + PyMem_DEL(self); +} + +statichere PyTypeObject Mfsatype = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "Alias", /*tp_name*/ + sizeof(mfsaobject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)mfsa_dealloc, /*tp_dealloc*/ + (printfunc)0, /*tp_print*/ + (getattrfunc)mfsa_getattr, /*tp_getattr*/ + (setattrfunc)0, /*tp_setattr*/ + (cmpfunc)0, /*tp_compare*/ + (reprfunc)0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + (hashfunc)0, /*tp_hash*/ +}; + +/* End of code for Alias objects */ +/* -------------------------------------------------------- */ + +/* ---------------------------------------------------------------- */ + +static struct PyMethodDef mfsi_methods[] = { + + {NULL, NULL} /* sentinel */ +}; + +/* ---------- */ + +static mfsiobject * +newmfsiobject() +{ + mfsiobject *self; + + self = PyObject_NEW(mfsiobject, &Mfsitype); + if (self == NULL) + return NULL; + memset((char *)&self->finfo, '\0', sizeof(self->finfo)); + return self; +} + +static void +mfsi_dealloc(self) + mfsiobject *self; +{ + PyMem_DEL(self); +} + +static PyObject * +mfsi_getattr(self, name) + mfsiobject *self; + char *name; +{ + if ( strcmp(name, "Type") == 0 ) + return PyMac_BuildOSType(self->finfo.fdType); + else if ( strcmp(name, "Creator") == 0 ) + return PyMac_BuildOSType(self->finfo.fdCreator); + else if ( strcmp(name, "Flags") == 0 ) + return Py_BuildValue("i", (int)self->finfo.fdFlags); + else if ( strcmp(name, "Location") == 0 ) + return PyMac_BuildPoint(self->finfo.fdLocation); + else if ( strcmp(name, "Fldr") == 0 ) + return Py_BuildValue("i", (int)self->finfo.fdFldr); + else + return Py_FindMethod(mfsi_methods, (PyObject *)self, name); +} + + +static int +mfsi_setattr(self, name, v) + mfsiobject *self; + char *name; + PyObject *v; +{ + int rv; + int i; + + if ( v == NULL ) { + PyErr_SetString(PyExc_AttributeError, "Cannot delete attribute"); + return -1; + } + if ( strcmp(name, "Type") == 0 ) + rv = PyMac_GetOSType(v, &self->finfo.fdType); + else if ( strcmp(name, "Creator") == 0 ) + rv = PyMac_GetOSType(v, &self->finfo.fdCreator); + else if ( strcmp(name, "Flags") == 0 ) { + rv = PyArg_Parse(v, "i", &i); + self->finfo.fdFlags = (short)i; + } else if ( strcmp(name, "Location") == 0 ) + rv = PyMac_GetPoint(v, &self->finfo.fdLocation); + else if ( strcmp(name, "Fldr") == 0 ) { + rv = PyArg_Parse(v, "i", &i); + self->finfo.fdFldr = (short)i; + } else { + PyErr_SetString(PyExc_AttributeError, "No such attribute"); + return -1; + } + if (rv) + return 0; + return -1; +} + + +static PyTypeObject Mfsitype = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "FInfo", /*tp_name*/ + sizeof(mfsiobject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)mfsi_dealloc, /*tp_dealloc*/ + (printfunc)0, /*tp_print*/ + (getattrfunc)mfsi_getattr, /*tp_getattr*/ + (setattrfunc)mfsi_setattr, /*tp_setattr*/ + (cmpfunc)0, /*tp_compare*/ + (reprfunc)0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + (hashfunc)0, /*tp_hash*/ +}; + +/* End of code for FInfo object objects */ +/* -------------------------------------------------------- */ + + +/* +** Helper routines for the FSRef and FSSpec creators in macglue.c +** They return an FSSpec/FSRef if the Python object encapsulating +** either is passed. They return a boolean success indicator. +** Note that they do not set an exception on failure, they're only +** helper routines. +*/ +static int +_mfs_GetFSSpecFromFSSpec(PyObject *self, FSSpec *fssp) +{ + if ( is_mfssobject(self) ) { + *fssp = ((mfssobject *)self)->fsspec; + return 1; + } + return 0; +} + +/* Return an FSSpec if this is an FSref */ +static int +_mfs_GetFSSpecFromFSRef(PyObject *self, FSSpec *fssp) +{ + static FSRef *fsrp; + + if ( is_mfsrobject(self) ) { + fsrp = &((mfsrobject *)self)->fsref; + if ( FSGetCatalogInfo(&((mfsrobject *)self)->fsref, kFSCatInfoNone, NULL, NULL, fssp, NULL) == noErr ) + return 1; + } + return 0; +} + +/* Return an FSRef if this is an FSRef */ +static int +_mfs_GetFSRefFromFSRef(PyObject *self, FSRef *fsrp) +{ + if ( is_mfsrobject(self) ) { + *fsrp = ((mfsrobject *)self)->fsref; + return 1; + } + return 0; +} + +/* Return an FSRef if this is an FSSpec */ +static int +_mfs_GetFSRefFromFSSpec(PyObject *self, FSRef *fsrp) +{ + if ( is_mfssobject(self) ) { + if ( FSpMakeFSRef(&((mfssobject *)self)->fsspec, fsrp) == noErr ) + return 1; + } + return 0; +} + +/* +** Two generally useful routines +*/ +static OSErr +PyMac_GetFileDates(fss, crdat, mddat, bkdat) + FSSpec *fss; + unsigned long *crdat, *mddat, *bkdat; +{ + CInfoPBRec pb; + OSErr error; + + pb.dirInfo.ioNamePtr = fss->name; + pb.dirInfo.ioFDirIndex = 0; + pb.dirInfo.ioVRefNum = fss->vRefNum; + pb.dirInfo.ioDrDirID = fss->parID; + error = PBGetCatInfoSync(&pb); + if ( error ) return error; + *crdat = pb.hFileInfo.ioFlCrDat; + *mddat = pb.hFileInfo.ioFlMdDat; + *bkdat = pb.hFileInfo.ioFlBkDat; + return 0; +} + +static OSErr +PyMac_SetFileDates(fss, crdat, mddat, bkdat) + FSSpec *fss; + unsigned long crdat, mddat, bkdat; +{ + CInfoPBRec pb; + OSErr error; + + pb.dirInfo.ioNamePtr = fss->name; + pb.dirInfo.ioFDirIndex = 0; + pb.dirInfo.ioVRefNum = fss->vRefNum; + pb.dirInfo.ioDrDirID = fss->parID; + error = PBGetCatInfoSync(&pb); + if ( error ) return error; + pb.dirInfo.ioNamePtr = fss->name; + pb.dirInfo.ioFDirIndex = 0; + pb.dirInfo.ioVRefNum = fss->vRefNum; + pb.dirInfo.ioDrDirID = fss->parID; + pb.hFileInfo.ioFlCrDat = crdat; + pb.hFileInfo.ioFlMdDat = mddat; + pb.hFileInfo.ioFlBkDat = bkdat; + error = PBSetCatInfoSync(&pb); + return error; +} + +static PyObject * +mfss_as_pathname(self, args) + mfssobject *self; + PyObject *args; +{ + char strbuf[257]; + OSErr err; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + err = PyMac_GetFullPath(&self->fsspec, strbuf); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return PyString_FromString(strbuf); +} + +static PyObject * +mfss_as_tuple(self, args) + mfssobject *self; + PyObject *args; +{ + if (!PyArg_ParseTuple(args, "")) + return NULL; + return Py_BuildValue("(iis#)", self->fsspec.vRefNum, self->fsspec.parID, + &self->fsspec.name[1], self->fsspec.name[0]); +} + +static PyObject * +mfss_NewAlias(self, args) + mfssobject *self; + PyObject *args; +{ + FSSpec src, *srcp; + OSErr err; + AliasHandle alias; + + src.name[0] = 0; + if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &src)) + return NULL; + if ( src.name[0] ) + srcp = &src; + else + srcp = NULL; + err = NewAlias(srcp, &self->fsspec, &alias); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + + return (PyObject *)newmfsaobject(alias); +} + +static PyObject * +mfss_NewAliasMinimal(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + AliasHandle alias; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + err = NewAliasMinimal(&self->fsspec, &alias); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return (PyObject *)newmfsaobject(alias); +} + +static PyObject * +mfss_FSpMakeFSRef(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + FSRef fsref; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + err = FSpMakeFSRef(&self->fsspec, &fsref); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return (PyObject *)newmfsrobject(&fsref); +} + +/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */ +static PyObject * +mfss_GetCreatorType(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + FInfo info; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + err = FSpGetFInfo(&self->fsspec, &info); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return Py_BuildValue("(O&O&)", + PyMac_BuildOSType, info.fdCreator, PyMac_BuildOSType, info.fdType); +} + +static PyObject * +mfss_SetCreatorType(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + OSType creator, type; + FInfo info; + + if (!PyArg_ParseTuple(args, "O&O&", PyMac_GetOSType, &creator, PyMac_GetOSType, &type)) + return NULL; + err = FSpGetFInfo(&self->fsspec, &info); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + info.fdType = type; + info.fdCreator = creator; + err = FSpSetFInfo(&self->fsspec, &info); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +mfss_GetFInfo(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + mfsiobject *fip; + + + if (!PyArg_ParseTuple(args, "")) + return NULL; + if ( (fip=newmfsiobject()) == NULL ) + return NULL; + err = FSpGetFInfo(&self->fsspec, &fip->finfo); + if ( err ) { + PyErr_Mac(ErrorObject, err); + Py_DECREF(fip); + return NULL; + } + return (PyObject *)fip; +} + +static PyObject * +mfss_SetFInfo(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + mfsiobject *fip; + + if (!PyArg_ParseTuple(args, "O!", &Mfsitype, &fip)) + return NULL; + err = FSpSetFInfo(&self->fsspec, &fip->finfo); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + +static PyObject * +mfss_GetDates(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + unsigned long crdat, mddat, bkdat; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + err = PyMac_GetFileDates(&self->fsspec, &crdat, &mddat, &bkdat); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return Py_BuildValue("ddd", (double)crdat, (double)mddat, (double)bkdat); +} + +static PyObject * +mfss_SetDates(self, args) + mfssobject *self; + PyObject *args; +{ + OSErr err; + double crdat, mddat, bkdat; + + if (!PyArg_ParseTuple(args, "ddd", &crdat, &mddat, &bkdat)) + return NULL; + err = PyMac_SetFileDates(&self->fsspec, (unsigned long)crdat, + (unsigned long)mddat, (unsigned long)bkdat); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + Py_INCREF(Py_None); + return Py_None; +} + +static struct PyMethodDef mfss_methods[] = { + {"as_pathname", (PyCFunction)mfss_as_pathname, 1}, + {"as_tuple", (PyCFunction)mfss_as_tuple, 1}, + {"as_fsref", (PyCFunction)mfss_FSpMakeFSRef, 1}, + {"FSpMakeFSRef", (PyCFunction)mfss_FSpMakeFSRef, 1}, + {"NewAlias", (PyCFunction)mfss_NewAlias, 1}, + {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1}, + {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1}, + {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1}, + {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1}, + {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1}, + {"GetDates", (PyCFunction)mfss_GetDates, 1}, + {"SetDates", (PyCFunction)mfss_SetDates, 1}, + + {NULL, NULL} /* sentinel */ +}; + +/* ---------- */ + +static PyObject * +mfss_getattr(self, name) + mfssobject *self; + char *name; +{ + if ( strcmp(name, "data") == 0) + return PyString_FromStringAndSize((char *)&self->fsspec, sizeof(FSSpec)); + return Py_FindMethod(mfss_methods, (PyObject *)self, name); +} + +mfssobject * +newmfssobject(fss) + FSSpec *fss; +{ + mfssobject *self; + + self = PyObject_NEW(mfssobject, &Mfsstype); + if (self == NULL) + return NULL; + self->fsspec = *fss; + return self; +} + +static void +mfss_dealloc(self) + mfssobject *self; +{ + PyMem_DEL(self); +} + +static PyObject * +mfss_repr(self) + mfssobject *self; +{ + char buf[512]; + + sprintf(buf, "FSSpec((%d, %d, '%.*s'))", + self->fsspec.vRefNum, + self->fsspec.parID, + self->fsspec.name[0], self->fsspec.name+1); + return PyString_FromString(buf); +} + +static int +mfss_compare(v, w) + mfssobject *v, *w; +{ + int minlen; + int res; + + if ( v->fsspec.vRefNum < w->fsspec.vRefNum ) return -1; + if ( v->fsspec.vRefNum > w->fsspec.vRefNum ) return 1; + if ( v->fsspec.parID < w->fsspec.parID ) return -1; + if ( v->fsspec.parID > w->fsspec.parID ) return 1; + minlen = v->fsspec.name[0]; + if ( w->fsspec.name[0] < minlen ) minlen = w->fsspec.name[0]; + res = strncmp((char *)v->fsspec.name+1, (char *)w->fsspec.name+1, minlen); + if ( res ) return res; + if ( v->fsspec.name[0] < w->fsspec.name[0] ) return -1; + if ( v->fsspec.name[0] > w->fsspec.name[0] ) return 1; + return res; +} + +statichere PyTypeObject Mfsstype = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "FSSpec", /*tp_name*/ + sizeof(mfssobject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)mfss_dealloc, /*tp_dealloc*/ + (printfunc)0, /*tp_print*/ + (getattrfunc)mfss_getattr, /*tp_getattr*/ + (setattrfunc)0, /*tp_setattr*/ + (cmpfunc)mfss_compare, /*tp_compare*/ + (reprfunc)mfss_repr, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + (hashfunc)0, /*tp_hash*/ +}; + +/* End of code for FSSpec objects */ +/* -------------------------------------------------------- */ + +static PyObject * +mfsr_as_fsspec(self, args) + mfsrobject *self; + PyObject *args; +{ + OSErr err; + FSSpec fss; + + if (!PyArg_ParseTuple(args, "")) + return NULL; + err = FSGetCatalogInfo(&self->fsref, kFSCatInfoNone, NULL, NULL, &fss, NULL); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + Py_INCREF(Py_None); + return (PyObject *)newmfssobject(&fss); +} + +static struct PyMethodDef mfsr_methods[] = { + {"as_fsspec", (PyCFunction)mfsr_as_fsspec, 1}, +#if 0 + {"as_pathname", (PyCFunction)mfss_as_pathname, 1}, + {"as_tuple", (PyCFunction)mfss_as_tuple, 1}, + {"NewAlias", (PyCFunction)mfss_NewAlias, 1}, + {"NewAliasMinimal", (PyCFunction)mfss_NewAliasMinimal, 1}, + {"GetCreatorType", (PyCFunction)mfss_GetCreatorType, 1}, + {"SetCreatorType", (PyCFunction)mfss_SetCreatorType, 1}, + {"GetFInfo", (PyCFunction)mfss_GetFInfo, 1}, + {"SetFInfo", (PyCFunction)mfss_SetFInfo, 1}, + {"GetDates", (PyCFunction)mfss_GetDates, 1}, + {"SetDates", (PyCFunction)mfss_SetDates, 1}, +#endif + + {NULL, NULL} /* sentinel */ +}; + +/* ---------- */ + +static PyObject * +mfsr_getattr(self, name) + mfsrobject *self; + char *name; +{ + if ( strcmp(name, "data") == 0) + return PyString_FromStringAndSize((char *)&self->fsref, sizeof(FSRef)); + return Py_FindMethod(mfsr_methods, (PyObject *)self, name); +} + +mfsrobject * +newmfsrobject(fsr) + FSRef *fsr; +{ + mfsrobject *self; + + self = PyObject_NEW(mfsrobject, &Mfsrtype); + if (self == NULL) + return NULL; + self->fsref = *fsr; + return self; +} + +static int +mfsr_compare(v, w) + mfsrobject *v, *w; +{ + OSErr err; + + if ( v == w ) return 0; + err = FSCompareFSRefs(&v->fsref, &w->fsref); + if ( err == 0 ) + return 0; + if (v < w ) + return -1; + return 1; +} + +static void +mfsr_dealloc(self) + mfsrobject *self; +{ + PyMem_DEL(self); +} + +statichere PyTypeObject Mfsrtype = { + PyObject_HEAD_INIT(&PyType_Type) + 0, /*ob_size*/ + "FSRef", /*tp_name*/ + sizeof(mfsrobject), /*tp_basicsize*/ + 0, /*tp_itemsize*/ + /* methods */ + (destructor)mfsr_dealloc, /*tp_dealloc*/ + (printfunc)0, /*tp_print*/ + (getattrfunc)mfsr_getattr, /*tp_getattr*/ + (setattrfunc)0, /*tp_setattr*/ + (cmpfunc)mfsr_compare, /*tp_compare*/ + (reprfunc)0, /*tp_repr*/ + 0, /*tp_as_number*/ + 0, /*tp_as_sequence*/ + 0, /*tp_as_mapping*/ + (hashfunc)0, /*tp_hash*/ +}; + +/* End of code for FSRef objects */ +/* -------------------------------------------------------- */ + +static PyObject * +mfs_ResolveAliasFile(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + FSSpec fss; + Boolean chain = 1, isfolder, wasaliased; + OSErr err; + + if (!PyArg_ParseTuple(args, "O&|i", PyMac_GetFSSpec, &fss, &chain)) + return NULL; + err = ResolveAliasFile(&fss, chain, &isfolder, &wasaliased); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return Py_BuildValue("Oii", newmfssobject(&fss), (int)isfolder, (int)wasaliased); +} + +#if !TARGET_API_MAC_CARBON +static PyObject * +mfs_StandardGetFile(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + SFTypeList list; + short numtypes; + StandardFileReply reply; + + list[0] = list[1] = list[2] = list[3] = 0; + numtypes = 0; + if (!PyArg_ParseTuple(args, "|O&O&O&O&", PyMac_GetOSType, &list[0], + PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], + PyMac_GetOSType, &list[3]) ) + return NULL; + while ( numtypes < 4 && list[numtypes] ) { + numtypes++; + } + if ( numtypes == 0 ) + numtypes = -1; + StandardGetFile((FileFilterUPP)0, numtypes, list, &reply); + return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); +} + +static PyObject * +mfs_PromptGetFile(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + SFTypeList list; + short numtypes; + StandardFileReply reply; + char *prompt = NULL; + + list[0] = list[1] = list[2] = list[3] = 0; + numtypes = 0; + if (!PyArg_ParseTuple(args, "s|O&O&O&O&", &prompt, PyMac_GetOSType, &list[0], + PyMac_GetOSType, &list[1], PyMac_GetOSType, &list[2], + PyMac_GetOSType, &list[3]) ) + return NULL; + while ( numtypes < 4 && list[numtypes] ) { + numtypes++; + } + if ( numtypes == 0 ) + numtypes = -1; + PyMac_PromptGetFile(numtypes, list, &reply, prompt); + return Py_BuildValue("(Oi)", newmfssobject(&reply.sfFile), reply.sfGood); +} + +static PyObject * +mfs_StandardPutFile(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + Str255 prompt, dft; + StandardFileReply reply; + + dft[0] = 0; + if (!PyArg_ParseTuple(args, "O&|O&", PyMac_GetStr255, &prompt, PyMac_GetStr255, &dft) ) + return NULL; + StandardPutFile(prompt, dft, &reply); + return Py_BuildValue("(Oi)",newmfssobject(&reply.sfFile), reply.sfGood); +} + +/* +** Set initial directory for file dialogs */ +static PyObject * +mfs_SetFolder(self, args) + PyObject *self; + PyObject *args; +{ + FSSpec spec; + FSSpec ospec; + short orefnum; + long oparid; + + /* Get old values */ + orefnum = -LMGetSFSaveDisk(); + oparid = LMGetCurDirStore(); + (void)FSMakeFSSpec(orefnum, oparid, "\pplaceholder", &ospec); + + /* Go to working directory by default */ + (void)FSMakeFSSpec(0, 0, "\p:placeholder", &spec); + if (!PyArg_ParseTuple(args, "|O&", PyMac_GetFSSpec, &spec)) + return NULL; + /* Set standard-file working directory */ + LMSetSFSaveDisk(-spec.vRefNum); + LMSetCurDirStore(spec.parID); + return (PyObject *)newmfssobject(&ospec); +} +#endif + +static PyObject * +mfs_FSSpec(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + FSSpec fss; + + if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSSpec, &fss)) + return NULL; + return (PyObject *)newmfssobject(&fss); +} + +static PyObject * +mfs_FSRef(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + FSRef fsr; + + if (!PyArg_ParseTuple(args, "O&", PyMac_GetFSRef, &fsr)) + return NULL; + return (PyObject *)newmfsrobject(&fsr); +} + +static PyObject * +mfs_RawFSSpec(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + FSSpec *fssp; + int size; + + if (!PyArg_ParseTuple(args, "s#", &fssp, &size)) + return NULL; + if ( size != sizeof(FSSpec) ) { + PyErr_SetString(PyExc_TypeError, "Incorrect size for FSSpec record"); + return NULL; + } + return (PyObject *)newmfssobject(fssp); +} + +static PyObject * +mfs_RawAlias(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + char *dataptr; + Handle h; + int size; + + if (!PyArg_ParseTuple(args, "s#", &dataptr, &size)) + return NULL; + h = NewHandle(size); + if ( h == NULL ) { + PyErr_NoMemory(); + return NULL; + } + HLock(h); + memcpy((char *)*h, dataptr, size); + HUnlock(h); + return (PyObject *)newmfsaobject((AliasHandle)h); +} + +#if !TARGET_API_MAC_CARBON +static PyObject * +mfs_GetDirectory(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + FSSpec fsdir; + int ok; + char *prompt = NULL; + + if (!PyArg_ParseTuple(args, "|s", &prompt) ) + return NULL; + + ok = PyMac_GetDirectory(&fsdir, prompt); + return Py_BuildValue("(Oi)", newmfssobject(&fsdir), ok); +} +#endif + +static PyObject * +mfs_FindFolder(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + OSErr err; + short where; + OSType which; + int create; + short refnum; + long dirid; + + if (!PyArg_ParseTuple(args, "hO&i", &where, PyMac_GetOSType, &which, &create) ) + return NULL; + err = FindFolder(where, which, (Boolean)create, &refnum, &dirid); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return Py_BuildValue("(ii)", refnum, dirid); +} + +static PyObject * +mfs_FindApplication(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + OSErr err; + OSType which; + FSSpec fss; + + if (!PyArg_ParseTuple(args, "O&", PyMac_GetOSType, &which) ) + return NULL; + err = FindApplicationFromCreator(which, &fss); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return (PyObject *)newmfssobject(&fss); +} + +static PyObject * +mfs_FInfo(self, args) + PyObject *self; + PyObject *args; +{ + return (PyObject *)newmfsiobject(); +} + +static PyObject * +mfs_NewAliasMinimalFromFullPath(self, args) + PyObject *self; /* Not used */ + PyObject *args; +{ + OSErr err; + char *fullpath; + int fullpathlen; + AliasHandle alias; + Str32 zonename; + Str31 servername; + + if (!PyArg_ParseTuple(args, "s#", &fullpath, &fullpathlen) ) + return NULL; + zonename[0] = 0; + servername[0] = 0; + err = NewAliasMinimalFromFullPath(fullpathlen, (Ptr)fullpath, zonename, + servername, &alias); + if ( err ) { + PyErr_Mac(ErrorObject, err); + return NULL; + } + return (PyObject *)newmfsaobject(alias); +} + + +/* List of methods defined in the module */ + +static struct PyMethodDef mfs_methods[] = { + {"ResolveAliasFile", mfs_ResolveAliasFile, 1}, +#if !TARGET_API_MAC_CARBON + {"StandardGetFile", mfs_StandardGetFile, 1}, + {"PromptGetFile", mfs_PromptGetFile, 1}, + {"StandardPutFile", mfs_StandardPutFile, 1}, + {"GetDirectory", mfs_GetDirectory, 1}, + {"SetFolder", mfs_SetFolder, 1}, +#endif + {"FSSpec", mfs_FSSpec, 1}, + {"FSRef", mfs_FSRef, 1}, + {"RawFSSpec", mfs_RawFSSpec, 1}, + {"RawAlias", mfs_RawAlias, 1}, + {"FindFolder", mfs_FindFolder, 1}, + {"FindApplication", mfs_FindApplication, 1}, + {"FInfo", mfs_FInfo, 1}, + {"NewAliasMinimalFromFullPath", mfs_NewAliasMinimalFromFullPath, 1}, + + {NULL, NULL} /* sentinel */ +}; + +/* +** Convert a Python object to an FSSpec. +** The object may either be a full pathname, an FSSpec, an FSRef or a triple +** (vrefnum, dirid, path). +*/ +int +PyMac_GetFSRef(PyObject *v, FSRef *fsr) +{ + OSErr err; + + /* If it's an FSRef we're also okay. */ + if (_mfs_GetFSRefFromFSRef(v, fsr)) + return 1; + /* first check whether it already is an FSSpec */ + if ( _mfs_GetFSRefFromFSSpec(v, fsr) ) + return 1; + if ( PyString_Check(v) ) { + PyErr_SetString(PyExc_NotImplementedError, "Cannot create an FSRef from a pathname on this platform"); + return 0; + } + PyErr_SetString(PyExc_TypeError, "FSRef argument should be existing FSRef, FSSpec or (OSX only) pathname"); + return 0; +} + +/* Convert FSSpec to PyObject */ +PyObject *PyMac_BuildFSRef(FSRef *v) +{ + return (PyObject *)newmfsrobject(v); +} + +/* +** Convert a Python object to an FSRef. +** The object may either be a full pathname (OSX only), an FSSpec or an FSRef. +*/ +int +PyMac_GetFSSpec(PyObject *v, FSSpec *fs) +{ + Str255 path; + short refnum; + long parid; + OSErr err; + + /* first check whether it already is an FSSpec */ + if ( _mfs_GetFSSpecFromFSSpec(v, fs) ) + return 1; + /* If it's an FSRef we're also okay. */ + if (_mfs_GetFSSpecFromFSRef(v, fs)) + return 1; + if ( PyString_Check(v) ) { + /* It's a pathname */ + if( !PyArg_Parse(v, "O&", PyMac_GetStr255, &path) ) + return 0; + refnum = 0; /* XXXX Should get CurWD here?? */ + parid = 0; + } else { + if( !PyArg_Parse(v, "(hlO&); FSSpec should be FSSpec, FSRef, fullpath or (vrefnum,dirid,path)", + &refnum, &parid, PyMac_GetStr255, &path)) { + return 0; + } + } + err = FSMakeFSSpec(refnum, parid, path, fs); + if ( err && err != fnfErr ) { + PyMac_Error(err); + return 0; + } + return 1; +} + +/* Convert FSSpec to PyObject */ +PyObject *PyMac_BuildFSSpec(FSSpec *v) +{ + return (PyObject *)newmfssobject(v); +} + +/* Initialization function for the module (*must* be called initmacfs) */ + +void +initmacfs() +{ + PyObject *m, *d; + + /* Create the module and add the functions */ + m = Py_InitModule("macfs", mfs_methods); + + /* Add some symbolic constants to the module */ + d = PyModule_GetDict(m); + ErrorObject = PyMac_GetOSErrException(); + PyDict_SetItemString(d, "error", ErrorObject); + + Mfsatype.ob_type = &PyType_Type; + Py_INCREF(&Mfsatype); + PyDict_SetItemString(d, "AliasType", (PyObject *)&Mfsatype); + Mfsstype.ob_type = &PyType_Type; + Py_INCREF(&Mfsstype); + PyDict_SetItemString(d, "FSSpecType", (PyObject *)&Mfsstype); + Mfsitype.ob_type = &PyType_Type; + Py_INCREF(&Mfsitype); + PyDict_SetItemString(d, "FInfoType", (PyObject *)&Mfsitype); + /* XXXX Add constants here */ +} diff --git a/Mac/Python/macimport.c b/Mac/Python/macimport.c new file mode 100644 index 0000000..b47a694 --- /dev/null +++ b/Mac/Python/macimport.c @@ -0,0 +1,492 @@ +/*********************************************************** +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 "pythonresources.h" + +#include +#include +#include +#if 0 +#include /* for Set(Current)A5 */ +#include +#include +#include +#include +#include +#include +#include +#include +#endif +#include +#include + +#ifdef USE_GUSI1 +#include "TFileSpec.h" /* for Path2FSSpec() */ +#endif + +typedef void (*dl_funcptr)(); +#define FUNCNAME_PATTERN "init%.200s" + +static int +fssequal(FSSpec *fs1, FSSpec *fs2) +{ + if ( fs1->vRefNum != fs2->vRefNum || fs1->parID != fs2->parID ) + return 0; + return EqualString(fs1->name, fs2->name, false, true); +} +/* +** findnamedresource - Common code for the various *ResourceModule functions. +** Check whether a file contains a resource of the correct name and type, and +** optionally return the value in it. +*/ +static int +findnamedresource( + PyStringObject *obj, + char *module, + char *filename, + OSType restype, + StringPtr dataptr) +{ + FSSpec fss; + FInfo finfo; + short oldrh, filerh; + int ok; + Handle h; + +#ifdef INTERN_STRINGS + /* + ** If we have interning find_module takes care of interning all + ** sys.path components. We then keep a record of all sys.path + ** components for which GetFInfo has failed (usually because the + ** component in question is a folder), and we don't try opening these + ** as resource files again. + */ +#define MAXPATHCOMPONENTS 32 + static PyStringObject *not_a_file[MAXPATHCOMPONENTS]; + static int max_not_a_file = 0; + int i; + + if (obj && obj->ob_sinterned ) { + for( i=0; i< max_not_a_file; i++ ) + if ( obj == not_a_file[i] ) + return 0; + } +#endif /* INTERN_STRINGS */ +#ifdef USE_GUSI1 + if ( Path2FSSpec(filename, &fss) != noErr ) { +#else + if ( FSMakeFSSpec(0, 0, Pstring(filename), &fss) != noErr ) { +#endif +#ifdef INTERN_STRINGS + if ( obj && max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned ) + not_a_file[max_not_a_file++] = obj; +#endif /* INTERN_STRINGS */ + /* doesn't exist or is folder */ + return 0; + } + if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) { + /* + ** Special case: the application itself. Use a shortcut to + ** forestall opening and closing the application numerous times + ** (which is dead slow when running from CDROM) + */ + oldrh = CurResFile(); + UseResFile(PyMac_AppRefNum); + filerh = -1; + } else { +#ifdef INTERN_STRINGS + if ( FSpGetFInfo(&fss, &finfo) != noErr ) { + if ( obj && max_not_a_file < MAXPATHCOMPONENTS && obj->ob_sinterned ) + not_a_file[max_not_a_file++] = obj; + /* doesn't exist or is folder */ + return 0; + } +#endif /* INTERN_STRINGS */ + oldrh = CurResFile(); + filerh = FSpOpenResFile(&fss, fsRdPerm); + if ( filerh == -1 ) + return 0; + UseResFile(filerh); + } + if ( dataptr == NULL ) + SetResLoad(0); + h = Get1NamedResource(restype, Pstring(module)); + SetResLoad(1); + ok = (h != NULL); + if ( ok && dataptr != NULL ) { + HLock(h); + /* XXXX Unsafe if resource not correctly formatted! */ +#ifdef __CFM68K__ + /* for cfm68k we take the second pstring */ + *dataptr = *((*h)+(**h)+1); + memcpy(dataptr+1, (*h)+(**h)+2, (int)*dataptr); +#else + /* for ppc we take the first pstring */ + *dataptr = **h; + memcpy(dataptr+1, (*h)+1, (int)*dataptr); +#endif + HUnlock(h); + } + if ( filerh != -1 ) + CloseResFile(filerh); + UseResFile(oldrh); + return ok; +} + +/* +** Returns true if the argument has a resource fork, and it contains +** a 'PYC ' resource of the correct name +*/ +int +PyMac_FindResourceModule(obj, module, filename) +PyStringObject *obj; +char *module; +char *filename; +{ + int ok; + + ok = findnamedresource(obj, module, filename, 'PYC ', (StringPtr)0); + return ok; +} + +/* +** Returns true if the argument has a resource fork, and it contains +** a 'PYD ' resource of the correct name +*/ +int +PyMac_FindCodeResourceModule(obj, module, filename) +PyStringObject *obj; +char *module; +char *filename; +{ + int ok; + + ok = findnamedresource(obj, module, filename, 'PYD ', (StringPtr)0); + return ok; +} + + +/* +** Load the specified module from a code resource +*/ +PyObject * +PyMac_LoadCodeResourceModule(name, pathname) + char *name; + char *pathname; +{ + PyObject *m, *d, *s; + char funcname[258]; + char *lastdot, *shortname, *packagecontext; + dl_funcptr p = NULL; + Str255 fragmentname; + CFragConnectionID connID; + Ptr mainAddr; + Str255 errMessage; + OSErr err; + char buf[512]; + Ptr symAddr; + CFragSymbolClass class; + + if ((m = _PyImport_FindExtension(name, name)) != NULL) { + Py_INCREF(m); + return m; + } + lastdot = strrchr(name, '.'); + if (lastdot == NULL) { + packagecontext = NULL; + shortname = name; + } + else { + packagecontext = name; + shortname = lastdot+1; + } + sprintf(funcname, FUNCNAME_PATTERN, shortname); + if( !findnamedresource((PyStringObject *)0, name, pathname, 'PYD ', fragmentname)) { + PyErr_SetString(PyExc_ImportError, "PYD resource not found"); + return NULL; + } + + /* Load the fragment + (or return the connID if it is already loaded */ + err = GetSharedLibrary(fragmentname, kCompiledCFragArch, + kLoadCFrag, &connID, &mainAddr, + errMessage); + if ( err ) { + sprintf(buf, "%.*s: %.200s", + errMessage[0], errMessage+1, + PyMac_StrError(err)); + PyErr_SetString(PyExc_ImportError, buf); + return NULL; + } + /* Locate the address of the correct init function */ + err = FindSymbol(connID, Pstring(funcname), &symAddr, &class); + if ( err ) { + sprintf(buf, "%s: %.200s", + funcname, PyMac_StrError(err)); + PyErr_SetString(PyExc_ImportError, buf); + return NULL; + } + p = (dl_funcptr)symAddr; + if (p == NULL) { + PyErr_Format(PyExc_ImportError, + "dynamic module does not define init function (%.200s)", + funcname); + return NULL; + } + _Py_PackageContext = packagecontext; + (*p)(); + _Py_PackageContext = NULL; + if (PyErr_Occurred()) + return NULL; + if (_PyImport_FixupExtension(name, name) == NULL) + return NULL; + + m = PyDict_GetItemString(PyImport_GetModuleDict(), name); + if (m == NULL) { + PyErr_SetString(PyExc_SystemError, + "dynamic module not initialized properly"); + return NULL; + } +#if 1 + /* Remember the filename as the __file__ attribute */ + d = PyModule_GetDict(m); + s = PyString_FromString(pathname); + if (s == NULL || PyDict_SetItemString(d, "__file__", s) != 0) + PyErr_Clear(); /* Not important enough to report */ + Py_XDECREF(s); +#endif + if (Py_VerboseFlag) + PySys_WriteStderr("import %s # pyd fragment %#s loaded from %s\n", + name, fragmentname, pathname); + Py_INCREF(m); + return m; +} + +/* +** Load the specified module from a resource +*/ +PyObject * +PyMac_LoadResourceModule(module, filename) +char *module; +char *filename; +{ + FSSpec fss; + FInfo finfo; + short oldrh, filerh; + Handle h; + OSErr err; + PyObject *m, *co; + long num, size; + +#ifdef USE_GUSI1 + if ( (err=Path2FSSpec(filename, &fss)) != noErr || + FSpGetFInfo(&fss, &finfo) != noErr ) +#else + if ( (err=FSMakeFSSpec(0, 0, Pstring(filename), &fss)) != noErr ) +#endif + goto error; + if ( fssequal(&fss, &PyMac_ApplicationFSSpec) ) { + /* + ** Special case: the application itself. Use a shortcut to + ** forestall opening and closing the application numerous times + ** (which is dead slow when running from CDROM) + */ + oldrh = CurResFile(); + UseResFile(PyMac_AppRefNum); + filerh = -1; + } else { + if ( (err=FSpGetFInfo(&fss, &finfo)) != noErr ) + goto error; + oldrh = CurResFile(); + filerh = FSpOpenResFile(&fss, fsRdPerm); + if ( filerh == -1 ) { + err = ResError(); + goto error; + } + UseResFile(filerh); + } + h = Get1NamedResource('PYC ', Pstring(module)); + if ( h == NULL ) { + err = ResError(); + goto error; + } + HLock(h); + /* + ** XXXX The next few lines are intimately tied to the format of pyc + ** files. I'm not sure whether this code should be here or in import.c -- Jack + */ + size = GetHandleSize(h); + if ( size < 8 ) { + PyErr_SetString(PyExc_ImportError, "Resource too small"); + co = NULL; + } else { + num = (*h)[0] & 0xff; + num = num | (((*h)[1] & 0xff) << 8); + num = num | (((*h)[2] & 0xff) << 16); + num = num | (((*h)[3] & 0xff) << 24); + if ( num != PyImport_GetMagicNumber() ) { + PyErr_SetString(PyExc_ImportError, "Bad MAGIC in resource"); + co = NULL; + } else { + co = PyMarshal_ReadObjectFromString((*h)+8, size-8); + /* + ** Normally, byte 4-7 are the time stamp, but that is not used + ** for 'PYC ' resources. We abuse byte 4 as a flag to indicate + ** that it is a package rather than an ordinary module. + ** See also py_resource.py. (jvr) + */ + if ((*h)[4] & 0xff) { + /* it's a package */ + /* Set __path__ to the package name */ + PyObject *d, *s; + int err; + + m = PyImport_AddModule(module); + if (m == NULL) { + co = NULL; + goto packageerror; + } + d = PyModule_GetDict(m); + s = PyString_InternFromString(module); + if (s == NULL) { + co = NULL; + goto packageerror; + } + err = PyDict_SetItemString(d, "__path__", s); + Py_DECREF(s); + if (err != 0) { + co = NULL; + goto packageerror; + } + } + } + } +packageerror: + HUnlock(h); + if ( filerh != -1 ) + CloseResFile(filerh); + else + ReleaseResource(h); + UseResFile(oldrh); + if ( co ) { + m = PyImport_ExecCodeModuleEx(module, co, ""); + Py_DECREF(co); + } else { + m = NULL; + } + if (Py_VerboseFlag) + PySys_WriteStderr("import %s # pyc resource from %s\n", + module, filename); + return m; +error: + { + char buf[512]; + + sprintf(buf, "%s: %s", filename, PyMac_StrError(err)); + PyErr_SetString(PyExc_ImportError, buf); + return NULL; + } +} + +/* +** Look for a module in a single folder. Upon entry buf and len +** point to the folder to search, upon exit they refer to the full +** pathname of the module found (if any). +*/ +struct filedescr * +PyMac_FindModuleExtension(char *buf, size_t *lenp, char *module) +{ + struct filedescr *fdp; + unsigned char fnbuf[64]; + int modnamelen = strlen(module); + FSSpec fss; +#ifdef USE_GUSI1 + FInfo finfo; +#endif + short refnum; + long dirid; + + /* + ** Copy the module name to the buffer (already :-terminated) + ** We also copy the first suffix, if this matches immedeately we're + ** lucky and return immedeately. + */ + if ( !_PyImport_Filetab[0].suffix ) + return 0; + +#if 0 + /* Pre 1.5a4 */ + strcpy(buf+*lenp, module); + strcpy(buf+*lenp+modnamelen, _PyImport_Filetab[0].suffix); +#else + strcpy(buf+*lenp, _PyImport_Filetab[0].suffix); +#endif +#ifdef USE_GUSI1 + if ( Path2FSSpec(buf, &fss) == noErr && + FSpGetFInfo(&fss, &finfo) == noErr) + return _PyImport_Filetab; +#else + if ( FSMakeFSSpec(0, 0, Pstring(buf), &fss) == noErr ) + return _PyImport_Filetab; +#endif + /* + ** We cannot check for fnfErr (unfortunately), it can mean either that + ** the file doesn't exist (fine, we try others) or the path leading to it. + */ + refnum = fss.vRefNum; + dirid = fss.parID; + if ( refnum == 0 || dirid == 0 ) /* Fail on nonexistent dir */ + return 0; + /* + ** We now have the folder parameters. Setup the field for the filename + */ + if ( modnamelen > 54 ) return 0; /* Leave room for extension */ + strcpy((char *)fnbuf+1, module); + + for( fdp = _PyImport_Filetab+1; fdp->suffix; fdp++ ) { + strcpy((char *)fnbuf+1+modnamelen, fdp->suffix); + fnbuf[0] = strlen((char *)fnbuf+1); + if (Py_VerboseFlag > 1) + PySys_WriteStderr("# trying %s%s\n", buf, fdp->suffix); + if ( FSMakeFSSpec(refnum, dirid, fnbuf, &fss) == noErr ) { + /* Found it. */ +#if 0 + strcpy(buf+*lenp+modnamelen, fdp->suffix); +#else + strcpy(buf+*lenp, fdp->suffix); +#endif + *lenp = strlen(buf); + return fdp; + } + } + return 0; +} diff --git a/Mac/Python/macmain.c b/Mac/Python/macmain.c new file mode 100644 index 0000000..10c5a5f --- /dev/null +++ b/Mac/Python/macmain.c @@ -0,0 +1,672 @@ +/*********************************************************** +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. + +******************************************************************/ + +/* Python interpreter main program */ + +#include "Python.h" +#include "pythonresources.h" +#include "import.h" +#include "marshal.h" +#include "macglue.h" + +#include +#include +#include +#include +#include +#include +#include +#ifdef USE_APPEARANCE +#include +#include +#endif /* USE_APPEARANCE */ +#ifdef __MWERKS__ +#include +#define USE_SIOUX +extern int ccommand(char ***); +#if __profile__ == 1 +#include +#endif +#endif +#include +#ifdef USE_MAC_SHARED_LIBRARY +extern PyMac_AddLibResources(void); +#endif +//#ifdef USE_GUSI +//#include "GUSISIOUX.h" +//#endif + +#define STARTUP "PythonStartup" + +#define COPYRIGHT \ + "Type \"copyright\", \"credits\" or \"license\" for more information." + + +extern int Py_DebugFlag; /* For parser.c, declared in pythonrun.c */ +extern int Py_VerboseFlag; /* For import.c, declared in pythonrun.c */ +short PyMac_AppRefNum; /* RefNum of application resource fork */ + +/* For Py_GetArgcArgv(); set by main() */ +static char **orig_argv; +static int orig_argc; + +/* A flag which remembers whether the user has acknowledged all the console +** output (by typing something) +*/ +#define STATE_UNKNOWN 0 +#define STATE_LASTREAD 1 +#define STATE_LASTWRITE 2 +int console_output_state = STATE_UNKNOWN; + +PyMac_PrefRecord PyMac_options; + +static void Py_Main(int, char **); /* Forward */ +void PyMac_Exit(int); /* Forward */ + +static void init_appearance() +{ +#ifdef USE_APPEARANCE + OSErr err; + SInt32 response; + + err = Gestalt(gestaltAppearanceAttr,&response); + if ( err ) goto no_appearance; + if ( !(response&(1< isn't pressed. + */ + if (p->nointopt) return; + + GetKeys(rmap); + map = (unsigned char *)rmap; + if ( ( map[0x3a>>3] & (1<<(0x3a&7)) ) == 0 ) /* option key is 3a */ + return; + + dialog = GetNewDialog(OPT_DIALOG, NULL, (WindowPtr)-1); + if ( dialog == NULL ) { + printf("Option dialog not found - cannot set options\n"); + return; + } + SetDialogDefaultItem(dialog, OPT_OK); + SetDialogCancelItem(dialog, OPT_CANCEL); + + /* Set default values */ +#define SET_OPT_ITEM(num, var) \ + GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \ + SetControlValue(handle, (short)p->var); + + SET_OPT_ITEM(OPT_INSPECT, inspect); + SET_OPT_ITEM(OPT_VERBOSE, verbose); + SET_OPT_ITEM(OPT_OPTIMIZE, optimize); + SET_OPT_ITEM(OPT_UNBUFFERED, unbuffered); + SET_OPT_ITEM(OPT_DEBUGGING, debugging); + GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS)); + GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT)); + GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR)); + GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER)); +/* SET_OPT_ITEM(OPT_KEEPCONSOLE, keep_console); */ + SET_OPT_ITEM(OPT_TABWARN, tabwarn); + SET_OPT_ITEM(OPT_NOSITE, nosite); + SET_OPT_ITEM(OPT_NONAVSERV, nonavservice); + /* The rest are not settable interactively */ + +#undef SET_OPT_ITEM + + while (1) { + handle = NULL; + ModalDialog(NULL, &item); + if ( item == OPT_OK ) + break; + if ( item == OPT_CANCEL ) { + DisposeDialog(dialog); + exit(0); + } +#if !TARGET_API_MAC_CARBON + if ( item == OPT_HELP ) { + HMSetBalloons(!HMGetBalloons()); + } +#endif + if ( item == OPT_CMDLINE ) { + int new_argc, newer_argc; + char **new_argv, **newer_argv; + + new_argc = ccommand(&new_argv); + newer_argc = (new_argc-1) + old_argc; + newer_argv = malloc((newer_argc+1)*sizeof(char *)); + if( !newer_argv ) + Py_FatalError("Cannot malloc argv\n"); + for(i=0; ivar = !p->var; \ + GetDialogItem(dialog, (num), &type, (Handle *)&handle, &rect); \ + SetControlValue(handle, (short)p->var); \ + } + + OPT_ITEM(OPT_INSPECT, inspect); + OPT_ITEM(OPT_VERBOSE, verbose); + OPT_ITEM(OPT_OPTIMIZE, optimize); + OPT_ITEM(OPT_UNBUFFERED, unbuffered); + OPT_ITEM(OPT_DEBUGGING, debugging); + if ( item == OPT_KEEPALWAYS ) p->keep_console = POPT_KEEPCONSOLE_ALWAYS; + if ( item == OPT_KEEPOUTPUT ) p->keep_console = POPT_KEEPCONSOLE_OUTPUT; + if ( item == OPT_KEEPERROR ) p->keep_console = POPT_KEEPCONSOLE_ERROR; + if ( item == OPT_KEEPNEVER ) p->keep_console = POPT_KEEPCONSOLE_NEVER; + GetDialogItem(dialog, OPT_KEEPALWAYS, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ALWAYS)); + GetDialogItem(dialog, OPT_KEEPOUTPUT, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_OUTPUT)); + GetDialogItem(dialog, OPT_KEEPERROR, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_ERROR)); + GetDialogItem(dialog, OPT_KEEPNEVER, &type, (Handle *)&handle, &rect); + SetControlValue(handle, (short)(p->keep_console == POPT_KEEPCONSOLE_NEVER)); + OPT_ITEM(OPT_TABWARN, tabwarn); + OPT_ITEM(OPT_NOSITE, nosite); + OPT_ITEM(OPT_NONAVSERV, nonavservice); + +#undef OPT_ITEM + } + DisposeDialog(dialog); +} + +/* +** Initialization code, shared by interpreter and applets +*/ +static void +init_common(int *argcp, char ***argvp, int embedded) +{ + /* Remember resource fork refnum, for later */ + PyMac_AppRefNum = CurResFile(); + + /* Initialize toolboxes */ + init_mac_world(); + +#ifdef USE_MAC_SHARED_LIBRARY + /* Add the shared library to the stack of resource files */ + (void)PyMac_init_process_location(); + PyMac_AddLibResources(); +#endif + +#if defined(USE_GUSI1) + /* Setup GUSI */ + GUSIDefaultSetup(); + PyMac_SetGUSISpin(); + PyMac_SetGUSIOptions(); +#endif +#if defined(USE_GUSI) + atexit(PyMac_StopGUSISpin); +#endif + +#ifdef USE_SIOUX + /* Set various SIOUX flags. Some are changed later based on options */ +/* SIOUXSettings.standalone = 0; /* XXXX Attempting to keep sioux from eating events */ + SIOUXSettings.asktosaveonclose = 0; + SIOUXSettings.showstatusline = 0; + SIOUXSettings.tabspaces = 4; +#endif + + /* Get options from preference file (or from applet resource fork) */ + PyMac_options.keep_console = POPT_KEEPCONSOLE_OUTPUT; /* default-default */ + PyMac_PreferenceOptions(&PyMac_options); + + if ( embedded ) { + static char *emb_argv[] = {"embedded-python", 0}; + + *argcp = 1; + *argvp = emb_argv; + } else { + /* Create argc/argv. Do it before we go into the options event loop. */ + *argcp = PyMac_GetArgv(argvp, PyMac_options.noargs); +#ifndef NO_ARGV0_CHDIR + if (*argcp >= 1 && (*argvp)[0] && (*argvp)[0][0]) { + /* Workaround for MacOS X, which currently (DP4) doesn't set + ** the working folder correctly + */ + char app_wd[256], *p; + + strncpy(app_wd, (*argvp)[0], 256); + p = strrchr(app_wd, ':'); + if ( p ) *p = 0; + chdir(app_wd); + } +#endif + /* Do interactive option setting, if allowed and