/* Loads the Last Visited pages from cache */
/*$VER: AWebLastPages.awebrx 3.1 (28.11.99)*/
/*
mailto:bsteers@btinternet.com
http://www.btinternet.com/~bsteers/
*/

ver='3.1' ; cdate='(28.11.99)'  ; pipe=0 ; shlp.0=0

OPTIONS RESULTS

parse source . . prog .

if ~show('l','rexxsupport.library') then call addlib('rexxsupport.library',0,-30,0)
ib=showlist(l,'intuition.library',,a); call forbid; scrA=next(ib,56);
scrw=c2d(IMPORT(offset(scrA,12),2)); scrh=c2d(IMPORT(offset(scrA,14),2)); call permit

IF ~EXISTS('env:aweb3/LastPage.cfg') THEN address command 'echo >env:aweb3/LastPage.cfg "; $VER: ''AWebLastPages configuration'' 'ver' 'preftime()'*n0 0 1 1*nwidth 300 height 40*nwidth 200 height 1*n#?.html*nHTML Only¿#?.html*nSlash Only¿#?/*nHTML And Slash¿#?(.html|/)*nIndex Files¿#?/index.html"'
IF ~EXISTS('envarc:aweb3/LastPage.cfg') THEN address command 'copy env:aweb3/LastPage.cfg envarc:AWeb3/LastPage.cfg'

IF OPEN(hand,'env:aweb3/lastpage.cfg')==0 THEN exit 20
call readln(hand)
distance=READLN(hand); parse var distance distance lvh lvv rmode .
mwnd=READLN(hand)
lwnd=READLN(hand)
defpat=READLN(hand)
 do num=1 while ~eof(hand)
 line=readln(hand);
  if line~="" then do;
  parse var line pats.num.name '¿' pats.num.pat
  pats.num.pat=strip(pats.num.pat)
  pats.0=num
  end
 end
CLOSE(hand)
mjust=0; ljust=0
if verify(word(mwnd,words(mwnd)),'fcstl','m')~=0 then; mjust=word(mwnd,words(mwnd))
if verify(word(lwnd,words(lwnd)),'fcstl','m')~=0 then; ljust=word(mwnd,words(lwnd))
if mjust='cm' then mwnd=strip(delword(mwnd,words(mwnd)))
if ljust='cm' then lwnd=strip(delword(lwnd,words(lwnd)))
IF distance==""|distance<0 THEN; distance=0

address value awebport()
'GET SCREEN' VAR screen
getcfg mime stem mimevar
address AREXX
nois='#?.~(' ;
htmls='#?(.(' ;

DO i=1 to mimevar.0
pattern=mimevar.i.value
select;when index(pattern,'IMAGE/')~=0 then mtype='I'; when index(pattern,'TEXT/HTML')~=0 then mtype='H';otherwise mtype='O';
end

pos=INDEX(pattern,';')+1; pattern=SUBSTR(pattern,pos) ;
pos=INDEX(pattern,';')-1
pattern=SUBSTR(pattern,1,pos) ;
wrds=WORDS(pattern)
  DO num=1 to wrds ;
  if mtype=="H" then htmls=''htmls'' || WORD(pattern,num) || '|' ;
  if mtype=="I" then nois=''nois'' || WORD(pattern,num) || '|' ;
  END
END
nois=''substr(nois,1,length(nois)-1)')'
htmls=''substr(htmls,1,length(htmls)-1)')/)'

stext=defpat

 do forever
 call mainloop()
 if xit==1 then call cleanup()
 end
exit

 cleanup:
 exit

mainloop:
call maingui()
call closep()
if xit==1 then return
call showfiles()
call closep()
return



/*----------------------------------Main GUI---------------------------------*/

maingui:
openp='p'
call open(pipe,"awnpipe:LastPages/xc")
call topipe('"A.L.P 'ver'  :^)" st "AWebLastPages 'ver' 'cdate' : By Bruce Steers" 'mwnd' fh sc "¿" h m cg ig it "LastPages" ii "'prog'" db dg sg si v a sk bf AWebPath:docs/awebbg.iff ps 'screen'')
call topipe('menu gt " Main ¿About LastPages¿$!AWebLastPages 'ver' 'cdate'¿About AWNPipe:¿$!Version 2.23 (12/11/99)¿$!Written By Bill Parker¿$-¿$Mailto:Bill Parker <wparker@amitrix.com>¿$-¿$Dowload awnp from Bruces Website¿Contact Me¿$@Mmailto:Bruce Steers <bsteers@btinternet.com>¿$-¿$@Hhttp://www.btinternet.com/~bsteers/¿-¿@HHelp ???¿-¿@SSettings¿-¿@QQuit"')

 call topipe('layout weih 0 si b 3')
 stextg= topipe('string tc gt "'stext'" maxc 5000')
 call makeclist()
 grab=topipe('chooser gt "Pre" tc 'clist' weiw 0')
 help=topipe('button tc gt "_Hlp" weiw 0')
 call topipe('le')

 call topipe('layout b 0 si weih 0')
 cfgg=topipe('button tc gt "_Cfg" ')
 call topipe('label gt "*n*n Search " weiw 0')
integ=topipe('integer a maxc 5 maxn 99999 defn 'distance' weiw 0')
 gog=topipe('button gt "_Go" tc c')
 call topipe('le')

call topipe('open')

call makeMhelp()

do while ~eof(pipe)
call topipe('con')
in= readln(pipe)
parse var in in1 in2 in3 in4 .
if in1='help' then if in2~=-1 then call helps()
if in1='menu' then call mmen()
if in1='key' then call keys()
if in1='gadget' then call gadget()
if in1='close' then if in2==0 then xit=1
if in1='iconify' then call topipe('id 0 s '64-(in2*32))
end
call close(pipe) ; openp=0
return

makeclist: ; clist='cl "'; do num=1 to pats.0; clist=''clist''pats.num.name'¿'; end; clist=''clist'MIME/HTML¿Not Images"';  return

keys:
select
when in2==69 then do; xit=1; call cleanup(); end
when in2==95 then call fileup('file://localhost/AWebPath:Docs/AWebLastPages.html')
when in2==19 then do; address command 'run >nil: rx 'prog ; xit=1; call cleanup(); end
otherwise nop
end
return

helps:
call stats(mhlp.in2)
return

makeMhelp:
mhlp.integ='Set the maximum number of pages to list' ; mhlp.cfgg='Change settings'
mhlp.help='Load AWebLattPages.html from AWebPath:docs/ dir' ; mhlp.gog='Start search for ''displayed pattern'' files'
mhlp.stextg='Pattern to be used when pressing ''Go' ; mhlp.grab='Select a preset search pattern'
mhlp.0=''
return

mmen:
  if in2==0 then do
  if in3==1 then if in4==3 then call mail('Bill Parker <wparker@amitrix.com,>?subject=Your Most Excellent AWNPipe')
  else; call fileup('http://www.btinternet.com/~bsteers/prog/awnp/index.html')
  if in3==2 then if in4==0 then ; call mail('Bruce Steers <bsteers@btinternet.com>?subject=AWebLastPages')
  else; call fileup('http://www.btinternet.com/~bsteers/')

  if in3==4 then call fileup('file://localhost/AWebPath:Docs/AWebLastPages.html')
  if in3==6 then call settings()
  if in3==8 then do; xit=1; call cleanup(); end
  end

return

gadget:
if in2=help then call fileup('file://localhost/AWebPath:Docs/AWebLastPages.html')
if in2=stextg then stext=substr(in,10)
if in2=grab then call grabp()
if in2=qit then xit=1
if in2=integ then distance=in3
if in2=cfgg then call settings()
return


/*-------------------------------URL ListBrowser-----------------------------*/

showfiles:
if rmode==1 then if req('Start Search',' Begin a search for pattern... *n 'stext' ','_Yes','_Cancel')==2 then return
openp='p'
call open(pipe,"awnpipe:ALPlister/xc")
call topipe('"AWebLastPages" sc "¿" 'lwnd' m ig it "LastPages" ii "'prog'" defg v a bf AWebPath:docs/awebbg.iff ps 'screen'')
call topipe('layout b 1 weih 0')
call topipe('space')

call stats('Reading Cache Now (Please Be Patient)')

address value awebport()
IF stext~="" THEN; 'GET CACHE STEM cach PAT='stext''
ELSE ; 'GET CACHE STEM cach'
ADDRESS AREXX
numc=cach.0
if distance==0 then todo=cach.0 ; else ; todo=distance
call stats('OK Preparing GUI for ('todo'/'cach.0') Pages')

call topipe('label gt "*n*nAWebLastPages*n Showing ('todo'/'cach.0') Pages "')
call topipe('space')
call topipe('le')
call topipe('layout v b 0')

l='listbrowser m lbl "\/¿Internet Location" st a'
if lvh then l=''l' h'
if lvv then l=''l' v'
lview=topipe(l)

am=1
bnode.0=0
DO WHILE am<=todo
bnode.am=topipe('browsernode st ro gt "' || am || '¿' || cach.numc.url || '"')
numc=numc-1
am=am+1
END

display=topipe('string gt "Double Click to Select Page" lj maxc 5000')
am=cach.0; am=am-1

call topipe('layout weih 0')
lod=topipe('button gt "_Select Page(s)"')
bak=topipe('button gt "_Main Window" close')
qit=topipe('button gt "_Quit" close')
call topipe('le')
call topipe('le')
call topipe('open')
opurl=''
 do while ~eof(pipe)
 call topipe('con')
 in= readln(pipe)
 parse var in in1 in2 in3 in4 in5 .
 if in1='gadget' then call gadget2()
 end
openp=0
return

gadget2:
if in2=lod then call cfileup()
if in2=display then do;
call topipe('id 'lview' s 0')
 parse var in . . rest . ;
 sel.0=1; sel.1.selp=-1
 sel.1=STRIP(rest); if word(rest,1)=='Double' then do; call noselect(); Return; end
call cfileup()
return
; end
if in2=bak then xit=0
if in2=qit then xit=1
 if in2=lview then DO;
 if in5=="" then do;  call noselect();return; end
 parse var in . . . . rest;
 rest=STRIP(rest); sel.0=WORDS(rest);
  do n=1 to sel.0;
  num=WORD(rest,n)-4;
  sel.n.selp=num+1
  num=cach.0-num;
  sel.n=cach.num.url;
  end
 num=sel.0
 if sel.0>1 then; call topipe('id 'display' gt "{m} 'sel.num'" ref')
 else; call topipe('id 'display' gt "'sel.num'" ref')
 IF in3==16 THEN call cfileup()
 end
return

/*--------------------------------The Settings-------------------------------*/

settings:

call topipe('id 0 s 128')
openp='s'
call open(seth,'awnpipe:alpsett/xc')
call toset('"''StartUp'' Prefs" width 250 ig it "LastPages" ii "'prog'" sc="¿" m h st "AWebLastPages Written by Bruce Steers: ''Main'' Preferences Settings" defg a v bf "AWebPath:docs/awebbg.iff" ps 'screen'')

call toset('clicktab ctl "Start_Up¿_Other"')

  call toset('layout b 0 si weih 0')
  setsveg=toset('button tc gt "_Save" weih 0 c')
  setcang=toset('button tc dis 1 gt "_Restore" weih 0')
  call toset('le')

  call toset('layout page 1 v b 0 so si')
    call toset('layout gt "Main Window" b 4 weih 0 si so')
    mwjusg=toset('chooser weih 0 tc s 'justnum(mjust)' pu cl "Custom X,Y¿CenterScreen¿TopLeft¿Full Screen¿Mouse Center"')
    mwsizg=toset('button weih 0 tc gt "Si_ze"')
    defpatg=toset('button weih 0 dis 1 tc gt "_Pattern"')
    call toset('le')

    call toset('layout v b 4 gt "Pattern Gadgets"')
    gadlv=toset('listbrowser lbl "Name¿Pattern" v st minh '11*(2+pats.0)'')
    goto=pats.0

    do n=1 to goto ;
    num=toset('browsernode gt "^'pats.n.name'¿^'pats.n.pat'"')
    bn.num=n
    pats.n.node=num
    end

      call toset('layout b 0 weih 0 si')
      slvaddg=toset('button tc weih 0 gt "_Add"')
      slvug=toset('button tc dis 1 weih 0 weiw 0 ab 5')
      slvdg=toset('button tc dis 1 weih 0 weiw 0 ab 6')
      slvremg=toset('button tc dis 1 weih 0 gt "_Remove"')
      call toset('le')
    call toset('le')
  call toset('le')

  call toset('layout page 1 b 0 v si so')
    call toset('layout v gt "Lister Window" b 4 si so')
      call toset('layout b 0 si')
      lwjusg=toset(' chooser tc s 'justnum(ljust)' pu cl "Custom X,Y¿CenterScreen¿TopLeft¿Full Screen¿Mouse Center"')
      lwsizg=toset('button tc gt "Si_ze" weih 0')
      call toset('le')

      call toset('layout b 0')
      call toset('label gt "*n*n Search Distance = " weiw 0')
      sint=toset('integer a minc 6 weiw 0 maxn 50000 defn 'distance'')
      call toset('space')
      call toset('le')

      call toset('layout b 4 so si gt "Spacer Lines"')
      lvhg=toset('checkbox gt "_Horizontal" s 'lvh'')
      lvvg=toset('checkbox gt "_Vertical" s 'lvv'')
      call toset('le')
    call toset('le')

    call toset('layout gt "Program Settings" v si so b 4 weih 0')
    rmodeg=toset('CheckBox gt "Warning Requesters" s 'rmode'')
    call toset('le')
call toset('space')
  call toset('le')


call toset('open')

if shlp.0==0 then call makeShelp()

patnum=0; cpat=0

call copyprefs()

do while ~eof(seth)
call toset('con')
in= readln(seth)
parse var in in1 in2 in3 in4 in5 .
if in1='help' then if in2~=-1 then call shelp()
if in1='gadget' then call sgad()
end

call close(seth);
openp='p'
call topipe('id 0 s 64')
return

/*------------------------------Settings Gadgets-------------------------*/
sgad:
if (showrestore~=1&in2~=1)==1 then do; toset('id 'setcang' dis 0 ref');showrestore=1; end
select
when in2==mwsizg|in2==lwsizg then call sizewin()
when in2==mwjusg|in2==lwjusg then call setjust()
when in2==rmodeg then rmode=in3
when in2==lvhg then lvh=in3
when in2==lvvg then lvv=in3
when in2==sint then do; distance=in3;call topipe('id 'integ' defn 'in3''); end
 when in2==defpatg then do;
 if rmode then if askfunc(' OK to Set the StartUp Search Pattern ? *n*n for..*n'splitsel(pats.patnum.pat)'') then return
 defpat=pats.patnum.pat
call topipe('id 'stextg' gt "'defpat'"')
call stats('Default Pattern Has Been Set')
 end


when in2==1 then do ; page=word('StartUp Other',in3+1); call toset('id 0 s 8 gt "'''page''' Window"'); call toset('id 0 s 16 gt "AWebLastPages Written by Bruce Steers: '''page''' Window Settings"'); end

 when in2==gadlv then do;
  if patnum==0 then do;
  call toset('id 'defpatg' dis 0 ref');
  call toset('id 'slvremg' dis 0 ref');
  end
 if in5==0 then do;call toset('id 'defpatg' dis 1 ref'); call toset('id 'slvremg' dis 1 ref'); call stats('No Pattern Selected'); return; end
 patnum=bn.in5; cpat=in5

 call stats('Ptrn: 'pats.patnum.name' : 'pats.patnum.pat'');

 dis=(patnum=1); call toset('id 'slvug' dis 'dis' ref')
 dis=(patnum=pats.0); call toset('id 'slvdg' dis 'dis' ref')
  if in3==8 then do;
  call writeln(seth,'id 'in5' read sort 'in4'');
  if in4==0 then pats.patnum.name=readln(seth); else; pats.patnum.pat=readln(seth)
  call makeclist()
  call toset('id 'grab' 'clist'')
  end
 end
when in2=setsveg then call saveprefs()
when in2=setcang then call restorprefs()
when in2=slvaddg then call addgad()
when in2=slvremg then call remgad()
when in2=slvug then call movegad('U')
when in2=slvdg then call movegad('D')
otherwise nop
end
showrestore=0
return

remgad:
if rmode then if askfunc(' OK to Remove gadget *n '''pats.patnum.name''' *n from the Gadget List ? ') then return
np=pats.0; pats.0=np-1
do n=patnum to np
 if n~=np then do
 plus=n+1
 pats.n.name=pats.plus.name
 pats.n.pat=pats.plus.pat
 pats.n.node=pats.plus.node
 nn=pats.n.node; m=bn.nn ; bn.nn=m-1
 end
end
call toset('id 'cpat' remn')
in2=gadlv
patnum=min(patnum,pats.0)
if pats.0~=0 then do
in5=pats.patnum.node
call toset('id 'gadlv' s 'in5'')
end

else do;
in5=0
patnum=0
call toset('id 'gadlv' s 0')
end

call sgad()
return

movegad: ;
if arg(1)='U' then sg=patnum-1; else; sg=patnum+1;
tn=pats.sg.name
tp=pats.sg.pat
pats.sg.name=pats.patnum.name
pats.sg.pat=pats.patnum.pat
pats.patnum.name=tn
pats.patnum.pat=tp
in5=pats.sg.node
call toset('id 'gadlv' list 0')
call toset('id 'in5' gt "^'pats.sg.name'¿^'pats.sg.pat'"')
call toset('id 'pats.patnum.node' gt "^'pats.patnum.name'¿^'pats.patnum.pat'"')
call toset('id 'gadlv' list 0')

call toset('id 'gadlv' list 1')
call toset('id 'gadlv' s 'in5'')
patnum=sg ; in2=gadlv
call sgad()
return

addgad:
if rmode then if askfunc(' OK to Add a New gadget *n*n Name: "New Pattern" *n Pattern:  "#?.html" *nTo the Gadget List ? ') then return
next=1+pats.0
pats.0=next
pats.next.name='New'
pats.next.pat='Pattern'
in5=toset('id 'gadlv' addn gt "^New¿^Pattern"')
pats.next.node=in5
bn.in5=next
call toset('id 'gadlv' s 'in5'')
patnum=next
in2=gadlv
call sgad()
return

shelp:
call stats(shlp.in2)
return

makeshelp:
shlp.1='Toggle between StartUp and Other Settings' ; shlp.setsveg='Save or Use Current settings'
shlp.setcang='Abort all changes to settings' ; shlp.mwjusg='Set Main window Opening Justification'
shlp.lwjusg='Set List window Opening Justification' ; shlp.mwsizg='Call a dummy Main window to move/size'
shlp.lwsizg='Call a dummy List window to move/size' ; shlp.lvvg='ListBrowser has vertical lines'
shlp.lvhg='ListBrowser has horizontal lines' ; shlp.defpatg='Set default pattern as selected in list'
shlp.gadlv='List of preset patterns (click to edit' ; shlp.slvaddg='Add a new pattern to the list'
shlp.slvremg='Remove selected pattern from list' ; shlp.rmodeg='Switch ON/OFF Function Requesters'
shlp.0=''
 return

sizewin:
call open(swh,'awnpipe:sisew/xc') ; gad=in2
 if gad==mwsizg then; win=''mwnd' fh';
 else; win=lwnd

 call tosw('"« Press Close Gadget When Finished" defg si so a m 'win' bf "AWebPath:docs/awebbg.iff" ps 'screen'')
call tosw('button c gt "_OK"');
call tosw('open');

 do while ~eof(swh)
  call writeln(swh,'id 0 read'); newdims=readln(swh)
 call tosw('con') ;
 in=readln(swh)
 parse var in in1 in2 in3 .
  if in1=='gadget' then do;
  end

 end /* end while */
call close(swh)

parse var newdims wl wt ww wh .

ns='width 'ww' height 'wh''
if gad==mwsizg then do
if mjust=='cm' then mwnd='left 'wl' top 'wt' 'ns''
else; mwnd=''ns' 'mjust''
end

else do;
if ljust=='cm' then lwnd='left 'wl' top 'wt' 'ns''
else; lwnd=''ns' 'ljust''
end

return

setjust:

if in2==mwjusg then; win=mwnd; else; win=lwnd

parse var win 'width' ww .
parse var win 'height' wh .
parse var win 'left' wl .; if wl=="" then wl=(scrw-ww)%2
parse var win 'top' wt .; if wt=="" then wt=(scrh-wh)%2

select
when in3==0 then do; twnd='left 'wl' top 'wt' width 'ww' height 'wh''; tj='cm'; end
when in3==1 then do; twnd='width 'ww' height 'wh' cs'; tj='cs'; end
when in3==2 then do; twnd='width 'ww' height 'wh' tl'; tj='tl'; end
when in3==3 then do; twnd='width 'ww' height 'wh' fs'; tj='fs'; end
       otherwise do; twnd='width 'ww' height 'wh''; tj=0; end
end

twnd=space(twnd,1)
if in2==mwjusg then do; mwnd=twnd; mjust=tj; end
else do; lwnd=twnd; ljust=tj; end
return

justnum:; if arg(1)~=0 then return(find('cm cs tl fs',arg(1))-1); return(4)

topipe:; parse arg out ; call writeln(pipe,out) ; res=readln(pipe); parse var res res1 res2 . ; if res1='ok' then return(res2); say 'error from: 'out; say '  responce: ' in; call closep(); exit
toset: ; parse arg out ; call writeln(seth,out) ; res=readln(seth); parse var res res1 res2 . ; if res1='ok' then return(res2); say 'error from: 'out; say '  responce: ' in; call close(seth); exit
tosw:  ; parse arg out ; call writeln(swh,out) ; res=readln(swh); parse var res res1 res2 . ; if res1='ok' then return(res2); say 'error from: 'out; say '  responce: ' in; call close(swh); exit

req: ; parse arg bar,txt,g1,g2,g3,g4,g5,g6,g7 .
if openp~=0 then call diswin(256)
if rf~=0 then call close(rf)
nxt=txt;
p=1; do while p~=0; p=index(nxt,'"',p); if P~=0 then do; nxt=insert('*',nxt,p-1);p=p+2; end; end;
call open(rf,'awnpipe:req/xc')
call writeln(rf,'"'bar'" v sw dg db a ps "'screen'"');
call writeln(rf,'space');
call writeln(rf,'layout b 5');
call writeln(rf,'space');
call writeln(rf,'label so weih 5 weiw 10 gt "*n*n'nxt'"');
call writeln(rf,'space');
call writeln(rf,'le');
call writeln(rf,'layout b 0 si so');
if g1~="" then call writeln(rf,'button gt "'g1'" close');if g2~="" then call writeln(rf,'button gt "'g2'" close');if g3~="" then call writeln(rf,'button gt "'g3'" close');if g4~="" then call writeln(rf,'button gt "'g4'" close');if g5~="" then call writeln(rf,'button gt "'g5'" close');if g6~="" then call writeln(rf,'button gt "'g6'" close');if g7~="" then call writeln(rf,'button gt "'g7'" close');
call writeln(rf,'le');
call writeln(rf,'open');call readln(rf)
do while ~eof(rf); rn=readln(rf); parse var rn rn1 rn2 rn3 rn4 rn5 .; if rn1=='gadget' then do ;
if openp~=0 then call diswin(512)
return(rn2-2);
end; end
if openp~=0 then call diswin(512)
return(0)

splitsel:
parse arg str
len=LENGTH(str);
div=len%70
if div==0 then return str
str2=' ';
 do c=0 to div-1 ;
 str2=''str2' 'SUBSTR(str,1+(c*70), ((c+1)*70)-(1+(c*70))+1 )' *n';
 end;
str2=space(' 'str2' 'substr(str,div*70)' ',1)
return str2

cfileup:
if sel.num=="" then RETURN
ans=req('AWebLastPages',' Your selected File is.. *n "'splitsel(sel.num)'" *n*n Select A Function for this Document ','Open _Current','Open _New','_Delete','_Abort')
call topipe('id 0 s 256')
if ans==4 then do; call topipe('id 0 s 512'); return; end
address value awebport()
if ans==1 then 'OPEN 'sel.num''
if ans==2 then 'NEW 'sel.num''
 if ans==3 then do
 if sel.0>1 then text='This will Delete ALL ('sel.0') Files*nMatching The EXACT Patterns Selected..'
 else; text='This will Delete ALL Files*nMatching The EXACT Pattern...*n'sel.num''
   if req('Delete From Cache',text,'_OK','_Cancel')==1 then do
   address value awebport()
     do n=1 to sel.0
     'DELETECACHE FORCE PAT 'sel.n''
     slp=sel.n.selp;
     if sel.n.selp~=-1 then call topipe('id 'bnode.slp' remn');
     end
   call topipe('id 'lview' selected=0 ref')
   call noselect()
   end
 end
address AREXX
call topipe('id 0 s 512')
return

noselect:;
call topipe('id 'display' gt "Double Click to Select Page" ref');
return

fileup:
parse arg lurl
ans=req('AWebLastPages Load URL','Load The URL*n "'lurl'*" *nSelect type of AWeb Window *n:^)','Open _Current','Open _New','_Abort')
if ans==3 then return
address value awebport()
call topipe('id 0 s 256')
if ans==1 then 'OPEN 'lurl
if ans==2 then 'NEW 'lurl
call topipe('id 0 s 512')
address AREXX
return

closep: ; call close(pipe); pipe=0; return

grabp: ; num=pats.0;  in4=in3+1; select; when in3<num then stext=pats.in4.pat ; when in3==num then stext=htmls
otherwise stext=nois; end; call topipe('id 'stextg' gt 'stext' ref'); return


saveprefs:

ans=req('Save Prefs','Save Current Settings','_Only Env:','_Env: & Envarc:','_Dont Save')
if ans==3 then return


call open(np,'env:AWeb3/LastPage.cfg','W');
call writeln(np,'; $VER: ''AWebLastPages configuration'' 'ver' 'preftime()'')
call writeln(np,distance lvh lvv rmode);
if mjust=='cm' then wnd=''mwnd' cm'; else ; wnd=mwnd
call writeln(np,wnd);

if ljust=='cm' then wnd=''lwnd' cm'; else ; wnd=lwnd
call writeln(np,wnd);

call writeln(np,defpat);

do n=1 to pats.0
call writeln(np,''pats.n.name'¿'pats.n.pat'')
end
call close(np)
if ans==2 then address command 'Copy >nil: env:AWeb3/LastPage.cfg envarc:AWeb3/LastPage.cfg'
return

preftime: date=date('e'); parse var date d '/' m '/' y . ; return('('d'.'m'.'y') 'time('c')'')

copyprefs:; bdist=distance; blh=lvh; blv=lvv; brmode=rmode; bmw=mwnd; bmwj=ljust; blw=lwnd; blwj=ljust; bdp=defpat; blp.0=pats.0; do n=1 to pats.0; blp.n.nam=pats.n.name; blp.n.ptrn=pats.n.pat; blp.n.nod=pats.n.node; end; return

restorprefs:
call toset('id 0 s 128')

distance=bdist; lvh=blh; lvv=blv; rmode=brmode; mwnd=bmw; ljust=bmwj; lwnd=blw; ljust=blwj; defpat=bdp; pats.0=blp.0

call topipe('id 'integ' defn "'bdist'"')
call topipe('id 'defpatg' gt 'bdp'')

xx=justnum(bmwj)
call toset('id 'mwjusg' s 'xx'')
call toset('id 'gadlv' remn')
do x=1 to pats.0
pats.x.name=blp.x.nam
pats.x.pat=blp.x.ptrn
pats.x.node=blp.x.nod
 num=toset('id 'gadlv' addn gt "^'pats.x.name'¿^'pats.x.pat'"')
 bn.0=x
 bn.num=x
end

xx=justnum(blwj)
call toset('id 'lwjusg' s 'xx'')
call toset('id 'sint' defn "'bdist'"')
call toset('id 'lvhg' s 'lvh'')
call toset('id 'lvvg' s 'lvv'')
call toset('id 'rmodeg' s 'rmode'')

call toset('id 0 s 64')
return

mail: ;
if askfunc(' OK to Load YAM:YAM *n Fill in the Address Field *n and*n The Subject field too ? *n:)') then return
 if ~exists('YAM:YAM') then do;
 call req('Sending e-mails','Sorry i Can''t find YAM:YAM by Marcel Beck*n*n If you do not use YAM you could edit this Script to run your own Mailer','_OK'); return
 end
PARSE ARG mailto
temp=UPPER(mailto)
jump=9
p=INDEX(temp,'?SUBJECT=')
 IF p==0 THEN DO
 p=INDEX(temp,'?')
 jump=1
 END
 IF p~=0 THEN DO
 subject=SUBSTR(mailto,p+jump)
 mailto=SUBSTR(mailto,1,p-1)
 END
 ELSE DO
 subject='I''m too lazy to write a subject'
 END
 IF ~SHOW('p','YAM') THEN DO
 address command 'run >nil: yam:yam NOCHECK MAILTO "' || mailto || '" SUBJECT "' || subject || '"'
 END
 ELSE DO
 ADDRESS YAM
 MailWrite
 'WRITETO "'mailto'"'
 'WRITESUBJECT "'subject'"'
 END
address AREXX
return

askfunc:
ret=req('AWebLastPages',arg(1),'_YES','_NO')
if ret==1 then return 0
return 1

stats:
address value awebport()
'STATUSFIELD "'arg(1)'"'
address AREXX
return

awebport:
pt=show('p')
parse var pt . 'AWEB.' pn . ;
 if pn=="" then do;
  if req('AWebLastPages',' AWeb Is not running !! *n :-\ *n Do you want to load it ?? ','_YES','_NO')==1 then do
  address command 'run >nil: Aweb3:Aweb-II'
  address command 'Waitforport AWEB.1'
  pt=show('p')
  parse var pt . 'AWEB.' pn . ;
  end
  else; exit(0)
 end
address value AWEB.pn
'GET ACTIVEPORT'
awp=result
address AREXX
return awp

diswin:
if openp=='p' then call topipe('id 0 s 'arg(1)'')
if openp=='s' then call toset('id 0 s 'arg(1)'')
return
