home *** CD-ROM | disk | FTP | other *** search
/ BCI NET 2 / BCI NET 2.iso / archives / applications / wp / polyed.lha / PolyEd / macros / brackets.ped < prev    next >
Encoding:
Text File  |  1994-11-13  |  1.5 KB  |  81 lines

  1. /*(((HaHa)))*/
  2.  
  3. /*
  4. ** $VER: bracket.rexx 1.0 (12.11.94) written by Robert Brandner
  5. **
  6. ** Finds corresponding bracket
  7. **
  8. ** Das geht nicht sehr gut in ARexx !
  9. */
  10.  
  11. /* enable return codes */
  12.  
  13. OPTIONS RESULTS
  14.  
  15. TRACE RESULTS
  16.  
  17. /* is PolyEd out there ? */
  18.  
  19. if ~SHOW("Ports", "POLYED.1") then do
  20.     say "Please start PolyEd before running this program."
  21.     exit
  22. end
  23.  
  24. ADDRESS POLYED.1.1
  25.  
  26.  
  27. 'GETCURSORPOS STEM CPOS.'    /* position in CPOS.LINE and CPOS.COLUMN    */
  28. 'GETCHAR VAR C'
  29.  
  30. OPENING = '([{<'
  31. CLOSING = ')[}>'    /* same order! */
  32.  
  33. OP = pos(C, OPENING)
  34. CL = pos(C, CLOSING)
  35.  
  36. if OP=0 & CL=0 then exit 10    /* not a bracket */
  37.  
  38. /* search forward for a closing bracket */
  39. if OP>0 then do
  40.     'CURSOR RIGHT'    /* move past bracket so that we don't find it again */
  41.     OPCHAR = substr(OPENING, OP, 1)
  42.     CLCHAR = substr(CLOSING, OP, 1)
  43.     LEVEL=1
  44.     do while LEVEL > 0
  45.         /* Find next occurence of opening and closing bracket */
  46.  
  47.         FIND NEXT OPCHAR
  48.         if RC > 0 then break    /* not found! */
  49.  
  50.         'GETCURSORPOS STEM OPPOS.'
  51.         'GOTOLINE' CPOS.LINE
  52.         'GOTOCOLUMN' CPOS.COLUMN
  53.  
  54.         FIND NEXT CLCHAR
  55.         if RC > 0 then break    /* not found! */
  56.         'GETCURSORPOS STEM CLPOS.'
  57.  
  58.  
  59.         if (OPPOS.LINE < CLPOS.LINE) | ((OPPOS.LINE = CLPOS.LINE) & (OPPOS.COLUMN < CLPOS.COLUMN)) then
  60.         do
  61.             LEVEL = LEVEL+1
  62.             CPOS.LINE = OPPOS.LINE
  63.             CPOS.COLUMN = OPPOS.COLUMN
  64.             say CPOS.LINE
  65.             say CPOS.COLUMN
  66.         end
  67.         else
  68.         do
  69.             LEVEL = LEVEL-1
  70.             CPOS.LINE = CLPOS.LINE
  71.             CPOS.COLUMN = CLPOS.COLUMN
  72.         end
  73.  
  74.         'GOTOLINE' CPOS.LINE
  75.         'GOTOCOLUMN' CPOS.COLUMN
  76.     end
  77. end
  78.  
  79. /* The End */
  80.  
  81.