home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
bu1_os2.zip
/
U1_Hooks.INF
(
.txt
)
< prev
next >
Wrap
OS/2 Help File
|
1995-05-09
|
17KB
|
343 lines
ΓòÉΓòÉΓòÉ 1. Title Page ΓòÉΓòÉΓòÉ
ΓòÉΓòÉΓòÉ <hidden> Dummy ΓòÉΓòÉΓòÉ
U1 Rexx Hooks
Guide & Reference
Beta Version!
Dmitry Zavalishin
Artworks by Dmitry Zavalishin and Kira Stratonnikova
Moscow, 1995
ΓòÉΓòÉΓòÉ <hidden> Dummy ΓòÉΓòÉΓòÉ
ΓòÉΓòÉΓòÉ 2. What is REXX hook? ΓòÉΓòÉΓòÉ
There it a lot of things in a gate, that differrent people like to be done some
unusual way. Examples are address translation, data compression, accounting,
etc etc. Instead of adding to the U1 all of the possible ways of doing those
things and, thus, making it grow bigger, it's configs to become clumsier, I
decided to let users control the way gate works themselves by writing scripts
in REXX that will intercept some data, processed by gate and convert that data
the way user likes. The best example of such hook is UU2Fido uucp address
hook, which is called before gateing letter and given uucp address this letter
is addressed to. Hook script can convert that address to anything user seems
to be appropriate and then return new address for gate to use instead of the
original one. If no hook provided, address will be passed as is to U1 uucp to
fido address convertor.
ΓòÉΓòÉΓòÉ 3. How can I write my own REXX hook? ΓòÉΓòÉΓòÉ
Every OS/2 system has a simple book on REXX language. Please make sure you're
familiar enough with REXX before trying to use REXX hooks. Each hook is
described separately below, please read carefully about hook arguments, return
value and situation, in which that hook is called. REXX hook is a rexx program
file, which name is given in corresponding U1 setup file parameter. Most hooks
are started with arguments and all of them must return some value.
Hook parameters
The following line of REXX code will retrieve first argument of REXX
hook into the variable 'First_Arg':
Parse Arg First_Arg
Return values
The following line of REXX code will return result of script to the
caller and terminate execution of script:
/**
* Assume that variable 'result' contains the value we
* want to return.
**/
Return result
If no return value is needed for the hook you're writing, return 0
(zero) on success and -1 on failure.
/**
* We're failed, failed, failed :(
**/
Return -1
ΓòÉΓòÉΓòÉ 4. Additional REXX operators ΓòÉΓòÉΓòÉ
When writing U1 REXX hooks you can use additional operators, described below.
Please don't forget that additional operators are defined in "U1" environment
only, and if you change environment with 'ADDRESS' operator all of them will be
unavailable. To switch environment back use 'ADDRESS "U1"' command. See Rexx
reference book, keyword instruction 'ADDRESS' for further information on
environments.
ΓòÉΓòÉΓòÉ 4.1. Operator 'log': Writing debug info to U1 log file ΓòÉΓòÉΓòÉ
Purpose
Can be used to write debugging information to U1 log file.
Parameters
Text to be logged.
Notes
U1 setup parameter LogLevel must have 'x' character in it's value,
or debug mode must be turned on in oprder for log operator to be
effective.
Sample
/* Log value of variable 'input' */
log 'Rexx Hook is running. Parameter is: 'input
ΓòÉΓòÉΓòÉ 4.2. Operator 'warning': Displaying warning message ΓòÉΓòÉΓòÉ
Purpose
Can be used to warn user about unususal conditions.
Parameters
Text to be displayed and logged.
Notes
Text will be prepended with 'Warning: ' before displaying it.
Sample
/* Issue a warning message */
warning 'Address 'in_address' seems to be strange.'
ΓòÉΓòÉΓòÉ 4.3. Operator 'error': Displaying error message ΓòÉΓòÉΓòÉ
Purpose
Can be used to tell user about non-fatal error.
Parameters
Text to be displayed and logged.
Notes
Text will be prepended with 'Error: ' before displaying it.
Sample
/* Issue an error message */
error 'No username in address 'in_address'. Forwarding letter to postmaster.'
ΓòÉΓòÉΓòÉ 4.4. Operator 'fatal': Displaying fatal error message and halting ΓòÉΓòÉΓòÉ
Purpose
Can be used to tell user about fatal error.
Parameters
Text to be displayed and logged.
Notes
Text will be prepended with 'Fatal: ' before displaying it.
CAUTION:
Executing operator 'fatal' you'll stop currently running gate module
non-gracefully, possibly loosing some data (letters or articles).
Sample
/* Issue an error message and terminate gate */
fatal 'Out of disk space!'
ΓòÉΓòÉΓòÉ 5. Sample (NULL) script (Rexx.U2F.Address) ΓòÉΓòÉΓòÉ
/*********************************************************************/
/* address conversion hook for U1 UU2Fido.exe */
/* */
/* Input: uucp address of recepient */
/* */
/* Output: replacement address */
/* */
/*********************************************************************/
/* Here's we are loading variable 'inaddr' with value of the first argument */
Parse Arg inaddr
/* initialize output to default */
OutString = inaddr
/* Put debug info to log file */
log 'Rexx.U2F.Address: InAddr is 'inaddr
/* return string, removing any blanks on the front or back. */
Return Strip(OutString)
/* end */
ΓòÉΓòÉΓòÉ 6. Detailed hooks descriptions ΓòÉΓòÉΓòÉ
The hooks that are currently available are follow.
ΓòÉΓòÉΓòÉ 6.1. Rexx.U2F.Address: UU2Fido UUCP Address Hook ΓòÉΓòÉΓòÉ
Description
Example
ΓòÉΓòÉΓòÉ 6.1.1. Description of Rexx.U2F.Address ΓòÉΓòÉΓòÉ
Purpose
This hook can be used to preprocess (convert) uucp destination
address of the letter before passing it to uucp to fido address
translator of U1. Note that translating address to user@p#.f#.n#.z#
form you can avoid nearly all furher translation of the address by
gate.
Call reason
This hook is called for each destination address of letter passed to
UU2Fido.
Parameters
The only parameter is destination uucp address.
Return value
This hook must return new uucp address for message or its first
parameter if no replacement needed.
ΓòÉΓòÉΓòÉ 6.1.2. Sample script for Rexx.U2F.Address ΓòÉΓòÉΓòÉ
/**
* Address conversion hook for UU2Fido.exe. Does nothing.
*
* Input: uucp address of recepient
*
* Output: replacement address
*
**/
/* Load variable 'inaddr' with value of the first arg. */
Parse Arg inaddr
/* initialize output to default */
OutString = inaddr
/* Put debug info to log file */
log 'Rexx.U2F.Address: InAddr is 'inaddr
/* return string, removing blanks on the front or back. */
Return Strip(OutString)
ΓòÉΓòÉΓòÉ 6.2. Rexx.U2F.Pack: UU2Fido UUCP File Compression Hook ΓòÉΓòÉΓòÉ
Description
Example
ΓòÉΓòÉΓòÉ 6.2.1. Description of Rexx.U2F.Pack ΓòÉΓòÉΓòÉ
Purpose
This hook can be used to compress files, attached to the FIDO
letters by UU2Fido, with the archiving program you like.
Call reason
This hook is called when letter passed to UU2Fido is large enough to
be sent as an attached file instead of simple FIDO message.
Parameters
The first parameter is full name of the file to be compressed,
second one points to the directory where compressed file must be
created.
Return value
This hook must return name of resulting compressed file. If
compression failed, return name of the original file, and, please,
leave the file itself intact. If compression is succeded, it is your
responcibility to delete original file.
ΓòÉΓòÉΓòÉ 6.2.2. Sample script for Rexx.U2F.Pack ΓòÉΓòÉΓòÉ
/*****************************************************/
/* attachment packing hook for U1 UU2Fido.exe */
/* */
/* */
/* Input: unpacked file name (full) */
/* directory to put packed file to */
/* */
/* Output: packed file name (full) */
/* */
/*****************************************************/
/* get parameters */
Parse Arg unp_name, out_dir
/* make sure execution environment is U1's */
address "U1"
/* log parameters */
log "Rexx packer ("unp_name", "out_dir")"
/* initialize output to default */
OutString = unp_name
/* extract filename.extension part form the full name */
p=lastpos('\',unp_name)
if p = 0 then unp_file_ext=unp_name
else unp_file_ext=substr(unp_name,p+1)
p=lastpos('/',unp_file_ext)
if \ (p = 0) then unp_file_ext=substr(unp_file_ext,p+1)
debug "unp_file_ext: "unp_file_ext
/* cut extension off */
p=lastpos('.',unp_file_ext)
if p = 0 then unp_file=unp_file_ext
else unp_file=substr(unp_file_ext,1,p-1)
debug "unp_file: "unp_file
/* build name of compressed file */
p_name=out_dir||'\'||unp_file||'.zip'
debug "p_name: "p_name
say "Compressing with zip "unp_name
/* execute command */
Address "CMD" 'zip -oj '||p_name||' '||unp_name
if rc = 0 then
do
/* Success. Set return value to compressed file name... */
OutString=p_name
/* ...and delete uncompressed file */
call SysDeleteFile unp_name
end
else
Error "Unable to zip file, exit code = "||rc
/* return string, removing any blanks on the front or back. */
Return Strip(OutString)
ΓòÉΓòÉΓòÉ <hidden> ΓòÉΓòÉΓòÉ
To reach that book open the 'Information' folder on your desktop and
double-click 'Rexx Information' object in it.
ΓòÉΓòÉΓòÉ <hidden> ΓòÉΓòÉΓòÉ
usually with an extension of .Rexx