parent
c9998e1b19
commit
250a29f97d
|
@ -522,6 +522,10 @@ class Binary32Buffer(FileBuffer):
|
||||||
bytes.append(chr(int(lastc + '0', 16)))
|
bytes.append(chr(int(lastc + '0', 16)))
|
||||||
return ''.join(bytes)
|
return ''.join(bytes)
|
||||||
|
|
||||||
|
class Binary64Buffer(Binary32Buffer):
|
||||||
|
wordsize = 8
|
||||||
|
numwords = 2
|
||||||
|
|
||||||
class DirBuffer(Buffer):
|
class DirBuffer(Buffer):
|
||||||
btype = 'dir'
|
btype = 'dir'
|
||||||
def __init__(self, path, nl='\n', name=None):
|
def __init__(self, path, nl='\n', name=None):
|
||||||
|
|
46
mode/hex.py
46
mode/hex.py
|
@ -20,6 +20,8 @@ class Hex(mode2.Fundamental):
|
||||||
mode2.Fundamental.__init__(self, w)
|
mode2.Fundamental.__init__(self, w)
|
||||||
|
|
||||||
self.add_action_and_bindings(GotoWord(), ('M-g',))
|
self.add_action_and_bindings(GotoWord(), ('M-g',))
|
||||||
|
self.add_action(FindStrings())
|
||||||
|
self.add_action(WhichWord())
|
||||||
|
|
||||||
# create all the insert actions for the basic text input
|
# create all the insert actions for the basic text input
|
||||||
for c in string.letters + string.digits + string.punctuation:
|
for c in string.letters + string.digits + string.punctuation:
|
||||||
|
@ -39,7 +41,49 @@ class GotoWord(Method):
|
||||||
if n < 0:
|
if n < 0:
|
||||||
w.set_error("Negative word counts not supported.")
|
w.set_error("Negative word counts not supported.")
|
||||||
try:
|
try:
|
||||||
p = Point((n % 4) * 9, n / 4)
|
x = (n % w.buffer.numwords) * (w.buffer.wordsize + 1)
|
||||||
|
y = n / w.buffer.numwords
|
||||||
|
p = Point(x, y)
|
||||||
w.goto(p)
|
w.goto(p)
|
||||||
except:
|
except:
|
||||||
w.goto_end()
|
w.goto_end()
|
||||||
|
|
||||||
|
class WhichWord(Method):
|
||||||
|
'''Show the current word number'''
|
||||||
|
def _execute(self, w, **vargs):
|
||||||
|
cursor = w.logical_cursor()
|
||||||
|
n = cursor.y * w.buffer.numwords
|
||||||
|
n += cursor.x / (w.buffer.wordsize + 1)
|
||||||
|
w.set_error("Currently in word %s (%s)" % (hex(n), n))
|
||||||
|
|
||||||
|
class FindStrings(Method):
|
||||||
|
def _execute(self, w, **vargs):
|
||||||
|
newlines = []
|
||||||
|
lastline = ''
|
||||||
|
i = 0
|
||||||
|
for line in w.buffer.lines:
|
||||||
|
lastc = None
|
||||||
|
newline = ""
|
||||||
|
for c in line:
|
||||||
|
if c not in '0123456789abcdefABCDEF':
|
||||||
|
lastc = None
|
||||||
|
elif lastc is None:
|
||||||
|
lastc = c
|
||||||
|
else:
|
||||||
|
char = chr(int(lastc + c, 16))
|
||||||
|
lastc = None
|
||||||
|
if char in string.whitespace:
|
||||||
|
newline += ' '
|
||||||
|
elif char in string.letters + string.digits + string.punctuation:
|
||||||
|
newline += char
|
||||||
|
else:
|
||||||
|
newline += '.'
|
||||||
|
if lastc is not None:
|
||||||
|
newline += '.'
|
||||||
|
if i == 3:
|
||||||
|
newlines.append(lastline)
|
||||||
|
lastline = ''
|
||||||
|
else:
|
||||||
|
lastline += newline
|
||||||
|
i = (i + 1) % 4
|
||||||
|
w.application.data_buffer("*Strings*", '\n'.join(newlines), switch_to=True)
|
||||||
|
|
Loading…
Reference in New Issue