home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
ifu98148.zip
/
INIWRITE.CMD
next >
Wrap
OS/2 REXX Batch file
|
1998-05-28
|
10KB
|
305 lines
/*
* Pgm Name : E:\DB\BATCH\CMD\HTMLPP.CMD
* Pgm Version : 98.144
* Time : Thursday, 28 May 1998 6:16:04pm
* Input File : E:\DB\PROJECTS\OS2\iniwrite\INIWRITE.x
* Output File : .\OUT\INIWRITE.CMD
*/
OneBeep = ''
TwoBeep = OneBeep || OneBeep
EscapeChar = d2c(27)
Reset = EscapeChar || '[0m'
ColorStartupMsg = EscapeChar || '[1;33m'
ColorInputLine = EscapeChar || '[1;33m'
ColorError = EscapeChar || '[1;31m'
ColorWarning = EscapeChar || '[1;35m'
ColorStatus = EscapeChar || '[32m'
call RxFuncAdd 'SysIni', 'RexxUtil', 'SysIni'
Indent = " * "
/*
* 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:
LastIni = ''
IniHandle = ''
if FastIniIsFast = 'N' then
call ToStderr "FASTINI.DLL can not be accessed (" || FastRc || ').'
signal on HALT name RexxCtrlC
signal on NOVALUE name RexxTrapUninitializedVariable
signal on SYNTAX name RexxTrapSyntaxError
call DisplayLine ColorStartupMsg, '[]--------------------------------------------------------------[]'
call DisplayLine ColorStartupMsg, '| INIWRITE.CMD: Version 98.148 (C)opyright Dennis Bareis 1997 |'
call DisplayLine ColorStartupMsg, '| http://www.ozemail.com.au/~dbareis (db0@anz.com) |'
call DisplayLine ColorStartupMsg, '[]--------------------------------------------------------------[]'
say ''
CommandLine = strip( arg(1) )
if CommandLine = '' then
UserSyntaxError("Expected at least one parameter")
if left(CommandLine, 1) <> '@' then
do
ScriptFile = ''
parse var CommandLine '"'App Key KeyCmd'"'Crap
if Crap <> '' then
UserSyntaxError("Supplied update command is not correctly quoted!")
SingleCommand = App || ' ' Key || ' ' || KeyCmd
call DisplayLine ColorInputLine, SingleCommand
PgmExit( ProcessOneCommand('USER', SingleCommand) )
end
ScriptFile = substr(CommandLine, 2)
if ScriptFile = '' then
do
call DisplayLine ColorError, 'ERROR: Expected to find the name of a file after the "@" character!'
PgmExit(ThisLineNumber())
end
call stream ScriptFile, 'c', 'close'
if stream(ScriptFile, 'c', 'query exists') = '' then
do
call DisplayLine ColorError, 'ERROR: The script file "' || ScriptFile || '" does not exist!' || TwoBeep
PgmExit(ThisLineNumber())
end
call stream ScriptFile, 'c', 'open read'
LineNumber = 0
ExitRc = 0
do while lines(ScriptFile) <> 0
Line = LINEIN(ScriptFile)
Line = strip(Line)
LineNumber = LineNumber + 1
if Line = "" | left(Line, 1) = ";" then
iterate
CmdSource = filespec('name', ScriptFile) || '(' || LineNumber || ')'
call DisplayLine ColorInputLine, CmdSource || ': ' || Line
ProcessRc = ProcessOneCommand(CmdSource, Line)
if ProcessRc <> 0 then
ExitRc = ProcessRc
end
CommandErrorExit:
if IniHandle <> '' then
FastRc = FastIniCloseIni(IniHandle)
call stream ScriptFile, 'c', 'close'
if ExitRc <> 0 then
do
say ''
call DisplayLine ColorError, 'ERROR: The script "' || ScriptFile || '" terminated abnormally (on line #' || LineNumber || ')...' || OneBeep
end
PgmExit(ExitRc)
ProcessOneCommand:
CmdSource = arg(1)
Cmd = arg(2)
parse var Cmd IniFileName ApplicationName KeyName IniWriteCommand
if ApplicationName = "" then
do
call DisplayLine ColorError, Indent || 'ERROR: not enough information on the line...'
return(ThisLineNumber())
end
IniWriteCommand = strip(IniWriteCommand)
IniFileName = SubstituteStandardCodes(IniFileName, "INI Filename")
ApplicationName = SubstituteStandardCodes(ApplicationName, "Application Name")
KeyName = SubstituteStandardCodes(KeyName, "Key Name")
if LastIni <> IniFileName then
do
if IniHandle <> '' then
FastRc = FastIniCloseIni(IniHandle)
FastRc = FastIniOpenIni(IniFileName, "IniHandle")
LastIni = IniFileName
end
if KeyName = 'DELETE:' | KeyName = '"DELETE:"' | KeyName = "'DELETE:'" then
do
call DisplayLine ColorStatus, Indent || 'Deleting the Application "' || ApplicationName || '"...'
SysIniRc = SysIni(IniFileName, ApplicationName, "DELETE:")
end
else
do
if IniWriteCommand = 'DELETE:' | IniWriteCommand = '"DELETE:"' | IniWriteCommand = "'DELETE:'" then
do
call DisplayLine ColorStatus, Indent || 'Deleting the Key "' || ApplicationName || '" + "' || KeyName || '"...'
SysIniRc = SysIni(IniFileName, ApplicationName, KeyName, "DELETE:")
if SysIniRc = "ERROR:" then
do
call DisplayLine ColorWarning, Indent || 'Warning, this key probably did not exist...'
SysIniRc = "WARNING"
end
end
else
do
if IniWriteCommand = "" then
do
call DisplayLine ColorError, Indent || 'ERROR: Not enough parameters specified to update INI...'
return(ThisLineNumber())
end
ExecuteTheCommand = 'NewIniValue = ' || IniWriteCommand
signal ON SYNTAX name InvalidIniWriteCommand
signal ON NOVALUE name InvalidIniWriteCommand
interpret ExecuteTheCommand
signal OFF SYNTAX
signal OFF NOVALUE
OldIniValue = SysIni(IniFileName, ApplicationName, KeyName)
NeedToUpdateIni = 'Y'
if OldIniValue = "ERROR:" then
call DisplayLine ColorStatus, Indent || 'Adding the Key "' || ApplicationName || '" + "' || KeyName || '"...'
else
do
if OldIniValue \== NewIniValue then
call DisplayLine ColorStatus, Indent || 'Updating the INI files value...'
else
do
call DisplayLine ColorStatus, Indent || 'New value same as old (no need to update).'
NeedToUpdateIni = 'N'
end
end
if NeedToUpdateIni = 'Y' then
SysIniRc = SysIni(IniFileName, ApplicationName, KeyName, NewIniValue)
else
SysIniRc = "NotUpdatedAsValuesEqual"
end
end
if SysIniRc = "ERROR:" then
do
call DisplayLine ColorError, Indent || 'ERROR: update failed...'
return(ThisLineNumber())
end
return(0)
SubstituteStandardCodes:
BeforeString = arg(1)
AfterString = SubstituteOneStandardCode(BeforeString, "{Space}", " ")
if BeforeString <> AfterString then
call DisplayLine ColorStatus, Indent || 'At least 1 standard code was substituted in the ' || arg(2) || '...'
return(AfterString)
UserSyntaxError:
call ToStderr "SYNTAX ERROR"
call ToStderr "~~~~~~~~~~~~"
call ToStderr ' ' || arg(1)
call ToStderr ''
call ToStderr 'CORRECT SYNTAX'
call ToStderr '~~~~~~~~~~~~~~'
call ToStderr ' INIWRITE[.CMD] @ChangesFile | "OneChangeLine"'
call ToStderr ''
call ToStderr 'EXAMPLES'
call ToStderr '~~~~~~~~'
call ToStderr ' INIWRITE.CMD @C:\Changes.LST'
call ToStderr ' INIWRITE.CMD "' || "C:\TEST.INI AppName KeyName 'null terminated' || d2c(0)" || '"'
call ToStderr ' INIWRITE.CMD "' || "USER Shield fMaximize '0100'x" || '"'
call ToStderr ' INIWRITE.CMD "' || "USER Shield ~Font{Space}Size... '06 0a'x" || '"'
call ToStderr ' INIWRITE.CMD "' || "user Shield sInitialShape 'DELETE:'" || '"'
call ToStderr ''
call ToStderr 'Please see "INIWRITE.INF" for more details.'
call ToStderr TwoBeep
PgmExit(ThisLineNumber())
SubstituteOneStandardCode:
TheString = arg(1)
Before = arg(2)
FoundPos = pos(Before, TheString)
if FoundPos <> 0 then
do
After = arg(3)
LengthBefore = length(Before)
do until FoundPos = 0
TheString = left(TheString, FoundPos - 1) || After || substr(TheString, FoundPos+LengthBefore)
FoundPos = pos(Before, TheString)
end
end
return(TheString)
DisplayLine:
call charout, arg(1)
say arg(2)
call charout, Reset
return
InvalidIniWriteCommand:
if condition('C') = 'NOVALUE' then
call DisplayLine ColorError, Indent || 'ERROR: Incorrectly quoted string (i.e. ' || condition('D') || ')!'
else
call DisplayLine ColorError, Indent || 'ERROR: REXX Syntax error (New INI value was invalid)!'
call DisplayLine ColorError, Indent || 'Failing Command: ' || ExecuteTheCommand
if ScriptFile <> '' then
CloseRc = stream(ScriptFile, 'c', 'close')
PgmExit(ThisLineNumber())
CommonTrapHandler:
FailingLine = arg(1)
TrapHeading = 'BUG: ' || arg(2)
TextDescription = arg(3)
Text = arg(4)
parse source . . SourceFileName
call ToStderr ColorError || 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) || Reset
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 ColorError || copies('=+', 39)
call ToStderr "Come on, you pressed Ctrl+C or Break didn't you!"
call ToStderr copies('=+', 39) || Reset
PgmExit(LineCtrlC)
ThisLineNumber:
return(SIGL)
GetEnv:
return( value(arg(1),,'OS2ENVIRONMENT') )
ToStderr:
call lineout 'STDERR', arg(1)
return
PgmExit:
call FastIniCleanup
exit( arg(1) )