home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 18 REXX / 18-REXX.zip / ifr98148.zip / INIREAD.CMD
OS/2 REXX Batch file  |  1998-05-28  |  11KB  |  450 lines

  1. /*
  2.  * Pgm Name    : E:\DB\BATCH\CMD\HTMLPP.CMD
  3.  * Pgm Version : 98.144
  4.  * Time        : Thursday, 28 May 1998  6:13:22pm
  5.  * Input File  : E:\DB\PROJECTS\OS2\iniread\INIREAD.X
  6.  * Output File : .\OUT\INIREAD.CMD
  7.  */
  8.  
  9. PGM_VERSION = "98.148"
  10. call RxFuncAdd  'SysIni',      'RexxUtil', 'SysIni'
  11. call RxFuncAdd  'SysFileTree', 'RexxUtil', 'SysFileTree'
  12. /*
  13. * FASTINI.XH Version 98.147 by Dennis Bareis
  14. *            http://www.ozemail.com.au/~dbareis (db0@anz.com)
  15. */
  16. _FiOpenCount = 0
  17. call RxFuncAdd  'FastIniStart',   'FastIni',  'FastIniStart'
  18. call RxFuncAdd  'FastIniEnd',     'FastIni',  'FastIniEnd'
  19. call RxFuncAdd  'FastIniVersion', 'FastIni',  'FastIniVersion'
  20. _fiAvailable = _FastIniOk()
  21. signal  EndFASTINIXh
  22. FastIniIsFast:
  23. return(_fiAvailable)
  24. FastIniOpenIni:
  25. _fiFile      = arg(1)
  26. _fiHandleVar = arg(2)
  27. if  _fiAvailable = 'N' then
  28. do
  29. interpret _fiHandleVar || ' = 0'
  30. return('OK')
  31. end
  32. interpret _fiHandleVar || ' = ""'
  33. _fiFastRc = FastIniStart(_fiFile, _fiHandleVar)
  34. interpret '_FiHandle = ' || _fiHandleVar
  35. if  _FiHandle <> '' then
  36. do
  37. _FiOpenCount               = _FiOpenCount + 1
  38. _FiOpenedList._FiOpenCount = _FiHandle
  39. end
  40. return(_fiFastRc)
  41. FastIniCloseIni:
  42. if  _fiAvailable = 'N' then
  43. return('OK')
  44. return( FastIniEnd(arg(1)) )
  45. FastIniGetVersion:
  46. if  _fiAvailable = 'Y' then
  47. return( FastIniVersion(arg(1)) )
  48. else
  49. do
  50. interpret arg(1) || ' = "00.000 http://www.ozemail.com.au/~dbareis db0@anz.com Dennis Bareis"'
  51. return('OK')
  52. end
  53. FastIniCleanup:
  54. if  _fiAvailable = 'N' then
  55. return('OK')
  56. do  _fi = 1 to _FiOpenCount
  57. call FastIniEnd(_FiOpenedList._fi)
  58. _FiOpenedList._fi = 0
  59. end
  60. _FiOpenCount = 0
  61. return('OK')
  62. _FastIniOk:
  63. signal on SYNTAX  name _FastIniNotOk
  64. interpret "_fiRc = FastIniVersion('_fiVersion')"
  65. return('Y')
  66. _FastIniNotOk:
  67. return('N')
  68. EndFASTINIXh:
  69. signal on HALT    name RexxCtrlC
  70. signal on NOVALUE name RexxTrapUninitializedVariable
  71. signal on SYNTAX  name RexxTrapSyntaxError
  72. Args = ARG(1)
  73. Args = strip(Args)
  74. PARSE VAR Args IniFile Application Key
  75. if  IniFile = "" then
  76. call SyntaxError 'ERROR: Expected "USER", "SYSTEM", "BOTH", or the name of an .INI file...'
  77. parse UPPER VAR IniFile IniFile
  78. if IniFile <> "USER" & IniFile <> "SYSTEM" & IniFile <> "BOTH" then
  79. do
  80. TreeRc = SysFileTree(IniFile, 'FileBase', 'FO')
  81. if   TreeRc <> 0 | FileBase.0 = 0 then
  82. do
  83. call ToStderr 'ERROR: The INI file "' || IniFile || '" does not exist.'
  84. PgmExit( SourceLine() )
  85. end
  86. end
  87. FastRc = FastIniOpenIni(IniFile, "IniHandle")
  88. if FastRc <> 'OK' then
  89. call ToStderr "FASTINI.DLL can not be accessed (" || FastRc || ').'
  90. if Application = "" then
  91. call SyntaxError 'ERROR: Expected the "APPLICATION" key part, or "*SubStr", or "*" for all.'
  92. if left(Application,1) = "!" then
  93. do
  94. Application = substr(Application, 2)
  95. call CheckWholeIni IniFile, Application
  96. PgmExit(0)
  97. end
  98. if left(Application,1) = "*" then
  99. do
  100. Application = substr(Application, 2)
  101. call DumpWholeIni IniFile, Application
  102. PgmExit(0)
  103. end
  104. else
  105. do
  106. if  Key = "" then
  107. call SyntaxError "ERROR: Expected a key to identify the value to be dumped..."
  108. call Dump1Key IniFile, Application, Key
  109. PgmExit(0)
  110. end
  111. ToStderr:
  112. call lineout 'STDERR',  arg(1)
  113. return
  114. Dump1Key:
  115. call DumpIniValue ARG(1), ARG(2), ARG(3)
  116. PgmExit(0)
  117. DumpWholeIni:
  118. UpperDumpSpec = ARG(2)
  119. parse UPPER VAR UpperDumpSpec UpperDumpSpec
  120. call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs'
  121. call sysloadfuncs
  122. call SysIni ARG(1), 'All:', 'aTmp'
  123. if Result = 'ERROR:' then
  124. do
  125. call ToStderr 'ERROR: Could not obtain list of APPLICATION keys.'
  126. RETURN
  127. end
  128. if aTmp.0 = 0 then
  129. do
  130. call ToStderr 'ERROR: INI file "'ARG(1)'" does not exist, or contains no data.'
  131. RETURN
  132. end
  133. call quicksort 1, aTmp.0
  134. do  i = 0 to aTmp.0
  135. Apps.i = aTmp.i
  136. end
  137. do i = 1 to Apps.0
  138. if ARG(2) <> "" then
  139. do
  140. parse UPPER VAR Apps.i UpperApplication
  141. if pos(UpperDumpSpec, UpperApplication) = 0 then iterate
  142. end
  143. call SysIni ARG(1), Apps.i, 'All:', 'aTmp'
  144. if Result = 'ERROR:' then
  145. do
  146. call ToStderr 'Could not obtain List of Keys for APPLICATION = 'Apps.i
  147. call AddSeperator ARG(1)
  148. iterate
  149. end
  150. if aTmp.0 = 0 then
  151. do
  152. call ToStderr 'There are no keys for application "'Apps.i'".'
  153. iterate
  154. end
  155. call quicksort 1, aTmp.0
  156. do  j = 0 to aTmp.0
  157. Keys.j = aTmp.j
  158. end
  159. do j=1 to Keys.0
  160. call AddSeperator ARG(1)
  161. call DumpIniValue ARG(1), Apps.i, Keys.j
  162. end
  163. end
  164. PgmExit(0)
  165. CheckWholeIni:
  166. say 'Checking INI = 'ARG(1)', please wait...'
  167. InvalidCount = 0
  168. UpperDumpSpec = ARG(2)
  169. parse UPPER VAR UpperDumpSpec UpperDumpSpec
  170. call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
  171. call sysloadfuncs
  172. call SysIni ARG(1), 'All:', 'Apps.'
  173. if Result = 'ERROR:' then
  174. do
  175. call ToStderr 'ERROR: Could not obtain list of APPLICATION keys.'
  176. PgmExit( SourceLine() )
  177. end
  178. if Apps.0 = 0 then
  179. do
  180. call ToStderr 'ERROR: INI file "'ARG(1)'" does not exist (or may be corrupt).'
  181. PgmExit( SourceLine() )
  182. end
  183. do i = 1 to Apps.0
  184. if ARG(2) <> "" then
  185. do
  186. parse UPPER VAR Apps.i UpperApplication
  187. if pos(UpperDumpSpec, UpperApplication) = 0 then iterate
  188. end
  189. call SysIni ARG(1), Apps.i, 'All:', 'Keys'
  190. if Result = 'ERROR:' then
  191. do
  192. call ToStderr 'Could not obtain List of Keys for APPLICATION = 'Apps.i
  193. call AddSeperator ARG(1)
  194. InvalidCount = InvalidCount + 1
  195. iterate
  196. end
  197. do j=1 to Keys.0
  198. Value = SysIni( ARG(1), Apps.i, Keys.j)
  199. if Value = "ERROR:" then
  200. do
  201. InvalidCount = InvalidCount + 1
  202. say 'INVALID COMBINATION'
  203. say '~~~~~~~~~~~~~~~~~~~'
  204. say 'INI FILE   : "'ARG(1)'"'
  205. say 'APPLICATION: "'Apps.i'"'
  206. say 'KEY        : "'Keys.j'"'
  207. call AddSeperator ARG(1)
  208. end
  209. end
  210. end
  211. if  InvalidCount <> 0 then
  212. do
  213. call ToStderr InvalidCount" ERRORS WERE FOUND IN THE INI FILE!"
  214. PgmExit( SourceLine() )
  215. end
  216. else
  217. do
  218. say "No errors were found"
  219. PgmExit(0)
  220. end
  221. DumpIniValue:
  222. say 'APPLICATION: "'ARG(2)'"'
  223. say 'KEY        : "'ARG(3)'"'
  224. Value = SysIni( ARG(1), ARG(2), ARG(3))
  225. if Value = "ERROR:" then
  226. do
  227. say '<<INI READ FAILED>>'
  228. RETURN
  229. end
  230. StrLength   = length(Value)
  231. HasHex      = 'N'
  232. AsciiString = 'N'
  233. Position  = 1
  234. do while Position <= StrLength
  235. Character    = substr(Value, Position, 1)
  236. CharValue    = C2D(Character)
  237. if  CharValue < 32 | CharValue > 127 then
  238. do
  239. if Position = StrLength & HasHex = 'N' then
  240. do
  241. if CharValue = 0 then
  242. do
  243. AsciiString = 'Y'
  244. Value = left(Value, StrLength - 1)
  245. leave
  246. end
  247. end
  248. HasHex    = 'Y'
  249. end
  250. Position = Position + 1
  251. end
  252. if  HasHex = 'N' then
  253. do
  254. if  StrLength = 0 then
  255. say "VALUE      : <<Zero Length Data>>"
  256. else
  257. do
  258. if   AsciiString = 'Y' then
  259. say 'STRING     : "'Value'"'
  260. else
  261. say 'VALUE      : "'Value'"'
  262. end
  263. RETURN
  264. end
  265. say "VALUE:"
  266. say "~~~~~~"
  267. AsciiStr     = ""
  268. HexStr       = ""
  269. WantSpace    = 'Y'
  270. Position     = 1
  271. PositionRel0 = 0
  272. do while Position <= StrLength
  273. if PositionRel0 // 16 = 0 then
  274. do
  275. if  AsciiStr \== "" then
  276. do
  277. say left(HexStr, 41) || '  | ' || AsciiStr || ' |' 
  278. AsciiStr  = ""
  279. HexStr    = ""
  280. WantSpace = 'Y'
  281. end
  282. call charout , D2X(PositionRel0, 4)":"
  283. end
  284. Character    = substr(Value, Position, 1)
  285. CharHexValue = C2X(Character)
  286. CharValue    = C2D(Character)
  287. if  CharValue < 32 | CharValue > 127 then Character = '.'
  288. if  WantSpace = 'Y' then
  289. do
  290. HexStr    = HexStr' 'CharHexValue
  291. WantSpace = 'N'
  292. end
  293. else
  294. do
  295. HexStr    = HexStr''CharHexValue
  296. WantSpace = 'Y'
  297. end
  298. AsciiStr     = AsciiStr''Character
  299. Position     = Position     + 1
  300. PosItionRel0 = PosItionRel0 + 1
  301. end
  302. if  AsciiStr \== "" then
  303. do
  304. say left(HexStr, 41) || '  | ' || left(AsciiStr, 16) || ' |' 
  305. end
  306. RETURN
  307. AddSeperator:
  308. Padding = length(ARG(1))
  309. Padding = (79 - Padding) - 3
  310. say ""
  311. say copies('#', Padding) || ' : ' || ARG(1)
  312. RETURN
  313. SyntaxError:
  314. ErrorLine = SIGL
  315. call ToStderr "[]----------------------------------------------------------[]"
  316. call ToStderr "| INIREAD.CMD, Version " || PGM_VERSION || " (C)opyright Dennis Bareis 1993 |"
  317. call ToStderr '|      http://www.ozemail.com.au/~dbareis (db0@anz.com)      |'
  318. call ToStderr "[]----------------------------------------------------------[]"
  319. call ToStderr ""
  320. call ToStderr "This program dumps the value of a specific application & key component from"
  321. call ToStderr "the specified INI file.  You can also dump INI values by specifying a"
  322. call ToStderr "ApplicationPart which should be contained in an INI Application name, the"
  323. call ToStderr "whole INI is then searched (case insensitive) for matching entries."
  324. call ToStderr ""
  325. call ToStderr "There is another mode where selected INI entries will be tested, if a"
  326. call ToStderr "application/key value can be read it is concidered OK.  Invalid entries"
  327. call ToStderr "are reported."
  328. call ToStderr ""
  329. call ToStderr "CORRECT SYNTAX:"
  330. call ToStderr "        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ![ApplicationPartSubStr]  or"
  331. call ToStderr "        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName *[ApplicationPartSubStr]  or"
  332. call ToStderr "        INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ApplicationPart KeyPart "
  333. call ToStderr ""
  334. call ToStderr "Example to dump whole USER INI file (usually C:\OS2\OS2.INI):"
  335. call ToStderr "        (a) INIREAD.CMD  USER *   (b) INIREAD.CMD C:\OS2\OS2.INI *"
  336. call ToStderr ""
  337. call ToStderr ARG(1)
  338. PgmExit(ErrorLine)
  339. PgmExit:
  340. call FastIniCleanup
  341. exit( arg(1) )
  342. CommonTrapHandler:
  343. FailingLine     = arg(1)
  344. TrapHeading     = 'BUG: ' || arg(2)
  345. TextDescription = arg(3)
  346. Text            = arg(4)
  347. parse source . . SourceFileName
  348. call ToStderr "" || copies('=+', 39)
  349. call ToStderr TrapHeading
  350. call ToStderr copies('~', length(TrapHeading))
  351. call ToStderr substr(TextDescription, 1 , 16) || ': ' || Text
  352. call ToStderr 'Failing Module  : ' || SourceFileName
  353. call ToStderr 'Failing Line #  : ' || FailingLine
  354. call ToStderr 'Failing Command : ' || strip(SourceLine(FailingLine))
  355. call ToStderr copies('=+', 39) || ""
  356. PgmExit(FailingLine)
  357. RexxTrapUninitializedVariable:
  358. call CommonTrapHandler SIGL, 'NoValue Abort!', 'Unknown Variable', condition('D')
  359. RexxTrapSyntaxError:
  360. call CommonTrapHandler SIGL, 'Syntax Error!', 'Reason', errortext(Rc)
  361. RexxCtrlC:
  362. LineCtrlC = SIGL
  363. call ToStderr ''
  364. call ToStderr "" || copies('=+', 39)
  365. call ToStderr "Come on, you pressed Ctrl+C or Break didn't you!"
  366. call ToStderr copies('=+', 39) || ""
  367. PgmExit(LineCtrlC)
  368. SourceLine:
  369. return(SIGL)
  370. qsCompFunc: PROCEDURE
  371. parse arg a, b
  372. select
  373. when ( a < b ) then
  374. return(-1)
  375. when ( a > b ) then
  376. return(1)
  377. otherwise
  378. return(0)
  379. end
  380. QuickSort: PROCEDURE EXPOSE atmp.
  381. parse arg top, down
  382. if ( ( down-top ) < 2 ) then
  383. do
  384. if ( ( down - top ) > 0 ) then
  385. /* if ( atmp.top > atmp.down ) then */
  386. if ( qsCompFunc( atmp.top, atmp.down ) > 0 ) then
  387. do
  388. tmpval      = atmp.top
  389. atmp.top    = atmp.down
  390. atmp.down   = tmpval
  391. end
  392. end
  393. else
  394. do
  395. l = top
  396. r = down
  397. m = top + trunc( ( down-top )/2 )
  398. do while ( l<r )
  399. m_val = atmp.m
  400. /* do while ( atmp.l < m_val ) */
  401. do while ( qsCompFunc( atmp.l, m_val ) < 0 )
  402. if  ( l < m ) then
  403. l=l+1
  404. else
  405. leave
  406. end
  407. /* do while ( atmp.r > m_val ) */
  408. do while ( qsCompFunc( atmp.r, m_val ) > 0 )
  409. if  ( m < r ) then
  410. r=r-1
  411. else
  412. leave
  413. end
  414. if ( l < r ) then
  415. do
  416. tmpval = atmp.l
  417. atmp.l = atmp.r
  418. atmp.r = tmpval
  419. select
  420. when ( m=r ) then
  421. do
  422. r = r-1
  423. m = l
  424. end
  425. when ( m=l ) then
  426. do
  427. l = l+1
  428. m = r
  429. end
  430. otherwise
  431. do
  432. l = l+1
  433. r = r-1
  434. end
  435. end
  436. end
  437. end
  438. if ( ( r-top ) < ( down-l ) ) then
  439. do
  440. call quicksort top, m-1
  441. call quicksort m+1, down
  442. end
  443. else
  444. do
  445. call quicksort m+1, down
  446. call quicksort top, m-1
  447. end
  448. end
  449. return
  450.