summaryrefslogtreecommitdiffstats
path: root/Mac/Modules/res
diff options
context:
space:
mode:
authorTim Peters <tim.peters@gmail.com>2004-07-18 06:16:08 (GMT)
committerTim Peters <tim.peters@gmail.com>2004-07-18 06:16:08 (GMT)
commit182b5aca27d376b08a2904bed42b751496f932f3 (patch)
treedf13115820dbc879c0fe2eae488c9f8c0215a7da /Mac/Modules/res
parente6ddc8b20b493fef2e7cffb2e1351fe1d238857e (diff)
downloadcpython-182b5aca27d376b08a2904bed42b751496f932f3.zip
cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.gz
cpython-182b5aca27d376b08a2904bed42b751496f932f3.tar.bz2
Whitespace normalization, via reindent.py.
Diffstat (limited to 'Mac/Modules/res')
-rw-r--r--Mac/Modules/res/resedit.py28
-rw-r--r--Mac/Modules/res/resscan.py130
-rw-r--r--Mac/Modules/res/ressupport.py296
3 files changed, 227 insertions, 227 deletions
diff --git a/Mac/Modules/res/resedit.py b/Mac/Modules/res/resedit.py
index ab60b34..b3ef790 100644
--- a/Mac/Modules/res/resedit.py
+++ b/Mac/Modules/res/resedit.py
@@ -4,11 +4,11 @@
##Handle h;
##
##if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
-## return NULL;
+## return NULL;
##h = NewHandle(len);
##if ( h == NULL ) {
-## PyErr_NoMemory();
-## return NULL;
+## PyErr_NoMemory();
+## return NULL;
##}
##HLock(h);
##memcpy(*h, buf, len);
@@ -33,11 +33,11 @@ Handle h;
ResourceObject *rv;
if (!PyArg_ParseTuple(_args, "s#", &buf, &len))
- return NULL;
+ return NULL;
h = NewHandle(len);
if ( h == NULL ) {
- PyErr_NoMemory();
- return NULL;
+ PyErr_NoMemory();
+ return NULL;
}
HLock(h);
memcpy(*h, buf, len);
@@ -66,10 +66,10 @@ return _res;
def genresconverter(longname, shortname):
- f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname))
- docstring = "Return this resource/handle as a %s"%longname
- f.docstring = lambda docstring=docstring: docstring
- return f
+ f = ManualGenerator("as_%s"%longname, as_xxx_body%(shortname, longname))
+ docstring = "Return this resource/handle as a %s"%longname
+ f.docstring = lambda docstring=docstring: docstring
+ return f
resmethods.append(genresconverter("Control", "Ctl"))
resmethods.append(genresconverter("Menu", "Menu"))
@@ -87,13 +87,13 @@ resmethods.append(f)
AutoDispose_body = """
int onoff, old = 0;
if (!PyArg_ParseTuple(_args, "i", &onoff))
- return NULL;
+ return NULL;
if ( _self->ob_freeit )
- old = 1;
+ old = 1;
if ( onoff )
- _self->ob_freeit = PyMac_AutoDisposeHandle;
+ _self->ob_freeit = PyMac_AutoDisposeHandle;
else
- _self->ob_freeit = NULL;
+ _self->ob_freeit = NULL;
_res = Py_BuildValue("i", old);
return _res;
"""
diff --git a/Mac/Modules/res/resscan.py b/Mac/Modules/res/resscan.py
index 47a19a6..47a97e4 100644
--- a/Mac/Modules/res/resscan.py
+++ b/Mac/Modules/res/resscan.py
@@ -13,73 +13,73 @@ sys.path.append(BGENDIR)
from scantools import Scanner
def main():
- input = "Resources.h"
- output = "resgen.py"
- defsoutput = TOOLBOXDIR + "Resources.py"
- scanner = ResourcesScanner(input, output, defsoutput)
- scanner.scan()
- scanner.close()
- print "=== Testing definitions output code ==="
- execfile(defsoutput, {}, {})
- print "=== Done scanning and generating, now doing 'import ressupport' ==="
- import ressupport
- print "=== Done 'import ressupport'. It's up to you to compile Resmodule.c ==="
+ input = "Resources.h"
+ output = "resgen.py"
+ defsoutput = TOOLBOXDIR + "Resources.py"
+ scanner = ResourcesScanner(input, output, defsoutput)
+ scanner.scan()
+ scanner.close()
+ print "=== Testing definitions output code ==="
+ execfile(defsoutput, {}, {})
+ print "=== Done scanning and generating, now doing 'import ressupport' ==="
+ import ressupport
+ print "=== Done 'import ressupport'. It's up to you to compile Resmodule.c ==="
class ResourcesScanner(Scanner):
- def destination(self, type, name, arglist):
- classname = "ResFunction"
- listname = "functions"
- if arglist:
- t, n, m = arglist[0]
- if t == "Handle" and m == "InMode":
- classname = "ResMethod"
- listname = "resmethods"
- return classname, listname
-
- def makeblacklistnames(self):
- return [
- "ReadPartialResource",
- "WritePartialResource",
- "TempInsertROMMap",
-## "RmveResource", # RemoveResource
-## "SizeResource", # GetResourceSizeOnDisk
-## "MaxSizeRsrc", # GetMaxResourceSize
- # OS8 only
- 'RGetResource',
- 'OpenResFile',
- 'CreateResFile',
- 'RsrcZoneInit',
- 'InitResources',
- 'RsrcMapEntry',
- ]
-
- def makeblacklisttypes(self):
- return [
- ]
-
- def makerepairinstructions(self):
- return [
- ([("Str255", "*", "InMode")],
- [("*", "*", "OutMode")]),
-
- ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
- [("InBuffer", "*", "*")]),
-
- ([("void", "*", "OutMode"), ("long", "*", "InMode")],
- [("InOutBuffer", "*", "*")]),
-
- ([("void", "*", "OutMode"), ("long", "*", "InMode"),
- ("long", "*", "OutMode")],
- [("OutBuffer", "*", "InOutMode")]),
-
- ([("SInt8", "*", "*")],
- [("SignedByte", "*", "*")]),
-
-
- ([("UniCharCount", "*", "InMode"), ("UniChar_ptr", "*", "InMode")],
- [("UnicodeReverseInBuffer", "*", "*")]),
- ]
+ def destination(self, type, name, arglist):
+ classname = "ResFunction"
+ listname = "functions"
+ if arglist:
+ t, n, m = arglist[0]
+ if t == "Handle" and m == "InMode":
+ classname = "ResMethod"
+ listname = "resmethods"
+ return classname, listname
+
+ def makeblacklistnames(self):
+ return [
+ "ReadPartialResource",
+ "WritePartialResource",
+ "TempInsertROMMap",
+## "RmveResource", # RemoveResource
+## "SizeResource", # GetResourceSizeOnDisk
+## "MaxSizeRsrc", # GetMaxResourceSize
+ # OS8 only
+ 'RGetResource',
+ 'OpenResFile',
+ 'CreateResFile',
+ 'RsrcZoneInit',
+ 'InitResources',
+ 'RsrcMapEntry',
+ ]
+
+ def makeblacklisttypes(self):
+ return [
+ ]
+
+ def makerepairinstructions(self):
+ return [
+ ([("Str255", "*", "InMode")],
+ [("*", "*", "OutMode")]),
+
+ ([("void_ptr", "*", "InMode"), ("long", "*", "InMode")],
+ [("InBuffer", "*", "*")]),
+
+ ([("void", "*", "OutMode"), ("long", "*", "InMode")],
+ [("InOutBuffer", "*", "*")]),
+
+ ([("void", "*", "OutMode"), ("long", "*", "InMode"),
+ ("long", "*", "OutMode")],
+ [("OutBuffer", "*", "InOutMode")]),
+
+ ([("SInt8", "*", "*")],
+ [("SignedByte", "*", "*")]),
+
+
+ ([("UniCharCount", "*", "InMode"), ("UniChar_ptr", "*", "InMode")],
+ [("UnicodeReverseInBuffer", "*", "*")]),
+ ]
if __name__ == "__main__":
- main()
+ main()
diff --git a/Mac/Modules/res/ressupport.py b/Mac/Modules/res/ressupport.py
index 6135560..04a1821 100644
--- a/Mac/Modules/res/ressupport.py
+++ b/Mac/Modules/res/ressupport.py
@@ -7,13 +7,13 @@ from macsupport import *
class ResMixIn:
- def checkit(self):
- if self.returntype.__class__ != OSErrType:
- OutLbrace()
- Output("OSErr _err = ResError();")
- Output("if (_err != noErr) return PyMac_Error(_err);")
- OutRbrace()
- FunctionGenerator.checkit(self) # XXX
+ def checkit(self):
+ if self.returntype.__class__ != OSErrType:
+ OutLbrace()
+ Output("OSErr _err = ResError();")
+ Output("if (_err != noErr) return PyMac_Error(_err);")
+ OutRbrace()
+ FunctionGenerator.checkit(self) # XXX
class ResFunction(ResMixIn, OSErrWeakLinkFunctionGenerator): pass
class ResMethod(ResMixIn, OSErrWeakLinkMethodGenerator): pass
@@ -42,7 +42,7 @@ extern int _OptResObj_Convert(PyObject *, Handle *);
static void
PyMac_AutoDisposeHandle(Handle h)
{
- DisposeHandle(h);
+ DisposeHandle(h);
}
"""
@@ -51,159 +51,159 @@ finalstuff = finalstuff + """
/* Alternative version of ResObj_New, which returns None for null argument */
PyObject *OptResObj_New(Handle itself)
{
- if (itself == NULL) {
- Py_INCREF(Py_None);
- return Py_None;
- }
- return ResObj_New(itself);
+ if (itself == NULL) {
+ Py_INCREF(Py_None);
+ return Py_None;
+ }
+ return ResObj_New(itself);
}
int OptResObj_Convert(PyObject *v, Handle *p_itself)
{
- PyObject *tmp;
-
- if ( v == Py_None ) {
- *p_itself = NULL;
- return 1;
- }
- if (ResObj_Check(v))
- {
- *p_itself = ((ResourceObject *)v)->ob_itself;
- return 1;
- }
- /* If it isn't a resource yet see whether it is convertible */
- if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) {
- *p_itself = ((ResourceObject *)tmp)->ob_itself;
- Py_DECREF(tmp);
- return 1;
- }
- PyErr_Clear();
- PyErr_SetString(PyExc_TypeError, "Resource required");
- return 0;
+ PyObject *tmp;
+
+ if ( v == Py_None ) {
+ *p_itself = NULL;
+ return 1;
+ }
+ if (ResObj_Check(v))
+ {
+ *p_itself = ((ResourceObject *)v)->ob_itself;
+ return 1;
+ }
+ /* If it isn't a resource yet see whether it is convertible */
+ if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) ) {
+ *p_itself = ((ResourceObject *)tmp)->ob_itself;
+ Py_DECREF(tmp);
+ return 1;
+ }
+ PyErr_Clear();
+ PyErr_SetString(PyExc_TypeError, "Resource required");
+ return 0;
}
"""
initstuff = initstuff + """
- PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, ResObj_New);
- PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, ResObj_Convert);
- PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, OptResObj_New);
- PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, OptResObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, ResObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, ResObj_Convert);
+ PyMac_INIT_TOOLBOX_OBJECT_NEW(Handle, OptResObj_New);
+ PyMac_INIT_TOOLBOX_OBJECT_CONVERT(Handle, OptResObj_Convert);
"""
module = MacModule('_Res', 'Res', includestuff, finalstuff, initstuff)
class ResDefinition(PEP253Mixin, GlobalObjectDefinition):
- getsetlist = [
- ('data',
- """
- PyObject *res;
- char state;
-
- state = HGetState(self->ob_itself);
- HLock(self->ob_itself);
- res = PyString_FromStringAndSize(
- *self->ob_itself,
- GetHandleSize(self->ob_itself));
- HUnlock(self->ob_itself);
- HSetState(self->ob_itself, state);
- return res;
- """,
- """
- char *data;
- long size;
-
- if ( v == NULL )
- return -1;
- if ( !PyString_Check(v) )
- return -1;
- size = PyString_Size(v);
- data = PyString_AsString(v);
- /* XXXX Do I need the GetState/SetState calls? */
- SetHandleSize(self->ob_itself, size);
- if ( MemError())
- return -1;
- HLock(self->ob_itself);
- memcpy((char *)*self->ob_itself, data, size);
- HUnlock(self->ob_itself);
- /* XXXX Should I do the Changed call immedeately? */
- return 0;
- """,
- 'The resource data'
- ), (
- 'size',
- 'return PyInt_FromLong(GetHandleSize(self->ob_itself));',
- None,
- 'The length of the resource data'
- )]
-
- def outputCheckNewArg(self):
- Output("if (itself == NULL) return PyMac_Error(resNotFound);")
-
- def outputCheckConvertArg(self):
- # if it isn't a resource we may be able to coerce it
- Output("if (!%s_Check(v))", self.prefix)
- OutLbrace()
- Output("PyObject *tmp;")
- Output('if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) )')
- OutLbrace()
- Output("*p_itself = ((ResourceObject *)tmp)->ob_itself;")
- Output("Py_DECREF(tmp);")
- Output("return 1;")
- OutRbrace()
- Output("PyErr_Clear();")
- OutRbrace()
-
- def outputStructMembers(self):
- GlobalObjectDefinition.outputStructMembers(self)
- Output("void (*ob_freeit)(%s ptr);", self.itselftype)
-
- def outputInitStructMembers(self):
- GlobalObjectDefinition.outputInitStructMembers(self)
- Output("it->ob_freeit = NULL;")
-
- def outputCleanupStructMembers(self):
- Output("if (self->ob_freeit && self->ob_itself)")
- OutLbrace()
- Output("self->ob_freeit(self->ob_itself);")
- OutRbrace()
- Output("self->ob_itself = NULL;")
-
- def output_tp_newBody(self):
- Output("PyObject *self;")
- Output
- Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
- Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
- Output("((%s *)self)->ob_freeit = NULL;", self.objecttype)
- Output("return self;")
-
- def output_tp_initBody(self):
- Output("char *srcdata = NULL;")
- Output("int srclen = 0;")
- Output("%s itself;", self.itselftype);
- Output("char *kw[] = {\"itself\", 0};")
- Output()
- Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
- self.prefix);
- OutLbrace()
- Output("((%s *)self)->ob_itself = itself;", self.objecttype)
- Output("return 0;")
- OutRbrace()
- Output("PyErr_Clear();")
- Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"|s#\", kw, &srcdata, &srclen)) return -1;")
- Output("if ((itself = NewHandle(srclen)) == NULL)")
- OutLbrace()
- Output("PyErr_NoMemory();")
- Output("return 0;")
- OutRbrace()
- Output("((%s *)self)->ob_itself = itself;", self.objecttype)
-# XXXX Output("((%s *)self)->ob_freeit = PyMac_AutoDisposeHandle;")
- Output("if (srclen && srcdata)")
- OutLbrace()
- Output("HLock(itself);")
- Output("memcpy(*itself, srcdata, srclen);")
- Output("HUnlock(itself);")
- OutRbrace()
- Output("return 0;")
+ getsetlist = [
+ ('data',
+ """
+ PyObject *res;
+ char state;
+
+ state = HGetState(self->ob_itself);
+ HLock(self->ob_itself);
+ res = PyString_FromStringAndSize(
+ *self->ob_itself,
+ GetHandleSize(self->ob_itself));
+ HUnlock(self->ob_itself);
+ HSetState(self->ob_itself, state);
+ return res;
+ """,
+ """
+ char *data;
+ long size;
+
+ if ( v == NULL )
+ return -1;
+ if ( !PyString_Check(v) )
+ return -1;
+ size = PyString_Size(v);
+ data = PyString_AsString(v);
+ /* XXXX Do I need the GetState/SetState calls? */
+ SetHandleSize(self->ob_itself, size);
+ if ( MemError())
+ return -1;
+ HLock(self->ob_itself);
+ memcpy((char *)*self->ob_itself, data, size);
+ HUnlock(self->ob_itself);
+ /* XXXX Should I do the Changed call immedeately? */
+ return 0;
+ """,
+ 'The resource data'
+ ), (
+ 'size',
+ 'return PyInt_FromLong(GetHandleSize(self->ob_itself));',
+ None,
+ 'The length of the resource data'
+ )]
+
+ def outputCheckNewArg(self):
+ Output("if (itself == NULL) return PyMac_Error(resNotFound);")
+
+ def outputCheckConvertArg(self):
+ # if it isn't a resource we may be able to coerce it
+ Output("if (!%s_Check(v))", self.prefix)
+ OutLbrace()
+ Output("PyObject *tmp;")
+ Output('if ( (tmp=PyObject_CallMethod(v, "as_Resource", "")) )')
+ OutLbrace()
+ Output("*p_itself = ((ResourceObject *)tmp)->ob_itself;")
+ Output("Py_DECREF(tmp);")
+ Output("return 1;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ OutRbrace()
+
+ def outputStructMembers(self):
+ GlobalObjectDefinition.outputStructMembers(self)
+ Output("void (*ob_freeit)(%s ptr);", self.itselftype)
+
+ def outputInitStructMembers(self):
+ GlobalObjectDefinition.outputInitStructMembers(self)
+ Output("it->ob_freeit = NULL;")
+
+ def outputCleanupStructMembers(self):
+ Output("if (self->ob_freeit && self->ob_itself)")
+ OutLbrace()
+ Output("self->ob_freeit(self->ob_itself);")
+ OutRbrace()
+ Output("self->ob_itself = NULL;")
+
+ def output_tp_newBody(self):
+ Output("PyObject *self;")
+ Output
+ Output("if ((self = type->tp_alloc(type, 0)) == NULL) return NULL;")
+ Output("((%s *)self)->ob_itself = NULL;", self.objecttype)
+ Output("((%s *)self)->ob_freeit = NULL;", self.objecttype)
+ Output("return self;")
+
+ def output_tp_initBody(self):
+ Output("char *srcdata = NULL;")
+ Output("int srclen = 0;")
+ Output("%s itself;", self.itselftype);
+ Output("char *kw[] = {\"itself\", 0};")
+ Output()
+ Output("if (PyArg_ParseTupleAndKeywords(args, kwds, \"O&\", kw, %s_Convert, &itself))",
+ self.prefix);
+ OutLbrace()
+ Output("((%s *)self)->ob_itself = itself;", self.objecttype)
+ Output("return 0;")
+ OutRbrace()
+ Output("PyErr_Clear();")
+ Output("if (!PyArg_ParseTupleAndKeywords(args, kwds, \"|s#\", kw, &srcdata, &srclen)) return -1;")
+ Output("if ((itself = NewHandle(srclen)) == NULL)")
+ OutLbrace()
+ Output("PyErr_NoMemory();")
+ Output("return 0;")
+ OutRbrace()
+ Output("((%s *)self)->ob_itself = itself;", self.objecttype)
+# XXXX Output("((%s *)self)->ob_freeit = PyMac_AutoDisposeHandle;")
+ Output("if (srclen && srcdata)")
+ OutLbrace()
+ Output("HLock(itself);")
+ Output("memcpy(*itself, srcdata, srclen);")
+ Output("HUnlock(itself);")
+ OutRbrace()
+ Output("return 0;")
resobject = ResDefinition('Resource', 'ResObj', 'Handle')
module.addobject(resobject)