/**************************************************************************\
             $VER: ViewLog Maint, v5.01 (3-Nov-96) by Dotoran!
\**************************************************************************/
options results ; signal on SYNTAX ; signal on ERROR ; signal on IOERR
tr=transmit ; se=sendstring ; gc=getchar ; gu=getuser ; mg=maygetchar
a='rexxsupport.library';if ~show('l',a) then if ~addlib(a,0,-30) then exit

changewhere "ViewLog5 Maint" ; tw=0 ; ver="5.01"
se "f1[12;38HcfHello...[23;5HceViewLog5 c9Maint c6loading...cc"

BEGIN:
  call READCONFIG ; call CHECKVER ; call READTITLES ; call READDATA
  call SETUP ; call SCREEN

START:;rr=word(rows,row);cc=word(cols,col);inc=4;if ed=1 then do;rr=row+4;inc=15;end
  if col~=2 then help=help.col ; else do ; z=lo+(row-1) ; a=trim.z ; help=res.a ; end
  se "z2cf[22;5H"center(help,52)"z0["rr";"cc"Ho1cf>o0[21;78H" ; gc ; call CHECK
  k=result ; kk="" ; if c2d(k)=27 then do ; do 2 ; mg ; end ; kk=result ; end
  if c2d(k)=13 then signal EDIT
  if (c2d(k)=27 & kk="NOCHAR") | k="Q" then signal QUIT
  if kk~="NOCHAR" & k~="" then tr "["rr";"cc"H "
  if k=8 | kk="A" then do
    row=row-1 ; if row<1 then row=hi2-lo+1 ; signal START ; end
  if k=2 | kk="B" then do
    row=row+1 ; if row>hi2-lo+1 then row=1
    signal START ; end
  if k=6 | kk="C" then do
    col=col+1 ; if col>7 then col=1 ; signal START ; end
  if k=4 | kk="D" then do
    col=col-1 ; if col<1 then col=7 ; signal START ; end
  if k="N" & hi<logs then do ; lo=lo+inc ; hi=hi+inc
    if ed=2 then call DISPLAY1 ; else call DISPLAY2
    if hi2=logs then row=1 ; signal START ; end
  if k="P" & lo>1 then do ; lo=lo-inc ; hi=hi-inc
    if ed=2 then call DISPLAY1 ; else call DISPLAY2 ; signal START ; end
  if k="M" & ed=1 then do ; ed=2 ; row=1 ; col=1 ; lo=1 ; hi=4
    if hi>logs then hi=logs ; call SCREEN ; signal START ; end
  if k="L" & ed=2 then do ; ed=1 ; row=1 ; col=1 ; lo=1 ; hi=15
    if hi>logs then hi=logs ; call SCREEN ; signal START ; end
  if k="S" then do;call SCANDATA;signal BEGIN;end
  if k="G" then do
    se "[23;5HcbGoto c6which cdpagec6? c7(cf1c6-cf"logs%inc"c6/cf[cb"logs%inc%2"cf]c7)c6: cfi64 2}"
    gu 70;a=result;if a<1|a>logs%inc|datatype(a,'n')=0 then a=logs%inc%2

    lo=a*inc-inc+1 ; hi=lo+inc-1

    se "[23;1H[K"
    if ed=2 then call DISPLAY1 ; else call DISPLAY2 ; signal START;end

 signal START

EDIT:;it=lo+(row-1);z=1;if it/2=it%2&ed~=2 then z=2;a="EDIT"col;signal (a)

EDIT1:;se "["rr";"cc+1"Hc"substr("e6",z,1)"L1305640 #"uacc.it"}i4 18}[21;75Hcf"
  gu 70;a=result;if uacc.it=a then signal START
  a=PARSE(a,0,31);a=RANGE(itt.0);uac.it=itt.0;uacc.it=a;save=1
  tr "["rr";"cc+1"Hc"substr("e6",z,1)left(a,18)"[21;75H ";signal START

EDIT2:;a=trim.it;a=a+1;if a=3 then a=1;trim.it=a;save=1
  se "["rr";"cc+1"Hc"substr("91",z,1)left(word("Ask Auto",a),7)
 signal START

EDIT3:;se "["rr";"cc+4"Hh3c"substr("f7",z,1)"L1305640 #"trln.it"}i4 3}"
  gu 70;a=result;if a<5 then a=5 ; trln.it=a ; save=1
  tr "["rr";"cc+1"Hc"substr("f7",z,1)right(a,3);signal START

EDIT4:;a=logH.it;a=a+1;if a>1 then a=0;logH.it=a;save=1
  se "["rr";"cc+1"Hc"substr("a2",z,1)right(word("No Yes",a+1),3)
  if a=0 then hisT.it="N/A" ; else hisT.it=trln.it*10
  se "["rr";"cc+5"Hc"substr("e6",z,1)right(hisT.it,7);signal START

EDIT5:;se "["rr";"cc+5"Hh4c"substr("e6",z,1)"L1305640 #"hisT.it"}i4 4}"
  gu 70;a=result;if a<0 then a=0 ; hisT.it=a ; save=1
  tr "["rr";"cc+1"Hc"substr("e6",z,1)right(a,4);signal START

EDIT6:;aa=logI.it
  se "[23;1Hcc>cdL1305640 #"title.aa"}i4 78}[23;1H[K"
  gu 70;a=result;save=1;title.aa=a;zz=0;if a>"" then zz=1
  tr "["rr";"cc+1"Hc"substr("d5",z,1)right(word("No Yes",zz+1),3)
  if ed=2 then tr "["rr+1";3Hcd"left(a,76)
 signal START

EDIT7:;a=sysM.it;a=a+1;if a>1 then a=0;sysM.it=a;save=1
  se "["rr";"cc+1"Hc"substr("91",z,1)right(word("No Yes",a+1),3)
 signal START

QUIT:
  if save=1 then do;call SAVEDATA;call SAVETITLES;end;se "[23;1H"
 exit

SAVEDATA:
  se "[23;5HcbSaving cddata filesc6...c9"
  call open(f1,comP"VL_Data","w")
    do i=1 to logs ; se TWIRL()
      log.i=left(logI.i,4)left(logN.i,15)left(logF.i,15)left(uacc.i,15)
      log.i=log.i||left(uac.i,90)left(trim.i,2)left(trln.i,3)
      log.i=log.i||left(logH.i,2)left(hisT.i,4)left(sysM.i,2)asoc.i
      call writeln(f1,log.i)
    end i
  call close(f1)
  address command "sort "comP"VL_Data "comP"VL_Data COLSTART 5"
 return

SAVETITLES:
  call open(f1,comP"VL_Titles","w")
    do i=1 to logs ; z=logI.i ; se TWIRL()
      call writeln(f1,left(logI.i,4)left(logN.i,12)title.z)
    end i
  call close(f1)
 return

SCREEN:;a="SCREEN"ed;signal (a)
SCREEN1:;tr "f1@4 [1;42;37m      ViewLog, v"ver" Maintenance Module by Dotoran of Frontiers BBS!         "
  tr "[34;40mÉÍÍËÍÍÍËÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍËÍÍÍÍÍËÍÍÍÍËÍÍÍÍÍÍÍËÍÍÍÍÍÍËÍÍÍÍÍÍÍ»"
  tr "º[37m##[34mº[33mID#[34mº[32mLog Name [34mº[36mUser Access Groups[34mº[31mReStart[34mº [37mTrim[34mº[32mHist[34mº[36mHistory[34mº[35mHeader[34mº [31mMaster[34mº"
  tr "ÌÍÍÊÍÍÍÊÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍÊÍÍÍÍÍÍÍÊÍÍÍÍÍÍÊÍÍÍÍÍÍÍ¹"
  do i=1 to 15;tr "º[77Cº";end i;tr "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍ[33mN[32mEXT[34mÍÍ[33mP[32mAST[34mÍÍ[33mS[32mCAN[34mÍÍ¹"
  tr "º[0;36mUse [1;32mArrows [0;36mto [1;32mMove[0;36m, [37m<[1;33mENTER[0m> [36mto [1;33mEdit[0;36m, [37m<[1;35mESC[0m> [36mto [1;35mSave[0;36m/[1;35mQuit[34mÄ[0;36mor[1;34mÄÅÄÄÄÄÄÅÄÄÄÄÄ´[5Cº"
  tr "ÈÄ>[42m                                                    [40m<ÄÏÍÍ[33mG[32mOTO[34mÍÍ[33mM[32mORE[34mÍÍ[33mL[32mESS[34m<Ä¼";signal DISPLAY2
SCREEN2:;tr "f1@4 [1;42;37m      ViewLog, v"ver" Maintenance Module by Dotoran of Frontiers BBS!         "
  tr "[34;40mÉÍÍËÍÍÍËÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍÍÍÍÍÍËÍÍÍÍÍËÍÍÍÍËÍÍÍÍÍÍÍËÍÍÍÍÍÍËÍÍÍÍÍÍÍ»"
  tr "º[37m##[34mº[33mID#[34mº[32mLog Name [34mº[36mUser Access Groups[34mº[31mReStart[34mº [37mTrim[34mº[32mHist[34mº[36mHistory[34mº[35mHeader[34mº [31mMaster[34mº"
  tr "ÌÍÍÊÍÍÍÊÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÊÍÍÍÍÍÍÍÊÍÍÍÍÍÊÍÍÍÍÊÍÍÍÍÍÍÍÊÍÍÍÍÍÍÊÍÍÍÍÍÍÍ¹"
  do i=1 to 3;tr "º[77Cº";tr "º[77Cº";tr "º[77Cº";tr "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍ¹";end i
  tr "º[77Cº";tr "º[77Cº";tr "º[77Cº";tr "ÌÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍÍËÍÍ[33mN[32mEXT[34mÍÍ[33mP[32mAST[34mÍÍ[33mS[32mCAN[34mÍÍ¹"
  tr "º[0;36mUse [1;32mArrows [0;36mto [1;32mMove[0;36m, [37m<[1;33mENTER[0m> [36mto [1;33mEdit[0;36m, [37m<[1;35mESC[0m> [36mto [1;35mSave[0;36m/[1;35mQuit[34mÄ[0;36mor[1;34mÄÅÄÄÄÄÄÅÄÄÄÄÄ´[5Cº"
  tr "ÈÄ>[42m                                                    [40m<ÄÏÍÍ[33mG[32mOTO[34mÍÍ[33mM[32mORE[34mÍÍ[33mL[32mESS[34m<Ä¼";signal DISPLAY1

DISPLAY1: ; ro=1 ; hi2=hi ; if hi>logs then hi2=logs
  do i=lo to hi2 ; r=ro*4+1
    se "cf["r";2H"right(i,2)" cb"logI.i" ca"left(logF.i,9)" ce"
    se left(uacc.i,20)" c9"left(word("Ask Auto",trim.i),5)
    se " cf"right(trln.i,5)" ca"right(word("No Yes",logH.i+1),4)" ce"
    if logH.i=1 then se right(hisT.i,7)"cd" ; else se right("N/A",7)"cd"
    a=0;z=logI.i;if title.z>"" then a=1
    tr right(word("No Yes",a+1),7)" c9"right(word("No Yes",sysM.i+1),7)
    tr "["r+1";3Hcd"left(title.z,76) ; tr "["r+2";3Hc9"left(asoc.i,76)
    ro=ro+1
  end i
  if hi2=logs then do
    do i=hi2-lo to inc-2 ; r=ro*4+1
      tr "["r";2H"left(" ",77)"["r+1";2H"left(" ",77)
      tr "["r+2";2H"left(" ",77) ; ro=ro+1
    end i ; end
 return

DISPLAY2: ; ro=1 ; hi2=hi ; if hi>logs then hi2=logs
  do i=lo to hi2 ; r=ro+4 ; c=1 ; if i/2=i%2 then c=2
    se "c"substr("f7",c,1)"["r";2H"right(i,2)" c"substr("b3",c,1)logI.i
    se " c"substr("a2",c,1)left(logF.i,9)" c"substr("e6",c,1)left(uacc.i,20)
    se " c"substr("91",c,1)left(word("Ask Auto",trim.i),5)
    se " c"substr("f7",c,1)right(trln.i,5)" c"substr("a2",c,1)right(word("No Yes",logH.i+1),4)
    if logH.i=1 then se " c"substr("e6",c,1)right(hisT.i,7)" c"substr("d5",c,1)
      else se " c"substr("e6",c,1)"    N/A c"substr("d5",c,1)
    a=0;z=logI.i;if title.z>"" then a=1
    se right(word("No Yes",a+1),6)" c"substr("91",c,1)right(word("No Yes",sysM.i+1),7);ro=ro+1
  end i
  if hi2=logs then do
    do i=hi2-lo to inc-2
      tr "["i+6";2H"left(" ",77)
    end i ; end
 return

SETUP: ; ed=1 ; it=1 ; lo=1 ; hi=15 ; tw=0 ; if hi>logs then hi=logs
  help.1="The Access Group RANGE that can VIEW this log file."
  help.3="The number of Lines to Trim this Log file down to."
  help.4="Should a history of this log be created/maintained."
  help.5="The number of Lines that a History file can become."
  help.6="The title text to use when displaying this log."
  help.7="Is this a MASTER SYSOP(ID#1) ONLY editable log."
  res.1="Ask Maint User to Trim or Delete Logs & Histories."
  res.2="Automatically Trim Logs during AutoMaintenance."
  row=1 ; col=1 ; rows="5 9 13 17" ; cols="18 39 47 52 59 67 75"
 return

CHECKVER: ; if ver=vers then return
  tr "f1n6c9Version Conflict:n1"
  tr "   `ViewLog5.cfg' version: v"vers
  tr "   `VL_Maint'     version: v"ver
  tr "n1   BOTH files above need to be v"max(ver,vers)"!"
  tr "n1Halting, due to conflicting versions..."
 exit

READCONFIG:;gu 1311992;comP=result
  call open(f1,comP"ViewLog5.cfg","r")
    vers=readln(f1) ; macc=readln(f1)
    uacc=readln(f1) ; trim=readln(f1) ; trln=readln(f1)
    logH=readln(f1) ; hisP=readln(f1) ; hisT=readln(f1)
    ETex=readln(f1)
    ARus=readln(f1) ; ARsy=readln(f1) ; ARpt=readln(f1)
  call close(f1)
 return

READDATA:
  if ~exists(comP"VL_Data") then call SCANDATA2
  call open(f1,comP"VL_Data","r")
    do i=1 until eof(f1) ; log.i=readln(f1) ; se TWIRL()
      parse var log.i 1 logI.i . 5 logN.i . 20 logF.i . 35 uacc.i .,
                      50 uac.i"  " 138 trim.i . 140 trln.i . 143 logH.i .,
                      145 hisT.i . 149 sysM.i . 151 asoc.i
    end i ; logs=i-1
  call close(f1)
 return

READTITLES:
  call open(f1,comP"VL_Titles","r") ; title.=""
    do i=1 until eof(f1) ; a=readln(f1) ; se TWIRL()
      parse var a 1 v1 . 5 v2 . 17 v3 ; title.v1=v3 ; end i ; titles=i-1
  call close(f1)
 return

PARSE: ; arg rng,min,maxx
   itt.='';c=0;itt=translate(rng,'  ','.,')
    do a=1 to words(itt);c=c+1;itt.c=word(itt,a);se TWIRL()
        if index(itt.c,'-')>0 then do;parse var itt.c x'-'y
        if y='' then y=maxx;if x='' then x=min
        if x>y then do;d=x;x=y;y=d;end
        if x<min|y>maxx|~datatype(x,'W')|~datatype(y,'W') then do;c=c-1;iterate;end
        do b=x to y;itt.c=b;c=c+1;end;c=c-1;end
    else if itt.c<min|itt.c>maxx|~datatype(itt.c,'W') then do;c=c-1;iterate;end;end
    if c>0 then do;do a=1 to c-1;d=a;do b=a+1 to c;d=d+1;se TWIRL()
        if itt.d<itt.a then do;y=itt.a;itt.a=itt.d;itt.d=y;end
        else if itt.d=itt.a then do;itt.d=itt.c;c=c-1;d=d-1;end;end;end;end;a=0
    do i=1 to c;se TWIRL();j=i+1;if itt.i~=itt.j then do;a=a+1;itt.a=itt.i;end;end;c=a
    do i=1 to c;se TWIRL();itt.0=itt.0||itt.i' ';end
  return itt.0

RANGE:;arg gr;a="";if words(gr)=1 then return strip(gr)
  do i=1 to words(gr) ; se TWIRL()
    j=i+1 ; v1=word(gr,i) ; v2=word(gr,j)
    if v2>"" then if v2-v1=1 then do ; s=v1
      do while v2-v1=1
        i=i+1 ; j=j+1 ; v1=word(gr,i) ; v2=word(gr,j)
        if v2="" then leave
      end
      a=a||s"-"v1"," ; iterate i
    end
    if v2="" then a=a||v1","
  end i
 return strip(a,'t',',')

TWIRL:;sh="--\\||//";tw=tw+1;if tw>8 then tw=1;return substr(sh,tw,1)"<1"

SCANDATA: ; se "[23;5HcbScan c6memory for cddefined logsc6? c7[caYesc7]c9: ";gc;a=result
  if a="N" then do;se "c9Noc6.[23;1H[K";signal START;end;else se "caYesc6!"
SCANDATA2: ; se "[23;5Hc6Scanning caInternal Logsc6...c9[K" ; logs=0 ; l=""
  do i=1 to 88 ; v=2321898+(i*24) ; se TWIRL()
    gu v ; v1=result ; gu v+12 ; v2=result ; gu (v+10)-100000 ; v3=result
    if v2>"" then do ; logs=logs+1 ; logI.logs=v3 ; logN.logs=v1
      logF.logs=v2 ; l=l||v2" " ; end ; end i
  if open(f1,comP"VL_Data2","r") then do
    id=readln(f1)
    do i=1 until eof(f1)
      a=readln(f1) ; l=l||a" "
    end i
    logs=logs+i-1
    call close(f1)
  end
  else id=499
  se "[23;5Hc6Scanning cbExternal Logsc6...ca[K"
  if ~exists(comP"VL_Data2") then do
    call open(f1,comP"VL_Data2","w")
      call writeln(f1,id) ; end
  else call open(f1,comP"VL_Data2","a")
  a=showdir("SysData:Log/","F"," ")
  do i=1 to words(a) ; aa=word(a,i) ; se TWIRL()
    if find(l,aa)=0 then do ; logs=logs+1 ; call writeln(f1,aa)
      id=id+1 ; logI.logs=id ; logN.logs=aa ; logF.logs=aa ; end
  end i ; call seek(f1,0,"b") ; call writech(f1,id) ; call close(f1)
  se "[23;5Hc6Creating cdLog Associationsc6...cb[K"
  do i=1 to logs ; asoc.i=logN.i
    do j=i+1 to logs ; se TWIRL()
      if logF.i=logF.j then asoc.i=asoc.i" "logN.j ; end j ; end i
  se "[23;5Hc6Saving cf"comP"VL_Data c6files...ce"
  call open(f1,comP"VL_Data","w") ; uac=PARSE(uacc,0,31)
    do i=1 to logs ; se TWIRL()
      log.i=left(logI.i,4)left(logN.i,15)left(logF.i,15)left(uacc,15)
      log.i=log.i||left(uac,90)left(trim,2)left(trln,3)
      log.i=log.i||left(logH,2)left(hisT,4)left("0",2)asoc.i
      call writeln(f1,log.i)
    end i ; call close(f1)
  address command "sort "comP"VL_Data "comP"VL_Data COLSTART 5"
  se "[23;5Hc6Reloading c9data filesc6...[K"
 return

CHECK:;if result~="###PANIC" then return result
  a="Lost Carrier!";tr "[23;1Hc9"a;logentry a;bufferflush;exit

SYNTAX:;ERROR:;IOERR:;e1=' Error: 'rc' ('errortext(rc)')'
  e2='  Line: 'left(sigl,4)'File:';gu 1311992;a=result;gu 1311960
  b=result;c='"'a||b'"';e2=e2' 'c;tr e1;tr e2;logentry e1;logentry e2
  e=sourceline(sigl);do while e~='';e3='Source: 'left(e,37);tr e3
  logentry e3;e=substr(e,38);end;bufferflush;exit
/**************************************************************************\
\****************************************** Frontiers BBS (716)/823-9892 **/
