Expanding Tabs in a Text File to a PostScript Queue


Contents

About this document
Problem
Solution for an ASCII text queue
Solution for PostScript queues
Working directions

About this document

The expand command is a UNIX command to expand tabs to a fixed number of spaces. ASCII virtual printers also expand tabs using the wh attribute, but this function does not exist for ASCII data converted to PostScript in PostScript virtual printers. PostScript printers use the enscript command to convert text to PostScript. This document explains how to combine the expand command to expand tabs with the enscript command to convert to PostScript in a single AIX virtual printer queue.

This document applies to AIX Versions 3.2.5 and 4.x.


Problem

Users wanted to use "expand -3" to expand tabs to three characters.


Solution for an ASCII text queue

See the technical document "How to Set the Virtual Printer Tabs".

Solution for PostScript queues

The solution to the problem when using a postscript queue is to set the _d attribute to a for ASCII, and to add a user filter that calls the expand utility before passing the file to enscript.

AIX 4 solution

At AIX Version 4, testing indicates that one can simply add the expand command as a User Filter as follows:

  1. chvirprt -q ps -d lp0 -a "f2=/usr/bin/expand -3"
  2. chvirprt -q ps -d lp0 -a "f=2"
  3. chvirprt -q ps -d lp0 -a "d=a"

    Testing indicates that this process works fine. All tabs printed to this queue now print as 3 spaces when sent to a PostScript queue.

    AIX 3.2.5 solution

    At AIX Version 3, the solution is not as simple. Included here are the failed attempts as a lesson in modifying the virtual printer. The final solution is given at the end and was done by modifying the ia attribute of the virtual printer.

    Testing using the fc filter failed

    First, tests to add the expand command as an fc filter were done as follows:

    1. Added line in custom file:
      :264:fc::/usr/bin/expand -3
    2. chvirprt -q ps -d lp0 -a "f=c"
    3. chvirprt -q ps -d lp0 -a "d=a"

      When running expand as a filter using "fc=/usr/bin/expand -3", nothing prints to the printer.

      Adding expand to the ia Attribute (Failed Attempt)

      This is included in the document only to show how looking at the pipeline with the -A2 flag can help resolve problems.

      lsvirprt
        ia~v
      Changed line from:
       ' && BFLAG=" -b $PIOTITLE ";/usr/bin/enscript '
       to
       ' && BFLAG=" -b $PIOTITLE ";/usr/bin/expand -3 | /usr/bin/enscript '
      
      This seemed to print, but not change the file at all.

      Printed with qprt -A2 -da -Pexpand tab.test This shows why the file is not changed. The pipeline shows:

      test "$PIOTITLE" !=  /tmp/tab.test &&
      BFLAG="
         -b $PIOTITLE ";
      /usr/bin/expand
         -3 |
      /usr/bin/enscript
         -XISO8859-1
         -p-
         -q
         -B $BFLAG
         -L66
         -fCourier10  /tmp/tab.test |
      ....
      
      This shows that enscript is being passed the original file name to print.

      Using lsvirprt with the ia~v (ia tilde v) subcommand to look at the attribute provides the following vi-like window to show the changes:

         'test "$PIOTITLE" !=  '
         %I@1          INCLUDE: (Path Name of File Being Printed)
         ' && BFLAG=" -b $PIOTITLE ";/usr/bin/expand -3 | /usr/bin/enscript '
         %?            <IF>
             %CX       PUSH: (1 If -X Flag on Command Line; Otherwise 0)
         %t            <THEN>
             %f[X]     For Each Flag x on Command Line: "-xArgument" -> OUTPUT
         %e            <ELSE>
             ' -X'
             %I_X      INCLUDE: (Code Page Name For Print Data Stream (file with same
                       name in dir. "d1"))
         %;            <END>
        
      The problem is nothing is being passed to expand, and then later at the bottom of the ia attribute we find:
         %?            <IF>
             %L_f      PUSH: (Length of Attribute:  Single-Character BSD-type Filter
                       Name (for example, "p" for "pr" filter))
         %t            <THEN>
         %e            <ELSE>
             ' '
             %I@1      INCLUDE: (Path Name of File Being Printed)
         %;            <END>
         ' | '
         %Iis          INCLUDE: (Pipeline for Input Data Stream "s" (PostScript))
        
      This shows where enscript gets the filename to print. This means that when you send data through a filter, it should not get the file name. What is evident is that no file name and no data are sent.

      Working directions

      lsvirprt
          Choose Printer Queue
          ia~v
      
      Move down below the top, long line to:
         'test "$PIOTITLE" !=  '
         %I@1          INCLUDE: (Path Name of File Being Printed)
         ' && BFLAG=" -b $PIOTITLE ";/usr/bin/enscript '
         %?            <IF>
             %CX       PUSH: (1 If -X Flag on Command Line; Otherwise 0)
         %t            <THEN>
        
      Go to the line that shows:
      • ' && BFLAG=" -b $PIOTITLE "usr/bin/enscript '
      Change this line so that it reads in 3 lines:
      • ' && BFLAG=" -b $PIOTITLE "usr/bin/expand -3 '
      • %I@1
      • ' | /usr/bin/enscript '

      Move to the bottom of the file (/tmp/expand:lpx.ia), still without leaving the vi session from ia~v.

      Delete the lines that say:

         %?            <IF>
             %L_f      PUSH: (Length of Attribute:  Single-Character BSD-type Filter
                       Name (for example, "p" for "pr" filter))
         %t            <THEN>
         %e            <ELSE>
             ' '
             %I@1      INCLUDE: (Path Name of File Being Printed)
         %;            <END>
        
      Save the changes with :wq. Back at the lsvirprt prompt reenter ia~v.

      The lines should now read:

         'test "$PIOTITLE" !=  '
         %I@1          INCLUDE: (Path Name of File Being Printed)
         ' && BFLAG=" -b $PIOTITLE ";/usr/bin/expand -3 '
         %I@1          INCLUDE: (Path Name of File Being Printed)
         ' | /usr/bin/enscript '
        
      Note how the virtual printer added the explanation:
                    INCLUDE: (Path Name of File Being Printed)
      

      Exit the vi session and then the virtual printer. You should now be ready to print.




      [ Doc Ref: 91790943811424     Publish Date: Feb. 13, 2001     4FAX Ref: 6493 ]