To use this Arexx program, simply save this html file (as an html) and cut at cut lines
--------cut IQ03.rexx beginning -----
/* VIC IQ command - www.mindspring.com/~timrue/ -- timrue@mindspring.com */
/* Copyright 1998 Timothy Rue - VIC IQ command: version 0.3-arexx */
/* Uses rexxtricks.library (available on Aminet) for ADOS style pattern */
/* matching */
/* check for and addlib rexxtricks.library */
IF ~ SHOW('L',"rexxtricks.library") THEN
IF ~ ADDLIB("rexxtricks.library",0,-30,0) THEN DO
SAY 'rexxtricks.library not available, exiting'
EXIT 10
END
/* parse command line arguements */
PARSE ARG to_port from word subs subl
/* help options */
IF to_port == '' | to_port == ? | to_port == '-?' | to_port == '-h' | to_port == 'help' THEN DO
SAY "FOR HELP:"
SAY "rx IQ.rexx -OR- rx IQ.rexx [ ? | -? | -h | help ]"
SAY ""
SAY "COMMAND LINE:"
SAY "rx IQ.rexx [word|pattern] {sub|pattern}"
SAY ""
SAY "OPTIONAL REDIRECTION COMMAND LINE (may be used with any '-' option):"
SAY "rx IQ.rexx [>dev:path/filename | pipe:name] [word|pattern] {sub|pattern}"
SAY ""
SAY "TO SILENCE WARNINGS:"
SAY "rx IQ.rexx < -s | -S > [word|pattern] {sub|pattern}"
SAY ""
SAY "FOR UNIQUE KEYS LIST (filekeys and w/word and sub pattern matching):"
SAY "rx IQ.rexx < -k | -K | -Keys | -KEYS > [word|pattern] {sub|pattern}"
SAY ""
SAY "FOR AVAILABLE PORTS LIST:"
SAY "rx IQ.rexx [ -p | -P | -Ports | -PORTS ]"
SAY ""
EXIT 0
END
tellnot = 0
IF UPPER(to_port) == '-S' THEN DO
tellnot = 1
to_port = from
from = word
word = subs
subs = subl
END
ELSE subs = subs subl
/* show ports available */
IF UPPER(to_port) == '-P' | UPPER(to_port) == '-PORTS' THEN DO
SAY 'Ports Available:'
SAY '----------------'
ports = SHOW('P')
tn = WORDS(ports)
DO i = 1 TO tn
SAY WORD(ports,i)
END
SAY ""
EXIT 0
END
tell = 0
key = UPPER(to_port)
IF key == '-K' | key == '-KEYS' THEN tell = 1
/* check port argument and if valid set output to port*/
IF ~ SHOW('p',to_port) THEN DO
IF tellnot ~= 1 THEN SAY "WARNING: Cannot find port >" to_port "< - Default to STDOUT"
END
ELSE ADDRESS VALUE to_port
IF tell = 1 THEN SAY 'Listing Unique KEYS (first time found - filekeys and w/word and sub pattern matching):'
/* Sets compound variable by reading the first line of IQ file
and checks for the first word to = contents of the 'key' variable */
key = 'filekey'
key.1 = 'word:'
key.2 = 'sub:'
key.3 = 'file:'
key.4 = 1
iqsu = 0
iqsc = 0
tn = 1
/* test for valid file arguement */
IF ~ OPEN(iqfile,from,'R') THEN DO
SAY 'ERROR: IQ file> 'from' 0 THEN DO i = 1 to iqsu
IF IQ_stacku.i == fromt THEN position = i
END
IF position > 0 THEN BREAK /* break from select */
/* check if file exists */
IF ~ EXISTS(fromt) THEN DO
IF tellnot ~= 1 THEN SAY 'WARNING: IQ file> 'fromt' 'from'< @Line#'ln
position = -1
END
IF position == -1 THEN BREAK /* break from select */
/* check if in current stack - if so save current settings,
read in previous settings, sort stack, seek to cp */
IF iqsc > 0 THEN DO i = 1 to iqsc
IF WORD(IQ_stack.i,1) == fromt THEN position = i
END
IF position > 0 THEN DO
cp = SEEK(iqfile,0)
IQ_stackt = from key.1 key.2 key.3 key.4 key.4.level ln cp
PARSE VAR IQ_stack.position from key.1 key.2 key.3 key.4 key.4.level ln cp
Do i = position to iqsc
j = i + 1
IQ_stack.i = IQ_stack.j
END
IQ_stack.iqsc = IQ_stackt
CLOSE(iqfile)
OPEN(iqfile, from,'R')
SEEK(iqfile,cp,'BEGIN')
position = -1
END
IF position == -1 THEN BREAK /* break from select */
/* if not in either stack - save current settings and
read in key of new file if exist */
IF position == 0 THEN DO
cp = SEEK(iqfile,0)
iqsc = iqsc + 1
IQ_stack.iqsc = from key.1 key.2 key.3 key.4 key.4.level ln cp
from = fromt
CLOSE(iqfile)
OPEN(iqfile, from,'R')
inline = READLN(iqfile)
ln = 1
key.4.level = 0
IF MATCHPATTERN(inline,key || #?) THEN DO i = 1 to 3
key.i = WORD(inline,i+1)
END
ELSE i = -1
END
END
/* when sub from sub or word level*/
WHEN key.2.result & key.4.level > 0 THEN DO
key.4 = 0
key.4.level = 1
/* test arg sub match (within matching word)*/
DO sn = 1 to subn
subpattern = key.2 || WORD(subs,sn)
IF MATCHPATTERN(inline,subpattern) THEN DO
key.4.level = 2
key.4 = 1
BREAK
END
END
/* if w/blank sub */
IF inline == key.2 & key.4.level == 1 THEN key.4 = 1
END
/* when word */
WHEN key.1.result THEN DO
key.4 = 0
key.4.level = 0
/* if arg word match */
IF MATCHPATTERN(inline,key.1 || word) THEN DO
key.4.level = 1
key.4 = 1
END
/* if exiting word w/blank word */
IF inline == key.1 THEN key.4 = 1
END
WHEN tell = 1 THEN NOP
/* ??? can this ever happen ??? */
OTHERWISE say 'Error in IQ file at linenumber> 'ln
END
/* **** begin multi-file test/IQ_stacks output. UNCOMMENT to use */
/*
IF iqsc > 0 THEN DO
result = WORD(IQ_stack.1,1)'@Line#'WORD(IQ_stack.1,7)
DO test = 2 to iqsc
result = result WORD(IQ_stack.test,1)'@Line#'WORD(IQ_stack.test,7)
END
SAY 'IQ Stack>'result from'@Line#'ln /* This is the PK files IQ stack*/
END
ELSE SAY 'IQ Stack>'from'@Line#'ln /* This is the PK files IQ stack*/
IF iqsu > 0 THEN DO
result = IQ_stacku.1
DO test = 2 to iqsu
result = result IQ_stacku.test
END
SAY 'IQ completely scanned file list> 'result
END
*/
/* **** end of multi-file test output */
IF linetest ~= 0 & tell == 1 & key.4 = 1 THEN DO
/*Check and build array of words, subs and files*/
STRIP(inline)
DO t = 0 to tn -1
IF COMPARE(key_count.t, inline) ~= 0 THEN ITERATE t
ELSE LEAVE
END
IF t = tn then DO
key_count.t = inline
tn = tn + 1
End
END
/* handle EOF and IQ stacks*/
IF EOF(iqfile) THEN
IF iqsc > 0 THEN DO
CLOSE(iqfile)
iqsu = iqsu + 1
IQ_stacku.iqsu = from
PARSE VAR IQ_stack.iqsc from key.1 key.2 key.3 key.4 key.4.level ln cp
iqsc = iqsc -1
OPEN(iqfile,from,'R')
SEEK(iqfile,cp,'BEGIN')
END
ELSE BREAK /* from do forever */
END
IF tell = 1 THEN DO t = 0 to tn
SAY key_count.t
END
--- cut line end ---