home *** CD-ROM | disk | FTP | other *** search
- /*
- $VER: DelBBSAds.dopus 4.8 (14.7.94)
- Copyright © 1993-1994 EAV Productions International
-
- ARexx script for Directory Opus to delete BBS ads from LhA archives.
-
- Requires: LhA, Directory Opus, MultiView, ReqTools.library and
- RexxReqTools.library
-
- DelBBSAds.dopus will also use locale.library to adapt to different
- languages, provided there is a catalog.
- */
-
- maxads=60 /* maximum number of ads in the config */
- configname='S:BBSAds.list' /* name of the config file to use */
-
-
- busy on /* switch busy mouse pointer on */
-
- signal on syntax /* intercept syntax errors */
- options results /* need results from DOpus */
- options failat 21 /* external commands are allowed returncode 20 */
-
- lf='a'x /* ascii code for linefeed */
- flag=0 /* something deleted? flag */
-
- call initlocale /* initialize local strings */
-
- viewer='AmigaGuide'
- if open('ksenv','ENV:Kickstart','r') then do
- version=readln('ksenv')
- if version>=39 then
- viewer='MultiView'
- call close('ksenv')
- end
-
- now=date('I')
- if now<6035 then
- call quitit msg.21
- nads=0
- totremoved=0
- totdate=0
-
- if open('configfile',configname,'r') then do
- thisline=readln('configfile')
- do until eof('configfile')
- nads=nads+1
- if nads>maxads then
- leave
- parse var thisline removed.nads date.nads adname.nads
- parse var adname.nads ' ' adname.nads
- totremoved=totremoved+removed.nads
- totdate=totdate+date.nads
- thisline=readln('configfile')
- end
- call close ('configfile')
- end
-
- compare=''
- do i=1 to nads
- compare=compare i':'adname.i
- end
-
- query updateflags
- follow=bittst(d2c(result),1) /* scroll window to follow operations? */
- query font 8 /* which font should requesters use? */
- fonttag='rt_font='result
-
- remember /* remember config settings */
- busy on
- modify deleteflags 8 /* don't ask when deleting internal */
-
- query screenname
- if result=0 then /* for compatibility with old DOpus */
- screenname=address()
- else
- screenname=result
-
- status 3 /* get active window */
- window=result
- status 9 window /* get number of selected entries */
- entries=result
-
- if entries=0 then
- call quitit msg.1
-
- if ~show('l','rexxreqtools.library') then
- call addlib('rexxreqtools.library',0,-30,0)
- eztags='rt_reqpos=reqpos_centerscr rt_pubscrname='screenname 'rtez_flags=ezreqf_centertext' fonttag
-
- /* Let the user choose between interactive and automatic. */
- call rtezrequest(msg.2,msg.3,,eztags)
- if rtresult=0 then
- call quitit msg.4
- automatic=(rtresult=2)
-
- checkabort /* reset abort flag */
- status 13 window /* get directory name */
- drawer=result
-
- do entries
-
- getnextselected
- filename=result
- if follow then
- scrolltoshow '"'filename'"'
- call insstr(filename,msg.5)
- toptext msgstring
- ext=upper(right(filename,4))
- arcfile=ext='.LHA'|ext='.LZH'|ext='.RUN'
- fileinfo '"'filename'" /'
- parse var result . '/' . '/' . '/' filetype '/'
-
- if filetype>0|~arcfile then
- call skipask msg.6
- else do /* list the archive's contents */
- address command 'LhA >T:DelBBSAds.temp vq -N -Qw -Qo "'drawer||filename'"'
- if rc>0 then
- call skipask msg.8
- else do
- call open('tempfile','T:DelBBSAds.temp','r')
- nfiles=0
- do until eof('tempfile')
- nfiles=nfiles+1
- name.nfiles=readln('tempfile')
- end
- nfiles=nfiles-1
- call close('tempfile')
-
- delthese=''
- delcount=0
- nomore=0
- call open('actionfile','T:actionfile','w')
-
- do i=nfiles to 1 by -1
- cuthere=pos(':'name.i' ',compare' ')
- select
- when upper(name.i)=='FILE_ID.DIZ' then
- nop
- when right(upper(name.i),10)=='.DISPLAYME' then
- call markfordel
- when cuthere>0 then
- call markfordel
- when automatic|nomore then
- nop
- otherwise do /* check by hand */
- call insstr(name.i,msg.9)
- call rtezrequest(msgstring,msg.10,,eztags)
- select
- when rtresult=0 then
- call stopit
- when rtresult=1 then
- nop
- when rtresult=2 then do
- toptext msg.11
- address command 'LhA e -q -x2 -a -C0 -Qo "'patchname(drawer||filename)'" T: "'patchname(name.i)'"'
- if rc>0 then do
- call skipask msg.12
- delcount=0
- leave /* a short way out of here */
- end
- temp=reverse(name.i)
- parse var temp thisfile '/'
- thisfile='"T:'reverse(thisfile)'"'
-
- address command viewer 'PUBSCREEN' screenname thisfile
- if rc>0 then do
- beep
- busy on
- call insstr(viewer,msg.13)
- call rtezrequest(msgstring,,,eztags)
- end
-
- delete thisfile /* delete temp file */
- busy on
-
- call insstr(name.i,msg.14)
- call rtezrequest(msgstring,msg.15,,eztags)
- if ~result then
- nomore=1
- end
- otherwise nomore=1
- end
-
- if ~nomore then do
- nads=nads+1
- adname.nads=name.i
- date.nads=now
- removed.nads=1
- compare=compare nads':'name.i
- call markfordel
- end
- end
- end
- end
- busy on
- call close('actionfile')
-
- if delcount>0 then do
- toptext msg.16 delcount'x'delthese
- flag=1
- address command 'LhA d -q -Qp -Qo "'patchname(drawer||filename)'" @T:actionfile'
- if rc>0 then
- call skipask msg.17
- delete 'T:actionfile'
- busy on
- end
- end
- end
- selectfile filename 0 1 /* deselect the processed file */
- checkabort /* did the user press both mouse buttons? */
- if result then
- call stopit msg.4
- end /* on to the next file */
-
- call stopit
-
-
- skipask:
-
- parse arg reason
- beep
- busy on
- call rtezrequest(reason||lf||msg.18,msg.19,,eztags)
- if ~rtresult then
- call stopit
- return
-
-
- initlocale:
-
- /* These are the English default strings. */
- msg.1="Nothing selected!"
- msg.2="How do you want to delete the\n.Displayme's and BBS ads?"
- msg.3="_Interactive|_Automatic|A_bort"
- msg.4="Aborted..."
- msg.5="Processing '%s'..."
- msg.6="Sorry, I can only process LhA archives!"
- msg.7="ERROR"
- msg.8="Error while listing archive."
- msg.9="Do you want to delete the file\n%s\nfrom the archive?"
- msg.10="_Yes|_View|_No|_Stop"
- msg.11="Extracting file..."
- msg.12="Error while extracting."
- msg.13="Sorry, %s cannot\nview this file."
- msg.14="Well, do you want to delete the file\n%s\nfrom the archive?"
- msg.15="_Yes|_No"
- msg.16="Deleting:"
- msg.17="Error while deleting from archive."
- msg.18="Do you wish to skip this file?"
- msg.19="_Skip|S_top"
- msg.20="Syntax Error %s, %s in line %s."
- msg.21="Error, system time not set right!"
- msg.22="Saving config..."
- msgno=22 /* number of locale strings */
-
- ok=show(l,'locale.library')
- if ~ok then
- ok=addlib('locale.library',0,-30)
- if ok then do
- catalog=opencatalog('DelBBSAds.catalog','',0)
- if catalog~=0 then
- do i=1 to msgno
- msg.i=getcatalogstr(catalog,i,msg.i)
- end
- call closecatalog(catalog);
- end
-
- /* Convert \n into real linefeeds. */
- do i=1 to msgno
- if pos('\n',msg.i)>0 then do
- parse var msg.i fore '\n' aft
- msg.i=fore||'a'x||aft
- i=i-1
- end
- end
- return
-
-
- insstr:
-
- parse arg replace,msgstring
- if pos('%s',msgstring)>0 then do
- parse var msgstring fore '%s' aft
- msgstring=fore||replace||aft
- end
- return
-
-
- markfordel:
-
- totremoved=totremoved+1
- delcount=delcount+1
- delthese=delthese "'"name.i"'"
- call writeln('actionfile','"'patchname(name.i)'"')
- if cuthere>0 then do
- cutagain=lastpos(' ',compare,cuthere-1)+1
- fileno=substr(compare,cutagain,cuthere-cutagain)
- removed.fileno=removed.fileno+1
- totdate=totdate-date.fileno+now
- date.fileno=now
- end
- return
-
-
- stopit: /* sort and save config */
-
- parse arg topline
- if flag then do /* some ads deleted */
- toptext msg.22
- call open('configfile',configname,'w')
- if automatic then
- do i= 1 to nads
- call writeln('configfile',removed.i date.i adname.i)
- end
- else do /* calculate the points rewarded to each entry */
- avgremoved=totremoved/nads
- avgdays=now-totdate/nads+1
- do i=1 to nads
- points.i=3.5*removed.i/avgremoved-(now-date.i)/avgdays
- end
- do i= 1 to nads
- if i>maxads then
- leave
- next=i
- itspoints=points.i
- do j=i+1 to nads
- if points.j>itspoints then do
- next=j
- itspoints=points.j
- end
- end
- call writeln('configfile',removed.next date.next adname.next)
- removed.next=removed.i
- date.next=date.i
- adname.next=adname.i
- points.next= points.i
- end
- end
- call close('configfile')
- end
- call quitit topline
-
-
- patchname: /* patch filenames containing pattern matching tokens */
-
- parse arg patched
- pos=1
- do forever
- here=verify(substr(patched,pos),"#?|%()[]~'",'m')
- if here=0 then
- leave
- pos=pos+here+1
- patched=insert("'",patched,pos-3)
- end
- do forever
- here=verify(substr(patched,pos),'*@','m')
- if here=0 then
- leave
- pos=pos+here+1
- patched=insert("*",patched,pos-3)
- end
- patched=translate(patched,'?','"')
- return patched
-
-
- syntax:
-
-
- call quitit "Syntax Error" rc"," errortext(rc) "in line" sigl"."
-
-
- quitit:
-
- parse arg topline
- if flag then
- rescan /* files should be shorter! */
- if exists('T:DelBBSAds.temp') then
- delete 'T:DelBBSAds.temp'
- if exists('T:actionfile') then do
- call close('actionfile')
- delete 'T:actionfile'
- end
- if topline~=="" then
- toptext topline
- if pos(msg.7,upper(topline))>0 then
- beep /* an error occurred */
- restore /* restore config settings */
- busy off /* switch to normal pointer */
- exit /* stop script here */
-