home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 18 REXX
/
18-REXX.zip
/
tem98233.zip
/
TEMPLATE.CMD
< prev
next >
Wrap
OS/2 REXX Batch file
|
1998-08-21
|
36KB
|
1,274 lines
/*
* Pgm Name : E:\DB\BATCH\CMD\PPWIZARD.CMD
* Pgm Version : 98.233
* Time : Friday, 21 Aug 1998 8:30:48pm
* Input File : E:\DB\PROJECTS\OS2\template\TEMPLATE.X
* Output File : .\OUT\TEMPLATE.CMD
*/
/*
* $Header: E:/DB/PVCS.IT/OS2/TEMPLATE/TEMPLATE.X_V 1.1 21 Aug 1998 20:30:42 Dennis_Bareis $/template/Template.x_v 1.0 16 Jan 1998 16:19:40 Dennis_Bareis $
*/
PgmVersion = "98.233"
Aborting = 'N'
say '[]--------------------------------------------------------------------------[]'
say '| TEMPLATE.CMD, v' || PgmVersion || ' (C)opyright Dennis Bareis 1998. All Rights Reserved. |'
say '| http://www.ozemail.com.au/~dbareis (db0@anz.com) |'
say '[]--------------------------------------------------------------------------[]'
say ''
/*
* REXSYSTM.XH Version 98.232 By Dennis Bareis
* http://www.ozemail.com.au/~dbareis (db0@anz.com)
*/
parse version RexVersionInfo
if pos('REGINA', translate(RexVersionInfo)) <> 0 then
RexWhich = 'REGINA'
else
RexWhich = 'STANDARD_OS/2'
parse source RexSystemOpSys .
if RexSystemOpSys = "WIN32" then
do
parse value uname() with RexSystemOpSys .
if RexSystemOpSys <> "WIN95" & RexSystemOpSys <> "WINNT" then
do
call RexSystemFailure 'Regina uname() returned "' || uname() || '" (expected WIN95 or WINNT)'
end
end
RexSystmRexxPgmName = '?'; RexSystmRexxPgmName = RexGetFullSourceName()
if arg(2) <> '' then
call RexSystemFailure 'ARG(2) contains unexpected data of ' || arg(2) || '.'
if translate(strip(arg(1))) = 'DEBUG' then
do
call RexDumpSystemInfo
exit(0)
end
if RexWhich = 'STANDARD_OS/2' then
do
call RxFuncAdd 'SysFileDelete', 'RexxUtil', 'SysFileDelete'
call RxFuncAdd 'SysSearchPath', 'RexxUtil', 'SysSearchPath'
call SetLocal
RexEnvVarPool = 'OS2ENVIRONMENT'
RexStdoutStream = 'STDOUT'
RexStderrStream = 'STDERR'
end
else
do
OPTIONS NOEXT_COMMANDS_AS_FUNCS
RexEnvVarPool = 'SYSTEM'
RexStdoutStream = '<stdout>'
RexStderrStream = '<stderr>'
end
OverrideId = GetEnv("REXSYSTM_OPSYS")
if OverrideId <> '' then
RexSystemOpSys = OverrideId
signal EndREXSYSTMXh
RexDumpSystemInfo:
say 'Program Name : ' || RexSystmRexxPgmName
say 'Op System : ' || RexSystemOpSys
say 'Rexx Ver : ' || RexVersionInfo
say 'Which System : ' || RexWhich
if RexWhich = 'REGINA' then
say 'regina uname(): ' || uname()
return
RexNeedReginaWorkAround:
if RexWhich = 'STANDARD_OS/2' then
return('N')
else
return('Y')
RexGetFullSourceName:
parse source . . TmpRexxSrc
if RexWhich = 'REGINA' then
TmpRexxSrc = stream(strip(TmpRexxSrc), 'c', 'query exists')
if TmpRexxSrc = '' then
call RexSystemFailure 'Could not determine the name of the rexx program!'
return(TmpRexxSrc)
RexQueryExists:
return( stream(arg(1), 'c', 'query exists') )
RexGetNameOfTmpDir:
TmpDir = GetEnv('TMP')
if TmpDir = '' then
TmpDir = GetEnv('TEMP')
return(TmpDir)
Stderr2:
if RexSystemOpSys = "DOS" | RexSystemOpSys = "WIN95" then
return('')
else
return(' 2>' || arg(1))
AddressCmd:
if RexWhich = 'STANDARD_OS/2' then
address cmd '@' || arg(1)
else
do
if RexSystemOpSys = "DOS" | RexSystemOpSys = "WIN95" then
address command arg(1)
else
address command '@' || arg(1)
end
return(Rc)
_SysFileDelete:
if RexWhich = 'STANDARD_OS/2' then
return( SysFileDelete(arg(1)) )
if RexSystemOpSys = "DOS" | RexSystemOpSys = "WIN95" then
return( AddressCmd('if exist ' || arg(1) || ' del ' || arg(1) || ' > nul') )
else
return( AddressCmd('del ' || arg(1) || ' > nul ' || Stderr2('&1')) )
_SysSearchPath:
if RexWhich = 'STANDARD_OS/2' then
return( SysSearchPath(arg(1),arg(2)) )
SspPath = GetEnv(arg(1))
if SspPath = '' then
return('')
do while SspPath <> ''
parse var SspPath SspThisFile';'SspPath
if right(SspThisFile, 1) <> '\' then
SspThisFile = SspThisFile || '\'
SspThisFile = RexQueryExists(SspThisFile || arg(2))
if SspThisFile <> '' then
return(SspThisFile)
end
return('')
GetEnv:
return( value(arg(1),, RexEnvVarPool) )
SetEnv:
return( value(arg(1), arg(2), RexEnvVarPool) )
EndREXSYSTMXh:
if RexWhich = 'STANDARD_OS/2' then
call RxFuncAdd 'SysCurPos', 'RexxUtil', 'SysCurPos'
/*
* ADDCOMMA.XH Version 98.090 by Dennis Bareis
* http://www.ozemail.com.au/~dbareis (db0@anz.com)
*/
signal EndOfADDCOMMACode
AddCommasToDecimalNumber: procedure
NoComma = strip( arg(1) )
if pos(',', NoComma) <> 0 then
return(NoComma)
DotPos = pos('.', NoComma)
if DotPos = 0 then
AfterDecimal = ''
else
do
if DotPos = 1 then
return("0" || NoComma)
AfterDecimal = substr(NoComma, DotPos+1)
NoComma = left(NoComma, DotPos-1)
end
NoComma = reverse(NoComma)
ResultWithCommas = ""
do while length(NoComma) > 3
ResultWithCommas = ResultWithCommas || left(NoComma, 3) || ','
NoComma = substr(NoComma, 4)
end
ResultWithCommas = ResultWithCommas || NoComma
ResultWithCommas = reverse(ResultWithCommas)
if AfterDecimal <> '' then
ResultWithCommas = ResultWithCommas || '.' || AfterDecimal
return(ResultWithCommas)
EndOfADDCOMMACode:
signal on HALT name RexxCtrlC
signal on NOVALUE name RexxTrapUninitializedVariable
signal on SYNTAX name RexxTrapSyntaxError
InLineCmt = ';' || ';'
Tt.OutputFile = ''
DebugMode = 'N'
IncludeLevel = 0
call SetupHashVariables '#'
ValidIfOutsideOrInPrompt = '-' || 'P'
CmdState = '-'
Parameters = arg(1)
parse var Parameters TemplateFile GeneratedFileBase Crap
if GeneratedFileBase = '' | Crap <> '' then
CmdlineSyntaxError("Invalid number of parameters (2 expected)!")
if stream(TemplateFile, 'c', 'query exists') = '' then
AbortProcessing('ERROR: The template file "' || TemplateFile || '" does not seem to exist...')
/*
* $Header: E:/DB/PVCS.IT/OS2/TEMPLATE/HASHIF.XHV 1.0 26 Jul 1998 10:44:12 Dennis_Bareis $/template/hashif.xhv 1.0 16 Jan 1998 16:19:38 Dennis_Bareis $
*/
IfNesting = 0
IfState.WantLines.0 = 'Y'
IfState.IfTrue.0 = 'Y'
IfState.InTrue.0 = 'Y'
signal EndHashIf
WantLine:
if IfNesting = 0 then
return('Y')
if IfState.WantLines.IfNesting = 'N' then
return('N')
else
do
if IfState.IfTrue.IfNesting = IfState.InTrue.IfNesting then
return('Y')
else
return('N')
end
ProcessHashIf:
TestCondition = arg(1)
WantTheLines = WantLine()
if WantTheLines = 'N' then
IfResult = 'N'
else
do
call SayIfDebugOn 'COMMAND: #if ' || TestCondition
interpret 'IfResult = (' || strip( TestCondition ) || ')'
if IfResult then
IfResult = 'Y'
else
IfResult = 'N'
if IfResult = 'Y' then
call SayIfDebugOn ' #if: True'
else
call SayIfDebugOn ' #if: False'
end
IfNesting = IfNesting + 1
IfState.WantLines.IfNesting = WantTheLines
IfState.InTrue.IfNesting = 'Y'
IfState.IfTrue.IfNesting = IfResult
return('OK')
ProcessHashElse:
if IfNesting = 0 then
AbortProcessing("Found #elseif without matching #if")
if IfState.InTrue.IfNesting = 'N' then
AbortProcessing("Found unexpected #elseif (duplicated #elseif?)")
IfState.InTrue.IfNesting = 'N'
return('OK')
ProcessHashEndif:
if IfNesting = 0 then
AbortProcessing("Found #endif without matching #if")
IfNesting = IfNesting - 1
return('OK')
EndHashIf:
/*
* $Header: E:/DB/PVCS.IT/OS2/TEMPLATE/DEFINE.XHV 1.0 26 Jul 1998 10:44:12 Dennis_Bareis $/template/define.xhv 1.0 16 Jan 1998 16:19:36 Dennis_Bareis $
*/
HashDefineCount = 0
G.StdVar.TemplateFile = translate(TemplateFile)
signal EndDefine
HashDefineExists:
do DefineIndex = 1 to HashDefineCount
if arg(1) = DefineVariable.DefineIndex then
return(DefineIndex)
end
return('N')
AddHashDefine:
DefineVariable = '{' || arg(1) || '}'
DefineContents = strip(arg(2))
ItExists = HashDefineExists(DefineVariable)
if ItExists <> 'N' then
do
SaveIndex = ItExists
end
else
do
HashDefineCount = HashDefineCount + 1
SaveIndex = HashDefineCount
end
DefineVariable.SaveIndex = DefineVariable
DefineContents.SaveIndex = DefineContents
return(0)
ReplaceHashAndStandardDefines:
HashDefineString = arg(1)
TotalChanges = 0
if pos("{", HashDefineString) <> 0 then
do
do until ChangeCount = 0
ChangeCount = 0
do DefineIndex = 1 to HashDefineCount
HashDefineString = ReplaceString(HashDefineString, DefineVariable.DefineIndex, DefineContents.DefineIndex, "ChangeCount")
end
TotalChanges = TotalChanges + ChangeCount
end
if pos("${", HashDefineString) <> 0 then
HashDefineString = ReplaceStandardDefinitions(HashDefineString, "TotalChanges")
end
if arg(2) <> '' then
interpret arg(2) || " = TotalChanges"
return(HashDefineString)
ReplaceStandardDefinitions:
DefineString = arg(1)
DefineString = ReplaceString(DefineString, "${Template}", G.StdVar.TemplateFile, arg(2))
if pos("${", DefineString) <> 0 then
do
DefineString = ReplaceString(DefineString, "${Version}", PgmVersion, arg(2))
ChangeTime = date('Weekday') || ', ' || date() || ' ' || GetAmPmTime()
DefineString = ReplaceString(DefineString, "${ChangeTime}", ChangeTime, arg(2))
end
return(DefineString)
ReplaceString:
TheString = arg(1)
ChangeFrom = arg(2)
ChangeTo = arg(3)
ChangeCntVar = arg(4)
LimitChange = arg(5)
if LimitChange = '' then
LimitChange = 99999
ChangeFromLength = length(ChangeFrom)
ChangeToLength = length(ChangeTo)
FoundPosn = pos(ChangeFrom, TheString)
ReplaceStringCounter = 0
do while FoundPosn <> 0 & LimitChange > 0
TheString = left(TheString, FoundPosn-1) || ChangeTo || substr(TheString, FoundPosn+ChangeFromLength)
FoundPosn = pos(ChangeFrom, TheString, FoundPosn+ChangeToLength)
ReplaceStringCounter = ReplaceStringCounter + 1
LimitChange = LimitChange - 1
end
if ChangeCntVar <> '' then
interpret ChangeCntVar || " = ReplaceStringCounter + " || ChangeCntVar
return(TheString)
EndDefine:
/*
* $Header: E:/DB/PVCS.IT/OS2/TEMPLATE/EVALUATE.XHV 1.0 26 Jul 1998 10:44:12 Dennis_Bareis $/template/evaluate.xhv 1.0 16 Jan 1998 16:19:36 Dennis_Bareis $
*/
signal EndEvaluate
ProcessEvaluate:
HashDefineAnswerName = GetQuotedText(arg(1), "Rest")
if Rest = '' then
CmdToEvaluate = HashDefineAnswerName
else
do
CmdToEvaluate = GetQuotedText(Rest, "Rest")
call ExpectNoMoreParms TheRest
end
signal ON SYNTAX NAME SyntaxErrorInEvaluateCommand
signal ON NOVALUE NAME UnknownVariableInEvaluateCommand
HashDefineRc = 0
if HashDefineAnswerName = '' then
do
FullCmdBeingEvaluated = CmdToEvaluate
interpret CmdToEvaluate
end
else
do
FullCmdBeingEvaluated = 'EvaluateAnswer = ' || CmdToEvaluate
interpret FullCmdBeingEvaluated
HashDefineRc = AddHashDefine(HashDefineAnswerName, EvaluateAnswer)
end
signal on NOVALUE name RexxTrapUninitializedVariable
signal on SYNTAX name RexxTrapSyntaxError
return(HashDefineRc)
SyntaxErrorInEvaluateCommand:
FailReason = errortext(RC)
AbortProcessing( 'Evaluate of "' || FullCmdBeingEvaluated || '" failed with syntax error (' || FailReason || ')' )
UnknownVariableInEvaluateCommand:
FailReason = "Variable=" || condition('D')
AbortProcessing( 'Evaluate of "' || FullCmdBeingEvaluated || '" failed with unknown variable (' || FailReason || ')' )
EndEvaluate:
/*
* $Header: E:/DB/PVCS.IT/OS2/REXXHDR/GETRESP.XHV 1.1 01 Jun 1998 17:57:56 Dennis_Bareis $
*/
GetRespVer = "98.152"
call RxFuncAdd 'SysCurPos', 'RexxUtil', 'SysCurPos'
call RxFuncAdd 'SysGetKey', 'RexxUtil', 'SysGetKey'
CursorTAvailable = 'Y'
trace off
CurrentCursorMode = -1
signal SkipOver_GETRESP
GetKeyFromUser:
if CursorTAvailable = 'Y' then
do
WantedCursorMode = !CmdLine.History.insert
if WantedCursorMode <> CurrentCursorMode then
do
if WantedCursorMode = "0" then
CursorSize = "0 15"
else
CursorSize = "13 15"
address cmd '@CursorT.EXE ' || CursorSize || ' >nul 2>&1'
if Rc = 0 then
CurrentCursorMode = WantedCursorMode
else
CursorTAvailable = 'N'
end
end
return( SysGetKey("NoEcho") )
GetRespErrorBeep:
call beep 400, 50
return
CmdLineProcedure: procedure expose !history. CurrentCursorMode
CmdLine:
CmdLine.Hidden=0
CmdLine.History=1
CmdLine.Keep=1
CmdLine.SameLine=0
CmdLine.Required=0
CmdLine.Reset=0
CmdLine.Valid=xrange()
CmdLine.Upper=0
CmdLine.Lower=0
CmdLine.Width=0
CmdLine.AutoSkip=0
/* DB$ */ EscapeCancels = 0; InitialValue = ""
parse value SysCurPos() with x y
do i=1 to arg()
cmd=translate(left(arg(i),1))
parm=""
if pos("=",arg(i))\=0 then
parse value arg(i) with ."="parm
select
when arg(i)="~Esc~" then
EscapeCancels=1
when cmd="B" then
do
parse value SysCurPos() with x y
if parm="" then
do
i = i + 1
parm=arg(i)
end
InitialValue = parm
end
when cmd="X" then
do
parse value SysCurPos() with x y
if parm="" then
do;i=i+1;parm=arg(i);end
if datatype(parm,"W") then
Call SysCurPos parm,y
end
when cmd="Y" then
do
parse value SysCurPos() with x y
if parm="" then
do;i=i+1;parm=arg(i);end
if datatype(parm,"W") then
Call SysCurPos x,parm
end
when cmd="T" then
do
if parm="" then
do;i=i+1;parm=arg(i);end
call charout, parm
end
when cmd="H" then
do
CmdLine.Hidden=1
CmdLine.Keep=0
CmdLine.History=0
end
when cmd="C" then
CmdLine.Reset=1
when cmd="O" then
!CmdLine.History.insert = 0
when cmd="I" then
!CmdLine.History.insert = 1
when cmd="F" then
CmdLine.Keep=0
when cmd="S" then
CmdLine.SameLine=1
when cmd="R" then
CmdLine.Required=1
when cmd="V" then
do
if parm="" then
do;i=i+1;parm=arg(i);end
CmdLine.Valid=parm
CmdLine.History=0
CmdLine.Keep=0
end
when cmd="U" then
do; CmdLine.Upper=1; CmdLine.Lower=0; CmdLine.History=0; CmdLine.Keep=0; end
when cmd="L" then
do; CmdLine.Upper=0; CmdLine.Lower=1; CmdLine.History=0; CmdLine.Keep=0; end
when cmd="A" then
CmdLine.AutoSkip=1
when cmd="W" then
do
if parm="" then
do;i=i+1;parm=arg(i);end
CmdLine.Width=parm
if \datatype(CmdLine.Width,"Whole") then CmdLine.Width=0
if CmdLine.Width<0 then CmdLine.Width=0
CmdLine.History=0
CmdLine.Keep=0
end
otherwise nop
end
end
if CmdLine.Width=0 then CmdLine.AutoSkip=0
if CmdLine.Reset then
do
drop !CmdLine.History.
return ""
end
if symbol("!CmdLine.History.0")="LIT" then
!CmdLine.History.0=0
if symbol("!CmdLine.History.insert")="LIT" then
!CmdLine.History.insert = 1
word = InitialValue
if word <> "" then
call charout, word
pos = length(word)
historical=-1
TheKey = GetKeyFromUser()
do forever
if TheKey=d2c(13) then
if CmdLine.Required & word="" then
call GetRespErrorBeep
else
leave
else if (TheKey=d2c(8)) then
do
if pos = 0 then
call GetRespErrorBeep
else
do
word=delstr(word,pos,1)
call rubout 1
pos=pos-1
if pos<length(word) then
do
if \CmdLine.Hidden then
call charout, substr(word,pos+1)||" "
else
call charout, copies("*",length(substr(word,pos+1)))||" "
call charout, copies(d2c(8),length(word)-pos+1)
end
end
end
else if TheKey=d2c(27) then
do
if EscapeCancels then
do
if word == '' then
do
word="~Esc~"
pos=0
leave
end
end
historical=-1
if pos<length(word) then
do
if \CmdLine.Hidden then
call charout, substr(word,pos+1)
else
call charout, copies("*",length(substr(word,pos+1)))
end
call rubout length(word)
word=""
pos=0
/*
*if pos<length(word) then
* if \CmdLine.Hidden then call charout, substr(word,pos+1)
* else call charout, copies("*",length(substr(word,pos+1)))
* call rubout length(word)
* word=""
* pos=0
*/
end
else if TheKey=d2c(10) | TheKey=d2c(9) then
nop
else if TheKey=d2c(224) | TheKey=d2c(0) then
do
key2 = GetKeyFromUser()
select
when key2=d2c(59) then
if (CmdLine.History) & (!CmdLine.History.0<>0) then
do
if symbol('search')='LIT' then
search=word
if symbol('LastFind')='LIT' then
search=word
else
do
if LastFind\=word then
search=word
end
if historical=-1 then
start=!CmdLine.History.0
else
start=historical-1
if start=0 then
start=!CmdLine.History.0
found=0
do i=start to 1 by -1
if abbrev(!CmdLine.History.i,search) then
do
found=1
historical=i
LastFind=!CmdLine.History.i
leave
end
end
if found then
do
if pos<length(word) then
do
if \CmdLine.Hidden then
call charout, substr(word,pos+1)
else
call charout, copies("*",length(substr(word,pos+1)))
end
call rubout length(word)
word=!CmdLine.History.historical
pos=length(word)
if \CmdLine.Hidden then
call charout, word
else
call charout, copies("*",length(word))
end
end
when key2=d2c(72) then
if (CmdLine.History) & (!CmdLine.History.0<>0) then
do
if historical=-1 then
historical=!CmdLine.History.0
else historical=historical-1
if historical=0 then
historical=!CmdLine.History.0
if pos<length(word) then
if \CmdLine.Hidden then call charout, substr(word,pos+1)
else call charout, copies("*",length(substr(word,pos+1)))
call rubout length(word)
word=!CmdLine.History.historical
pos=length(word)
if \CmdLine.Hidden then call charout, word
else call charout, copies("*",length(word))
end
when key2=d2c(80) then
if (CmdLine.History) & (!CmdLine.History.0<>0) then
do
if historical=-1 then
historical=1
else historical=historical+1
if historical>!CmdLine.History.0 then
historical=1
if pos<length(word) then
if \CmdLine.Hidden then call charout, substr(word,pos+1)
else call charout, copies("*",length(substr(word,pos+1)))
call rubout length(word)
word=!CmdLine.History.historical
pos=length(word)
if \CmdLine.Hidden then call charout, word
else call charout, copies("*",length(word))
end
when key2=d2c(75) then
if pos>0 then
do
call Charout, d2c(8)
pos=pos-1
end
when key2=d2c(77) then
if pos<length(word) then
do
if \CmdLine.Hidden then call Charout, substr(word,pos+1,1)
else call charout, "*"
pos=pos+1
end
when key2=d2c(115) then
if pos>0 then
do
call charout, d2c(8)
pos=pos-1
do forever
if pos=0 then leave
if substr(word,pos+1,1)\==" " & substr(word,pos,1)==" " then
leave
else
do
call charout, d2c(8)
pos=pos-1
end
end
end
when key2=d2c(116) then
if pos<length(word) then
do
if \CmdLine.Hidden then call Charout, substr(word,pos+1,1)
else call charout, "*"
pos=pos+1
do forever
if pos=length(word) then
leave
if substr(word,pos,1)==" " & substr(word,pos+1,1)\==" " then
leave
else
do
if \CmdLine.Hidden then call Charout, substr(word,pos+1,1)
else call charout, "*"
pos=pos+1
end
end
end
when key2=d2c(83) then
if pos<length(word) then
do
word=delstr(word,pos+1,1)
if \CmdLine.Hidden then call Charout, substr(word,pos+1)||" "
else call Charout, copies("*",length(substr(word,pos+1)))||" "
call charout, copies(d2c(8),length(word)-pos+1)
end
when key2=d2c(82) then
!CmdLine.History.insert = \!CmdLine.History.insert
when key2=d2c(79) then
if pos<length(word) then
do
if \CmdLine.Hidden then call Charout, substr(word,pos+1)
else call Charout, copies("*",length(substr(word,pos+1)))
pos=length(word)
end
when key2=d2c(71) then
if pos\=0 then
do
call Charout, copies(d2c(8),pos)
pos=0
end
when key2=d2c(117) then
if pos<length(word) then
do
call Charout, copies(" ",length(word)-pos)
call Charout, copies(d2c(8),length(word)-pos)
word=left(word,pos)
end
when key2=d2c(119) then
if pos>0 then
do
if pos<length(word) then
if \CmdLine.Hidden then call charout, substr(word,pos+1)
else call charout, copies("*",length(substr(word,pos+1)))
call rubout length(word)
word=substr(word,pos+1)
if \CmdLine.Hidden then call Charout, word
else call Charout, copies("*",length(word))
call Charout, copies(d2c(8),length(word))
pos=0
end
otherwise
if CmdLine.History & symbol('!CmdLine.History.key.'||c2d(key2))\='LIT' then
do
if pos<length(word) then
if \CmdLine.Hidden then call charout, substr(word,pos+1)
else call charout, copies("*",length(substr(word,pos+1)))
call rubout length(word)
i=c2d(key2)
word=!CmdLine.History.key.i
pos=length(word)
if \CmdLine.Hidden then call charout, word
else call charout, copies("*",length(word))
end
end
end
else
if CmdLine.Width=0 | (length(word)<CmdLine.Width | (pos<CmdLine.Width & !CmdLine.History.insert = 0)) then
do
if CmdLine.Upper then TheKey=translate(TheKey)
if CmdLine.Lower then TheKey=translate(TheKey,"abcdefghijklmnopqrstuvwxyz","ABCDEFGHIJKLMNOPQRSTUVWXYZ")
if pos(TheKey,CmdLine.Valid)\=0 then
do
if \CmdLine.Hidden then
call Charout, TheKey
else
call charout, "*"
if !CmdLine.History.insert then
word=insert(TheKey,word,pos)
else
word=overlay(TheKey,word,pos+1)
pos=pos+1
if pos<length(word) then
do
if \CmdLine.Hidden then
call Charout, substr(word,pos+1)
else
call Charout, copies("*", length(substr(word,pos+1)))
call Charout, copies(d2c(8),length(word)-pos)
end
end
else
call GetRespErrorBeep
end
else
call GetRespErrorBeep
if CmdLine.AutoSkip & length(word)=CmdLine.Width then leave
TheKey = GetKeyFromUser()
end
if \CmdLine.SameLine then say
if (CmdLine.Keep) & (word\=="") then
do
historical=!CmdLine.History.0
if word\=!CmdLine.History.historical then
do
!CmdLine.History.0=!CmdLine.History.0+1
historical=!CmdLine.History.0
!CmdLine.History.historical=word
end
end
return word
rubout: procedure
arg n
do i=1 to n
call Charout, d2c(8)||" "||d2c(8)
end
return
SkipOver_GETRESP:
DefaultP.StripAnswer = 'B'
DefaultP.ValidationRoutine = "*Empty*"
if RexSystemOpSys = "OS/2" then
do
DefaultP.BeforePrompt = '
'
DefaultP.AfterPrompt = '
'
AnsiReset = ''
end
else
do
DefaultP.BeforePrompt = ''
DefaultP.AfterPrompt = ''
AnsiReset = ''
end
call ProcessInputFile(TemplateFile)
exit(0)
FindIncludeFile:
LookForFile = arg(1)
FoundFile = _SysSearchPath('TEMPLATE', LookForFile)
if FoundFile = "" then
FoundFile = _SysSearchPath('INCLUDE', LookForFile)
return(FoundFile)
ProcessInputFile:
RequestedFile = arg(1)
IncludeLevel = IncludeLevel + 1
InputFile.IncludeLevel = stream(RequestedFile, 'c', 'query exists')
InputFile.IncludeLevel = stream(RequestedFile, 'c', 'query exists')
if InputFile.IncludeLevel = '' then
InputFile.IncludeLevel = FindIncludeFile(RequestedFile)
if InputFile.IncludeLevel = '' then
AbortProcessing('File "' || RequestedFile || '" does not exist!')
call OutputProcessingFileStringToScreen
CloseRc = stream(InputFile.IncludeLevel, 'c', 'close')
LinesProcessed.IncludeLevel = 0
do while lines(InputFile.IncludeLevel) <> 0
CurrentLine = linein(InputFile.IncludeLevel)
LinesProcessed.IncludeLevel = LinesProcessed.IncludeLevel + 1
if DebugMode = 'Y' then
call SayIfDebugOn InputFile.IncludeLevel || '(' || LinesProcessed.IncludeLevel || '): ' || CurrentLine
CurrentLine = ReplaceHashAndStandardDefines(CurrentLine)
if DebugMode = 'Y' then
do
if pos('{', CurrentLine) <> 0 then
call SayIfDebugOn "FOUND '{': " || CurrentLine
end
if CmdState <> 'T' then
do
CmtPos = lastpos(InLineCmt, CurrentLine)
if CmtPos > 1 then
CurrentLine = left(CurrentLine, CmtPos - 1)
CurrentLine = strip(CurrentLine)
if CurrentLine = '' then
iterate
if left(CurrentLine, 1) = ';' then
iterate
end
CurrentCmd = translate( word(CurrentLine, 1) )
CurrentCmdParms = subword(CurrentLine, 2)
select
when CurrentCmd = HashIf then
do
call ProcessHashIf CurrentCmdParms
iterate
end
when CurrentCmd = HashElseIf then
do
call ProcessHashElse
iterate
end
when CurrentCmd = HashEndIf then
do
call ProcessHashEndif
iterate
end
otherwise
end
if WantLine() <> 'Y' then
iterate
if CmdState <> 'T' then
do
select
when CurrentCmd = HashHash then
do
NewHash = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
call SetupHashVariables NewHash
iterate
end
when CurrentCmd = 'DEBUG' then
do
DebugMode = 'Y'
iterate
end
otherwise
end
end
select
when CurrentCmd = 'STARTPROMPT' then
do
call MustBeInOrOutsideAnyPromptOrTemplateDefinition
CmdState = 'P'
Tp.PromptVar = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
Tp.PromptText = "*Empty*"
Tp.AnswerLengthFrom = 0
Tp.AnswerLengthTo = "*Empty*"
Tp.ValidCharList = "*Empty*"
Tp.ValidationRoutine = DefaultP.ValidationRoutine
Tp.StripAnswer = DefaultP.StripAnswer
Tp.BeforePrompt = DefaultP.BeforePrompt
Tp.AfterPrompt = DefaultP.AfterPrompt
Tp.EntryValue = ''
Tp.PromptOptionList = ''
end
when CurrentCmd = 'ENDPROMPT' then
do
call MustBeWithinPromptDefinition
call ExpectNoMoreParms CurrentCmdParms
if Tp.PromptText = "*Empty*" then
call AbortProcessing 'ERROR: Expected a "PromptText" command'
if Tp.AnswerLengthTo = "*Empty*" then
Tp.AnswerLengthTo = 79 - length(Tp.PromptText)
Tp.PromptAnswer = PromptUserAndGetAnswer()
CmdState = '-'
end
when CurrentCmd = 'STARTTEMPLATE' then
do
call MustBeInOrOutsideAnyPromptOrTemplateDefinition
CmdState = 'T'
Tt.OutputFile = GeneratedFileBase || GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
CloseRc = stream(Tt.OutputFile, 'c', 'close')
DosDelRc = _SysFileDelete(Tt.OutputFile)
if stream(Tt.OutputFile, 'c', 'query exists') <> '' then
call AbortProcessing 'ERROR: Could not delete the output file "' || Tt.OutputFile || '"'
Tt.OutputLine = 0
end
when CurrentCmd = 'ENDTEMPLATE' then
do
call MustBeWithinTemplateDefinition
call ExpectNoMoreParms CurrentCmdParms
call OutputProcessingStatusStringToScreen 'Wrote ' || AddCommasToDecimalNumber(Tt.OutputLine) || ' line(s) to "' || Tt.OutputFile || '".'
CloseRc = stream(Tt.OutputFile, 'c', 'close')
Tt.OutputFile = ''
CmdState = '-'
end
when CurrentCmd = 'ANSWERLENGTH' then
do
call MustBeWithinPromptDefinition
Tp.AnswerLengthFrom = GetQuotedText(CurrentCmdParms, "CurrentCmdParms")
Tp.AnswerLengthTo = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
end
when CurrentCmd = 'PROMPTOPTION' then
do
call MustBeWithinPromptDefinition
TheOption = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
Tp.PromptOptionList = Tp.PromptOptionList || ', "' || TheOption || '"'
end
when CurrentCmd = 'PROMPTTEXT' then
do
call MustBeWithinPromptDefinition
Tp.PromptText = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
end
when CurrentCmd = 'VALIDCHARLIST' then
do
call MustBeWithinPromptDefinition
Tp.ValidCharList = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
end
when CurrentCmd = 'INITIALVALUE' then
do
call MustBeWithinPromptDefinition
Tp.EntryValue = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
end
when CurrentCmd = 'STRIPANSWER' then
do
TheOption = GetQuotedText(CurrentCmdParms, "TheRest")
TheOptionUpper = translate(TheOption)
call ExpectNoMoreParms TheRest
if TheOption = 'OFF' then
TheOption = ''
if TheOption <> '' & TheOption <> 'L' & TheOption <> 'T' & TheOption <> 'B' then
call AbortProcessing 'ERROR: Invalid value of "' || TheOption || '" on "StripAnswer" command.'
CurrentCmdParms = '"' || TheOptionUpper || '"'
call GetSinglePromptParm 'StripAnswer', ValidIfOutsideOrInPrompt
end
when CurrentCmd = 'BEFOREPROMPT' then
call GetSinglePromptParm 'BeforePrompt', ValidIfOutsideOrInPrompt
when CurrentCmd = 'AFTERPROMPT' then
call GetSinglePromptParm 'AfterPrompt', ValidIfOutsideOrInPrompt
when CurrentCmd = 'VALIDATIONROUTINE' then
call GetSinglePromptParm 'ValidationRoutine', ValidIfOutsideOrInPrompt
when CurrentCmd = "EVALUATE" then
call ProcessEvaluate CurrentCmdParms
when CurrentCmd = HashInclude then
call ProcessHashInclude CurrentCmdParms
when CurrentCmd = HashDefine then
do
DefineVar = GetQuotedText(CurrentCmdParms, "TheRest")
DefineVal = GetQuotedText(TheRest, "TheRest")
call ExpectNoMoreParms TheRest
call AddHashDefine DefineVar, DefineVal
iterate
end
otherwise
if CmdState <> 'T' then
call AbortProcessing 'ERROR: Invalid Template command of "' || CurrentCmd || '" found on line ' || LinesProcessed.IncludeLevel
if lineout(Tt.OutputFile, CurrentLine) <> 0 then
AbortProcessing('Could not write to the file "' || Tt.OutputFile || '"!')
Tt.OutputLine = Tt.OutputLine + 1
end
end
CloseRc = stream(InputFile.IncludeLevel, 'c', 'close')
IncludeLevel = IncludeLevel - 1
return(0)
ProcessHashInclude:
NextFile = GetQuotedText(arg(1), "TheRest")
call ExpectNoMoreParms TheRest
call ProcessInputFile(NextFile)
call OutputProcessingFileStringToScreen
return
OutputProcessingFileStringToScreen:
call SayIfDebugOn copies(" ", IncludeLevel) || ' * Processing: ' || InputFile.IncludeLevel
return
OutputProcessingStatusStringToScreen:
if DebugMode = 'N' then
say arg(1)
else
say copies(" ", IncludeLevel) || ' * ' || arg(1)
return
SayIfDebugOn:
if DebugMode = 'Y' then
say arg(1)
return
GetSinglePromptParm:
AnswerBase = arg(1)
ValidStates = arg(2)
if pos(CmdState, ValidStates) = 0 then
do
call MustBeWithinPromptDefinition
call MustBeInOrOutsideAnyPromptOrTemplateDefinition
end
ThisParm = GetQuotedText(CurrentCmdParms, "TheRest")
call ExpectNoMoreParms TheRest
if CmdState = '-' then
VarDot = "DefaultP."
else
do
if CmdState = 'T' then
VarDot = "Tt."
else
VarDot = "Tp."
end
interpret VarDot || AnswerBase || ' = ThisParm'
return
ExpectNoMoreParms:
if arg(1) <> '' then
call AbortProcessing 'ERROR: Too many parameters on "' || CurrentCmd || '" command ("' || arg(1) || '" was unexpected).'
return
MustBeWithinPromptDefinition:
if CmdState <> 'P' then
call AbortProcessing 'ERROR: Command of "' || CurrentCmd || '" is outside of Prompt Definition!'
return
MustBeWithinTemplateDefinition:
if CmdState <> 'T' then
call AbortProcessing 'ERROR: Command of "' || CurrentCmd || '" is outside of Template Definition!'
return
MustBeInOrOutsideAnyPromptOrTemplateDefinition:
if CmdState <> '-' then
call AbortProcessing 'ERROR: Command of "' || CurrentCmd || '" is inside of Prompt/Template Definition!'
return
PromptUserAndGetAnswer:
call charout ,Tp.BeforePrompt || Tp.PromptText || Tp.AfterPrompt
if RexWhich = 'STANDARD_OS/2' then
parse value SysCurPos() with StartX StartY
ThePromptOptionList = '"SameLine", "Overwrite", "Forget", "NoHistory", "Beginning", TheInitialValue' || ', "Width", Tp.AnswerLengthTo' || Tp.PromptOptionList
if Tp.ValidCharList <> "*Empty*" then
ThePromptOptionList = ThePromptOptionList || ', "Valid", Tp.ValidCharList'
TheInitialValue = Tp.EntryValue
do forever
if RexWhich = 'STANDARD_OS/2' then
interpret "UsersAnswer = CmdLine(" || ThePromptOptionList || ')'
else
UsersAnswer = linein()
if Tp.StripAnswer <> '' then
UsersAnswer = strip(UsersAnswer, Tp.StripAnswer)
call SetEnv '_' || Tp.PromptVar || '_', UsersAnswer
call AddHashDefine Tp.PromptVar, UsersAnswer
UsersAnswerOk = 'Y'
if length(UsersAnswer) < Tp.AnswerLengthFrom then
UsersAnswerOk = 'N'
if Tp.ValidationRoutine <> "*Empty*" then
do
interpret 'ValResult = "' || Tp.ValidationRoutine || '"("' || Tp.PromptVar || '")'
if ValResult <> "OK" then
UsersAnswerOk = 'N'
end
if UsersAnswerOk = 'Y' then
leave
call charout ,''
if RexWhich = 'STANDARD_OS/2' then
do
call SysCurPos StartX, StartY
call charout ,copies(' ', length(UsersAnswer))
call SysCurPos StartX, StartY
end
else
do
call charout ,Tp.BeforePrompt || Tp.PromptText || Tp.AfterPrompt
end
TheInitialValue = UsersAnswer
end
call charout ,AnsiReset
if RexWhich = 'STANDARD_OS/2' then
say ''
return(UsersAnswer)
GetQuotedText:
TheString = strip(arg(1))
RestVarName = arg(2)
NoCheckWhitespace = arg(3)
if TheString = '' then
AbortProcessing('Expect a quoted string, no parameters available')
QuoteChar = left(TheString, 1)
if datatype(QuoteChar, 'Alphanumeric') then
do
SpacePos = pos(' ', TheString)
if SpacePos = 0 then
do
QuotedString = TheString
TheRest = ''
end
else
do
QuotedString = substr(TheString, 1, SpacePos-1)
TheRest = substr(TheString, SpacePos+1)
end
end
else
do
SecondQuotePosn = pos(QuoteChar, substr(TheString, 2))
if SecondQuotePosn <> 0 then
SecondQuotePosn = SecondQuotePosn + 1
else
AbortProcessing('Could not find a matching end quote character of "' || QuoteChar || '"')
QuotedString = substr(TheString, 2, SecondQuotePosn-2)
TheRest = substr(TheString, SecondQuotePosn+1)
end
if TheRest <> '' then
do
if NoCheckWhitespace <> 'Y' then
do
if left(TheRest, 1) <> ' ' then
AbortProcessing('There is no whitespace after the 2nd quote char of "' || QuoteChar || '" (did not expect to find "' || left(TheRest, 1) || '")')
end
end
TheRest = strip(TheRest)
if RestVarName <> '' then
interpret RestVarName || " = TheRest;"
else
do
if TheRest <> '' then
AbortProcessing('Extra unexpected parameters of "' || TheRest || '" found')
end
return(QuotedString)
AddHashDefine:
HashDefineV = arg(1)
HashDefineC = arg(2)
if pos('{', HashDefineV) <> 0 | pos('}', HashDefineV) <> 0 then
AbortProcessing('Attempt to #define invalid name of "' || HashDefineV || '".')
HashDefineV = '<' || '$' || HashDefineV
ItExists = HashDefineExists(HashDefineV)
if ItExists <> 'N' then
do
SaveIndex = ItExists
if HashDefineC.SaveIndex = strip(HashDefineC)
then
ReplaceMsg = "Redefinition same as previous"
else
ReplaceMsg = "Redefinition old value = " || HashDefineC.SaveIndex
call SayIfDebugOn ReplaceMsg
end
else
do
HashDefineCount = HashDefineCount + 1
SaveIndex = HashDefineCount
end
HashDefineV.SaveIndex = HashDefineV
HashDefineC.SaveIndex = strip(HashDefineC)
return(0)
SetupHashVariables:
HashChar = arg(1)
HashHash = HashChar || "HASH"
HashDefine = HashChar || "DEFINE"
HashInclude = HashChar || "INCLUDE"
HashIf = HashChar || "IF"
HashElseIf = HashChar || "ELSEIF"
HashEndIf = HashChar || "ENDIF"
return
CmdlineSyntaxError:
say "SYNTAX ERROR"
say "~~~~~~~~~~~~"
say ' ' || arg(1)
say ''
say 'CORRECT SYNTAX'
say '~~~~~~~~~~~~~~'
say ' TEMPLATE[.CMD] InputTemplateFileName OutputPrefix'
say ''
say ''
say 'Please view "TEMPLATE.INF" for full details.'
exit(SIGL)
AbortProcessing:
if arg(2) = '' then
AbortLocation = SIGL
else
AbortLocation = arg(2)
AbortMsg = arg(1)
if AbortMsg <> '' then
say AbortMsg || ''
if Aborting = 'N' then
do
Aborting = 'Y'
if Tt.OutputFile <> '' then
CloseRc = stream(Tt.OutputFile, 'c', 'close')
if IncludeLevel <> 0 then
do
do FileIndex = 1 to IncludeLevel
if InputFile.FileIndex <> '' then
CloseRc = stream(InputFile.FileIndex, 'c', 'close')
end
end
end
exit(AbortLocation)
GetAmPmTime:
CivilTime = time('C'); if length(CivilTime) = 6 then CivilTime=' 'CivilTime
TheTime = time(); NumSeconds = ':'substr(TheTime, 7, 2)
return( insert(NumSeconds, CivilTime, 5) )
RexxCtrlC:
LineCtrlC = SIGL
say ''
say copies('=+', 39)
say "Come on, you pressed Ctrl+C or Break didn't you!"
say copies('=+', 39)
call AbortProcessing ,LineCtrlC
CommonTrapHandler:
FailingLine = arg(1)
TrapHeading = 'BUG: ' || arg(2)
TextDescription = arg(3)
Text = arg(4)
say ''
say copies('=+', 39)
say TrapHeading
say copies('~', length(TrapHeading))
say substr(TextDescription, 1 , 16) || ': ' || Text
say 'Failing Module : ' || RexSystmRexxPgmName
say 'Failing Line # : ' || FailingLine
say 'Failing Command : ' || strip(SourceLine(FailingLine))
say copies('=+', 39)
call AbortProcessing ,FailingLine
RexxTrapUninitializedVariable:
FailedAt = SIGL
call CommonTrapHandler FailedAt, 'NoValue Abort!', 'Unknown Variable', condition('D')
RexxTrapSyntaxError:
FailedAt = SIGL
call CommonTrapHandler FailedAt, 'Syntax Error!', 'Reason', errortext(Rc)
RexSystemFailure:
FailedAt = SIGL
call RexDumpSystemInfo
call AbortProcessing arg(1), FailedAt