home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
High Voltage Shareware
/
high1.zip
/
high1
/
DIR36
/
KEXX.ZIP
/
RUNCMD.KEX
< prev
next >
Wrap
Text File
|
1992-12-29
|
13KB
|
361 lines
************************************************
* RUNCMD.KEX
*
* Function: Run programs and locate the lines that are indicated
* in messages in the output listings.
* More concisely, this is the logic that is common to macros
* like CC and BROWSE.
*
* Requires: KEDIT 5.0
* Version: 1.1 (December, 1992)
*
* Internal EDITV variables:
* Current.xx current line
* Total.xx number of lines
* Line.1.xx ... Line.n.xx complete message text for a given line
*
* Parameters:
* /Text/ - Text of message to display at each location.
* "%m" is replaced by the output from the external program.
* EditvSuffix - Tail value for EDITV variables used by RUNCMD.
* Unique values allow things like BROWSE and CC to coexist
* during the same editing session.
* TempFileid - Fileid to redirect the output of the external command to.
* TypeOfLine - Label for each located line.
* NextKey - Key to use for "next location" function.
* PrevKey - Key to use for "previous location" function.
* CurrKey - Key to use to redisplay the current location.
* ShellCmd - KEDIT command used to execute the external function.
* E.g., DOSNOWAIT, or DOSQUIET
* Parms - The commandline used to execute the external command.
* "%s" is replaced by the fileid of the current file.
* "%n" is replaced by the filename of the current file.
* "-" means skip the execution of the command and use the
* current file as the output file.
*
************************************************
TRUE = 1
FALSE = 0
* Obtain parameters from command line
Parse Arg "/" MessageText "/" EditvSuffix TempFileid TypeOfLine NextKey PrevKey CurrKey ShellCmd Parms
* Make sure we got the parameters needed before continuing!
If EditvSuffix = "" | TempFileid = "" | TypeOfLine = "" | NextKey = "" | PrevKey = "" | CurrKey = "" Then
Call FatalErr 4 'Missing parameters in RUNCMD.KEX'
* We depend on KEDIT messages to convey info to user
MsgMode = MsgMode.1()
If MsgMode = "OFF" Then "Set MsgMode ON"
UseGetCommand = FALSE;
* Process user's command
If Parms \= '+find' & Parms \= '-find' & Parms \= '-+find' Then Do
SourceFid = Fileid.1()
* An argument of "-" means skip the command step and use current
* file as if it were command output
If Parms \= '-' Then Do
* Get rid of any old error logs on disk or in memory
Call ErrorCheck 'Kedit .:.\'TempFileid '(New NoProf'
If (Ring.0() > 1) & (SourceFid \= Fileid.1()) Then
'QQuit'
Else Do
UseGetCommand = TRUE
'NoMsg Delete All'
End
'NoMsg Erase .:.\'TempFileid
If Upper(TestFid) \= Upper(TempFileid) Then
Call ErrorCheck 'Kedit' SourceFid
* Process any placeholders in the command string
P = Pos("%s", Parms)
If P \= 0 Then
Parms = Substr(Parms, 1, P - 1)Fileid.1()Substr(Parms, P + 2)
P = Pos("%n", Parms)
If P \= 0 Then
Parms = Substr(Parms, 1, P - 1)FName.1()Substr(Parms, P + 2)
* Remember current directory, in case the command changes it
SaveDir = Directory.1()
* Execute the command
If ShellCmd = "DOSNOWAIT" | ShellCmd = "DOS" Then
ShellCmd "/c" TempFileid Parms
Else
ShellCmd Parms ">"TempFileid
* Restore current directory
'NoMsg ChDrive' Substr(SaveDir, 1, 1)
'NoMsg ChDir' SaveDir
End
* Edit the error log (abort if impossible or empty)
If UseGetCommand = FALSE Then
Call ErrorCheck 'Kedit .:.\'TempFileid '(NoProf'
Else Do
Call ErrorCheck 'Get .:.\'TempFileid
'NoMsg Top'
End
If Size.1() = 0 Then Do
If Ring.0() > 1 Then 'QQuit'
Call FatalErr 1 'No output from' Parms
End
* Insert command into error log
If Parms \= '-' Then Do
'I' Parms
'Set Alt 0 0'
End
* Remember number of editv variables from previous run
Call ErrorCheck 'Editv Get Total.'EditvSuffix
OldErrors = Total.EditvSuffix
* These 2 lines inserted for OPTASM, which starts error logs with a linefeed
Call ErrorCheck 'Locate :1'
If Substr(CurLine.3(), 1, 1) = 'a'x Then Call ErrorCheck 'Shift Left'
* Process all message lines in error listing
* First, ignore any lines that can't have error messages
'NoMsg All /:/'
If RC \= 0 Then Do
'NoMsg All'
Call ErrorCheck 'Set CurLine On 3'
'NoMsg Locate :1'
'SOS Beep'
'Dialog' Delimit("No recognizable" TypeOfLine"s encountered") 'OK'
If MsgMode = "OFF" Then "Set MsgMode OFF"
Exit 1
End
* RC output can cause problems
'Extract /Zone/'
* Troublesome RC output will have "#line" starting in column one
'NoMsg Set Zone 1 5'
'NoMsg Less /#line/'
'NoMsg Set Zone' Zone.1 Zone.2
'NoMsg Top'
Total.EditvSuffix = 0
Do Forever
Call ErrorCheck 'Kedit' TempFileid
'NoMsg Next'
If RC \= 0 Then Leave
* Process error messages in one of the following formats:
* filename(row):message
* filename(row,column): message
* filename(row:column): message
* filename row column: message
* "filename", row column:message
* Error filename row: message
Line = CurLine.3()
Parse Var Line Prefix ":" Message
If (SubStr(Message, 1, 1) = "\" | Substr(Message, 1, 1) = "/") & Length(Strip(Prefix)) = 1 Then Do
* Probably picked up a colon in the fileid
Parse Var Message MorePrefix ":" Message
Prefix = Prefix":"MorePrefix
End
If (Pos('(', Prefix) \= 0) & (Pos(')', Prefix) = 0) & (Pos(')', Message) \= 0) Then Do
* Picked up a colon inside the parenthesis
Parse Var Message MorePrefix ":" Message
Prefix = Prefix":"MorePrefix
End
Open = Pos('(', Prefix)
If Open > 0 Then Do
Close = Pos(')', Substr(Prefix, Open + 1))
If Close = 0 Then Iterate
Parse Var Prefix Fid "(" LineNO "," . ")"
Parse Var LineNO LineNO ":"
Parse Var LineNO LineNO ")"
End
Else Do
If Substr(Prefix, 1, 1) = '"' Then Do
CloseQuote = Pos('",', Substr(Prefix, 2))
If CloseQuote = 0 Then Iterate
Parse Var Prefix '"' Fid '"' LineNO .
End
Else Do
BorlandCheck = Word(Prefix, 1)
If BorlandCheck = "Error" | BorlandCheck = "Warning"
Then
Parse Var Prefix . Fid LineNO .
Else
Parse Var Prefix Fid LineNO .
End
End
If \DataType(LineNO, 'N') | Message = '' | Length(Fid) = 0 Then Iterate
If Upper(Fid) = "<UNKNOWN>" Then Iterate
* Ignore any troublesome macro messages from MASM 6.0
If Upper(Strip(Message)) = "MACRO CALLED FROM" Then Do
'NoMsg Next'
Iterate
End
* Change any /s in the fileid to \s
Fid = Translate(Fid, '\', '/')
Total.EditvSuffix = Total.EditvSuffix + 1
Call ErrorCheck 'Editv SetL Line.'Total.EditvSuffix'.'EditvSuffix Fid Message
Call ErrorCheck 'Kedit' Fid '(NoDefExt'
'NoMsg Locate :'LineNO
If RC > 1 Then Iterate
Call ErrorCheck 'Set Point .'EditvSuffix'.'Total.EditvSuffix
End
Call ErrorCheck 'All'
* Clear out any extra editv variables from the last run
If DataType(OldErrors, 'N') Then
Do I = Total.EditvSuffix + 1 To OldErrors
Call ErrorCheck 'Editv Set Line.'I'.'EditvSuffix
End
* Set global variable indicating number of lines
Call ErrorCheck 'Editv Put Total.'EditvSuffix
* If no lines, issue a message and exit
if Total.EditvSuffix = 0 Then Do
Call ErrorCheck 'Set CurLine On 3'
'NoMsg Locate :1'
'SOS Beep'
'Dialog' Delimit("No recognizable" TypeOfLine"s encountered") 'OK'
If MsgMode = "OFF" Then "Set MsgMode OFF"
Exit 1
End
* Define keys to find next, previous, and current lines
'NoMsg Define' NextKey '"Macro RUNCMD /' || MessageText || '/' EditvSuffix TempFileid TypeOfLine NextKey PrevKey CurrKey ShellCmd '+find"'
If RC \= 0 Then
Call FatalErr RC "Unable to define key" NextKey
'NoMsg Define' PrevKey '"Macro RUNCMD /' || MessageText || '/' EditvSuffix TempFileid TypeOfLine NextKey PrevKey CurrKey ShellCmd '-find"'
If RC \= 0 Then
Call FatalErr RC "Unable to define key" PrevKey
* Define key to recall current message
'NoMsg Define' CurrKey '"Macro RUNCMD /' || MessageText || '/' EditvSuffix TempFileid TypeOfLine NextKey PrevKey CurrKey ShellCmd '-+find"'
If RC \= 0 Then
Call FatalErr RC "Unable to define key" CurrKey
* Setup to locate the first error
If NBFile.1() > 1 Then 'QQuit'
Current.EditvSuffix = 0
Call ErrorCheck 'Editv Put Current.'EditvSuffix
Parms = '+find'
'SOS Beep'
End
Call ErrorCheck 'Editv Get Total.'EditvSuffix
Call ErrorCheck 'Editv Get Current.'EditvSuffix
* Find next or previous lines (+find and -find)
If \DataType(Total.EditvSuffix, 'N') | \DataType(Current.EditvSuffix, 'N') Then
Call FatalErr 99 'RUNCMD.KEX setup error'
If Total.EditvSuffix = 0 Then
Call FatalErr 1 'No' TypeOfLine's found'
If Parms \= '-+find' Then Do
If Parms = '+find' Then
Current.EditvSuffix = Min(Current.EditvSuffix + 1, Total.EditvSuffix + 1)
Else If Parms = '-find' Then
Current.EditvSuffix = Max(Current.EditvSuffix - 1, 0)
Else
Call FatalErr 99 "Unrecognized parameter: '"Parms"'"
If 1 > Current.EditvSuffix Then Do
Current.EditvSuffix = 1
'Editv Put Current.'EditvSuffix
'Msg No previous' TypeOfLine's'
exit
End
If Current.EditvSuffix > Total.EditvSuffix Then Do
Current.EditvSuffix = Total.EditvSuffix
'Editv Put Current.'EditvSuffix
'Msg No more' TypeOfLine's'
exit
End
'Editv Put Current.'EditvSuffix
End
CurrentLine = Current.EditvSuffix
Call ErrorCheck 'Editv Get Line.'CurrentLine'.'EditvSuffix
Parse Var Line.CurrentLine.EditvSuffix Fid Message
Call ErrorCheck 'Kedit' Fid '(NoDefExt'
If Size.1() = 0 Then Do
'QQuit'
Call FatalErr 99 'File' Upper(Fid) 'not found.'
End
Else Do
'NoMsg Locate .'EditvSuffix'.'CurrentLine
If RC > 1 Then Do
'Msg' CurrentLine 'of' Total.EditvSuffix '- Use' NextKey'/'PrevKey'/'CurrKey 'to find the next/previous/current' TypeOfLine
'Msg Cannot locate the line. It was probably deleted from the file.'
If MsgMode = "OFF" Then "Set MsgMode OFF"
Return 1
End
End
MessageOut = Strip(MessageText)
P = Pos("%m", MessageOut)
If P \= 0 Then
MessageOut = Substr(MessageOut, 1, P - 1) || Strip(Message) || Substr(MessageOut, P + 2)
'Msg' CurrentLine 'of' Total.EditvSuffix '- Use' NextKey'/'PrevKey'/'CurrKey 'to find the next/previous/current' TypeOfLine
WindowWidth = LScreen.2()
'Extract /SCROLLBAR/'
If ScrollBar.1 = "ON" & (ScrollBar.2 = "VERTICAL" | ScrollBar.2 = "BOTH") Then
WindowWidth = WindowWidth - 1
Do While MessageOut \= ''
'Msg' Substr(MessageOut, 1, WindowWidth)
MessageOut = Substr(MessageOut, WindowWidth + 1)
End
'SOS Current Firstch'
If MsgMode = "OFF" Then "Set MsgMode OFF"
Return 0
************************************************
* Subroutine to bail out with error message in alert box
* Note: This subroutine never returns to it's caller
************************************************
FatalErr:
Parse Arg ReturnCode ErrorMessage
If ErrorMessage \= "" Then 'Alert' Delimit(ErrorMessage)
If MsgMode = "OFF" Then "Set MsgMode OFF"
Exit ReturnCode
************************************************
* Execute command and check for zero return code
* If RC is not 0, then bail out with FatalErr
************************************************
ErrorCheck:
Parse Arg CmdString
NoMsgCmd = "NOMSG"
* NOMSG KEDIT and REPROFILE OFF can result in undesirable
* ... MSGMODE OFF situations
If Upper(Word(CmdString, 1)) = "KEDIT" Then NoMsgCmd = ""
NoMsgCmd CmdString
If RC \= 0 & NoMsgCmd \= "" Then
Call FatalErr RC "From <"Word(CmdString, 1)">" LastMsg.1()
Else If RC \= 0 Then Call FatalErr RC
Return