home *** CD-ROM | disk | FTP | other *** search
- /***********************************************************************************/
- /* Highlight the lines between a 'begin' and 'end' RPG Control */
- /* structure. For instance, place cursor of line containing IFEQ */
- /* and will highlite all of the lines to the matching ENDIF */
- /* */
- /* (C) Copyright IBM Corporation 1993 - 1995 */
- /* */
- /***********************************************************************************/
- /* */
- /* The match command takes one parameter, JUMP. If this parameter is issued, the */
- /* cursor jumps to the matching END without highlighting. */
- /* */
- /***********************************************************************************/
-
- parse arg opTion /* to get options */
- opTion = translate(opTion)
- prefNum = 1 /* to allow highliting */
- if opTion = 'JUMP' then prefNum = 0
-
- 'EXTRACT DOCTYPE CONTENT' /* get document type */
- 'EXTRACT ELEMENTS' /* total number of lines */
- 'EXTRACT ELEMENT POSITION' /* and current line */
- rowNum = element /* get the starting line number,*/
- colNum = position /* column number */
-
- if (doctype = "RPG") then opcode = 28 /* opcode in column 28 for RPG */
- else opcode = 26 /* and column 26 for ILE RPG */
-
- str2 = Substr(content,opcode,2) /* get the contents */
- str3 = Substr(content,opcode,3) /* starting from the */
- str5 = Substr(content,opcode,5) /* line number 28 */
- str6 = Substr(str5, 4, 2) /* Opcode + 3 */
- specChar = Substr(content,6,1) /* RPG C specs ? */
- ProcBegEnd = Substr(content,24,1) /* RPG Proc Begin/End */
- parse upper var str2 str2 /* Convert to Upper */
- parse upper var str3 str3 /* Convert to Upper */
- parse upper var str5 str5 /* Convert to Upper */
- parse upper var str6 str6 /* Convert to Upper */
- parse upper var specChar specChar /* Convert to Upper */
- parse upper var ProcBegEnd ProcBegEnd /* Convert to Upper */
-
- keyNum = 1 /* how many keywords ? */
- num = -1 /* just a flag */
- maxLineNo = 0 /* to check wrapping */
-
- nextclass = 'CONTROL'
- If ((str2='IF' | str2='DO' | str2='WH' | str3='DOU' | str3='DOW' |,
- str3='CAS' | str5='SELEC' ) & specChar='C') then num = 1
- if (str3 = 'END' & specChar = 'C') then num = 0 /* if END, match others */
- if (specChar = 'P') then do /* Procedure? */
- nextclass = 'SUBROUTINE'
- if (ProcBegEnd = 'B') then num = 1 /* Beginning?? */
- else if (ProcBegEnd = 'E') then num = 0 /* Ending?? */
- end
- else if ((specChar = 'C') & (str6 = 'SR')) then do /* Subroutine? */
- nextclass = 'SUBROUTINE'
- if (str5 = 'BEGSR') then num = 1 /* Beginning?? */
- else if (str5 = 'ENDSR') then num = 0 /* Ending?? */
- end
-
- if (num = 0 | num = 1) then /* IFxx or ENDxx, continue here */
- do
- if (Substr(content,7,1) = '*') then /* comment */
- do
- Msg 'Cursor is on a comment line'
- Exit 0
- end
- if (str5= 'CASEQ') then /* for CALL statements */
- do
- Msg 'Cursor is on the calling statement'
- Exit 0
- end
- if (prefNum = 1) then /* block the lines */
- do
- 'BLOCK CLEAR' /* clear if already blocked */
- 'BLOCK SET ELEMENT' /* set starting of the block */
- end
-
- Do until ( keyNum = 0 )
- 'EXTRACT ELEMENT'
- if (maxLineNo < element) then maxLineNo = element
- else
- do
- msg 'Match not found ... wrapping'
- exit 0
- end
- if ((num = 1 & element = elements) | (num = 0 & element =1)) then
- do /* search for the end */
- 'BLOCK CLEAR' /* clear if already blocked */
- 'FIND ELEMENT' rowNum /* to handle mismatching */
- 'SET POSITION' colNum /* cases-reset the pos. */
- if (num=1) then Msg 'Matching END not found '
- else Msg 'Matching statement not found'
- Exit 0
- end
-
- if (num = 1) then
- 'NEXT CLASS' nextclass
- else 'PREV CLASS' nextclass /* upwards or downwards */
-
- 'EXTRACT CONTENT' /* get the current line */
-
- text2 = Substr(content,opcode,2) /* for IF, DO, WH.. */
- text3 = Substr(content,opcode,3) /* for DOW.., DOU.. */
- text5 = Substr(content,opcode,5) /* for SELEC. */
- specChar = Substr(content,6,1) /* RPG C specs ? */
- ProcBegEnd = Substr(content,24,1) /* RPG Proc Begin/End*/
- parse upper var text2 text2 /* Convert to Upper */
- parse upper var text3 text3 /* Convert to Upper */
- parse upper var text5 text5 /* Convert to Upper */
- parse upper var specChar specChar /* Convert to Upper */
- parse upper var ProcBegEnd ProcBegEnd /* Convert to Upper */
-
- if (text2 = 'IF' | text2= 'WH' | text2 = 'DO' | text3 = 'DOW' |,
- text3 = 'DDU' | text3 = 'CAS' |,
- text5 = 'SELEC' |,
- ((specChar='P') & (ProcBegEnd='B')) |,
- ((specChar='C') & (text5='BEGSR'))) then
- do
- if (text5 \= 'CASEQ') then
- do
- if(num = 1) then
- keyNum = keyNum + 1
- else keyNum = keyNum -1
- end
- end
-
- if ((text3 = 'END') |,
- ((specChar='P') & (ProcBegEnd='E')) |,
- ((specChar='C') & (text5='ENDSR')) ) then
- do
- if (text5 \= 'ENDCS') then
- do
- if (num = 0) then
- keyNum = keyNum +1
- else keyNum = keyNum -1
- end
- end
- end
- if (prefNum = 1) then
- do
- 'BLOCK SET'
- 'FIND ELEMENT' rowNum /* reset cursor position */
- 'SET POSITION' colNum
- end
- end
- else
- Msg 'Cursor is not on the proper line'
- Exit 0 /* normal exit */