home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #26 / NN_1992_26.iso / spool / vmsnet / tpu / 482 < prev    next >
Encoding:
Text File  |  1992-11-08  |  11.9 KB  |  338 lines

  1. Newsgroups: vmsnet.tpu
  2. Path: sparky!uunet!zaphod.mps.ohio-state.edu!pacific.mps.ohio-state.edu!linac!unixhub!slacvx.slac.stanford.edu!fairfield
  3. From: fairfield@slacvx.slac.stanford.edu
  4. Subject: MATCHD.1-of-1 (Re: Procedure to matchup (){}[]  ???)
  5. Message-ID: <1992Nov8.152144.1@slacvx.slac.stanford.edu>
  6. Lines: 326
  7. Sender: news@unixhub.SLAC.Stanford.EDU
  8. Organization: Stanford Linear Accelerator Center
  9. References: <1992Nov8.053543.383@wsuhub.uc.twsu.edu>
  10. Date: Sun, 8 Nov 1992 23:21:44 GMT
  11.  
  12. In article <1992Nov8.053543.383@wsuhub.uc.twsu.edu>, ldgiltne@wsuhub.uc.twsu.edu (Lawrence Giltner) writes:
  13. > Before I spend a lot of time reinventing the wheel:
  14. > Does anybody have a procedure to pair up parenthesis, brackets, and
  15. > braces.  I would like to put the cursor on one of ()[]{} and let the
  16. > program figure out which direction it has to search and if found, then
  17. > marks/selects all the text between them, including the ()[]{}.
  18. > Is there a TPU procedure for this?   TPU v2.6 on VMS v5.5.
  19.  
  20.     Below I've included a VMS_SHARE file containing TPU code to do just
  21. what you want.  In addition to matching (), [], and {}, it matches <>,
  22. `', Ascii(171) with  Ascii(187) [the left an right angle-quotation marks],
  23. and Asccii(191) with ? [the upside-down with the rightside-up quesion marks].
  24. It also matches double quotes with each other, but that's pretty much useless
  25. as they have no "parity"...
  26.  
  27.     The TPU file is in a form suitable to be include in an EVE$BUILD master 
  28. list, i.e., with MODULE_IDENT and MODULE_INIT routines.  If you just want to
  29. EXTEND TPU * and save the sectionfile, you'll need to move the definition
  30. of khf$kt_left_delims and khf$kt_right_delims to your init file, or into
  31. the main procedure, EVE_MATCH_DELIMITORS, defining them each time through the
  32. routine...
  33.  
  34.     To use, just put the cursor on one member of the delimitors you want to 
  35. match, then hit DO and type "MATCH" on the EVE command line (or define a key 
  36. to do MATCH DELIMITORS and press that key).
  37.  
  38.         Cheers, Ken
  39. -- 
  40.  Dr. Kenneth H. Fairfield    |  Internet: Fairfield@Slac.Stanford.Edu
  41.  SLAC, P.O.Box 4349, MS 98   |  DECnet:   45537::FAIRFIELD (45537=SLACVX)
  42.  Stanford, CA   94309        |  BITNET    Fairfield@Slacvx
  43.  ----------------------------------------------------------------------------
  44.  These opinions are mine, not SLAC's, Stanford's, nor the DOE's...
  45.  
  46. $! ------------------ CUT HERE -----------------------
  47. $ v='f$verify(f$trnlnm("SHARE_UNPACK_VERIFY"))'
  48. $!
  49. $! This archive created by VMS_SHARE Version 8.1
  50. $!   On  8-NOV-1992 15:08:14.25   By user FAIRFIELD   
  51. $!
  52. $! The VMS_SHARE software that created this archive
  53. $!    was written by  Andy Harper, Kings College London UK
  54. $!    -- September 1992
  55. $!
  56. $! Credit is due to these people for their original ideas:
  57. $!    James Gray, Michael Bednarek 
  58. $!
  59. $! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
  60. $! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
  61. $!
  62. $! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
  63. $!       1. MATCHDELIM.TPU;2
  64. $!
  65. $set="set"
  66. $set symbol/scope=(nolocal,noglobal)
  67. $f=f$parse("SHARE_UNPACK_TEMP","SYS$SCRATCH:."+f$getjpi("","PID"))
  68. $e="write sys$error  ""%UNPACK"", "
  69. $w="write sys$output ""%UNPACK"", "
  70. $ if .not. f$trnlnm("SHARE_UNPACK_LOG") then $ w = "!"
  71. $ ve=f$getsyi("version")
  72. $ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto start
  73. $ e "-E-OLDVER, Must run at least VMS 4.4"
  74. $ v=f$verify(v)
  75. $ exit 44
  76. $unpack: subroutine ! P1=filename, P2=checksum, P3=attributes
  77. $ if f$search(P1) .eqs. "" then $ goto file_absent
  78. $ e "-W-EXISTS, File ''P1' exists. Skipped."
  79. $ delete 'f'*
  80. $ exit
  81. $file_absent:
  82. $ if f$parse(P1) .nes. "" then $ goto dirok
  83. $ dn=f$parse(P1,,,"DIRECTORY")
  84. $ w "-I-CREDIR, Creating directory ''dn'"
  85. $ create/dir 'dn'
  86. $ if $status then $ goto dirok
  87. $ e "-E-CREDIRFAIL, Unable to create ''dn' File skipped."
  88. $ delete 'f'*
  89. $ exit
  90. $dirok:
  91. $ w "-I-UNPACK, Unpacking file ''P1'"
  92. $ n=P1
  93. $ if P3 .nes. "" then $ n=f
  94. $ if .not. f$verify() then $ define/user sys$output nl:
  95. $ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='n'
  96. PROCEDURE GetHex LOCAL x1,x2;x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,
  97. ERASE_CHARACTER(1))-1;RETURN 16*x1+x2;ENDPROCEDURE;
  98. PROCEDURE SkipPartsep LOOP EXITIF INDEX(ERASE_LINE,"-+-+-+-+-+-+-+-+")=1;
  99. ENDLOOP;ENDPROCEDURE;
  100. PROCEDURE ExpandChar CASE CURRENT_CHARACTER FROM ' ' TO 'z' ["`"]
  101. :ERASE_CHARACTER(1);COPY_TEXT(ASCII(GetHex));[" "]:ERASE_CHARACTER(1);[
  102. OUTRANGE,INRANGE]:MOVE_HORIZONTAL(1);ENDCASE;ENDPROCEDURE;
  103. PROCEDURE ProcessLine s:=ERASE_CHARACTER(1);LOOP EXITIF CURRENT_OFFSET>=LENGTH(
  104. CURRENT_LINE);ExpandChar;ENDLOOP;IF s="V" THEN APPEND_LINE;ENDIF;ENDPROCEDURE;
  105. PROCEDURE AdvanceLine MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);
  106. ENDPROCEDURE;PROCEDURE Decode POSITION(BEGINNING_OF(b));LOOP EXITIF MARK(NONE)=
  107. END_OF(b);IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+-")=1 THEN SkipPartSep;
  108. ELSE ProcessLine;AdvanceLine;ENDIF;ENDLOOP;ENDPROCEDURE;SET(FACILITY_NAME,
  109. "UNPACK");SET(SUCCESS,OFF);SET(INFORMATIONAL,OFF);t:="0123456789ABCDEF";f:=
  110. GET_INFO(COMMAND_LINE,"file_name");b:=CREATE_BUFFER(f,f);Decode;WRITE_FILE(b,
  111. GET_INFO(COMMAND_LINE,"output_file"));QUIT;
  112. $ if p3 .eqs. "" then $ goto dl
  113. $ open/write fdl &f
  114. $ write fdl "RECORD"
  115. $ write fdl P3
  116. $ close fdl
  117. $ w "-I-CONVRFM, Converting record format to ", P3
  118. $ convert/fdl=&f &f-1 &P1
  119. $dl: delete 'f'*
  120. $ if P2 .eqs. "" then $ goto ckskip
  121. $ checksum 'P1'
  122. $ if checksum$checksum .nes. P2 then $ -
  123.   e "-E-CHKSMFAIL, Checksum of ''P1' failed."
  124. $ exit
  125. $ckskip: e "-W-CHKSUMSKIP, checksum validation unavailable for ''P1'"
  126. $ endsubroutine
  127. $start:
  128. $!
  129. $ create 'f'
  130. Xprocedure`20KHF_MATCHD_MODULE_IDENT
  131. X`09return`20"V02-001";
  132. Xendprocedure;
  133. X
  134. X
  135. Xprocedure`20KHF_MATCHD_MODULE_INIT
  136. X
  137. X!+
  138. X!`20`20Initialize`20marker`20variables`20used`20by`20Eve_Match_Delimitors:
  139. X!-
  140. X`20`20khf$x_match1_position:=`200;
  141. X`20`20khf$x_match2_position:=`200;
  142. X`20`20khf$x_match3_position:=`200;
  143. X`20`20khf$x_match4_position:=`200;
  144. X
  145. X!+
  146. X!`20`20Initialize`20list`20of`20delimitors`20used`20by`20Eve_Match_Delimitors.
  147. V`20`20Include
  148. X!`20`20double-angle`20quotes`20and`20upside-down`20question`20mark`20in`20deli
  149. Vmitor`20list;
  150. X!`20`20a`20generic`20double-quote`20mark`20matches`20itself.`20`20A`20user`20m
  151. Vay`20modify`20these
  152. X!`20`20strings`20in`20a`20TPU$COMMAND`20procedure.
  153. X!-
  154. X`20`20khf$kt_left_delims`20`20:=`20Ascii(34)`20+`20"(<`5B`60`7B"`20+`20Ascii(1
  155. V71)`20+`20Ascii(191);
  156. X`20`20khf$kt_right_delims`20:=`20Ascii(34)`20+`20")>`5D'`7D"`20+`20Ascii(187)
  157. V`20+`20"?";
  158. X
  159. Xendprocedure;
  160. X
  161. X
  162. X!++
  163. X!`20`20`20This`20procedure`20highlights`20(in`20BOLD,`20REVERSE`20video)`20mat
  164. Vching`20pairs
  165. X!`20`20`20of`20delimitors,`20the`20first`20of`20which`20is`20taken`20to`20be
  166. V`20the`20character`20at
  167. X!`20`20`20the`20current`20cursor`20position.`20`20Highlighting`20is`20turned
  168. V`20off`20by`20invoking
  169. X!`20`20`20this`20procedure`20with`20the`20cursor`20positioned`20on`20a`20non-d
  170. Velimitor`20character.
  171. X!`20`20`20Subsequent`20invocations`20turn`20off`20the`20highlighting`20on`20pr
  172. Veviously`20matched
  173. X!`20`20`20pairs,`20as`20well.
  174. X!
  175. X!`20`20`20This`20procedure`20uses`20the`20global`20marker`20variables`20khf$x_
  176. Vmatch1_position,
  177. X!`20`20`20khf$x_match2_position,`20khf$x_match3_position,`20and`20khf$x_match4
  178. V_position.
  179. X!
  180. X!`20Author/Date:`09`09K.H.`20Fairfield,`09`0916-Jan-1988
  181. X!
  182. X!--
  183. XProcedure`20Eve_Match_Delimitors
  184. X!`09`20`20--------------------
  185. XLocal`20saved_mark,`09!`20mark`20current`20position
  186. X`20`20`20`20`20`20first_char,`09!`20first`20character`20of`20matching`20pair
  187. X`20`20`20`20`20`20last_char,`09!`20second`20character`20of`20matching`20pair
  188. X`20`20`20`20`20`20direction,`09!`20search`20direction
  189. X`20`20`20`20`20`20n;`09`09!`20character`20position`20in`20khf$kt_left_delims
  190. V`20or
  191. X`09`09`09!`20khf$kt_right_delims`20string.
  192. X
  193. X
  194. X`20`20`20`20On_Error
  195. X`09`5BTPU$_CONTROLC`5D:
  196. X`09`20`20`20`20Eve$Learn_Abort;
  197. X`09`20`20`20`20Eve$$Restore_Position`20(saved_mark);
  198. X`09`5BOTHERWISE`5D:
  199. X`09`20`20`20`20Eve$$Restore_Position`20(saved_mark);
  200. X`20`20`20`20Endon_Error;
  201. X
  202. X
  203. X`20`20`20`20saved_mark`20:=`20Mark`20(NONE);
  204. X
  205. X!+
  206. X!`20`20Make`20an`20early`20return`20here`20if`20the`20current`20position`20is
  207. V`20the`20same
  208. X!`20`20position`20as`20the`20last`20previously`20marked`20delimitor.
  209. X!-
  210. X`20`20`20`20If`20khf$x_match1_position`20<>`200`20Then
  211. X`09If`20saved_mark`20=`20khf$x_match1_position`20Then
  212. X
  213. X`09`20`20`20`20khf$x_match1_position:=`200;
  214. X`09`20`20`20`20khf$x_match2_position:=`200;
  215. X`09`20`20`20`20khf$x_match3_position:=`200;
  216. X`09`20`20`20`20khf$x_match4_position:=`200;
  217. X`09`20`20`20`20Return`20(TRUE);
  218. X
  219. X`09Endif;
  220. X`20`20`20`20Endif;
  221. X
  222. X`20`20`20`20first_char`20:=`20CURRENT_CHARACTER;
  223. X
  224. X`20`20`20`20n`20:=`20Index`20(khf$kt_left_delims,`20first_char);
  225. X
  226. X`20`20`20`20If`20n`20>`200`20Then
  227. X`09last_char`20:=`20Substr`20(khf$kt_right_delims,`20n,`201);
  228. X`09direction`20:=`20FORWARD;
  229. X`20`20`20`20Else
  230. X`09n`20:=`20Index`20(khf$kt_right_delims,`20first_char);
  231. X
  232. X`09If`20n`20>`200`20Then
  233. X`09`20`20`20`20last_char`20:=`20Substr`20(khf$kt_left_delims,`20n,`201);
  234. X`09`20`20`20`20direction`20:=`20REVERSE;
  235. X`09Else
  236. X!+
  237. X!`20`20Current_Character`20was`20not`20a`20delimitor.`20`20If`20highlighting
  238. V`20is`20on,`20turn`20it
  239. X!`20`20off,`20else`20issue`20an`20error`20message.
  240. X!-
  241. X`09`20`20`20`20If`20khf$x_match1_position`20=`200`20Then
  242. X`09`09Eve$message`20("The`20current`20character,`20"`20+`20first_char`20+
  243. X`09`09`09`20",`20is`20not`20a`20valid`20delimitor`20to`20match.");
  244. X`09`20`20`20`20Endif;
  245. X`09`20`20`20`20khf$x_match1_position:=`200;
  246. X`09`20`20`20`20khf$x_match2_position:=`200;
  247. X`09`20`20`20`20khf$x_match3_position:=`200;
  248. X`09`20`20`20`20khf$x_match4_position:=`200;
  249. X`09`20`20`20`20Return`20(FALSE);
  250. X`09Endif;
  251. X`20`20`20`20Endif;
  252. X
  253. X`20`20`20`20khf$x_match1_position:=`20Mark`20(BOLD);
  254. X`20`20`20`20khf$x_match2_position:=`20Mark`20(REVERSE);
  255. X
  256. X`20`20`20`20If`20Khf_Find_Match`20(first_char,`20last_char,`20direction)`20=
  257. V`201`20Then
  258. X`09khf$x_match3_position:=`20Mark`20(BOLD);
  259. X`09khf$x_match4_position:=`20Mark`20(REVERSE);
  260. X`09Update`20(CURRENT_WINDOW);
  261. X`09Position`20(khf$x_match1_position);
  262. X`09Return`20(TRUE);
  263. X`20`20`20`20Else
  264. X`09Position`20(khf$x_match1_position);
  265. X`09khf$x_match1_position:=`200;
  266. X`09khf$x_match2_position:=`200;
  267. X`09khf$x_match3_position:=`200;
  268. X`09khf$x_match4_position:=`200;
  269. X`09Eve$message`20("`20Could`20not`20find`20the`20matching`20"`20+`20last_char
  270. V`20+
  271. X`09`09`20"`20character`20for`20the`20current`20character,`20"`20+`20first_char
  272. V);
  273. X`09Return`20(FALSE);
  274. X`20`20`20`20Endif;
  275. X
  276. X
  277. XEndProcedure;`09`09!`20Eve_Match_Delimitors
  278. X
  279. X
  280. X!++
  281. X!`20`20`20The`20following`20procedure`20does`20the`20actually`20search`20for
  282. V`20the`20matching
  283. X!`20`20`20delimitor`20character.`20`20A`20recursive`20algorithm`20is`20used
  284. V`20so`20that`20intervening
  285. X!`20`20`20pairs`20of`20matched`20delimitors`20are`20not`20mistakenly`20selecte
  286. Vd`20as`20the`20match.
  287. X!
  288. X!`20Input`20Parameters:
  289. X!
  290. X!`09first`09`20`20`20`20the`20delimitor`20character`20whose`20mate`20is`20bein
  291. Vg`20sought
  292. X!
  293. X!`09last`09`20`20`20`20the`20matching`20delimitor`20character
  294. X!
  295. X!`09direction`20`20`20the`20direction`20to`20search.`20`20If`20first_char`20is
  296. V`20a`20right-
  297. X!`09`09`20`20`20`20delimitor,`20the`20search`20direction`20is`20FORWARD,
  298. X!`09`09`20`20`20`20otherwise`20it`20is`20REVERSE.
  299. X!
  300. X!`20Author/Date:`09`09K.H.`20Fairfield,`09`0916-Jan-1988
  301. X!-
  302. X
  303. XProcedure`20Khf_Find_Match`20(first,`20last,`20direction)
  304. X!`09`20`20--------------
  305. XLocal`20this_patt,`20this_range;
  306. X
  307. X`20`20`20`20this_patt`20:=`20first`20+`20last;
  308. X`20`20`20`20Loop
  309. X`09If`20direction`20=`20FORWARD`20Then
  310. X`09`20`20`20`20Move_Horizontal`20(1);
  311. X`09Else
  312. X`09`20`20`20`20Move_Horizontal`20(-1);
  313. X`09Endif;
  314. X`09this_range`20:=`20Search_Quietly`20(Any`20(this_patt),`20direction);
  315. X`09If`20this_range`20<>`200
  316. X`09Then
  317. X`09`20`20`20`20Position`20(this_range);
  318. X`09Else
  319. X`09`20`20`20`20Return`20(0);
  320. X`09Endif;
  321. X`09If`20CURRENT_CHARACTER`20=`20last`20Then
  322. X`09`20`20`20`20Return`20(1);
  323. X`09Else
  324. X`09`20`20`20`20If`20Khf_Find_Match`20(first,`20last,`20direction)`20=`200`20Th
  325. Ven
  326. X`09`09Return`20(0);
  327. X`09`20`20`20`20Endif;
  328. X`09Endif;
  329. X`20`20`20`20Endloop;
  330. X
  331. XEndprocedure;`09`09!`20Khf_Find_Match
  332. X
  333. $ call unpack MATCHDELIM.TPU;2 1952715885 ""
  334. $ v=f$verify(v)
  335. $ exit
  336.