home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / vmsnet / tpu / 484 < prev    next >
Encoding:
Internet Message Format  |  1992-11-09  |  5.4 KB

  1. Path: sparky!uunet!zaphod.mps.ohio-state.edu!moe.ksu.ksu.edu!mccall!info-tpu-newsgate!list
  2. Newsgroups: vmsnet.tpu
  3. Subject: RE: Procedure to matchup (){}[]  ???
  4. Message-ID: <009635A2.BF79C100.26937@SHSU.edu>
  5. From: "George D. Greenwade" <bed_gdg@shsu.edu>
  6. Date: Mon, 09 Nov 1992 10:32:39 CST
  7. Reply-To: "George D. Greenwade" <bed_gdg@SHSU.edu>
  8. Organization: The Internet
  9. Return-Path: <TPU-Mgr@SHSU.edu>
  10. Errors-To: TPU-Mgr@SHSU.edu
  11. X-Listname: Text Processing Utility (TPU) Language Discussion List
  12. CC: info-tpu@SHSU.edu
  13. Lines: 129
  14.  
  15. On 8 Nov 92 05:35:43 CST, ldgiltne@wsuhub.uc.twsu.edu (Lawrence Giltner)
  16. asked:
  17. > Does anybody have a procedure to pair up parenthesis, brackets, and braces.
  18. > I would like to put the cursor on one of ()[]{} and let the program figure
  19. > out which direction it has to search and if found, then marks/selects all
  20. > the text between them, including the ()[]{}.
  21. >
  22. > Is there a TPU procedure for this?   TPU v2.6 on VMS v5.5.
  23. >
  24. > I wrote a procedure like this for VDE and would like the same convenience.
  25.  
  26. Taken shamelessly from my EFE code, I attach efe$find_match and
  27. efe$find_matching.  This set of two procedures allows you to place the
  28. cursor on the opening delimiter, (, [, {, or <, and find the matching
  29. closing delimiter.  This function is defined as Gold/X in EFE.  While I
  30. haven't coded it in, it should be relatively trivial to do a backward
  31. search, starting on the closing delimiter to find the opening delimiter
  32. (copy efe$find_matching to something such as efe$find_matching_reverse,
  33. change the search from forward to reverse in the copied procedure, add a
  34. few extra if/endif statements near the start of efe$find_match pointing to
  35. to efe$find_matching_reverse if the delimiter is a closer, etc.).
  36.  
  37. If you rename efe$find_match to something such as eve_match_delimiter, you
  38. should be able to place the cursor on the opening delimiter, then use
  39. DO/MATCH DELIMITER.
  40.  
  41. Regards,   George
  42. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  43. George D. Greenwade, Ph.D.                            Bitnet:  BED_GDG@SHSU
  44. Department of Economics and Business Analysis         THEnet: SHSU::BED_GDG
  45. College of Business Administration                    Voice: (409) 294-1266
  46. P. O. Box 2118                                        FAX:   (409) 294-3612
  47. Sam Houston State University              Internet:        bed_gdg@SHSU.edu
  48. Huntsville, TX 77341                      bed_gdg%SHSU.decnet@relay.the.net
  49. %%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%%
  50. procedure efe$find_match        ! Find matching enclosures
  51.   local the_char,               ! Character we want to match
  52.         original_position,      ! Where we presently are (mark)
  53.         original_character,     ! What we are trying to match
  54.         find_character,         ! Character we are searching for
  55.         found_target,           ! Where we are going (mark)
  56.         response;               ! Check to go to first mark
  57.     original_position := mark(reverse);
  58.     original_character := current_character;
  59.     if original_character = "(" then find_character := ")" ;
  60.     else
  61.         if original_character = "[" then find_character := "]" ;
  62.     else
  63.         if original_character = "{" then find_character := "}" ;
  64.     else
  65.         if original_character = "<" then find_character := ">" ;
  66. ! EFE.TPU                 25-APR-1991 18:18                            PAGE 35
  67.     else    message("Current character is not a valid starting delimiter.  " +
  68.                       "Must be (,[,{, or < .");
  69.         return;
  70.         endif;
  71.         endif;
  72.         endif;
  73.     endif;
  74. if original_character = "(" then efe$find_matching("(",")");
  75. else
  76.     if original_character = "[" then efe$find_matching("[","]");
  77. else
  78.     if original_character = "{" then efe$find_matching("{","}");
  79. else
  80.     if original_character = "<" then efe$find_matching("<",">");
  81.     endif;
  82.     endif;
  83.     endif;
  84. endif;
  85. if current_character <> find_character then
  86.  message(find_character + ' not found!');
  87. position(original_position);
  88. return;
  89. endif;
  90. found_target := mark(bold);
  91.     set(screen_update,on);
  92.     update(current_window);
  93. EVE$PROMPT_STRING("",response,
  94.     "Return to original (boxed) search position? [Yes] ","");
  95.     edit(response,UPPER);
  96. if SUBSTR(response,1,1) = "Y" then position(original_position);
  97. else
  98. if SUBSTR(response,1,1) = "" then position(original_position);
  99. endif;
  100. endif;
  101. set(screen_update,on);
  102. endprocedure;  !efe$find_match
  103.  
  104.  
  105. ! EFE.TPU                 25-APR-1991 18:18                            PAGE 36
  106. procedure efe$find_matching(match_left,match_right)
  107. local   next_close, ! Marks next closing paren
  108.     next_open,  ! Marks next open paren
  109.     next_close_mark,
  110.     next_open_mark,
  111.     temp_mark;
  112.   on_error  ! Ignore search fails
  113.   endon_error;
  114.   loop
  115.     move_horizontal (1);
  116.     next_close := search (match_right,forward);
  117.     if next_close = 0 then
  118.       return (0);
  119.     else
  120.       temp_mark := mark(none);
  121.       position (next_close);
  122.       next_close_mark := mark(none);
  123.       position (temp_mark);
  124.     endif;
  125.     next_open := search (match_left,forward);
  126.     if next_open <> 0 then
  127.       position (next_open);
  128.       next_open_mark := mark(none);
  129.       if next_open_mark < next_close_mark then
  130.         if (not efe$find_matching(match_left,match_right)) then
  131.       return (0);
  132.     endif;
  133.       else
  134.     position (next_close);
  135.     exitif 1;
  136.       endif;
  137.     else
  138.       position (next_close);
  139.       exitif 1;
  140.     endif;
  141.   endloop;
  142.   return (1);
  143. endprocedure;  !efe$find_matching
  144.