Sidebar: Panasonic Printer Interface Codes
The Bourne shell code in Listing 1 is extracted from
a printer interface
file for the Panasonic KX-P1180, a small dot-matrix
printer. It recognizes
several codes that can apply to an entire document,
and a couple of
codes that might be useful for some documents, even
if they are not
widely applicable. Instead of the "standard"
file, however,
I chose to modify one of the other files, named "dumb."
It
is a minimal printer interface definition that is a
good place to
start when all the facilities of the standard file are
not needed.
Several variables are defined at the top to have numerical
codes that
correspond to the actual codes the printer uses. This
allows the variable
names to be plugged directly into the command string.
Notice that
some of the variables are initialized with the word
"no" and
others are initialized in terms of other variable settings.
Then the
loop that evaluates the options variable begins.
The nlq and tab4 variables are simple options set by
using -o nlq or -o tab4. The font and justify
options are value-setting options, which could have
any of the
names listed as NLQ fonts or Justification codes. It
uses the parse
function discussed in the text, but it also uses a technique
I found
for working with meaningful names instead of requiring
magic numbers.
By using the syntax
font=`eval echo $"$font"`
the current value set in the font variable by
the parse function will be output within the quotation
marks.
The quotation marks will be stripped when the substitution
surrounded
by back-quotes is evaluated. Thus, that quoted name
will become a
variable because of the $ placed before the open quotation
mark, so the value associated with that name, now a
variable, is delivered
to the echo command. So, if -o font=sansserif is used,
the first pass becomes
font=`eval echo $sansserif`
which becomes
font=1
letting the computer remember the magic number and the
user remember the font name. The same logic is used
with the justify
option.
The other options take advantage of the fact that this
printer can
combine several enhancements in a single, bit-encoded
command. Pica
is default 0, and mutually exclusive with elite, but
the rest --
proportional, compressed, emphasized, double-strike,
wide, italic,
and underline -- may all be possible in any combination.
If you
combine them into a single variable, progpitch (for
programmable
pitch), they can be output at once.
When the options are all determined, the code first
resets the printer,
then sets up the NLQ operation, if needed. These steps
are done with
the echo command, since everything that goes to stdout
will get to the printer. These commands take advantage
of echo's ability
to embed octal codes in the string (recall that the
\c code
tells echo not to output a newline after the string).
The second echo
of the NLQ string sequence embeds the font variable.
For the programmable pitch variable, there was a small
problem. The
printer needed the command expressed as a binary value
(which echo
can do as an octal value), not the decimal value expressed
by echoing
a variable. By running it through the printf() function
in
awk (a little overkill, but it worked), I could convert
it
to the octal form needed. The echo program is pretty
particular
about this format, too, wanting to see that leading
zero in the octal
number no matter what, so a zero had to be specifically
put into the
echo. (The awk descriptor could have been made %04o
instead.)
After this code comes the loop that outputs the copies
to the printer.
This fragment should give some ideas on how to handle
some of the
special capabilities offered by most of the more advanced
printers
available today.
|