I wish to share the convertor code in the hope it can improve further. It takes Text87 ESC/P printer file and translates it into HTML stream. It is not perfect and it can convert some 85-90% at the moment.
I started coding it with S*BASIC then I decided to complete it in Linux, that is my home computer next to and connected to QL.
It is coded as shell application using SED and PERL. If you have access to UNIX terminal, Linux or Raspberry PI, the convertor will run there. I use Debian or Raspbian on RPI. I cannot test on iMac but it may run there as well.
I am no Linux expert just possibly an advanced user, I did not know PERL before, just learnt my first steps on this project.
The convertor runs in four passes.
1st pass, translates ESC/P sequences.
note:
An escape ESC/P sequence is a formating directive for the EPSON printer.
It begins with ESC control character followed by optional parameters, on UNIX it is displayed as ^[ and can be input from the keyboard as ctrl-V + ctrl-[. Generally UNIX control characters begin with ^, and can be coded as above, e.g. ctrl-V + ctrl-Z = ^Z for end of file, Any character can be coded as ctrl-V + ctrl-(three octal digits), e.g. NULL ctrl-V + ctrl-000 produces ^@. Characters can also be coded in octal, decimal, and hex, e.g. \0101, \d65, \x41 all for capital A.
note 2:
The code below is copied to plain text, all escapes and controls reformated and appear as two chars, to run the code please use tarball posted later on at the thread
Code: Select all
#!/bin/sed -f
# converts EPSON printer file
# into HTML stream, translates ESC/P sequences
:lbl {
s/^[@// ;t lbl # file start, printer init
s/^[!.// ;t lbl # removes escape seq.
s/^[(U...// ;t lbl # -"-
s/^[6// ;t lbl # -"-
s/^[x.// ;t lbl # -"-
s/^[C.// ;t lbl # -"-
s/^[(t.....// ;t lbl # -"-
s/^[t.// ;t lbl # -"-
s/^[\\F./<hr style="width: 100%; height: 2px;">/ ;t lbl # adds seperator
s/^[\\^[^A/<br>/ ;t lbl # adds line break
s/^[\\..// ;t lbl # removes escape seq.
s/^[J.// ;t lbl # -"-
s/^[k.// ;t lbl # -"-
s/^[p.// ;t lbl # -"-
s/^[X...// ;t lbl # -"-
s/^[E/<h3>/ ;t lbl # bold font start
s/^[F/<\/h3>/ ;t lbl # bold font end
s/^[P// ;t lbl # removes escape seq.
s/^[g// ;t lbl # -"-
s/^[(^...// ;t lbl # -"-
s/^[M// ;t lbl # -"-
s/^[R.// ;t lbl # -"-
s/^[-.// ;t lbl # -"-
s/^[4/<span style="font-style: italic;">/ ;t lbl # italic script start
s/^[5/<\/span>/ ;t lbl # italic script end
s/^[S./<sup>/ ;t lbl # subscript start
s/^[T/<\/sup>/ ;t lbl # subscript end
s/SBASIC\/.*Section [0-9]// ;t lbl # removes page note
s/SBASIC\/.*Appendix [0-9 ]*// ;t lbl # removes page note
s/^L// ;t lbl # and ctrl-L
s/<\([A-Z0-9]*\)>/\<\1\>/ ;t lbl # maps < and > to html
s/\x84/\xe4/ ;t lbl # maps a umlaut to latin1
s/\xc6/\xe3/ ;t lbl # a tilde
s/\x86/\xe5/ ;t lbl # a circle
s/\xa0/\xe1/ ;t lbl # a acute
s/\x85/\xe0/ ;t lbl # a grave
#s/\xc0/\xe2/ ;t lbl # a circumflex
s/\x89/\xeb/ ;t lbl # e umlaut
s/\x82/\xe9/ ;t lbl # e acute
s/\x8a/\xe8/ ;t lbl # e grave
s/\x88/\xea/ ;t lbl # e circumflex
s/\x8b/\xef/ ;t lbl # i umlaut
s/\xa1/\xed/ ;t lbl # i acute
s/\x8d/\xec/ ;t lbl # i grave
s/\x8c/\xee/ ;t lbl # i circumflex
s/\x94/\xf6/ ;t lbl # o umlaut
#s/\x/\x/ ;t lbl # o tilde
s/\xa2/\xf3/ ;t lbl # o acute
s/\x95/\xf2/ ;t lbl # o grave
s/\x93/\xf4/ ;t lbl # o circumflex
#s/\x/\x/ ;t lbl # o bar
s/\x81/\xfc/ ;t lbl # u umlaut
#s/\x/\x/ ;t lbl # u acute
s/\x97/\xf9/ ;t lbl # u grave
s/\x96/\xfb/ ;t lbl # u circumflex
s/\x87/\xe7/ ;t lbl # c cedilla
s/\xa4/\xf1/ ;t lbl # n tilde
#s/\x/\x/ ;t lbl # ae diphthong
#s/\x/\x/ ;t lbl # oe diphthong
s/\x8e/\xc4/ ;t lbl # A umlaut
s/\x83/\xc0/ ;t lbl # A grave
s/\xc7/\xc3/ ;t lbl # A tilde
s/\x8f/\xc5/ ;t lbl # A circle
s/\x90/\xc9/ ;t lbl # E acute
#s/\x/\x/ ;t lbl # E grave
s/\x99/\xd6/ ;t lbl # O umlaut
#s/\x/\x/ ;t lbl # O tilde
#s/\x/\x/ ;t lbl # O bar
s/\x9a/\xdc/ ;t lbl # U umlaut
#s/\x/\x/ ;t lbl # C cedilla
#s/\x/\x/ ;t lbl # N tilde
#s/\x/\x/ ;t lbl # AE diphthong
#s/\x/\x/ ;t lbl # OE diphthong
s/\x9c/\xa3/ ;t lbl # pound symbol
#s/\x/\x/ ;t lbl # cent symbol
#s/\x/\x/ ;t lbl # yen symbol
#s/\x/\x/ ;t lbl # backquote
#s/\x/\x/ ;t lbl # inverse !
#s/\x/\x/ ;t lbl # inverse ?
#s/\x/\x/ ;t lbl # degree
#s/\x/\x/ ;t lbl # division
#s/\x/\x/ ;t lbl # left arrow
#s/\x/\x/ ;t lbl # right arrow
#s/\x/\x/ ;t lbl # up arrow
#s/\x/\x/ ;t lbl # down arrow
s/\xb8/\xa9/ ;t lbl # copyright
#s/\x/\x/ ;t lbl # registered
#s/\x/\x/ ;t lbl # one-quarter
#s/\x/\x/ ;t lbl # one-half
#s/\x/\x/ ;t lbl # three-quarters
}