Lysters code is up to version 0.9 and is, as far as I have deterimined,
compatable in user operation as my 0.32 here.
Actually I believe this would be version 0.7 acording to Lysters
Numbering.
Code wise Lysters versions includes more in the way of information useful
to the programmer. He is working from a programmers perspective and
optimization of code speed. There is a distinct difference in look between
his code and mine.
Biggest difference is size (he includes more programmer information)
----------------8<--------------------------------------------------
/* IQ command SYNTAX: IQ.rexx TO FROM WORD SUBS... */
/* Copyright 1998 Timothy Rue - VIC IQ command: version 0.32-arexx (v0.7)*/
/* See Usenet archive dated on or about 11/08/98 for credit to */
/* Lyster E. Wick Jr. */
/* Uses rexxtricks.library (available on Aminet) for ADOS style pattern */
/* matching */
/* set linenumbers to 1 to show line numbers & IQ stacks. set to 0
otherwise */
linenumbers = 0
/* 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 i
SAY ""
EXIT 0
END
/* check for -k option and output top line if selected*/
tell = 0
key = UPPER(to_port)
IF key == '-K' | key == '-KEYS' THEN DO
tell = 1
SAY 'Listing Unique KEYS (first time found - filekeys and w/word and sub pattern matching):'
END
/* check port argument and if valid set output to port*/
IF ~ SHOW('p',to_port) THEN DO
IF tellnot == 0 & tell ~= 1 THEN SAY "WARNING: Cannot find port >" to_port "< - Default to STDOUT"
END
ELSE ADDRESS VALUE to_port
/* 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 i
IF position > 0 THEN BREAK /* break from select */
/* check if file exists */
IF ~ EXISTS(fromt) THEN DO
IF tellnot == 0 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 i
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 i
IQ_stack.iqsc = IQ_stackt
CALL CLOSE(iqfile)
CALL OPEN(iqfile, from,'R')
CALL 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 key 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
CALL CLOSE(iqfile)
IF tell == 1 & key.4 == 1 THEN DO
/*Check and build array of words, subs and files*/
inline = STRIP(inline)
DO t = 0 to tn -1
IF COMPARE(key_count.t, inline) ~= 0 THEN ITERATE t
ELSE LEAVE t
END t
IF t = tn THEN DO
key_count.t = inline
tn = tn + 1
End
END
CALL OPEN(iqfile, from,'R')
inline = READLN(iqfile)
ln = 1
key.4.level = 0
IF Abbrev(inline,key) THEN DO i = 1 to 3
key.i = WORD(inline,i+1)
END i
ELSE DO
i = -1
flipflop = 1
END
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 t = 1 to subn
subpattern = key.2 || WORD(subs,t)
IF RxTr_MATCHPATTERN(inline,subpattern) THEN DO
key.4.level = 2
key.4 = 1
BREAK
END
END t
/* 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 RxTr_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 /* end of select */
/***** begin multi-file test/IQ_stacks output.
Set 'linenumbers' ~= 0, to use */
IF linenumbers THEN DO
IF iqsc > 0 THEN DO
result = WORD(IQ_stack.1,1)'@Line#'WORD(IQ_stack.1,7)
DO t = 2 to iqsc
result = result WORD(IQ_stack.t,1)'@Line#'WORD(IQ_stack.t,7)
END t
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 t = 2 to iqsu
result = result IQ_stacku.t
END t
SAY 'IQ completely scanned file list> 'result
END
END
/***** end of multi-file test output */
/* Make list of unique Keys if -k option selected */
IF linetest ~= 0 & tell == 1 & key.4 == 1 & flipflop == 0 THEN DO
/*Check and build array of words, subs and files*/
inline = STRIP(inline)
DO t = 0 to tn -1
IF COMPARE(key_count.t, inline) ~= 0 THEN ITERATE t
ELSE LEAVE t
END t
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
CALL 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
CALL OPEN(iqfile,from,'R')
CALL SEEK(iqfile,cp,'BEGIN')
END
ELSE BREAK /* from do forever */
END /* loop end of Do Forever */
/* list unique keys if option -k selected */
IF tell = 1 THEN DO t = 0 to tn
SAY key_count.t
END t
EXIT 0
------------------------->8---------------------------------------------