home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ifu98148.zip / INIWRITE.CMD next >
OS/2 REXX Batch file  |  1998-05-28  |  10KB  |  305 lines

  1. /*
  2.  * Pgm Name    : E:\DB\BATCH\CMD\HTMLPP.CMD
  3.  * Pgm Version : 98.144
  4.  * Time        : Thursday, 28 May 1998  6:16:04pm
  5.  * Input File  : E:\DB\PROJECTS\OS2\iniwrite\INIWRITE.x
  6.  * Output File : .\OUT\INIWRITE.CMD
  7.  */
  8.  
  9. OneBeep         = ''
  10. TwoBeep         = OneBeep || OneBeep
  11. EscapeChar      = d2c(27)
  12. Reset           = EscapeChar || '[0m'
  13. ColorStartupMsg = EscapeChar || '[1;33m'
  14. ColorInputLine  = EscapeChar || '[1;33m'
  15. ColorError      = EscapeChar || '[1;31m'
  16. ColorWarning    = EscapeChar || '[1;35m'
  17. ColorStatus     = EscapeChar || '[32m'
  18. call RxFuncAdd  'SysIni', 'RexxUtil', 'SysIni'
  19. Indent     = "        * "
  20. /*
  21. * FASTINI.XH Version 98.147 by Dennis Bareis
  22. *            http://www.ozemail.com.au/~dbareis (db0@anz.com)
  23. */
  24. _FiOpenCount = 0
  25. call RxFuncAdd  'FastIniStart',   'FastIni',  'FastIniStart'
  26. call RxFuncAdd  'FastIniEnd',     'FastIni',  'FastIniEnd'
  27. call RxFuncAdd  'FastIniVersion', 'FastIni',  'FastIniVersion'
  28. _fiAvailable = _FastIniOk()
  29. signal  EndFASTINIXh
  30. FastIniIsFast:
  31. return(_fiAvailable)
  32. FastIniOpenIni:
  33. _fiFile      = arg(1)
  34. _fiHandleVar = arg(2)
  35. if  _fiAvailable = 'N' then
  36. do
  37. interpret _fiHandleVar || ' = 0'
  38. return('OK')
  39. end
  40. interpret _fiHandleVar || ' = ""'
  41. _fiFastRc = FastIniStart(_fiFile, _fiHandleVar)
  42. interpret '_FiHandle = ' || _fiHandleVar
  43. if  _FiHandle <> '' then
  44. do
  45. _FiOpenCount               = _FiOpenCount + 1
  46. _FiOpenedList._FiOpenCount = _FiHandle
  47. end
  48. return(_fiFastRc)
  49. FastIniCloseIni:
  50. if  _fiAvailable = 'N' then
  51. return('OK')
  52. return( FastIniEnd(arg(1)) )
  53. FastIniGetVersion:
  54. if  _fiAvailable = 'Y' then
  55. return( FastIniVersion(arg(1)) )
  56. else
  57. do
  58. interpret arg(1) || ' = "00.000 http://www.ozemail.com.au/~dbareis db0@anz.com Dennis Bareis"'
  59. return('OK')
  60. end
  61. FastIniCleanup:
  62. if  _fiAvailable = 'N' then
  63. return('OK')
  64. do  _fi = 1 to _FiOpenCount
  65. call FastIniEnd(_FiOpenedList._fi)
  66. _FiOpenedList._fi = 0
  67. end
  68. _FiOpenCount = 0
  69. return('OK')
  70. _FastIniOk:
  71. signal on SYNTAX  name _FastIniNotOk
  72. interpret "_fiRc = FastIniVersion('_fiVersion')"
  73. return('Y')
  74. _FastIniNotOk:
  75. return('N')
  76. EndFASTINIXh:
  77. LastIni   = ''
  78. IniHandle = ''
  79. if FastIniIsFast = 'N' then
  80. call ToStderr "FASTINI.DLL can not be accessed (" || FastRc || ').'
  81. signal on HALT    name RexxCtrlC
  82. signal on NOVALUE name RexxTrapUninitializedVariable
  83. signal on SYNTAX  name RexxTrapSyntaxError
  84. call DisplayLine ColorStartupMsg, '[]--------------------------------------------------------------[]'
  85. call DisplayLine ColorStartupMsg, '| INIWRITE.CMD: Version 98.148 (C)opyright Dennis Bareis 1997    |'
  86. call DisplayLine ColorStartupMsg, '|               http://www.ozemail.com.au/~dbareis (db0@anz.com) |'
  87. call DisplayLine ColorStartupMsg, '[]--------------------------------------------------------------[]'
  88. say ''
  89. CommandLine = strip( arg(1) )
  90. if CommandLine = '' then
  91. UserSyntaxError("Expected at least one parameter")
  92. if left(CommandLine, 1) <> '@' then
  93. do
  94. ScriptFile = ''
  95. parse var CommandLine '"'App Key KeyCmd'"'Crap
  96. if  Crap <> '' then
  97. UserSyntaxError("Supplied update command is not correctly quoted!")
  98. SingleCommand = App || ' ' Key || ' ' || KeyCmd
  99. call DisplayLine ColorInputLine, SingleCommand
  100. PgmExit( ProcessOneCommand('USER', SingleCommand) )
  101. end
  102. ScriptFile = substr(CommandLine, 2)
  103. if ScriptFile = '' then
  104. do
  105. call DisplayLine ColorError, 'ERROR: Expected to find the name of a file after the "@" character!'
  106. PgmExit(ThisLineNumber())
  107. end
  108. call stream ScriptFile, 'c', 'close'
  109. if stream(ScriptFile, 'c', 'query exists') = '' then
  110. do
  111. call DisplayLine ColorError, 'ERROR: The script file "' || ScriptFile || '" does not exist!' || TwoBeep
  112. PgmExit(ThisLineNumber())
  113. end
  114. call stream ScriptFile, 'c', 'open read'
  115. LineNumber = 0
  116. ExitRc     = 0
  117. do     while lines(ScriptFile) <> 0
  118. Line       = LINEIN(ScriptFile)
  119. Line       = strip(Line)
  120. LineNumber = LineNumber + 1
  121. if  Line = "" | left(Line, 1) = ";" then
  122. iterate
  123. CmdSource = filespec('name', ScriptFile) || '(' || LineNumber || ')'
  124. call DisplayLine ColorInputLine, CmdSource || ': ' || Line
  125. ProcessRc = ProcessOneCommand(CmdSource, Line)
  126. if  ProcessRc <> 0 then
  127. ExitRc = ProcessRc
  128. end
  129. CommandErrorExit:
  130. if IniHandle <> '' then
  131. FastRc = FastIniCloseIni(IniHandle)
  132. call stream ScriptFile, 'c', 'close'
  133. if ExitRc <> 0 then
  134. do
  135. say ''
  136. call DisplayLine ColorError, 'ERROR: The script "' || ScriptFile || '" terminated abnormally (on line #' || LineNumber || ')...' || OneBeep
  137. end
  138. PgmExit(ExitRc)
  139. ProcessOneCommand:
  140. CmdSource = arg(1)
  141. Cmd       = arg(2)
  142. parse var Cmd IniFileName ApplicationName KeyName IniWriteCommand
  143. if  ApplicationName = "" then
  144. do
  145. call DisplayLine ColorError, Indent || 'ERROR: not enough information on the line...'
  146. return(ThisLineNumber())
  147. end
  148. IniWriteCommand = strip(IniWriteCommand)
  149. IniFileName     = SubstituteStandardCodes(IniFileName,     "INI Filename")
  150. ApplicationName = SubstituteStandardCodes(ApplicationName, "Application Name")
  151. KeyName         = SubstituteStandardCodes(KeyName,         "Key Name")
  152. if  LastIni <> IniFileName then
  153. do
  154. if  IniHandle <> '' then
  155. FastRc = FastIniCloseIni(IniHandle)
  156. FastRc  = FastIniOpenIni(IniFileName, "IniHandle")
  157. LastIni = IniFileName
  158. end
  159. if  KeyName = 'DELETE:' | KeyName = '"DELETE:"' | KeyName = "'DELETE:'"  then
  160. do
  161. call DisplayLine ColorStatus, Indent || 'Deleting the Application "' || ApplicationName || '"...'
  162. SysIniRc = SysIni(IniFileName, ApplicationName, "DELETE:")
  163. end
  164. else
  165. do
  166. if  IniWriteCommand = 'DELETE:' | IniWriteCommand = '"DELETE:"' | IniWriteCommand = "'DELETE:'" then
  167. do
  168. call DisplayLine ColorStatus, Indent || 'Deleting the Key "' || ApplicationName || '" + "' || KeyName || '"...'
  169. SysIniRc = SysIni(IniFileName, ApplicationName, KeyName, "DELETE:")
  170. if SysIniRc = "ERROR:" then
  171. do
  172. call DisplayLine ColorWarning, Indent || 'Warning, this key probably did not exist...'
  173. SysIniRc = "WARNING"
  174. end
  175. end
  176. else
  177. do
  178. if  IniWriteCommand = "" then
  179. do
  180. call DisplayLine ColorError, Indent || 'ERROR: Not enough parameters specified to update INI...'
  181. return(ThisLineNumber())
  182. end
  183. ExecuteTheCommand = 'NewIniValue = ' || IniWriteCommand
  184. signal ON SYNTAX   name InvalidIniWriteCommand
  185. signal ON NOVALUE  name InvalidIniWriteCommand
  186. interpret ExecuteTheCommand
  187. signal OFF SYNTAX
  188. signal OFF NOVALUE
  189. OldIniValue     = SysIni(IniFileName, ApplicationName, KeyName)
  190. NeedToUpdateIni = 'Y'
  191. if  OldIniValue = "ERROR:" then
  192. call DisplayLine ColorStatus, Indent || 'Adding the Key "' || ApplicationName || '" + "' || KeyName || '"...'
  193. else
  194. do
  195. if  OldIniValue \== NewIniValue then
  196. call DisplayLine ColorStatus, Indent || 'Updating the INI files value...'
  197. else
  198. do
  199. call DisplayLine ColorStatus, Indent || 'New value same as old (no need to update).'
  200. NeedToUpdateIni = 'N'
  201. end
  202. end
  203. if  NeedToUpdateIni = 'Y' then
  204. SysIniRc = SysIni(IniFileName, ApplicationName, KeyName, NewIniValue)
  205. else
  206. SysIniRc = "NotUpdatedAsValuesEqual"
  207. end
  208. end
  209. if SysIniRc = "ERROR:" then
  210. do
  211. call DisplayLine ColorError, Indent || 'ERROR: update failed...'
  212. return(ThisLineNumber())
  213. end
  214. return(0)
  215. SubstituteStandardCodes:
  216. BeforeString = arg(1)
  217. AfterString  = SubstituteOneStandardCode(BeforeString, "{Space}", " ")
  218. if  BeforeString <> AfterString then
  219. call DisplayLine ColorStatus, Indent || 'At least 1 standard code was substituted in the ' || arg(2) || '...'
  220. return(AfterString)
  221. UserSyntaxError:
  222. call ToStderr "SYNTAX ERROR"
  223. call ToStderr "~~~~~~~~~~~~"
  224. call ToStderr '    ' || arg(1)
  225. call ToStderr ''
  226. call ToStderr 'CORRECT SYNTAX'
  227. call ToStderr '~~~~~~~~~~~~~~'
  228. call ToStderr '    INIWRITE[.CMD] @ChangesFile | "OneChangeLine"'
  229. call ToStderr ''
  230. call ToStderr 'EXAMPLES'
  231. call ToStderr '~~~~~~~~'
  232. call ToStderr '    INIWRITE.CMD @C:\Changes.LST'
  233. call ToStderr '    INIWRITE.CMD "' || "C:\TEST.INI AppName KeyName 'null terminated' || d2c(0)" || '"'
  234. call ToStderr '    INIWRITE.CMD "' || "USER Shield fMaximize '0100'x" || '"'
  235. call ToStderr '    INIWRITE.CMD "' || "USER Shield ~Font{Space}Size... '06 0a'x" || '"'
  236. call ToStderr '    INIWRITE.CMD "' || "user Shield sInitialShape 'DELETE:'" || '"'
  237. call ToStderr ''
  238. call ToStderr 'Please see "INIWRITE.INF" for more details.' 
  239. call ToStderr TwoBeep
  240. PgmExit(ThisLineNumber())
  241. SubstituteOneStandardCode:
  242. TheString   = arg(1)
  243. Before      = arg(2)
  244. FoundPos    = pos(Before, TheString)
  245. if  FoundPos <> 0 then
  246. do
  247. After        = arg(3)
  248. LengthBefore = length(Before)
  249. do  until FoundPos = 0
  250. TheString = left(TheString, FoundPos - 1) || After || substr(TheString, FoundPos+LengthBefore)
  251. FoundPos = pos(Before, TheString)
  252. end
  253. end
  254. return(TheString)
  255. DisplayLine:
  256. call charout, arg(1)
  257. say arg(2)
  258. call charout, Reset
  259. return
  260. InvalidIniWriteCommand:
  261. if  condition('C') = 'NOVALUE' then
  262. call DisplayLine ColorError, Indent || 'ERROR: Incorrectly quoted string (i.e. ' || condition('D') || ')!'
  263. else
  264. call DisplayLine ColorError, Indent || 'ERROR: REXX Syntax error (New INI value was invalid)!'
  265. call DisplayLine ColorError, Indent || 'Failing Command: ' || ExecuteTheCommand
  266. if  ScriptFile <> '' then
  267. CloseRc = stream(ScriptFile, 'c', 'close')
  268. PgmExit(ThisLineNumber())
  269. CommonTrapHandler:
  270. FailingLine     = arg(1)
  271. TrapHeading     = 'BUG: ' || arg(2)
  272. TextDescription = arg(3)
  273. Text            = arg(4)
  274. parse source . . SourceFileName
  275. call ToStderr ColorError || copies('=+', 39)
  276. call ToStderr TrapHeading
  277. call ToStderr copies('~', length(TrapHeading))
  278. call ToStderr substr(TextDescription, 1 , 16) || ': ' || Text
  279. call ToStderr 'Failing Module  : ' || SourceFileName
  280. call ToStderr 'Failing Line #  : ' || FailingLine
  281. call ToStderr 'Failing Command : ' || strip(SourceLine(FailingLine))
  282. call ToStderr copies('=+', 39) || Reset
  283. PgmExit(FailingLine)
  284. RexxTrapUninitializedVariable:
  285. call CommonTrapHandler SIGL, 'NoValue Abort!', 'Unknown Variable', condition('D')
  286. RexxTrapSyntaxError:
  287. call CommonTrapHandler SIGL, 'Syntax Error!', 'Reason', errortext(Rc)
  288. RexxCtrlC:
  289. LineCtrlC = SIGL
  290. call ToStderr ''
  291. call ToStderr ColorError || copies('=+', 39)
  292. call ToStderr "Come on, you pressed Ctrl+C or Break didn't you!"
  293. call ToStderr copies('=+', 39) || Reset
  294. PgmExit(LineCtrlC)
  295. ThisLineNumber:
  296. return(SIGL)
  297. GetEnv:
  298. return( value(arg(1),,'OS2ENVIRONMENT') )
  299. ToStderr:
  300. call lineout 'STDERR',  arg(1)
  301. return
  302. PgmExit:
  303. call FastIniCleanup
  304. exit( arg(1) )
  305.