/* Script to edit one of the srehttp/2.cfg files */
parse upper arg whichone


/* enable ansi screen controls */
aesc='1B'x
cy_ye=aesc||'[37;46;m'
cyanon=cy_ye
normal=aesc||'[0;m'
bold=aesc||'[1;m'
re_wh=aesc||'[31;47;m'
reverse=aesc||'[7;m'

thehost='DEFAULT'
parse source . . cmdfile
oo=filespec('d',cmdfile)||filespec('p',cmdfile)
iaa0=lastpos('\',oo)
iaa=lastpos('\',oo,iaa0-1)

sredir=substr(oo,iaa+1)

thefiles.!attribs='SREHTTP2\CFG\ATTRIBS.CFG'
thefiles.!CONFIGS='SREHTTP2\CFG\SREHTTP2.CFG'
thefiles.!REPLACEMENTS="SREHTTP2\CFG\SSI_VARS.CFG"
thefiles.!MIMETYPE="SREHTTP2\CFG\MIMETYPE.CFG"
thefiles.!USERS='SREHTTP2\CFG\USERS.CFG'

thefiles.!LOGS="SREHTTP2\CFG\LOGS.CFG"
thefiles.!HOSTDATA="SREHTTP2\CFG\HOSTDATA.CFG"
thefiles.!ADDONS="SREHTTP2\CFG\PRELOADS.CFG"

thefiles0.!LOGS="SREHTTP2\CFG\LOGS.CFG"
thefiles0.!HOSTDATA="SREHTTP2\CFG\HOSTDATA.CFG"
thefiles0.!ADDONS="SREHTTP2\CFG\PRELOADS.CFG"

thefiles0.!attribs=OO'SREHTTP2\CFG\ATTRIBS.CFG'
thefiles0.!CONFIGS=OO'SREHTTP2\CFG\SREHTTP2.CFG'
thefiles0.!REPLACEMENTS=OO"SREHTTP2\CFG\SSI_VARS.CFG"
thefiles0.!MIMETYPE=OO"SREHTTP2\CFG\MIMETYPE.CFG"
thefiles0.!USERS=OO'SREHTTP2\CFG\USERS.CFG'



newhost:

whichone=strip(whichone)
select
  when whichone='C' then goo='C'
  when whichone='U' then goo='U'
  when whichone<>'' then goo=strip(translate(whichone))
  otherwise do
    say "Which srehttp/2 configuration file would you like to edit... "
    say "   "bold"H"normal": Host data                      ("thefiles.!HOSTDATA
    say "   "bold"P"normal": Load-addons, etc.              ("thefiles.!ADDONs
    say "   "bold"L"normal": Logs                           ("thefiles.!LOGS

    say " " reverse"host specific files: "normal
    say "   "bold"N"normal": Host-specific CFG directory    (current: "bold||thehost||normal
    say "   "bold"A"normal": Attributes                     ("thefiles.!ATTRIBS
    say "   "bold"C"normal": Configuration parameters       ("thefiles.!CONFIGS
    say "   "bold"S"normal": SSI Var Replacements           ("thefiles.!REPLACEMENTS
    say "   "bold"M"normal": Mimetype                       ("thefiles.!MIMETYPE

    say "   "bold"U"normal": Usernames/passwords/privileges ("thefiles.!USERS

    say "   "bold"X"normal": Exit  "

    call charout,'Which one 'bold'H'normal', 'bold'P'normal', 'bold'N'normal', 'bold'A'normal', 'bold'C'normal', 'bold'R'normal', 'bold'U'normal', 'bold'X'normal']? '
   pull goo
   goo=strip(goo)
  end
end
if goo='X' then do
    say "  Note: the on-line configurator is: /sre2k/srehttp2/config.htm "
   exit
end
if goo='N' then do

   checkd=OO"SREHTTP2\CFG\*.*"
   foo=sysfiletree(checkd,'goo.','DO')
   dlist=''
   do jj=1 to goo.0
       iaa=lastpos('\',goo.jj)
       ahost=translate(substr(goo.jj,iaa+1))
       dlist=dlist' 'ahost
   end

   do forever
     call charout, bold"Subdirectory containing host CFG files? "normal
     pull hostnick
     hostnick=strip(hostnick)
     if hostnick='' then exit
     if wordpos(hostnick,dlist)=0 then do
            if hostnick<>'?' then say "No such subirectory."
            say "Valid directories: "
            call show_list dlist
            iterate
     end
     leave
    end
                   

   thefiles.!attribs='SREHTTP2\CFG\'hostnick'\ATTRIBS.CFG'
   thefiles.!CONFIGS='SREHTTP2\CFG\'hostnick'\SREHTTP2.CFG'
   thefiles.!REPLACEMENTS='SREHTTP2\CFG\'hostnick'\SSI_VARS.CFG'
   thefiles.!MIMETYPE='SREHTTP2\CFG\'hostnick'\MIMETYPE.CFG'
   thefiles.!USERS='SREHTTP2\CFG\'hostnick'\USERS.CFG'

   thefiles0.!attribs=OO'SREHTTP2\CFG\'hostnick'\ATTRIBS.CFG'
   thefiles0.!CONFIGS=OO'SREHTTP2\CFG\'hostnick'\SREHTTP2.CFG'
   thefiles0.!REPLACEMENTS=OO'SREHTTP2\CFG\'hostnick'\SSI_VARS.CFG'
   thefiles0.!MIMETYPE=OO'SREHTTP2\CFG\'hostnick'\MIMETYPE.CFG'
   thefiles0.!USERS=OO'SREHTTP2\CFG\'hostnick'\USERS.CFG'

   thehost=hostnick
   signal newhost
end


say
SAY "For the " bold||thehost||normal" host..."
if goo='C' | goo=' ' then do
   say "Editing SREHTTP2.CFGs -- the default srehttp/2 configuration parameters file "
  'EPM 'THEFILES0.!CONFIGS
end
if goo='U' then do
  say 'Editing USERS.CFGs-- the default srehttp/2 username/password/privileges file '
  'EPM 'THEFILES0.!users
end
if goo='P' then do
  say 'Editing PRELOADS.CFG -- the srehttp/2 load-addon definitions '
  'EPM 'thefiles0.!Addons
end
if goo='S' then do
  say 'Editing SSI_VARS.CFGs -- the srehttp/2 SSI variable  definitions '
  'EPM 'thefiles0.!REPLACEMENTS
end
if goo='M' then do
  say 'Editing MIMETYPE.CFGs -- the srehttp/2 extension-to-mimetype mappings '
  'EPM 'thefiles0.!MIMETYPE
end
if goo='L' then do
  say 'Editing LOGS.CFG -- the srehttp/2 log-file parameter file      '
  'EPM 'thefiles.!LOGS
end


if goo='A' then do
  say 'Editing ATTRIBS.CFGs -- the srehttp/2 selector-specific attributes'
  'EPM 'thefiles0.!ATTRIBS
end

if goo='H' then do
  say 'Editing HOSTDATA.CFG -- the srehttp/2 hosta data definitions '
  'EPM 'thefiles0.!HOSTDATA
end


exit

show_list:
parse arg alist
oof=''

do kjj=1 to words(alist)
    aword=strip(word(alist,kjj))
    i10=((length(aword)-0.01)%10)+1
    addme='  '||left(aword,i10*10,' ')
    if length(oof)+length(addme)+1>80 then do
      say oof
      oof=addme
    end 
    else do
      oof=oof||addme
    end 
end
if oof<>'' then say oof
return 1
