home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Spezial
/
SPEZIAL2_97.zip
/
SPEZIAL2_97.iso
/
ANWEND
/
ONLINE
/
SREFV12J
/
ALIASCHK.RXX
< prev
next >
Wrap
Text File
|
1997-06-30
|
10KB
|
388 lines
/* Check aliases module for SRE-FILTER. Uses contents of aliasfile
To call: set queue/sempahore with:
newqueue,newsem,OLDURL
Returns
match , newurl
If match=0. then no match (and newurl=oldurl)
*/
parse upper arg aliasfile, usequeue , USESEM, max_semwait
call pmprintf_sref(' SRE-FILTER alias thread: aliasfile='||aliasfile)
call pmprintf_sref(' SRE-FILTER alias thread: queue='||usequeue)
call pmprintf_sref(' SRE-FILTER alias thread: semaphore='||usesem)
mytid=dostid()
call pmprintf_sref(' SRE-FILTER alias thread: thread id='||mytid)
resetit:
if usequeue="" | USESEM="" then do
call pmprintf_sref('SRE-FILTER alias thread: initialization ERROR: '||usequeue)
exit
end
call set_alias(aliasfile)
if naliases=0 then do
call pmprintf_sref(' SRE-FILTER alias thread: Warning: No valid entries in alias file:'||aliasfile)
end
else do
call pmprintf_sref(' SRE-FILTER alias thread: #aliases= '||naliases)
end
/* Initialization now done == start waiting for requests for alias info */
signal on error name iserror
signal on syntax name iserror
bakme:
a=rxqueue('s',usequeue)
aq=queued()
if aq=0 then do
WOW=EVENTSEM_WAIT(USESEM,max_semwait)
aq=-1
if wow=640 then do
signal bakme
end
IF WOW<>0 THEN do /* FATAL ERROR */
call pmprintf_sref(' SRE-FILTER alias thread: fatal semaphore error ')
exit
end
end
wow=EVENTSEM_RESET(usesem)
if aq=-1 then
if queued()=0 then signal bakme
PARSE pull isit0
isit0=translate(isit0,' ','000d0a09'x)
if isit0="" then signal bakme
/* die command? */
if abbrev(isit0,'*DIE*')=1 then
exit
parse var isit0 idnum ',' newq ',' newsem ',' ISIT
parse var idnum idnum host_nickname
isitorig=isit
if newq="" | newsem="" then do
call pmprintf_sref(' SRE-FILTER alias thread: missing queue or semaphore ')
signal bakme
end
newq=upper(strip(newq)); newsem=upper(strip(newsem))
ISIT=STRIP(ISIT)
if abbrev(isit,'*RESET*') then do
parse var isit foo newfile .
if newfile<>' ' then aliasfile=newfile
call set_alias(aliasfile)
call pmprintf_sref(' SRE-Filter alias thread: Reread aliases file: 'aliasfile)
end
else do
if naliases=0 then do
dog1=' 0 '||isitorig
end
else do
if pos('?',isit)>0 then do
parse var isit a1 '?' a2
isit=translate(a1,'/','\')
isit=strip(isit,'l','/')||'?'||a2
end
dog1=fig_alias(isit,host_nickname)
end
a=rxqueue('s',newq)
push idnum ',' dog1
wow=eventsem_post(newsem)
end
signal bakme
iserror:
signal off error ; signal off syntax
call pmprintf_sref(' SRE-FIlter: error in alias thread 'sigl)
a=rxqueue('d',usequeue)
a=rxqueue('c',usequeue)
a=eventsem_close(usesem)
a=eventsem_create(usesem)
a=rxqueue('s',newq)
push idnum ', 0 '
wow=eventsem_post(newsem)
call pmprintf_sref('SRE-FIlter: done resetting alias thread ')
signal on error name iserror
signal on syntax name iserror
signal bakme
exit
/* ---------- */
fig_alias:procedure expose aliases. aliashosts.
parse arg inline , host_nickname,isit0
host_nickname=strip(upper(host_nickname))
sel=translate(inline,' ','000d0a09'x)
doexact=0
gotit=0 ; resu=' ';tsel=upper(sel)
do m=1 to aliases.0
if host_nickname<>aliashosts.m & aliashosts.m<>' ' then iterate
jlias=aliases.m
parse var jlias jlias1 .
aresu=wild_match(tsel,jlias1)
if aresu=0 then iterate /* no match */
if aresu=-1 then do /* exact match */
resu=-1
gotit=m
leave
end
if resu=' ' then do /* FIRST WILDCARD MATCH */
resu=aresu
GOTIT=M
iterate
end
/* DETERMINE WHICH IS BEST WILDCARD MATCH */
wrds2=words(ARESU);wrds1=words(RESU)
use1=1
do Nmm=1 to max(wrds1,wrds2)
if Nmm>wrds2 then leave
if Nmm>wrds1 then do
use1=0; leave
end
a1=strip(word(resu,Nmm))
a2=strip(word(aresu,Nmm))
if a1=a2 then iterate
if a2>a1 then leave
use1=0
leave
end
IF USE1=0 THEN DO
GOTIT=M
RESU=ARESU
END
end
select
when gotit=0 then usesel=inline /* no match, use original */
when resu=-1 then do /* exact match, use candidate as is */
parse var aliases.gotit . usesel
end
otherwise do /* wildcard match */
parse var aliases.gotit . jlias1 ; jlias1=strip(jlias1)
if pos('*',jlias1)=0 then do /* no wildcards in candidate */
usesel=jlias1
end
else do /* fill in * appropriately */
psel=sel
do il=1 to words(resu)
psel=overlay(' ',psel,strip(word(resu,il)))
end
arf='';idog=0 ; jlias2=jlias1
do until jlias2=""
parse var jlias2 a1 '*' jlias2
arf=arf||a1
if jlias2<>' ' then do
idog=idog+1
if idog<=words(psel) then arf=arf||strip(word(psel,idog))
end
else do
if right(jlias1,1)='*' then do
idog=idog+1
if idog<=words(psel) then arf=arf||strip(word(psel,idog))
end
leave
end /* parse on * */
end /* scanning jlias2 */
usesel=space(arf,0)
end /* fill in wildcards */
end /* otherwise */
end /*select */
/* fix up / */
parse var usesel k1 '?' k2
k1=translate(k1,'/','\')
if pos('?',usesel)>0 then
usesel=k1||'?'||k2
else
usesel=k1
return gotit ' ' usesel
/* ---------------- */
/* read and set up aliases */
set_alias:
parse arg afile
naliases=0
aliases.0=0
a=sref_fileread(afile,'ulines',,'E') /* read it to a stem variable */
foo=do_extends(1)
oo=stream(afile,'c','close')
if a=0 then do
call pmprintf_sref(' SRE-FILTER alias thread: ERROR reading user-file: '||afile)
return
end
exton=0
do mm=1 to ulines.0
t1=strip(ulines.mm)
if exton=1 then do
t1=t1storage||t1
end
exton=0
if t1="" then iterate
if abbrev(t1,';')=1 then iterate
if right(t1,2)=' ,' & mm < ulines.0 then do
exton=1
t1=left(t1,length(t1)-2)
t1storage=strip(t1)
iterate
end
tm1=strip(word(t1,1)) ; ahost=' '
if right(tm1,2)='//' then do
ahost=upper(left(tm1,length(tm1)-2))
parse var t1 foo t1a t1b
end
else
parse var t1 t1a t1b
if pos('?',t1a)>0 then do
parse var t1a q1 '?' q2
t1a=strip(translate(q1,'/','\'),'l','/')||'?'||q2
end
else do
t1a=strip(translate(t1a,'/','\'),'l','/')
end
if pos('?',t1b)>0 then do
parse var t1b q1 '?' q2
t1b=strip(translate(q1,'/','\'),'l','/')||'?'||q2
end
else do
t1b=strip(translate(t1b,'/','\'),'l','/')
end
naliases=naliases+1
aliases.naliases=upper(t1a)||' '||t1b
aliashosts.naliases=ahost
end
aliases.0=naliases
return 0
/************/
/* Redo ulines, by treating lines starting with , as continuation lines */
do_extends:procedure expose ulines.
if ulines.0=0 then return
isnew=1
tmps.1=ulines.1
do mm=2 to ulines.0
ali=strip(ulines.mm)
if abbrev(ali,',')=0 then do
isnew=isnew+1
tmps.isnew=ulines.mm
end
else do
tmps.isnew=tmps.isnew||substr(ali,2)
end
end
do mm=1 to isnew
ulines.mm=tmps.mm
end
ulines.0=isnew
return 0
/************************/
/* Do a multi wild card match -- return stats on match
Stats are list of letter positions (in needle) that are matched
Or, -1 for "exact match"
OR, 0 for "no match"
Example: Needle="THIS/IS/VERY/SILLY"
haystack="THIS*VERY*"
would yield: 1 2 3 4 9 10 11 12
One can then compare this result list to other result lists (to ascertain
best match */
wild_match:procedure
parse upper arg needle, haystack ; haystack=strip(haystack)
if needle=haystack then return -1 /* -1 signals exact match */
ast1=pos('*',haystack)
if ast1=0 then return 0 /* 0 means no match */
if haystack='*' then do
if length(needle)=0 then
return 100000
else
return length(needle)
end
ff=haystack
ii=0
do until ff=""
ii=ii+1
parse var ff hw.ii '*' ff
hw.ii=strip(hw.ii)
end
if hw.ii='' then ii=ii-1
hw.0=ii
/* check each component of haystackw against needle -- all components
must be there */
resu=' '
istart=1 ; ido=2
if ast1>1 then do /* first check abbrev */
if abbrev(needle,hw.1)=0 then return 0
aresu=length(hw.1)
if hw.0=1 then do
do nm=1 to aresu
resu=resu||' '||nm
end /* do */
return resu /* if haystacy of form abc*, we have a match */
end
ido=2 ; istart=aresu+1
do mm=1 to aresu
resu=resu||' '||mm
end /* do */
end
/* if here, then first part (a non wildcard) of haystack matches first
part of needle
Now check sequentially that each remaining part also exists
*/
do mm=ido to hw.0
igoo=pos(hw.mm,needle,istart)
if igoo=0 then return 0
tres=length(hw.mm)
istart=igoo+tres
do nn=igoo to (istart-1)
resu=resu||' '||nn
end /* do */
end
if istart >= length(needle) | right(haystack,1)='*' then
return resu
return 0