mirror of
https://github.com/AdaCore/cpython.git
synced 2026-02-12 12:57:15 -08:00
Getting rid of support for MacOS9 and earlier. This is the first step,
and the biggest in size, but probably the easiest. Hunting through the source code comes next.
This commit is contained in:
Binary file not shown.
@@ -1,7 +0,0 @@
|
||||
__terminate
|
||||
__initialize
|
||||
__start
|
||||
__ptmf_null
|
||||
__vec_longjmp
|
||||
longjmp
|
||||
exit
|
||||
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
@@ -1 +0,0 @@
|
||||
init_CG
|
||||
Binary file not shown.
@@ -1 +0,0 @@
|
||||
init_tkinter
|
||||
Binary file not shown.
@@ -1,17 +0,0 @@
|
||||
/* The equivalent of the Unix 'sync' system call: FlushVol.
|
||||
Public domain by Guido van Rossum, CWI, Amsterdam (July 1987).
|
||||
For now, we only flush the default volume
|
||||
(since that's the only volume written to by MacB). */
|
||||
|
||||
#include "macdefs.h"
|
||||
|
||||
void
|
||||
sync(void)
|
||||
{
|
||||
if (FlushVol((StringPtr)0, 0) == noErr)
|
||||
return;
|
||||
else {
|
||||
errno= ENODEV;
|
||||
return;
|
||||
}
|
||||
}
|
||||
@@ -1,362 +0,0 @@
|
||||
'''
|
||||
AECaptureParser makes a brave attempt to convert the text output
|
||||
of the very handy Lasso Capture AE control panel
|
||||
into close-enough executable python code.
|
||||
|
||||
In a roundabout way AECaptureParser offers the way to write lines of AppleScript
|
||||
and convert them to python code. Once Pythonised, the code can be made prettier,
|
||||
and it can run without Capture or Script Editor being open.
|
||||
|
||||
You need Lasso Capture AE from Blueworld:
|
||||
ftp://ftp.blueworld.com/Lasso251/LassoCaptureAE.hqx
|
||||
|
||||
Lasso Capture AE prints structured ascii representations in a small window.
|
||||
As these transcripts can be very complex, cut and paste to AECaptureParser, it parses and writes
|
||||
python code that will, when executed, cause the same events to happen.
|
||||
It's been tested with some household variety events, I'm sure there will be tons that
|
||||
don't work.
|
||||
|
||||
All objects are converted to standard aetypes.ObjectSpecifier instances.
|
||||
|
||||
How to use:
|
||||
1. Start the Capture window
|
||||
2. Cause the desired appleevent to happen
|
||||
- by writing a line of applescript in Script Editor and running it (!)
|
||||
- by recording some action in Script Editor and running it
|
||||
3. Find the events in Capture:
|
||||
- make sure you get the appropriate events, cull if necessary
|
||||
- sometimes Capture barfs, just quit and start Capture again, run events again
|
||||
- AECaptureParser can process multiple events - it will just make more code.
|
||||
4. Copy and paste in this script and execute
|
||||
5. It will print python code that, when executed recreates the events.
|
||||
|
||||
Example:
|
||||
For instance the following line of AppleScript in Script Editor
|
||||
tell application "Finder"
|
||||
return application processes
|
||||
end tell
|
||||
will result in the following transcript:
|
||||
[event: target="Finder", class=core, id=getd]
|
||||
'----':obj {form:indx, want:type(pcap), seld:abso(«616C6C20»), from:'null'()}
|
||||
[/event]
|
||||
Feed a string with this (and perhaps more) events to AECaptureParser
|
||||
|
||||
Some mysteries:
|
||||
* what is '&subj' - it is sent in an activate event: &subj:'null'()
|
||||
The activate event works when this is left out. A possibility?
|
||||
* needs to deal with embedded aliasses
|
||||
|
||||
|
||||
'''
|
||||
__version__ = '0.002'
|
||||
__author__ = 'evb'
|
||||
|
||||
|
||||
import string
|
||||
|
||||
opentag = '{'
|
||||
closetag = '}'
|
||||
|
||||
|
||||
|
||||
import aetools
|
||||
import aetypes
|
||||
|
||||
class eventtalker(aetools.TalkTo):
|
||||
pass
|
||||
|
||||
def processes():
|
||||
'''Helper function to get the list of current processes and their creators
|
||||
This code was mostly written by AECaptureParser! It ain't pretty, but that's not python's fault!'''
|
||||
talker = eventtalker('MACS')
|
||||
_arguments = {}
|
||||
_attributes = {}
|
||||
p = []
|
||||
names = []
|
||||
creators = []
|
||||
results = []
|
||||
# first get the list of process names
|
||||
_arguments['----'] = aetypes.ObjectSpecifier(want=aetypes.Type('pcap'),
|
||||
form="indx", seld=aetypes.Unknown('abso', "all "), fr=None)
|
||||
_reply, _arguments, _attributes = talker.send('core', 'getd', _arguments, _attributes)
|
||||
if _arguments.has_key('errn'):
|
||||
raise aetools.Error, aetools.decodeerror(_arguments)
|
||||
if _arguments.has_key('----'):
|
||||
p = _arguments['----']
|
||||
for proc in p:
|
||||
names.append(proc.seld)
|
||||
# then get the list of process creators
|
||||
_arguments = {}
|
||||
_attributes = {}
|
||||
AEobject_00 = aetypes.ObjectSpecifier(want=aetypes.Type('pcap'), form="indx", seld=aetypes.Unknown('abso', "all "), fr=None)
|
||||
AEobject_01 = aetypes.ObjectSpecifier(want=aetypes.Type('prop'), form="prop", seld=aetypes.Type('fcrt'), fr=AEobject_00)
|
||||
_arguments['----'] = AEobject_01
|
||||
_reply, _arguments, _attributes = talker.send('core', 'getd', _arguments, _attributes)
|
||||
if _arguments.has_key('errn'):
|
||||
raise aetools.Error, aetools.decodeerror(_arguments)
|
||||
if _arguments.has_key('----'):
|
||||
p = _arguments['----']
|
||||
for proc in p:
|
||||
creators.append(proc.type)
|
||||
# then put the lists together
|
||||
for i in range(len(names)):
|
||||
results.append((names[i], creators[i]))
|
||||
return results
|
||||
|
||||
|
||||
class AECaptureParser:
|
||||
'''convert a captured appleevent-description into executable python code'''
|
||||
def __init__(self, aetext):
|
||||
self.aetext = aetext
|
||||
self.events = []
|
||||
self.arguments = {}
|
||||
self.objectindex = 0
|
||||
self.varindex = 0
|
||||
self.currentevent = {'variables':{}, 'arguments':{}, 'objects':{}}
|
||||
self.parse()
|
||||
|
||||
def parse(self):
|
||||
self.lines = string.split(self.aetext, '\n')
|
||||
for l in self.lines:
|
||||
if l[:7] == '[event:':
|
||||
self.eventheader(l)
|
||||
elif l[:7] == '[/event':
|
||||
if len(self.currentevent)<>0:
|
||||
self.events.append(self.currentevent)
|
||||
self.currentevent = {'variables':{}, 'arguments':{}, 'objects':{}}
|
||||
self.objectindex = 0
|
||||
else:
|
||||
self.line(l)
|
||||
|
||||
def line(self, value):
|
||||
'''interpret literals, variables, lists etc.'''
|
||||
# stuff in [ ], l ists
|
||||
varstart = string.find(value, '[')
|
||||
varstop = string.find(value, ']')
|
||||
if varstart <> -1 and varstop <> -1 and varstop>varstart:
|
||||
variable = value[varstart:varstop+1]
|
||||
name = 'aevar_'+string.zfill(self.varindex, 2)
|
||||
self.currentevent['variables'][name] = variable
|
||||
value = value[:varstart]+name+value[varstop+1:]
|
||||
self.varindex = self.varindex + 1
|
||||
# stuff in « »
|
||||
# these are 'ordinal' descriptors of 4 letter codes, so translate
|
||||
varstart = string.find(value, '«')
|
||||
varstop = string.find(value, '»')
|
||||
if varstart <> -1 and varstop <> -1 and varstop>varstart:
|
||||
variable = value[varstart+1:varstop]
|
||||
t = ''
|
||||
for i in range(0, len(variable), 2):
|
||||
c = eval('0x'+variable[i : i+2])
|
||||
t = t + chr(c)
|
||||
|
||||
name = 'aevar_'+string.zfill(self.varindex, 2)
|
||||
self.currentevent['variables'][name] = '"' + t + '"'
|
||||
value = value[:varstart]+name+value[varstop+1:]
|
||||
self.varindex = self.varindex + 1
|
||||
pos = string.find(value, ':')
|
||||
if pos==-1:return
|
||||
ok = 1
|
||||
while ok <> None:
|
||||
value, ok = self.parseobject(value)
|
||||
self.currentevent['arguments'].update(self.splitparts(value, ':'))
|
||||
|
||||
# remove the &subj argument?
|
||||
if self.currentevent['arguments'].has_key('&subj'):
|
||||
del self.currentevent['arguments']['&subj']
|
||||
|
||||
# check for arguments len(a) < 4, and pad with spaces
|
||||
for k in self.currentevent['arguments'].keys():
|
||||
if len(k)<4:
|
||||
newk = k + (4-len(k))*' '
|
||||
self.currentevent['arguments'][newk] = self.currentevent['arguments'][k]
|
||||
del self.currentevent['arguments'][k]
|
||||
|
||||
def parseobject(self, obj):
|
||||
a, b = self.findtag(obj)
|
||||
stuff = None
|
||||
if a<>None and b<>None:
|
||||
stuff = obj[a:b]
|
||||
name = 'AEobject_'+string.zfill(self.objectindex, 2)
|
||||
self.currentevent['objects'][name] = self.splitparts(stuff, ':')
|
||||
obj = obj[:a-5] + name + obj[b+1:]
|
||||
self.objectindex = self.objectindex +1
|
||||
return obj, stuff
|
||||
|
||||
def nextopen(self, pos, text):
|
||||
return string.find(text, opentag, pos)
|
||||
|
||||
def nextclosed(self, pos, text):
|
||||
return string.find(text, closetag, pos)
|
||||
|
||||
def nexttag(self, pos, text):
|
||||
start = self.nextopen(pos, text)
|
||||
stop = self.nextclosed(pos, text)
|
||||
if start == -1:
|
||||
if stop == -1:
|
||||
return -1, -1
|
||||
return 0, stop
|
||||
if start < stop and start<>-1:
|
||||
return 1, start
|
||||
else:
|
||||
return 0, stop
|
||||
|
||||
def findtag(self, text):
|
||||
p = -1
|
||||
last = None,None
|
||||
while 1:
|
||||
kind, p = self.nexttag(p+1, text)
|
||||
if last[0]==1 and kind==0:
|
||||
return last[1]+len(opentag), p
|
||||
if (kind, p) == (-1, -1):
|
||||
break
|
||||
last=kind, p
|
||||
return None, None
|
||||
|
||||
def splitparts(self, txt, splitter):
|
||||
res = {}
|
||||
parts = string.split(txt, ', ')
|
||||
for p in parts:
|
||||
pos = string.find(p, splitter)
|
||||
key = string.strip(p[:pos])
|
||||
value = string.strip(p[pos+1:])
|
||||
res[key] = self.map(value)
|
||||
return res
|
||||
|
||||
def eventheader(self, hdr):
|
||||
self.currentevent['event'] = self.splitparts(hdr[7:-1], '=')
|
||||
|
||||
def printobject(self, d):
|
||||
'''print one object as python code'''
|
||||
t = []
|
||||
obj = {}
|
||||
obj.update(d)
|
||||
t.append("aetypes.ObjectSpecifier(")
|
||||
if obj.has_key('want'):
|
||||
t.append('want=' + self.map(obj['want']))
|
||||
del obj['want']
|
||||
t.append(', ')
|
||||
if obj.has_key('form'):
|
||||
t.append('form=' + addquotes(self.map(obj['form'])))
|
||||
del obj['form']
|
||||
t.append(', ')
|
||||
if obj.has_key('seld'):
|
||||
t.append('seld=' + self.map(obj['seld']))
|
||||
del obj['seld']
|
||||
t.append(', ')
|
||||
if obj.has_key('from'):
|
||||
t.append('fr=' + self.map(obj['from']))
|
||||
del obj['from']
|
||||
if len(obj.keys()) > 0:
|
||||
print '# ', `obj`
|
||||
t.append(")")
|
||||
return string.join(t, '')
|
||||
|
||||
def map(self, t):
|
||||
'''map some Capture syntax to python
|
||||
matchstring : [(old, new), ... ]
|
||||
'''
|
||||
m = {
|
||||
'type(': [('type(', "aetypes.Type('"), (')', "')")],
|
||||
"'null'()": [("'null'()", "None")],
|
||||
'abso(': [('abso(', "aetypes.Unknown('abso', ")],
|
||||
'–': [('–', '"')],
|
||||
'”': [('”', '"')],
|
||||
'[': [('[', '('), (', ', ',')],
|
||||
']': [(']', ')')],
|
||||
'«': [('«', "«")],
|
||||
'»': [('»', "»")],
|
||||
|
||||
}
|
||||
for k in m.keys():
|
||||
if string.find(t, k) <> -1:
|
||||
for old, new in m[k]:
|
||||
p = string.split(t, old)
|
||||
t = string.join(p, new)
|
||||
return t
|
||||
|
||||
def printevent(self, i):
|
||||
'''print the entire captured sequence as python'''
|
||||
evt = self.events[i]
|
||||
code = []
|
||||
code.append('\n# start event ' + `i` + ', talking to ' + evt['event']['target'])
|
||||
# get the signature for the target application
|
||||
code.append('talker = eventtalker("'+self.gettarget(evt['event']['target'])+'")')
|
||||
code.append("_arguments = {}")
|
||||
code.append("_attributes = {}")
|
||||
# write the variables
|
||||
for key, value in evt['variables'].items():
|
||||
value = evt['variables'][key]
|
||||
code.append(key + ' = ' + value)
|
||||
# write the object in the right order
|
||||
objkeys = evt['objects'].keys()
|
||||
objkeys.sort()
|
||||
for key in objkeys:
|
||||
value = evt['objects'][key]
|
||||
code.append(key + ' = ' + self.printobject(value))
|
||||
# then write the arguments
|
||||
for key, value in evt['arguments'].items():
|
||||
code.append("_arguments[" + addquotes(key) + "] = " + value )
|
||||
code.append('_reply, _arguments, _attributes = talker.send("'+
|
||||
evt['event']['class']+'", "'+evt['event']['id']+'", _arguments, _attributes)')
|
||||
code.append("if _arguments.has_key('errn'):")
|
||||
code.append('\traise aetools.Error, aetools.decodeerror(_arguments)')
|
||||
code.append("if _arguments.has_key('----'):")
|
||||
code.append("\tprint _arguments['----']")
|
||||
code.append('# end event ' + `i`)
|
||||
return string.join(code, '\n')
|
||||
|
||||
def gettarget(self, target):
|
||||
'''get the signature for the target application'''
|
||||
target = target[1:-1]
|
||||
if target == 'Finder':
|
||||
return "MACS"
|
||||
apps = processes()
|
||||
for name, creator in apps:
|
||||
if name == target:
|
||||
return creator
|
||||
return '****'
|
||||
|
||||
def makecode(self):
|
||||
code = []
|
||||
code.append("\n\n")
|
||||
code.append("# code generated by AECaptureParser v " + __version__)
|
||||
code.append("# imports, definitions for all events")
|
||||
code.append("import aetools")
|
||||
code.append("import aetypes")
|
||||
code.append("class eventtalker(aetools.TalkTo):")
|
||||
code.append("\tpass")
|
||||
code.append("# the events")
|
||||
# print the events
|
||||
for i in range(len(self.events)):
|
||||
code.append(self.printevent(i))
|
||||
code.append("# end code")
|
||||
return string.join(code, '\n')
|
||||
|
||||
def addquotes(txt):
|
||||
quotes = ['"', "'"]
|
||||
if not txt[0] in quotes and not txt[-1] in quotes:
|
||||
return '"'+txt+'"'
|
||||
return txt
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
|
||||
# ------------------------------------------
|
||||
# the factory
|
||||
# ------------------------------------------
|
||||
|
||||
# for instance, this event was captured from the Script Editor asking the Finder for a list of active processes.
|
||||
|
||||
eventreceptacle = """
|
||||
|
||||
[event: target="Finder", class=core, id=setd]
|
||||
'----':obj {form:prop, want:type(prop), seld:type(posn), from:obj {form:name, want:type(cfol), seld:–MoPar:Data:DevDev:Python:Python 1.5.2c1:Extensions”, from:'null'()}}, data:[100, 10]
|
||||
[/event]
|
||||
|
||||
"""
|
||||
|
||||
aet = AECaptureParser(eventreceptacle)
|
||||
print aet.makecode()
|
||||
@@ -1,5 +0,0 @@
|
||||
AECaptureParser is a tool by Erik van Blokland, erik@letterror.com, which
|
||||
listens for AppleEvents and turns them into the Python code that will generate
|
||||
those events when executed.
|
||||
|
||||
Lots more information is in the docstring in the code.
|
||||
@@ -1,456 +0,0 @@
|
||||
#include <AEDataModel.h>
|
||||
|
||||
#define DEBUG 0
|
||||
|
||||
#define kComponentSignatureString "BBPy.LM"
|
||||
#include <Debugging.h>
|
||||
|
||||
|
||||
#include <BBLMInterface.h>
|
||||
#include <BBXTInterface.h>
|
||||
//#include <BBLMTextIterator.h>
|
||||
|
||||
#include <ctype.h>
|
||||
#include <string.h>
|
||||
#include <stdio.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#include <Sound.h>
|
||||
|
||||
#if DEBUG
|
||||
void debugf_(const char* func,const char* fileName,long line, const char*fmt,...)
|
||||
{
|
||||
va_list arg;
|
||||
char msg[256];
|
||||
va_start(arg, fmt);
|
||||
vsnprintf(msg,256 ,fmt, arg);
|
||||
DebugAssert(COMPONENT_SIGNATURE, DEBUG_NO_OPTIONS, kComponentSignatureString ": " , msg, nil, fileName, line, 0 );
|
||||
|
||||
//debug_string(msg);
|
||||
}
|
||||
#define debugf(FMT,...) debugf_( __FUNCTION__,__FILE__, __LINE__,FMT,__VA_ARGS__);
|
||||
#else
|
||||
#define debugf(FMT,...)
|
||||
#endif
|
||||
|
||||
typedef const char *Str;
|
||||
|
||||
|
||||
enum{
|
||||
kPyBBLMStringSubst = kBBLMFirstUserRunKind
|
||||
};
|
||||
|
||||
#define iswordchar(x) (isalnum(x)||x=='_')
|
||||
|
||||
|
||||
struct runloc{
|
||||
bool past_gap;
|
||||
long pos;
|
||||
long last_start;
|
||||
unsigned char*p;
|
||||
};
|
||||
|
||||
char start(struct runloc& r,BBLMParamBlock &pb)
|
||||
{
|
||||
r.past_gap = false;
|
||||
r.last_start = pb.fCalcRunParams.fStartOffset;
|
||||
r.pos = pb.fCalcRunParams.fStartOffset;
|
||||
r.p = ((unsigned char*)pb.fText) + pb.fCalcRunParams.fStartOffset;
|
||||
// Adjust for the gap if weÕre not already past it.
|
||||
if ((!r.past_gap) && (r.pos >= pb.fTextGapLocation)){
|
||||
r.p += pb.fTextGapLength;
|
||||
r.past_gap = true;
|
||||
}
|
||||
return *r.p;
|
||||
|
||||
}
|
||||
|
||||
char nextchar(struct runloc&r,BBLMParamBlock &pb)
|
||||
{
|
||||
if ( r.pos< pb.fTextLength){
|
||||
++r.pos;
|
||||
++r.p;
|
||||
if ((!r.past_gap) && (r.pos >= pb.fTextGapLocation)){
|
||||
r.p += pb.fTextGapLength;
|
||||
r.past_gap = true;
|
||||
}
|
||||
return *r.p;
|
||||
}
|
||||
else{
|
||||
return 0;
|
||||
}
|
||||
}
|
||||
|
||||
bool addRun(BBLMRunCode kind, int start,int len , const BBLMCallbackBlock& bblm_callbacks)
|
||||
{
|
||||
if (len > 0){ // Tie off the code run we were in, unless the length is zero.
|
||||
debugf("Run %d %d:%d", kind, start, start+len-1 );
|
||||
return bblmAddRun( &bblm_callbacks, 'Pyth',
|
||||
kind, start, len, false);
|
||||
|
||||
}
|
||||
else{
|
||||
return true;
|
||||
}
|
||||
}
|
||||
|
||||
bool addRunBefore (BBLMRunCode kind,struct runloc& r, const BBLMCallbackBlock& bblm_callbacks)
|
||||
{
|
||||
bool more_runs = addRun(kind, r.last_start, r.pos - r.last_start, bblm_callbacks);
|
||||
r.last_start = r.pos;
|
||||
return more_runs;
|
||||
}
|
||||
|
||||
bool addRunTo (BBLMRunCode kind, struct runloc& r, const BBLMCallbackBlock& bblm_callbacks)
|
||||
{
|
||||
bool more_runs = addRun(kind, r.last_start, r.pos - r.last_start+1, bblm_callbacks);
|
||||
r.last_start = r.pos+1;
|
||||
return more_runs;
|
||||
}
|
||||
|
||||
|
||||
bool colorstr( char delim,
|
||||
BBLMParamBlock &pb,
|
||||
struct runloc &r,
|
||||
const BBLMCallbackBlock &bblm_callbacks)
|
||||
{
|
||||
bool tripple = false , pers = false, lookup = false, more_runs = true;
|
||||
char c = nextchar(r,pb);
|
||||
|
||||
if (c == delim){
|
||||
c = nextchar(r,pb);
|
||||
if (c == delim){
|
||||
tripple = true;
|
||||
c = nextchar(r,pb);
|
||||
}
|
||||
else{
|
||||
//double
|
||||
return addRunBefore(kBBLMRunIsSingleString,r,bblm_callbacks);
|
||||
}
|
||||
}
|
||||
while (c && more_runs){
|
||||
if (pers ){
|
||||
if (isalpha(c)){
|
||||
more_runs = addRunTo(kPyBBLMStringSubst,r,bblm_callbacks);
|
||||
}
|
||||
else if (c == '('){
|
||||
lookup = true;
|
||||
}
|
||||
}
|
||||
pers = false;
|
||||
if (c == delim){
|
||||
if (tripple){
|
||||
if ((c = nextchar(r,pb))== delim && (c = nextchar(r,pb)) == delim){
|
||||
break; // end of tripple-quote.
|
||||
}
|
||||
}
|
||||
else{
|
||||
break; // end of single-quote.
|
||||
}
|
||||
|
||||
}
|
||||
else if (c== '\\'){
|
||||
nextchar(r,pb);
|
||||
}
|
||||
else if (c=='\r'||c=='\n'){
|
||||
if (!tripple){
|
||||
break;
|
||||
}
|
||||
}
|
||||
else if (c=='%'){
|
||||
more_runs = addRunBefore(kBBLMRunIsSingleString,r,bblm_callbacks);
|
||||
pers = true;
|
||||
}
|
||||
else if (c==')' && lookup){
|
||||
more_runs = addRunTo(kPyBBLMStringSubst,r,bblm_callbacks);
|
||||
lookup = false;
|
||||
}
|
||||
c = nextchar(r,pb);
|
||||
}
|
||||
return more_runs && addRunTo(lookup?kPyBBLMStringSubst:kBBLMRunIsSingleString,r,bblm_callbacks);
|
||||
}
|
||||
|
||||
bool colorcomment(BBLMParamBlock &pb,
|
||||
struct runloc &r,
|
||||
const BBLMCallbackBlock &bblm_callbacks)
|
||||
{
|
||||
while (char c = nextchar(r,pb)){
|
||||
if (c=='\r'|| c=='\n'){
|
||||
break;
|
||||
}
|
||||
}
|
||||
return addRunTo(kBBLMRunIsLineComment,r,bblm_callbacks);
|
||||
}
|
||||
|
||||
void CalculateRuns(BBLMParamBlock &pb,
|
||||
const BBLMCallbackBlock &bblm_callbacks)
|
||||
|
||||
{
|
||||
const struct rundesc *state = NULL;
|
||||
bool more_runs=true;
|
||||
|
||||
struct runloc r;
|
||||
|
||||
char c = start(r,pb);
|
||||
|
||||
while (c && more_runs){
|
||||
loop:
|
||||
// Process a char
|
||||
if (state==NULL){
|
||||
//If we're in the basic 'code' state, check for each interesting char (rundelims[i].start).
|
||||
switch (c){
|
||||
case '\'':
|
||||
case '"':
|
||||
more_runs = addRunBefore(kBBLMRunIsCode,r,bblm_callbacks);
|
||||
if (more_runs){
|
||||
more_runs = colorstr(c,pb,r,bblm_callbacks);
|
||||
}
|
||||
break;
|
||||
case '#' :
|
||||
more_runs = addRunBefore(kBBLMRunIsCode,r,bblm_callbacks);
|
||||
if (more_runs){
|
||||
more_runs = colorcomment(pb,r,bblm_callbacks);
|
||||
}
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
|
||||
}
|
||||
c = nextchar(r,pb);
|
||||
}
|
||||
if (more_runs){
|
||||
addRunBefore(kBBLMRunIsCode,r,bblm_callbacks);
|
||||
}
|
||||
|
||||
|
||||
}
|
||||
static void AdjustRange(BBLMParamBlock ¶ms,
|
||||
const BBLMCallbackBlock &callbacks)
|
||||
{
|
||||
DescType language;
|
||||
BBLMRunCode kind;
|
||||
SInt32 charPos;
|
||||
SInt32 length;
|
||||
UInt32 index = params.fAdjustRangeParams.fStartIndex;
|
||||
|
||||
while( index > 0 &&
|
||||
bblmGetRun(&callbacks, index, language, kind, charPos, length) &&
|
||||
(kind==kPyBBLMStringSubst||kind==kBBLMRunIsSingleString)){
|
||||
index--;
|
||||
};
|
||||
params.fAdjustRangeParams.fStartIndex = index;
|
||||
}
|
||||
|
||||
|
||||
// The next couple funcs process the text of a file assumming it's in 1 piece in memory,
|
||||
// so they may not be called from CalculateRuns.
|
||||
|
||||
bool matchword(BBLMParamBlock &pb, const char *pat ,unsigned long *pos)
|
||||
{
|
||||
const char *asciText = (const char *) (pb.fTextIsUnicode?NULL:pb.fText);
|
||||
|
||||
int i;
|
||||
for (i=0; pat[i]; i++){
|
||||
if (*pos+i>=pb.fTextLength){
|
||||
return false;
|
||||
}
|
||||
if (asciText[*pos+i] != pat[i]){
|
||||
return false;
|
||||
}
|
||||
}
|
||||
if ((*pos+i<pb.fTextLength)&&iswordchar(asciText[*pos+i])){
|
||||
return false;
|
||||
}
|
||||
*pos+=i;
|
||||
return true;
|
||||
}
|
||||
|
||||
int matchindent(BBLMParamBlock &pb, UInt32 *pos)
|
||||
{
|
||||
const char *asciText = (const char *) (pb.fTextIsUnicode?NULL:pb.fText);
|
||||
int indent=0;
|
||||
|
||||
while(*pos<pb.fTextLength){
|
||||
switch (/*(char)(pb.fTextIsUnicode?uniText[pos]:*/asciText[*pos]/*)*/){
|
||||
case ' ':
|
||||
++*pos;
|
||||
indent++;
|
||||
break;
|
||||
case '\t':
|
||||
++*pos;
|
||||
indent+=8;
|
||||
break;
|
||||
case '#':
|
||||
return -1;
|
||||
break;
|
||||
default:
|
||||
return indent;
|
||||
break;
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
void eat_line(BBLMParamBlock &pb, unsigned long* pos)
|
||||
{
|
||||
const char *asciText = (const char *) (pb.fTextIsUnicode?NULL:pb.fText);
|
||||
while (asciText[*pos]!='\r' && asciText[*pos]!='\n' && *pos<pb.fTextLength) {++*pos;}
|
||||
while ((asciText[*pos]=='\r' || asciText[*pos]=='\n') && *pos<pb.fTextLength) {++*pos;}
|
||||
|
||||
}
|
||||
|
||||
void addItem(BBLMParamBlock &pb, UInt32 pos, int nest, BBLMFunctionKinds kind,
|
||||
const BBLMCallbackBlock *bblm_callbacks)
|
||||
{
|
||||
UInt32 funcstartpos = pos;
|
||||
UInt32 funcnamelen=0;
|
||||
UInt32 offset=0;
|
||||
const char *asciText = (const char *) pb.fText;
|
||||
UInt32 index;
|
||||
OSErr err;
|
||||
|
||||
while (isspace(asciText[pos]) && pos<pb.fTextLength) {++pos;}
|
||||
UInt32 fnamestart = pos;
|
||||
while ((isalnum(asciText[pos])||asciText[pos]=='_') && pos<pb.fTextLength) {pos++; funcnamelen++;}
|
||||
|
||||
err = bblmAddTokenToBuffer( bblm_callbacks,
|
||||
pb.fFcnParams.fTokenBuffer,
|
||||
(void*)&asciText[fnamestart],
|
||||
funcnamelen,
|
||||
pb.fTextIsUnicode,
|
||||
&offset);
|
||||
BBLMProcInfo procInfo;
|
||||
procInfo.fFunctionStart = fnamestart; // char offset in file of first character of function
|
||||
procInfo.fFunctionEnd = pos; // char offset of last character of function
|
||||
|
||||
procInfo.fSelStart = fnamestart; // first character to select when choosing function
|
||||
procInfo.fSelEnd = pos; // last character to select when choosing function
|
||||
|
||||
procInfo.fFirstChar = fnamestart; // first character to make visible when choosing function
|
||||
|
||||
procInfo.fKind = kind;
|
||||
|
||||
procInfo.fIndentLevel = nest; // indentation level of token
|
||||
procInfo.fFlags = 0; // token flags (see BBLMFunctionFlags)
|
||||
procInfo.fNameStart = offset; // char offset in token buffer of token name
|
||||
procInfo.fNameLength = funcnamelen; // length of token name
|
||||
|
||||
err = bblmAddFunctionToList(bblm_callbacks,
|
||||
pb.fFcnParams.fFcnList,
|
||||
procInfo,
|
||||
&index);
|
||||
}
|
||||
|
||||
|
||||
|
||||
enum{
|
||||
maxnest=5
|
||||
};
|
||||
|
||||
void ScanForFunctions(BBLMParamBlock &pb,
|
||||
const BBLMCallbackBlock &bblm_callbacks)
|
||||
{
|
||||
|
||||
const char *asciText = (const char *) (pb.fTextIsUnicode?NULL:pb.fText);
|
||||
UniCharPtr uniText = (UniCharPtr) (pb.fTextIsUnicode?pb.fText:NULL);
|
||||
|
||||
int indents[maxnest]= {0};
|
||||
int nest = 0;
|
||||
|
||||
UInt32 pos=0; // current character offset
|
||||
|
||||
|
||||
while (pos<pb.fTextLength){
|
||||
|
||||
int indent = matchindent(pb, &pos);
|
||||
|
||||
if (indent >= 0){
|
||||
for (int i=0; i <= nest; i++){
|
||||
if (indent<=indents[i]){
|
||||
nest = i;
|
||||
indents[nest]=indent;
|
||||
goto x;
|
||||
}
|
||||
}
|
||||
indents[++nest]=indent;
|
||||
x:
|
||||
|
||||
if (matchword(pb,"def",&pos)){
|
||||
addItem( pb, pos, nest, kBBLMFunctionMark, &bblm_callbacks);
|
||||
}
|
||||
else if (matchword(pb, "class", &pos)){
|
||||
addItem( pb, pos, nest, kBBLMTypedef, &bblm_callbacks);
|
||||
}
|
||||
}
|
||||
eat_line(pb,&pos);
|
||||
}
|
||||
|
||||
}
|
||||
|
||||
OSErr main( BBLMParamBlock ¶ms,
|
||||
const BBLMCallbackBlock &bblm_callbacks,
|
||||
const BBXTCallbackBlock &bbxt_callbacks)
|
||||
{
|
||||
OSErr result;
|
||||
|
||||
if ((params.fSignature != kBBLMParamBlockSignature) ||
|
||||
(params.fLength < sizeof(BBLMParamBlock)))
|
||||
{
|
||||
return paramErr;
|
||||
}
|
||||
|
||||
switch (params.fMessage)
|
||||
{
|
||||
case kBBLMInitMessage:
|
||||
case kBBLMDisposeMessage:
|
||||
{
|
||||
result = noErr; // nothing to do
|
||||
break;
|
||||
}
|
||||
|
||||
case kBBLMCalculateRunsMessage:
|
||||
CalculateRuns(params, bblm_callbacks);
|
||||
result = noErr;
|
||||
break;
|
||||
|
||||
case kBBLMScanForFunctionsMessage:
|
||||
ScanForFunctions(params, bblm_callbacks);
|
||||
result = noErr;
|
||||
break;
|
||||
|
||||
case kBBLMAdjustRangeMessage:
|
||||
AdjustRange(params, bblm_callbacks);
|
||||
result = noErr;
|
||||
break;
|
||||
|
||||
case kBBLMMapRunKindToColorCodeMessage:
|
||||
switch (params.fMapRunParams.fRunKind){
|
||||
case kPyBBLMStringSubst:
|
||||
params.fMapRunParams.fColorCode = kBBLMSGMLAttributeNameColor;
|
||||
params.fMapRunParams.fMapped = true;
|
||||
break;
|
||||
default:
|
||||
params.fMapRunParams.fMapped = false;
|
||||
}
|
||||
result = noErr;
|
||||
break;
|
||||
|
||||
case kBBLMEscapeStringMessage:
|
||||
case kBBLMAdjustEndMessage:
|
||||
case kBBLMMapColorCodeToColorMessage:
|
||||
case kBBLMSetCategoriesMessage:
|
||||
case kBBLMMatchKeywordMessage:
|
||||
{
|
||||
result = userCanceledErr;
|
||||
break;
|
||||
}
|
||||
|
||||
default:
|
||||
{
|
||||
result = paramErr;
|
||||
break;
|
||||
}
|
||||
}
|
||||
return result;
|
||||
}
|
||||
Binary file not shown.
@@ -1,35 +0,0 @@
|
||||
#include "BBLMTypes.r"
|
||||
#include "MacTypes.r"
|
||||
|
||||
#define kKeyWords 1057
|
||||
|
||||
resource 'BBLF' (128, "Python Language Mappings", purgeable)
|
||||
{
|
||||
kCurrentBBLFVersion,
|
||||
|
||||
{
|
||||
kLanguagePython,
|
||||
(kBBLMScansFunctions|kBBLMColorsSyntax|kBBLMIsCaseSensitive),
|
||||
kKeyWords,
|
||||
"Python",
|
||||
{
|
||||
kNeitherSourceNorInclude, ".py",
|
||||
}
|
||||
}
|
||||
};
|
||||
|
||||
#define VERSION 0x1, 0x0, final, 0x0
|
||||
|
||||
resource 'vers' (1) {
|
||||
VERSION,
|
||||
verUS,
|
||||
"1.1",
|
||||
"1.1,"
|
||||
};
|
||||
|
||||
resource 'vers' (2) {
|
||||
VERSION,
|
||||
verUS,
|
||||
$$Date,
|
||||
$$Date
|
||||
};
|
||||
File diff suppressed because one or more lines are too long
@@ -1 +0,0 @@
|
||||
(This file must be converted with BinHex 4.0)
|
||||
@@ -1,12 +0,0 @@
|
||||
This is the Python Language Module for BBEdit.
|
||||
|
||||
This software is a plugin to Bare Bones Software's BBEdit 6.0.2 (or more), designed to make editing & browsing Python Language files easer.
|
||||
|
||||
It parses any file ending in .py (or extentions of your choice.) providing BBEdit with the information BBEdit needs to provide services for python files similar to those it provides for 'C'. Namely: syntax coloring and populating BBEdit's '€' popup menu with file's functions and classes.
|
||||
|
||||
This Plug-in needs to be placed in your :BBEdit 6.0:BBEdit Support:Language Modules: folder.
|
||||
|
||||
If you wish, I have no objections to redistributing it in whole or in part, modify it, or beating small fury animals to death with rolled up printouts of the source code.
|
||||
|
||||
Christopher Stern
|
||||
cistern@earthlink.net
|
||||
Some files were not shown because too many files have changed in this diff Show More
Reference in New Issue
Block a user