home *** CD-ROM | disk | FTP | other *** search
/ Power GUI Programming with VisualAge C++ / powergui.iso / trialva / ibmcppw / macros / match.lx < prev    next >
Encoding:
Text File  |  1996-02-22  |  8.1 KB  |  150 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. /*           (C) Copyright IBM Corporation 1993 - 1995                             */
  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            */
  21. 'EXTRACT ELEMENTS'                                /* total number of lines        */
  22. 'EXTRACT ELEMENT POSITION'                        /* and current line             */
  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. str6           = Substr(str5, 4, 2)                        /* Opcode + 3           */
  33. specChar       = Substr(content,6,1)                       /* RPG C specs ?        */
  34. ProcBegEnd     = Substr(content,24,1)                      /* RPG Proc Begin/End   */
  35. parse upper var str2 str2                                  /* Convert to Upper     */
  36. parse upper var str3 str3                                  /* Convert to Upper     */
  37. parse upper var str5 str5                                  /* Convert to Upper     */
  38. parse upper var str6 str6                                  /* Convert to Upper     */
  39. parse upper var specChar specChar                          /* Convert to Upper     */
  40. parse upper var ProcBegEnd ProcBegEnd                      /* Convert to Upper     */
  41.  
  42. keyNum         =  1                                        /* how many keywords ?  */
  43. num            = -1                                        /* just a flag          */
  44. maxLineNo      =  0                                        /* to check wrapping    */
  45.  
  46. nextclass = 'CONTROL'
  47. If ((str2='IF' | str2='DO' | str2='WH' | str3='DOU' | str3='DOW' |,
  48.     str3='CAS' | str5='SELEC' ) & specChar='C') then   num = 1
  49. if (str3 = 'END' & specChar = 'C') then num = 0            /* if END, match others */
  50. if (specChar = 'P') then do                                /* Procedure?           */
  51.   nextclass = 'SUBROUTINE'
  52.   if (ProcBegEnd = 'B') then num = 1                       /*  Beginning??         */
  53.   else if (ProcBegEnd = 'E') then num = 0                  /*  Ending??            */
  54.   end
  55. else if ((specChar = 'C') & (str6 = 'SR')) then do         /* Subroutine?          */
  56.   nextclass = 'SUBROUTINE'
  57.   if (str5 = 'BEGSR') then num = 1                         /*  Beginning??         */
  58.   else if (str5 = 'ENDSR') then num = 0                    /*  Ending??            */
  59.   end
  60.  
  61. if (num = 0 | num = 1)  then                       /* IFxx or ENDxx, continue here */
  62.     do
  63.        if (Substr(content,7,1) = '*') then                            /* comment   */
  64.           do
  65.                 Msg 'Cursor is on a comment line'
  66.                 Exit 0
  67.           end
  68.        if (str5= 'CASEQ') then                     /* for CALL statements          */
  69.           do
  70.                 Msg 'Cursor is on the calling statement'
  71.                 Exit 0
  72.           end
  73.        if (prefNum = 1) then                               /* block the lines      */
  74.           do
  75.                 'BLOCK CLEAR'                      /* clear if already blocked     */
  76.                 'BLOCK SET ELEMENT'                /* set starting of the block    */
  77.           end
  78.  
  79.        Do until ( keyNum = 0 )
  80.           'EXTRACT ELEMENT'
  81.           if (maxLineNo < element) then maxLineNo = element
  82.           else
  83.             do
  84.               msg 'Match not found ... wrapping'
  85.               exit 0
  86.             end
  87.           if ((num = 1 & element = elements) | (num = 0 & element =1)) then
  88.               do                                          /* search for the end    */
  89.                     'BLOCK CLEAR'                  /* clear if already blocked     */
  90.                     'FIND ELEMENT' rowNum                 /* to handle mismatching */
  91.                     'SET POSITION' colNum                 /* cases-reset the pos.  */
  92.                      if (num=1) then Msg 'Matching END not found '
  93.                         else Msg 'Matching statement not found'
  94.                      Exit 0
  95.               end
  96.  
  97.           if (num = 1) then
  98.                 'NEXT CLASS' nextclass
  99.           else  'PREV CLASS' nextclass                  /* upwards or downwards    */
  100.  
  101.           'EXTRACT CONTENT'                          /* get the current line       */
  102.  
  103.            text2 = Substr(content,opcode,2)                    /* for IF, DO, WH.. */
  104.            text3 = Substr(content,opcode,3)                    /* for DOW.., DOU.. */
  105.            text5 = Substr(content,opcode,5)                    /* for SELEC.       */
  106.            specChar   = Substr(content,6,1)                    /* RPG C specs ?    */
  107.            ProcBegEnd = Substr(content,24,1)                   /* RPG Proc Begin/End*/
  108.            parse upper var text2 text2                         /* Convert to Upper */
  109.            parse upper var text3 text3                         /* Convert to Upper */
  110.            parse upper var text5 text5                         /* Convert to Upper */
  111.            parse upper var specChar specChar                   /* Convert to Upper */
  112.            parse upper var ProcBegEnd ProcBegEnd               /* Convert to Upper */
  113.  
  114.            if (text2 = 'IF' | text2= 'WH' | text2 = 'DO' | text3 = 'DOW' |,
  115.                text3 = 'DDU' | text3 = 'CAS' |,
  116.                text5 = 'SELEC' |,
  117.                ((specChar='P') & (ProcBegEnd='B')) |,
  118.                ((specChar='C') & (text5='BEGSR'))) then
  119.                do
  120.                     if (text5 \= 'CASEQ') then
  121.                         do
  122.                            if(num = 1) then
  123.                                  keyNum = keyNum + 1
  124.                            else  keyNum = keyNum -1
  125.                         end
  126.                 end
  127.  
  128.            if ((text3 = 'END') |,
  129.                ((specChar='P') & (ProcBegEnd='E')) |,
  130.                ((specChar='C') & (text5='ENDSR')) ) then
  131.                do
  132.                     if (text5 \= 'ENDCS') then
  133.                         do
  134.                            if (num = 0) then
  135.                                 keyNum = keyNum +1
  136.                            else  keyNum = keyNum -1
  137.                         end
  138.                end
  139.       end
  140.       if (prefNum = 1) then
  141.           do
  142.               'BLOCK SET'
  143.               'FIND ELEMENT' rowNum                      /* reset cursor position */
  144.               'SET POSITION' colNum
  145.           end
  146.     end
  147.  else
  148.          Msg 'Cursor is not on the proper line'
  149.  Exit 0                                                           /* normal exit  */
  150.