Hi,
I was recently in need for converting calculator ASCII files written in
user RPL (with embedded digraphs) to their corresponding HP character
representations for further processing on the PC. This small Python
script does exactly that. Maybe someone has use for it ...
<code>
#!/usr/bin/env python
# CONVERT ASCII FILES WITH EMBEDDED HP CALC DIGRAPHS TO
# THEIR ACCORDING CHARACTER REPRESENTATIONS AND WRITE
# TO STDOUT.
# USAGE: hp_digraphs filename.asc| - > out.hpe
REV = "$Id: hp_digraphs.py 395 2007-06-10 16:14:26Z ingo $"
import re,sys
hp_chars = {'<>':128,'x-':129,'.V':130,'v/':131,'.S':132,'GS':133,'|>':134,
'pi':135,'.d':136,'<=':137,'>=':138,'=/':139,'Ga':140,'->':141,
'<-':142,'|v':143,'|^':144,'Gg':145,'Gd':146,'Ge':147,'Gn':148,
'Gh':149,'Gl':150,'Gr':151,'Gs':152,'Gt':153,'Gw':154,'GD':155,
'PI':156,'GW':157,'[]':158,'oo':159,'<<':171,'^o':176,'Gm':181,
'>>':187,'.x':215,'0/':216,'Gb':223,':-':247}
digraphs = hp_chars.keys()
f = sys.argv[1]
if f == '-':
# READ FROM STDIN WHEN FILENAME IS "-".
# DOESN'T WORK WITH WINDOZE COMMAND PROMPT PIPES ...
# OKAY ON ALL *X PLATFORMS, THOUGH.
inp = sys.stdin
else:
inp = open(f,"r")
s = inp.read()
t = []
p = 0
S = len(s)
while p < S:
if s[p] == '\\':
d = s[p+1:p+3]
if d in digraphs:
t.append(chr(hp_chars[d]))
p += 3
else:
if re.match('\d{3}',s[p+1:p+4]):
t.append(chr(int(s[p+1:p+4])))
p += 4
else:
raise "invalid digraph '%s' detected" % d
else:
t.append(s[p])
p += 1
T = ''.join(t)
# WRITE CONVERTED TEXT TO STDOUT
print T
</code>
- --
Ingo Blank
http://hpgcc.org
http://blog.hpgcc.org
-----BEGIN PGP SIGNATURE-----
Version: GnuPG v1.4.6 (MingW32)
Comment: Using GnuPG with Mozilla - http://enigmail.mozdev.org
iD8DBQFGbcZ3r9bi0BQTf30RAnhwAJ44ldHmk0OdXSaEkchi/AA5ngjqIQCg8oRW
hzJGq43dZqIfQ4X+ngmjyFQ=
=ugML
-----END PGP SIGNATURE-----
http://www.hpcalc.org/details.php?id=3671
http://www.hpcalc.org/hp48/pc/emulators/hpbinasc.zip
Another converter which can be used on a Windows PC
(and which also includes "\\" -> "\")
is a program called "Emu48," aided by
\<< \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Dh #3016Bh IFTE SYSEVAL + \>> 'KINV' STO
Drag (or paste) text file to Emu48 (goes on stack);
invoke program, copy result from stack to clipboard.
Actually, if you want to preserve CRLF
(not change line endings to LF alone), then:
\<< \->STR 3 TRANSIO RCLF SIZE 3 >
#2F34Dh #3016Bh IFTE SYSEVAL + 1 TRANSIO
RCLF SIZE 3 > #2F34Fh #2FEC9h IFTE SYSEVAL \>> 'KINVCR' STO
Emu48:
http://www.hpcalc.org/hp48/pc/emulators/
http://www.hpcalc.org/hp49/pc/emulators/
[r->] [OFF]