Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Support
Keyboard shortcuts
?
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
C
cpython
Project overview
Project overview
Details
Activity
Releases
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Issues
0
Issues
0
List
Boards
Labels
Milestones
Merge Requests
0
Merge Requests
0
Analytics
Analytics
Repository
Value Stream
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Create a new issue
Commits
Issue Boards
Open sidebar
Kirill Smelkov
cpython
Commits
c42386ad
Commit
c42386ad
authored
Jan 30, 1997
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Renamed
parent
1b7cfc85
Changes
5
Hide whitespace changes
Inline
Side-by-side
Showing
5 changed files
with
617 additions
and
621 deletions
+617
-621
Mac/Modules/ctbmodule.c
Mac/Modules/ctbmodule.c
+137
-137
Mac/Modules/gestaltmodule.c
Mac/Modules/gestaltmodule.c
+10
-11
Mac/Modules/macfsmodule.c
Mac/Modules/macfsmodule.c
+171
-172
Mac/Modules/macmodule.c
Mac/Modules/macmodule.c
+184
-185
Mac/Modules/macspeechmodule.c
Mac/Modules/macspeechmodule.c
+115
-116
No files found.
Mac/Modules/ctbmodule.c
View file @
c42386ad
...
...
@@ -26,7 +26,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* ctbcm objects */
#include "
allobjects
.h"
#include "
Python
.h"
#include "macglue.h"
...
...
@@ -46,19 +46,19 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define _CommToolboxTrap 0x8B
#define _UnimplementedOSTrap 0x9F
extern
object
*
PyErr_Mac
(
o
bject
*
,
int
);
extern
PyObject
*
PyErr_Mac
(
PyO
bject
*
,
int
);
static
o
bject
*
ErrorObject
;
static
PyO
bject
*
ErrorObject
;
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
ConnHandle
hdl
;
/* The handle to the connection */
o
bject
*
callback
;
/* Python callback routine */
PyO
bject
*
callback
;
/* Python callback routine */
int
has_callback
;
/* True if callback not None */
int
err
;
/* Error to pass to the callback */
}
ctbcmobject
;
staticforward
typeo
bject
ctbcmtype
;
staticforward
PyTypeO
bject
ctbcmtype
;
#define is_ctbcmobject(v) ((v)->ob_type == &ctbcmtype)
...
...
@@ -86,7 +86,7 @@ initialize_ctb()
initialized
=
0
;
if
(
!
TrapAvailable
(
_CommToolboxTrap
,
OSTrap
)
)
{
err_setstr
(
ErrorObject
,
"CTB not available"
);
PyErr_SetString
(
ErrorObject
,
"CTB not available"
);
return
0
;
}
if
(
(
err
=
InitCTBUtilities
())
)
{
...
...
@@ -110,16 +110,16 @@ ctbcm_pycallback(arg)
void
*
arg
;
{
ctbcmobject
*
self
=
(
ctbcmobject
*
)
arg
;
o
bject
*
args
,
*
rv
;
PyO
bject
*
args
,
*
rv
;
if
(
!
self
->
has_callback
)
/* It could have been removed in the meantime */
return
0
;
args
=
mkv
alue
(
"(i)"
,
self
->
err
);
rv
=
call_o
bject
(
self
->
callback
,
args
);
DECREF
(
args
);
args
=
Py_BuildV
alue
(
"(i)"
,
self
->
err
);
rv
=
PyEval_CallO
bject
(
self
->
callback
,
args
);
Py_
DECREF
(
args
);
if
(
rv
==
NULL
)
return
-
1
;
DECREF
(
rv
);
Py_
DECREF
(
rv
);
return
0
;
}
...
...
@@ -139,15 +139,15 @@ ctbcm_ctbcallback(hconn)
static
ctbcmobject
*
newctbcmobject
(
arg
)
o
bject
*
arg
;
PyO
bject
*
arg
;
{
ctbcmobject
*
self
;
self
=
NEWOBJ
(
ctbcmobject
,
&
ctbcmtype
);
self
=
PyObject_NEW
(
ctbcmobject
,
&
ctbcmtype
);
if
(
self
==
NULL
)
return
NULL
;
self
->
hdl
=
NULL
;
INCREF
(
None
);
self
->
callback
=
None
;
Py_INCREF
(
Py_
None
);
self
->
callback
=
Py_
None
;
self
->
has_callback
=
0
;
return
self
;
}
...
...
@@ -164,104 +164,104 @@ ctbcm_dealloc(self)
CMDispose
(
self
->
hdl
);
self
->
hdl
=
NULL
;
}
DEL
(
self
);
PyMem_
DEL
(
self
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_open
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
long
timeout
;
OSErr
err
;
ConnectionCompletionUPP
cb_upp
=
NewConnectionCompletionProc
(
ctbcm_ctbcallback
);
if
(
!
getargs
(
args
,
"l"
,
&
timeout
))
if
(
!
PyArg_Parse
(
args
,
"l"
,
&
timeout
))
return
NULL
;
if
(
(
err
=
CMOpen
(
self
->
hdl
,
self
->
has_callback
,
cb_upp
,
timeout
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_listen
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
long
timeout
;
OSErr
err
;
ConnectionCompletionUPP
cb_upp
=
NewConnectionCompletionProc
(
ctbcm_ctbcallback
);
if
(
!
getargs
(
args
,
"l"
,
&
timeout
))
if
(
!
PyArg_Parse
(
args
,
"l"
,
&
timeout
))
return
NULL
;
if
(
(
err
=
CMListen
(
self
->
hdl
,
self
->
has_callback
,
cb_upp
,
timeout
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_accept
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
int
accept
;
OSErr
err
;
if
(
!
getargs
(
args
,
"i"
,
&
accept
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
accept
))
return
NULL
;
if
(
(
err
=
CMAccept
(
self
->
hdl
,
accept
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_close
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
int
now
;
long
timeout
;
OSErr
err
;
ConnectionCompletionUPP
cb_upp
=
NewConnectionCompletionProc
(
ctbcm_ctbcallback
);
if
(
!
getargs
(
args
,
"(li)"
,
&
timeout
,
&
now
))
if
(
!
PyArg_Parse
(
args
,
"(li)"
,
&
timeout
,
&
now
))
return
NULL
;
if
(
(
err
=
CMClose
(
self
->
hdl
,
self
->
has_callback
,
cb_upp
,
timeout
,
now
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_read
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
long
timeout
,
len
;
int
chan
;
CMFlags
flags
;
OSErr
err
;
o
bject
*
rv
;
PyO
bject
*
rv
;
ConnectionCompletionUPP
cb_upp
=
NewConnectionCompletionProc
(
ctbcm_ctbcallback
);
if
(
!
getargs
(
args
,
"(lil)"
,
&
len
,
&
chan
,
&
timeout
))
if
(
!
PyArg_Parse
(
args
,
"(lil)"
,
&
len
,
&
chan
,
&
timeout
))
return
NULL
;
if
((
rv
=
newsizedstringobject
(
NULL
,
len
))
==
NULL
)
if
((
rv
=
PyString_FromStringAndSize
(
NULL
,
len
))
==
NULL
)
return
NULL
;
if
((
err
=
CMRead
(
self
->
hdl
,
(
Ptr
)
getstringvalue
(
rv
),
&
len
,
(
CMChannel
)
chan
,
if
((
err
=
CMRead
(
self
->
hdl
,
(
Ptr
)
PyString_AsString
(
rv
),
&
len
,
(
CMChannel
)
chan
,
self
->
has_callback
,
cb_upp
,
timeout
,
&
flags
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
resizestring
(
&
rv
,
len
);
return
mkv
alue
(
"(Oi)"
,
rv
,
(
int
)
flags
);
_PyString_Resize
(
&
rv
,
len
);
return
Py_BuildV
alue
(
"(Oi)"
,
rv
,
(
int
)
flags
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_write
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
long
timeout
,
len
;
int
chan
,
ilen
,
flags
;
...
...
@@ -269,184 +269,184 @@ ctbcm_write(self, args)
char
*
buf
;
ConnectionCompletionUPP
cb_upp
=
NewConnectionCompletionProc
(
ctbcm_ctbcallback
);
if
(
!
getargs
(
args
,
"(s#ili)"
,
&
buf
,
&
ilen
,
&
chan
,
&
timeout
,
&
flags
))
if
(
!
PyArg_Parse
(
args
,
"(s#ili)"
,
&
buf
,
&
ilen
,
&
chan
,
&
timeout
,
&
flags
))
return
NULL
;
len
=
ilen
;
if
((
err
=
CMWrite
(
self
->
hdl
,
(
Ptr
)
buf
,
&
len
,
(
CMChannel
)
chan
,
self
->
has_callback
,
cb_upp
,
timeout
,
(
CMFlags
)
flags
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
return
newintobject
((
int
)
len
);
return
PyInt_FromLong
((
int
)
len
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_status
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
CMBufferSizes
sizes
;
CMStatFlags
flags
;
OSErr
err
;
o
bject
*
rv
;
PyO
bject
*
rv
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
((
err
=
CMStatus
(
self
->
hdl
,
sizes
,
&
flags
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
(
int
)
err
);
rv
=
mkv
alue
(
"(llllll)"
,
sizes
[
0
],
sizes
[
1
],
sizes
[
2
],
sizes
[
3
],
sizes
[
4
],
sizes
[
5
]);
rv
=
Py_BuildV
alue
(
"(llllll)"
,
sizes
[
0
],
sizes
[
1
],
sizes
[
2
],
sizes
[
3
],
sizes
[
4
],
sizes
[
5
]);
if
(
rv
==
NULL
)
return
NULL
;
return
mkv
alue
(
"(Ol)"
,
rv
,
(
long
)
flags
);
return
Py_BuildV
alue
(
"(Ol)"
,
rv
,
(
long
)
flags
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_getconfig
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
char
*
rv
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
((
rv
=
(
char
*
)
CMGetConfig
(
self
->
hdl
))
==
NULL
)
{
err_setstr
(
ErrorObject
,
"CMGetConfig failed"
);
PyErr_SetString
(
ErrorObject
,
"CMGetConfig failed"
);
return
NULL
;
}
return
newstringobject
(
rv
);
return
PyString_FromString
(
rv
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_setconfig
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
char
*
cfg
;
OSErr
err
;
if
(
!
getargs
(
args
,
"s"
,
&
cfg
))
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
cfg
))
return
NULL
;
if
((
err
=
CMSetConfig
(
self
->
hdl
,
(
Ptr
)
cfg
))
<
0
)
return
PyErr_Mac
(
ErrorObject
,
err
);
return
newintobject
((
int
)
err
);
return
PyInt_FromLong
((
int
)
err
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_choose
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
int
rv
;
Point
pt
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
pt
.
v
=
40
;
pt
.
h
=
40
;
rv
=
CMChoose
(
&
self
->
hdl
,
pt
,
(
ConnectionChooseIdleUPP
)
0
);
return
newintobject
(
rv
);
return
PyInt_FromLong
(
rv
);
}
static
o
bject
*
static
PyO
bject
*
ctbcm_idle
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
CMIdle
(
self
->
hdl
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_abort
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
CMAbort
(
self
->
hdl
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_reset
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
CMReset
(
self
->
hdl
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
ctbcm_break
(
self
,
args
)
ctbcmobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
long
duration
;
ConnectionCompletionUPP
cb_upp
=
NewConnectionCompletionProc
(
ctbcm_ctbcallback
);
if
(
!
getargs
(
args
,
"l"
,
&
duration
))
if
(
!
PyArg_Parse
(
args
,
"l"
,
&
duration
))
return
NULL
;
CMBreak
(
self
->
hdl
,
duration
,
self
->
has_callback
,
cb_upp
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
struct
methodlist
ctbcm_methods
[]
=
{
{
"Open"
,
(
method
)
ctbcm_open
},
{
"Close"
,
(
method
)
ctbcm_close
},
{
"Read"
,
(
method
)
ctbcm_read
},
{
"Write"
,
(
method
)
ctbcm_write
},
{
"Status"
,
(
method
)
ctbcm_status
},
{
"GetConfig"
,
(
method
)
ctbcm_getconfig
},
{
"SetConfig"
,
(
method
)
ctbcm_setconfig
},
{
"Choose"
,
(
method
)
ctbcm_choose
},
{
"Idle"
,
(
method
)
ctbcm_idle
},
{
"Listen"
,
(
method
)
ctbcm_listen
},
{
"Accept"
,
(
method
)
ctbcm_accept
},
{
"Abort"
,
(
method
)
ctbcm_abort
},
{
"Reset"
,
(
method
)
ctbcm_reset
},
{
"Break"
,
(
method
)
ctbcm_break
},
static
struct
PyMethodDef
ctbcm_methods
[]
=
{
{
"Open"
,
(
PyCFunction
)
ctbcm_open
},
{
"Close"
,
(
PyCFunction
)
ctbcm_close
},
{
"Read"
,
(
PyCFunction
)
ctbcm_read
},
{
"Write"
,
(
PyCFunction
)
ctbcm_write
},
{
"Status"
,
(
PyCFunction
)
ctbcm_status
},
{
"GetConfig"
,
(
PyCFunction
)
ctbcm_getconfig
},
{
"SetConfig"
,
(
PyCFunction
)
ctbcm_setconfig
},
{
"Choose"
,
(
PyCFunction
)
ctbcm_choose
},
{
"Idle"
,
(
PyCFunction
)
ctbcm_idle
},
{
"Listen"
,
(
PyCFunction
)
ctbcm_listen
},
{
"Accept"
,
(
PyCFunction
)
ctbcm_accept
},
{
"Abort"
,
(
PyCFunction
)
ctbcm_abort
},
{
"Reset"
,
(
PyCFunction
)
ctbcm_reset
},
{
"Break"
,
(
PyCFunction
)
ctbcm_break
},
{
NULL
,
NULL
}
/* sentinel */
};
static
o
bject
*
static
PyO
bject
*
ctbcm_getattr
(
self
,
name
)
ctbcmobject
*
self
;
char
*
name
;
{
if
(
strcmp
(
name
,
"callback"
)
==
0
)
{
INCREF
(
self
->
callback
);
Py_
INCREF
(
self
->
callback
);
return
self
->
callback
;
}
return
findmethod
(
ctbcm_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
ctbcm_methods
,
(
PyO
bject
*
)
self
,
name
);
}
static
int
ctbcm_setattr
(
self
,
name
,
v
)
ctbcmobject
*
self
;
char
*
name
;
o
bject
*
v
;
PyO
bject
*
v
;
{
if
(
strcmp
(
name
,
"callback"
)
!=
0
)
{
err_setstr
(
AttributeError
,
"ctbcm objects have callback attr only"
);
PyErr_SetString
(
PyExc_
AttributeError
,
"ctbcm objects have callback attr only"
);
return
-
1
;
}
if
(
v
==
NULL
)
{
v
=
None
;
v
=
Py_
None
;
}
INCREF
(
v
);
/* XXXX Must I do this? */
Py_
INCREF
(
v
);
/* XXXX Must I do this? */
self
->
callback
=
v
;
self
->
has_callback
=
(
v
!=
None
);
self
->
has_callback
=
(
v
!=
Py_
None
);
return
0
;
}
statichere
typeo
bject
ctbcmtype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
statichere
PyTypeO
bject
ctbcmtype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"ctbcm"
,
/*tp_name*/
sizeof
(
ctbcmobject
),
/*tp_basicsize*/
...
...
@@ -467,13 +467,13 @@ statichere typeobject ctbcmtype = {
/* Function of no arguments returning new ctbcm object */
static
o
bject
*
static
PyO
bject
*
ctb_cmnew
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
int
strlen
;
o
bject
*
sizes_obj
;
PyO
bject
*
sizes_obj
;
char
*
c_str
;
unsigned
char
p_str
[
255
];
CMBufferSizes
sizes
;
...
...
@@ -481,16 +481,16 @@ ctb_cmnew(self, args)
ConnHandle
hdl
;
ctbcmobject
*
rv
;
if
(
!
getargs
(
args
,
"(s#O)"
,
&
c_str
,
&
strlen
,
&
sizes_obj
))
if
(
!
PyArg_Parse
(
args
,
"(s#O)"
,
&
c_str
,
&
strlen
,
&
sizes_obj
))
return
NULL
;
strncpy
((
char
*
)
p_str
+
1
,
c_str
,
strlen
);
p_str
[
0
]
=
strlen
;
if
(
!
initialize_ctb
())
return
NULL
;
if
(
sizes_obj
==
None
)
{
if
(
sizes_obj
==
Py_
None
)
{
memset
(
sizes
,
'\0'
,
sizeof
sizes
);
}
else
{
if
(
!
getargs
(
sizes_obj
,
"(llllll)"
,
&
sizes
[
0
],
&
sizes
[
1
],
&
sizes
[
2
],
if
(
!
PyArg_Parse
(
sizes_obj
,
"(llllll)"
,
&
sizes
[
0
],
&
sizes
[
1
],
&
sizes
[
2
],
&
sizes
[
3
],
&
sizes
[
4
],
&
sizes
[
5
]))
return
NULL
;
}
...
...
@@ -498,7 +498,7 @@ ctb_cmnew(self, args)
return
PyErr_Mac
(
ErrorObject
,
procid
);
hdl
=
CMNew
(
procid
,
cmNoMenus
|
cmQuiet
,
sizes
,
0
,
0
);
if
(
hdl
==
NULL
)
{
err_setstr
(
ErrorObject
,
"CMNew failed"
);
PyErr_SetString
(
ErrorObject
,
"CMNew failed"
);
return
NULL
;
}
rv
=
newctbcmobject
(
args
);
...
...
@@ -506,26 +506,26 @@ ctb_cmnew(self, args)
return
NULL
;
/* XXXX Should dispose of hdl */
rv
->
hdl
=
hdl
;
CMSetUserData
(
hdl
,
(
long
)
rv
);
return
(
o
bject
*
)
rv
;
return
(
PyO
bject
*
)
rv
;
}
static
o
bject
*
static
PyO
bject
*
ctb_available
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
ok
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
ok
=
initialize_ctb
();
err_c
lear
();
return
newintobject
(
ok
);
PyErr_C
lear
();
return
PyInt_FromLong
(
ok
);
}
/* List of functions defined in the module */
static
struct
methodlist
ctb_methods
[]
=
{
static
struct
PyMethodDef
ctb_methods
[]
=
{
{
"CMNew"
,
ctb_cmnew
},
{
"available"
,
ctb_available
},
{
NULL
,
NULL
}
/* sentinel */
...
...
@@ -537,15 +537,15 @@ static struct methodlist ctb_methods[] = {
void
initctb
()
{
o
bject
*
m
,
*
d
,
*
o
;
PyO
bject
*
m
,
*
d
,
*
o
;
/* Create the module and add the functions */
m
=
initm
odule
(
"ctb"
,
ctb_methods
);
m
=
Py_InitM
odule
(
"ctb"
,
ctb_methods
);
/* Add some symbolic constants to the module */
d
=
getmoduled
ict
(
m
);
d
=
PyModule_GetD
ict
(
m
);
#define CMCONST(name, value) o =
newintobject(value); dictinsert
(d, name, o)
#define CMCONST(name, value) o =
PyInt_FromLong(value); PyDict_SetItemString
(d, name, o)
CMCONST
(
"cmData"
,
1
);
CMCONST
(
"cmCntl"
,
2
);
...
...
@@ -576,10 +576,10 @@ initctb()
CMCONST
(
"cmStatusListenPend"
,
0x2000
);
CMCONST
(
"cmStatusIncomingCallPresent"
,
0x4000
);
ErrorObject
=
newstringobject
(
"ctb.error"
);
dictinsert
(
d
,
"error"
,
ErrorObject
);
ErrorObject
=
PyString_FromString
(
"ctb.error"
);
PyDict_SetItemString
(
d
,
"error"
,
ErrorObject
);
/* Check for errors */
if
(
err_o
ccurred
())
fatal
(
"can't initialize module ctb"
);
if
(
PyErr_O
ccurred
())
Py_FatalError
(
"can't initialize module ctb"
);
}
Mac/Modules/gestaltmodule.c
View file @
c42386ad
...
...
@@ -24,26 +24,25 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Macintosh Gestalt interface */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include <Types.h>
#include <GestaltEqu.h>
static
o
bject
*
static
PyO
bject
*
gestalt_gestalt
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
OSErr
iErr
;
char
*
str
;
int
size
;
OSType
selector
;
long
response
;
if
(
!
getargs
(
args
,
"s#"
,
&
str
,
&
size
))
if
(
!
PyArg_Parse
(
args
,
"s#"
,
&
str
,
&
size
))
return
NULL
;
if
(
size
!=
4
)
{
err_setstr
(
TypeError
,
"gestalt arg must be 4-char string"
);
PyErr_SetString
(
PyExc_
TypeError
,
"gestalt arg must be 4-char string"
);
return
NULL
;
}
selector
=
*
(
OSType
*
)
str
;
...
...
@@ -51,13 +50,13 @@ gestalt_gestalt(self, args)
if
(
iErr
!=
0
)
{
char
buf
[
100
];
sprintf
(
buf
,
"Gestalt error code %d"
,
iErr
);
err_setstr
(
RuntimeError
,
buf
);
PyErr_SetString
(
PyExc_
RuntimeError
,
buf
);
return
NULL
;
}
return
newintobject
(
response
);
return
PyInt_FromLong
(
response
);
}
static
struct
methodlist
gestalt_methods
[]
=
{
static
struct
PyMethodDef
gestalt_methods
[]
=
{
{
"gestalt"
,
gestalt_gestalt
},
{
NULL
,
NULL
}
/* Sentinel */
};
...
...
@@ -65,5 +64,5 @@ static struct methodlist gestalt_methods[] = {
void
initgestalt
()
{
initm
odule
(
"gestalt"
,
gestalt_methods
);
Py_InitM
odule
(
"gestalt"
,
gestalt_methods
);
}
Mac/Modules/macfsmodule.c
View file @
c42386ad
...
...
@@ -22,8 +22,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
******************************************************************/
#include "allobjects.h"
#include "modsupport.h"
/* For getargs() etc. */
#include "Python.h"
#include "macglue.h"
#include <Memory.h>
...
...
@@ -39,17 +38,17 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#define FileFilterUPP FileFilterProcPtr
#endif
static
o
bject
*
ErrorObject
;
static
PyO
bject
*
ErrorObject
;
/* ----------------------------------------------------- */
/* Declarations for objects of type Alias */
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
AliasHandle
alias
;
}
mfsaobject
;
staticforward
typeo
bject
Mfsatype
;
staticforward
PyTypeO
bject
Mfsatype
;
#define is_mfsaobject(v) ((v)->ob_type == &Mfsatype)
...
...
@@ -57,11 +56,11 @@ staticforward typeobject Mfsatype;
/* Declarations for objects of type FSSpec */
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
FSSpec
fsspec
;
}
mfssobject
;
staticforward
typeo
bject
Mfsstype
;
staticforward
PyTypeO
bject
Mfsstype
;
#define is_mfssobject(v) ((v)->ob_type == &Mfsstype)
...
...
@@ -70,11 +69,11 @@ staticforward typeobject Mfsstype;
/* Declarations for objects of type FInfo */
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
FInfo
finfo
;
}
mfsiobject
;
staticforward
typeo
bject
Mfsitype
;
staticforward
PyTypeO
bject
Mfsitype
;
#define is_mfsiobject(v) ((v)->ob_type == &Mfsitype)
...
...
@@ -83,17 +82,17 @@ mfssobject *newmfssobject(FSSpec *fss); /* Forward */
/* ---------------------------------------------------------------- */
static
o
bject
*
static
PyO
bject
*
mfsa_Resolve
(
self
,
args
)
mfsaobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
FSSpec
from
,
*
fromp
,
result
;
Boolean
changed
;
OSErr
err
;
from
.
name
[
0
]
=
0
;
if
(
!
newgetargs
(
args
,
"|O&"
,
PyMac_GetFSSpec
,
&
from
))
if
(
!
PyArg_ParseTuple
(
args
,
"|O&"
,
PyMac_GetFSSpec
,
&
from
))
return
NULL
;
if
(
from
.
name
[
0
]
)
fromp
=
&
from
;
...
...
@@ -104,39 +103,39 @@ mfsa_Resolve(self, args)
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
return
mkv
alue
(
"(Oi)"
,
newmfssobject
(
&
result
),
(
int
)
changed
);
return
Py_BuildV
alue
(
"(Oi)"
,
newmfssobject
(
&
result
),
(
int
)
changed
);
}
static
o
bject
*
static
PyO
bject
*
mfsa_GetInfo
(
self
,
args
)
mfsaobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
Str63
value
;
int
i
;
OSErr
err
;
if
(
!
newgetargs
(
args
,
"i"
,
&
i
))
if
(
!
PyArg_ParseTuple
(
args
,
"i"
,
&
i
))
return
NULL
;
err
=
GetAliasInfo
(
self
->
alias
,
(
AliasInfoType
)
i
,
value
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
return
0
;
}
return
newsizedstringobject
((
char
*
)
&
value
[
1
],
value
[
0
]);
return
PyString_FromStringAndSize
((
char
*
)
&
value
[
1
],
value
[
0
]);
}
static
o
bject
*
static
PyO
bject
*
mfsa_Update
(
self
,
args
)
mfsaobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
FSSpec
target
,
fromfile
,
*
fromfilep
;
OSErr
err
;
Boolean
changed
;
fromfile
.
name
[
0
]
=
0
;
if
(
!
newgetargs
(
args
,
"O&|O&"
,
PyMac_GetFSSpec
,
&
target
,
if
(
!
PyArg_ParseTuple
(
args
,
"O&|O&"
,
PyMac_GetFSSpec
,
&
target
,
PyMac_GetFSSpec
,
&
fromfile
))
return
NULL
;
if
(
fromfile
.
name
[
0
]
)
...
...
@@ -148,20 +147,20 @@ mfsa_Update(self, args)
PyErr_Mac
(
ErrorObject
,
err
);
return
0
;
}
return
mkv
alue
(
"i"
,
(
int
)
changed
);
return
Py_BuildV
alue
(
"i"
,
(
int
)
changed
);
}
static
struct
methodlist
mfsa_methods
[]
=
{
{
"Resolve"
,
(
method
)
mfsa_Resolve
,
1
},
{
"GetInfo"
,
(
method
)
mfsa_GetInfo
,
1
},
{
"Update"
,
(
method
)
mfsa_Update
,
1
},
static
struct
PyMethodDef
mfsa_methods
[]
=
{
{
"Resolve"
,
(
PyCFunction
)
mfsa_Resolve
,
1
},
{
"GetInfo"
,
(
PyCFunction
)
mfsa_GetInfo
,
1
},
{
"Update"
,
(
PyCFunction
)
mfsa_Update
,
1
},
{
NULL
,
NULL
}
/* sentinel */
};
/* ---------- */
static
o
bject
*
static
PyO
bject
*
mfsa_getattr
(
self
,
name
)
mfsaobject
*
self
;
char
*
name
;
...
...
@@ -176,7 +175,7 @@ mfsa_getattr(self, name)
HUnlock
((
Handle
)
self
->
alias
);
return
rv
;
}
return
findmethod
(
mfsa_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
mfsa_methods
,
(
PyO
bject
*
)
self
,
name
);
}
mfsaobject
*
...
...
@@ -185,7 +184,7 @@ newmfsaobject(alias)
{
mfsaobject
*
self
;
self
=
NEWOBJ
(
mfsaobject
,
&
Mfsatype
);
self
=
PyObject_NEW
(
mfsaobject
,
&
Mfsatype
);
if
(
self
==
NULL
)
return
NULL
;
self
->
alias
=
alias
;
...
...
@@ -203,11 +202,11 @@ mfsa_dealloc(self)
}
#endif
DEL
(
self
);
PyMem_
DEL
(
self
);
}
statichere
typeo
bject
Mfsatype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
statichere
PyTypeO
bject
Mfsatype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"Alias"
,
/*tp_name*/
sizeof
(
mfsaobject
),
/*tp_basicsize*/
...
...
@@ -230,7 +229,7 @@ statichere typeobject Mfsatype = {
/* ---------------------------------------------------------------- */
static
struct
methodlist
mfsi_methods
[]
=
{
static
struct
PyMethodDef
mfsi_methods
[]
=
{
{
NULL
,
NULL
}
/* sentinel */
};
...
...
@@ -242,7 +241,7 @@ newmfsiobject()
{
mfsiobject
*
self
;
self
=
NEWOBJ
(
mfsiobject
,
&
Mfsitype
);
self
=
PyObject_NEW
(
mfsiobject
,
&
Mfsitype
);
if
(
self
==
NULL
)
return
NULL
;
memset
((
char
*
)
&
self
->
finfo
,
'\0'
,
sizeof
(
self
->
finfo
));
...
...
@@ -253,10 +252,10 @@ static void
mfsi_dealloc
(
self
)
mfsiobject
*
self
;
{
DEL
(
self
);
PyMem_
DEL
(
self
);
}
static
o
bject
*
static
PyO
bject
*
mfsi_getattr
(
self
,
name
)
mfsiobject
*
self
;
char
*
name
;
...
...
@@ -272,7 +271,7 @@ mfsi_getattr(self, name)
else
if
(
strcmp
(
name
,
"Fldr"
)
==
0
)
return
Py_BuildValue
(
"i"
,
(
int
)
self
->
finfo
.
fdFldr
);
else
return
findmethod
(
mfsi_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
mfsi_methods
,
(
PyO
bject
*
)
self
,
name
);
}
...
...
@@ -280,13 +279,13 @@ static int
mfsi_setattr
(
self
,
name
,
v
)
mfsiobject
*
self
;
char
*
name
;
o
bject
*
v
;
PyO
bject
*
v
;
{
int
rv
;
int
i
;
if
(
v
==
NULL
)
{
err_setstr
(
AttributeError
,
"Cannot delete attribute"
);
PyErr_SetString
(
PyExc_
AttributeError
,
"Cannot delete attribute"
);
return
-
1
;
}
if
(
strcmp
(
name
,
"Type"
)
==
0
)
...
...
@@ -302,7 +301,7 @@ mfsi_setattr(self, name, v)
rv
=
PyArg_Parse
(
v
,
"i"
,
&
i
);
self
->
finfo
.
fdFldr
=
(
short
)
i
;
}
else
{
err_setstr
(
AttributeError
,
"No such attribute"
);
PyErr_SetString
(
PyExc_
AttributeError
,
"No such attribute"
);
return
-
1
;
}
if
(
rv
)
...
...
@@ -311,8 +310,8 @@ mfsi_setattr(self, name, v)
}
static
typeo
bject
Mfsitype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
static
PyTypeO
bject
Mfsitype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"FInfo object"
,
/*tp_name*/
sizeof
(
mfsiobject
),
/*tp_basicsize*/
...
...
@@ -340,7 +339,7 @@ static typeobject Mfsitype = {
*/
FSSpec
*
mfs_GetFSSpecFSSpec
(
self
)
o
bject
*
self
;
PyO
bject
*
self
;
{
if
(
is_mfssobject
(
self
)
)
return
&
((
mfssobject
*
)
self
)
->
fsspec
;
...
...
@@ -395,46 +394,46 @@ PyMac_SetFileDates(fss, crdat, mddat, bkdat)
return
error
;
}
static
o
bject
*
static
PyO
bject
*
mfss_as_pathname
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
char
strbuf
[
257
];
OSErr
err
;
if
(
!
newgetargs
(
args
,
""
))
if
(
!
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
err
=
PyMac_GetFullPath
(
&
self
->
fsspec
,
strbuf
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
return
newstringobject
(
strbuf
);
return
PyString_FromString
(
strbuf
);
}
static
o
bject
*
static
PyO
bject
*
mfss_as_tuple
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
newgetargs
(
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
o
bject
*
static
PyO
bject
*
mfss_NewAlias
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
FSSpec
src
,
*
srcp
;
OSErr
err
;
AliasHandle
alias
;
src
.
name
[
0
]
=
0
;
if
(
!
newgetargs
(
args
,
"|O&"
,
PyMac_GetFSSpec
,
&
src
))
if
(
!
PyArg_ParseTuple
(
args
,
"|O&"
,
PyMac_GetFSSpec
,
&
src
))
return
NULL
;
if
(
src
.
name
[
0
]
)
srcp
=
&
src
;
...
...
@@ -446,37 +445,37 @@ mfss_NewAlias(self, args)
return
NULL
;
}
return
(
o
bject
*
)
newmfsaobject
(
alias
);
return
(
PyO
bject
*
)
newmfsaobject
(
alias
);
}
static
o
bject
*
static
PyO
bject
*
mfss_NewAliasMinimal
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
AliasHandle
alias
;
if
(
!
newgetargs
(
args
,
""
))
if
(
!
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
err
=
NewAliasMinimal
(
&
self
->
fsspec
,
&
alias
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
return
(
o
bject
*
)
newmfsaobject
(
alias
);
return
(
PyO
bject
*
)
newmfsaobject
(
alias
);
}
/* XXXX These routines should be replaced by a wrapper to the *FInfo routines */
static
o
bject
*
static
PyO
bject
*
mfss_GetCreatorType
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
FInfo
info
;
if
(
!
newgetargs
(
args
,
""
))
if
(
!
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
err
=
FSpGetFInfo
(
&
self
->
fsspec
,
&
info
);
if
(
err
)
{
...
...
@@ -487,16 +486,16 @@ mfss_GetCreatorType(self, args)
PyMac_BuildOSType
,
info
.
fdCreator
,
PyMac_BuildOSType
,
info
.
fdType
);
}
static
o
bject
*
static
PyO
bject
*
mfss_SetCreatorType
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
OSType
creator
,
type
;
FInfo
info
;
if
(
!
newgetargs
(
args
,
"O&O&"
,
PyMac_GetOSType
,
&
creator
,
PyMac_GetOSType
,
&
type
))
if
(
!
PyArg_ParseTuple
(
args
,
"O&O&"
,
PyMac_GetOSType
,
&
creator
,
PyMac_GetOSType
,
&
type
))
return
NULL
;
err
=
FSpGetFInfo
(
&
self
->
fsspec
,
&
info
);
if
(
err
)
{
...
...
@@ -510,78 +509,78 @@ mfss_SetCreatorType(self, args)
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mfss_GetFInfo
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
mfsiobject
*
fip
;
if
(
!
newgetargs
(
args
,
""
))
if
(
!
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
if
(
(
fip
=
newmfsiobject
())
==
NULL
)
return
NULL
;
err
=
FSpGetFInfo
(
&
self
->
fsspec
,
&
fip
->
finfo
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
DECREF
(
fip
);
Py_
DECREF
(
fip
);
return
NULL
;
}
return
(
o
bject
*
)
fip
;
return
(
PyO
bject
*
)
fip
;
}
static
o
bject
*
static
PyO
bject
*
mfss_SetFInfo
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
mfsiobject
*
fip
;
if
(
!
newgetargs
(
args
,
"O!"
,
&
Mfsitype
,
&
fip
))
if
(
!
PyArg_ParseTuple
(
args
,
"O!"
,
&
Mfsitype
,
&
fip
))
return
NULL
;
err
=
FSpSetFInfo
(
&
self
->
fsspec
,
&
fip
->
finfo
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mfss_GetDates
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
unsigned
long
crdat
,
mddat
,
bkdat
;
if
(
!
newgetargs
(
args
,
""
))
if
(
!
PyArg_ParseTuple
(
args
,
""
))
return
NULL
;
err
=
PyMac_GetFileDates
(
&
self
->
fsspec
,
&
crdat
,
&
mddat
,
&
bkdat
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
return
mkv
alue
(
"ddd"
,
(
double
)
crdat
,
(
double
)
mddat
,
(
double
)
bkdat
);
return
Py_BuildV
alue
(
"ddd"
,
(
double
)
crdat
,
(
double
)
mddat
,
(
double
)
bkdat
);
}
static
o
bject
*
static
PyO
bject
*
mfss_SetDates
(
self
,
args
)
mfssobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
double
crdat
,
mddat
,
bkdat
;
if
(
!
newgetargs
(
args
,
"ddd"
,
&
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
);
...
...
@@ -589,35 +588,35 @@ mfss_SetDates(self, args)
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
INCREF
(
None
);
return
None
;
}
static
struct
methodlist
mfss_methods
[]
=
{
{
"as_pathname"
,
(
method
)
mfss_as_pathname
,
1
},
{
"as_tuple"
,
(
method
)
mfss_as_tuple
,
1
},
{
"NewAlias"
,
(
method
)
mfss_NewAlias
,
1
},
{
"NewAliasMinimal"
,
(
method
)
mfss_NewAliasMinimal
,
1
},
{
"GetCreatorType"
,
(
method
)
mfss_GetCreatorType
,
1
},
{
"SetCreatorType"
,
(
method
)
mfss_SetCreatorType
,
1
},
{
"GetFInfo"
,
(
method
)
mfss_GetFInfo
,
1
},
{
"SetFInfo"
,
(
method
)
mfss_SetFInfo
,
1
},
{
"GetDates"
,
(
method
)
mfss_GetDates
,
1
},
{
"SetDates"
,
(
method
)
mfss_SetDates
,
1
},
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
},
{
"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
o
bject
*
static
PyO
bject
*
mfss_getattr
(
self
,
name
)
mfssobject
*
self
;
char
*
name
;
{
if
(
strcmp
(
name
,
"data"
)
==
0
)
return
PyString_FromStringAndSize
((
char
*
)
&
self
->
fsspec
,
sizeof
(
FSSpec
));
return
findmethod
(
mfss_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
mfss_methods
,
(
PyO
bject
*
)
self
,
name
);
}
mfssobject
*
...
...
@@ -626,7 +625,7 @@ newmfssobject(fss)
{
mfssobject
*
self
;
self
=
NEWOBJ
(
mfssobject
,
&
Mfsstype
);
self
=
PyObject_NEW
(
mfssobject
,
&
Mfsstype
);
if
(
self
==
NULL
)
return
NULL
;
self
->
fsspec
=
*
fss
;
...
...
@@ -637,10 +636,10 @@ static void
mfss_dealloc
(
self
)
mfssobject
*
self
;
{
DEL
(
self
);
PyMem_
DEL
(
self
);
}
static
o
bject
*
static
PyO
bject
*
mfss_repr
(
self
)
mfssobject
*
self
;
{
...
...
@@ -650,7 +649,7 @@ mfss_repr(self)
self
->
fsspec
.
vRefNum
,
self
->
fsspec
.
parID
,
self
->
fsspec
.
name
[
0
],
self
->
fsspec
.
name
+
1
);
return
newstringobject
(
buf
);
return
PyString_FromString
(
buf
);
}
static
int
...
...
@@ -673,8 +672,8 @@ mfss_compare(v, w)
return
res
;
}
statichere
typeo
bject
Mfsstype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
statichere
PyTypeO
bject
Mfsstype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"FSSpec"
,
/*tp_name*/
sizeof
(
mfssobject
),
/*tp_basicsize*/
...
...
@@ -695,29 +694,29 @@ statichere typeobject Mfsstype = {
/* End of code for FSSpec objects */
/* -------------------------------------------------------- */
static
o
bject
*
static
PyO
bject
*
mfs_ResolveAliasFile
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
FSSpec
fss
;
Boolean
chain
=
1
,
isfolder
,
wasaliased
;
OSErr
err
;
if
(
!
newgetargs
(
args
,
"O&|i"
,
PyMac_GetFSSpec
,
&
fss
,
&
chain
))
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
mkv
alue
(
"Oii"
,
newmfssobject
(
&
fss
),
(
int
)
isfolder
,
(
int
)
wasaliased
);
return
Py_BuildV
alue
(
"Oii"
,
newmfssobject
(
&
fss
),
(
int
)
isfolder
,
(
int
)
wasaliased
);
}
static
o
bject
*
static
PyO
bject
*
mfs_StandardGetFile
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
SFTypeList
list
;
short
numtypes
;
...
...
@@ -725,7 +724,7 @@ mfs_StandardGetFile(self, args)
list
[
0
]
=
list
[
1
]
=
list
[
2
]
=
list
[
3
]
=
0
;
numtypes
=
0
;
if
(
!
newgetargs
(
args
,
"|O&O&O&O&"
,
PyMac_GetOSType
,
&
list
[
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
;
...
...
@@ -735,13 +734,13 @@ mfs_StandardGetFile(self, args)
if
(
numtypes
==
0
)
numtypes
=
-
1
;
StandardGetFile
((
FileFilterUPP
)
0
,
numtypes
,
list
,
&
reply
);
return
mkv
alue
(
"(Oi)"
,
newmfssobject
(
&
reply
.
sfFile
),
reply
.
sfGood
);
return
Py_BuildV
alue
(
"(Oi)"
,
newmfssobject
(
&
reply
.
sfFile
),
reply
.
sfGood
);
}
static
o
bject
*
static
PyO
bject
*
mfs_PromptGetFile
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
SFTypeList
list
;
short
numtypes
;
...
...
@@ -750,7 +749,7 @@ mfs_PromptGetFile(self, args)
list
[
0
]
=
list
[
1
]
=
list
[
2
]
=
list
[
3
]
=
0
;
numtypes
=
0
;
if
(
!
newgetargs
(
args
,
"s|O&O&O&O&"
,
&
prompt
,
PyMac_GetOSType
,
&
list
[
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
;
...
...
@@ -760,30 +759,30 @@ mfs_PromptGetFile(self, args)
if
(
numtypes
==
0
)
numtypes
=
-
1
;
PyMac_PromptGetFile
(
numtypes
,
list
,
&
reply
,
prompt
);
return
mkv
alue
(
"(Oi)"
,
newmfssobject
(
&
reply
.
sfFile
),
reply
.
sfGood
);
return
Py_BuildV
alue
(
"(Oi)"
,
newmfssobject
(
&
reply
.
sfFile
),
reply
.
sfGood
);
}
static
o
bject
*
static
PyO
bject
*
mfs_StandardPutFile
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
Str255
prompt
,
dft
;
StandardFileReply
reply
;
dft
[
0
]
=
0
;
if
(
!
newgetargs
(
args
,
"O&|O&"
,
PyMac_GetStr255
,
&
prompt
,
PyMac_GetStr255
,
&
dft
)
)
if
(
!
PyArg_ParseTuple
(
args
,
"O&|O&"
,
PyMac_GetStr255
,
&
prompt
,
PyMac_GetStr255
,
&
dft
)
)
return
NULL
;
StandardPutFile
(
prompt
,
dft
,
&
reply
);
return
mkv
alue
(
"(Oi)"
,
newmfssobject
(
&
reply
.
sfFile
),
reply
.
sfGood
);
return
Py_BuildV
alue
(
"(Oi)"
,
newmfssobject
(
&
reply
.
sfFile
),
reply
.
sfGood
);
}
/*
** Set initial directory for file dialogs */
static
o
bject
*
static
PyO
bject
*
mfs_SetFolder
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
FSSpec
spec
;
FSSpec
ospec
;
...
...
@@ -797,53 +796,53 @@ mfs_SetFolder(self, args)
/* Go to working directory by default */
(
void
)
FSMakeFSSpec
(
0
,
0
,
"\p:placeholder"
,
&
spec
);
if
(
!
newgetargs
(
args
,
"|O&"
,
PyMac_GetFSSpec
,
&
spec
))
if
(
!
PyArg_ParseTuple
(
args
,
"|O&"
,
PyMac_GetFSSpec
,
&
spec
))
return
NULL
;
/* Set standard-file working directory */
LMSetSFSaveDisk
(
-
spec
.
vRefNum
);
LMSetCurDirStore
(
spec
.
parID
);
return
(
o
bject
*
)
newmfssobject
(
&
ospec
);
return
(
PyO
bject
*
)
newmfssobject
(
&
ospec
);
}
static
o
bject
*
static
PyO
bject
*
mfs_FSSpec
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
FSSpec
fss
;
if
(
!
newgetargs
(
args
,
"O&"
,
PyMac_GetFSSpec
,
&
fss
))
if
(
!
PyArg_ParseTuple
(
args
,
"O&"
,
PyMac_GetFSSpec
,
&
fss
))
return
NULL
;
return
(
o
bject
*
)
newmfssobject
(
&
fss
);
return
(
PyO
bject
*
)
newmfssobject
(
&
fss
);
}
static
o
bject
*
static
PyO
bject
*
mfs_RawFSSpec
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
FSSpec
*
fssp
;
int
size
;
if
(
!
newgetargs
(
args
,
"s#"
,
&
fssp
,
&
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
(
o
bject
*
)
newmfssobject
(
fssp
);
return
(
PyO
bject
*
)
newmfssobject
(
fssp
);
}
static
o
bject
*
static
PyO
bject
*
mfs_RawAlias
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
char
*
dataptr
;
Handle
h
;
int
size
;
if
(
!
newgetargs
(
args
,
"s#"
,
&
dataptr
,
&
size
))
if
(
!
PyArg_ParseTuple
(
args
,
"s#"
,
&
dataptr
,
&
size
))
return
NULL
;
h
=
NewHandle
(
size
);
if
(
h
==
NULL
)
{
...
...
@@ -853,29 +852,29 @@ mfs_RawAlias(self, args)
HLock
(
h
);
memcpy
((
char
*
)
*
h
,
dataptr
,
size
);
HUnlock
(
h
);
return
(
o
bject
*
)
newmfsaobject
((
AliasHandle
)
h
);
return
(
PyO
bject
*
)
newmfsaobject
((
AliasHandle
)
h
);
}
static
o
bject
*
static
PyO
bject
*
mfs_GetDirectory
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
FSSpec
fsdir
;
int
ok
;
char
*
prompt
=
NULL
;
if
(
!
newgetargs
(
args
,
"|s"
,
&
prompt
)
)
if
(
!
PyArg_ParseTuple
(
args
,
"|s"
,
&
prompt
)
)
return
NULL
;
ok
=
PyMac_GetDirectory
(
&
fsdir
,
prompt
);
return
mkv
alue
(
"(Oi)"
,
newmfssobject
(
&
fsdir
),
ok
);
return
Py_BuildV
alue
(
"(Oi)"
,
newmfssobject
(
&
fsdir
),
ok
);
}
static
o
bject
*
static
PyO
bject
*
mfs_FindFolder
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
OSErr
err
;
short
where
;
...
...
@@ -884,46 +883,46 @@ mfs_FindFolder(self, args)
short
refnum
;
long
dirid
;
if
(
!
newgetargs
(
args
,
"hO&i"
,
&
where
,
PyMac_GetOSType
,
&
which
,
&
create
)
)
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
mkv
alue
(
"(ii)"
,
refnum
,
dirid
);
return
Py_BuildV
alue
(
"(ii)"
,
refnum
,
dirid
);
}
static
o
bject
*
static
PyO
bject
*
mfs_FindApplication
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
OSErr
err
;
OSType
which
;
FSSpec
fss
;
if
(
!
newgetargs
(
args
,
"O&"
,
PyMac_GetOSType
,
&
which
)
)
if
(
!
PyArg_ParseTuple
(
args
,
"O&"
,
PyMac_GetOSType
,
&
which
)
)
return
NULL
;
err
=
FindApplicationFromCreator
(
which
,
&
fss
);
if
(
err
)
{
PyErr_Mac
(
ErrorObject
,
err
);
return
NULL
;
}
return
(
o
bject
*
)
newmfssobject
(
&
fss
);
return
(
PyO
bject
*
)
newmfssobject
(
&
fss
);
}
static
o
bject
*
static
PyO
bject
*
mfs_FInfo
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
return
(
o
bject
*
)
newmfsiobject
();
return
(
PyO
bject
*
)
newmfsiobject
();
}
/* List of methods defined in the module */
static
struct
methodlist
mfs_methods
[]
=
{
static
struct
PyMethodDef
mfs_methods
[]
=
{
{
"ResolveAliasFile"
,
mfs_ResolveAliasFile
,
1
},
{
"StandardGetFile"
,
mfs_StandardGetFile
,
1
},
{
"PromptGetFile"
,
mfs_PromptGetFile
,
1
},
...
...
@@ -946,19 +945,19 @@ static struct methodlist mfs_methods[] = {
void
initmacfs
()
{
o
bject
*
m
,
*
d
;
PyO
bject
*
m
,
*
d
;
/* Create the module and add the functions */
m
=
initm
odule
(
"macfs"
,
mfs_methods
);
m
=
Py_InitM
odule
(
"macfs"
,
mfs_methods
);
/* Add some symbolic constants to the module */
d
=
getmoduled
ict
(
m
);
ErrorObject
=
newstringobject
(
"macfs.error"
);
dictinsert
(
d
,
"error"
,
ErrorObject
);
d
=
PyModule_GetD
ict
(
m
);
ErrorObject
=
PyString_FromString
(
"macfs.error"
);
PyDict_SetItemString
(
d
,
"error"
,
ErrorObject
);
/* XXXX Add constants here */
/* Check for errors */
if
(
err_o
ccurred
())
fatal
(
"can't initialize module macfs"
);
if
(
PyErr_O
ccurred
())
Py_FatalError
(
"can't initialize module macfs"
);
}
Mac/Modules/macmodule.c
View file @
c42386ad
...
...
@@ -24,8 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* Mac module implementation */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include "ceval.h"
#include <stdio.h>
...
...
@@ -89,100 +88,100 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
#ifndef USE_GUSI
int
chdir
PROTO
((
const
char
*
path
));
int
mkdir
PROTO
((
const
char
*
path
,
int
mode
));
DIR
*
opendir
PROTO
((
char
*
));
void
closedir
PROTO
((
DIR
*
));
struct
dirent
*
readdir
PROTO
((
DIR
*
));
int
rmdir
PROTO
((
const
char
*
path
));
int
sync
PROTO
((
void
));
int
chdir
P
y_P
ROTO
((
const
char
*
path
));
int
mkdir
P
y_P
ROTO
((
const
char
*
path
,
int
mode
));
DIR
*
opendir
P
y_P
ROTO
((
char
*
));
void
closedir
P
y_P
ROTO
((
DIR
*
));
struct
dirent
*
readdir
P
y_P
ROTO
((
DIR
*
));
int
rmdir
P
y_P
ROTO
((
const
char
*
path
));
int
sync
P
y_P
ROTO
((
void
));
#if defined(THINK_C) || defined(__SC__)
int
unlink
PROTO
((
char
*
));
int
unlink
P
y_P
ROTO
((
char
*
));
#else
int
unlink
PROTO
((
const
char
*
));
int
unlink
P
y_P
ROTO
((
const
char
*
));
#endif
#endif
/* USE_GUSI */
char
*
getwd
PROTO
((
char
*
));
char
*
getbootvol
PROTO
((
void
));
char
*
getwd
P
y_P
ROTO
((
char
*
));
char
*
getbootvol
P
y_P
ROTO
((
void
));
static
o
bject
*
MacError
;
/* Exception mac.error */
static
PyO
bject
*
MacError
;
/* Exception mac.error */
/* Set a MAC-specific error from errno, and return NULL */
static
o
bject
*
static
PyO
bject
*
mac_error
()
{
return
err_e
rrno
(
MacError
);
return
PyErr_SetFromE
rrno
(
MacError
);
}
/* MAC generic methods */
static
o
bject
*
static
PyO
bject
*
mac_1str
(
args
,
func
)
o
bject
*
args
;
int
(
*
func
)
FPROTO
((
const
char
*
));
PyO
bject
*
args
;
int
(
*
func
)
Py_
FPROTO
((
const
char
*
));
{
char
*
path1
;
int
res
;
if
(
!
getargs
(
args
,
"s"
,
&
path1
))
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
path1
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
(
*
func
)(
path1
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
<
0
)
return
mac_error
();
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mac_2str
(
args
,
func
)
o
bject
*
args
;
int
(
*
func
)
FPROTO
((
const
char
*
,
const
char
*
));
PyO
bject
*
args
;
int
(
*
func
)
Py_
FPROTO
((
const
char
*
,
const
char
*
));
{
char
*
path1
,
*
path2
;
int
res
;
if
(
!
getargs
(
args
,
"(ss)"
,
&
path1
,
&
path2
))
if
(
!
PyArg_Parse
(
args
,
"(ss)"
,
&
path1
,
&
path2
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
(
*
func
)(
path1
,
path2
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
<
0
)
return
mac_error
();
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mac_strint
(
args
,
func
)
o
bject
*
args
;
int
(
*
func
)
FPROTO
((
const
char
*
,
int
));
PyO
bject
*
args
;
int
(
*
func
)
Py_
FPROTO
((
const
char
*
,
int
));
{
char
*
path
;
int
i
;
int
res
;
if
(
!
getargs
(
args
,
"(si)"
,
&
path
,
&
i
))
if
(
!
PyArg_Parse
(
args
,
"(si)"
,
&
path
,
&
i
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
(
*
func
)(
path
,
i
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
<
0
)
return
mac_error
();
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mac_chdir
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
#ifdef USE_GUSI
o
bject
*
rv
;
PyO
bject
*
rv
;
/* Change MacOS's idea of wd too */
rv
=
mac_1str
(
args
,
chdir
);
...
...
@@ -194,264 +193,264 @@ mac_chdir(self, args)
}
static
o
bject
*
static
PyO
bject
*
mac_close
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
fd
,
res
;
if
(
!
getargs
(
args
,
"i"
,
&
fd
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
fd
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
close
(
fd
);
END_SAVE
Py_END_ALLOW_THREADS
#ifndef USE_GUSI
/* GUSI gives surious errors here? */
if
(
res
<
0
)
return
mac_error
();
#endif
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
#ifdef WEHAVE_DUP
static
o
bject
*
static
PyO
bject
*
mac_dup
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
fd
;
if
(
!
getargs
(
args
,
"i"
,
&
fd
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
fd
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
fd
=
dup
(
fd
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
fd
<
0
)
return
mac_error
();
return
newintobject
((
long
)
fd
);
return
PyInt_FromLong
((
long
)
fd
);
}
#endif
#ifdef WEHAVE_FDOPEN
static
o
bject
*
static
PyO
bject
*
mac_fdopen
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
extern
int
fclose
PROTO
((
FILE
*
));
extern
int
fclose
P
y_P
ROTO
((
FILE
*
));
int
fd
;
char
*
mode
;
FILE
*
fp
;
if
(
!
getargs
(
args
,
"(is)"
,
&
fd
,
&
mode
))
if
(
!
PyArg_Parse
(
args
,
"(is)"
,
&
fd
,
&
mode
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
fp
=
fdopen
(
fd
,
mode
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
fp
==
NULL
)
return
mac_error
();
return
newopenfileobject
(
fp
,
"(fdopen)"
,
mode
,
fclose
);
return
PyFile_FromFile
(
fp
,
"(fdopen)"
,
mode
,
fclose
);
}
#endif
static
o
bject
*
static
PyO
bject
*
mac_getbootvol
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
*
res
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
getbootvol
();
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
==
NULL
)
return
mac_error
();
return
newstringobject
(
res
);
return
PyString_FromString
(
res
);
}
static
o
bject
*
static
PyO
bject
*
mac_getcwd
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
path
[
MAXPATHLEN
];
char
*
res
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GUSI
res
=
getcwd
(
path
,
sizeof
path
);
#else
res
=
getwd
(
path
);
#endif
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
==
NULL
)
{
err_setstr
(
MacError
,
path
);
PyErr_SetString
(
MacError
,
path
);
return
NULL
;
}
return
newstringobject
(
res
);
return
PyString_FromString
(
res
);
}
static
o
bject
*
static
PyO
bject
*
mac_listdir
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
*
name
;
o
bject
*
d
,
*
v
;
PyO
bject
*
d
,
*
v
;
DIR
*
dirp
;
struct
dirent
*
ep
;
if
(
!
getargs
(
args
,
"s"
,
&
name
))
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
name
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
if
((
dirp
=
opendir
(
name
))
==
NULL
)
{
RET_SAVE
Py_BLOCK_THREADS
return
mac_error
();
}
if
((
d
=
newlistobject
(
0
))
==
NULL
)
{
if
((
d
=
PyList_New
(
0
))
==
NULL
)
{
closedir
(
dirp
);
RET_SAVE
Py_BLOCK_THREADS
return
NULL
;
}
while
((
ep
=
readdir
(
dirp
))
!=
NULL
)
{
v
=
newstringobject
(
ep
->
d_name
);
v
=
PyString_FromString
(
ep
->
d_name
);
if
(
v
==
NULL
)
{
DECREF
(
d
);
Py_
DECREF
(
d
);
d
=
NULL
;
break
;
}
if
(
addlistitem
(
d
,
v
)
!=
0
)
{
DECREF
(
v
);
DECREF
(
d
);
if
(
PyList_Append
(
d
,
v
)
!=
0
)
{
Py_
DECREF
(
v
);
Py_
DECREF
(
d
);
d
=
NULL
;
break
;
}
DECREF
(
v
);
Py_
DECREF
(
v
);
}
closedir
(
dirp
);
END_SAVE
Py_END_ALLOW_THREADS
return
d
;
}
static
o
bject
*
static
PyO
bject
*
mac_lseek
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
fd
;
int
where
;
int
how
;
long
res
;
if
(
!
getargs
(
args
,
"(iii)"
,
&
fd
,
&
where
,
&
how
))
if
(
!
PyArg_Parse
(
args
,
"(iii)"
,
&
fd
,
&
where
,
&
how
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
lseek
(
fd
,
(
long
)
where
,
how
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
<
0
)
return
mac_error
();
return
newintobject
(
res
);
return
PyInt_FromLong
(
res
);
}
static
o
bject
*
static
PyO
bject
*
mac_mkdir
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
res
;
char
*
path
;
int
mode
=
0777
;
/* Unused */
if
(
!
newgetargs
(
args
,
"s|i"
,
&
path
,
&
mode
))
if
(
!
PyArg_ParseTuple
(
args
,
"s|i"
,
&
path
,
&
mode
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
#ifdef USE_GUSI
res
=
mkdir
(
path
);
#else
res
=
mkdir
(
path
,
mode
);
#endif
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
<
0
)
return
mac_error
();
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mac_open
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
char
*
path
;
int
mode
;
int
fd
;
if
(
!
getargs
(
args
,
"(si)"
,
&
path
,
&
mode
))
if
(
!
PyArg_Parse
(
args
,
"(si)"
,
&
path
,
&
mode
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
fd
=
open
(
path
,
mode
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
fd
<
0
)
return
mac_error
();
return
newintobject
((
long
)
fd
);
return
PyInt_FromLong
((
long
)
fd
);
}
static
o
bject
*
static
PyO
bject
*
mac_read
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
fd
,
size
;
o
bject
*
buffer
;
if
(
!
getargs
(
args
,
"(ii)"
,
&
fd
,
&
size
))
PyO
bject
*
buffer
;
if
(
!
PyArg_Parse
(
args
,
"(ii)"
,
&
fd
,
&
size
))
return
NULL
;
buffer
=
newsizedstringobject
((
char
*
)
NULL
,
size
);
buffer
=
PyString_FromStringAndSize
((
char
*
)
NULL
,
size
);
if
(
buffer
==
NULL
)
return
NULL
;
BGN_SAVE
size
=
read
(
fd
,
getstringvalue
(
buffer
),
size
);
END_SAVE
Py_BEGIN_ALLOW_THREADS
size
=
read
(
fd
,
PyString_AsString
(
buffer
),
size
);
Py_END_ALLOW_THREADS
if
(
size
<
0
)
{
DECREF
(
buffer
);
Py_
DECREF
(
buffer
);
return
mac_error
();
}
resizestring
(
&
buffer
,
size
);
_PyString_Resize
(
&
buffer
,
size
);
return
buffer
;
}
static
o
bject
*
static
PyO
bject
*
mac_rename
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
return
mac_2str
(
args
,
rename
);
}
static
o
bject
*
static
PyO
bject
*
mac_rmdir
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
return
mac_1str
(
args
,
rmdir
);
}
static
o
bject
*
static
PyO
bject
*
mac_stat
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
struct
stat
st
;
char
*
path
;
int
res
;
if
(
!
getargs
(
args
,
"s"
,
&
path
))
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
path
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
stat
(
path
,
&
st
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
!=
0
)
return
mac_error
();
#if 1
return
mkv
alue
(
"(lllllllddd)"
,
return
Py_BuildV
alue
(
"(lllllllddd)"
,
(
long
)
st
.
st_mode
,
(
long
)
st
.
st_ino
,
(
long
)
st
.
st_dev
,
...
...
@@ -463,7 +462,7 @@ mac_stat(self, args)
(
double
)
st
.
st_mtime
,
(
double
)
st
.
st_ctime
);
#else
return
mkv
alue
(
"(llllllllll)"
,
return
Py_BuildV
alue
(
"(llllllllll)"
,
(
long
)
st
.
st_mode
,
(
long
)
st
.
st_ino
,
(
long
)
st
.
st_dev
,
...
...
@@ -477,34 +476,34 @@ mac_stat(self, args)
#endif
}
static
o
bject
*
static
PyO
bject
*
mac_xstat
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
struct
macstat
mst
;
struct
stat
st
;
char
*
path
;
int
res
;
if
(
!
getargs
(
args
,
"s"
,
&
path
))
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
path
))
return
NULL
;
/*
** Convoluted: we want stat() and xstat() to agree, so we call both
** stat and macstat, and use the latter only for values not provided by
** the former.
*/
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
macstat
(
path
,
&
mst
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
!=
0
)
return
mac_error
();
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
stat
(
path
,
&
st
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
!=
0
)
return
mac_error
();
#if 1
return
mkv
alue
(
"(llllllldddls#s#)"
,
return
Py_BuildV
alue
(
"(llllllldddls#s#)"
,
(
long
)
st
.
st_mode
,
(
long
)
st
.
st_ino
,
(
long
)
st
.
st_dev
,
...
...
@@ -519,7 +518,7 @@ mac_xstat(self, args)
mst
.
st_creator
,
4
,
mst
.
st_type
,
4
);
#else
return
mkv
alue
(
"(llllllllllls#s#)"
,
return
Py_BuildV
alue
(
"(llllllllllls#s#)"
,
(
long
)
st
.
st_mode
,
(
long
)
st
.
st_ino
,
(
long
)
st
.
st_dev
,
...
...
@@ -536,61 +535,61 @@ mac_xstat(self, args)
#endif
}
static
o
bject
*
static
PyO
bject
*
mac_sync
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
res
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
res
=
sync
();
END_SAVE
Py_END_ALLOW_THREADS
if
(
res
!=
0
)
return
mac_error
();
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
mac_unlink
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
return
mac_1str
(
args
,
(
int
(
*
)(
const
char
*
))
unlink
);
}
static
o
bject
*
static
PyO
bject
*
mac_write
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
int
fd
,
size
;
char
*
buffer
;
if
(
!
getargs
(
args
,
"(is#)"
,
&
fd
,
&
buffer
,
&
size
))
if
(
!
PyArg_Parse
(
args
,
"(is#)"
,
&
fd
,
&
buffer
,
&
size
))
return
NULL
;
BGN_SAVE
Py_BEGIN_ALLOW_THREADS
size
=
write
(
fd
,
buffer
,
size
);
END_SAVE
Py_END_ALLOW_THREADS
if
(
size
<
0
)
return
mac_error
();
return
newintobject
((
long
)
size
);
return
PyInt_FromLong
((
long
)
size
);
}
#ifdef USE_MALLOC_DEBUG
static
o
bject
*
static
PyO
bject
*
mac_mstats
(
self
,
args
)
o
bject
*
self
;
o
bject
*
args
;
PyO
bject
*
self
;
PyO
bject
*
args
;
{
mstats
(
"python"
);
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
#endif USE_MALLOC_DEBUG
static
struct
methodlist
mac_methods
[]
=
{
static
struct
PyMethodDef
mac_methods
[]
=
{
{
"chdir"
,
mac_chdir
},
{
"close"
,
mac_close
},
#ifdef WEHAVE_DUP
...
...
@@ -625,13 +624,13 @@ static struct methodlist mac_methods[] = {
void
initmac
()
{
o
bject
*
m
,
*
d
;
PyO
bject
*
m
,
*
d
;
m
=
initm
odule
(
"mac"
,
mac_methods
);
d
=
getmoduled
ict
(
m
);
m
=
Py_InitM
odule
(
"mac"
,
mac_methods
);
d
=
PyModule_GetD
ict
(
m
);
/* Initialize mac.error exception */
MacError
=
newstringobject
(
"mac.error"
);
if
(
MacError
==
NULL
||
dictinsert
(
d
,
"error"
,
MacError
)
!=
0
)
fatal
(
"can't define mac.error"
);
MacError
=
PyString_FromString
(
"mac.error"
);
if
(
MacError
==
NULL
||
PyDict_SetItemString
(
d
,
"error"
,
MacError
)
!=
0
)
Py_FatalError
(
"can't define mac.error"
);
}
Mac/Modules/macspeechmodule.c
View file @
c42386ad
...
...
@@ -24,8 +24,7 @@ OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE.
/* xx module */
#include "allobjects.h"
#include "modsupport.h"
#include "Python.h"
#include <GestaltEqu.h>
#include "Speech.h"
...
...
@@ -48,7 +47,7 @@ int lib_available;
#define double2fixed(x) ((Fixed)((x)*32768.0))
char
*
CurrentSpeech
;
o
bject
*
ms_error_object
;
PyO
bject
*
ms_error_object
;
int
speech_available
;
static
...
...
@@ -68,12 +67,12 @@ init_available() {
static
check_available
()
{
if
(
!
speech_available
)
{
err_setstr
(
ms_error_object
,
"Speech Mgr not available"
);
PyErr_SetString
(
ms_error_object
,
"Speech Mgr not available"
);
return
0
;
}
#ifdef __powerc
if
(
!
lib_available
)
{
err_setstr
(
ms_error_object
,
"Speech Mgr available, but shared lib missing"
);
PyErr_SetString
(
ms_error_object
,
"Speech Mgr available, but shared lib missing"
);
return
0
;
}
#endif
...
...
@@ -85,12 +84,12 @@ check_available() {
** Part one - the speech channel object
*/
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
SpeechChannel
chan
;
o
bject
*
curtext
;
/* If non-NULL current text being spoken */
PyO
bject
*
curtext
;
/* If non-NULL current text being spoken */
}
scobject
;
staticforward
typeo
bject
sctype
;
staticforward
PyTypeO
bject
sctype
;
#define is_scobject(v) ((v)->ob_type == &sctype)
...
...
@@ -101,11 +100,11 @@ newscobject(arg)
scobject
*
self
;
OSErr
err
;
self
=
NEWOBJ
(
scobject
,
&
sctype
);
self
=
PyObject_NEW
(
scobject
,
&
sctype
);
if
(
self
==
NULL
)
return
NULL
;
if
(
(
err
=
NewSpeechChannel
(
arg
,
&
self
->
chan
))
!=
0
)
{
DECREF
(
self
);
Py_
DECREF
(
self
);
return
(
scobject
*
)
PyErr_Mac
(
ms_error_object
,
err
);
}
self
->
curtext
=
NULL
;
...
...
@@ -119,146 +118,146 @@ sc_dealloc(self)
scobject
*
self
;
{
DisposeSpeechChannel
(
self
->
chan
);
DEL
(
self
);
PyMem_
DEL
(
self
);
}
static
o
bject
*
static
PyO
bject
*
sc_Stop
(
self
,
args
)
scobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
((
err
=
StopSpeech
(
self
->
chan
))
!=
0
)
{
PyErr_Mac
(
ms_error_object
,
err
);
return
NULL
;
}
if
(
self
->
curtext
)
{
DECREF
(
self
->
curtext
);
Py_
DECREF
(
self
->
curtext
);
self
->
curtext
=
NULL
;
}
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
sc_SpeakText
(
self
,
args
)
scobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
char
*
str
;
int
len
;
if
(
!
getargs
(
args
,
"s#"
,
&
str
,
&
len
))
if
(
!
PyArg_Parse
(
args
,
"s#"
,
&
str
,
&
len
))
return
NULL
;
if
(
self
->
curtext
)
{
StopSpeech
(
self
->
chan
);
DECREF
(
self
->
curtext
);
Py_
DECREF
(
self
->
curtext
);
self
->
curtext
=
NULL
;
}
if
((
err
=
SpeakText
(
self
->
chan
,
(
Ptr
)
str
,
(
long
)
len
))
!=
0
)
{
PyErr_Mac
(
ms_error_object
,
err
);
return
0
;
}
(
void
)
getargs
(
args
,
"O"
,
&
self
->
curtext
);
/* Or should I check this? */
INCREF
(
self
->
curtext
);
INCREF
(
None
);
return
None
;
(
void
)
PyArg_Parse
(
args
,
"O"
,
&
self
->
curtext
);
/* Or should I check this? */
Py_
INCREF
(
self
->
curtext
);
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
sc_GetRate
(
self
,
args
)
scobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
Fixed
farg
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
((
err
=
GetSpeechRate
(
self
->
chan
,
&
farg
))
!=
0
)
{
PyErr_Mac
(
ms_error_object
,
err
);
return
0
;
}
return
newfloatobject
(
fixed2double
(
farg
));
return
PyFloat_FromDouble
(
fixed2double
(
farg
));
}
static
o
bject
*
static
PyO
bject
*
sc_GetPitch
(
self
,
args
)
scobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
Fixed
farg
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
((
err
=
GetSpeechPitch
(
self
->
chan
,
&
farg
))
!=
0
)
{
PyErr_Mac
(
ms_error_object
,
err
);
return
0
;
}
return
newfloatobject
(
fixed2double
(
farg
));
return
PyFloat_FromDouble
(
fixed2double
(
farg
));
}
static
o
bject
*
static
PyO
bject
*
sc_SetRate
(
self
,
args
)
scobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
double
darg
;
if
(
!
getargs
(
args
,
"d"
,
&
darg
))
if
(
!
PyArg_Parse
(
args
,
"d"
,
&
darg
))
return
NULL
;
if
((
err
=
SetSpeechRate
(
self
->
chan
,
double2fixed
(
darg
)))
!=
0
)
{
PyErr_Mac
(
ms_error_object
,
err
);
return
0
;
}
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
o
bject
*
static
PyO
bject
*
sc_SetPitch
(
self
,
args
)
scobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
OSErr
err
;
double
darg
;
if
(
!
getargs
(
args
,
"d"
,
&
darg
))
if
(
!
PyArg_Parse
(
args
,
"d"
,
&
darg
))
return
NULL
;
if
((
err
=
SetSpeechPitch
(
self
->
chan
,
double2fixed
(
darg
)))
!=
0
)
{
PyErr_Mac
(
ms_error_object
,
err
);
return
NULL
;
}
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
static
struct
methodlist
sc_methods
[]
=
{
{
"Stop"
,
(
method
)
sc_Stop
},
{
"SetRate"
,
(
method
)
sc_SetRate
},
{
"GetRate"
,
(
method
)
sc_GetRate
},
{
"SetPitch"
,
(
method
)
sc_SetPitch
},
{
"GetPitch"
,
(
method
)
sc_GetPitch
},
{
"SpeakText"
,
(
method
)
sc_SpeakText
},
static
struct
PyMethodDef
sc_methods
[]
=
{
{
"Stop"
,
(
PyCFunction
)
sc_Stop
},
{
"SetRate"
,
(
PyCFunction
)
sc_SetRate
},
{
"GetRate"
,
(
PyCFunction
)
sc_GetRate
},
{
"SetPitch"
,
(
PyCFunction
)
sc_SetPitch
},
{
"GetPitch"
,
(
PyCFunction
)
sc_GetPitch
},
{
"SpeakText"
,
(
PyCFunction
)
sc_SpeakText
},
{
NULL
,
NULL
}
/* sentinel */
};
static
o
bject
*
static
PyO
bject
*
sc_getattr
(
self
,
name
)
scobject
*
self
;
char
*
name
;
{
return
findmethod
(
sc_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
sc_methods
,
(
PyO
bject
*
)
self
,
name
);
}
static
typeo
bject
sctype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
static
PyTypeO
bject
sctype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"MacSpeechChannel"
,
/*tp_name*/
sizeof
(
scobject
),
/*tp_basicsize*/
...
...
@@ -281,13 +280,13 @@ static typeobject sctype = {
** Part two - the voice object
*/
typedef
struct
{
OB
_HEAD
PyObject
_HEAD
int
initialized
;
VoiceSpec
vs
;
VoiceDescription
vd
;
}
mvobject
;
staticforward
typeo
bject
mvtype
;
staticforward
PyTypeO
bject
mvtype
;
#define is_mvobject(v) ((v)->ob_type == &mvtype)
...
...
@@ -295,7 +294,7 @@ static mvobject *
newmvobject
()
{
mvobject
*
self
;
self
=
NEWOBJ
(
mvobject
,
&
mvtype
);
self
=
PyObject_NEW
(
mvobject
,
&
mvtype
);
if
(
self
==
NULL
)
return
NULL
;
self
->
initialized
=
0
;
...
...
@@ -326,56 +325,56 @@ static void
mv_dealloc
(
self
)
mvobject
*
self
;
{
DEL
(
self
);
PyMem_
DEL
(
self
);
}
static
o
bject
*
static
PyO
bject
*
mv_getgender
(
self
,
args
)
mvobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
o
bject
*
rv
;
PyO
bject
*
rv
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
!
self
->
initialized
)
{
err_setstr
(
ms_error_object
,
"Uninitialized voice"
);
PyErr_SetString
(
ms_error_object
,
"Uninitialized voice"
);
return
NULL
;
}
rv
=
newintobject
(
self
->
vd
.
gender
);
rv
=
PyInt_FromLong
(
self
->
vd
.
gender
);
return
rv
;
}
static
o
bject
*
static
PyO
bject
*
mv_newchannel
(
self
,
args
)
mvobject
*
self
;
o
bject
*
args
;
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
!
self
->
initialized
)
{
err_setstr
(
ms_error_object
,
"Uninitialized voice"
);
PyErr_SetString
(
ms_error_object
,
"Uninitialized voice"
);
return
NULL
;
}
return
(
o
bject
*
)
newscobject
(
&
self
->
vs
);
return
(
PyO
bject
*
)
newscobject
(
&
self
->
vs
);
}
static
struct
methodlist
mv_methods
[]
=
{
{
"GetGender"
,
(
method
)
mv_getgender
},
{
"NewChannel"
,
(
method
)
mv_newchannel
},
static
struct
PyMethodDef
mv_methods
[]
=
{
{
"GetGender"
,
(
PyCFunction
)
mv_getgender
},
{
"NewChannel"
,
(
PyCFunction
)
mv_newchannel
},
{
NULL
,
NULL
}
/* sentinel */
};
static
o
bject
*
static
PyO
bject
*
mv_getattr
(
self
,
name
)
mvobject
*
self
;
char
*
name
;
{
return
findmethod
(
mv_methods
,
(
o
bject
*
)
self
,
name
);
return
Py_FindMethod
(
mv_methods
,
(
PyO
bject
*
)
self
,
name
);
}
static
typeo
bject
mvtype
=
{
OB_HEAD_INIT
(
&
Typet
ype
)
static
PyTypeO
bject
mvtype
=
{
PyObject_HEAD_INIT
(
&
PyType_T
ype
)
0
,
/*ob_size*/
"MacVoice"
,
/*tp_name*/
sizeof
(
mvobject
),
/*tp_basicsize*/
...
...
@@ -401,46 +400,46 @@ static typeobject mvtype = {
/* See if Speech manager available */
static
o
bject
*
static
PyO
bject
*
ms_Available
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
return
newintobject
(
speech_available
);
return
PyInt_FromLong
(
speech_available
);
}
/* Count number of busy speeches */
static
o
bject
*
static
PyO
bject
*
ms_Busy
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
short
result
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
!
check_available
()
)
return
NULL
;
result
=
SpeechBusy
();
return
newintobject
(
result
);
return
PyInt_FromLong
(
result
);
}
/* Say something */
static
o
bject
*
static
PyO
bject
*
ms_SpeakString
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
OSErr
err
;
char
*
str
;
int
len
;
if
(
!
getstrarg
(
args
,
&
str
))
if
(
!
PyArg_Parse
(
args
,
"s"
,
&
str
))
return
NULL
;
if
(
!
check_available
())
return
NULL
;
...
...
@@ -459,68 +458,68 @@ ms_SpeakString(self, args)
PyErr_Mac
(
ms_error_object
,
err
);
return
NULL
;
}
INCREF
(
None
);
return
None
;
Py_INCREF
(
Py_
None
);
return
Py_
None
;
}
/* Count number of available voices */
static
o
bject
*
static
PyO
bject
*
ms_CountVoices
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
short
result
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
!
check_available
())
return
NULL
;
CountVoices
(
&
result
);
return
newintobject
(
result
);
return
PyInt_FromLong
(
result
);
}
static
o
bject
*
static
PyO
bject
*
ms_GetIndVoice
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
mvobject
*
rv
;
long
ind
;
if
(
!
getargs
(
args
,
"i"
,
&
ind
))
if
(
!
PyArg_Parse
(
args
,
"i"
,
&
ind
))
return
NULL
;
if
(
!
check_available
()
)
return
NULL
;
rv
=
newmvobject
();
if
(
!
initmvobject
(
rv
,
ind
)
)
{
DECREF
(
rv
);
Py_
DECREF
(
rv
);
return
NULL
;
}
return
(
o
bject
*
)
rv
;
return
(
PyO
bject
*
)
rv
;
}
static
o
bject
*
static
PyO
bject
*
ms_Version
(
self
,
args
)
o
bject
*
self
;
/* Not used */
o
bject
*
args
;
PyO
bject
*
self
;
/* Not used */
PyO
bject
*
args
;
{
NumVersion
v
;
if
(
!
getnoarg
(
args
))
if
(
!
PyArg_NoArgs
(
args
))
return
NULL
;
if
(
!
check_available
())
return
NULL
;
v
=
SpeechManagerVersion
();
return
newintobject
(
*
(
int
*
)
&
v
);
return
PyInt_FromLong
(
*
(
int
*
)
&
v
);
}
/* List of functions defined in the module */
static
struct
methodlist
ms_methods
[]
=
{
static
struct
PyMethodDef
ms_methods
[]
=
{
{
"Available"
,
ms_Available
},
{
"CountVoices"
,
ms_CountVoices
},
{
"Busy"
,
ms_Busy
},
...
...
@@ -535,18 +534,18 @@ static struct methodlist ms_methods[] = {
void
initmacspeech
()
{
o
bject
*
m
,
*
d
;
PyO
bject
*
m
,
*
d
;
speech_available
=
init_available
();
/* Create the module and add the functions */
m
=
initm
odule
(
"macspeech"
,
ms_methods
);
m
=
Py_InitM
odule
(
"macspeech"
,
ms_methods
);
/* Add some symbolic constants to the module */
d
=
getmoduled
ict
(
m
);
ms_error_object
=
newstringobject
(
"macspeech.error"
);
dictinsert
(
d
,
"error"
,
ms_error_object
);
d
=
PyModule_GetD
ict
(
m
);
ms_error_object
=
PyString_FromString
(
"macspeech.error"
);
PyDict_SetItemString
(
d
,
"error"
,
ms_error_object
);
/* Check for errors */
if
(
err_o
ccurred
())
fatal
(
"can't initialize module macspeech"
);
if
(
PyErr_O
ccurred
())
Py_FatalError
(
"can't initialize module macspeech"
);
}
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment