From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 18-JUL-1989 03:36
To:	MRGATE::"ARISIA::EVERHART"
Subj:	new global edit procedure.

Received: From KL.SRI.COM ([0.0.0.0]) by CRVAX.SRI.COM with TCP; Mon, 17 JUL 89 23:35:49 PDT
Received: from nac.no by KL.SRI.COM with TCP; Mon, 17 Jul 89 23:18:25 PDT
Received: from runix.runit.sintef.no by nac.no (5.54/1.15) 
	id AA02916; Tue, 18 Jul 89 08:14:01 +0200
Received: by runix.runit.sintef.no (norunix.EARN) (1.2/6.1)
	id AA19001;  Tue, 18 Jul 89 08:15:02 +0200
Date: 18 Jul 89  8:16 +0100
From: Joern Yngve Dahl-Stamnes <dahls%vax.elab.unit.uninett@nac.no>
To: info-vax@kl.sri.com
Message-Id: <448*dahls@vax.elab.unit.uninett>
Subject: new global edit procedure.

Hello again.

Sorry about this, but my last version of GLOBAL_EDIT.COM got one bug.
This bug is fixed in this version - just forget the old one.

  +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+
  | The University of Trondheim           | Joern Yngve Dahl-Stamnes  |
  | The Norwegian Institute of Technology | System Manager            |
  | Division of Physical Electronics      | UN*IX  -  My the Balrog   |
  | N 7034 Trondheim, Norway              | find it tasty.            |
  |---------------------------------------+---------------------------|
  |            dahls%vax.elab.unit.uninett@norunix.bitnet             |
  |    dahls%vax.elab.unit.uninett%norunix.bitnet@cunyvm.cuny.edu     |
  |                    PSI%02422530001005::DAHLS                      |
  |                                                                   |
  |      The above message has been tested and found OK by META       |
  |                 (Murphy's English Text Analyzer)                  |
  +-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-=-+

$! ................... Cut between dotted lines and save. ...................
$!...........................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.10 7-FEB-1989.
$!
$! VMS_SHARE was written by James Gray (Gray:OSBUSouth@Xerox.COM) from
$! VMS_SHAR by Michael Bednarek (U3369429@ucsvc.dn.mu.oz.au).
$!
$! To unpack, simply save, concatinate all parts into one file and
$! execute (@) that file.
$!
$! This archive was created by user DAHLS
$! on 18-JUL-1989 08:11:09.24.
$!
$! It contains the following 1 file:
$!        GLOBAL_EDIT.COM
$!
$!============================================================================
$ SET SYMBOL/SCOPE=( NOLOCAL, NOGLOBAL )
$ VERSION = F$GETSYI( "VERSION" )
$ IF VERSION .GES "V4.4" THEN GOTO VERSION_OK
$ WRITE SYS$OUTPUT "You are running VMS ''VERSION'; ", -
    "VMS_SHARE V06.10 7-FEB-1989 requires VMS V4.4 or higher."
$ EXIT 44 ! SS$_ABORT
$VERSION_OK:
$ GOTO START
$!
$UNPACK_FILE:
$ WRITE SYS$OUTPUT "Creating ''FILE_IS'"
$ DEFINE/USER_MODE SYS$OUTPUT NL:
$ EDIT/TPU/COMMAND=SYS$INPUT/NODISPLAY/OUTPUT='FILE_IS'/NOSECTION -
    VMS_SHARE_DUMMY.DUMMY
b_part := CREATE_BUFFER( "{Part}", GET_INFO( COMMAND_LINE, "file_name" ) )
; s_file_spec := GET_INFO( COMMAND_LINE, "output_file" ); SET( OUTPUT_FILE
, b_part, s_file_spec ); b_errors := CREATE_BUFFER( "{Errors}" ); i_errors 
:= 0; pat_beg_1 := ANCHOR & "-+-+-+ Beginning"; pat_beg_2 := LINE_BEGIN 
& "+-+-+-+ Beginning"; pat_end := ANCHOR & "+-+-+-+-+ End"; POSITION
( BEGINNING_OF( b_part ) ); LOOP EXITIF SEARCH( SPAN( ' ' )@r_trail 
& LINE_END, FORWARD) = 0; POSITION( r_trail ); ERASE( r_trail ); ENDLOOP
; POSITION( BEGINNING_OF( b_part ) ); i_append_line := 0; LOOP EXITIF MARK
( NONE ) = END_OF( b_part ); s_x := ERASE_CHARACTER( 1 )
; IF s_x = '+' THEN r_skip := SEARCH( pat_beg_1, FORWARD, EXACT ); IF r_skip 
<> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ERASE_LINE; ENDIF
; ENDIF; IF s_x = '-' THEN r_skip := SEARCH( pat_end, FORWARD, EXACT )
; IF r_skip <> 0 THEN s_x := ''; MOVE_HORIZONTAL( -CURRENT_OFFSET ); m_skip 
:= MARK( NONE ); r_skip := SEARCH( pat_beg_2, FORWARD, EXACT ); IF r_skip 
<> 0 THEN POSITION( END_OF( r_skip ) ); MOVE_HORIZONTAL( -CURRENT_OFFSET )
; MOVE_VERTICAL( 1 ); MOVE_HORIZONTAL( -1 ); ELSE POSITION( END_OF( b_part 
) ); ENDIF; ERASE( CREATE_RANGE( m_skip, MARK( NONE ), NONE ) ); ENDIF; ENDIF
; IF s_x = 'V' THEN s_x := ''; IF i_append_line <> 0 THEN APPEND_LINE
; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF; i_append_line := 1
; MOVE_VERTICAL( 1 ); ENDIF; IF s_x = 'X' THEN s_x := ''; IF i_append_line 
<> 0 THEN APPEND_LINE; MOVE_HORIZONTAL( -CURRENT_OFFSET ); ENDIF
; i_append_line := 0; MOVE_VERTICAL( 1 ); ENDIF; IF s_x <> '' THEN i_errors 
:= i_errors + 1; s_text := CURRENT_LINE; POSITION( b_errors ); COPY_TEXT
( "The following line could not be unpacked properly:" ); SPLIT_LINE
; COPY_TEXT( s_x ); COPY_TEXT( s_text ); POSITION( b_part ); MOVE_VERTICAL
( 1 ); ENDIF; ENDLOOP; POSITION( BEGINNING_OF( b_part ) ); LOOP r_x := SEARCH
( "`", FORWARD, EXACT ); EXITIF r_x = 0; POSITION( r_x ); ERASE_CHARACTER
( 1 ); COPY_TEXT( ASCII( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDLOOP
; IF i_errors = 0 THEN SET( NO_WRITE, b_errors, ON ); ELSE POSITION
( BEGINNING_OF( b_errors ) ); COPY_TEXT( FAO
( "The following !UL errors were detected while unpacking !AS", i_errors
, s_file_spec ) ); SPLIT_LINE; SET( OUTPUT_FILE, b_errors, "SYS$COMMAND" )
; ENDIF; EXIT; 
$ DELETE VMS_SHARE_DUMMY.DUMMY;*
$ CHECKSUM 'FILE_IS
$ WRITE SYS$OUTPUT " CHECKSUM ", -
  F$ELEMENT( CHECKSUM_IS .EQ. CHECKSUM$CHECKSUM, ",", "failed!!,passed." )
$ RETURN
$!
$START: 
$ FILE_IS = "GLOBAL_EDIT.COM"
$ CHECKSUM_IS = 660888716
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$ SAVE_VER = f$verify (0)
X$!
X$! GLOBAL_EDIT.COM
X$!
X$! Command procedure to substitute one ore more strings in one or more files.
X$! The procedure will generate a TPU file and later invoke the TPU editor
X$! to do the substitution(s).
X$!
X$! Written by Joern Yngve Dahl-Stamnes.
X$!
X$ TPU_CMD_FILE = "sys$scratch:global_edit_tmp.tpu"
X$ COM_CMD_FILE = "sys$scratch:global_edit_tmp.com"
X$ SAY := write sys$output
X$ PUT := write out
X$ DBG := 'SYS_DEBUG
X$ if DBG then set verify
X$!
X$! Create the TPU command file. First write the standard routine which
X$! replace one string with another (case sensitive).
X$!
X$ open/write out 'TPU_CMD_FILE
X$ put f$fao ("!!!70*-")
X$ put "procedure global_replace (old_str,new_str)"
X$ put ""
X$ put "local`009msg_txt,"
X$ put "`009old_str_range,"
X$ put "`009rcount;"
X$ put ""
X$ put "on_error"
X$ put "    msg_txt := fao ('!UL replacement!%S of !AS with !AS',"
X$ put "`009rcount, old_str, new_str);"
X$ put "    message (msg_txt);"
X$ put "    if rcount <> 0 then"
X$ put "        gbl_update := 1;"
X$ put "    endif;"
X$ put "    return;"
X$ put "endon_error;"
X$ put ""
X$ put "rcount := 0;"
X$ put "position ( beginning_of (current_buffer));"
X$ put "loop"
X$ put "    old_str_range := search (old_str, forward, exact);"
X$ put "    exitif old_str_range = 0;"
X$ put "    erase (old_str_range);"
X$ put "    position ( end_of (old_str_range));"
X$ put "    copy_text (new_str);"
X$ put "    rcount := rcount + 1;"
X$ put "endloop;"
X$ put ""
X$ put "endprocedure;"
X$ put ""
X$!
X$! Write the TPU routine that will process each file.
X$!
X$ put f$fao ("!!!70*-")
X$ put "procedure process_file (file_spec)"
X$ put ""
X$ put "message ( fao('!/!5** Processing file !AS', file_spec));"
X$ put "read_file (file_spec);"
X$ put "gbl_update := 0;"
X$ put ""
X$!
X$! Ask for old and new string(s), case sensitive.
X$!
X$SLOOP:
X$ say ""
V$ say "Enter Old and New string (case sensitive), terminate with a null strin
Xg."
X$ read/error=END_SLOOP/prompt="Old string :" sys$command OLD_STR
X$ if OLD_STR .eqs. "" then goto END_SLOOP
X$ read/error=END_SLOOP/prompt="New string :" sys$command NEW_STR
X$ put f$fao ("global_replace ('!AS','!AS');",OLD_STR,NEW_STR)
X$ goto SLOOP
X$
X$END_SLOOP:
X$ put ""
X$ put "if gbl_update = 1 then"
X$ put "    write_file (gbl_buffer,file_spec);"
X$ put "endif;"
X$ put "erase (gbl_buffer);"
X$ put "endprocedure;"
X$ put ""
X$!
X$! Write some more TPU stuff.
X$!
X$ put f$fao ("!!!70*-")
X$ put "gbl_update := 0;"
X$ put "gbl_buffer := create_buffer ('GLOBAL_BUFFER');"
X$ put "position ( beginning_of (gbl_buffer));"
X$ put ""
X$!
X$! Ask for file-name(s)...
X$!
X$ASK_FILE_LOOP:
X$ say ""
X$ say "Enter file(s) to be edited, terminate with a null string."
X$ read/error=END_FILE_LOOP/prompt="File spec. :" sys$command FILE_SPEC
X$ if FILE_SPEC .eqs. "" then goto END_FILE_LOOP
X$ say "Searching for file(s), please wait..."
X$ CNT = 0
X$
X$FLOOP:
X$ FILE = f$search (FILE_SPEC)
X$ if FILE .eqs. "" then goto END_FLOOP
X$ FILE = f$extract (0,f$locate(";",FILE),FILE)
X$ put f$fao ("process_file ('!AS');",FILE)
X$ CNT = CNT + 1
X$ goto FLOOP
X$
X$END_FLOOP:
X$ say f$fao ("!UL file!%S found",CNT)
X$ goto ASK_FILE_LOOP
X$
XEND_FILE_LOOP:
X$ put ""
X$ put "set (no_write,gbl_buffer);"
X$ put "exit;"
X$ close out
X$!
X$! Batch or Interactive execution?
X$!
X$ASK_MODE:
V$ read/prompt="Interactive or Batch execution (I or B) [B] :" sys$command SVA
XR
X$ SVAR = f$extract (0,1,f$edit(SVAR,"collapse,upcase"))
X$ if f$locate (SVAR,"IB") .eq. 2 then goto ASK_MODE
X$ if SVAR .eqs. "I" then goto MODE_I
X$!
X$! Create a DCL file to execute TPU in batch mode.
X$!
X$ open/write out 'COM_CMD_FILE
X$ put "$ set noverify"
X$ put "$ set default ",f$environment ("default")
X$ put -
X  f$fao ("$ edit/tpu/nodisplay/nosection/nojournal/command=!AS",TPU_CMD_FILE)
X$ put f$fao ("$ delete !AS;*",TPU_CMD_FILE)
X$ put f$fao ("$ delete !AS;*",COM_CMD_FILE)
X$ put "$ exit"
X$ close out
X$!
X$! Ask for batch queue name.
X$!
X$ASK_QUEUE:
X$ read/prompt="Enter queue name :" sys$command QUEUE
X$ if QUEUE .eqs. "" then goto ASK_QUEUE
X$
X$ submit/name="Global Edit"/queue='QUEUE/notify/log=[]global_edit.log -
X  'GOM_CMD_FILE
X$ goto QUIT
X$
X$MODE_I:
X$ edit/tpu/nodisplay/nosection/nojournal/command='TPU_CMD_FILE
X$ delete 'TPU_CMD_FILE;*
X$!
X$! That's it.
X$!
X$QUIT:
X$ SAVE_VER = f$verify (SAVE_VER)
X$ exit
$ GOSUB UNPACK_FILE
$ EXIT

