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
90ecdf49
Commit
90ecdf49
authored
Apr 16, 1996
by
Jack Jansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
An interface to WASTE, an all-singing-all-dancing TextEdit replacement
parent
6528b1fe
Changes
3
Expand all
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
1955 additions
and
0 deletions
+1955
-0
Mac/Modules/waste/wastemodule.c
Mac/Modules/waste/wastemodule.c
+1694
-0
Mac/Modules/waste/wastescan.py
Mac/Modules/waste/wastescan.py
+75
-0
Mac/Modules/waste/wastesupport.py
Mac/Modules/waste/wastesupport.py
+186
-0
No files found.
Mac/Modules/waste/wastemodule.c
0 → 100644
View file @
90ecdf49
This diff is collapsed.
Click to expand it.
Mac/Modules/waste/wastescan.py
0 → 100644
View file @
90ecdf49
# Scan an Apple header file, generating a Python file of generator calls.
import
addpack
addpack
.
addpack
(
':tools:bgen:bgen'
)
from
scantools
import
Scanner
from
bgenlocations
import
TOOLBOXDIR
WASTEDIR
=
":::::Waste 1.2a5:"
OBJECT
=
"TEHandle"
SHORT
=
"waste"
OBJECT
=
"WEReference"
OBJECT2
=
"WEObjectReference"
def
main
():
input
=
WASTEDIR
+
"WASTE C/C++ Headers:WASTE.h"
output
=
SHORT
+
"gen.py"
defsoutput
=
TOOLBOXDIR
+
"WASTEconst.py"
scanner
=
MyScanner
(
input
,
output
,
defsoutput
)
scanner
.
scan
()
scanner
.
gentypetest
(
SHORT
+
"typetest.py"
)
scanner
.
close
()
print
"=== Done scanning and generating, now importing the generated code... ==="
exec
"import "
+
SHORT
+
"support"
print
"=== Done. It's up to you to compile it now! ==="
class
MyScanner
(
Scanner
):
def
initpatterns
(
self
):
# Waste doesn't use 'extern':
Scanner
.
initpatterns
(
self
)
self
.
head_pat
=
"^pascal[
\
t
]+"
def
destination
(
self
,
type
,
name
,
arglist
):
classname
=
"Function"
listname
=
"functions"
if
arglist
:
t
,
n
,
m
=
arglist
[
-
1
]
# This is non-functional today
if
t
==
OBJECT
and
m
==
"InMode"
:
classname
=
"Method"
listname
=
"methods"
else
:
t
,
n
,
m
=
arglist
[
0
]
if
t
==
OBJECT2
and
m
==
"InMode"
:
classname
=
"Method2"
listname
=
"methods2"
return
classname
,
listname
def
makeblacklistnames
(
self
):
return
[
"WEDispose"
,
"WESetInfo"
,
# Argument type unknown...
"WEGetInfo"
,
"WEGetObjectOwner"
,
# Returns ref to existing WE
]
def
makeblacklisttypes
(
self
):
return
[
"DragReference"
,
# For now...
"UniversalProcPtr"
,
]
def
makerepairinstructions
(
self
):
return
[
([(
"void_ptr"
,
"*"
,
"InMode"
),
(
"long"
,
"*"
,
"InMode"
)],
[(
"InBuffer"
,
"*"
,
"*"
)]),
# WEContinuousStyle
([(
"WEStyleMode"
,
"mode"
,
"OutMode"
),
(
"TextStyle"
,
"aStyle"
,
"OutMode"
)],
[(
"WEStyleMode"
,
"mode"
,
"InOutMode"
),
(
"TextStyle"
,
"aStyle"
,
"InOutMode"
)])
]
if
__name__
==
"__main__"
:
main
()
Mac/Modules/waste/wastesupport.py
0 → 100644
View file @
90ecdf49
# This script generates a Python interface for an Apple Macintosh Manager.
# It uses the "bgen" package to generate C code.
# The function specifications are generated by scanning the mamager's header file,
# using the "scantools" package (customized for this particular manager).
import
string
# Declarations that change for each manager
MACHEADERFILE
=
'WASTE.h'
# The Apple header file
MODNAME
=
'waste'
# The name of the module
OBJECTNAME
=
'waste'
# The basic name of the objects used here
KIND
=
'Ptr'
# Usually 'Ptr' or 'Handle'
# The following is *usually* unchanged but may still require tuning
MODPREFIX
=
MODNAME
# The prefix for module-wide routines
OBJECTTYPE
=
"WEReference"
# The C type used to represent them
OBJECTPREFIX
=
MODPREFIX
+
'Obj'
# The prefix for object methods
INPUTFILE
=
'wastegen.py'
# The file generated by the scanner
TYPETESTFILE
=
'wastetypetest.py'
# Another file generated by the scanner
OUTPUTFILE
=
"wastemodule.c"
# The file generated by this program
from
macsupport
import
*
# Create the type objects
WEReference
=
OpaqueByValueType
(
"WEReference"
,
"wasteObj"
)
WEObjectReference
=
OpaqueByValueType
(
"WEObjectReference"
,
"WEOObj"
)
##CharsHandle = OpaqueByValueType("CharsHandle", "ResObj")
##Handle = OpaqueByValueType("Handle", "ResObj")
StScrpHandle
=
OpaqueByValueType
(
"StScrpHandle"
,
"ResObj"
)
##TEStyleHandle = OpaqueByValueType("TEStyleHandle", "ResObj")
RgnHandle
=
OpaqueByValueType
(
"RgnHandle"
,
"ResObj"
)
EventModifiers
=
Type
(
"EventModifiers"
,
"h"
)
FlavorType
=
OSTypeType
(
"FlavorType"
)
WESelector
=
OSTypeType
(
"WESelector"
)
WEStyleMode
=
Type
(
"WEStyleMode"
,
"h"
)
WEActionKind
=
Type
(
"WEActionKind"
,
"h"
)
WEAlignment
=
Type
(
"WEAlignment"
,
"b"
)
WESoupHandle
=
OpaqueByValueType
(
"WESoupHandle"
,
"ResObj"
)
WERunInfo
=
OpaqueType
(
"WERunInfo"
,
"RunInfo"
)
TextStyle
=
OpaqueType
(
"TextStyle"
,
"TextStyle"
)
TextStyle_ptr
=
TextStyle
LongPt
=
OpaqueType
(
"LongPt"
,
"LongPt"
)
LongPt_ptr
=
LongPt
LongRect
=
OpaqueType
(
"LongRect"
,
"LongRect"
)
LongRect_ptr
=
LongRect
includestuff
=
includestuff
+
"""
#include <%s>"""
%
MACHEADERFILE
+
"""
/* Exported by Qdmodule.c: */
extern PyObject *QdRGB_New(RGBColor *);
extern int QdRGB_Convert(PyObject *, RGBColor *);
/* Forward declaration */
staticforward PyObject *WEOObj_New(WEObjectReference);
/*
** Parse/generate TextStyle records
*/
static
PyObject *TextStyle_New(itself)
TextStylePtr itself;
{
return Py_BuildValue("lllO&", (long)itself->tsFont, (long)itself->tsFace, (long)itself->tsSize, QdRGB_New,
&itself->tsColor);
}
static
TextStyle_Convert(v, p_itself)
PyObject *v;
TextStylePtr p_itself;
{
long font, face, size;
if( !PyArg_ParseTuple(v, "lllO&", &font, &face, &size, QdRGB_Convert, &p_itself->tsColor) )
return 0;
p_itself->tsFont = (short)font;
p_itself->tsFace = (Style)face;
p_itself->tsSize = (short)size;
return 1;
}
/*
** Parse/generate RunInfo records
*/
static
PyObject *RunInfo_New(itself)
WERunInfo *itself;
{
return Py_BuildValue("llhhO&O&", itself->runStart, itself->runEnd, itself->runHeight,
itself->runAscent, TextStyle_New, &itself->runStyle, WEOObj_New, itself->runObject);
}
/* Conversion of long points and rects */
int
LongRect_Convert(PyObject *v, LongRect *r)
{
return PyArg_Parse(v, "(llll)", &r->left, &r->top, &r->right, &r->bottom);
}
PyObject *
LongRect_New(LongRect *r)
{
return Py_BuildValue("(llll)", r->left, r->top, r->right, r->bottom);
}
LongPt_Convert(PyObject *v, LongPt *p)
{
return PyArg_Parse(v, "(ll)", &p->h, &p->v);
}
PyObject *
LongPt_New(LongPt *p)
{
return Py_BuildValue("(ll)", p->h, p->v);
}
"""
class
WEMethodGenerator
(
OSErrMethodGenerator
):
"""Similar to MethodGenerator, but has self as last argument"""
def
parseArgumentList
(
self
,
args
):
args
,
a0
=
args
[:
-
1
],
args
[
-
1
]
t0
,
n0
,
m0
=
a0
if
m0
!=
InMode
:
raise
ValueError
,
"method's 'self' must be 'InMode'"
self
.
itself
=
Variable
(
t0
,
"_self->ob_itself"
,
SelfMode
)
FunctionGenerator
.
parseArgumentList
(
self
,
args
)
self
.
argumentList
.
append
(
self
.
itself
)
class
WEObjectDefinition
(
GlobalObjectDefinition
):
def
outputCheckNewArg
(
self
):
Output
(
"""if (itself == NULL) {
PyErr_SetString(waste_Error,"Cannot create null WE");
return NULL;
}"""
)
def
outputFreeIt
(
self
,
itselfname
):
Output
(
"WEDispose(%s);"
,
itselfname
)
class
WEOObjectDefinition
(
GlobalObjectDefinition
):
def
outputCheckNewArg
(
self
):
Output
(
"""if (itself == NULL) {
Py_INCREF(Py_None);
return Py_None;
}"""
)
# From here on it's basically all boiler plate...
# Test types used for existence
execfile
(
TYPETESTFILE
)
# Create the generator groups and link them
module
=
MacModule
(
MODNAME
,
MODPREFIX
,
includestuff
,
finalstuff
,
initstuff
)
object
=
WEObjectDefinition
(
OBJECTNAME
,
OBJECTPREFIX
,
OBJECTTYPE
)
object2
=
WEOObjectDefinition
(
"WEO"
,
"WEOObj"
,
"WEObjectReference"
)
module
.
addobject
(
object2
)
module
.
addobject
(
object
)
# Create the generator classes used to populate the lists
Function
=
OSErrFunctionGenerator
Method
=
WEMethodGenerator
Method2
=
OSErrMethodGenerator
# Create and populate the lists
functions
=
[]
methods
=
[]
methods2
=
[]
execfile
(
INPUTFILE
)
# add the populated lists to the generator groups
# (in a different wordl the scan program would generate this)
for
f
in
functions
:
module
.
add
(
f
)
for
f
in
methods
:
object
.
add
(
f
)
for
f
in
methods2
:
object2
.
add
(
f
)
# generate output (open the output file as late as possible)
SetOutputFileName
(
OUTPUTFILE
)
module
.
generate
()
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