Explanation of showpr

[previous] [next] [table of contents] [index]

The Section Custom Printing: showpr gives an overview of this script. Here is the showpr script (you might want to open it in a separate browser window). To install it, see the Section Programs in This Book's Archive.

The prwidth shell variable sets the width passed to scan at the start of the final while loop. This is the maximum width of the heading that is given to pr, not including the first five characters of the scan output (namely, the message number). Because our version of pr can take headings that are about 50 characters wide without making the output line more than 80 characters wide, I've set prwidth=55 here (50 + 5 = 55). You might need to adjust it for your version of pr.

The eval set x ... command combines options from your MH profile with the options typed on the command line. showpr reads your MH profile entry with mhparam or mhprofile. The shell's set command resets the command-line parameters, and the dummy x argument makes sure that there's at least one parameter set. (Without the dummy argument, if there are no other arguments, set will output a list of current shell variables.) The shift command removes the dummy argument.

The Table below shows what happens inside the shell as it interprets the eval command. It assumes that the MH profile entry looks like this:

showpr: -format 'Message %(msg)' -mhl
And the command line is:
% showpr -pr -f

Table: Shell Evaluating showpr eval Command


Original line   eval set x `$mhprofile -b $myname` '${1+"$@"}'

Before eval     eval set x -format 'Message %(msg)' -mhl ${1+"$@"}

After eval*     set x -format Message %(msg) -mhl -pr -f
                ___ _ _______ ______________ ____ ___ __
*In the last table step, each argument is underlined.

Notice that some of those arguments -- like Message %(msg) -- have embedded spaces. The shell doesn't have any problem with that. Here are a few debugging lines you can add to showpr that show the command-line arguments one by one, with a count of how many:

echo "DEBUG: $# arguments now.  They are:"
for arg
do echo "$arg"
For example, with the command line above, putting that code after line 21 would print:
DEBUG: 6 arguments now.  They are:
Message %(msg)
Another way to look at this is by setting the shell's -xv flags to get debugging/tracing output.

The -help message uses the revision number and date from the co command of the Revision Control System, RCS, with its $Revision: 1.0 $ and $Date: 1996/06/06 15:09:54 $ keywords. The backslash (\) before each dollar sign ($) stops the shell from trying to expand $Revision and $Date as shell variables.

The final while loop watches for unreadable messages that the scan in MH 6.6 and before complains about (it complains on the standard output channel, unfortunately, so the error messages go down the pipe and into the loop!). This problem was fixed in MH 6.7.

scan in MH 6.7 (and later) prints a much more useful message. Even better, the message goes to the standard error:

scan: can't open message num: Permission denied, continuing...
That message on stderr never reaches stdout -- so the read gets the next line of scan's standard output, and the loop continues right away.

Because the while loop keeps running until it's read all the messages, and because pr prints out complete pages, the user running showpr can't tell how many times the loop is executed. To the user (or the program reading from showpr), the output looks like a constant stream of pages to print.

[Table of Contents] [Index] [Previous: Explanation of scandrafts] [Next: Explanation of storeparts]

Last change $Date: 1996/06/06 15:09:54 $

This file is from the third edition of the book MH & xmh: Email for Users & Programmers, ISBN 1-56592-093-7, by Jerry Peek. Copyright © 1991, 1992, 1995 by O'Reilly & Associates, Inc. This file is freely-available; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation. For more information, see the file copying.htm.

Suggestions are welcome: Jerry Peek <jpeek@jpeek.com>