home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ifd98149.zip / INIDUMP.CMD
OS/2 REXX Batch file  |  1998-05-29  |  14KB  |  504 lines

  1. /*
  2.  * Pgm Name    : E:\DB\BATCH\CMD\HTMLPP.CMD
  3.  * Pgm Version : 98.144
  4.  * Time        : Friday, 29 May 1998  8:29:12pm
  5.  * Input File  : E:\DB\PROJECTS\OS2\inidump\INIDUMP.X
  6.  * Output File : .\OUT\INIDUMP.CMD
  7.  */
  8.  
  9. /*
  10. * $Header:   E:/DB/PVCS.IT/OS2/INIDUMP/INIDUMP.X_V   1.3   29 May 1998 20:29:04   Dennis_Bareis  $/htmlpp/HtmlPP.cmv   1.4   07 Nov 1997 15:40:04   Dennis_Bareis  $/htmlpp/HtmlPP.cmv   1.3   07 Nov 1997 15:18:38   Dennis_Bareis  $/htmlpp/HtmlPP.cmv   1.2   07 Nov 1997 10:57:22   Dennis_Bareis  $/PLATFORM/PLATFRM.X_V   1.5   11 Oct 1996 16:40:40   Dennis_Bareis  $/PLATFORM/PLATFRM.X_V   1.4   11 Oct 1996 16:26:28   Dennis_Bareis  $/PLATFORM/PLATFRM.X_V   1.3   17 Sep 1996 10:51:38   Dennis_Bareis  $
  11. */
  12. call RxFuncAdd  'SysIni',      'RexxUtil', 'SysIni'
  13. call RxFuncAdd  'SysFileTree', 'RexxUtil', 'SysFileTree'
  14. NewSingleQuote = "' || " || '"' || "'" || '" || ' || "'"
  15. ExitRc         = 0
  16. PGM_VERSION    = "98.149"
  17. /*
  18. * FASTINI.XH Version 98.147 by Dennis Bareis
  19. *            http://www.ozemail.com.au/~dbareis (db0@anz.com)
  20. */
  21. _FiOpenCount = 0
  22. call RxFuncAdd  'FastIniStart',   'FastIni',  'FastIniStart'
  23. call RxFuncAdd  'FastIniEnd',     'FastIni',  'FastIniEnd'
  24. call RxFuncAdd  'FastIniVersion', 'FastIni',  'FastIniVersion'
  25. _fiAvailable = _FastIniOk()
  26. signal  EndFASTINIXh
  27. FastIniIsFast:
  28. return(_fiAvailable)
  29. FastIniOpenIni:
  30. _fiFile      = arg(1)
  31. _fiHandleVar = arg(2)
  32. if  _fiAvailable = 'N' then
  33. do
  34. interpret _fiHandleVar || ' = 0'
  35. return('OK')
  36. end
  37. interpret _fiHandleVar || ' = ""'
  38. _fiFastRc = FastIniStart(_fiFile, _fiHandleVar)
  39. interpret '_FiHandle = ' || _fiHandleVar
  40. if  _FiHandle <> '' then
  41. do
  42. _FiOpenCount               = _FiOpenCount + 1
  43. _FiOpenedList._FiOpenCount = _FiHandle
  44. end
  45. return(_fiFastRc)
  46. FastIniCloseIni:
  47. if  _fiAvailable = 'N' then
  48. return('OK')
  49. return( FastIniEnd(arg(1)) )
  50. FastIniGetVersion:
  51. if  _fiAvailable = 'Y' then
  52. return( FastIniVersion(arg(1)) )
  53. else
  54. do
  55. interpret arg(1) || ' = "00.000 http://www.ozemail.com.au/~dbareis db0@anz.com Dennis Bareis"'
  56. return('OK')
  57. end
  58. FastIniCleanup:
  59. if  _fiAvailable = 'N' then
  60. return('OK')
  61. do  _fi = 1 to _FiOpenCount
  62. call FastIniEnd(_FiOpenedList._fi)
  63. _FiOpenedList._fi = 0
  64. end
  65. _FiOpenCount = 0
  66. return('OK')
  67. _FastIniOk:
  68. signal on SYNTAX  name _FastIniNotOk
  69. interpret "_fiRc = FastIniVersion('_fiVersion')"
  70. return('Y')
  71. _FastIniNotOk:
  72. return('N')
  73. EndFASTINIXh:
  74. /*
  75. * BIN2REXP.XH Version 98.149 by Dennis Bareis
  76. *            http://www.ozemail.com.au/~dbareis (db0@anz.com)
  77. */
  78. b2rNewSingleQuote = "' || " || '"' || "'" || '" || ' || "'"
  79. b2rAllHexCodes    = ''
  80. b2rAllAsciiCodes  = ''
  81. do b2rCharCode = 0 to 31
  82. b2rAllHexCodes = b2rAllHexCodes || d2c(b2rCharCode)
  83. end
  84. do b2rCharCode = 32 to 126
  85. b2rAllAsciiCodes = b2rAllAsciiCodes || d2c(b2rCharCode)
  86. end
  87. do b2rCharCode = 127 to 255
  88. b2rAllHexCodes = b2rAllHexCodes || d2c(b2rCharCode)
  89. end
  90. signal  EndBIN2REXPXh
  91. _QuoteAscii:
  92. b2rAscii2Quote = arg(1)
  93. if  pos("'", b2rAscii2Quote) = 0 then
  94. return("'" || b2rAscii2Quote || "'")
  95. else
  96. do
  97. if  pos('"', b2rAscii2Quote) = 0 then
  98. return('"' || b2rAscii2Quote || '"')
  99. else
  100. do
  101. return("'" || ReplaceString(b2rAscii2Quote, "'", b2rNewSingleQuote) || "'")
  102. end
  103. end
  104. _FormatHex:
  105. b2rHexString    = arg(1)
  106. b2rLengthHex    = length(b2rHexString)
  107. b2rFormattedHex = "'"
  108. if  b2rLengthHex > 7 then
  109. do
  110. b2rLeft1     = left(b2rHexString, 1)
  111. b2rLeft1Pos  = verify(b2rHexString, b2rLeft1)
  112. if  b2rLeft1Pos = 0 then
  113. return( "copies('" || c2x(b2rLeft1) || "'x, " || b2rLengthHex || ")" )
  114. else
  115. do
  116. if  b2rLeft1Pos > 7 then
  117. do
  118. b2rFormattedHex = "copies('" || c2x(b2rLeft1) || "'x, " || b2rLeft1Pos-1 || ") || '"
  119. b2rHexString    = substr(b2rHexString, b2rLeft1Pos)
  120. b2rLengthHex    = b2rLengthHex - (b2rLeft1Pos-1)
  121. end
  122. end
  123. end
  124. do  b2rCharPosn = 1 to b2rLengthHex
  125. if  (b2rCharPosn // 8) = 1 then
  126. do
  127. if  b2rCharPosn <> 1 then
  128. b2rFormattedHex = b2rFormattedHex || ' '
  129. end
  130. b2rFormattedHex = b2rFormattedHex || c2x(substr(b2rHexString, b2rCharPosn, 1))
  131. end
  132. b2rFormattedHex = b2rFormattedHex || "'x"
  133. return(b2rFormattedHex)
  134. _QuoteAsciiBreakIfRequired:
  135. qabAscii  = arg(1)
  136. qabLength = length(qabAscii)
  137. qabReturn = ''
  138. do  while qabLength > 256
  139. qabLeft   = left(qabAscii, 256)
  140. qabAscii  = substr(qabAscii, 256+1)
  141. qabLength = qabLength - 256
  142. if  qabReturn = '' then
  143. qabReturn = _QuoteAscii(qabLeft)
  144. else
  145. qabReturn = qabReturn || " || " || _QuoteAscii(qabLeft)
  146. end
  147. if  qabLength = 0 then
  148. return(qabReturn)
  149. else
  150. do
  151. if  qabReturn = '' then
  152. return( _QuoteAscii(qabAscii) )
  153. else
  154. return( qabReturn || " || " || _QuoteAscii(qabAscii) )
  155. end
  156. _FormatHexBreakIfRequired:
  157. fhbHex    = arg(1)
  158. fhbLength = length(fhbHex)
  159. fhbReturn = ''
  160. do  while fhbLength > 80
  161. fhbLeft   = left(fhbHex, 80)
  162. fhbHex    = substr(fhbHex, 80+1)
  163. fhbLength = fhbLength - 80
  164. if  fhbReturn = '' then
  165. fhbReturn = _FormatHex(fhbLeft)
  166. else
  167. fhbReturn = fhbReturn || " || " || _FormatHex(fhbLeft)
  168. end
  169. if  fhbLength = 0 then
  170. return(fhbReturn)
  171. else
  172. do
  173. if  fhbReturn = '' then
  174. return( _FormatHex(fhbHex) )
  175. else
  176. return( fhbReturn || " || " || _FormatHex(fhbHex) )
  177. end
  178. BIN2REXP:
  179. call BIN2REXP_START
  180. b2rValue       = arg(1)
  181. b2rValueLength = length(b2rValue)
  182. if  b2rValueLength = 0 then
  183. call BIN2REXP_ONEBIT  '""'
  184. else
  185. do
  186. do  while b2rValue \== ''
  187. b2rEndAsciiPos = verify(b2rValue, b2rAllAsciiCodes)
  188. if  b2rEndAsciiPos = 0 then
  189. do
  190. call BIN2REXP_ONEBIT _QuoteAsciiBreakIfRequired(b2rValue)
  191. b2rValue = ''
  192. end
  193. else
  194. do
  195. if  b2rEndAsciiPos <> 1 then
  196. do
  197. call BIN2REXP_ONEBIT _QuoteAsciiBreakIfRequired(left(b2rValue, b2rEndAsciiPos-1))
  198. b2rValue = substr(b2rValue, b2rEndAsciiPos)
  199. end
  200. else
  201. do
  202. b2rEndBinaryPos = verify(b2rValue, b2rAllHexCodes)
  203. if  b2rEndBinaryPos = 0 then
  204. do
  205. call BIN2REXP_ONEBIT _FormatHexBreakIfRequired(b2rValue)
  206. b2rValue = ''
  207. end
  208. else
  209. do
  210. call BIN2REXP_ONEBIT _FormatHexBreakIfRequired(left(b2rValue, b2rEndBinaryPos-1))
  211. b2rValue = substr(b2rValue, b2rEndBinaryPos)
  212. end
  213. end
  214. end
  215. end
  216. end
  217. call BIN2REXP_END
  218. return
  219. EndBIN2REXPXh:
  220. signal on HALT    name RexxCtrlC
  221. signal on NOVALUE name RexxTrapUninitializedVariable
  222. signal on SYNTAX  name RexxTrapSyntaxError
  223. TooLongToDump = 10000
  224. AllHexCodes   = ''
  225. AllAsciiCodes = ''
  226. do CharCode = 0 to 31
  227. AllHexCodes = AllHexCodes || d2c(CharCode)
  228. end
  229. do CharCode = 32 to 126
  230. AllAsciiCodes = AllAsciiCodes || d2c(CharCode)
  231. end
  232. do CharCode = 127 to 255
  233. AllHexCodes = AllHexCodes || d2c(CharCode)
  234. end
  235. IniFile = translate( strip(arg(1)) )
  236. if  IniFile = "" then
  237. call SyntaxError 'ERROR: Expected "USER", "SYSTEM", "BOTH", or the name of an .INI file...'
  238. if IniFile <> "USER" & IniFile <> "SYSTEM" & IniFile <> "BOTH" then
  239. do
  240. TreeRc = SysFileTree(IniFile, 'FileBase', 'FO')
  241. if   TreeRc <> 0 | FileBase.0 = 0 then
  242. do
  243. call ToStderr 'ERROR: The INI file "' || IniFile || '" does not exist.'
  244. PgmExit( SourceLine() )
  245. end
  246. end
  247. FastRc = FastIniOpenIni(IniFile, "IniHandle")
  248. if FastRc <> 'OK' then
  249. call ToStderr "FASTINI.DLL can not be accessed (" || FastRc || ').'
  250. call DumpWholeIni IniFile
  251. PgmExit(ExitRc)
  252. PgmExit:
  253. call FastIniCleanup
  254. exit( arg(1) )
  255. CommonTrapHandler:
  256. FailingLine     = arg(1)
  257. TrapHeading     = 'BUG: ' || arg(2)
  258. TextDescription = arg(3)
  259. Text            = arg(4)
  260. parse source . . SourceFileName
  261. call ToStderr "" || copies('=+', 39)
  262. call ToStderr TrapHeading
  263. call ToStderr copies('~', length(TrapHeading))
  264. call ToStderr substr(TextDescription, 1 , 16) || ': ' || Text
  265. call ToStderr 'Failing Module  : ' || SourceFileName
  266. call ToStderr 'Failing Line #  : ' || FailingLine
  267. call ToStderr 'Failing Command : ' || strip(SourceLine(FailingLine))
  268. call ToStderr copies('=+', 39) || ""
  269. PgmExit(FailingLine)
  270. RexxTrapUninitializedVariable:
  271. call CommonTrapHandler SIGL, 'NoValue Abort!', 'Unknown Variable', condition('D')
  272. RexxTrapSyntaxError:
  273. call CommonTrapHandler SIGL, 'Syntax Error!', 'Reason', errortext(Rc)
  274. RexxCtrlC:
  275. LineCtrlC = SIGL
  276. call ToStderr ''
  277. call ToStderr "" || copies('=+', 39)
  278. call ToStderr "Come on, you pressed Ctrl+C or Break didn't you!"
  279. call ToStderr copies('=+', 39) || ""
  280. PgmExit(LineCtrlC)
  281. SyntaxError:
  282. ErrorLine = SIGL
  283. call ToStderr  "[]----------------------------------------------------------[]"
  284. call ToStderr  "| INIDUMP.CMD, Version " || PGM_VERSION || " (C)opyright Dennis Bareis 1998 |"
  285. call ToStderr  '|      http://www.ozemail.com.au/~dbareis (db0@anz.com)      |'
  286. call ToStderr  "[]----------------------------------------------------------[]"
  287. call ToStderr  ""
  288. call ToStderr  "This program allows you to dump a whole INI file in the same format that my"
  289. call ToStderr  "INIWRITE.CMD program uses.  This allows you to maintain the contents of a"
  290. call ToStderr  "binary INI file as TEXT, which means you can use any text editor, difference"
  291. call ToStderr  "programs or source management programs such as PVCS."
  292. call ToStderr  ""
  293. call ToStderr  "The dump would normally only be required ONCE to get a text form of an INI"
  294. call ToStderr  "from an external source as you would maintain the text file as TEXT adding"
  295. call ToStderr  "or commenting out bits as required."
  296. call ToStderr  ""
  297. call ToStderr  ""
  298. call ToStderr  "CORRECT SYNTAX"
  299. call ToStderr  "~~~~~~~~~~~~~~"
  300. call ToStderr  "        INIDUMP[.CMD] USER|SYSTEM|BOTH|IniFileName >Output.IU"
  301. call ToStderr  ""
  302. call ToStderr  ARG(1)
  303. PgmExit(ErrorLine)
  304. ToStderr:
  305. call lineout 'STDERR',  arg(1)
  306. return
  307. DisplayError:
  308. ExitRc = SourceLine()
  309. say ''
  310. say           ';ERROR: ' || arg(1)
  311. call ToStderr  'ERROR: ' || arg(1) || ''
  312. say ''
  313. say ''
  314. return
  315. DumpWholeIni:
  316. call SysIni ARG(1), 'All:', 'aTmp.'
  317. if Result = 'ERROR:' then
  318. do
  319. call DisplayError 'Could not obtain list of APPLICATION keys.'
  320. return
  321. end
  322. if aTmp.0 = 0 then
  323. do
  324. call DisplayError 'INI file "'ARG(1)'" does not exist, or contains no data.'
  325. return
  326. end
  327. call quicksort 1, aTmp.0
  328. do  i = 0 to aTmp.0
  329. Apps.i = aTmp.i
  330. end
  331. do i = 1 to Apps.0
  332. if  i <> 1 then
  333. do
  334. say ""
  335. say ""
  336. say ';'copies('#', 78)
  337. end
  338. call SysIni ARG(1), Apps.i, 'All:', 'aTmp'
  339. if Result = 'ERROR:' then
  340. do
  341. call DisplayError 'Could not obtain List of Keys for APPLICATION = 'Apps.i
  342. iterate
  343. end
  344. if aTmp.0 = 0 then
  345. do
  346. call DisplayError 'There are no keys for application "'Apps.i'".'
  347. iterate
  348. end
  349. call quicksort 1, aTmp.0
  350. do  j = 0 to aTmp.0
  351. Keys.j = aTmp.j
  352. end
  353. LongestKeyName = 0
  354. do  j=1 to Keys.0
  355. LengthKeyName = length(SubstituteStandardCodes(Keys.j))
  356. if  LengthKeyName > LongestKeyName then
  357. LongestKeyName = LengthKeyName
  358. end
  359. do  j=1 to Keys.0
  360. call DumpIniValue ARG(1), Apps.i, Keys.j
  361. end
  362. end
  363. return
  364. SubstituteStandardCodes:
  365. return( ReplaceString(arg(1), " ", "{Space}") )
  366. BIN2REXP_START:
  367. FormattedValue = ''
  368. return
  369. BIN2REXP_ONEBIT:
  370. ToAdd    = arg(1)
  371. if  FormattedValue = '' then
  372. FormattedValue = ToAdd
  373. else
  374. FormattedValue = FormattedValue || " || " || ToAdd
  375. return
  376. BIN2REXP_END:
  377. if  pos(';' || ';', FormattedValue) = 0 then
  378. say FormattedValue
  379. else
  380. say FormattedValue || '    ;' || ';Warning Leave this!'
  381. return
  382. DumpIniValue:
  383. dipIniName = arg(1)
  384. dipAppName = arg(2)
  385. dipKeyName = arg(3)
  386. FirstPart = SubstituteStandardCodes(dipIniName) || '  ' || SubstituteStandardCodes(dipAppName) || '  ' || left(SubstituteStandardCodes(dipKeyName), LongestKeyName) || ' '
  387. Value = SysIni(dipIniName, dipAppName, dipKeyName)
  388. if  Value = "ERROR:" then
  389. do
  390. say ';' || FirstPart || '<<INI READ FAILED>>'
  391. call DisplayError 'Could not read key = ' || dipKeyName
  392. return
  393. end
  394. ValueLength = length(Value)
  395. if  ValueLength > TooLongToDump then
  396. do
  397. ErrorMsg = "At " || ValueLength || ' the value is too large to dump (>' || TooLongToDump || ' bytes)'
  398. say ';' || FirstPart || ErrorMsg
  399. call DisplayError ErrorMsg
  400. return
  401. end
  402. call charout ,FirstPart || ' '
  403. call BIN2REXP Value
  404. return
  405. ReplaceString:
  406. TheString    = arg(1)
  407. ChangeFrom   = arg(2)
  408. ChangeTo     = arg(3)
  409. ChangeCntVar = arg(4)
  410. ChangeFromLength = length(ChangeFrom)
  411. ChangeToLength   = length(ChangeTo)
  412. FoundPosn = pos(ChangeFrom, TheString)
  413. ReplaceStringCounter = 0
  414. do  while FoundPosn <> 0
  415. TheString = left(TheString, FoundPosn-1) || ChangeTo || substr(TheString, FoundPosn+ChangeFromLength)
  416. FoundPosn = pos(ChangeFrom, TheString, FoundPosn+ChangeToLength)
  417. ReplaceStringCounter = ReplaceStringCounter + 1
  418. end
  419. if  ChangeCntVar <> "" then
  420. interpret ChangeCntVar || " = ReplaceStringCounter + " || ChangeCntVar
  421. return(TheString)
  422. SourceLine:
  423. return(SIGL)
  424. qsCompFunc: PROCEDURE
  425. parse arg a, b
  426. select
  427. when ( a < b ) then
  428. return(-1)
  429. when ( a > b ) then
  430. return(1)
  431. otherwise
  432. return(0)
  433. end
  434. QuickSort: PROCEDURE EXPOSE atmp.
  435. parse arg top, down
  436. if ( ( down-top ) < 2 ) then
  437. do
  438. if ( ( down - top ) > 0 ) then
  439. /* if ( atmp.top > atmp.down ) then */
  440. if ( qsCompFunc( atmp.top, atmp.down ) > 0 ) then
  441. do
  442. tmpval      = atmp.top
  443. atmp.top    = atmp.down
  444. atmp.down   = tmpval
  445. end
  446. end
  447. else
  448. do
  449. l = top
  450. r = down
  451. m = top + trunc( ( down-top )/2 )
  452. do while ( l<r )
  453. m_val = atmp.m
  454. /* do while ( atmp.l < m_val ) */
  455. do while ( qsCompFunc( atmp.l, m_val ) < 0 )
  456. if  ( l < m ) then
  457. l=l+1
  458. else
  459. leave
  460. end
  461. /* do while ( atmp.r > m_val ) */
  462. do while ( qsCompFunc( atmp.r, m_val ) > 0 )
  463. if  ( m < r ) then
  464. r=r-1
  465. else
  466. leave
  467. end
  468. if ( l < r ) then
  469. do
  470. tmpval = atmp.l
  471. atmp.l = atmp.r
  472. atmp.r = tmpval
  473. select
  474. when ( m=r ) then
  475. do
  476. r = r-1
  477. m = l
  478. end
  479. when ( m=l ) then
  480. do
  481. l = l+1
  482. m = r
  483. end
  484. otherwise
  485. do
  486. l = l+1
  487. r = r-1
  488. end
  489. end
  490. end
  491. end
  492. if ( ( r-top ) < ( down-l ) ) then
  493. do
  494. call quicksort top, m-1
  495. call quicksort m+1, down
  496. end
  497. else
  498. do
  499. call quicksort m+1, down
  500. call quicksort top, m-1
  501. end
  502. end
  503. return
  504.