Some time ago various memebers of the mailing list offered me ideas for
getting a REBOL program to print something.  I have come up with an idea
of my own, and am passing it back in case anyone is interested.  I have
pasted into this message a REBOL script followed by a Korn Shell script.
 Omitted is a COBOL program, but I suspect that that might be a bit of
overload.

In executive summary, the enclosed script is a function the "prints" a
string (which must be pre-formatted by the caller).  "Printing" means
attaching it to the end of a big string which is, in effect, the entire
"report" stored in memory as a string.  When the calling REBOL program
"closes" the print file (using a function provided), the procedure that
"closes" the print file actually sends it to our networked IBM RS6000. 
On the RS6000, a "cron" job runs every two minutes to see if any "print
files" have appeared, and if any have, the cron job assembles their
names and passes the names to a COBOL program, which prints each file.

The attached REBOL code is not very "rebol-ish" but at my level of
skill I need the excessive comments and the capitalized words to keep
track of what I am doing.

Thank you.  In the few times I have posted questions to the REBOL
mailing list I have found it to be extremely helpful, and FAST.  (and
friendly too)

*_*_*_ REBOL script *_*_*_

REBOL [
    Title: "In-house unix printing module"
]

;;  [----------------------------------------------------------------]
;;  [ This is a module that you may "do" and that will define        ]
;;  [ functions you may use for printing.  Here is a general idea    ]
;;  [ of how it works:                                               ]
;;  [                                                                ]
;;  [ When you "print" a line, the function adds it to the end of    ]
;;  [ previous lines you have "printed."  When you are done printing ]
;;  [ and "close" the "print file," the lines you have "printed"     ]
;;  [ are written to a text file...AND...sent by ftp over to the     ]
;;  [ RS6000 into a dedicated directory of "print files."            ]
;;  [ At intervals, a cron job on the RS6000 detects new files in    ]
;;  [ the special directory and writes them to physical printers.    ]
;;  [                                                                ]
;;  [ The following specific operating instructions, besides telling ]
;;  [ you how to use the module, will clarify exactly what happens   ]
;;  [ when you use this module.                                      ]
;;  [                                                                ]
;;  [ Before you print your first line, you must set values into     ]
;;  [ sevaral interface items.  These interface items define things  ]
;;  [ like the printer you want to use, the name of the report,      ]
;;  [ the headings, and so on.  Refer to the code below for the      ]
;;  [ exact list.  You do this just once, at the beginning of your   ]
;;  [ program, before you do any printing.                           ]
;;  [                                                                ]
;;  [ Optionally, you may perform the procedure PRINT-OPEN.          ]
;;  [ If you do not, the procedure will be performed for you         ]
;;  [ the first time you try to print.  This procedure will          ]
;;  [ initialize a big string and write to the front of the          ]
;;  [ string the values of the interface items you set, in the       ]
;;  [ following format:                                              ]
;;  [     $<interface-item> = <interface-value>                      ]
;;  [ These items will be written in lines, one value per line,      ]
;;  [ with a dollar sign in column one.  These values will be        ]
;;  [ scanned by a program on the RS6000 and used to set values      ]
;;  [ in the standard module (PRINT2) that we use for printing in    ]
;;  [ COBOL programs on that computer.                               ]
;;  [                                                                ]

;;  [ When you want to print, you must format a string that is       ]
;;  [ exactly what you want printed.  This module has no facilities  ]
;;  [ for helping you with that.  Then, when the string is           ]
;;  [ formatted, set its value into the word PRINT-LINE.             ]
;;  [                                                                ]
;;  [ After you have set PRINT-LINE with a value, perform one of     ]
;;  [ the following procedures:                                      ]
;;  [     PRINT-BEFORE-1                                             ]
;;  [     PRINT-BEFORE-2                                             ]
;;  [ These procedures perform PRINT-OPEN if it has not been         ]
;;  [ performed, then add PRINT-LINE to the end of the big string    ]
;;  [ that was created by PRINT-OPEN.  PRINT-LINE is appended to     ]
;;  [ the string AFTER it has a "1" or "2" attached to the front     ]
;;  [ in column one.  The "1" or "2" stands for, naturally, printing ]
;;  [ before advancing 1 or 2 lines.                                 ]
;;  [                                                                ]
;;  [ When you are done printing, you MUST explicitely perform       ]
;;  [ PRINT-CLOSE to transmit the string of print lines over to      ]
;;  [ the RS6000.  From there, it will be detected and printed       ]
;;  [ automatically.  The PRINT-CLOSE procedure also sends to the    ]
;;  [ RS6000 a one-record "command" file the presence of which       ]
;;  [ will start the printing process.                               ]
;;  [                                                                ]
;;  [ For more information about what happens on the RS6000 end,     ]
;;  [ refer to /u01/scripts/commandchecker and                       ]
;;  [ SRC/DAT/COMMANDPROCESSOR.                                      ]
;;  [ The commandchecker script checks for command files every       ]
;;  [ two minutes.  If if finds some, it gathers all their names     ]
;;  [ into a text file with a known name and runs the                ]
;;  [ COMMANDPROCESSOR program to execute the commands.              ]
;;  [----------------------------------------------------------------]

;;  [----------------------------------------------------------------]
;;  [ These are the interface items the caller must set before       ]
;;  [ doing any printing.                                            ]
;;  [                                                                ]
;;  [ PURGE-AFTER-PRINTING  A YES/NO indicator to control purging    ]
;;  [                       of the file after printing--currently    ]
;;  [                       ignored                                  ]
;;  [ WS-FILENAME           The name of the printer to use, as       ]
;;  [                       defined in our list of available         ]
;;  [                       printers in /ect/cblconfig               ]
;;  [ WS-REPORT-ID          The name of the report, printed at the   ]
;;  [                       start of the second line of standard     ]
;;  [                       heading                                  ]
;;  [ WS-PROGRAM            The name of the creating program,        ]
;;  [                       printed at the start of the first line   ]
;;  [                       of standard heading                      ]
;;  [ WS-SUBTITLE           The string printed on the second heading ]
;;  [                       line below "C I T Y    O F    B L ...etc ] 
   
;;  [ WS-REPTNAME           The name of the report, printed at the   ]
;;  [                       start of the third line of standard      ]
;;  [                       heading                                  ]
;;  [ WS-HEADING-LINE-COUNT Number of heading lines (1-3) that       ]
;;  [                       should be printed on each page           ]
;;  [ WS-USER-HEADING-1     The first heading line                   ]
;;  [ WS-USER-HEADING-2     The second heading line                  ]
;;  [ WS-USER-HEADING-3     The third heading line                   ]
;;  [ WS-PRE-HEADING-1      The first line of "pre-heading" that     ]
;;  [                       will be printed (if present) after the   ]
;;  [                       top three lines of standard heading      ]
;;  [                       lines and before the (up to) three lines ]
;;  [                       of user heading                          ]
;;  [ WS-PRE-HEADING-2      The second line or pre-heading           ]
;;  [ WS-PRE-HEADING-3      The third line of pre-heading            ]
;;  [----------------------------------------------------------------]

PURGE-AFTER-PRINTING: "YES"
PRINT-WS-FILENAME: "LASERJET5"
PRINT-WS-REPORT-ID: ""
PRINT-WS-PROGRAM: ""
PRINT-WS-SUBTITLE: ""
PRINT-WS-REPTNAME: ""
PRINT-WS-HEADING-LINE-COUNT: 0
PRINT-WS-USER-HEADING-1: ""
PRINT-WS-USER-HEADING-2: ""
PRINT-WS-USER-HEADING-3: ""
PRINT-WS-PRE-HEADING-1: ""
PRINT-WS-PRE-HEADING-2: ""
PRINT-WS-PRE-HEADING-3: ""

;;  [----------------------------------------------------------------]
;;  [ These are the interface areas the caller must/may set before   ]
;;  [ calling the printing procedures PRINT-BEFORE-1 and             ]
;;  [ PRINT-BEFORE-2.                                                ]
;;  [                                                                ]
;;  [ PRINT-LINE    This is the exact string of characters, up to    ]
;;  [               220 (the maximum supported by the PRINT2 module  ]
;;  [               on the RS6000), that you want to have printed.   ]
;;  [               This string will be cleared to an empty string   ]
;;  [               after printing.                                  ]
;;  [----------------------------------------------------------------]

PRINT-LINE: ""

;;  [----------------------------------------------------------------]
;;  [ This are internal working items the caller should leave alone. ]
;;  [                                                                ]
;;  [ INITIALIZED        A flag set by PRINT-OPEN so PRINT-OPEN does ]
;;  [                    get performed twice.                        ]
;;  [ FILE-IN-MEMORY     This is the monster string that contains    ]
;;  [                    the whole "print file" in memory.  Print    ]
;;  [                    lines                                       ]
;;  [                    are added to the end of it, and then the    ]
;;  [                    whole thing is written to disk by           ]
;;  [                    PRINT-CLOSE.                                ]
;;  [ COMMAND-DIRECTORY  The directory on the RS6000 to which we     ]
;;  [                    write a one-line text file containing a     ]
;;  [                    command to start printing                   ]
;;  [ DATA-DIRECTORY     The directory on the RS6000 to which we     ]
;;  [                    write the file of print lines               ]
;;  [ FTP-COMPUTER       The network IP address of the RS6000        ]
;;  [ FTP-USERID         The user ID we need to log on to the RS6000 ]
;;  [                    for the file transfer                       ]
;;  [ FTP-PASSWORD       The password for the above user ID          ]
;;  [ GENERATED-ID       The last node of the file name that will    ]
;;  [                    identify both the command file and the      ]
;;  [                    data file of print lines.  We will make it  ]
;;  [                    from the date and time, so if several       ]
;;  [                    programs are "printing" there will be no    ]
;;  [                    name conflicts.                             ]
;;  [ COMMAND-WORD       This is the keyword that goes into the      ]
;;  [                    one-record command file that causes         ]
;;  [                    printing to start on the RS6000.            ]
;;  [                    This command is executed by the program     ]
;;  [                    called COMMANDPROCESSOR on the RS6000.      ]
;;  [ COMMAND-LINE       This is a area for building the one-record  ]
;;  [                    command line that we send to the RS6000 to  ]
;;  [                    start printing                              ] 

;;  [ COMMAND-URL        This is the full FTP url that we need to    ]
;;  [                    transfer the command file                   ]
;;  [ DATA-URL           This is the full FTP url that we need to    ]
;;  [                    transfer the data file                      ]
;;  [ TIME-PARTS         This is a block that will hold the parts    ]
;;  [                    of the current time so we can string them   ]
;;  [                    together for a file name                    ] 

;;  [----------------------------------------------------------------]

PRINT-INITIALIZED: false
PRINT-FILE-IN-MEMORY: ""
PRINT-COMMAND-DIRECTORY: "/u01/DAT/DAT/COMMANDQUEUE"
PRINT-DATA-DIRECTORY: "/u01/DAT/DAT/REBOLPRINTFILES"
PRINT-FTP-COMPUTER: "10.1.0.1"
PRINT-FTP-USERID: "x"
PRINT-FTP-PASSWORD: "y"
PRINT-GENERATED-ID: ""
PRINT-COMMAND-WORD: "REBOLPRINT"
PRINT-COMMAND-LINE: ""
PRINT-COMMAND-URL: none
PRINT-DATA-URL: none
PRINT-TIME-PARTS: []

;;  [----------------------------------------------------------------]
;;  [ This procedure "opens" the print file by clearing out the      ]
;;  [ big string that holds it and placing into the string a bunch   ]
;;  [ of lines that contain the interface data items that will be    ]
;;  [ used by the program on the RS6000.  The program on the RS6000  ]
;;  [ will scan the interface items and use them to load the PRINT2  ]
;;  [ module for standard printing.                                  ]
;;  [----------------------------------------------------------------]

PRINT-OPEN: does [
    PRINT-INITIALIZED: true
    PRINT-FILE-IN-MEMORY: copy ""
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PURGE-AFTER-PRINTING = " 
            "^"" 
            PURGE-AFTER-PRINTING  
            "^"" 
            newline 
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-FILENAME = " 
            "^"" 
            PRINT-WS-FILENAME 
            "^""  
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-REPORT-ID = " 
            "^"" 
            PRINT-WS-REPORT-ID  
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-PROGRAM = " 
            "^"" 
            PRINT-WS-PROGRAM 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-SUBTITLE = " 
            "^"" 
            PRINT-WS-SUBTITLE 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-REPTNAME = " 
            "^"" 
            PRINT-WS-REPTNAME 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-HEADING-LINE-COUNT = " 
            PRINT-WS-HEADING-LINE-COUNT 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-USER-HEADING-1 = " 
            "^"" 
            PRINT-WS-USER-HEADING-1 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-USER-HEADING-2 = " 
            "^"" 
            PRINT-WS-USER-HEADING-2 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-USER-HEADING-3 = "  
            "^"" 
            PRINT-WS-USER-HEADING-3 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-PRE-HEADING-1 = " 
            "^"" 
            PRINT-WS-PRE-HEADING-1 
            "^"" newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-PRE-HEADING-2 = " 
            "^"" 
            PRINT-WS-PRE-HEADING-2 
            "^"" 
            newline
        ]
    append PRINT-FILE-IN-MEMORY 
        rejoin ["$PRINT-WS-PRE-HEADING-3 = " 
            "^"" 
            PRINT-WS-PRE-HEADING-3 
            "^"" 
            newline
        ]
]

;;  [----------------------------------------------------------------]
;;  [ This procedure "closes" the print file.  It writes it into     ]
;;  [ a text file on the RS6000 where it will be detected and        ]
;;  [ printed.                                                       ]
;;  [                                                                ]
;;  [ A second thing that this procedure must do to make the         ]
;;  [ printing work is put a "command file" into a special           ]
;;  [ directory on the RS6000.  The printing over there actually     ]
;;  [ is handled by a command processor that does some other         ]
;;  [ things besides REBOL printing.                                 ]
;;  [----------------------------------------------------------------]

PRINT-CLOSE: does [
    TIME-PARTS: copy []
    TIME-PARTS: parse to-string now/time ":"
    PRINT-GENERATED-ID: copy ""
    PRINT-GENERATED-ID: rejoin [ 
        "PRN-"
        to-string now/year
        to-string now/month
        to-string now/day
        TIME-PARTS/1
        TIME-PARTS/2
        TIME-PARTS/3
    ]
    PRINT-COMMAND-LINE: copy ""
    PRINT-COMMAND-LINE: rejoin [
        PRINT-COMMAND-WORD
        " " 
        PRINT-GENERATED-ID
    ]
    PRINT-COMMAND-URL: none
    PRINT-COMMAND-URL: to-url rejoin [
        "ftp://";
        PRINT-FTP-USERID
        ":"
        PRINT-FTP-PASSWORD
        "@"
        PRINT-FTP-COMPUTER
        "/"
        PRINT-COMMAND-DIRECTORY
        "/"
        PRINT-GENERATED-ID
        ".CMD"
    ] 
    PRINT-DATA-URL: none
    PRINT-DATA-URL: to-url rejoin [
        "ftp://";
        PRINT-FTP-USERID
        ":"
        PRINT-FTP-PASSWORD
        "@"
        PRINT-FTP-COMPUTER
        "/"
        PRINT-DATA-DIRECTORY
        "/"
        PRINT-GENERATED-ID
    ] 
    write PRINT-DATA-URL PRINT-FILE-IN-MEMORY
    write PRINT-COMMAND-URL PRINT-COMMAND-LINE
]

;;  [----------------------------------------------------------------]
;;  [ This procedure "prints" a line with single spacing.            ]
;;  [ It sticks a "1" on the front of PRINT-LINE and appends it to   ]
;;  [ the end of PRINT-FILE-IN-MEMORY.                               ]
;;  [----------------------------------------------------------------]
 
PRINT-BEFORE-1: does [
    if not PRINT-INITIALIZED [
        PRINT-OPEN
    ]
    append PRINT-FILE-IN-MEMORY rejoin [
        "1" 
        PRINT-LINE
        newline
    ]
    PRINT-LINE: copy ""
]

;;  [----------------------------------------------------------------]
;;  [ This procedure "prints" with double spacing.                   ]
;;  [----------------------------------------------------------------]

PRINT-BEFORE-2: does [
    if not PRINT-INITIALIZED [
        PRINT-OPEN
    ]
    append PRINT-FILE-IN-MEMORY rejoin [
        "2" 
        PRINT-LINE
        newline
    ]
    PRINT-LINE: copy ""
]

;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;;

*_*_*_ end of REBOL script *_*_*_

*_*_*_ Korn Shell script that detects "command" files that cause
printing to start *_*_*_

######################################################################
#
# commandchecker:
#
# This is a cron job that runs at intervals and checks to see
# if there are any files in a directory of command files.
# (A command file is a one-record text file with some command
# in it--a command of our own invention.)
# If there are any files in this directory, the script writes
# them to a text file and runs our in-house COMMANDPROCESSOR
# program to read and analyze those command files.
#
#---------------------------------------------------------------------
#
. /etc/setprodpath

DIR=${INHOUSE_SYSTEM_DIR}/DAT/DAT/COMMANDQUEUE
log=${DIR}/executionlog

## echo >>$log "$(date +%D-%H:%S:%M) BOJ commandchecker"

cd ${DIR}
ls -1 *.CMD >${DIR}/COMMANDLIST 2>>/dev/null
cd ${INHOUSE_SYSTEM_DIR}

if [[ -s ${DIR}/COMMANDLIST ]]
then
##  echo >>$log "Running COMMANDPROCESSOR"
    ${ACUCOBOL_LOC}/runcbl +e $log
${INHOUSE_SYSTEM_DIR}/OBJ/DAT/COMMANDPROCESSOR
else
##  echo >>$log "No command files found"
    rm ${DIR}/COMMANDLIST >>$log 2>>$log
fi

## echo >>$log "$(date +%D-%H:%S:%M) EOJ commandchecker"

######################################################################

*_*_*_ end of Korn Shell script *_*_*_




Steven White
City of Bloomington
1800 W Old Shakopee Rd
Bloomington MN 55431-3096
USA
952-563-4882 (voice)
952-563-4672 (fax)
[EMAIL PROTECTED]
-- 
To unsubscribe from the list, just send an email to 
lists at rebol.com with unsubscribe as the subject.

Reply via email to