/* Forcetag Prefs Editor/Sysop Utility
   By: The Force                         */
Options Results; SIGNAL ON ERROR; SIGNAL ON IOERR; SIGNAL ON SYNTAX;
tr=transmit; gu=getuser; gc=getchar; ss=sendstring; q=query;
version='94.278.00'

/* Sysop Variables */
BBS='Cool World BBS'
TAGPATH='PFILES:forcetag/'
RAMPATH='RAM:t/'    /* The path to quick HD or RAM for faster taglines */
USERAM=1        /* 1=Use RAMPATH for taglines to increase SPEED, 0=DO NOT USE */
SYSOP=30        /* The minimum level to use sysop functions...(ex. 30 is 30-31) */
/* End of the sysop variables... */
gu 15; access=result;
if USERAM=1 then call LOADRAM 
call CHKPREFS     /* Check for the users PREFERENCES */
call MAINPRG           /* Call main program.... */
exit

MAINPRG:
  /* The main menu section of the CODE */
  cls
  gu 15; access=result;
  tr CENTER('c4Forcetag Prefs Editor ('version')',79)
  newline
  tr 'c3C)c5hange your current Preference..'
  tr 'c3A)c5dd a tagline to the database..'
  tr 'c3L)c5ist the tagline database..'
  if access >= SYSOP then tr 'c3*) c5SysOp Menu Functions'
  tr 'c3Q)uit to c4'BBS
  newline
  ss '                 Option--> c5'; gc;    answer=result
  if answer='###PANIC' then exit 10
  tr answer
  SELECT
    when UPPER(answer)='A' then call addtag
    when UPPER(answer)='C' then call cngprefs
    when UPPER(answer)='L' then call tagl
    when answer='*' then call sysopmenu
    when UPPER(answer)='Q' then RETURN
    OTHERWISE DO
      tr 'c3Incorrect Response....'; signal MAINPRG
    END
  END
signal MAINPRG
RETURN

LOADRAM:        /* Copy tagline file to RAM for faster use */
  if ~exists(rampath||"tags.data") then DO
    tr 'c4Please wait a few secs copying datafiles to ram..'
    address command     /* Tell arexx to pass commands to shell */
    'copy 'tagpath'tags.#? TO 'rampath      /* Copy data files to correct place */
    address
  END
RETURN        
  
CHKPREFS:     /* Check to see if the user has filled out his prefs */
  if ~exists("ftagprefs") then DO
    getuser 1
    handle=result
    tr 'c7Well, 'handle' it appears you have not filled out your preference'
    tr 'c6for taglines yet. Its a very simple process, I will give you three'
    tr 'c4different choices and you can Select the one you like the best...'
    newline
    tr 'c41)c3 NEVER add a tagline I do not like them.  You will never be prompted..'
    tr 'c42)c2 PROMPT me to see if I am in the mood for a tagline..'
    tr 'c43)c6 ALWAYS add a tagline to the message...'
    q 'c5            (1,2,3)--> c4';  answer=result;
    if answer='###PANIC' then exit 10
    SELECT
      when answer=1 then call saveprefs
      when answer=2 then call saveprefs
      when answer=3 then call saveprefs
      OTHERWISE signal chckprefs
    END
  tr 'c5Prefs saved...'
  END
  call open(prefs,"ftagprefs", "R")
  pref=readln(prefs)
  call close(prefs)
RETURN

SAVEPREFS:
  call open(prefs,"ftagprefs", "W")
  call writeln(prefs,answer)
  call close(prefs)
RETURN

ADDTAG:
  cls        /* Clear the Screen */
  tr 'c5You will have a limit of 80 characters for your tagline.'
  ss 'c612345678901234567890123456789012345678901234567890123456789012345678901234567890'
  ss 'c5---------|---------|---------|---------|---------|---------|---------|---------|'
  query '...';   tagline=result;
  if tagline='###PANIC' then exit
  if tagline='' then return
  call okay
return

OKAY:
  newline; tr 'Okay, I see that your TAGLINE looks like this, is it Correct?';
  tr '...'tagline;   ss 'Is this Okay? (Y/n) ';
  getchar;  answer=result;  tr answer;
  if answer='###PANIC' then exit
  if UPPER(answer)='N' then signal mainprg
  ctrlfile="tags.ctrl"
  tagfile="tags.data"
  if USERAM=1 then TEMPPATH=RAMPATH
              else TEMPPATH=TAGPATH
  call open(ctrl,TEMPPATH||ctrlfile,"R")
  numtags=readln(ctrl)
  newtag=numtags + 1
  call close(ctrl)
  call open(file,TEMPPATH||tagfile,"A")
  call writeln(file,tagline)
  gu 1;  author=result;
  call writeln(file,author)
  call close(file)
  call open(newctrl,TEMPPATH||ctrlfile,"W")
  call writeln(newctrl,newtag)
  call close(newctrl)
  if USERAM=1 then DO
    tr 'c7To maintain data integrity please be patient while I copy the tagline file to'
    tr 'its permenant storage on the Hard Drive...'
    address command
    'copy 'RAMPATH'tags#? TO 'TAGPATH
    address
  END
return

CNGPREFS:   /* Change your preferences for taglines */
  cls
  ss 'c4Your current preference is: c5'
  SELECT
    when pref=1 then tr 'NEVER'
    when pref=2 then tr 'PROMPT'
    when pref=3 then tr 'ALWAYS'
  END
  address command
  'delete ftagprefs'
  address
  call chkprefs
RETURN

TAGL:    /* List the taglines in the database */
  cls
  ctrlfile="tags.ctrl"
  if USERAM=1 then TEMPPATH=RAMPATH
              else TEMPPATH=TAGPATH
  call open(ctrl,TEMPPATH||ctrlfile)
  numtags=readln(ctrl)
  call close(ctrl)
  q 'c6Enter starting number (1-'numtags') or <ENTER> to quit-> c7';  start=result;
  if start='###PANIC' then exit 10
  if start='' then return
  if start > numtags then DO
    tr 'Too large of a number try again...'
    return
  END
  if datatype(start, 'N')=0 then do
    tr 'invalid character in line...'; return
  END
  q 'c6Enter ending number ('start'-'numtags') or <ENTER> for #'start' only-> c7'; stop=result;
  if start='###PANIC' then exit 10
  if start='' then start=numtags
  if datatype(start, 'N')=0 then DO
    tr 'invalid character in line...'; return
  END
  tagfile="tags.data"
  call open(tags,TEMPPATH||tagfile, "R")
  ncount=1
  if start>1 then DO count=1 TO (start-1)
    tagline=readln(tags)
    author=readln(tags)
    ncount=ncount+1
  END
  DO UNTIL ncount > stop
    tagline=readln(tags)
    author=readln(tags)
    newline
    tr 'c3Tagline #'ncount', By: c5'author
    tr 'c4...'tagline
    ncount = ncount + 1
  END
  call close(tags)
  newline; tr 'c5Thats all folks, press any key to return to the menu...'
  gc;   dummy=result;
RETURN

SYSOPMENU:      /* This is a menu with options for people with sysop access */
  if access < SYSOP then RETURN
  cls
  tr CENTER('c6SysOp Menu...',79)
  tr 'c6M)c5erge two FORCETAG tagline database..'
  tr 'c6D)c5elete a tagline from the database..'
  tr 'c6Q)c5uit to the Main Menu...'
  tr '             c4Option--> c6'
  gc;   answer=result;
  if answer='###PANIC' then exit
  SELECT
    when UPPER(answer)='M' then call merge
    when UPPER(answer)='D' then call delete
    when UPPER(answer)='Q' then  return
    OTHERWISE signal sysopmenu
  END
RETURN

MERGE:      /* Merge two forcetag */
  if USERAM=1 then TEMPPATH=RAMPATH
              else TEMPPATH=TAGPATH
  cls;
  q 'Enter path and name of tagline file to be added (Ex. df0:tags.data)n1->'
  insertfile=result
  if insertfile='###PANIC' then exit 10
  if insertfile='' then signal sysopmenu
  if exists(insertfile) then DO
    call open(insert,insertfile, "R")
    ctrlfile="tags.ctrl"
    call open(ctrl,TEMPPATH||ctrlfile,"R")
    numtags=readln(ctrl)
    call close(ctrl)
    tagfile="tags.data"
    call open(tags,TEMPPATH||tagfile, "A")
    ss 'Please be patientk1'
    DO until EOF(insert)
      tagline=readln(insert)
      author=readln(insert)
      call writeln(tags,tagline)
      call writeln(tags,author)
      ss '.'
      numtags=numtags+1
    END
    call close(tags)
    call close(insert)
    call open(ctrl,TEMPPATH||ctrlfile, "W")
    call writeln(ctrl,numtags)
    call close(ctrl)
    tr '.k0 DONE!'
    if USERAM=1 then DO
      tr 'n1c4Copying ram files back to Hard Drive, please be patient..'
      address command
      'copy 'RAMPATH'tags.#? TO 'TAGPATH
      address
    END
    RETURN
  END
  tr 'Invalid File name... Press any key to go to the sysop menu...'
  gc;   dummy=result; if dummy='###PANIC' then exit
RETURN

DELETE:     /* This function will delete a tagline from the database */
  cls
  if USERAM=1 then TEMPPATH=RAMPATH
              else TEMPPATH=TAGPATH
  gu 15; access=result
  if access < SYSOP then DO
    newline; tr'c1Insuffient Access....'
    tr 'c5 Press any key to continue...'; gc;
    RETURN
  END
  call open(ctrl,TEMPPATH||ctrlfile, "R")
  numtags=readln(ctrl)
  call close(ctrl)
  q 'Delete Which tagline (1-'numtags')-> '; tag=result
  tr 'c4Reading Tagfile into Memory... Please be patient'
  call open(tags,TEMPPATH||tagfile,"R")
  DO count=1 TO numtags
    tagline.count=readln(tags)
    author.count=readln(tags)
  END
  call close(tags)
  tr 'c1'tagline.tag
  ss 'c3Written By: c4'author.tag'c3, Delete this one (y/N) ? '
  gc; answer=result; tr 'c6'answer
  if UPPER(answer)='Y' then DO
    newline; ss 'c5Deleting tagline nowk1'
    call open(tags,TEMPPATH||tagfile,"W")
    DO count=1 to numtags
      if count=tag THEN ss 'DELETED'
         ELSE DO
           call writeln(tags,tagline.count)
           call writeln(tags,author.count)
           ss '.'
         END
    END
  call close(tags)
  ss '.'
  call open(ctrl,TEMPPATH||ctrlfile,"W")
  ss '.'
  newtags=numtags-1
  call writeln(ctrl,newtags)
  ss '.'
  call close(ctrl)
  tr 'DONE..k0'
  if USERAM=1 then DO
    tr 'n1c7Copying ram datafiles to HD for data integrity...'
    address command
    'copy 'RAMPATH'tags.#? TO 'TAGPATH
    address
  END
RETURN

SYNTAX:; IOERR:; ERROR:;
  tr 'c1o1BOOM! Result Code-> 'rc' 'errortext(rc)'n1Line Number 'sigl'...'
  bufferflush
  exit
