How the stack language describing page width works

The IBM® LaserPrinter 4029 Series technical reference contains a figure and a table that together describe the printable and unprintable areas on a page, and the paper and envelope dimensions, in pels, for standard paper and envelope sizes.

For example, the printable area on an 8.5 x 11 (width by length) inch page is 2400 x 3200 pels (width by length). Note that if the page is rotated either 90 or 270 degrees for landscape printing, the dimensions are swapped and become 3200 x 2400 pels (width by length).

The evaluation of %IwW begins by checking to see if the w flag was used on the command line; if it was, then there are no calculations to perform. The requested value will be used. (That is not a promise that it will work, just that it will be used.) If the w flag was not used on the command line, then piobe has to figure out how wide the page is under the current job environment, as determined by other command line flags and by colon file defaults.

The first item checked in the evaluation of _w (page width) is page orientation (_z). As noted above, rotating the page by odd multiples of 90 degrees flips the page dimensions. Looking at the if-then-else statement that is the beginning of the definition of wK, it can be seen that the value of _z is a switch that controls which of wJ and wK will be used for page width. If the page has a portrait orientation, then wJ is width. If the page has a landscape orientation, then wK is width. After the page width in pels is resolved, the remainder of the escape sequences in the definition of wK just take pitch and character-width (double wide or not) into account while converting the number of pels to the number of characters.

The wK attribute is selected because the page orientation is landscape. Thus far all that is known is that the dimensions have been flipped; what the dimensions actually are is still unknown. The evaluation of wK begins by fetching the value (if any) of a command line usage of the Q flag, which is a printer-dependent value requesting a specific paper size. If the Q flag was used on the command line, then that value will be used to select the paper width in pels, otherwise a value for Q will be determined by evaluating Wu, which is a value for the paper source based on the attributes _O (type of input paper handling) and _u (input paper source). Note that _Q is defined as %IwQ, whose definition begins with %IWu.

Because Q was not used on the command line, the evaluation of Wu determines that the O flag wasn't used either, and so executes the else clause in the outer if-then-else statement in the definition of Wu, returning the default colon file value of _u, 1, to the evaluation of wQ.

Because this is as deep as the nesting of escape sequences goes for the evaluation of _w, it is worth taking a closer look at the logic defining Wu. Keep in mind the definitions and legal values for O, u, and Q, which are:

  • O - type of input paper handling - 1 (manual), 2 (continuous forms), 3 (sheet feed) - default is sheet feed.
  • u - input paper source - 1 (primary), 2 (alternate), 3 (envelope) - default is primary.
  • Q - paper size for input paper source - values are printer-dependent - defined by combination of O and u.

The escape sequences defining Wu say this:

  • Case 1: If the O flag was not used on the command line, then return the colon file default value for _u. For example, if the user did not specify a type of input paper handling, then return the input paper source (either from the command line or the default from the colon file) to the evaluation of %IwQ.
  • Case 2: If the O flag was used on the command line but its value was not 1, then return the colon file's default value for _u. For example, if the user-specified a type of input paper handling other than manual,then return the input paper source (either from the command line or the default from the colon file) to the evaluation of %IwQ.
  • Case 3: If the O flag was used on the command line and its value was 1, and the u flag was not used on the command line, then return a 0. For example, if the user-specified manual paper handling but did not specify an input paper source, then return a 0 to the evaluation of %IwQ.
  • Case 4: If the O flag was used on the command line and its value was 1, and the u flag was used on the command line and its value was not greater than 2, then return a 0. For example, if the user-specified manual paper handling and also specified either the primary or alternate input paper source, then return a 0 to the evaluation of %IwQ.
  • Case 5: If the O flag was used on the command line and its value was 1, and the u flag was used on the command line and its value was greater than 2, then return a 4. For example, if the user-specified manual paper handling and also specified an input paper source of envelope, then return a 4 to the evaluation of %IwQ.

The definition of wQ is an if-then-else-then-else-then-else-then-else statement that repeatedly compares the value of Wu to the integers 0, 1, 2, and 3, looking for a match. The match selects the value of one of the attriubes s0, s1, s2, s3, or s4, respectively (s4 is selected when there is no other match). The items these attributes define are as follows:

  • s0 - paper size for manual paper feed
  • s1 - paper size for tray 1 (upper)
  • s2 - paper size for tray 2 (lower)
  • s3 - envelope size for envelope feeder
  • s4 - envelope size for manual envelope size

In the virtual printer definition for an ASCII queue on an IBM 4029 LaserPrinter, there are only two unique values for these five attributes: s0, s1, and s2 are all 1, while s3 and s4 are both 3.

Looking back up the nested escape sequences, you can see that the definition of wK is composed of an outer if-then-else statement. Both the if and the else pieces of this statement contain a chain of if-then-else-then-else... statements. The value of Wu (which is a value for paper source, based on O and u) determines whether the if or the else piece of the outer statement executes; if Wu is 1 or 2 (less than 3), then the if piece executes, otherwise the else piece executes. It is in the final determination of wK that the page width, in pels, is fixed.

Case 1: Either the command line value of u or the default from the colon file (1, primary paper tray) is returned to the evaluation of wQ. The remaining escape sequences in the definiton of wQ test the value of Wu and select the value of one of s0, s1, s2, s3, or s4. That value is in turn returned to the evaluation of wK. If u is 1 or 2 , then Q will be 1 (non-envelope paper size). If u is 3, then Q will be 3 (envelope paper size). When the evaluation of wK is resumed, a u value of 1 or 2 will direct the process into the if piece of the outer if-then-else statement, and the Q value of 1 will select a page width of 3200 pels. A u value of 3 will direct the process into the else piece of the outer if-then-else statement, and the Q value of 3 will select an envelope page width of 2750 pels.

Case 2: Same as case 1.

Case 3: The user-specified manual paper handling on the command line but did not specify a paper source so Wu is assigned the value 0, and that value is returned to the evaluation of wQ. The 0 will cause wQ to be assigned the value of s0 (the paper size for manual paper feed, a 1). When the evaluation of wK is resumed, the u value of 0 will direct the process into the if piece of the outer if-then-else statement, and the Q value of 1 (s0) will select a page width of 3200 pels.

Case 4: The user-specified manual paper handling on the command line and also used the u flag to specify either the primary or alternate paper source (but definitely not envelopes). As with case 3, a page width of 3200 pels will be chosen.

Case 5: The user-specified manual paper handling on the command line and also used the u flag to specify an envelope paper source so Wu is assigned the value 4, and that value is returned to the evaluation of wQ. The 4 will cause wQ to be assigned the value of s4 (the envelope size for manual envelope size, a 3). When the evaluation of wK is resumed, the u value of 4 will direct the process into the else piece of the outer if-then-else statement, and the Q value of 3 will select an envelope width of 2498 pels.

  • Our example is case 1: neither the O nor the u flags were used on the command line, so Wu is assigned a value of 1, the default _u value for this colon file. When the evaluation of wQ resumes, the match occurs on s1, and a 1 is returned to the evaluation of wK. The u value of 1 direct the process into the if piece of the outer if-then-else statement, and the Q value of 1 selects a page width of 3200 pels. This value is returned to the evaluation of _w.

The remaining printer colon file escape sequences defining _w reason that if there are 3200 pels available (horizontally), and if we want 12 characters per inch, and if the resolution of printer is 300 pels per inch, then 128 characters can be printed across the page. Both the pitch and the printer resolution are multiplied by 10 to account for the possibility of a 17-pitch being specified. A 17-pitch is actually 17.1, so multiplying both the numerator and the denominator by 10 causes the .1 to be accounted for in the final calculation of page width. The value 128 is returned to the evaluation of ia. That's basically where the -128 in the PIPELINE OF FILTERS came from.