annotate Mac/think/macconsole/macconsole.c @ 4566:6403c94de50d legacy-trunk

Added safeguard against failure in __del__.
author Guido van Rossum <guido@python.org>
date Wed, 27 Nov 1996 19:39:58 +0000
parents 8adcb808d8dd
children
Ignore whitespace changes - Everywhere: Within whitespace: At end of lines:
rev   line source
2172
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
1 /***********************************************************
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
2 Copyright 1991, 1992, 1993, 1994 by Stichting Mathematisch Centrum,
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
3 Amsterdam, The Netherlands.
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
4
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
5 All Rights Reserved
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
6
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
7 Permission to use, copy, modify, and distribute this software and its
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
8 documentation for any purpose and without fee is hereby granted,
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
9 provided that the above copyright notice appear in all copies and that
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
10 both that copyright notice and this permission notice appear in
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
11 supporting documentation, and that the names of Stichting Mathematisch
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
12 Centrum or CWI not be used in advertising or publicity pertaining to
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
13 distribution of the software without specific, written prior permission.
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
14
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
15 STICHTING MATHEMATISCH CENTRUM DISCLAIMS ALL WARRANTIES WITH REGARD TO
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
16 THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
17 FITNESS, IN NO EVENT SHALL STICHTING MATHEMATISCH CENTRUM BE LIABLE
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
18 FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
19 WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
20 ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
21 OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
22
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
23 ******************************************************************/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
24
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
25 /*
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
26 ** Written by Jack Jansen, October 1994, initially only to allow him to
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
27 ** test the ctb module:-)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
28 */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
29
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
30 #include "allobjects.h"
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
31 #include "modsupport.h" /* For getargs() etc. */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
32 #include "structmember.h"
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
33
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
34 #include <console.h>
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
35
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
36 static object *ErrorObject;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
37
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
38 #define OFF(x) offsetof(struct __copt, x)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
39
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
40 static struct memberlist copt_memberlist[] = {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
41 {"top", T_SHORT, OFF(top)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
42 {"left", T_SHORT, OFF(left)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
43 {"title", T_PSTRING, OFF(title)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
44 {"procID", T_SHORT, OFF(procID), RO},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
45 {"txFont", T_SHORT, OFF(txFont)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
46 {"txSize", T_SHORT, OFF(txSize)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
47 {"txFace", T_SHORT, OFF(txFace)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
48 {"nrows", T_SHORT, OFF(nrows)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
49 {"ncols", T_SHORT, OFF(ncols)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
50 {"pause_atexit", T_SHORT, OFF(pause_atexit)},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
51 {NULL}
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
52 };
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
53
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
54 static unsigned char mytitle[256];
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
55 typedef struct {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
56 OB_HEAD
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
57 } coptobject;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
58
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
59 staticforward typeobject Xxotype;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
60
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
61 #define is_coptobject(v) ((v)->ob_type == &Xxotype)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
62
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
63 static coptobject *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
64 newcoptobject()
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
65 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
66 coptobject *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
67 self = NEWOBJ(coptobject, &Xxotype);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
68 return self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
69 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
70
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
71 /* Xxo methods */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
72
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
73 static void
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
74 copt_dealloc(self)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
75 coptobject *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
76 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
77 DEL(self);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
78 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
79
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
80 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
81 copt_getattr(self, name)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
82 coptobject *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
83 char *name;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
84 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
85 return getmember((char *)&console_options, copt_memberlist, name);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
86 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
87
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
88 static int
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
89 copt_setattr(self, name, v)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
90 coptobject *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
91 char *name;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
92 object *v;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
93 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
94 char *str;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
95 int len;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
96
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
97 if ( strcmp(name, "title") == 0 ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
98 if ( !v || !is_stringobject(v)) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
99 err_setstr(ErrorObject, "title must be a string");
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
100 return -1;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
101 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
102 str = getstringvalue(v);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
103 len = strlen(str);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
104 mytitle[0] = (unsigned char)len;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
105 strncpy((char *)mytitle+1, str, mytitle[0]);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
106 console_options.title = mytitle;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
107 return 0;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
108 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
109 return setmember((char *)&console_options, copt_memberlist, name, v);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
110 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
111
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
112 static typeobject Xxotype = {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
113 OB_HEAD_INIT(&Typetype)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
114 0, /*ob_size*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
115 "console options", /*tp_name*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
116 sizeof(coptobject), /*tp_basicsize*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
117 0, /*tp_itemsize*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
118 /* methods */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
119 (destructor)copt_dealloc, /*tp_dealloc*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
120 0, /*tp_print*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
121 (getattrfunc)copt_getattr, /*tp_getattr*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
122 (setattrfunc)copt_setattr, /*tp_setattr*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
123 0, /*tp_compare*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
124 0, /*tp_repr*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
125 0, /*tp_as_number*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
126 0, /*tp_as_sequence*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
127 0, /*tp_as_mapping*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
128 0, /*tp_hash*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
129 };
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
130
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
131 /* ------------------------------------------- */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
132
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
133 typedef struct {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
134 OB_HEAD
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
135 FILE *fp;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
136 object *file;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
137 } cons_object;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
138
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
139 staticforward typeobject constype;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
140
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
141 #define is_cons_object(v) ((v)->ob_type == &constype)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
142
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
143 static cons_object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
144 newcons_object(fp, file)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
145 FILE *fp;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
146 object *file;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
147 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
148 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
149 self = NEWOBJ(cons_object, &constype);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
150 if (self == NULL)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
151 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
152 self->fp = fp;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
153 self->file = file;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
154 return self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
155 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
156
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
157 /* cons methods */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
158
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
159 static void
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
160 cons_dealloc(self)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
161 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
162 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
163 DECREF(self->file);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
164 DEL(self);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
165 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
166
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
167 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
168 cons_setmode(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
169 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
170 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
171 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
172 int mode;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
173
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
174 if (!getargs(args, "i", &mode))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
175 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
176 csetmode(mode, self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
177 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
178 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
179 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
180
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
181 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
182 cons_cleos(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
183 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
184 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
185 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
186 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
187 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
188 ccleos(self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
189 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
190 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
191 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
192
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
193 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
194 cons_cleol(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
195 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
196 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
197 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
198 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
199 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
200 ccleol(self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
201 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
202 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
203 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
204
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
205 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
206 cons_show(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
207 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
208 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
209 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
210 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
211 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
212 cshow(self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
213 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
214 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
215 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
216
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
217 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
218 cons_hide(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
219 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
220 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
221 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
222 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
223 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
224 chide(self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
225 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
226 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
227 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
228
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
229 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
230 cons_echo2printer(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
231 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
232 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
233 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
234 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
235 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
236 cecho2printer(self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
237 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
238 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
239 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
240
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
241 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
242 cons_gotoxy(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
243 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
244 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
245 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
246 int x, y;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
247
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
248 if (!getargs(args, "(ii)", &x, &y))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
249 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
250 cgotoxy(x, y, self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
251 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
252 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
253 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
254
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
255 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
256 cons_getxy(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
257 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
258 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
259 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
260 int x, y;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
261
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
262 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
263 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
264 cgetxy(&x, &y, self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
265 return mkvalue("(ii)", x, y);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
266 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
267
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
268 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
269 cons_settabs(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
270 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
271 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
272 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
273 int arg;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
274
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
275 if (!getargs(args, "i", &arg))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
276 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
277 csettabs(arg, self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
278 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
279 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
280 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
281
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
282 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
283 cons_inverse(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
284 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
285 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
286 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
287 int arg;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
288
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
289 if (!getargs(args, "i", &arg))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
290 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
291 cinverse(arg, self->fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
292 INCREF(None);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
293 return None;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
294 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
295
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
296 static struct methodlist cons_methods[] = {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
297 {"setmode", (method)cons_setmode},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
298 {"gotoxy", (method)cons_gotoxy},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
299 {"getxy", (method)cons_getxy},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
300 {"cleos", (method)cons_cleos},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
301 {"cleol", (method)cons_cleol},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
302 {"settabs", (method)cons_settabs},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
303 {"inverse", (method)cons_inverse},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
304 {"show", (method)cons_show},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
305 {"hide", (method)cons_hide},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
306 {"echo2printer", (method)cons_echo2printer},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
307 {NULL, NULL} /* sentinel */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
308 };
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
309
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
310 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
311 cons_getattr(self, name)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
312 cons_object *self;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
313 char *name;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
314 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
315 if ( strcmp(name, "file") == 0 ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
316 INCREF(self->file);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
317 return self->file;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
318 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
319 return findmethod(cons_methods, (object *)self, name);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
320 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
321
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
322 static typeobject constype = {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
323 OB_HEAD_INIT(&Typetype)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
324 0, /*ob_size*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
325 "cons", /*tp_name*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
326 sizeof(cons_object), /*tp_basicsize*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
327 0, /*tp_itemsize*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
328 /* methods */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
329 (destructor)cons_dealloc, /*tp_dealloc*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
330 0, /*tp_print*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
331 (getattrfunc)cons_getattr, /*tp_getattr*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
332 0, /*tp_setattr*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
333 0, /*tp_compare*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
334 0, /*tp_repr*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
335 0, /*tp_as_number*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
336 0, /*tp_as_sequence*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
337 0, /*tp_as_mapping*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
338 0, /*tp_hash*/
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
339 };
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
340 /* --------------------------------------------------------------------- */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
341
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
342 /* Return a new console */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
343
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
344 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
345 maccons_copen(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
346 object *self; /* Not used */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
347 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
348 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
349 FILE *fp;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
350 object *file;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
351 cons_object *rv;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
352 char *name;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
353 unsigned char nbuf[256];
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
354 int len;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
355
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
356 name = NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
357 if (!getnoarg(args))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
358 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
359 if ( (fp=fopenc()) == NULL ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
360 err_errno(ErrorObject);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
361 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
362 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
363 if ( (file=newopenfileobject(fp, "<a console>", "r+", fclose)) == NULL)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
364 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
365 rv = newcons_object(fp, file);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
366 if ( rv == NULL ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
367 fclose(fp);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
368 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
369 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
370 return (object *)rv;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
371 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
372
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
373 /* Return an open file as a console */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
374
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
375 static object *
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
376 maccons_fopen(self, args)
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
377 object *self; /* Not used */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
378 object *args;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
379 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
380 cons_object *rv;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
381 object *file;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
382 FILE *fp;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
383
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
384 if (!newgetargs(args, "O", &file))
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
385 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
386 if ( !is_fileobject(file) ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
387 err_badarg();
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
388 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
389 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
390 fp = getfilefile(file);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
391 if ( !isatty(fileno(fp)) ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
392 err_setstr(ErrorObject, "File is not a console");
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
393 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
394 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
395 rv = newcons_object(fp, file);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
396 if ( rv == NULL ) {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
397 return NULL;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
398 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
399 INCREF(file);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
400 return (object *)rv;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
401 }
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
402
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
403 /* List of functions defined in the module */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
404
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
405 static struct methodlist maccons_methods[] = {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
406 {"fopen", (method)maccons_fopen, 1},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
407 {"copen", (method)maccons_copen, 0},
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
408 {NULL, NULL} /* sentinel */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
409 };
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
410
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
411
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
412 /* Initialization function for the module (*must* be called initmacconsole) */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
413
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
414 void
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
415 initmacconsole()
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
416 {
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
417 object *m, *d, *o;
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
418
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
419 /* Create the module and add the functions */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
420 m = initmodule("macconsole", maccons_methods);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
421
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
422 /* Add some symbolic constants to the module */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
423 #define INTATTR(name, value) o = newintobject(value); dictinsert(d, name, o);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
424 d = getmoduledict(m);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
425 ErrorObject = newstringobject("macconsole.error");
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
426 dictinsert(d, "error", ErrorObject);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
427 o = (object *)newcoptobject();
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
428 dictinsert(d, "options", o);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
429 INTATTR("C_RAW", C_RAW);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
430 INTATTR("C_CBREAK", C_CBREAK);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
431 INTATTR("C_ECHO", C_ECHO);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
432 INTATTR("C_NOECHO", C_NOECHO);
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
433
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
434 /* Check for errors */
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
435 if (err_occurred())
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
436 fatal("can't initialize module macconsole");
8adcb808d8dd Macconsole module is think-specific
Jack Jansen <jack.jansen@cwi.nl>
parents:
diff changeset
437 }