From:	CSBVAX::CSBVAX::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX" 27-FEB-1989 14:24
To:	MRGATE::"ARISIA::EVERHART"
Subj:	experimental UNSHAR for VMS


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri, 24 FEB 89 18:32:05 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri, 24 Feb 89 18:27:24 PST
Received: by ucbvax.Berkeley.EDU (5.61/1.34)
	id AA28284; Fri, 24 Feb 89 17:36:38 -0800
Received: from USENET by ucbvax.Berkeley.EDU with netnews
	for info-vax@kl.sri.com (info-vax@kl.sri.com)
	(contact usenet@ucbvax.Berkeley.EDU if you have questions)
Date: 12 Feb 89 20:55:48 GMT
From: unmvax!nmtsun!warner%hydrovax.nmt.edu@ucbvax.Berkeley.EDU  (M. Warner Losh)
Organization: New Mexico Tech Hydrology Program
Subject: experimental UNSHAR for VMS
Message-Id: <1868@nmtsun.nmt.edu>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

Here is my experimental UNSHAR for VMS.  It is designed to work on VMS
SHAR files created with either VMS_SHARE or VMS_SHAR or any COM file that
starts with a line that begins with $!.

The program works by stripping off the headers (up to the line that has $! on
it), then copying the rest of the file to some temp file (based on you PID),
and then executing that file.  It seems to work relatively well for SHARE and
SHAR files that have been posted to the net in the past few months.  Home
brewed shar files work less well, expecially those that start with $ CREATE
xxx.xxx. 

It is still experimental in nature, so any comments on its construction or
methodology are encouraged.  I've been using it for the past few weeks with no
ill effects (that I've been able to detect anyway).

$!..................... Cut between dotted lines and save. ...................
$!............................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.03 20-Oct-1988.
$!
$! 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 WARNER
$! on 12-FEB-1989 14:05:21.60.
$!
$! It contains the following 1 file:
$!        UNSHAR.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.03 20-Oct-1988 requires VMS V4.4 or higher."
$ EXIT 44 
$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";
pat_trail := " " & LINE_END;POSITION( BEGINNING_OF( b_part ) ); LOOP b 
:= SEARCH( pat_trail, FORWARD); EXITIF b=0; POSITION( END_OF( b ) )
; LOOP MOVE_HORIZONTAL( -1 ); EXITIF CURRENT_CHARACTER <> ' '; ERASE_CHARACTER
( 1 ); EXITIF CURRENT_OFFSET=0; ENDLOOP; 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 ); 
  IF CURRENT_CHARACTER = "`" THEN MOVE_HORIZONTAL( 1 ); ELSE COPY_TEXT( ASCII
( INT( ERASE_CHARACTER( 3 ) ) ) ); ENDIF; 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 = "UNSHAR.COM"
$ CHECKSUM_IS = 370425769
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$! UNSHAR.COM(X-1) MWL, see end of file for more details
X$`009Verify = 'F$Verify (0)
X!$`009ON`009ERROR -
X!`009THEN`009GOTO CleanUp
X$`009In_Name`009= F$SEARCH (P1)
X$`009IF`009In_Name .NES. "" -
X`009THEN`009GOTO Have_Input_File
X$ Get_In_Name_Loop:
X$`009READ`009SYS$COMMAND In_Name/PROMPT="_File to unshar$ "
X$`009IF`009F$SEARCH(In_Name) .EQS. "" -
X`009THEN`009GOTO Get_In_Name_Loop
X$ Have_Input_File:
X$`009OPEN/READ`009in`009'In_Name'
X$ Top_Of_Loop:
X$`009READ/END=No_Shar_Found`009in line
X$`009IF`009F$EXTRACT (0, 2, Line) .NES. "$!" -
X`009THEN`009GOTO Top_Of_Loop
X$`009PID = F$GetJPI (0, "PID")
X$`009COPY`009In Tmp_'PID'.COM`009! Copies the rest of P1 into tmp.com
X$`009CLOSE IN
X$`009SET NOVERIFY
X$`009@TMP_'PID'.COM
X$`009DELETE TMP_'PID'.COM;*
X$`009GOTO Get_Me_Out_Of_Here
X$ CleanUp:
X$`009CLOSE/NOLOG In
X$`009IF`009F$SEARCH ("TMP_''PID'.COM") .NES. "" -
X`009THEN`009DELETE TMP_'PID'.COM;*
X$`009GOTO`009Get_Me_Out_Of_Here
X$ No_Shar_Found:
X$`009WRITE SYS$OUTPUT "I Couldn't find anything that looks like a shar file"
X$ Get_Me_Out_Of_Here:
X$`009Verify = F$VERIFY(Verify)
X$`009EXIT
X!
X!`009U N S H A R . C O M
X!
X!`009Program`009`009: Unshar
X!`009Version`009`009: X-1
X!`009Version date`009: 22-Jan-1989
X!`009Programmer`009: M. Warner Losh (warner@hydrovax.nmt.edu)
X!`009Abstract`009: Unshars
X!
X!`009`009D e s c r i p t i o n
X!
X!`009Takes a shar message, strips out all lines until it sees one beginning
X!`009with a "$", then executes the rest of the file.  For use in multi-
X!`009part postings, do the following:
X!`009`009o save all message in some order (eg xxx.01, xxx.02, etc)
X!`009`009o copy all messages into one file (eg copy xxx.%% xxx.src)
X!`009`009o run unshar on it (eg @unshar xxx.src)
X!
X! Sleezy DCL tricks:
X!      When DCL has a file open, you can refer to that stream using the
X!`009logical that you specified on the open command.  So if you read
X!`009the first five records from the file, then the logical that you
X!`009used refers to the rest of the file.  For example:
X!
X!`009`009$ open xxx junk.com
X!`009`009$ read xxx line
X!`009`009$ read xxx line
X!`009`009$ read xxx line
X!`009`009$ read xxx line
X!`009`009$ read xxx line
X!`009`009$ copy xxx tmp.com
X!`009`009$ close xxx
X!
X!`009will all but the first five records in junk.com to tmp.com.
X!
$ GOSUB UNPACK_FILE
$ EXIT

--
Warner Losh
warner@hydrovax.nmt.edu		...!unmvax!nmtsun!warner%hydrovax
What happened to our innocence, did it go out of style?
My spelling and views are my own.  Only the letters have been changed... 

