From 739267b7c34c0bdf934059804fde3f027e84bd0b Mon Sep 17 00:00:00 2001 From: Guido van Rossum Date: Mon, 29 Aug 1994 08:42:37 +0000 Subject: Completed (hopefully) the unification of THINK 6.0 and MPW 3.2 versions -- they now share config.c and config.h, and statting is always done through macstat.[ch] (THINK's defines funny constants). Also the configuration of stdwin is done differently: you have to define USE_STDWIN to the compiler prefix. --- Mac/Compat/getwd.c | 2 +- Mac/Compat/macstat.c | 42 +++++++++++++++++++++++++----------------- Mac/Compat/macstat.h | 27 +++++++++++++++------------ Mac/Include/config.h | 7 ++++++- Mac/Include/macdefs.h | 11 +---------- Mac/Modules/config.c | 2 -- Mac/Modules/macmodule.c | 27 ++++++++++++++++++++------- Mac/Python/macgetmtime.c | 6 +++--- 8 files changed, 71 insertions(+), 53 deletions(-) diff --git a/Mac/Compat/getwd.c b/Mac/Compat/getwd.c index 3a093ed..a783ff6 100644 --- a/Mac/Compat/getwd.c +++ b/Mac/Compat/getwd.c @@ -27,10 +27,10 @@ Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). */ +#include "macdefs.h" #ifdef MPW #include #endif -#include "macdefs.h" #define ROOTID 2 /* Root directory ID */ diff --git a/Mac/Compat/macstat.c b/Mac/Compat/macstat.c index e645050..564da10 100644 --- a/Mac/Compat/macstat.c +++ b/Mac/Compat/macstat.c @@ -1,9 +1,10 @@ /* Minimal 'stat' emulation: tells directories from files and gives length and mtime. Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). + Updated to give more info, August 1994. */ -#include "stat.h" +#include "macstat.h" #include "macdefs.h" /* Bits in ioFlAttrib: */ @@ -11,9 +12,9 @@ #define DIRBIT (1<<4) /* It's a directory */ int -stat(path, buf) +macstat(path, buf) char *path; - struct stat *buf; + struct macstat *buf; { union { DirInfo d; @@ -23,35 +24,42 @@ stat(path, buf) char name[256]; short err; - pb.d.ioNamePtr= (unsigned char *)c2pstr(strcpy(name, path)); - pb.d.ioVRefNum= 0; - pb.d.ioFDirIndex= 0; - pb.d.ioDrDirID= 0; - pb.f.ioFVersNum= 0; /* Fix found by Timo! See Tech Note 102 */ + pb.d.ioNamePtr = (unsigned char *)c2pstr(strcpy(name, path)); + pb.d.ioVRefNum = 0; + pb.d.ioFDirIndex = 0; + pb.d.ioDrDirID = 0; + pb.f.ioFVersNum = 0; /* Fix found by Timo! See Tech Note 102 */ if (hfsrunning()) - err= PBGetCatInfo((CInfoPBPtr)&pb, FALSE); + err = PBGetCatInfo((CInfoPBPtr)&pb, FALSE); else - err= PBGetFInfo((ParmBlkPtr)&pb, FALSE); + err = PBGetFInfo((ParmBlkPtr)&pb, FALSE); if (err != noErr) { errno = ENOENT; return -1; } if (pb.d.ioFlAttrib & LOCKBIT) - buf->st_mode= 0444; + buf->st_mode = 0444; else - buf->st_mode= 0666; + buf->st_mode = 0666; if (pb.d.ioFlAttrib & DIRBIT) { buf->st_mode |= 0111 | S_IFDIR; - buf->st_size= pb.d.ioDrNmFls; - buf->st_rsize= 0; + buf->st_size = pb.d.ioDrNmFls; + buf->st_rsize = 0; } else { buf->st_mode |= S_IFREG; if (pb.f.ioFlFndrInfo.fdType == 'APPL') buf->st_mode |= 0111; - buf->st_size= pb.f.ioFlLgLen; - buf->st_rsize= pb.f.ioFlRLgLen; } - buf->st_mtime= pb.f.ioFlMdDat - TIMEDIFF; + buf->st_ino = pb.hf.ioDirID; + buf->st_nlink = 1; + buf->st_uid = 1; + buf->st_gid = 1; + buf->st_size = pb.f.ioFlLgLen; + buf->st_mtime = buf->st_atime = pb.f.ioFlMdDat; + buf->st_ctime = pb.f.ioFlCrDat; + buf->st_rsize = pb.f.ioFlRLgLen; + *(unsigned long *)buf->st_type = pb.f.ioFlFndrInfo.fdType; + *(unsigned long *)buf->st_creator = pb.f.ioFlFndrInfo.fdCreator; return 0; } diff --git a/Mac/Compat/macstat.h b/Mac/Compat/macstat.h index c14116a..4c24219 100644 --- a/Mac/Compat/macstat.h +++ b/Mac/Compat/macstat.h @@ -1,25 +1,28 @@ /* Include file belonging to stat emulator. - Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). */ + Public domain by Guido van Rossum, CWI, Amsterdam (July 1987). + Updated August 1994. */ -struct stat { +struct macstat { + unsigned short st_dev; + unsigned long st_ino; unsigned short st_mode; + unsigned short st_nlink; + unsigned short st_uid; + unsigned short st_gid; + unsigned short st_rdev; unsigned long st_size; - unsigned long st_rsize; /* Resource size -- nonstandard */ + unsigned long st_atime; unsigned long st_mtime; + unsigned long st_ctime; + /* Non-standard additions */ + unsigned long st_rsize; /* Resource size */ + char st_type[4]; /* File type, e.g. 'APPL' or 'TEXT' */ + char st_creator[4]; /* File creator, e.g. 'PYTH' */ }; -#ifdef UNIX_COMPAT #define S_IFMT 0170000L #define S_IFDIR 0040000L #define S_IFREG 0100000L #define S_IREAD 0400 #define S_IWRITE 0200 #define S_IEXEC 0100 -#else -#define S_IFMT 0xFFFF -#define S_IFDIR 0x0000 -#define S_IFREG 0x0003 -#define S_IREAD 0400 -#define S_IWRITE 0200 -#define S_IEXEC 0100 -#endif diff --git a/Mac/Include/config.h b/Mac/Include/config.h index 7b98e95..e04fde6 100644 --- a/Mac/Include/config.h +++ b/Mac/Include/config.h @@ -1,4 +1,9 @@ -/* config.h for Macintosh THINK C 6.0. */ +/* config.h for Macintosh THINK C 6.0 and MPW 3.2. */ + +#ifdef MPW +/* This must be is MPW 3.x */ +#define MPW_3 1 +#endif /* Define if on Macintosh (THINK_C or MPW should also be defined) */ #define macintosh diff --git a/Mac/Include/macdefs.h b/Mac/Include/macdefs.h index dcdedb1..c1e8a6e 100644 --- a/Mac/Include/macdefs.h +++ b/Mac/Include/macdefs.h @@ -7,17 +7,13 @@ #include #include -#ifndef MPW +#ifdef THINK_C #include #endif #include #include -/* Difference in origin between Mac and Unix clocks: */ -#define TIMEDIFF ((unsigned long) \ - (((1970-1904)*365 + (1970-1904)/4) * 24 * 3600)) - /* Macro to find out whether we can do HFS-only calls: */ #define FSFCBLen (* (short *) 0x3f6) #define hfsrunning() (FSFCBLen > 0) @@ -31,8 +27,3 @@ #endif #define EOS '\0' #define SEP ':' - -#if 0 // doesn't work -/* Call Macsbug: */ -pascal void Debugger() extern 0xA9FF; -#endif diff --git a/Mac/Modules/config.c b/Mac/Modules/config.c index 54fed74..3595a9e 100644 --- a/Mac/Modules/config.c +++ b/Mac/Modules/config.c @@ -31,8 +31,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #ifdef macintosh /* The Macintosh main program is in macmain.c */ #define NO_MAIN -/* Comment this out if you're not interested in STDWIN */ -#define USE_STDWIN #endif #include diff --git a/Mac/Modules/macmodule.c b/Mac/Modules/macmodule.c index ff06acd..d8d0dd8 100644 --- a/Mac/Modules/macmodule.c +++ b/Mac/Modules/macmodule.c @@ -23,8 +23,6 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ******************************************************************/ /* Mac module implementation */ -/* Richard J. Walker April 7, 1994 Island Graphics Corp. */ -/* Thanks to Guido's unix emulation routines */ #include "allobjects.h" #include "modsupport.h" @@ -33,7 +31,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. #include #include #include -#include + +#ifdef THINK_C +#include "unix.h" +#undef S_IFMT +#undef S_IFDIR +#undef S_IFCHR +#undef S_IFBLK +#undef S_IFREG +#undef S_ISDIR +#undef S_ISREG +#endif + +#include "macstat.h" #include @@ -54,9 +64,12 @@ DIR * opendir PROTO((char *)); void closedir PROTO((DIR *)); struct dirent * readdir PROTO((DIR *)); int rmdir PROTO((const char *path)); -int stat PROTO((const char *path, struct stat *buf)); int sync PROTO((void)); +#ifdef THINK_C +int unlink PROTO((char *)); +#else int unlink PROTO((const char *)); +#endif @@ -357,13 +370,13 @@ mac_stat(self, args) object *self; object *args; { - struct stat st; + struct macstat st; char *path; int res; if (!getargs(args, "s", &path)) return NULL; BGN_SAVE - res = stat(path, &st); + res = macstat(path, &st); END_SAVE if (res != 0) return mac_error(); @@ -402,7 +415,7 @@ mac_unlink(self, args) object *self; object *args; { - return mac_1str(args, unlink); + return mac_1str(args, (int (*)(const char *))unlink); } static object * diff --git a/Mac/Python/macgetmtime.c b/Mac/Python/macgetmtime.c index 9ba8136..d4d15be 100644 --- a/Mac/Python/macgetmtime.c +++ b/Mac/Python/macgetmtime.c @@ -1,4 +1,4 @@ -#include +#include "macstat.h" /* Interfaced used by import.c */ @@ -6,8 +6,8 @@ long getmtime(path) char *path; { - struct stat st; - if (stat(path, &st) != 0) + struct macstat st; + if (macstat(path, &st) != 0) return -1L; return st.st_mtime; } -- cgit v0.12