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

  1. /* Utility to edit the init_sta.80 file.
  2.    This is especially useful when you want to remotely
  3.    configure init_sta.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 ss=sref_error(' SRE-http Monitor: Warning: unable to register SREF_FILEREAD',1)
  22. end
  23. if rxfuncquery('sref_filewrite')<>0 then do
  24.   ik=rxfuncadd('sref_filewrite','rexxlib','LIB_FILEWRITE')
  25.   if ik<>0 then ss=sref_error(' SRE-http Monitor: Warning: unable to register SREF_FILEWRITE',1)
  26. end
  27.  
  28.  
  29.  
  30. parse upper arg aval0
  31. ii=wordpos('NOEXIT',aval0)
  32. if ii>0 then do
  33.     noexit=1
  34. end /* do */
  35.  
  36.  
  37. /* some io stuff */
  38. ansion=checkansi()
  39. if ansion=1 then do
  40.   aesc='1B'x
  41.   cy_ye=aesc||'[37;46;m'
  42.   normal=aesc||'[0;m'
  43.   bold=aesc||'[1;m'
  44.   re_wh=aesc||'[31;47;m'
  45.   reverse=aesc||'[7;m'
  46. end
  47. else do
  48.   say " Warning: Could not detect ANSI....  output will look ugly ! "
  49.   cy_ye="" ; normal="" ; bold="" ;re_wh="" ;
  50.   reverse=""
  51. end  /* Do */
  52.  
  53. cls
  54. say  " " ; say
  55.  
  56. issref=0
  57. say
  58. say cy_ye " The SRE-http program file configurator " normal
  59. say
  60. say " This is a simple editor for various SRE-http program files:"
  61. say "     including INIT_STA.80, SREFMON.CMD, and COUNTER.RXX "
  62. say "     (it's especially useful for remote (telnet) configuration ) "
  63. say " "
  64. say " "
  65. whatfile:
  66. say "What " bold "SRE-http "normal"  file should be edited?"
  67. call charout , reverse "(ENTER=cfgs\INIT_STA.80):" normal
  68.  
  69. pull dofile0
  70. if dofile0='' then do
  71.    dofile0='cfgs\INIT_STA.80'
  72.    issref=1
  73.    say " Hint:  If you are unfamiliar with what the INIT_STA.80 parameters "
  74.    say "        control, we recommend perusing INITFILT.DOC"
  75.    say
  76. end
  77. dofile=stream(dofile0,'c','query exists')
  78. if dofile=' ' then do
  79.     say " No such file: " dofile0
  80.     if pos('.RXX',translate(dofile0))>0 then
  81.        say ' Perhaps you meant ADDON\'||dofile0' ?'
  82.     signal whatfile
  83. end
  84.  
  85. foo=sref_fileread(dofile,lines,,'E')
  86. say " # lines in " dofile " = " lines.0
  87. isbegin=0 ; isend=0
  88. do mm=1 to lines.0
  89.    aline=strip(upper(lines.mm))
  90.    if abbrev(aline,'/*BEGIN')=1 then isbegin=mm
  91.     if abbrev(aline,'/*END')=1 then do
  92.         isend=mm
  93.         leave
  94.     end  /* Do */
  95. end /* do */
  96. if isbegin*isend=0 then do
  97.      say " Sorry, unable to find the /*BEGIN and /*END delimiters"
  98.      say " (EDITSREF is designed to work with SRE-http ver 1.2j and above)"
  99.      signal byebye
  100. end  /* Do */
  101. say " Parameter section between lines " isbegin " and " isend
  102.  
  103. /* now find variables and descriptions */
  104. /* assume cmt on, find cmt off */
  105. ik= isbegin+1
  106. ivar=0
  107. stuff.1.!c1=ik
  108. do until ik>isend-1
  109.    aline=strip(lines.ik)
  110.    if right(aline,2)='*/' then do
  111.       ivar=ivar+1
  112.       stuff.ivar.!c2=ik
  113.       stuff.ivar=ik+1
  114.       ivar1=ivar+1; ik=ik+2
  115.       stuff.ivar1.!c1=ik
  116.    end
  117.    ik=ik+1
  118. end /* do */
  119. say " There are " ivar " variables to set."
  120. say " "
  121. say bold " Enter values: " normal
  122. say "   ENTER -- retain current value "
  123. say "     ?   -- show a brief description "
  124. say "    !!   -- step backwards  "
  125. say "    ##   -- quit now, without making any changes  "
  126. say "   value -- replace with value (be sure to include ' around strings)"
  127. say " "
  128. say ' #)' reverse left('Variable name ',20) ' = ' normal bold 'Current Value 'normal cy_ye ' ? ' normal '(new value)'
  129. say ' ----------------------------------------------------------------------------'
  130. j1:
  131. ii=1 ;noemp=1
  132. do forever
  133.    if ii>ivar then leave
  134.  
  135.    i1=stuff.ii ; c1=stuff.ii.!c1 ; c2=stuff.ii.!c2
  136.    parse var lines.i1 vname '=' vval
  137.    vname0=left(vname,max(length(vname),24))
  138.   
  139.    call charout,left(ii,2)')' reverse vname0 ' = ' normal bold vval normal
  140.    if length(vval)>35 then do
  141.       say ; call charout,copies(' ',7+length(vname0))
  142.    end
  143.    call charout,cy_ye ' ? ' normal
  144.  
  145.    parse pull aval
  146.    if aval="" then do 
  147.         ii=ii+1
  148.         iterate
  149.    end  /* Do */
  150.    if aval="?" then do
  151.        say " " ; say " ----> " bold vname0 normal
  152.        do ll=c1 to c2
  153.           if lines.ll=' ' then iterate
  154.           gel=left(lines.ll,min(length(lines.ll),70))
  155.           say "   " cy_ye gel normal
  156.        end /* do */
  157.        iterate
  158.    end  /* Do */
  159.    if aval="!!"  then do
  160.         ii=max(ii-1,1)
  161.         iterate
  162.    end  /* Do */
  163.    if aval='##'  then do
  164.         say " Exiting without making any changes. "
  165.         call syssleep 2
  166.         signal byebye 
  167.    end /* do */
  168.    lines.i1=vname'='aval
  169. end /* do */
  170. foy1:say " "
  171. call charout, " Enter Y to save changes, N to quit, R to reenter: "
  172. pull ans
  173. if ans='R' then do
  174.     say
  175.     say bold " Current changes are retained (but not saved) ... "
  176.     signal j1
  177. end  /* Do */
  178. else
  179. if ans='N' then do
  180.     say " Changes " bold " not "normal " saved."
  181.     signal byebye
  182. end  /* Do */
  183. if ans<>'Y' then signal foy1
  184.  
  185. ip=pos('.',dofile)
  186. if ip=0 then do
  187.    bakfile=dofile||'.V??'
  188. end
  189. else do
  190.    bakfile=left(dofile,ip)||'V??'
  191. end
  192. bakfile=dostempname(bakfile)
  193. say dofile ' is being renamed as '  bakfile
  194. foo=dosrename(dofile,bakfile)
  195. if foo=0 then   say " Warning: ERROR renaming! "
  196.  
  197. nn=lines.0+1
  198. lines.nn='/* updated on '||time('n')||' '||date('n')||' */'
  199. lines.0=nn
  200.  
  201.  
  202. foo=sref_filewrite(dofile,lines)
  203. if foo=0 then do
  204.     say ' Warning: new version of ' dofile ' was NOT written '
  205. end
  206. else do
  207.   if issref=1 then do
  208.     say " Reminder: changes to the parameters contained in " dofile  
  209.     say "           will take effect only when GoServe is restarted. "
  210.   end
  211. end
  212. signal byebye
  213.  
  214.  
  215. byebye:
  216. if noexit=1  then return 1
  217. exit
  218.  
  219.  
  220.  
  221.  /* ------------------------------------------------------------------ */
  222.  /* function: Check if ANSI is activated                               */
  223.  /*                                                                    */
  224.  /* call:     CheckAnsi                                                */
  225.  /*                                                                    */
  226.  /* where:    -                                                        */
  227.  /*                                                                    */
  228.  /* returns:  1 - ANSI support detected                                */
  229.  /*           0 - no ANSI support available                            */
  230.  /*          -1 - error detecting ansi                                 */
  231.  /*                                                                    */
  232.  /* note:     Tested with the German and the US version of OS/2 3.0    */
  233.  /*                                                                    */
  234.  /*                                                                    */
  235.  CheckAnsi: PROCEDURE
  236.    thisRC = -1
  237.  
  238.    trace off
  239.                          /* install a local error handler              */
  240.    SIGNAL ON ERROR Name InitAnsiEnd
  241.  
  242.    "@ANSI 2>NUL | rxqueue 2>NUL"
  243.  
  244.    thisRC = 0
  245.  
  246.    do while queued() <> 0
  247.      queueLine = lineIN( "QUEUE:" )
  248.      if pos( " on.", queueLine ) <> 0 | ,                       /* USA */
  249.         pos( " (ON).", queueLine ) <> 0 then                    /* GER */
  250.        thisRC = 1
  251.    end /* do while queued() <> 0 */
  252.  
  253.  InitAnsiEnd:
  254.  signal off error
  255.  RETURN thisRC
  256.  
  257.  
  258.  
  259.  
  260.