home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / mtchfile.rx0 < prev    next >
Text File  |  1999-03-01  |  3KB  |  131 lines

  1. /* the "find best matching files" INTERPRETable sre-http addon
  2.    nshow: number of matches to list (default = 5)
  3.    prefix: prefix (default= <li> )
  4.    noscore: If 1, then do not display "match score"
  5.   altname: if not '', then use this (instead of the actual request selector)
  6.  
  7.   The DIR_EXCLUSION parameter is read, directories and filenames (files may
  8.   be wildcarded) that appear in dir_exclusion will NOT be displayed
  9.  
  10. */
  11.  
  12. parse arg nshow prefix noscore altname
  13.  
  14. if prefix='' then prefix='<li>'
  15. if nshow='' then nshow=5
  16.  
  17. basis=''
  18. if altname='' then
  19.    dname=strip(docname,,'/')
  20. else
  21.    dname=strip(altname,,'/')
  22.  
  23.  
  24. ii=lastpos('/',dname)
  25. checkname=substr(dname,ii+1)  
  26.  
  27. if ii=0 then do        
  28.    seldir='/'
  29.    basis=ddir          
  30. end
  31. else do
  32.   seldir=left(dname,ii)
  33. end
  34.  
  35. direx=translate(get_value('dir_exclusion'))
  36.  
  37. do until basis<>'' 
  38.   basis2=sref_do_virtual(ddir,seldir||checkname,enmadd,0,,,host_nickhame)  
  39.   gg=filespec('d',basis2)||filespec('p',basis2)
  40.   gg=strip(gg,,'\') ;  if right(gg,1)=':' then gg=gg'\'   
  41.   
  42.   ipoo=lastpos('\',gg)
  43.   naa=''
  44.   if ipoo>0 then do
  45.      naa=substr(gg,ipoo)
  46.   end
  47.   if wordpos(naa,direx)=0 then do 
  48.      if dosisdir(gg)=1 then do      
  49.           basis=gg
  50.           leave
  51.      end
  52.   end
  53.   oy=lastpos('/',seldir,length(seldir)-1)
  54.   if oy=0 then do
  55.      seldir='/'
  56.      basis=ddir
  57.      leave 
  58.   end
  59.   seldir=left(seldir,oy)
  60. end
  61.  
  62. basis=strip(translate(basis,'\','/'),,'\')'\'
  63. seldir='/'||strip(seldir,'l','/')
  64.  
  65. if basis<>'' then do
  66.   aa=sysfiletree(basis'*.*','goos','fo')
  67.   parse upper var checkname aname '.' aext
  68.   nwild=0
  69.   do ii=1 to words(direx)
  70.      aw=strip(word(direx,ii))
  71.      if left(aw,1)='\' then iterate
  72.      if pos('*',aw)=0 then iterate
  73.      nwild=nwild+1
  74.      wlist.nwild=aw
  75.   end
  76.   maxscore=-1
  77.   do mm=1 to goos.0
  78.      score1=0 ; score2=0
  79.      tname=filespec('n',goos.mm) 
  80.      if wordpos(translate(tname),direx)>0 then do
  81.          goos.mm.!score=-2
  82.      end
  83.      IF GOOS.MM.!SCORE<>-2 THEN DO
  84.        do ii=1 to nwild
  85.           if sref_wild_match(TRANSLATE(tname),wlist.ii,'')<>0 then do
  86.             goos.mm.!score=-2
  87.             leave
  88.           end
  89.        end
  90.      END
  91.      if goos.mm.!SCORE<>-2 then do
  92.         parse upper var tname bname '.' bext
  93.         sc1=sref_compword(aname,bname)
  94.         sc2=sref_compword(aext,bext)
  95.         score1=((3*sc1)+sc2)/4
  96.  
  97.         sc1=sref_compword(bname,aname)
  98.         sc2=sref_compword(bext,aext)
  99.         score2=((3*sc1)+sc2)/4
  100.  
  101.        score=(score1+score2)/2
  102.        goos.mm.!score=trunc(score*100)
  103.     end
  104.  
  105.   end
  106.  
  107. /* find top nshow */
  108.   do mm=1 to min(goos.0,nshow)
  109.     amax=-1
  110.     do nn=1 to goos.0
  111.        if goos.nn.!score>amax then do
  112.            amax=goos.nn.!score ; iat=nn
  113.        end
  114.     end
  115.     if amax<0 then do
  116.         nshow=mm-1
  117.         leave
  118.     end
  119.     bests.mm=goos.iat' 'goos.iat.!score
  120.     goos.iat.!score=-1
  121.   end 
  122.   do mm=1 to min(goos.0,nshow)
  123.    parse var bests.mm a1a score
  124.    a1=filespec('n',a1a)
  125.    mkk=prefix'<a href="'seldir||a1'">'a1'</a>'
  126.    if noscore<>1 then mkk=mkk' <em>('score')</em>'
  127.    queue mkk
  128.   end 
  129. end
  130.  
  131.