DEBUG.MSG
From Pickwiki
Jump to navigationJump to searchHomePage>>SourceCode>>BasicSource>>SvnWrapper>>DEBUG.MSG
Builds a list of Debug messages for later display/email/etc.
subroutine DEBUG.MSG( MSG, Params )
* @SUB Add a message to the current Debug list
* =======================================================================================
* 02.Mar.2010 james: 'A' is finally '[[AppendToPreviousLine]]' as it was supposed to be.
* 22.Feb.2010 james: Add DEBUG.MSG DEBUG.FLAG in case caller breaks before finishing.
* 14.Jul.2009 james: s'W'ap lines
* 07.Jul.2009 james: First draft
* =======================================================================================
* $Id$
* =======================================================================================
*
* Move code from SELECT.FORMS into this subroutine so it can also be used from AUDIT.SUB.
*
* Example usage:
*
* - First clear the Messages and turn on message tracking (like 'S' option) :
*
* call DEBUG.MSG( '', 'C' )
*
* - Now add messages as necessary; start with '|' to force a new line:
*
* call DEBUG.MSG( "| Plan Selection Type is '":PLAN$SELECT.TYPE:"'", '' )
* call DEBUG.MSG( '| Executing saved DELETE commands ...', '' )
* call DEBUG.MSG( 'Error Message', 'A' ) ;* Append the message to the last line
* call DEBUG.MSG( '', 'P' ) ;* 'P'rint debug messages
* call DEBUG.MSG( ' Document Selection for ':WS.NUM:' ', 'D' )
* =======================================================================================
$include RMS.BP RMS.COMMON
$include RMS.BP DEBUG.COMMON
* Use this in case the program you're working on never gets to the 'D' call; i.e.
* it's blowing before you see anything in here !:
locate 'DEBUG.MSG' in DEBUG.FLAG<1> setting dum then [[DebugIt]] = @TRUE else [[DebugIt]] = @FALSE
Opt = Params<1>
begin case
case Opt = 'A' ; gosub [[AppendToPreviousLine]]
case Opt = 'S' ; DEBUG.ON = @TRUE ;* 'S'tart
case Opt = 'E' ; DEBUG.ON = @FALSE ;* 'E'nd
case Opt = 'C' ; DEBUG.DISPLAY = MSG ; DEBUG.ON = @TRUE ;* 'C'lear and start
case Opt = 'D' ; gosub [[DisplayDebugMessages]] ; DEBUG.ON = @FALSE
case Opt = 'P' ; gosub [[PrintDebugMessages]] ; DEBUG.ON = @FALSE
case Opt = 'R' ; MSG = DEBUG.DISPLAY ;* 'R'eturn the current display
case Opt = 'W' ; if DEBUG.ON and MSG # '' then gosub [[SwapMessages]]
case 1 ; if DEBUG.ON and MSG # '' then gosub [[AddMsg]]
end case
return
[[AppendToPreviousLine]]:
if DEBUG.DISPLAY'R#1' = @FM then DEBUG.DISPLAY = DEBUG.DISPLAY[1, len(DEBUG.DISPLAY) - 1]
gosub [[AddMsg]]
return
* This is a little trick: if you're in the middle of adding a line; but find some
* condition that needs to be put ABOVE this line; use 'W' to 'Swap out' the current
* line with the message (i.e. insert MSG BEFORE the last line...).
[[SwapMessages]]:
[[NumLines]] = dcount( DEBUG.DISPLAY, @FM )
[[LastLine]] = DEBUG.DISPLAY< [[NumLines]] >
DEBUG.DISPLAY< [[NumLines]] > = MSG
if MSG[len(MSG),1] # ':' then ;* ':' at the end means 'no new line'
DEBUG.DISPLAY := @FM
end
MSG = [[LastLine]] ; gosub [[AddMsg]]
return
[[AddMsg]]:
if [[DebugIt]] then crt 'Adding ':MSG
loop while MSG[1,1] = '|' do ;* '|' at the beginning means 'new lines'
DEBUG.DISPLAY := @FM
MSG = MSG[2, 99999]
repeat
DEBUG.DISPLAY := MSG ;* Finally add text OR a chunk of lines or whatever.
if MSG[len(MSG),1] # ':' then ;* ':' at the end means 'no new line'
DEBUG.DISPLAY := @FM
end
return
[[DisplayDebugMessages]]:
Heading = MSG
OPTIONS = 'FULL.SCREEN'
call BOX.DISP.ITEM( DEBUG.DISPLAY, Heading, '', '', OPTIONS, OUT)
DEBUG.DISPLAY = '' ;* never print something twice: just in case calling logic is messed up.
return
* Does this even work ?
[[PrintDebugMessages]]:
printer on
[[NumLines]] = dcount(DEBUG.DISPLAY, @FM)
for N.L = 1 to [[NumLines]]
print DEBUG.DISPLAY< N.L >
next N.L
call PRT.OFF
return