PRINTRAN\PRINTRAN.DOC ·
DOC ·
18.2 KB ·
1990-05-02 ·
from PCPlus_Personal-Productivity-Pack_Disk-1_Jun-1990
PRINTRAN
Version 0.41
J.C. Mansfield
CONTENTS
Section
1 Copyright
2 Introduction
3 Invoking PRINTRAN
4 Replacing an existing translation
5 To cancel an existing translation
6 To restore a previous translation
7 Error Messages
8 PRINTRAN and graphics output
9 Translations supplied with PRINTRAN
10 Writing a translation file
11 Applications
1) Copyright
I wish to encourage free distribution of PRINTRAN to anyone who wishes
to use this program, and therefore I give permission for copies to be
made (for both private and commercial use) providing that the
following conditions are observed when making copies.
1) These conditions are to be imposed on all subsequent users and
recipients of copies.
2) Any person or organisation making copies for others does so on
a non-profit making basis, and may only charge for cost of
materials, postage and packing. This applies to the following
files:
PRINTRAN.COM
PRINTRAN.HLP
PRINTRAN.DOC
BOXES.TRA
BOXES.DOC
SHOWCTRL.TRA
^CHARS.TRA
HEXDUMP.TRA
3) The files PRINTRAN.COM & PRINTRAN.DOC (i.e. this file) must not
be modified or renamed. Distribution in an archived form is
permitted.
4) As a minimum, at least PRINTRAN.COM and PRINTRAN.DOC must be
copied.
5) Any files, except PRINTRAN.COM & PRINTRAN.DOC, may be
distributed in a modified form, providing the copyright of the
original file is acknowledged as a comment within the file.
Any comments or suggestions for new applications of PRINTRAN or
improvements to it are welcome. You may contact me by sending a
message -
via Email to: Microlink (on ISTEL INET) MAG31586 or
via telex to: 94081297 MANJC G
John Mansfield.
2) Introduction
I originally wrote PRINTRAN to get around problems I had in attempting
to make a new printer (NEC Pinwriter P2200) work with Amstrad 1512
Wordstar. Even though the Printer's disk contains drivers for 247
printers, I was unable to find a driver which exactly matched, and I
didn't have time to try all 247!. So I tried a driver suggested by
Amstrad, which appeared to be a close match. I then used the
hexadecimal dump facility on the printer to identify what escape codes
Wordstar was sending, and used the printer instruction booklet to
determine what codes the printer should receive. I now use PRINTRAN to
make any modifications necessary at the time a document is printed.
Part of PRINTRAN is a Terminate Stay Resident (TSR) program. When
PRINTRAN is run, and a valid, syntactically correct translation file
is specified, part of the program together with translation data
becomes resident in memory. The resident program intercepts characters
sent to LPT1 and checks for any sequences that require translation. If
a matching sequence is found, a different sequence is substituted; if
a character does not form part of a matching sequence, then it is sent
on to the printer unaltered.
Although PRINTRAN was originally intended for printer escape
sequences, it works with any characters. An example of a translation
involving printable characters can be found in the BOXES.TRA
translation file (See BOXES.DOC for further information).
3) Invoking PRINTRAN
At the MSDOS prompt, assuming PRINTRAN is in the current directory,
type:
PRINTRAN [<translation filename>] [<switch> [<switch> [ ... ]]
The filename and the switches must be separated from each other and
from the command (PRINTRAN) by spaces.
[ ] Indicates an optional item
<translation filename> must give the full filename including
extension. I have used the extension ".TRA" but this is not a default.
The extension must always be specified, unless either of the switches
"/on" or "/off" are specified. If these are specified, then any
filename given is ignored.
<switch> may be any of the following (in upper or lower case):
/large Reserves the maximum possible amount of data memory for the
translation table within the TSR program. This switch is only
effective at the time the TSR becomes resident. When the
switch is used, this message is displayed:
Large memory option used
If omitted, only sufficient memory (plus a small overhead) is
reserved for the particular translation specified and it will
not be possible to load larger translations without rebooting
the PC.
/notitle Normally, the title of the translation (given on the first
line of the translation file) is displayed using the error
output. Use of this switch suppresses this message.
/off Providing that a valid translation is installed and operating,
this switch causes translation to be removed, causing the
LPT1: device to revert to normal operation.
/on Providing that a valid translation exists in memory, but is
switched off, it may be brought back into service again by
use of this switch, without respecifying the translation file
name. This avoids the need for the translation file to be
reread from disk.
All error and status messages are sent to standard output and may be
suppressed by adding ">NUL" to the command line.
Once a translation is installed, any further text sent to LPT1: will
be translated automatically. If PRINTRAN is to be used regularly, it
is suggested that it is included in the AUTOEXEC.BAT file. If it is
being used with other resident programs such as MODE and PRINT, then
attention should be paid to the order in which they are placed. Any
redirection to serial ports should occur first, followed by
PRINTRAN and then by any programs that will make use of the
translation (eg. PRINT).
Example:
MODE COM1:1200,N,8,2,P
MODE LPT1:=COM1:
PRINTRAN <translation filename>
PRINT /d:LPT1
4) Replacing an existing translation
If a new translation is required in place of an existing one, repeat
the above procedure ("/large" has no effect):
PRINTRAN <translation filename>
5) To cancel an existing translation
PRINTRAN /off
6) To restore a previous translation:
PRINTRAN /on
7) Error Messages
Any error that occurs while the translation file is being processed is
displayed. Processing stops immediately an error is detected.
The error message is displayed in the form:
Error nn: <Text>
Where appropriate, the text will indicate the line number of the
translation file in which the error was detected.
Below is a complete list of all possible errors:
Error 1: Insufficient memory for translation table
Error 2: Translation file not specified
Error 3: Translation file not found
Error 4: Programming error
Error 5: Unable to read whole of translation file
(Error 6 not used)
Error 7: Invalid character follows tilde
Error 8: Missing delimiter and translation
Error 9: Two delimiters
Error 10: Missing file terminator
Error 11: Missing header - File must commence with "TRANSLATE"
Error 12: Matching file terminator and delimiter
Error 13: Duplicate input string
Error 14: No translations found
Error 15: Invalid decimal digit
Error 16: Decimal number > 255
Error 17: Invalid hexadecimal digit
Error 18: Translation too large to convert
Error 19: Incompatible switches - /ON & /OFF
Error 20: /ON cannot be used - No valid translation exists
Error 21: Translation is already ON
Error 22: /ON cannot be used - Current translation is invalid
Error 23: /OFF cannot be used - No valid translation exists
Error 24: Translation is already OFF
On exit, the error number is returned in errorlevel. If no error
occurs, errorlevel is set to 0.
If the file PRINTRAN.HLP is present in the current drive & directory
when the program is running, extra information will be displayed
automatically after an error occurs. However, when translation files
are known to be correct, PRINTRAN.HLP may be removed, to economise on
disk space.
PRINTRAN.HLP should not be edited in any way. If the message
"PRINTRAN.HLP corrupted" appears after an error message, a new copy of
this file should be obtained from the original disk on which it was
supplied.
8) PRINTRAN and graphics output
PRINTRAN is unable to distinguish between text and graphics output and
should be disabled when using graphics programs as it may corrupt
graphics images.
The following included in the batch file used to invoke the
graphics program will ensure that PRINTRAN is disabled, and re-enable
it again afterwards:
ECHO OFF
PRINTRAN /OFF >NUL
REM Branch taken if no translation present
IF ERRORLEVEL 23 GOTO run
ECHO Printer translation removed
SET pr=y
:run
---.-
Batch program to invoke graphics application
---.-
IF NOT "%pr%"=="y" GOTO end
SET pr=
PRINTRAN /ON
:end
9) Translations supplied with PRINTRAN
BOXES.TRA Converts line drawings made using keyboard characters
into continuous lines made up of block graphics
characters. BOXES.DOC gives further information
HEXDUMP.TRA Causes all output sent to LPT1 to be printed as a
sequence of 2 digit hexadecimal numbers. Make sure that
the printer is set to generate an automatic Carriage
Return / Linefeed when the print head reaches the right
edge of the paper.
^CHARS.TRA Prints ascii codes in the range 0 to 31 as their
corresponding control characters. E.g: 0 => ^@, 1 =>
^A, 2 => ^B, etc.
SHOWCTRL.TRA Prints ascii codes in the range 0 - 31 as their
corresponding names. E.g 0 => <NUL>, 1 => <SOH>, 27 =>
<ESC>.
10) Writing a translation file
The remainder of this introduction may be ignored by those who do not
need to write or modify translation files.
A translation file specifies a list of character sequences that when
encountered on output to LPT1 are to be substituted with another
string. The file must have this format:
<File header>
<File terminator>
<Delimiter>
<Body of file>
<File terminator>
Throughout the remaining description, the term "First significant
character" refers to the first character on a line which is not a
space or a control code. Note that this includes Carriage Return and
Linefeed, and therefore empty lines are allowed.
File header
The word "TRANSLATE" must be placed in line 1, column 1 of the file,
or the file will be ignored and an error message generated. The
remainder of the line is displayed at run time to indicate which
translation is being used. This line may be suppressed by adding the
switch "/notitle" to the command line
File terminator
The first significant character on the line following the file header
indicates the single character that will signal "end of file". In
theory, any character is possible, but it is wise to avoid tilde (~)
and alphanumeric characters.
A line must be placed at the end of the file which has the file
delimiter as the first significant character.
Delimiter
The first significant character on the line following the file
terminator indicates the single character that will be used as a
delimiter. The character used as the file terminator may not be used
here, but any other character is possible. As mentioned above it is
wise to avoid tilde (~) and alphanumeric characters.
Body of file
Normally, a character is specified by simply entering it as a text
character. However, this is not allowed where the character is:
a control code (Ascii value below 32)
space
tilde
delete (Ascii value 127)
file terminator
delimiter
A number of alternative methods are provided to specify these
characters all of which start with tilde (~):
~@ or ~` Null character (Ascii code = 0)
~A ... ~Z Corresponding control code
~a ... ~z Corresponding control code
~[ Escape (Ascii code 27)
~<Backslash> Ascii code 28
~] Ascii code 29
~^ Ascii code 30
~_ Ascii code 31
~$hh Ascii value given by hex value hh
~ddd Ascii value given by decimal value ddd
~c where "c" is any text character not accounted for
above, returns the character, with any special
significance removed. Of particular use are ~~ and
~space.
Any character defined using ~ will not be recognised as a file
terminator or delimiter.
Translation lines
Providing the first significant character on a line is not a
delimiter, the line must specify a translation. Starting from the
first significant character, the format of the line must be:
<match string><delimiter><substitution string>[<space><comment>]
A match string will be invalid if:
the string matches any previous match string;
any leading portion of the string matches any previous match
string;
the string matches the leading portion of any previous match
string;
or the string contains a space which has not been preceded by
tilde (~).
The delimiter must not be specified by any means involving tilde (~).
The substitution string may contain any characters. If space is
required within the string, then it must be preceded by tilde (~). Be
careful of strings with space as the final character; it is safer to
use ~032 in this case. Substitution strings may be duplicates of any
other strings in the file.
A space or end of line terminates the substitution string. Any
remaining characters are treated as a comment, and are ignored.
A null substitution string is allowed.
Comment lines
If the first significant character on a line is the delimiter, then
the remainder of the line is treated as a comment.
For an example of a translation file, use an editor to examine the
BOXES.TRA file.
11) Applications
Although I originally wrote PRINTRAN to overcome compatability
problems, I am continually finding new applications. As translations
such as BOXES.TRA demonstrate, PRINTRAN can translate both printing
and non-printing sequences. Below are some examples, which have been
used on an NEC Pinwriter P2200:
Printer initialisation
Most word processors will send an introducing sequence at the start of
a document. The translation files HEXDUMP.TRA, ^CHARS.TRA or
SHOWCTRL.TRA can be used to ascertain exactly what it is. Usually,
this will include a printer reset code, which PRINTRAN can be
programmed to recognise and add additional control information. I have
used this to place the printer into ITC Souvenir 10 before printing a
document. This is not possible with my wordprocessor or with the
printer front panel controls.
The following illustrates how this can be achieved:
~[@/~[@~[k~015
| | | |
| | | |
Matches printer reset ---].| | .]-.- Selects ITC Souvenir 10
code from the | |
word processor |.]----.- Repeats the printer reset code
|
Delimiter
Also, I had noticed that my word processor generated a code which was
not defined in the printer handbook, but would probably have selected
the italic character set as opposed to the IBM character set. Since I
required IBM characters, I used the following translation to select
IBM instead:
~[t~$02/~[t~$01
| | |
| | |
Select undefined set ---]. |.]-.- Select IBM set
(from word processor) | (to printer)
Delimiter
Modifying a printer character set
I have used a translation to insert a character from one font into
another. In this example I have taken a Greek capital Delta from a 10
cpi character set and inserted it into a 12 cpi character set. The
translation is shown below:
~253/~[k~012~209~[k~015
| | | | |
Code 253 specifies ---]. | | | .]-.- Reselect ITC Souvenir 10
the Delta character | | |
| | |
| | .]--.- Generate Delta character (209)
| |
|.]--------.- Select OCR-B character set
|
Delimiter
Visible Control Codes
Many wordprocessors prevent control codes from being entered directly
into a file. I use visible control codes by choosing sequences of
characters which I know will never occur in any document (except this
one!).
If the paper is to be positioned on my printer so that it can be
torn off, this leaves an unacceptably large top margin. I have created
the codes //REV & //ADV which cause the paper to reverse or advance a
fixed distance. By placing //REV in the header and //ADV in the
footer, the paper is repositioned for printing before the start of the
page and advanced at the end of the page to allow the paper to be torn
off. In this example, note the use of ~/ to remove the significance of
/ as a delimiter.
~/~/REV/~[j~225 Reverse feed 225/180 inches
~/~/ADV/~[J~225 Advance feed 225/180 inches
My wordprocessor is unable to generate double height or width
characters. I use the following codes to do this:
~/~/HIGH~/ON/~$1CV~001 Set double height
~/~/HIGH~/OFF/~$1CV~000 Set double height
~/~/WIDE~/ON/~$1CE~001 Set double width
~/~/WIDE~/OFF/~$1CE~000 Set double width
^
Suppressing Printer Output
In the course of my work, I frequently have to use a program which
gives alarm messages both on the screen and on the printer. When using
this program for teaching purposes, it can waste a lot of paper. I
have written a translation file (similar to HEXDUMP.TRA) which
translates every character to nothing, except Carriage Return, which
is translated to the Bell character (7). The result is that no paper
is used, but the printer beeps a few times when a new message appears
on the screen.