        Testing IFHP In Stand-alone Mode
             Patrick Powell
         Thu Jun 13 07:36:36 PDT 2002

Introduction

  Usually when you have problems with a print filter you want to
  find out the actual output and examine it in detail, or you want
  to process and send a job to a printer without the overhead of
  the print spooler.
  
  This note discusses how to use the built-in ifhp test facilities,
  the netcat (nc) program, and the sendhp.sh test script.

Debug Options

  The ifhp program has built in debugging and trace facilities that
  are enabled by using the -Tdebug=xxx and -Ttrace option.
  The 'trace' option causes trace output to be sent to STDOUT;
  the debug=xxx sets debug flags:
    debug=0   - no trace/debug output
    debug=1   - whimpy trace/debug output
    debug=2   - serious trace/debug output
    debug=3   - heavy duty trace/debug output
    debug=4 or higher - totally horribly anal debug output

   In addition you can enable tracing of the ifhp.conf database
   parsing operation:
    debug=database   - whimpy
    debug=database+1 - more detail 
    debug=database+2 - even more detail
    debug=database+3 or higher - more detail than you ever wanted

  And you can combine them:
    debug=1 database  - note that space separator
  
Test Script - sendhp.sh
  
  The ifhp source distribution has a set of utility programs in the
  UTILS directory, which is copied to the UTILS subdirectory in the
  same location as the ifhp filter.
  
  if ifhp is /usr/local/libexec/filters/ifhp then UTILS are in:
     /usr/local/libexec/filters/UTILS/sendhp.sh
  
  and the sendhp.sh test script is:
     /usr/local/libexec/filters/UTILS/sendhp.sh
  
   sendhp.sh  SCRIPT
  
    #!/bin/sh
    # test script for testing ifhp.conf
    
    prefix=/usr
    exec_prefix=${prefix}
    sysconfdir=/etc
    mandir=/usr/share/man
    libexecdir=${exec_prefix}/libexec
    FILTER_DIR=${libexecdir}/filters
    # variables:
    # ifhp - location of the ifhp file to use
    #   - if you are testing an INSTALLED version, set this
    #     to the location of ifhp
    # ifhp=${libexecdir}/filters/ifhp  # installed
    # ifhp=./ifhp             # current directory
    #
    # out - output is sent here
    #   this can be a file or a network connection, i.e. -
    #    port 9100 on most jetdirect or other boxes.  It can even
    #    be a bidirectional printer port.
    # out=10.0.0.14%9100      # network printer connection
    # out=/tmp/out            # output to a file
    #
    # debug  - set debug level and options
    # debug=0 or 1  or 2 or 3 or 4 ... you get the idea
    #             0 is NO debugging, 4 is extremely verboese
    # debug=1 database  # note the SPACE separator
    # debug=1 database+2
    #       The database flag controls debug traceing of reading
    #       the ifhp.conf database.  VERY verbose, and gets REALLY
    #       verbose.  I kinda went overboard here...
    # 
    # file -  input file              
    #       I usually use the UTILS/one.ps or UTILS/one.pcl file
    #       or do 'echo hi >/tmp/hi' for a test file.
    # model - set the model information
    #   yeah yeah, I know... but you have to have
    # model=ps
    # model=hp5si
    #
    # options - you set the options you want to add here
    # options=info=variables
    #
    ifhp=${libexecdir}/filters/ifhp
    ifhp=./ifhp
    out=10.0.0.14%9100
    out=/tmp/out
    debug=
    file=/tmp/hi
    file=${libexecdir}/filters/UTILS/one.ps
    file=${libexecdir}/filters/UTILS/one.pcl
    #model=model=ps
    #model=info=variables
    if [ -f "$out" ] ; then cp /dev/null $out ; fi
    $ifhp "-Tdev=$out,trace,debug=$debug,model=$model" \
       <$file 2>&1 | tee /tmp/log
  
  
USING sendifhp.sh

  These notes shows the various option values and then the command
  line and output. By convention, the sendif.sh script is copied
  to /tmp and then modified.

1. Simple Test

    ifhp=${libexecdir}/filters/ifhp
    out=/tmp/out
    file=${libexecdir}/filters/UTILS/one.ps
      (OR file=${libexecdir}/filters/UTILS/one.pcl
       if your printer does not support PostScript)
    debug=1

     # > sh /tmp/sendhp.sh
     ifhp 12:41:27.840 [31515] main: Debug '1', DbgFlag 0x0
     ifhp 12:41:27.840 [31515] main: dump <NULL>
     ifhp 12:41:27.840 [31515] main: Model_id ''
     ifhp 12:41:27.840 [31515] main: LANG '<NULL>', 'TRANSLATE TEST' is 'TRANSLATE TEST'
     ifhp 12:41:27.870 [31515] main: scanning Raw for default, then model ''
     ifhp 12:41:27.904 [31515] main: using model ''
     Version ifhp-3.5.9
     $Id: README.TESTING,v 1.1 2002/06/22 01:05:10 papowell Exp papowell $
     Copyright 1992-2002 Patrick Powell <papowell@astart.com>
     ifhp 12:41:27.905 [31515] Open_device: device '/tmp/out'
     ifhp 12:41:27.905 [31515] Open_device: closed fd 1
     ifhp 12:41:27.905 [31515] Open_device: device '/tmp/out', attempt 0
     ifhp 12:41:27.905 [31515] Open_device: success
     ifhp 12:41:27.905 [31515] main: poll for status 0, Dev_sleep 1000 msec
     ifhp 12:41:27.907 [31515] Process_job: setting up printer
     ifhp 12:41:27.907 [31515] Start_of_job: do_pagecount 0, ps 0, pjl 0, prog '<NULL>'
     ifhp 12:41:27.907 [31515] Do_accounting: pagecounter 0
     ifhp 12:41:27.907 [31515] Accounting: script '<NULL>', Accountfile '<NULL>',
            output 'filestart '-q31515' '-p0' '-t2002-06-13-12:41:27.907''
     ifhp 12:41:27.907 [31515] Start_of_job: doing 'init'
     ifhp 12:41:27.907 [31515] Start_of_job: doing pjl
     ifhp 12:41:27.907 [31515] Start_of_job: 'pjl_init'='[ info=id ustatus teoj ]'
     ifhp 12:41:27.907 [31515] Start_of_job: 'pjl' and Zopts
     ifhp 12:41:27.907 [31515] Start_of_job: 'pjl' and Topts
     ifhp 12:41:27.907 [31515] Process_job: sending job file
     ifhp 12:41:27.907 [31515] Send_job: starting transfer
     ifhp 12:41:27.907 [31515] Send_job: initial job type 'POSTSCRIPT'
     ifhp 12:41:27.907 [31515] Send_job: match language 'ps'
     ifhp 12:41:27.907 [31515] Send_job: converter pgm '\%s{ps_converter}', final '<NULL>'
     ifhp 12:41:27.907 [31515] Send_job: language 'POSTSCRIPT', converter pgm '<NULL>'
     ifhp 12:41:27.907 [31515] Send_job: decoded job type 'POSTSCRIPT'
     ifhp 12:41:27.907 [31515] Send_job: job type 'POSTSCRIPT'
     ifhp 12:41:27.907 [31515] Init_job: doing ps init
     ifhp 12:41:27.907 [31515] Init_job: 'ps' and Topts
     ifhp 12:41:27.907 [31515] Init_job: 'ps' and Zopts
     ifhp 12:41:27.908 [31515] Send_job: doing file transfer
     ifhp 12:41:27.908 [31515] Send_job: transferring 145 bytes
     ifhp 12:41:27.908 [31515] Send_job: finished file transfer
     ifhp 12:41:27.908 [31515] Term_job: doing ps term
     ifhp 12:41:27.908 [31515] Process_job: sent job file
     ifhp 12:41:27.908 [31515] End_of_job: doing pjl at end
     ifhp 12:41:27.908 [31515] End_of_job: 'pjl_term'='[ ustatus teoj ]'
     ifhp 12:41:27.908 [31515] End_of_job: end sync and pagecount, do_pagecount 0,
            ps 0, pjl 0, prog '<NULL>'
     ifhp 12:41:27.908 [31515] End_of_job: clearing console at end
     ifhp 12:41:27.908 [31515] Do_accounting: pagecounter 0, pages 0
     ifhp 12:41:27.908 [31515] Accounting: script '<NULL>', Accountfile '<NULL>',
            output 'fileend '-b0' '-T0' '-q31515' '-p0' '-t2002-06-13-12:41:27.908''
     ifhp 12:41:27.908 [31515] Process_job: done

  Output: /tmp/out

    ^[%-12345X@PJL
    @PJL RESET
    @PJL JOB NAME = ":" DISPLAY = ":"
    @PJL RDYMSG DISPLAY = ":"
    @PJL INFO ID
    @PJL USTATUSOFF
    @PJL USTATUS JOB = ON
    @PJL USTATUS DEVICE = ON
    @PJL USTATUS PAGE = ON
    @PJL USTATUS TIMED = 10
    @PJL ENTER LANGUAGE = POSTSCRIPT
    ^D%!
    %!PS-Adobe-3.0
    %% one page (i.e. - a page with a 1 on it)
    %%/Times-Roman
    /Courier
    findfont 200 scalefont setfont
    72 300 moveto
    (1) show
    showpage
    ^D^[%-12345X@PJL
    @PJL RDYMSG DISPLAY = ":"
    @PJL EOJ NAME = ":"
    @PJL USTATUSOFF
    @PJL USTATUS JOB = ON
    @PJL USTATUS DEVICE = ON
    @PJL USTATUS PAGE = ON
    @PJL USTATUS TIMED = 10
    @PJL RDYMSG DISPLAY = "Done:  :"
    ^[%-12345X

2. Testing Options

   Set the 'options' value with the options to be set.  For example,
   lpr -Zduplex -> options=duplex as show below:

    ifhp=${libexecdir}/filters/ifhp
    out=/tmp/out
    file=${libexecdir}/filters/UTILS/one.ps
    debug=0
    options=duplex

    #> sh -x /tmp/sendhp.sh
        ifhp 12:54:44.428 [31566] main: using model ''
        ifhp 12:54:44.430 [31566] Process_job: setting up printer
        ifhp 12:54:44.431 [31566] Do_accounting: pagecounter 0
        ifhp 12:54:44.431 [31566] Process_job: sending job file
        ifhp 12:54:44.431 [31566] Send_job: starting transfer
        ifhp 12:54:44.431 [31566] Send_job: initial job type 'POSTSCRIPT'
        ifhp 12:54:44.431 [31566] Send_job: decoded job type 'POSTSCRIPT'
        ifhp 12:54:44.431 [31566] Send_job: job type 'POSTSCRIPT'
        ifhp 12:54:44.431 [31566] Send_job: transferring 145 bytes
        ifhp 12:54:44.431 [31566] Send_job: 100 percent done
        ifhp 12:54:44.431 [31566] Process_job: sent job file
        ifhp 12:54:44.431 [31566] Do_accounting: pagecounter 0, pages 0
        ifhp 12:54:44.432 [31566] Process_job: done

  Output /tmp/out:
        ^[%-12345X@PJL
        @PJL RESET
        @PJL JOB NAME = ":" DISPLAY = ":"
        @PJL RDYMSG DISPLAY = ":"
        @PJL INFO ID
        @PJL USTATUSOFF
        @PJL USTATUS JOB = ON
        @PJL USTATUS DEVICE = ON
        @PJL USTATUS PAGE = ON
        @PJL USTATUS TIMED = 10
        @PJL SET DUPLEX = ON                <<--- duplex PJL
        @PJL ENTER LANGUAGE = POSTSCRIPT
        ^D%!
        statusdict begin true setduplexmode false settumble end
                   ^^^ duplex PostScript
        %!PS-Adobe-3.0
        %% one page (i.e. - a page with a 1 on it)
        %%/Times-Roman
        /Courier
        findfont 200 scalefont setfont
        72 300 moveto
        (1) show
        showpage
        ^D^[%-12345X@PJL
        @PJL RDYMSG DISPLAY = ":"
        @PJL EOJ NAME = ":"
        @PJL USTATUSOFF
        @PJL USTATUS JOB = ON
        @PJL USTATUS DEVICE = ON
        @PJL USTATUS PAGE = ON
        @PJL USTATUS TIMED = 10
        @PJL RDYMSG DISPLAY = "Done:  :"
        ^[%-12345X

  OR for a postscript only printer:

    ifhp=${libexecdir}/filters/ifhp
    out=/tmp/out
    file=${libexecdir}/filters/UTILS/one.ps
      (OR file=${libexecdir}/filters/UTILS/one.pcl
       if your printer does not support PostScript)
    debug=0
	model=ps
    options=duplex

3. Testing IFHP output on a printer

   If your printer has support for a socket connection via
   port 9100 (or some other port), then you can use the
   netcat program:

	ftp://ftp.lprng.com/pub/LPRng/TOOLS/netcat/nc110.tgz
        (see also other files in /netcat directory)
	http://ftp.cerias.purdue.edu/pub/tools/unix/netutils/netcat/nc110.tgz
	ftp://coast.cs.purdue.edu/pub/tools/unix/netutils/netcat/nc110.tgz
	ftp://ftp.cuhk.edu.hk/pub/packages/security/purdue/netutils/netcat/nc110.tgz

   If your printer has IP address 10.0.0.14 and uses port 9100 for
   connections,  then try:
   
    ifhp=${libexecdir}/filters/ifhp
    out=/tmp/out
    file=${libexecdir}/filters/UTILS/one.ps
    debug=0

   #> sh /tmp/sendhp.sh
   ....
   #> nc 10.0.0.14 9100 < /tmp/out

   If your printer has bidirectional status reporting,
   and supports PJL, you should see something like:

    @PJL USTATUS JOB
    START
    NAME=":"
    
    @PJL USTATUS DEVICE
    CODE=10001
    DISPLAY=":"
    ONLINE=TRUE
    
    @PJL INFO ID
    "LASERJET 4 PLUS"
    
    @PJL USTATUS DEVICE
    CODE=10001
    DISPLAY="Done:  :"
    ONLINE=TRUE
    
    @PJL USTATUS TIMED
    CODE=10001
    DISPLAY="Done:  :"
    ONLINE=TRUE
    
    @PJL USTATUS PAGE
    1
    
    @PJL USTATUS JOB
    END
    NAME=":"
    PAGES=1
    
    @PJL USTATUS TIMED
    CODE=10001
    DISPLAY="Done:  :"
    ONLINE=TRUE

    (kill the nc program with ^C when you get tired of
     seeing the status)

   If you have a PostScript only printer, then try sending the
   following file to the printer:

    ^D%!PS-Adobe-2.0
    /p{print}def ( %%[ pagecount: ) p
    statusdict begin pagecount end 20 string cvs p
    ( ]%% ) p () = flush
	^D

    (Note: the ^D are CTRL-D or \004 characters)

   #> nc 10.0.0.14 9100 < /tmp/out
     %%[ pagecount: 107217 ]%%

    Note that this indicates that pagecounts work.  You might want
    to try:

	#>  printf "%%!\024" | nc 10.0.0.14 9100
	%%[ status: busy ]%%

    The ^T or \024 character is supposed to cause the printer to return
    status.

4. Connecting to a Printer and Getting Status

   If your printer is on the network and returns status, then you
   can try getting status with ifhp:

    ifhp=${libexecdir}/filters/ifhp
    out=h14%9100
    file=${libexecdir}/filters/UTILS/one.ps
    debug=0

    #> sh -x /tmp/sendhp.sh

       (Note: I removed paper tray to cause and Out Of Paper error)

	ifhp 13:00:25.258 [31594] main: using model ''
	ifhp 13:00:25.267 [31594] Check_pagecount: pagecount using 'pjl info pagecount'
	ifhp 13:00:25.267 [31594] Process_job: setting up printer
	ifhp 13:00:25.267 [31594] Do_sync: getting sync using 'pjl echo'
	ifhp 13:00:26.461 [31594] Check_device_status: id = '"LASERJET 4 PLUS"'
	ifhp 13:00:26.472 [31594] Do_sync: sync done
	ifhp 13:00:26.480 [31594] Do_pagecount: pagecounter 107213 after 1 attempts
	ifhp 13:00:26.481 [31594] Do_accounting: pagecounter 107213
	ifhp 13:00:26.481 [31594] Process_job: sending job file
	ifhp 13:00:26.481 [31594] Send_job: starting transfer
	ifhp 13:00:26.481 [31594] Send_job: initial job type 'POSTSCRIPT'
	ifhp 13:00:26.481 [31594] Send_job: decoded job type 'POSTSCRIPT'
	ifhp 13:00:26.481 [31594] Send_job: job type 'POSTSCRIPT'
	ifhp 13:00:26.481 [31594] Send_job: transferring 145 bytes
	ifhp 13:00:26.481 [31594] Send_job: 100 percent done
	ifhp 13:00:26.481 [31594] Process_job: sent job file
	ifhp 13:00:26.481 [31594] Do_waitend: getting end using 'pjl job/eoj'
	ifhp 13:00:30.340 [31594] Check_device_status: code = 10003, 'Warming Up'
	ifhp 13:01:24.338 [31594] Check_device_status: code = 11202,
           'PC/Upper/Tray2 - Letter Paper'
	ifhp 13:01:25.655 [31594] Check_device_status: code = 41202,
           'PC/Upper/Tray2 - Letter Paper', ALERT OPERATOR

         (Put paper tray back in. Note that there is no indication that
          error condition cleared)

	ifhp 13:01:32.078 [31594] Do_waitend: end of job detected
	ifhp 13:32:22.434 [31594] Do_pagecount: pagecounter 107214 after 1 attempts
	ifhp 13:32:22.434 [31594] Do_accounting: pagecounter 107214, pages 1
	ifhp 13:32:22.435 [31594] Process_job: done


