/* this is the gif_text addon for  SRE-http installation program */ 

/* Load up advanced REXX functions */
call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
call SysLoadFuncs

crlf='0d0a'x
copyall=0

foo=rxfuncquery('UZLoadFuncs')   /* load UNZIP dll */
if foo=1 then do
  call RxFuncAdd 'UZLoadFuncs', 'UNZIPAPI', 'UZLoadFuncs'
  call UZLoadFuncs
end
zipfoo=rxfuncquery('UZLoadFuncs')   /* load UNZIP dll */
if zipfoo=1  then do
  say " UNZIPAPI.DLL not found. You'll have to do some UnZIPing by hand."
end

/*---   Load REXX libraries ----- */
/* Load up advanced REXX functions */
foo=rxfuncquery('sysloadfuncs')
if foo=1 then do
  call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  call SysLoadFuncs
end
foo=rxfuncquery('rexxlibregister')
if foo=1 then do
 call rxfuncadd 'rexxlibregister','rexxlib', 'rexxlibregister'
 call rexxlibregister
end
foo=rxfuncquery('rexxlibregister')
if foo=1 then do
   say "Caution: could not find REXXLIB (is it in your LIBPATH?) "
   say "(hit ENTER to continue)"
   pull ff
end /* do */


ansion=checkansi()
if ansion=1 then do
  aesc='1B'x
  cy_ye=aesc||'[37;46;m'
  normal=aesc||'[0;m'
  bold=aesc||'[1;m'
  re_wh=aesc||'[31;47;m'
  reverse=aesc||'[7;m'
end
else do
  say " Warning: Could not detect ANSI....  Install will look ugly ! "
  parse pull .
  cy_ye="" ; normal="" ; bold="" ;re_wh="" ;
  reverse=""
end  /* Do */

cls
say  " " ; say

call lineout, bold cy_ye
call lineout, "This is the GIF_TEXT (ver 1.3c) installation program (9/99).   "
call lineout, "      (for the SRE-http web server) "
call lineout, normal
call lineout,"      If you are installing GIF_TEXT as a CGI-BIN script, or as a  "
call lineout,'      stand-alone program, please see the "by hand" installation'
call lineout,'      instructions in GIF_TEXT.DOC.'
say "" 
say " This program will ask for the names of a few directories,"
say " and will copy a number of files to these directories."
say "  "

if yesno(" Are you ready to continue ")=1 then
 nop
else do
 say " See you later?.. "
 exit
end


nowdir=directory()

godir=filespec('d',nowdir)||'\GOSERVE'
webdir=filespec('d',godir)||'\WWW'


gunky2:
say " "
call charout,  bold " Enter the GoServe working directory (that contains SREFILTR.80)" normal crlf
call charout,"  ENTER= " godir  " ? "
parse pull work_dir
if work_dir="" then work_Dir=godir
work_dir=strip(work_dir,'t','\')
foo=ais_dir(work_dir)
if foo=0 then do
    say " Could not find directory: " work_dir
    signal gunky2
end
foo=work_dir||'\SREFILTR.80'
if stream(foo,'c','query exists')=' ' then do
   say " Could not find SREFILTR.80.  Please reenter "
   signal gunky2
end  /* Do */


addondir=work_dir||'\ADDON'
gunky2a:
say " "
call charout,  bold " Enter the SRE-http " normal reverse " addon " normal bold " directory " normal crlf
call charout,"  ENTER= " addondir  " ? "
parse pull addon_dir
if addon_dir="" then addon_Dir=addondir
addon_dir=strip(addon_dir,'t','\')
foo=ais_dir(addon_dir)
if foo=0 then do
    say " Could not find directory: " addon_dir
    signal gunky2a
end

gunky3:
say " "
call charout,  bold " Enter a WWW accessible directory (for the GIF_Text HTML documents)" normal crlf
call charout,"  ENTER= " webdir  " ? "
parse pull web_dir
if web_dir="" then web_Dir=webdir
web_dir=strip(web_dir,'t','\')
foo=ais_dir(web_dir)
if foo=0 then do
    say " Could not find directory: " web_dir
    signal gunky3
end



imgdir=web_dir'\IMGS'
gunky3a:
say " "
call charout,  bold " Enter the /IMGS directory or your WWW server (for sample .GIF files)" normal crlf
call charout,"  ENTER= " imgdir  " ? "
parse pull img_dir
if img_dir="" then img_Dir=imgdir
img_dir=strip(img_dir,'t','\')
foo=ais_dir(img_dir)
if foo=0 then do
    say " Could not find directory: " img_dir
    signal gunky3a
end

custdir=work_dir||'\ALPHABYT'
gunky4:
say " "
call charout,  bold " Enter the ALPHABYT directory (for storing fonts)" normal crlf
call charout,"  ENTER= " custdir  " ? "
parse pull custom_dir
if custom_dir="" then custom_Dir=custdir
custom_dir=strip(custom_dir,'t','\')
foo=ais_dir(custom_dir)
if foo=0 then do
    say " Creating " custom_dir
    '@MKDIR 'custom_dir
    if result <> 0 then do
      say " Could not create " custom_dir
       signal gunky4
    end
end
say " "


db=dosbootdrive()
ttfdir=db||":\os2\mdos\winos2\system"
gunky4a:
say " "
call charout,  bold " Enter the TTF directory (where TTF fonts are kept)" normal crlf
call charout,"  ENTER= " ttfdir  " ? "
parse pull ttf_dir
if ttf_dir="" then ttf_Dir=ttfdir
ttf_dir=strip(ttf_dir,'t','\')
foo=ais_dir(ttf_dir)
if foo=0 then do
    say " Creating " ttf_dir
    '@MKDIR 'ttf_dir
    if result <> 0 then do
       say " Could not create " ttf_dir
       signal gunky4a
    end
end
else do
   foo=sysfiletree(ttf_dir'\*.ttf',gaa,'FOS')
   in1=gaa.0
   foo=sysfiletree(ttf_dir'\*.ttf',gaa,'FO')
   in0=gaa.0

   say " ... a total of "in0" ("in1") TTF font files were found in (in & and under) "
   say "     "ttf_dir
   if in0=0 then do
        if yesno(normal"   "reverse"Are you sure you want to use this TTF font directory?")=0 then signal gunky4a
   end /* do */
end /* do */
say " "



if yesno(" Are you ready to copy the files ")=0 then do
   say " Okay, you can try again later "
   exit
end  /* Do */
    
say " "


say "Modifying MKGIFTXT and GIF_TEXT "

/* ---- modify GIF_TEXT.CMD */
ain=charin('GIF_TEXT.CMD',1,chars('GIF_TEXT.CMD'))
foo=stream('GIF_TEXT.CMD','c','close')

aa="GIF_DIR_ROOT='\goserve\alphabyt'"
parse var ain a1 (aa) a2
boo=a1||'0d0a'x||"GIF_DIR_ROOT='"||custom_dir||"' "||'0d0a'x||a2

aa="TTF_DIR_ROOT='\ttf'"
parse var boo a1 (aa) a2
boo=a1||'0d0a'x||"TTF_DIR_ROOT='"||ttf_dir||"' "||'0d0a'x||a2


foo=sysfiledelete('GIF_TEXT.$$$')
foo=charout('GIF_TEXT.$$$',boo,1)
if foo>0 then do
    say " ERROR: could not write temporary file (GIF_TEXT.$$$)"
    exit
end
foo=stream('GIF_TEXT.$$$','c','close')


/* --- modify MKGIFTEXT.CMD */
ain=charin('MKGIFTXT.CMD',1,chars('MKGIFTXT.CMD'))
foo=stream('MKGIFTXT.CMD','c','close')

aa="STYLES_DIR='\goserve\alphabyt'" 
parse var ain a1 (aa) a2
boo=a1||'0d0a'x||"STYLES_DIR='"||custom_dir||"' "||'0d0a'x||a2

aa="GIF_DIR_ROOT='\goserve\alphabyt'" 
parse var boo a1 (aa) a2
boo=a1||'0d0a'x||"GIF_DIR_ROOT='"||custom_dir||"' "||'0d0a'x||a2

aa="TTF_DIR_ROOT='\ttf'" 
parse var boo a1 (aa) a2
boo=a1||'0d0a'x||"TTF_DIR_ROOT='"||ttf_dir||"' "||'0d0a'x||a2

foo=sysfiledelete('MKGIFTXT.$$$')
foo=charout('MKGIFTXT.$$$',boo,1)
if foo>0 then do
    say " ERROR: could not write temporary file (MKGIFTXT.$$$)"
    exit
end
foo=stream('MKGIFTXT.$$$','c','close')

say ' Copying  .CMD and other stuff to ' addon_dir

foo=check_copy('GIF_TEXT.$$$',addon_dir'\GIF_TEXT.CMD',1)
aa=sysfiledelete('GIF_TEXT.$$$')

foo=check_copy('MKGIFTXT.$$$',addon_dir'\MKGIFTXT.CMD',1)
aa=sysfiledelete('MKGIFTXT.$$$')
say "Copying RXGDUTIL.DLL to " work_dir
foo=check_copy('RXGDUTIL.DLL',work_dir)
say "Copying RXTTF.DLL to " work_dir
foo=check_copy('RXTTF.DLL',work_dir)


say "Copying the AlphaByte (font) .ZIP file to " custom_dir
foo=check_copy('ALPHABYT.ZIP',custom_dir)
if zipfoo=1 then do
  say " Please CD to " custom_dir " and UNZIP ALPHABYT "
end
else do
   if yesno(' Unzip ALPHABYT.ZIP? ')=1 then do
     say " Unzipping .GIF files to subdirectories under  " custom_dir
     foo=uzunzip(' -o -qq -d'||custom_dir||' '||custom_dir||'\ALPHABYT ')
   end
end  /* Do */


say "Copying  MKGIFTXT.HTM and MKBUTTON.HTM sample documents to "web_dir

foo=check_copy('MKGIFTXT.SRE',web_dir'\MKGIFTXT.HTM',1) 

/*foo=check_copy('MKGIFTXH.$$$',web_dir'\MKGIFTXT.HTM',1)
aa=sysfiledelete('MKGIFTXH.$$$') */

foo=check_copy('MKBUTTON.SRE',web_dir'\MKBUTTON.HTM')

foo=check_copy('GIF_TEXT.DOC',web_dir)
foo=check_copy('MKGIFRM.HTM',web_dir)
foo=check_copy('MKGIFTOC.HTM',web_dir)
foo=check_copy('MKGIFTX2.HTM',web_dir)
foo=check_copy('MKGIFTX3.HTM',web_dir)

foo=check_copy('ALLBUT1.GIF',img_dir)

foo=check_copy('SAMPGIF.ZIP',img_dir)
if zipfoo=1  then do
  say " Please CD to " img_dir " and UNZIP SAMPGIF "
end
else do
   say " Unzipping .GIF files to subdirectories under  " img_dir
   foo=uzunzip(' -o -q -d'||img_dir||' '||img_dir||'\SAMPGIF ')
end  /* Do */



say " "
say reverse " ------------------------------------------------- "normal
say bold " The GIF_TEXT files and directories have been created. " normal
say " "
say " For some further hints, see the GIF_TEXT.DOC file. "
say" "
if stream('GIF_TEXT.DOC','c','query exists')<>'' then do
     ii=yesno(normal"      "bold"Would you like to view GIF_TEXT.DOC ?"normal,,'N')
     if ii=1 then '@START  "The GIF_text Manual" /C /F /WIN E GIF_TEXT.DOC'
end


exit

/* ------------------------------------------------------------------ */
 /* function: Check if ANSI is activated                               */
 /*                                                                    */
 /* call:     CheckAnsi                                                */
 /*                                                                    */
 /* where:    -                                                        */
 /*                                                                    */
 /* returns:  1 - ANSI support detected                                */
 /*           0 - no ANSI support available                            */
 /*          -1 - error detecting ansi                                 */
 /*                                                                    */
 /* note:     Tested with the German and the US version of OS/2 3.0    */
 /*                                                                    */
 /*                                                                    */
 CheckAnsi: PROCEDURE
   thisRC = -1
 
   trace off
                         /* install a local error handler              */
   SIGNAL ON ERROR Name InitAnsiEnd
 
   "@ANSI 2>NUL | rxqueue 2>NUL"
 
   thisRC = 0
 
   do while queued() <> 0
     queueLine = lineIN( "QUEUE:" )
     if pos( " on.", queueLine ) <> 0 | ,                       /* USA */
        pos( " (ON).", queueLine ) <> 0 then                    /* GER */
       thisRC = 1
   end /* do while queued() <> 0 */
 
 InitAnsiEnd:
 signal off error
 RETURN thisRC


/* -------------------- */
/* get a yes or no , return 1 if yes */
yesno:procedure expose normal reverse bold
parse arg fooa , allopt,altans
if altans<>" " & words(altans)>1 then do
   w1=strip(word(altans,1))
   w2=strip(word(altans,2))
   a1=left(w1,1) ; a2=left(w2,1)
   a1a=substr(w1,2) ; a2a=substr(w2,2)
end
else do
    a1='Y' ; a1a='es'
    a2='N' ; a2a='o'
end  /* Do */
ayn='  '||bold||a1||normal||a1a||'\'||bold||a2||normal||a2a
if allopt=1 then  ayn=ayn||'\'||bold||'A'||normal||'ll'

do forever
 foo1=normal||reverse||fooa||normal||ayn
 call charout,  foo1 normal ':'
 pull anans
 if abbrev(anans,a1)=1 then return 1
 if abbrev(anans,a2)=1 then return 0
 if allopt=1 & abbrev(anans,'A')=1 then return 2
end


/* ------------- */
/* ----------------------------------------------------------------------- */
/* REPLACESTRG: In string astring, find first occurence substring target and
.   replace it with substring putme
.      if no target, return unchanged astring
.      if no putme, then remove target
.      if type=backward, then find/change LAST occurence
.      if type=all, find/change all occurences
.      if exactmatch=yes, then do not capitalize during search (exact match only */
/* ----------------------------------------------------------------------- */

replacestrg: procedure

exactmatch=0
backward=0 ; doall=0

parse arg astring ,  target   , putme , type , exactmatch

type = translate(type)
if type="BACKWARD" then backward="YES"
if type="ALL" then doall="YES"

iat=1
joelen=length(target)
joelen2=length(putme)

doagain:                /* here if doall=yes */
 if exactmatch="YES" then do
    if   backward="YES" then
        joe= lastpos(target,astring)
    else
        joe= pos(target,astring,iat)
 end
 else do
   if   backward="YES" then
        joe= lastpos(translate(target),translate(astring))
    else
        joe= pos(translate(target),translate(astring),iat)
 end
 if joe=0 then
         return astring

 astring=delstr(astring,joe,joelen)
 if putme<>' ' then
    astring=insert(putme,astring,joe-1)

 if doall="YES" then do
     iat=joe+joelen2
     signal doagain
 end
/* else, all done */
 return astring

/*******************************************/
/* check for existence of file, then ask user to copy or not */
/* note that for X.* type copies, it only checks once
   (not for each file, but just for any one of them */
/********************************************/
check_copy: procedure expose copyall reverse bold normal
parse arg file1, dest1 , asis
amess=''

if asis="" then do
  dest2=strip(dest1,'t','\')||'\'
  filename=dest2||file1
end
else do
  filename=dest1
end /* do */

if copyall=1 then signal doit3

aa=sysfiletree(filename,isit,'F')

ok=1
if aa<>0 then do
   say " Warning: error when looking for pre-existing copy of: " filename
   ok=yesno(" Do you want to copy this file (or files) anyways? ")
   if ok=1 & amess<>""  then
      ok=yesno(amess)
end

if isit.0>0 then do
  if pos('*',file1)=0 then do
      say " "
      say " A file exists with the name: " filename
      ok=yesno(" Do you want to overwrite this file? ",1)
       say ' '
      if ok=1 & amess<>""  then
           ok=yesno(amess)
  end
  else do
    say " "
      say " There is at least one file that matches: " filename
      say "  (this match may " bold " not " normal " be one of the files that will be copied!) "
      ok=yesno(" Do you want to copy these files? ",1)
      say ' '
      if ok=1 & amess<>""  then
           ok=yesno(amess)
  end  /* Do */

end

if ok=2 then do
  say " "
  say "A number of files will be overwritten (not just this one) "
  copyall=yesno(" Are you sure you want to do this?")
  if copyall=0 then
      ok=yesno(" Do you want to overwrite the current file (or files)? ")
      say ' '
end

if ok=0  then return 0

doit3:          /* jump here if copyall is on, or noask=1 */
'@COPY ' file1 dest1 ' > NUL '

return 1

/* return 1 if adir is an existing (possibly empty) directory , 0 if not */
ais_dir:procedure 
parse arg adir

adir=strip(adir)
adir=strip(adir,'t','\')
nowdir=directory()
nowdrive=filespec('d',nowdir'\')
nowpath=filespec('p',nowdir'\')
adr=filespec('d',adir)
if adr='' then do
   if abbrev(adir,'\')=0 then 
       adir=nowdrive||nowpath||adir
   else
       adir=nowdrive||adir
end /* do */

foo=sysfiletree(adir,goo,'D')
if  goo.0>0  then return 1
return 0





