home *** CD-ROM | disk | FTP | other *** search
/ NetNews Usenet Archive 1992 #27 / NN_1992_27.iso / spool / vmsnet / tpu / 516 < prev    next >
Encoding:
Internet Message Format  |  1992-11-23  |  4.9 KB

  1. Path: sparky!uunet!olivea!decwrl!pa.dec.com!rdg.dec.com!uvo.dec.com!e2big.mko.dec.com!nntpd.lkg.dec.com!evetpu.enet.dec.com!mccarthy
  2. From: mccarthy@evetpu.enet.dec.com (Brian J. McCarthy)
  3. Newsgroups: vmsnet.tpu
  4. Subject: Re: How to EDIT files via a COMMAND FIle
  5. Message-ID: <1992Nov23.113949.17381@nntpd.lkg.dec.com>
  6. Date: 23 Nov 92 11:35:39 GMT
  7. References: <01GRDAR6Q8RM001XBD@utrcgw.utc.com> <1ejv1aINNeqa@gap.caltech.edu>
  8. Sender: usenet@nntpd.lkg.dec.com (USENET News System)
  9. Organization: Digital Equipment Corporation
  10. Lines: 106
  11.  
  12.  
  13. In article <1ejv1aINNeqa@gap.caltech.edu>, carl@SOL1.GPS.CALTECH.EDU (Carl J Lydick) writes...
  14. >In article <01GRDAR6Q8RM001XBD@utrcgw.utc.com>, "frank (Chip) Dyer x9568 ..Electrical Design" writes:
  15. >> EVE/TPU experts:
  16. >>
  17. >> I have about 50 files with the number "100C000" (hexadecimal) in them.  I
  18. >> need to edit all these files and replace "100C000" with "1010000."  Is it
  19. >> possible to do this through a non-interactive (automatic) process?
  20. >>
  21. >> Ideally I want to have a COMMAND procedure do a GLOBLAL REPLACE on
  22. >> "100C000" - something like
  23. >>
  24. >>    $ EDIT/TPU/NOINIT/NODISplay/COMmand=SYS$INPUT in.src/OUTput=OUT.SRC
  25. >>    EVE_REPLACE("100A","*!!*!!**")
  26. >>    $ EXIT
  27. >>
  28. >> Is this possible?  I have never written or used any TPU procedures, so
  29. >> any help you can provide will greatly be appreciated.  I use EVE quite a
  30. >> bit, but as far as writing or using TPU procedures, I have never done
  31. >> that.
  32. >$    EDIT/TPU/NODISPLAY/NOSECTION/COMMAND=SYS$INPUT: in.src/OUTPUT=out.src
  33. >POSITION(CREATE_BUFFER('',GET_INFO(COMMAND_LINE,'FILE_NAME')));
  34. >LOOP    R := SEARCH("100C000", FORWARD);
  35. >    EXITIF R=0;
  36. >    POSITION(R);
  37. >    ERASE(R);
  38. >    COPY_TEXT("1010000");
  39. >ENDLOOP;
  40. >WRITE_FILE(CURRENT_BUFFER, GET_INFO(COMMAND_LINE,'OUTPUT_FILE'));
  41. >EXIT;
  42. >--------------------------------------------------------------------------------
  43. >Carl J Lydick | INTERnet: CARL@SOL1.GPS.CALTECH.EDU | NSI/HEPnet: SOL1::CARL
  44.  
  45. This works great when you know exactly what you want to replace and want to
  46. hard code it into the command procedure.  I sent something out to info-tpu
  47. mailing list and I will post it here.  It creates a temporary TPU command file
  48. that senses wildcard searches.
  49.  
  50. I just did some quick hand edits to the file without checking to see if it 
  51. still works (but it should...)
  52.  
  53. Here it is:
  54.  
  55. $! replace_wild.com
  56. $!
  57. $! generic replacement com file.  Changes every occurance of P3 to P4
  58. $! found in file P1 and writes it out to P2
  59. $!
  60. $! If p3 (the search string) contains a wildcard character ("*"), then
  61. $! P5 contains what characters are to be matched for that wildcard character
  62. $! For example:
  63. $!
  64. $! @replace_wild <input-file> <output-file> "export : '*';" - 
  65. $! $_           "export : 'V01-123';" "vx1234567890-"
  66. $!
  67. $! would cause the following strings 
  68. $! export : '';
  69. $! export : 'Vx001-x55';
  70. $! export : 'V1.0';
  71. $! to be replaced with 
  72. $! "export : 'V01-123';"
  73. $!
  74. $ tmp_file = "sys$scratch:replace_wild.tmp"
  75. $ open/write replace_cmd 'tmp_file
  76. $ write replace_cmd "procedure global_replace (find_pat, repl_str, wild_chars);"
  77. $ write replace_cmd "local found_wildcard,begin_str,end_str,search_pattern,r1;"
  78. $ write replace_cmd "found_wildcard := index (find_pat, ""*"");"
  79. $ write replace_cmd "if found_wildcard = 0"
  80. $ write replace_cmd "then"
  81. $ write replace_cmd "    search_pattern := find_pat;"
  82. $ write replace_cmd "else"
  83. $ write replace_cmd "    begin_str := SUBSTR (find_pat, 1, found_wildcard-1);
  84. $ write replace_cmd "    end_str := SUBSTR (find_pat, found_wildcard+1);
  85. $ !
  86. $ ! Create a pattern that starts with everything up to the wildcard and then
  87. $ ! spans all the characters passed in to the command procedure in p5, then 
  88. $ ! ends with what ever follows the wildcard character
  89. $ !
  90. $ write replace_cmd "    search_pattern := begin_str + (SPAN (wild_chars) | """")  + end_str;"
  91. $ write replace_cmd "endif;"
  92. $ write replace_cmd "position (beginning_of (current_buffer));"
  93. $ write replace_cmd "loop"
  94. $ write replace_cmd "    r1 := search_quietly (search_pattern, forward, no_exact);"
  95. $ write replace_cmd "    if r1 = 0 then return; endif;"
  96. $ write replace_cmd "    position (r1);"
  97. $ write replace_cmd "    erase (r1);"
  98. $ write replace_cmd "    copy_text (repl_str);"
  99. $ write replace_cmd "endloop;"
  100. $ write replace_cmd "endprocedure;"
  101. $ write replace_cmd "!"
  102. $ write replace_cmd "b1 := create_buffer (""b1"", get_info(command_line,""file_name""));"
  103. $ write replace_cmd "position (b1);"
  104. $ write replace_cmd "global_replace (""''P3'"", ""''P4'"", ""''p5'"");"
  105. $ write replace_cmd "write_file (b1, get_info(command_line, ""output_file""));"
  106. $ write replace_cmd "quit (off, 1);             "
  107. $ close replace_cmd
  108. $ EDIT/TPU/NODISP/NOSECT/NOINIT/COMMAND='tmp_file' -
  109.     /output='P2 'P1
  110. $ !
  111. $ delete 'tmp_file';
  112. ********************************************************************************
  113. Brian J. McCarthy            DECTPU/EVE Engineering Project Leader
  114. Digital Equipment Corporation        Nashua, NH
  115. ********************************************************************************
  116.