#! /bin/sh
/*bin/true
REXXIMC=/nyx/projects/pgilmart/src/rexx/source
REXXPATH=/u/p/g/pgilmart/bin
export REXXPATH REXXIMC
exec $REXXIMC/rexx -x "$0" "$@" # */

/* Remove duplicate links from bookmarks files.
*/
signal on novalue

'set -ex;  [ -r ../cleanbook ] &&' ,
'( cat ../bookmarks.html;' ,
  'cat ../*.html ./bookmarks.html | grep ''^<LI>'' | sort' ,
') > ../work.cleanbook        &&' ,
'rm -f bookmarks.html'            ,
      '''STK Internal.html'''     ,
      '''Erotic Links.html''  &&' ,
'touch nothing.html           &&' ,
'mv *.html ..                 &&' ,
'rm -f * ../nothing.html'
if RC<>0 then exit RC

RC = Clean('newscan.html')
RC = Clean('VM FTP Test.html')
RC = Clean('STK Internal.html')
RC = Clean('MkLinux.html')
RC = Clean('Mac Stuff.html')
RC = Clean('Mainframe Links.html')
RC = Clean('WWW Info.html')
RC = Clean('Music Links.html')
RC = Clean('Science Links.html')
RC = Clean('Erotic Links.html')
RC = Clean('General.html')
RC = Clean('work.cleanbook')

'mv    work.cleanbook bookmarks.html &&' ,
'rm ../work.cleanbook'

exit(RC)

Clean:
    parse arg Dest
    From = '../'Dest
    say 'Filtering from' From 'to' Dest '========== =========='
    '[ -r '''From''' ]';  if RC<>0 then do
        say '    ##### Not Found #####'
        return(RC);  end
    'sleep 2'
    UnChanged = 1
    do Line = 1 while chars(From)>0
        L = linein(From)
        if left(L,4)=='<LI>' & length(L) < 240 then do
            if symbol('Seen.L')<>'LIT' then do
                UnChanged = 0
                say '    Skipping Dup:' Line Seen.L':' L
                iterate Line;  end
            Seen.L = Dest Line;  end
        call lineout Dest, L;  end Line
    call lineout From
    call lineout Dest
    if UnChanged then 'set -x;  rm '''Dest''''
    return(result)

novalue:
    say  'NOVALUE at' sigl
    X = X/(X-X)
