Re: Translating RAD-50 code
- From: Ben Morrow <benmorrow@xxxxxxxxxxxxx>
- Date: Tue, 28 Nov 2006 12:35:41 +0000
Quoth "Ferry Bolhar" <bol@xxxxxxxxxxxxxxxxx>:
I have files containing data encoded in RAD-50 format.
In this format, 3 characters (A-Z, 0-9, $, ., _, and blank
are stored in 2 bytes (so that each character is coded in
around 5 bits).
I have to read these files, process them and write out the
results again in RAD-50.
On the system, there is a shared library (under Linux, it
would be a .so, but it's VMS, so it's a .EXE), providing
routines to convert RAD-50 to ASCII and ASCII to
RAD-50.
Of course, I could write XS code containing two functions
to perform these conversions, place the XS code in a
module and load it using DynaLoader while use'ing it.
It hardly seems worth writing XS for such a simple task. Surely unpack
and a lookup table can handle it?
But I think this would be a perfect opportunity for an
IO-layer, so I (and others!) could simply write
open IN,'<:rad50',$input_file;
open OUT,'>:rad50',$output_file;
The interface for writing PerlIO layers in Perl is PerlIO::via, so if
you wanted to write the layer in Perl the interface would end up as
open my $IN, '<:via(rad50)', $input_file;
IMHO this is unnecessarily evil (the user should neither know nor care
whether a layer is implemented in Perl or C), but that's how it is.
So my question is: is there documentation how to write
IO layers in XS? Some examples, guidelines?
The documentation is in perliol (did you look?).
A good example of a simple translation layer is PerlIO::eol, on CPAN.
I'm sure you can find others by searching.
Ben
--
#!/bin/sh
quine="echo 'eval \$quine' >> \$0; echo quined"
eval $quine
# [benmorrow@xxxxxxxxxxxxx]
.
- References:
- Translating RAD-50 code
- From: Ferry Bolhar
- Translating RAD-50 code
- Prev by Date: Re: Translating RAD-50 code
- Next by Date: Re: How to get the DOM from a XML page
- Previous by thread: Re: Translating RAD-50 code
- Next by thread: regex matching exactly 10 digits
- Index(es):