home *** CD-ROM | disk | FTP | other *** search
/ The Developer Connection…ice Driver Kit for OS/2 3 / DEV3-D1.ISO / devtools / dataflex / tracer.pkg < prev    next >
Encoding:
Text File  |  1993-08-10  |  15.9 KB  |  558 lines

  1. //************************************************************************
  2. //
  3. // Copyright 1987-1992 Data Access Corporation, Miami FL, USA
  4. // All Rights reserved
  5. // DataFlex is a registered trademark of Data Access Corporation.
  6. //
  7. //
  8. //     $Source: /u3/source.30/product/pkg/RCS/tracer.pkg,v $
  9. //     $Revision: 1.1 $
  10. //     $State: Exp $
  11. //     $Author: james $
  12. //     $Date: 1992/09/08 14:43:10 $
  13. //     $Locker:  $
  14. //
  15. //     $Log: tracer.pkg,v $
  16. //Revision 1.1  1992/09/08  14:43:10  james
  17. //Initial revision
  18. //
  19. //Revision 1.3  92/05/14  17:09:14  SWM
  20. //Updated Copyright slug.
  21. //
  22. //Revision 1.2  92/03/09  19:05:26  james
  23. //Added #CHKSUB directive to insure source
  24. //only compiled with correct revision of 
  25. //compiler.
  26. //
  27. //Revision 1.1  91/10/23  10:23:02  elsa
  28. //Initial revision
  29. //
  30. //************************************************************************/
  31.  
  32. //************************************************************************
  33. //     File Name: Tracer.Pkg
  34. // Creation Date: January 1, 1991
  35. // Modified Date: May 23, 1991
  36. //     Author(s): Steven A. Lowe
  37. //
  38. // This module contains the Tracer class definition.
  39. //************************************************************************/
  40.  
  41. #CHKSUB 1 1 // Verify the UI subsystem.
  42.  
  43. Use UI
  44.  
  45.  
  46. //
  47. // This preprocessor command forces the compiler to retain symbols
  48. //
  49. #SYM
  50.  
  51.  
  52. //
  53. // The following constants are defined for readability.
  54. //
  55. #IFDEF Tracer.MsgHdrSize
  56. #ELSE
  57.   #REPLACE Tracer.MsgHdrSize |CI10 //number of characters in message header
  58.   #REPLACE Tracer.Mode_In    |CI0  //trace all sub-messages mode
  59.   #REPLACE Tracer.Mode_Over  |CI1  //trace only at current depth or less mode
  60. #ENDIF
  61.  
  62.  
  63. //
  64. //Class: Tracer
  65. //
  66. //SuperClass: TRACE
  67. //
  68. //Description: This class implements an augmented Trace utility which outputs
  69. //  formatted messages to an edit-object, using indentation and graphics
  70. //  characters to show the invocation of messages by other messages.
  71. //  Messages are retained in a queue (the edit-object).  Single-stepping,
  72. //  panning, and scrolling is supported.
  73. //
  74. //Usage: send TRACE_SWITCH TRUE TRUE to begin tracing in single-step mode;
  75. //  use defined accelerator keys to view trace text and control tracing
  76. //
  77. Class Tracer is a TRACE
  78.   //
  79.   //Operation: CONSTRUCT_OBJECT
  80.   //
  81.   //Assumption(s): none
  82.   //
  83.   //Goal(s): define instance with RIGHT_MARGIN = 250, and properties required
  84.   //  to maintain queue of formatted messages
  85.   //
  86.   //Algorithm: Augmented to set RIGHT_MARGIN to 250 and define the properties
  87.   //           Queue_Size, Trace_Mode, Active_Msg_Count, Wait_Depth, Current_Depth,
  88.   //           and Single_Step_State.  The default Queue_Size is 50.
  89.   //
  90.   //Usage: 
  91.   //
  92.   procedure construct_object
  93.     forward send construct_object
  94.     set right_margin to 250
  95.     //
  96.     //Attribute: Queue_Size
  97.     //
  98.     //Description: maximum number of inactive messages to retain in queue
  99.     //
  100.     //Representation: integer, default 50
  101.     //
  102.     Property integer Queue_Size      PUBLIC 50  //set default Queue_Size value
  103.     //
  104.     //Attribute: Trace_Mode
  105.     //
  106.     //Description: identifies mode of tracing; 0=in, 1=over
  107.     //
  108.     //Representation: integer
  109.     //
  110.     Property integer Trace_Mode      PUBLIC  0
  111.     //
  112.     //Attribute: Active_Msg_Count
  113.     //
  114.     //Description: number of active messages in queue
  115.     //
  116.     //Representation: integer
  117.     //
  118.     Property integer Active_Msg_Count PUBLIC  0  //default to none
  119.     //
  120.     //Attribute: Wait_Depth
  121.     //
  122.     //Description: depth of message at which Trace-Over was last executed
  123.     //
  124.     //Representation: integer
  125.     //
  126.     Property integer Wait_Depth      PUBLIC  0
  127.     //
  128.     //Attribute: Current_Depth
  129.     //
  130.     //Description: depth of current message
  131.     //
  132.     //Representation: integer
  133.     //
  134.     Property integer Current_Depth       PUBLIC  0
  135.     //
  136.     //Attribute: Single_Step_State
  137.     //
  138.     //Description: flag; true if self should wait for keypress after message
  139.     //
  140.     //Representation: integer
  141.     //
  142.     Property integer Single_Step_State PUBLIC  0
  143.   end_procedure
  144.   //
  145.   //Operation: HEIGHT
  146.   //
  147.   //Assumption(s): none
  148.   //
  149.   //Goal(s): return height of trace object in lines
  150.   //
  151.   //Algorithm: gets SIZE, calculates height, and returns height
  152.   //
  153.   //Usage: 
  154.   //
  155.   function Height returns integer
  156.     local integer ht
  157.     get size to ht
  158.     move (hi(ht)) to ht
  159.     function_return ht
  160.   end_function
  161.   //
  162.   //Operation: WIDTH
  163.   //
  164.   //Assumption(s): none
  165.   //
  166.   //Goal(s): return widht of trace object in columns
  167.   //
  168.   //Algorithm: gets SIZE, calculates width, and returns width
  169.   //
  170.   //Usage: 
  171.   //
  172.   function Width returns integer
  173.     local integer wdth
  174.     get size to wdth
  175.     move (low(wdth)) to wdth
  176.     function_Return wdth
  177.   end_function
  178.   //
  179.   //Operation: TRACE_SWITCH
  180.   //
  181.   //Assumption(s): TraceState and StepMode are booleans
  182.   //
  183.   //Goal(s): turns tracing on/off and sets Single_Step_State
  184.   //
  185.   //Algorithm: Augmented to set Single_Step_State
  186.   //
  187.   //Usage: 
  188.   //
  189.   procedure TRACE_SWITCH integer TraceState integer StepMode
  190.     set Single_Step_State to StepMode
  191.     Forward send TRACE_SWITCH TraceState FALSE
  192.   end_procedure
  193.   //
  194.   //Operation: CONTINUE_IN
  195.   //
  196.   //Assumption(s): none
  197.   //
  198.   //Goal(s): set Trace_Mode to Mode_In
  199.   //
  200.   //Algorithm: sets Trace_Mode to Mode_In
  201.   //
  202.   //Usage: 
  203.   //
  204.   procedure Continue_In
  205.     set Trace_Mode to Tracer.Mode_In
  206.   end_procedure
  207.   //
  208.   //Operation: CONTINUE_OVER
  209.   //
  210.   //Assumption(s): none
  211.   //
  212.   //Goal(s): set Trace_Mode to Mode_Over and remember current depth
  213.   //
  214.   //Algorithm: sets Trace_Mode to Mode_Over, sets Wait_Depth to Current_Depth
  215.   //
  216.   //Usage: 
  217.   //
  218.   procedure Continue_Over
  219.     set Trace_Mode to Tracer.Mode_Over
  220.     set Wait_Depth to (Current_Depth(current_object))
  221.   end_procedure
  222.   //
  223.   //Operation: TOGGLE_STEP
  224.   //
  225.   //Assumption(s): none
  226.   //
  227.   //Goal(s): if Single_Step_State is True, set it to False, else set it to True
  228.   //
  229.   //Algorithm: if Single_Step_State = 0, set Single_Step_State to True
  230.   //           else set Single_Step_State to False
  231.   //
  232.   //Usage: 
  233.   //
  234.   procedure Toggle_Step
  235.     local integer flag
  236.     get Single_Step_State to flag
  237.     if flag eq 0 set Single_Step_State to true
  238.     else set Single_Step_State to false
  239.   end_procedure
  240.   //
  241.   //Operation: NEXT_PAGE
  242.   //
  243.   //Assumption(s): none
  244.   //
  245.   //Goal(s): display to next page of data in the buffer
  246.   //
  247.   //Algorithm: recalculate and reset ORIGIN
  248.   //
  249.   //Usage: 
  250.   //
  251.   procedure Next_Page
  252.     local integer origX origY lines
  253.     move (origin(current_object)) to origY
  254.     move (low(origY)) to origX
  255.     move (hi(origY)) to origY
  256.     calc (origY + (Height(current_object)) - 1) to origY
  257.     get line_count to lines
  258.     if origY ge lines calc (lines - (Height(current_object)) + 1) to origY
  259.     if origY lt 0 move 0 to origY
  260.     set origin to origY origX
  261.   end_procedure
  262.   //
  263.   //Operation: PREVIOUS_PAGE
  264.   //
  265.   //Assumption(s): none
  266.   //
  267.   //Goal(s): display prior page of text
  268.   //
  269.   //Algorithm: recalculates and resets ORIGIN
  270.   //
  271.   //Usage: 
  272.   //
  273.   procedure Previous_Page
  274.     local integer origX origY
  275.     move (origin(current_object)) to origY
  276.     move (low(origY)) to origX
  277.     move (hi(origY)) to origY
  278.     calc (origY - (Height(current_object)) + 1) to origY
  279.     if origY lt 0 move 0 to origY
  280.     set origin to origY origX
  281.   end_procedure
  282.   //
  283.   //Operation: LEFT_PAGE
  284.   //
  285.   //Assumption(s): none
  286.   //
  287.   //Goal(s): scroll display to right by 1/2 page
  288.   //
  289.   //Algorithm: recalculates and resets ORIGIN
  290.   //
  291.   //Usage: 
  292.   //
  293.   procedure Left_Page
  294.     local integer origX origY
  295.     move (origin(current_object)) to origY
  296.     move (low(origY)) to origX
  297.     move (hi(origY)) to origY
  298.     calc (origX - (Width(current_object)) + 1) to origX
  299.     if origX lt 0 move 0 to origX
  300.     set origin to origY origX
  301.   end_procedure
  302.   //
  303.   //Operation: RIGHT_PAGE
  304.   //
  305.   //Assumption(s): none
  306.   //
  307.   //Goal(s): scroll display to left by 1/2 page
  308.   //
  309.   //Algorithm: recalculates and resets ORIGIN
  310.   //
  311.   //Usage: 
  312.   //
  313.   procedure Right_Page
  314.     local integer origX origY
  315.     move (origin(current_object)) to origY
  316.     move (low(origY)) to origX
  317.     move (hi(origY)) to origY
  318.     calc (origX + ((Width(current_object)) / 2)) to origX
  319.     if (origX + (Width(current_object))) gt (Right_Margin(current_object)) ;
  320.         calc ((Right_Margin(current_object)) - (Width(current_object)) + 1) to origX
  321.     set origin to origY origX
  322.   end_procedure
  323.   //
  324.   //Operation: UP_LINE
  325.   //
  326.   //Assumption(s): none
  327.   //
  328.   //Goal(s): scrolls display down one line
  329.   //
  330.   //Algorithm: recalculates and resets ORIGIN
  331.   //
  332.   //Usage: 
  333.   //
  334.   procedure Up_Line
  335.     local integer origX origY
  336.     move (origin(current_object)) to origY
  337.     move (low(origY)) to origX
  338.     move (hi(origY)) to origY
  339.     if origY gt 0 calc (origY - 1) to origY
  340.     set origin to origY origX
  341.   end_procedure
  342.   //
  343.   //Operation: DOWN_LINE
  344.   //
  345.   //Assumption(s): none
  346.   //
  347.   //Goal(s): scrolls display up one line
  348.   //
  349.   //Algorithm: recalculates and resets ORIGIN
  350.   //
  351.   //Usage: 
  352.   //
  353.   procedure Down_Line
  354.     local integer origX origY
  355.     move (origin(current_object)) to origY
  356.     move (low(origY)) to origX
  357.     move (hi(origY)) to origY
  358.     if origY lt (line_count(current_object) - 1) calc (origY + 1) to origY
  359.     set origin to origY origX
  360.   end_procedure
  361.   //
  362.   //Operation: CONTROL_VIEW
  363.   //
  364.   //Assumption(s): none
  365.   //
  366.   //Goal(s): allow user to control trace output
  367.   //
  368.   //Algorithm: keepon = 1
  369.   //           loop
  370.   //             wait for keypress
  371.   //             if key was accelerator, process key action; some key actions
  372.   //               set keepon to 0
  373.   //           until keepon < 1
  374.   //
  375.   //Usage: 
  376.   //
  377.   procedure control_view
  378.     local integer d keepon retval
  379.     local string ch
  380.     move 1 to keepon
  381.     move (Single_Step_State(current_object)) to d
  382.     while d gt 0
  383.       move 0 to termchar
  384.       Repeat
  385.         inkey$ ch
  386.       until termchar ne 0
  387.       if termchar eq kSWITCH  send Toggle_Step
  388.       else if termchar eq kSCROLL_FORWARD send Next_Page
  389.       else if termchar eq kSCROLL_BACK    send Previous_Page
  390.       else if termchar eq kSCROLL_LEFT    send Left_Page
  391.       else if termchar eq kSCROLL_RIGHT   send Right_Page
  392.       else if termchar eq kUPARROW        send Up_Line
  393.       else if termchar eq kDOWNARROW      send Down_Line
  394.       else if termchar eq kCLEAR          send Trace_Switch false false 
  395.       else if termchar eq kCANCEL         begin
  396.         send STOP_UI retval
  397.         move 0 to keepon
  398.       end
  399.       else if termchar eq kEXIT_FUNCTION  begin
  400.         send STOP_UI retval
  401.         move 0 to keepon
  402.       end
  403.       else if termchar eq kFIND_NEXT      begin
  404.         send Continue_Over
  405.         move 0 to keepon
  406.       end
  407.       else if termchar eq kSPACE          begin
  408.         send Continue_In
  409.         move 0 to keepon
  410.       end
  411.       move (Single_Step_State(current_object)) to d
  412.     until keepon lt 1
  413.   end_procedure
  414.   //
  415.   //Operation: OLDEST_DEAD_LEAF
  416.   //
  417.   //Assumption(s): none
  418.   //
  419.   //Goal(s): returns line# of oldest inactive message which has no
  420.   //  sub-messages
  421.   //
  422.   //Algorithm: term = -1
  423.   //           loop through lines in buffer from first to last
  424.   //             if line contains an inactive message
  425.   //               if message has no sub-messages
  426.   //                 set term to line#
  427.   //           until term >= 0
  428.   //           return term
  429.   //
  430.   //Usage: 
  431.   //
  432.   Function Oldest_Dead_Leaf RETURNS integer
  433.     local integer ndx lc d nextD col term
  434.     local string aStr tStr aStr2
  435.     move (line_count(current_object)) to lc
  436.     move -1 to term
  437.     move 0 to ndx
  438.     while ndx lt lc
  439.       move (value(current_object,ndx)) to aStr
  440.       left aStr to aStr2 1
  441.       if aStr2 ne "*" begin
  442.         mid aStr to d 2 2
  443.         calc ((d * 2) + Tracer.MsgHdrSize) to col //calc column offset
  444.         mid aStr to aStr2 1 col
  445.         if ndx lt (lc - 1) begin
  446.           move (value(current_object,(ndx + 1))) to tStr
  447.           mid tStr to nextD 2 2
  448.           if aStr2 eq "└" begin
  449.             if d gt nextD move ndx to term  //got oldest terminal
  450.           end
  451.           else if aStr2 eq "├" begin
  452.             if d eq nextD move ndx to term  //got oldest terminal
  453.           end
  454.         end
  455.       end
  456.       calc (ndx + 1) to ndx
  457.     until term ge 0
  458.     function_Return term
  459.   end_function
  460.   //
  461.   //Operation: SHRINK_QUEUE
  462.   //
  463.   //Assumption(s): none
  464.   //
  465.   //Goal(s): remove oldest inactive, terminal message from queue
  466.   //
  467.   //Algorithm: gets index of oldest inactive terminal message line, goes to
  468.   //           line and deletes it if line# >= 0
  469.   //
  470.   //Usage: 
  471.   //
  472.   procedure Shrink_Queue
  473.     local integer ndx
  474.     move (Oldest_Dead_Leaf(current_object)) to ndx
  475.     if ndx ge 0 begin
  476.       send goto_line ndx
  477.       send delete_line
  478.     end
  479.   end_procedure
  480.   //
  481.   //Operation: TRACE_OUTPUT
  482.   //
  483.   //Assumption(s): inStr is formatted trace-output string
  484.   //
  485.   //Goal(s): process trace-output string and place into queue, allowing
  486.   //  the user to interact with the queue if Single_Step_State is True
  487.   //
  488.   //Algorithm: if Trace_Mode = Mode_Over and message depth > Wait_Depth, exit
  489.   //           turn off dynamic updating
  490.   //           reformat trace-output string for queue
  491.   //           deactivate all messages of higher depth still active in queue
  492.   //           trim queue if necessary
  493.   //           add new message to end of queue
  494.   //           turn dynamic updating on
  495.   //           send Control_View
  496.   //
  497.   //Usage: 
  498.   //
  499.   procedure trace_output string inStr
  500.     local integer finis i d col qsize lc loopCount ActMsgCount
  501.     local string  ch str
  502.     mid inStr to d 2 2                          //get depth
  503.     if (Trace_Mode(current_object)) eq Tracer.Mode_Over ;
  504.         if d gt (Wait_Depth(current_object)) procedure_Return  //skip
  505.     set dynamic_update_state to false
  506.     move 0 to i
  507.     move "" to str
  508.     while i lt (d - 1)
  509.       append str "  "
  510.       calc (i + 1) to i
  511.     end
  512.     move ("*"+mid(inStr,2,2)+" ["+mid(inStr,4,7)+"] "+str+"└") to str
  513.     append str (right(inStr,(length(inStr) - Tracer.MsgHdrSize - 1)))
  514.     move str to inStr
  515.     move (Active_Msg_Count(current_object)) to ActMsgCount
  516.     move 0 to finis
  517.     get line_Count to loopCount              //get number of lines
  518.     while loopCount gt 0
  519.       get value item (loopCount - 1) to str
  520.       mid str to i 2 2                            //get depth
  521.       if d gt i move 1 to finis
  522.       else begin  //inactivate and edit message in queue, update ActMsgCount
  523.         if d lt i begin
  524.           move "│" to ch
  525.           calc ((d * 2) + Tracer.MsgHdrSize) to col //calc column offset
  526.         end
  527.         else begin
  528.           move "├" to ch
  529.           calc ((i * 2) + Tracer.MsgHdrSize) to col //calc column offset
  530.         end
  531.         move (left(str,(col - 1)) + ch + ;
  532.               right(str,(length(str) - col))) to str
  533.         left str to ch 1
  534.         if ch EQ "*" begin
  535.           replace "*" in str with " "
  536.           calc (ActMsgCount - 1) to ActMsgCount
  537.         end
  538.         set value item (loopCount - 1) to str
  539.       end
  540.       calc (loopCount - 1) to loopCount
  541.     until finis ne 0
  542.     move (Queue_Size(current_object)) to qsize
  543.     move (line_Count(current_object)) to lc
  544.     if (lc - ActMsgCount) gt QSize send Shrink_Queue  //drop a message from queue
  545.     if lc gt (Height(current_object)) set origin to (lc - (Height(current_object)) + 1) 0
  546.     else set origin to 0 0
  547.     send end_of_data
  548.     if lc gt 0 send key kEnter
  549.     set dynamic_update_state to true
  550.     if (length(inStr)) gt (Right_Margin(current_object)) left inStr to inStr (Right_Margin(current_object))
  551.     send insert inStr
  552.     set Active_Msg_Count to (ActMsgCount + 1)
  553.     set Current_Depth to d
  554.     send control_view
  555.   end_procedure
  556. end_class
  557.  
  558.