home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 35 Internet / 35-Internet.zip / srev13g.zip / EDITINIT.CMD < prev    next >
OS/2 REXX Batch file  |  1999-03-19  |  9KB  |  321 lines

  1. /* Utility to edit the srefiltr.80 file.
  2.    This is especially useful when you want to remotely
  3.    configure SREFILTR.80, as by a TELNET session */
  4.  
  5. /*--------------   Load REXX libraries ----- */
  6. /* Load up advanced REXX functions */
  7. foo=rxfuncquery('sysloadfuncs')
  8. if foo=1 then do
  9.   call RxFuncAdd 'SysLoadFuncs', 'RexxUtil', 'SysLoadFuncs'
  10.  
  11.   call SysLoadFuncs
  12. end
  13. foo=rxfuncquery('rexxlibregister')
  14. if foo=1 then do
  15.  call rxfuncadd 'rexxlibregister','rexxlib', 'rexxlibregister'
  16.  call rexxlibregister
  17. end
  18.  
  19. if rxfuncquery('sref_fileread')<>0 then do
  20.   ik=rxfuncadd('sref_fileread','rexxlib','LIB_FILEREAD')
  21.   if ik<>0 then call pmprintf_sref(' SRE-http Monitor: Warning: unable to register SREF_FILEREAD')
  22. end
  23. if rxfuncquery('sref_filewrite')<>0 then do
  24.   ik=rxfuncadd('sref_filewrite','rexxlib','LIB_FILEWRITE')
  25.   if ik<>0 then call pmprintf_sref(' SRE-http Monitor: Warning: unable to register SREF_FILEWRITE')
  26. end
  27.  
  28. /* some io stuff */
  29. ansion=checkansi()
  30. if ansion=1 then do
  31.   aesc='1B'x
  32.   cy_ye=aesc||'[37;46;m'
  33.   normal=aesc||'[0;m'
  34.   bold=aesc||'[1;m'
  35.   re_wh=aesc||'[31;47;m'
  36.   reverse=aesc||'[7;m'
  37. end
  38. else do
  39.   say " Warning: Could not detect ANSI....  output will look ugly ! "
  40.   cy_ye="" ; normal="" ; bold="" ;re_wh="" ;
  41.   reverse=""
  42. end  /* Do */
  43.  
  44. parse upper arg aval0
  45. ii=wordpos('NOEXIT',aval0)
  46. if ii>0 then do
  47.     noexit=1
  48.      aval0=delword(aval0,ii,1)
  49. end /* do */
  50. parse var aval0 davar daval
  51. davar=upper(davar)
  52. dofile0bk=''
  53.  
  54. if davar="" then do
  55.   
  56.    cls
  57.    say  " " ; say
  58.  
  59.    issref=0
  60.    say
  61.    say cy_ye " The SRE-http INITFILT editor " normal
  62.    say
  63.    say " This is a simple editor for the SRE-http INITFILT parameters file."
  64.    say " It's meant for quick and dirty use by those familiar with SRE-http."
  65.    say "     (it's especially useful for remote (telnet) configuration ) "
  66.    say " New users will probably want to use the www accessible configurator."
  67.    say " "
  68.  
  69. whatfile:
  70.    say "What " bold "  INITFILT file " normal"  file should be edited?"
  71.    call charout , reverse "(ENTER=CFGS\INITFILT.80):" normal
  72.  
  73.    pull dofile0
  74.    if dofile0='' then do
  75.       dofile0='CFGS\initfilt.80'
  76.       dofile0bk='CFGS\OLDCFGS\INIFILT.V??'
  77.       issref=1
  78.       say " Hint:  If you are unfamiliar with what these parameters do, "
  79.       say "        we recommend perusing INITFILT.DOC"
  80.       say
  81.    end
  82.    dofile=stream(dofile0,'c','query exists')
  83.    if dofile=' ' then do
  84.       say " No such file: " dofile
  85.       signal whatfile
  86.   end
  87. end
  88. else do
  89.   dofile='CFGS\INITFILT.80'
  90. end
  91. foo=sref_fileread(dofile,lines,,'E')
  92.  
  93. if lines.0=0 then do
  94.    say " Could not read " dofile
  95.    signal byebye
  96. end
  97.  
  98.  say " # lines in " dofile " = " lines.0
  99.  
  100.  
  101. ivars=0
  102. do ii=1 to lines.0
  103.    lines.ii.!change=0
  104.    lines.ii.!var=''
  105.    if abbrev(strip(lines.ii),';')=1 then iterate
  106.    ivars=ivars+1
  107.    parse var lines.ii avar '=' aval ; aval=strip(strip(aval),,"'")
  108.    lines.ii.!var=upper(strip(avar)) ; lines.ii.!val=aval
  109. end /* do */
  110. say " # of parameters=" ivars
  111.  
  112.  
  113. do forever 
  114.  
  115. if davar="" then do
  116.    say " "
  117.    say bold " Enter name of variable to change. " normal
  118.    say "     ? = List of variables "
  119.    say "     ENTER = Done (write changes ) "
  120.    say "     !QUIT = Exit (without writing changes "
  121.    call charout, bold " VarName: " normal 
  122.    parse upper pull lookvar ; lookvar=strip(lookvar)
  123. end
  124. else do
  125.   lookvar=davar
  126. end /* do */
  127.  
  128. if lookvar="" then leave
  129.  
  130. igot=0
  131. if translate(lookvar)="!QUIT" then do
  132.    say " Exiting without saving changes."
  133.    call syssleep 1
  134.    signal byebye 
  135. end /* do */
  136.  
  137. if lookvar="?" then do
  138.    Say bold " List of parameters (in alphabetical order) " normal
  139.    aa=""
  140.    ils=0 ; ikk=0
  141.    do kk=1 to lines.0 
  142.       if lines.kk.!var="" then iterate
  143.       ikk=ikk+1
  144.       hoo.ikk=lines.kk.!var
  145.    end
  146.    hoo.0=ikk
  147.    foo=arraysort(hoo)
  148.    do mm=1 to hoo.0
  149.       if length(hoo.mm)<19 then
  150.          aa=aa' 'left(hoo.mm,18)
  151.       else
  152.          aa=aa' 'left(hoo.mm,36)
  153.       if length(aa)>70 then do
  154.          say aa
  155.          aa=""
  156.          ils=ils+1
  157.          if ils>10 then do 
  158.               call charout, reverse " hit ENTER to continue, X to stop variable listing " normal
  159.               fii=inkey('w')
  160.               say
  161.               if upper(fii)='X' then leave
  162.               ils=0
  163.          end /* do */
  164.      end /* do */
  165.    end /* do */
  166.    if davar<>"" then do
  167.       say
  168.       say " Enter EDITINIT by itself for prompted actions. "
  169.       say " Or, you can enter:" bold" EDITINIT varname  " normal" :  display current value of  varname "
  170.       say "                   " bold" EDITINIT varname newvalue "normal " : set varname=newvalue "
  171.       signal byebye
  172.   end
  173.   iterate
  174.  
  175. end /* do */
  176.  
  177. do mm=1 to lines.0
  178.    if lines.mm.!var<>lookvar then iterate
  179.    igot=mm
  180. end /* do */
  181.  
  182. if igot=0 then do
  183.     say " No such parameter: " lookvar
  184.     if davar<>"" then signal byebye
  185.     iterate        
  186. end /* do */
  187.  
  188. if davar<>"" & daval="" then do
  189.   say  bold lookvar '=' normal lines.igot.!val 
  190.   signal byebye
  191. end
  192.  
  193. if daval="" then do
  194.   call charout,bold lookvar '='normal lines.igot.!val'  '
  195.   if length(lines.igot.!val)>40 then  do
  196.     say " " ; call charout,'      '
  197.   end
  198.   call charout, cy_ye'?'normal
  199.   parse pull newval
  200. end
  201. else do
  202.    newval=daval
  203. end
  204.  
  205. newval=strip(newval,,"'")
  206. tmp=""
  207. do until newval=""
  208.     parse var newval a1 "'" newval
  209.    if newval<>"" then tmp=tmp||a1||"''"
  210. end /* do */
  211. tmp=tmp||a1
  212. newval=tmp
  213.  
  214. if newval<>"" then lines.igot.!val=newval
  215. if daval<>"" then leave
  216.  
  217. end
  218.  
  219. foy1:say " "
  220. if daval<>"" then do
  221.    ans='Y'
  222. end /* do */
  223. else do
  224.   call charout, " Enter Y to save changes, N to quit: "
  225.   pull ans
  226. end
  227. if ans='N' then do
  228.     say " Changes " bold " not "normal " saved."
  229.     signal byebye
  230. end  /* Do */
  231. if ans<>'Y' then signal foy1
  232.  
  233. ip=pos('.',dofile)
  234. if ip=0 then do
  235.    bakfile=dofile||'.V??'
  236. end
  237. else do
  238.    bakfile=left(dofile,ip)||'V??'
  239. end
  240.  
  241. if dofile0bk<>'' then bakfile=dofile0bk /* special case */
  242.  
  243. bakfile=dostempname(bakfile)
  244. say ' Old version of ' dofile 
  245. say '     is being renamed as '  bakfile
  246. foo=dosrename(dofile,bakfile)
  247. if foo=0 then   say " Warning: ERROR renaming! "
  248.   
  249.  
  250. nl.0=lines.0
  251. do mm=1 to lines.0
  252.    if lines.mm.!var="" then do
  253.       nl.mm=lines.mm
  254.    end
  255.    else do
  256.       nl.mm=lines.mm.!var||"='"||lines.mm.!val||"'"
  257.    end /* do */
  258. end /* do */
  259.  
  260.  
  261. nnn1=nl.0+1
  262. nl.nnn1='; Updated on '||time('n')||' '||date('n')
  263. nl.0=nnn1
  264.  
  265. foo=sref_filewrite(dofile,nl)
  266. if foo=0 then do
  267.     say ' Warning: new version of ' dofile ' was NOT written '
  268. end
  269. else do
  270.   if issref=1 then do
  271.     say " Reminder: changes to the parameters contained in " dofile  
  272.     say "           will take effect within a few minutes. "
  273.   end
  274. end
  275. signal byebye
  276.  
  277.  
  278. byebye:
  279. if noexit=1  then return 1
  280. exit
  281.  
  282.  /* ------------------------------------------------------------------ */
  283.  /* function: Check if ANSI is activated                               */
  284.  /*                                                                    */
  285.  /* call:     CheckAnsi                                                */
  286.  /*                                                                    */
  287.  /* where:    -                                                        */
  288.  /*                                                                    */
  289.  /* returns:  1 - ANSI support detected                                */
  290.  /*           0 - no ANSI support available                            */
  291.  /*          -1 - error detecting ansi                                 */
  292.  /*                                                                    */
  293.  /* note:     Tested with the German and the US version of OS/2 3.0    */
  294.  /*                                                                    */
  295.  /*                                                                    */
  296.  CheckAnsi: PROCEDURE
  297.    thisRC = -1
  298.  
  299.    trace off
  300.                          /* install a local error handler              */
  301.    SIGNAL ON ERROR Name InitAnsiEnd
  302.  
  303.    "@ANSI 2>NUL | rxqueue 2>NUL"
  304.  
  305.    thisRC = 0
  306.  
  307.    do while queued() <> 0
  308.      queueLine = lineIN( "QUEUE:" )
  309.      if pos( " on.", queueLine ) <> 0 | ,                       /* USA */
  310.         pos( " (ON).", queueLine ) <> 0 then                    /* GER */
  311.        thisRC = 1
  312.    end /* do while queued() <> 0 */
  313.  
  314.  InitAnsiEnd:
  315.  signal off error
  316.  RETURN thisRC
  317.  
  318.  
  319.  
  320.  
  321.