1
package Language::INTERCAL::Charset::Baudot;
3
# Convert between Baudot and ASCII
5
# This file is part of CLC-INTERCAL.
7
# Copyright (C) 1999, 2000, 2002, 2006 Claudio Calvelli, all rights reserved
9
# CLC-INTERCAL is copyrighted software. However, permission to use, modify,
10
# and distribute it is granted provided that the conditions set out in the
11
# licence agreement are met. See files README and COPYING in the distribution.
13
use vars qw($PERVERSION);
14
$PERVERSION = "CLC-INTERCAL INTERCAL/Charset/Baudot.pm 1.-94.-4";
19
use Language::INTERCAL::Exporter '1.-94.-4';
20
use vars qw(@EXPORT @EXPORT_OK);
22
@EXPORT_OK = qw(ascii2baudot baudot2ascii);
24
use Language::INTERCAL::Splats '1.-94.-4', qw(:SP);
27
"\000E\nA SIU\rDRJNFCKTZWLHYPQOBG2MXV1",
28
"\000e\na siu\rdrjnfcktzwlhypqobg2mxv1",
29
"\0003\n- \a87\r\$4',!:(5\")2 6019?&3./;0",
30
"\000\242\n+\t\\#=\r*{~\245|^<[}>]\b@\253\243\254\377\2613%_\2730",
33
my $charset = join('', map { "\000" . substr($_, 1, 26) .
34
"\000" . substr($_, 28, 3) . "\000" }
39
@_ == 1 or croak "Usage: baudot2ascii(STRING)";
43
while ($string ne '') {
44
my $chr = ord($string) & 037;
45
$string = substr($string, 1);
46
if ($chr == 033 || $chr == 037) {
47
$set = ord(substr($charset[$set], $chr, 1)) & 03;
49
$result .= substr($charset[$set], $chr, 1);
56
@_ == 1 or @_ == 2 or croak "Usage: ascii2baudot(STRING)";
58
my $faint = @_ ? shift : 1;
61
while ($string ne '') {
62
my $chr = substr($string, 0, 1);
63
$string = substr($string, 1);
64
my $pos = index($charset[$set], $chr);
65
if ($pos < 0 || $pos == 033 || $pos == 037) {
66
$pos = index($charset, $chr);
67
if ($pos < 0 || $chr eq "\000") {
68
faint(SP_NOSUCHCHAR, ord($chr), "Baudot") if $faint;
69
$string = sprintf("\\%03o", ord($chr)) . $string;
75
$result .= ['[_', '__', '_[', '[[']->[$s];
77
$result .= ['', '_', '[', '[[',
81
]->[($set << 2) | $s];
85
$result .= sprintf("%c", 0x40 + $pos);
96
Charset::Baudot - allows to use Baudot string constants in ASCII programs (and v.v.)
100
use Charset::Baudot 'baudot2ascii';
102
my $a = baudot2ascii"(Baudot text)";
106
I<Charset::Baudot> defines functions to convert between a subset of ASCII and a
107
subset of nonstandard Baudot - the original Baudot allows only letters,
108
numbers, and some punctuation. We assume that a "Shift to letters" code
109
while already in letters mode means "Shift to lowercase" and "Shift to
110
figures" while already in figures mode means "Shift to symbols". This allows
111
to use up to 120 characters. However, for simplicity some characters are
112
available in multiple sets, so the total is less than that.
114
Two functions, I<baudot2ascii> and I<ascii2baudot>, are exportable (but
115
not exported by default). They do the obvious thing to their first argument
116
and return the transformed string.
118
=head1 BAUDOT CHARACTER TABLE
120
The following are the characters recognised. As described, the "shift"
121
characters have nonstandard meaning.
123
set Letters Lowercase Figures Symbols
127
02 L/F L/F L/F L/F (line feed)
129
04 Space Space Space Tab
133
08 C/R C/R C/R C/R (carriage return)
152
27 Figures Figures Symbols Symbols
156
31 Lowercase Lowercase Letters Letters
160
This module is part of CLC-INTERCAL.
162
Copyright (C) 1999, 2000, 2002, 2006 Claudio Calvelli, all rights reserved.
164
See files README and COPYING in the distribution for information.
168
A qualified psychiatrist.