home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1993 #3 / NN_1993_3.iso / spool / vmsnet / tpu / 614 < prev    next >
Encoding:
Internet Message Format  |  1993-01-28  |  5.4 KB

  1. Path: sparky!uunet!ukma!cs.widener.edu!cs.widener.edu!usenet
  2. From: YOUNG@tattoo.cs.widener.edu (Rob Young)
  3. Newsgroups: vmsnet.tpu
  4. Subject: Re: HELP!! String search and replace
  5. Date: 28 Jan 1993 08:04:29 GMT
  6. Organization: Widener News/Mail Gateway
  7. Lines: 131
  8. Distribution: world
  9. Message-ID: <1k842dINN32v@cs.widener.edu>
  10. References: <1993Jan27.022647.21209@seq.uncwil.edu> <1k5t24INN2ei@gap.caltech.edu> <1993Jan28.025042.7651@seq.uncwil.edu>
  11. NNTP-Posting-Host: tattoo.cs.widener.edu
  12. X-News-Reader: VMS NEWS 1.20
  13. In-Reply-To: hawks@seq.uncwil.edu's message of Thu, 28 Jan 1993 02:50:42 GMT
  14.  
  15. In <1993Jan28.025042.7651@seq.uncwil.edu> hawks@seq.uncwil.edu writes:
  16.  
  17.  
  18.     To do what you are after you could put a wrapper on the following
  19.     .com like so:
  20.  
  21.  
  22.     $ loop:
  23.     $ nextfile = f$search("*.*")
  24.     $ if nextfile .eqs. "" then exit
  25.     $ device = f$parse(nextfile,,"device")
  26.     $ direct = f$parse(nextfile,,"directory")
  27.     $ filename = f$parse(nextfile,,"name")
  28.     $ ftype = f$parse(nextfile,,"type")
  29.     $ allpieces = device + direct + filename + ftype
  30.     $ @replace_wildcard 'nextfile' 'allpieces' oldstring newstring
  31.     $ goto loop
  32.  
  33. The above is meant as an example.  I am unable to spawn out of this crazy
  34. newsreader and so can't test what is above.  What I am attempting to
  35. do is create a higher version of the same file.
  36.  
  37.  
  38.     From an earlier post, thanks to Brian McCarthy.  Very good
  39.     little piece of TPU.  One thing, note the dpl$$build needs to
  40.     be replaced.
  41.  
  42.  
  43. ---- Begin earlier post -----
  44.  
  45. From: dectpu/eve Engineering - the last of a dying race 20-Nov-1992 1545
  46. Newsgroups: vmsnet.tpu
  47. Subject: re:  How to EDIT files via a COMMAND FIle
  48. Message-ID: <9211202047.AA07837@enet-gw.pa.dec.com>
  49. Date: 20 Nov 92 20:47:49 GMT
  50. Reply-To: DECTPU/EVE Engineering - the last of a dying race 20-Nov-1992
  51.  
  52. >>% From: "Frank (Chip) Dyer x9568 ..Electrical Design" <DYERFDF@hsdwl.utc.com
  53.  
  54. Writes:
  55.  
  56. > EVE/TPU experts:
  57. >
  58. > I have about 50 files with the number "100C000" (hexadecimal) in them.  I
  59. > need to edit all these files and replace "100C000" with "1010000."  Is it
  60. > possible to do this through a non-interactive (automatic) process?
  61. >
  62. > Ideally I want to have a COMMAND procedure do a GLOBLAL REPLACE on
  63. > "100C000" - something like
  64. >
  65. >    $ EDIT/TPU/NOINIT/NODISplay/COMmand=SYS$INPUT in.src/OUTput=OUT.SRC
  66. >    EVE_REPLACE("100A","*!!*!!**")
  67. >    $ EXIT
  68. >
  69. > Is this possible?  I have never written or used any TPU procedures, so
  70. > any help you can provide will greatly be appreciated.  I use EVE quite a
  71. > bit, but as far as writing or using TPU procedures, I have never done
  72. > that.
  73. >
  74. >
  75. > Thanx,  Frank
  76.  
  77. Here ya go:
  78.  
  79. $! replace_wildcard.com
  80. $!
  81. $! generic replacement com file.  Changes every occurance of P3 to P4
  82. $! found in file P1 and writes it out to P2
  83. $!
  84. $! If p3 (the search string) contains a wildcard character ("*"), then
  85. $! P5 contains what characters are to be matched for that wildcard character
  86. $! For example:
  87. $!
  88. $! @replace_wildcard <input-file> <output-file> "export : '*';" -
  89. $! $_           "export : 'V01-123';" "vx1234567890-"
  90. $!
  91. $! would cause the following strings
  92. $! export : '';
  93. $! export : 'Vx001-x55';
  94. $! export : 'V1.0';
  95. $! to be replaced with
  96. $! "export : 'V01-123';"
  97. $!
  98. $ open/write replace_cmd dpl$$build:replace_dpl.tmp
  99. $ write replace_cmd "procedure global_replace (find_pat, repl_str, wild_chars);"
  100. $ write replace_cmd "local found_wildcard,begin_str,end_str,search_pattern,r1;"
  101. $ write replace_cmd "found_wildcard := index (find_pat, ""*"");"
  102. $ write replace_cmd "if found_wildcard = 0"
  103. $ write replace_cmd "then"
  104. $ write replace_cmd "    search_pattern := find_pat;"
  105. $ write replace_cmd "else"
  106. $ write replace_cmd "    begin_str := SUBSTR (find_pat, 1, found_wildcard-1);
  107. $ write replace_cmd "    end_str := SUBSTR (find_pat, found_wildcard+1);
  108. $ !
  109. $ ! Create a pattern that starts with everything up to the wildcard and then
  110. $ ! spans all the characters passed in to the command procedure in p5, then
  111. $ ! ends with what ever follows the wildcard character
  112. $ !
  113. $ write replace_cmd "    search_pattern := begin_str + (SPAN (wild_chars) | """")  + end_str;"
  114. $ write replace_cmd "endif;"
  115. $ write replace_cmd "position (beginning_of (current_buffer));"
  116. $ write replace_cmd "loop"
  117. $ write replace_cmd "    r1 := search_quietly (search_pattern, forward, no_exact);"
  118. $ write replace_cmd "    if r1 = 0 then return; endif;"
  119. $ write replace_cmd "    position (r1);"
  120. $ write replace_cmd "    erase (r1);"
  121. $ write replace_cmd "    copy_text (repl_str);"
  122. $ write replace_cmd "endloop;"
  123. $ write replace_cmd "endprocedure;"
  124. $ write replace_cmd "!"
  125. $ write replace_cmd "b1 := create_buffer (""b1"", get_info(command_line,""file_name""));"
  126. $ write replace_cmd "position (b1);"
  127. $ write replace_cmd "global_replace (""''P3'"", ""''P4'"", ""''p5'"");"
  128. $ write replace_cmd "write_file (b1, get_info(command_line, ""output_file""));"
  129. $ write replace_cmd "quit (off, 1);             "
  130. $ close replace_cmd
  131. $ EDIT/TPU/NODISP/NOSECT/NOINIT/COMMAND=replace_wildcard.tmp -
  132.     /output='P2 'P1
  133. $ !
  134. ********************************************************************************
  135. Brian J. McCarthy - DECTPU/EVE Development Project Leader
  136.  
  137. Digital Equipment Corp,  Nashua, NH
  138. ********************************************************************************
  139.  
  140. ---- End earlier post -----
  141.  
  142.                                                      young@tattoo.cs.widener.edu
  143. "He's got a force field and a flexible plan He's got a date with fate 
  144.    in a black sedan.  He plays fast forward as long as he can.  But he won't 
  145.      need a bed -- He's a DIGITAL man."                  -- Neil Peart  
  146.