summaryrefslogtreecommitdiffstats
path: root/Mac/think
diff options
context:
space:
mode:
authorJack Jansen <jack.jansen@cwi.nl>2000-06-04 21:56:05 (GMT)
committerJack Jansen <jack.jansen@cwi.nl>2000-06-04 21:56:05 (GMT)
commit021da55579bde93b6cc159e6aa7080218c00644c (patch)
treed7377d65e3d2a7939a22e1d702814e2d057e0db7 /Mac/think
parent031ac7112f608bd80f4d92d046a0195f0fafb30a (diff)
downloadcpython-021da55579bde93b6cc159e6aa7080218c00644c.zip
cpython-021da55579bde93b6cc159e6aa7080218c00644c.tar.gz
cpython-021da55579bde93b6cc159e6aa7080218c00644c.tar.bz2
Removed THINK_C support.
Diffstat (limited to 'Mac/think')
-rw-r--r--Mac/think/fopenRF.c336
-rw-r--r--Mac/think/macconsole/macconsole.c437
2 files changed, 0 insertions, 773 deletions
diff --git a/Mac/think/fopenRF.c b/Mac/think/fopenRF.c
deleted file mode 100644
index 04f192e..0000000
--- a/Mac/think/fopenRF.c
+++ /dev/null
@@ -1,336 +0,0 @@
-
-/*
- * fopen.c
- *
- * Copyright (c) 1991 Symantec Corporation. All rights reserved.
- *
- */
-
-#include <MacHeaders>
-
-#include "stdio.h"
-#include "errno.h"
-#include "string.h"
-#include "ansi_private.h"
-
-extern long _ftype, _fcreator;
-
-#define fcbVPtr(fcb) (* (VCB **) (fcb + 20))
-#define fcbDirID(fcb) (* (long *) (fcb + 58))
-#define fcbCName(fcb) (fcb + 62)
-
-static void setfiletype(StringPtr, int);
-static void stdio_exit(void);
-static int fileio(FILE *, int);
-static int close(FILE *);
-static void replace(unsigned char *, size_t, int, int);
-
-FILE *freopenRF();
-FILE *__openRF();
-
-FILE *
-fopenRF(const char *filename, const char *mode)
-{
- return(freopenRF(filename, mode, __getfile()));
-}
-
-
-FILE *
-freopenRF(const char *filename, const char *mode, FILE *fp)
-{
- int omode, oflag;
-
- /* interpret "rwa" */
-
- if (mode[0] == 'r') {
- omode = fsRdPerm;
- oflag = 0;
- }
- else if (mode[0] == 'w') {
- omode = fsWrPerm;
- oflag = F_CREAT+F_TRUNC;
- }
- else if (mode[0] == 'a') {
- omode = fsWrPerm;
- oflag = F_CREAT+F_APPEND;
- }
- else {
- errno = EINVAL;
- return(NULL);
- }
-
- /* interpret "b+" */
-
- if (mode[1] == 'b') {
- oflag |= F_BINARY;
- if (mode[2] == '+')
- omode = fsRdWrPerm;
- }
- else if (mode[1] == '+') {
- omode = fsRdWrPerm;
- if (mode[2] == 'b')
- oflag |= F_BINARY;
- }
-
- /* open the file */
-
- return(__openRF(filename, omode, oflag, fp));
-}
-
-
-FILE *
-__openRF(const char *filename, int omode, int oflag, FILE *fp)
-{
- IOParam pb;
- char pname[FILENAME_MAX];
-
- if (fp == NULL)
- return(NULL);
- fclose(fp);
-
- /* set up pb */
-
- pb.ioNamePtr = __c2p(filename, pname);
- pb.ioVRefNum = 0;
- pb.ioVersNum = 0;
- pb.ioPermssn = omode;
- pb.ioMisc = 0;
-
- /* create file */
-
- if (oflag & F_CREAT) {
- PBCreateSync((ParmBlkPtr)&pb);
- if (pb.ioResult == noErr)
- oflag &= ~F_TRUNC;
- else if (pb.ioResult == dupFNErr && !(oflag & F_EXCL))
- oflag &= ~F_CREAT;
- else {
- errno = pb.ioResult;
- return(NULL);
- }
- }
-
- /* open file */
-
- PBOpenRFSync((ParmBlkPtr)&pb);
- if (pb.ioResult) {
- errno = pb.ioResult;
- if (oflag & F_CREAT)
- PBDeleteSync((ParmBlkPtr)&pb);
- return(NULL);
- }
- fp->refnum = pb.ioRefNum;
-
- /* get/set file length */
-
- if (oflag & F_TRUNC)
- PBSetEOFSync((ParmBlkPtr)&pb);
- else if (!(oflag & F_CREAT))
- PBGetEOFSync((ParmBlkPtr)&pb);
- fp->len = (fpos_t) pb.ioMisc;
-
- /* initialize rest of FILE structure */
-
- if (oflag & F_APPEND) {
- fp->append = 1;
- fp->pos = fp->len;
- }
- if (oflag & F_BINARY)
- fp->binary = 1;
- setvbuf(fp, NULL, _IOFBF, BUFSIZ);
- fp->proc = fileio;
-
- /* set file type */
-
- if (oflag & (F_CREAT|F_TRUNC))
- setfiletype(pb.ioNamePtr, oflag);
-
- /* done */
-
- __atexit_stdio(stdio_exit);
- return(fp);
-}
-
-
-/*
- * setfiletype - set type/creator of new file
- *
- */
-
-static void
-setfiletype(StringPtr name, int oflag)
-{
- FileParam pb;
-
- pb.ioNamePtr = name;
- pb.ioVRefNum = 0;
- pb.ioFVersNum = 0;
- pb.ioFDirIndex = 0;
- if (PBGetFInfoSync((ParmBlkPtr)&pb) == noErr) {
- if (oflag & F_BINARY)
- pb.ioFlFndrInfo.fdType = _ftype;
- else
- pb.ioFlFndrInfo.fdType = 'TEXT';
- pb.ioFlFndrInfo.fdCreator = _fcreator;
- PBSetFInfoSync((ParmBlkPtr)&pb);
- }
-}
-
-
-/*
- * stdio_exit - stdio shutdown routine
- *
- */
-
-static void
-stdio_exit(void)
-{
- register FILE *fp;
- int n;
-
- for (fp = &__file[0], n = FOPEN_MAX; n--; fp++)
- fclose(fp);
-}
-
-
-/*
- * fileio - I/O handler proc for files and devices
- *
- */
-
-static int
-fileio(FILE *fp, int i)
-{
- IOParam pb;
-
- pb.ioRefNum = fp->refnum;
- switch (i) {
-
- /* read */
-
- case 0:
- pb.ioBuffer = (Ptr) fp->ptr;
- pb.ioReqCount = fp->cnt;
- pb.ioPosMode = fp->refnum > 0 ? fsFromStart : fsAtMark;
- pb.ioPosOffset = fp->pos - fp->cnt;
- PBReadSync((ParmBlkPtr)&pb);
- if (pb.ioResult == eofErr) {
- fp->pos = pb.ioPosOffset;
- if (fp->cnt = pb.ioActCount)
- pb.ioResult = 0;
- else {
- fp->eof = 1;
- return(EOF);
- }
- }
- if (!pb.ioResult && !fp->binary)
- replace(fp->ptr, fp->cnt, '\r', '\n');
- break;
-
- /* write */
-
- case 1:
- pb.ioBuffer = (Ptr) fp->ptr;
- pb.ioReqCount = fp->cnt;
- pb.ioPosMode = fp->refnum > 0 ? fsFromStart : fsAtMark;
- if ((pb.ioPosOffset = fp->pos - fp->cnt) > fp->len) {
- pb.ioMisc = (Ptr) pb.ioPosOffset;
- if (PBSetEOFSync((ParmBlkPtr)&pb) != noErr)
- break;
- }
- if (!fp->binary)
- replace(fp->ptr, fp->cnt, '\n', '\r');
- PBWriteSync((ParmBlkPtr)&pb);
- if (!pb.ioResult && pb.ioPosOffset > fp->len)
- fp->len = pb.ioPosOffset;
- break;
-
- /* close */
-
- case 2:
- pb.ioResult = close(fp);
- break;
- }
-
- /* done */
-
- if (pb.ioResult) {
- if (i < 2) {
- fp->pos -= fp->cnt;
- fp->cnt = 0;
- }
- fp->err = 1;
- errno = pb.ioResult;
- return(EOF);
- }
- return(0);
-}
-
-
-static int
-close(FILE *fp)
-{
- HFileParam pb;
- Str255 buf;
- register char *fcb = FCBSPtr + fp->refnum;
- VCB *vcb = fcbVPtr(fcb);
- register char *s;
- enum { none, MFS, HFS } del = none;
-
- pb.ioVRefNum = vcb->vcbVRefNum;
- if (fp->remove) {
- pb.ioNamePtr = buf;
- pb.ioFVersNum = 0;
-
- /* close temporary file - HFS */
-
- if (vcb->vcbSigWord == 0x4244) {
- pb.ioDirID = fcbDirID(fcb);
- s = fcbCName(fcb);
- memcpy(buf, s, Length(s) + 1);
- del = HFS;
- }
-
- /* close temporary file - MFS */
-
- else if (vcb->vcbSigWord == 0xD2D7) {
- for (pb.ioFDirIndex = 1; PBGetFInfoSync((ParmBlkPtr)&pb) == noErr; pb.ioFDirIndex++) {
- if (pb.ioFRefNum == fp->refnum) {
- del = MFS;
- break;
- }
- }
- }
- }
-
- /* close file and flush volume buffer */
-
- pb.ioFRefNum = fp->refnum;
- if (PBCloseSync((ParmBlkPtr)&pb) == noErr) {
- if (del == MFS)
- PBDeleteSync((ParmBlkPtr)&pb);
- else if (del == HFS)
- PBHDeleteSync((HParmBlkPtr)&pb);
- pb.ioNamePtr = 0;
- PBFlushVolSync((ParmBlkPtr)&pb);
- }
- return(pb.ioResult);
-}
-
-
-/*
- * replace - routine for doing CR/LF conversion
- *
- */
-
-static void
-replace(register unsigned char *s, register size_t n, register int c1, register int c2)
-{
-#pragma options(honor_register)
- register unsigned char *t;
-
- for (; n && (t = memchr(s, c1, n)); s = t) {
- *t++ = c2;
- n -= t - s;
- }
-}
diff --git a/Mac/think/macconsole/macconsole.c b/Mac/think/macconsole/macconsole.c
deleted file mode 100644
index 44530b5..0000000
--- a/Mac/think/macconsole/macconsole.c
+++ /dev/null
@@ -1,437 +0,0 @@
-/***********************************************************
-Copyright 1991, 1992, 1993, 1994 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.
-
-******************************************************************/
-
-/*
-** Written by Jack Jansen, October 1994, initially only to allow him to
-** test the ctb module:-)
-*/
-
-#include "allobjects.h"
-#include "modsupport.h" /* For getargs() etc. */
-#include "structmember.h"
-
-#include <console.h>
-
-static object *ErrorObject;
-
-#define OFF(x) offsetof(struct __copt, x)
-
-static struct memberlist copt_memberlist[] = {
- {"top", T_SHORT, OFF(top)},
- {"left", T_SHORT, OFF(left)},
- {"title", T_PSTRING, OFF(title)},
- {"procID", T_SHORT, OFF(procID), RO},
- {"txFont", T_SHORT, OFF(txFont)},
- {"txSize", T_SHORT, OFF(txSize)},
- {"txFace", T_SHORT, OFF(txFace)},
- {"nrows", T_SHORT, OFF(nrows)},
- {"ncols", T_SHORT, OFF(ncols)},
- {"pause_atexit", T_SHORT, OFF(pause_atexit)},
- {NULL}
-};
-
-static unsigned char mytitle[256];
-typedef struct {
- OB_HEAD
-} coptobject;
-
-staticforward typeobject Xxotype;
-
-#define is_coptobject(v) ((v)->ob_type == &Xxotype)
-
-static coptobject *
-newcoptobject()
-{
- coptobject *self;
- self = NEWOBJ(coptobject, &Xxotype);
- return self;
-}
-
-/* Xxo methods */
-
-static void
-copt_dealloc(self)
- coptobject *self;
-{
- DEL(self);
-}
-
-static object *
-copt_getattr(self, name)
- coptobject *self;
- char *name;
-{
- return getmember((char *)&console_options, copt_memberlist, name);
-}
-
-static int
-copt_setattr(self, name, v)
- coptobject *self;
- char *name;
- object *v;
-{
- char *str;
- int len;
-
- if ( strcmp(name, "title") == 0 ) {
- if ( !v || !is_stringobject(v)) {
- err_setstr(ErrorObject, "title must be a string");
- return -1;
- }
- str = getstringvalue(v);
- len = strlen(str);
- mytitle[0] = (unsigned char)len;
- strncpy((char *)mytitle+1, str, mytitle[0]);
- console_options.title = mytitle;
- return 0;
- }
- return setmember((char *)&console_options, copt_memberlist, name, v);
-}
-
-static typeobject Xxotype = {
- OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "console options", /*tp_name*/
- sizeof(coptobject), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)copt_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)copt_getattr, /*tp_getattr*/
- (setattrfunc)copt_setattr, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
-};
-
-/* ------------------------------------------- */
-
-typedef struct {
- OB_HEAD
- FILE *fp;
- object *file;
-} cons_object;
-
-staticforward typeobject constype;
-
-#define is_cons_object(v) ((v)->ob_type == &constype)
-
-static cons_object *
-newcons_object(fp, file)
- FILE *fp;
- object *file;
-{
- cons_object *self;
- self = NEWOBJ(cons_object, &constype);
- if (self == NULL)
- return NULL;
- self->fp = fp;
- self->file = file;
- return self;
-}
-
-/* cons methods */
-
-static void
-cons_dealloc(self)
- cons_object *self;
-{
- DECREF(self->file);
- DEL(self);
-}
-
-static object *
-cons_setmode(self, args)
- cons_object *self;
- object *args;
-{
- int mode;
-
- if (!getargs(args, "i", &mode))
- return NULL;
- csetmode(mode, self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_cleos(self, args)
- cons_object *self;
- object *args;
-{
- if (!getnoarg(args))
- return NULL;
- ccleos(self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_cleol(self, args)
- cons_object *self;
- object *args;
-{
- if (!getnoarg(args))
- return NULL;
- ccleol(self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_show(self, args)
- cons_object *self;
- object *args;
-{
- if (!getnoarg(args))
- return NULL;
- cshow(self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_hide(self, args)
- cons_object *self;
- object *args;
-{
- if (!getnoarg(args))
- return NULL;
- chide(self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_echo2printer(self, args)
- cons_object *self;
- object *args;
-{
- if (!getnoarg(args))
- return NULL;
- cecho2printer(self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_gotoxy(self, args)
- cons_object *self;
- object *args;
-{
- int x, y;
-
- if (!getargs(args, "(ii)", &x, &y))
- return NULL;
- cgotoxy(x, y, self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_getxy(self, args)
- cons_object *self;
- object *args;
-{
- int x, y;
-
- if (!getnoarg(args))
- return NULL;
- cgetxy(&x, &y, self->fp);
- return mkvalue("(ii)", x, y);
-}
-
-static object *
-cons_settabs(self, args)
- cons_object *self;
- object *args;
-{
- int arg;
-
- if (!getargs(args, "i", &arg))
- return NULL;
- csettabs(arg, self->fp);
- INCREF(None);
- return None;
-}
-
-static object *
-cons_inverse(self, args)
- cons_object *self;
- object *args;
-{
- int arg;
-
- if (!getargs(args, "i", &arg))
- return NULL;
- cinverse(arg, self->fp);
- INCREF(None);
- return None;
-}
-
-static struct methodlist cons_methods[] = {
- {"setmode", (method)cons_setmode},
- {"gotoxy", (method)cons_gotoxy},
- {"getxy", (method)cons_getxy},
- {"cleos", (method)cons_cleos},
- {"cleol", (method)cons_cleol},
- {"settabs", (method)cons_settabs},
- {"inverse", (method)cons_inverse},
- {"show", (method)cons_show},
- {"hide", (method)cons_hide},
- {"echo2printer", (method)cons_echo2printer},
- {NULL, NULL} /* sentinel */
-};
-
-static object *
-cons_getattr(self, name)
- cons_object *self;
- char *name;
-{
- if ( strcmp(name, "file") == 0 ) {
- INCREF(self->file);
- return self->file;
- }
- return findmethod(cons_methods, (object *)self, name);
-}
-
-static typeobject constype = {
- OB_HEAD_INIT(&Typetype)
- 0, /*ob_size*/
- "cons", /*tp_name*/
- sizeof(cons_object), /*tp_basicsize*/
- 0, /*tp_itemsize*/
- /* methods */
- (destructor)cons_dealloc, /*tp_dealloc*/
- 0, /*tp_print*/
- (getattrfunc)cons_getattr, /*tp_getattr*/
- 0, /*tp_setattr*/
- 0, /*tp_compare*/
- 0, /*tp_repr*/
- 0, /*tp_as_number*/
- 0, /*tp_as_sequence*/
- 0, /*tp_as_mapping*/
- 0, /*tp_hash*/
-};
-/* --------------------------------------------------------------------- */
-
-/* Return a new console */
-
-static object *
-maccons_copen(self, args)
- object *self; /* Not used */
- object *args;
-{
- FILE *fp;
- object *file;
- cons_object *rv;
- char *name;
- unsigned char nbuf[256];
- int len;
-
- name = NULL;
- if (!getnoarg(args))
- return NULL;
- if ( (fp=fopenc()) == NULL ) {
- err_errno(ErrorObject);
- return NULL;
- }
- if ( (file=newopenfileobject(fp, "<a console>", "r+", fclose)) == NULL)
- return NULL;
- rv = newcons_object(fp, file);
- if ( rv == NULL ) {
- fclose(fp);
- return NULL;
- }
- return (object *)rv;
-}
-
-/* Return an open file as a console */
-
-static object *
-maccons_fopen(self, args)
- object *self; /* Not used */
- object *args;
-{
- cons_object *rv;
- object *file;
- FILE *fp;
-
- if (!newgetargs(args, "O", &file))
- return NULL;
- if ( !is_fileobject(file) ) {
- err_badarg();
- return NULL;
- }
- fp = getfilefile(file);
- if ( !isatty(fileno(fp)) ) {
- err_setstr(ErrorObject, "File is not a console");
- return NULL;
- }
- rv = newcons_object(fp, file);
- if ( rv == NULL ) {
- return NULL;
- }
- INCREF(file);
- return (object *)rv;
-}
-
-/* List of functions defined in the module */
-
-static struct methodlist maccons_methods[] = {
- {"fopen", (method)maccons_fopen, 1},
- {"copen", (method)maccons_copen, 0},
- {NULL, NULL} /* sentinel */
-};
-
-
-/* Initialization function for the module (*must* be called initmacconsole) */
-
-void
-initmacconsole()
-{
- object *m, *d, *o;
-
- /* Create the module and add the functions */
- m = initmodule("macconsole", maccons_methods);
-
- /* Add some symbolic constants to the module */
-#define INTATTR(name, value) o = newintobject(value); dictinsert(d, name, o);
- d = getmoduledict(m);
- ErrorObject = newstringobject("macconsole.error");
- dictinsert(d, "error", ErrorObject);
- o = (object *)newcoptobject();
- dictinsert(d, "options", o);
- INTATTR("C_RAW", C_RAW);
- INTATTR("C_CBREAK", C_CBREAK);
- INTATTR("C_ECHO", C_ECHO);
- INTATTR("C_NOECHO", C_NOECHO);
-
- /* Check for errors */
- if (err_occurred())
- fatal("can't initialize module macconsole");
-}