home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
ifr98148.zip
/
INIREAD.CMD
Wrap
OS/2 REXX Batch file
|
1998-05-28
|
11KB
|
450 lines
/*
* Pgm Name : E:\DB\BATCH\CMD\HTMLPP.CMD
* Pgm Version : 98.144
* Time : Thursday, 28 May 1998 6:13:22pm
* Input File : E:\DB\PROJECTS\OS2\iniread\INIREAD.X
* Output File : .\OUT\INIREAD.CMD
*/
PGM_VERSION = "98.148"
call RxFuncAdd 'SysIni', 'RexxUtil', 'SysIni'
call RxFuncAdd 'SysFileTree', 'RexxUtil', 'SysFileTree'
/*
* FASTINI.XH Version 98.147 by Dennis Bareis
* http://www.ozemail.com.au/~dbareis (db0@anz.com)
*/
_FiOpenCount = 0
call RxFuncAdd 'FastIniStart', 'FastIni', 'FastIniStart'
call RxFuncAdd 'FastIniEnd', 'FastIni', 'FastIniEnd'
call RxFuncAdd 'FastIniVersion', 'FastIni', 'FastIniVersion'
_fiAvailable = _FastIniOk()
signal EndFASTINIXh
FastIniIsFast:
return(_fiAvailable)
FastIniOpenIni:
_fiFile = arg(1)
_fiHandleVar = arg(2)
if _fiAvailable = 'N' then
do
interpret _fiHandleVar || ' = 0'
return('OK')
end
interpret _fiHandleVar || ' = ""'
_fiFastRc = FastIniStart(_fiFile, _fiHandleVar)
interpret '_FiHandle = ' || _fiHandleVar
if _FiHandle <> '' then
do
_FiOpenCount = _FiOpenCount + 1
_FiOpenedList._FiOpenCount = _FiHandle
end
return(_fiFastRc)
FastIniCloseIni:
if _fiAvailable = 'N' then
return('OK')
return( FastIniEnd(arg(1)) )
FastIniGetVersion:
if _fiAvailable = 'Y' then
return( FastIniVersion(arg(1)) )
else
do
interpret arg(1) || ' = "00.000 http://www.ozemail.com.au/~dbareis db0@anz.com Dennis Bareis"'
return('OK')
end
FastIniCleanup:
if _fiAvailable = 'N' then
return('OK')
do _fi = 1 to _FiOpenCount
call FastIniEnd(_FiOpenedList._fi)
_FiOpenedList._fi = 0
end
_FiOpenCount = 0
return('OK')
_FastIniOk:
signal on SYNTAX name _FastIniNotOk
interpret "_fiRc = FastIniVersion('_fiVersion')"
return('Y')
_FastIniNotOk:
return('N')
EndFASTINIXh:
signal on HALT name RexxCtrlC
signal on NOVALUE name RexxTrapUninitializedVariable
signal on SYNTAX name RexxTrapSyntaxError
Args = ARG(1)
Args = strip(Args)
PARSE VAR Args IniFile Application Key
if IniFile = "" then
call SyntaxError 'ERROR: Expected "USER", "SYSTEM", "BOTH", or the name of an .INI file...'
parse UPPER VAR IniFile IniFile
if IniFile <> "USER" & IniFile <> "SYSTEM" & IniFile <> "BOTH" then
do
TreeRc = SysFileTree(IniFile, 'FileBase', 'FO')
if TreeRc <> 0 | FileBase.0 = 0 then
do
call ToStderr 'ERROR: The INI file "' || IniFile || '" does not exist.'
PgmExit( SourceLine() )
end
end
FastRc = FastIniOpenIni(IniFile, "IniHandle")
if FastRc <> 'OK' then
call ToStderr "FASTINI.DLL can not be accessed (" || FastRc || ').'
if Application = "" then
call SyntaxError 'ERROR: Expected the "APPLICATION" key part, or "*SubStr", or "*" for all.'
if left(Application,1) = "!" then
do
Application = substr(Application, 2)
call CheckWholeIni IniFile, Application
PgmExit(0)
end
if left(Application,1) = "*" then
do
Application = substr(Application, 2)
call DumpWholeIni IniFile, Application
PgmExit(0)
end
else
do
if Key = "" then
call SyntaxError "ERROR: Expected a key to identify the value to be dumped..."
call Dump1Key IniFile, Application, Key
PgmExit(0)
end
ToStderr:
call lineout 'STDERR', arg(1)
return
Dump1Key:
call DumpIniValue ARG(1), ARG(2), ARG(3)
PgmExit(0)
DumpWholeIni:
UpperDumpSpec = ARG(2)
parse UPPER VAR UpperDumpSpec UpperDumpSpec
call rxfuncadd 'sysloadfuncs', 'rexxutil', 'sysloadfuncs'
call sysloadfuncs
call SysIni ARG(1), 'All:', 'aTmp'
if Result = 'ERROR:' then
do
call ToStderr 'ERROR: Could not obtain list of APPLICATION keys.'
RETURN
end
if aTmp.0 = 0 then
do
call ToStderr 'ERROR: INI file "'ARG(1)'" does not exist, or contains no data.'
RETURN
end
call quicksort 1, aTmp.0
do i = 0 to aTmp.0
Apps.i = aTmp.i
end
do i = 1 to Apps.0
if ARG(2) <> "" then
do
parse UPPER VAR Apps.i UpperApplication
if pos(UpperDumpSpec, UpperApplication) = 0 then iterate
end
call SysIni ARG(1), Apps.i, 'All:', 'aTmp'
if Result = 'ERROR:' then
do
call ToStderr 'Could not obtain List of Keys for APPLICATION = 'Apps.i
call AddSeperator ARG(1)
iterate
end
if aTmp.0 = 0 then
do
call ToStderr 'There are no keys for application "'Apps.i'".'
iterate
end
call quicksort 1, aTmp.0
do j = 0 to aTmp.0
Keys.j = aTmp.j
end
do j=1 to Keys.0
call AddSeperator ARG(1)
call DumpIniValue ARG(1), Apps.i, Keys.j
end
end
PgmExit(0)
CheckWholeIni:
say 'Checking INI = 'ARG(1)', please wait...'
InvalidCount = 0
UpperDumpSpec = ARG(2)
parse UPPER VAR UpperDumpSpec UpperDumpSpec
call rxfuncadd sysloadfuncs, rexxutil, sysloadfuncs
call sysloadfuncs
call SysIni ARG(1), 'All:', 'Apps.'
if Result = 'ERROR:' then
do
call ToStderr 'ERROR: Could not obtain list of APPLICATION keys.'
PgmExit( SourceLine() )
end
if Apps.0 = 0 then
do
call ToStderr 'ERROR: INI file "'ARG(1)'" does not exist (or may be corrupt).'
PgmExit( SourceLine() )
end
do i = 1 to Apps.0
if ARG(2) <> "" then
do
parse UPPER VAR Apps.i UpperApplication
if pos(UpperDumpSpec, UpperApplication) = 0 then iterate
end
call SysIni ARG(1), Apps.i, 'All:', 'Keys'
if Result = 'ERROR:' then
do
call ToStderr 'Could not obtain List of Keys for APPLICATION = 'Apps.i
call AddSeperator ARG(1)
InvalidCount = InvalidCount + 1
iterate
end
do j=1 to Keys.0
Value = SysIni( ARG(1), Apps.i, Keys.j)
if Value = "ERROR:" then
do
InvalidCount = InvalidCount + 1
say 'INVALID COMBINATION'
say '~~~~~~~~~~~~~~~~~~~'
say 'INI FILE : "'ARG(1)'"'
say 'APPLICATION: "'Apps.i'"'
say 'KEY : "'Keys.j'"'
call AddSeperator ARG(1)
end
end
end
if InvalidCount <> 0 then
do
call ToStderr InvalidCount" ERRORS WERE FOUND IN THE INI FILE!"
PgmExit( SourceLine() )
end
else
do
say "No errors were found"
PgmExit(0)
end
DumpIniValue:
say 'APPLICATION: "'ARG(2)'"'
say 'KEY : "'ARG(3)'"'
Value = SysIni( ARG(1), ARG(2), ARG(3))
if Value = "ERROR:" then
do
say '<<INI READ FAILED>>'
RETURN
end
StrLength = length(Value)
HasHex = 'N'
AsciiString = 'N'
Position = 1
do while Position <= StrLength
Character = substr(Value, Position, 1)
CharValue = C2D(Character)
if CharValue < 32 | CharValue > 127 then
do
if Position = StrLength & HasHex = 'N' then
do
if CharValue = 0 then
do
AsciiString = 'Y'
Value = left(Value, StrLength - 1)
leave
end
end
HasHex = 'Y'
end
Position = Position + 1
end
if HasHex = 'N' then
do
if StrLength = 0 then
say "VALUE : <<Zero Length Data>>"
else
do
if AsciiString = 'Y' then
say 'STRING : "'Value'"'
else
say 'VALUE : "'Value'"'
end
RETURN
end
say "VALUE:"
say "~~~~~~"
AsciiStr = ""
HexStr = ""
WantSpace = 'Y'
Position = 1
PositionRel0 = 0
do while Position <= StrLength
if PositionRel0 // 16 = 0 then
do
if AsciiStr \== "" then
do
say left(HexStr, 41) || ' | ' || AsciiStr || ' |'
AsciiStr = ""
HexStr = ""
WantSpace = 'Y'
end
call charout , D2X(PositionRel0, 4)":"
end
Character = substr(Value, Position, 1)
CharHexValue = C2X(Character)
CharValue = C2D(Character)
if CharValue < 32 | CharValue > 127 then Character = '.'
if WantSpace = 'Y' then
do
HexStr = HexStr' 'CharHexValue
WantSpace = 'N'
end
else
do
HexStr = HexStr''CharHexValue
WantSpace = 'Y'
end
AsciiStr = AsciiStr''Character
Position = Position + 1
PosItionRel0 = PosItionRel0 + 1
end
if AsciiStr \== "" then
do
say left(HexStr, 41) || ' | ' || left(AsciiStr, 16) || ' |'
end
RETURN
AddSeperator:
Padding = length(ARG(1))
Padding = (79 - Padding) - 3
say ""
say copies('#', Padding) || ' : ' || ARG(1)
RETURN
SyntaxError:
ErrorLine = SIGL
call ToStderr "[]----------------------------------------------------------[]"
call ToStderr "| INIREAD.CMD, Version " || PGM_VERSION || " (C)opyright Dennis Bareis 1993 |"
call ToStderr '| http://www.ozemail.com.au/~dbareis (db0@anz.com) |'
call ToStderr "[]----------------------------------------------------------[]"
call ToStderr ""
call ToStderr "This program dumps the value of a specific application & key component from"
call ToStderr "the specified INI file. You can also dump INI values by specifying a"
call ToStderr "ApplicationPart which should be contained in an INI Application name, the"
call ToStderr "whole INI is then searched (case insensitive) for matching entries."
call ToStderr ""
call ToStderr "There is another mode where selected INI entries will be tested, if a"
call ToStderr "application/key value can be read it is concidered OK. Invalid entries"
call ToStderr "are reported."
call ToStderr ""
call ToStderr "CORRECT SYNTAX:"
call ToStderr " INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ![ApplicationPartSubStr] or"
call ToStderr " INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName *[ApplicationPartSubStr] or"
call ToStderr " INIREAD[.CMD] USER|SYSTEM|BOTH|IniFileName ApplicationPart KeyPart "
call ToStderr ""
call ToStderr "Example to dump whole USER INI file (usually C:\OS2\OS2.INI):"
call ToStderr " (a) INIREAD.CMD USER * (b) INIREAD.CMD C:\OS2\OS2.INI *"
call ToStderr ""
call ToStderr ARG(1)
PgmExit(ErrorLine)
PgmExit:
call FastIniCleanup
exit( arg(1) )
CommonTrapHandler:
FailingLine = arg(1)
TrapHeading = 'BUG: ' || arg(2)
TextDescription = arg(3)
Text = arg(4)
parse source . . SourceFileName
call ToStderr "
" || copies('=+', 39)
call ToStderr TrapHeading
call ToStderr copies('~', length(TrapHeading))
call ToStderr substr(TextDescription, 1 , 16) || ': ' || Text
call ToStderr 'Failing Module : ' || SourceFileName
call ToStderr 'Failing Line # : ' || FailingLine
call ToStderr 'Failing Command : ' || strip(SourceLine(FailingLine))
call ToStderr copies('=+', 39) || ""
PgmExit(FailingLine)
RexxTrapUninitializedVariable:
call CommonTrapHandler SIGL, 'NoValue Abort!', 'Unknown Variable', condition('D')
RexxTrapSyntaxError:
call CommonTrapHandler SIGL, 'Syntax Error!', 'Reason', errortext(Rc)
RexxCtrlC:
LineCtrlC = SIGL
call ToStderr ''
call ToStderr "
" || copies('=+', 39)
call ToStderr "Come on, you pressed Ctrl+C or Break didn't you!"
call ToStderr copies('=+', 39) || ""
PgmExit(LineCtrlC)
SourceLine:
return(SIGL)
qsCompFunc: PROCEDURE
parse arg a, b
select
when ( a < b ) then
return(-1)
when ( a > b ) then
return(1)
otherwise
return(0)
end
QuickSort: PROCEDURE EXPOSE atmp.
parse arg top, down
if ( ( down-top ) < 2 ) then
do
if ( ( down - top ) > 0 ) then
/* if ( atmp.top > atmp.down ) then */
if ( qsCompFunc( atmp.top, atmp.down ) > 0 ) then
do
tmpval = atmp.top
atmp.top = atmp.down
atmp.down = tmpval
end
end
else
do
l = top
r = down
m = top + trunc( ( down-top )/2 )
do while ( l<r )
m_val = atmp.m
/* do while ( atmp.l < m_val ) */
do while ( qsCompFunc( atmp.l, m_val ) < 0 )
if ( l < m ) then
l=l+1
else
leave
end
/* do while ( atmp.r > m_val ) */
do while ( qsCompFunc( atmp.r, m_val ) > 0 )
if ( m < r ) then
r=r-1
else
leave
end
if ( l < r ) then
do
tmpval = atmp.l
atmp.l = atmp.r
atmp.r = tmpval
select
when ( m=r ) then
do
r = r-1
m = l
end
when ( m=l ) then
do
l = l+1
m = r
end
otherwise
do
l = l+1
r = r-1
end
end
end
end
if ( ( r-top ) < ( down-l ) ) then
do
call quicksort top, m-1
call quicksort m+1, down
end
else
do
call quicksort m+1, down
call quicksort top, m-1
end
end
return