0
0
mirror of https://github.com/python/cpython.git synced 2024-11-24 00:38:00 +01:00

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 <stat.h> defines funny
constants).  Also the configuration of stdwin is done differently: you
have to define USE_STDWIN to the compiler prefix.
This commit is contained in:
Guido van Rossum 1994-08-29 08:42:37 +00:00
parent e783444440
commit 739267b7c3
8 changed files with 71 additions and 53 deletions

View File

@ -27,10 +27,10 @@
Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
*/
#include "macdefs.h"
#ifdef MPW
#include <Strings.h>
#endif
#include "macdefs.h"
#define ROOTID 2 /* Root directory ID */

View File

@ -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;
}

View File

@ -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

View File

@ -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

View File

@ -7,17 +7,13 @@
#include <Files.h>
#include <OSUtils.h>
#ifndef MPW
#ifdef THINK_C
#include <pascal.h>
#endif
#include <errno.h>
#include <string.h>
/* 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

View File

@ -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 <stdio.h>

View File

@ -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 <stdio.h>
#include <string.h>
#include <errno.h>
#include <stat.h>
#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 <fcntl.h>
@ -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 *

View File

@ -1,4 +1,4 @@
#include <stat.h>
#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;
}