home *** CD-ROM | disk | FTP | other *** search
/ OS/2 Shareware BBS: 5 Edit / 05-Edit.zip / texed133.zip / English.zip / Brace.cmd < prev    next >
OS/2 REXX Batch file  |  1996-02-02  |  2KB  |  111 lines

  1. /*
  2.  * BraceCheck
  3.  *
  4.  * This macro marks the whole text between an closing brace and the
  5.  * corresponding (opening) brace for a short time.
  6.  *
  7.  * The cursor has to be on or directly behind a closing brace
  8.  */
  9.  
  10.  
  11. /*
  12.  * Getting the text an the cursor position
  13.  */
  14. Text = VRGet( 'MLE_1', 'Value')
  15. pos  = VRGet( 'MLE_1', 'SelectedStart')
  16. if Check(pos) = 0 then return
  17.  
  18.  
  19. /*
  20.  * Get Brace
  21.  */
  22. if pos \= VRGet( 'MLE_1', 'SelectedEnd') then
  23.    Pos = Max( VRGet( 'MLE_1', 'SelectedStart'), VRGet( 'MLE_1', 'SelectedEnd'))
  24. OldPos = Pos
  25. Pos = Pos - 1
  26. SKl = SubStr( Text, Pos , 1)
  27. select
  28.    when SKl = ')' then OKl = '('
  29.    when SKl = '}' then OKl = '{'
  30.    when SKl = ']' then OKl = '['
  31.    otherwise return
  32. end
  33.  
  34.  
  35. /*
  36.  * Find corresponding brace
  37.  */
  38. found = 1
  39. do while found > 0
  40.    S = LastPos( SKl, Text, pos - 1)
  41.    ImText = Check(S)
  42.    do while ImText = 0
  43.       S = LastPos( SKl, Text, S - 1)
  44.       ImText = Check(S)
  45.    end
  46.    O = LastPos( OKl, Text, pos - 1)
  47.    ImText = Check(O)
  48.    do while ImText = 0
  49.       O = LastPos( OKl, Text, O - 1)
  50.       ImText = Check(O)
  51.    end
  52.    if (S = 0) then
  53.       select
  54.          when O > 0 then S = O - 1
  55.          when O = 0 then do
  56.             call VRMessage VRWindow(), "Öffnende Klammer nicht gefunden.",
  57.                "Klammer Makro", "Information"
  58.             return
  59.          end
  60.       end
  61.    if S > O then do
  62.       found = found + 1
  63.       pos = S
  64.    end
  65.    else do
  66.       found = found - 1
  67.       pos = O
  68.    end
  69. end
  70.  
  71.  
  72. /*
  73.  * Mark text for a short time
  74.  */
  75. call VRSet 'MLE_1', 'SelectedEnd', OldPos
  76. call VRSet 'MLE_1', 'SelectedStart', Pos
  77. do 50000
  78.    nop
  79. end
  80. call VRSet 'MLE_1', 'SelectedStart', OldPos
  81. return
  82.  
  83.  
  84. /*
  85.  * Subroutine, which tests, if the found brace belongs to a comment
  86.  */
  87.  
  88. Check:  procedure expose Text
  89. pos   = arg(1)
  90. rc = 1
  91. if pos > 0 then do
  92.    ENTER = LastPos( D2C(13), Text, pos) + 1
  93.    if ENTER = 1 then return rc
  94.    Str = SubStr(Text, ENTER, pos - ENTER + 1)
  95.    Marker = Pos( ' %', Str)
  96.    if (Marker < pos - ENTER) & (Marker > 0) then return 0
  97.    do forever
  98.       Str = DelStr( Str, 1, 1)
  99.       select
  100.          when C2D( Left( Str, 1, 1)) = '9' then iterate
  101.          when C2D( Left( Str, 1, 1)) = '32' then iterate
  102.          when C2D( Left( Str, 1, 1)) = '37' then do
  103.             rc = 0
  104.             leave
  105.          end
  106.          otherwise leave
  107.       end
  108.    end
  109. end
  110. return rc
  111.