home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 10 Tools / 10-Tools.zip / VSCPPv7.zip / VACPP / IBMCPP / macros / MATCH.LX < prev    next >
Text File  |  1995-05-11  |  6KB  |  120 lines

  1. /***********************************************************************************/
  2. /* Highlight the lines between a 'begin' and 'end' RPG Control                     */
  3. /* structure.  For instance, place cursor of line containing IFEQ                  */
  4. /* and will highlite all of the lines to the matching ENDIF                        */
  5. /*                                                                                 */
  6. /*          Copyright: IBM Corporation 1993                                        */
  7. /*                                                                                 */
  8. /***********************************************************************************/
  9. /*                                                                                 */
  10. /* The match command takes one parameter, JUMP. If this parameter is issued, the   */
  11. /* cursor jumps to the matching END without highlighting.                          */
  12. /*                                                                                 */
  13. /***********************************************************************************/
  14.  
  15. parse  arg opTion                                  /* to get options               */
  16. opTion = translate(opTion)
  17. prefNum    = 1                                     /* to allow highliting          */
  18. if opTion  = 'JUMP' then prefNum = 0
  19.  
  20. 'Extract doctype content'                          /* get document type and current line */
  21. 'Extract elements'                                 /* total number of lines        */
  22. 'Extract element position'
  23. rowNum = element                                  /* get the starting line number,*/
  24. colNum = position                                 /* column number                */
  25.  
  26. if (doctype = "RPG") then opcode = 28             /* opcode in column 28 for RPG   */
  27. else opcode = 26                                  /* and column 26 for ILE RPG     */
  28.  
  29. str2           = Substr(content,opcode,2)                  /* get the contents     */
  30. str3           = Substr(content,opcode,3)                  /* starting from the    */
  31. Str5           = Substr(content,opcode,5)                  /* line number 28       */
  32. specChar       = Substr(content,6,1)                       /* RPG C specs ?        */
  33.  
  34. keyNum         =  1                                        /* how many keywords ?  */
  35. num            = -1                                        /* just a flag          */
  36. maxLineNo      =  0                                        /* to check wrapping    */
  37.                            
  38. If ((str2='IF' | str2='DO' | str2='WH' | str3='DOU' | str3='DOW' |,
  39.     str3='CAS' | Str5='SELEC' ) & specChar='C') then   num = 1
  40. if (str3 = 'END' & specChar = 'C') then num = 0            /* if END, match others */
  41.                      
  42. if (num = 0 | num = 1)  then                       /* IFxx or ENDxx, continue here */
  43.     do
  44.        if (Substr(content,7,1) = '*') then                            /* comment   */
  45.           do
  46.                 Msg 'Cursor is on the Comment line'
  47.                 Exit 0
  48.           end
  49.        if (str5= 'CASEQ') then                     /* for CALL statements          */
  50.           do
  51.                 Msg ' Cursor is on the calling statement'
  52.                 Exit 0
  53.           end
  54.        if (prefNum = 1) then                               /* block the lines      */
  55.           do
  56.                 'block clear'                      /* clear if already blocked     */
  57.                 'block Set element'                /* set starting of the block    */
  58.           end
  59.  
  60.        Do until ( keyNum = 0 )
  61.           'Extract element'
  62.           if (maxLineNo < element) then maxLineNo = element
  63.           else
  64.             do
  65.               msg 'matching not found .. wrapping'
  66.               exit 0
  67.             end
  68.           if ((num = 1 & element = elements) | (num = 0 & element =1)) then
  69.               do                                          /* search for the end    */
  70.                     'block clear'                  /* clear if already blocked     */
  71.                     'Find element' rowNum                 /* to handle mismatching */
  72.                     'Set position' colNum                 /* cases-reset the pos.  */
  73.                      if (num=1) then Msg 'matching END not found '
  74.                         else Msg 'matching statement not found'
  75.                      Exit 0
  76.               end
  77.  
  78.           if (num = 1) then 
  79.                 'Next class CONTROL'
  80.           else  'Prev class CONTROL'                    /* upwards or downwards    */
  81.     
  82.           'Extract content'                          /* get the current line       */
  83.  
  84.            text2 = Substr(content,opcode,2)                    /* for IF, DO, WH.. */
  85.            text3 = Substr(content,opcode,3)                    /* for DOW.., DOU.. */
  86.            text5 = Substr(content,opcode,5)                    /* for SELEC.       */
  87.  
  88.            if (text2 = 'IF' | text2= 'WH' | text2 = 'DO' | text3 = 'DOW' |,
  89.                text3 = 'DDU' | text3 = 'CAS' |,
  90.                text5 = 'SELEC') then
  91.                do
  92.                     if (text5 \= 'CASEQ') then 
  93.                         do
  94.                            if(num = 1) then
  95.                                  keyNum = keyNum + 1
  96.                            else  keyNum = keyNum -1
  97.                         end
  98.                 end
  99.                   
  100.            if (text3 = 'END') then
  101.                do
  102.                     if (text5 \= 'ENDCS') then
  103.                         do
  104.                            if (num = 0) then
  105.                                 keyNum = keyNum +1
  106.                            else  keyNum = keyNum -1
  107.                         end
  108.                end
  109.       end
  110.       if (prefNum = 1) then
  111.           do
  112.               'block Set'
  113.               'Find element' rowNum                      /* reset cursor position */
  114.               'Set position' colNum
  115.           end
  116.     end
  117.  else
  118.          Msg 'cursor is not on the proper line'
  119.  Exit 0                                                           /* normal exit  */
  120.