home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 3 Comm / 03-Comm.zip / ijpb014.zip / Config.CMD < prev    next >
OS/2 REXX Batch file  |  1998-06-17  |  6KB  |  202 lines

  1. /*  Config.CMD
  2.  *  ----------
  3.  *  Copyright (c) Cornelis Bockemuehl, 1998
  4.  *
  5.  *  Configure InjoyPB
  6.  */
  7.  
  8. '@echo off'
  9.  
  10. if RxFuncQuery("SysLoadFuncs") then do
  11.    call RxFuncAdd "SysLoadFuncs", "RexxUtil", "SysLoadFuncs"
  12.    call SysLoadFuncs
  13. end
  14. crlf=d2c(13)||d2c(10)
  15. ijpbdir=directory()
  16.  
  17. /* Introduction */
  18. rc=SysCls()
  19. say ""
  20. say "*********************************"
  21. say "Configuration of Injoy Phone Bill"
  22. say "*********************************"
  23. say ""
  24. say "This script helps you adding a new host definition or overwriting"
  25. say "an existing, but it is not a full blown configuration program."
  26. say "Specifically, it doesn't do any error checking of your input; just"
  27. say "everything is accepted!"
  28. say "However, you get some explanations about what you are supposed to"
  29. say "enter and once you are running InjoyPB it will try to check all"
  30. say "input for consistency and show you any lines it doesn't like. You"
  31. say "may then start the manual configuration (i.e., edit the injoypb.cfg"
  32. say "file with an editor) and make any changes necessary."
  33. say ""
  34. do until (aa="Y") | (aa="N")
  35.   say "Do you want to go on configuring a host definition? (y/n)"
  36.   pull aa .
  37. end
  38. if aa="N" then exit
  39.  
  40. /* Get host name from user */
  41. rc=SysCls()
  42. say ""
  43. say "Injoy can handle several 'hosts'; you find their names in the upper"
  44. say "right corner of the main Injoy window. Each one of them can have"
  45. say "different settings and each one produces an own log file with the"
  46. say "name '<hostname>.log'. These contain the connection data used by"
  47. say "InjoyPB and it can also handle different settings for every host."
  48. say "Remark: If you want to add more than one host definition, just run"
  49. say "this configuration script several times."
  50. say ""
  51. say "Press RETURN to continue"
  52. parse pull .
  53. rc=SysCls()
  54. say ""
  55. say "The following log files were found:"
  56. rc=SysFileTree("..\*.log",logf,"FO")
  57. if 0=logf.0 then
  58.   say "  (none)"
  59. else do ff=1 to logf.0
  60.   say "  "||substr(logf.ff,lastpos("\",logf.ff)+1)
  61. end
  62. say "The following hosts are already defined:"
  63. rc=SysFileSearch("[","InjoyPB.CFG",hostf)
  64. if 0=hostf.0 then
  65.   say "  (none)"
  66. else do ff=1 to hostf.0
  67.   if "["=substr(hostf.ff,1,1) then
  68.     say "  "||substr(hostf.ff,2,pos("]",hostf.ff)-2)
  69. end
  70. say "Enter one of the names (without the '.log' extension) or any other"
  71. say "host name you intend to use:"
  72. parse pull hostname .
  73. bhostname="["||hostname||"]"
  74. parse upper var bhostname uhostname
  75.  
  76. /* Create program object for new host */
  77. found=0
  78. ff=1
  79. do until (found=1) | (ff>hostf.0)
  80.   parse upper var hostf.ff uhf
  81.   if uhf=uhostname then
  82.     found=1
  83.   ff=ff+1
  84. end
  85. if 0=found then do
  86.   say "Host "hostname" isn't defined yet:"
  87.   do until (aa="Y") | (aa="N")
  88.     say "Create a program object for it? (y/n)"
  89.     pull aa .
  90.   end
  91.   if aa="Y" then
  92.     call SysCreateObject "WPProgram", ,
  93.                          "Injoy Phone Bill"||crlf||hostname, ,
  94.                          "<INJOYPBFOLDER>", ,
  95.                          "OBJECTID=<INJOYPBPROGRAM_"hostname">;"|| ,
  96.                          "ICONFILE="||ijpbdir||"\InjoyPB.ICO;"|| ,
  97.                          "EXENAME="||ijpbdir||"\InjoyPB.EXE;"|| ,
  98.                          "STARTUPDIR="||ijpbdir||";"|| ,
  99.                          "PARAMETERS="hostname" [month (1-12)];"|| ,
  100.                          "NOAUTOCLOSE=YES", ,
  101.                          "REPLACE"
  102. end
  103.  
  104. /* Read explanations from configuration file */
  105. exn=0
  106. do while lines("InjoyPB.CFG")
  107.   buf=linein("InjoyPB.CFG")
  108.   if "-"=substr(buf,1,1) then do
  109.     exn=exn+1
  110.     exline.0=exn
  111.     exline.exn=buf
  112.   end
  113. end
  114.  
  115. /* Read new configuration lines from user */
  116. cfn=0
  117. exn=1
  118. do until exn > exline.0
  119.   ch=substr(exline.exn,2,1)
  120.   rc=SysCls()
  121.   say ""
  122.   do while ch = substr(exline.exn,2,1)
  123.     say substr(exline.exn,3)
  124.     exn=exn+1
  125.   end
  126.   say ""
  127.   inp="INP"
  128.   do while inp <> ""
  129.     say "Enter line (or RETURN for next group):"
  130.     inp = linein()
  131.     if inp <> "" then do
  132.       cfn=cfn+1
  133.       cfline.0=cfn
  134.       cfline.cfn=ch||" "||inp
  135.     end
  136.   end
  137. end
  138.  
  139. /* Ask once more */
  140. rc=SysCls()
  141. say ""
  142. do until (aa="Y") | (aa="N")
  143.   say "Do you want to save your new configuration? (y/n)"
  144.   say "Answer 'n' to cancel configuration and leave InjoyPB.CFG untouched."
  145.   say "If you answer 'y' the old InjoyPB.CFG is saved as InjoyPB.BAK; any"
  146.   say "existing InjoyPB.BAK file will be lost."
  147.   pull aa .
  148. end
  149. if aa="N" then do
  150.   say ""
  151.   say "Host definition cancelled"
  152.   exit
  153. end
  154.  
  155. /* Copy all lines of existing config file
  156.    except any old definition with the same host name */
  157. rc=SysCls()
  158. say ""
  159. say "Copying old data..."
  160. rc=lineout("InjoyPB.CFG",,1)  /* Reset file pointer */
  161. do while lines("InjoyPB.CFG")
  162.   buf=linein("InjoyPB.CFG")
  163.   parse upper var buf ubuf
  164.   if substr(ubuf,1,length(uhostname)) = uhostname then do
  165.     rc=lineout("InjoyPB.$$$","."||buf||" (old definition)")
  166.     do forever
  167.       buf=linein("InjoyPB.CFG")
  168.       if "[" = substr(buf,1,1) then do
  169.         rc=lineout("InjoyPB.$$$",buf)
  170.         leave
  171.       end
  172.       if "" = buf then
  173.         rc=lineout("InjoyPB.$$$","")
  174.       else
  175.         rc=lineout("InjoyPB.$$$","."||buf)
  176.       if 0 = lines("InjoyPB.CFG") then leave
  177.     end
  178.   end
  179.   else
  180.     rc=lineout("InjoyPB.$$$",buf)
  181. end
  182.  
  183. /* Append new definition */
  184. say "Appending new definitions..."
  185. rc=lineout("InjoyPB.$$$","")
  186. rc=lineout("InjoyPB.$$$",bhostname)
  187. cfn=1
  188. do until cfn > cfline.0
  189.   rc=lineout("InjoyPB.$$$",cfline.cfn)
  190.   cfn=cfn+1
  191. end
  192.  
  193. /* Rename files */
  194. say "Renaming files..."
  195. rc=stream("InjoyPB.CFG","c","CLOSE")
  196. rc=stream("InjoyPB.$$$","c","CLOSE")
  197. "if exist InjoyPB.BAK delete InjoyPB.BAK >nul"
  198. "rename InjoyPB.CFG InjoyPB.BAK >nul"
  199. "rename InjoyPB.$$$ InjoyPB.CFG >nul"
  200.  
  201. say "New host defined."
  202.