From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP  3-SEP-1988 04:24
To:	ARISIA::EVERHART
Subj:	ATREAD.1_of_4


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Fri,  2 SEP 88 19:40:21 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Fri, 2 Sep 88 19:17:54 PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA16071; Fri, 2 Sep 88 16:28:29 PDT
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: 29 Aug 88 03:22:47 GMT
From: naucse!jdc@arizona.edu  (John Campbell)
Organization: Northern Arizona University, Flagstaff, AZ
Subject: ATREAD.1_of_4
Message-Id: <848@naucse.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com


The following is the first of a four part VMS shar file that allows users
to dump any tape to the disk and should allow you to read any ASCII or EBCIDIC
tape (directly or from the disk image).  The help files are in this first
shar package--if you need to browse to see if you want it.

Warning:  You must have 'C' and (no kidding) Bison [or access to YACC] in
order to build this program.

Request:  Those with need and expertise, please add a feature and send it
back--I'd love to see this thing grow to encompass more than just ANSI tape
formats (that's why it is written as a grammar).

Thanks,

John Campbell   ...!arizona!naucse!jdc

$!.............................................................................
$! VAX/VMS archive file created by VMS_SHARE V06.00 26-May-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 CAMPBELL
$! on  6-APR-1866 20:07:23.77.
$!
$! ATTENTION: To keep each article below 31 blocks (15872 bytes), this
$!            program has been transmitted in 4 parts.  You should
$!            concatenate ALL parts to ONE file and execute (@) that file.
$!
$! It contains the following 6 files:
$!        ATREAD.RNH
$!        TDUMP.RNH
$!        BUILD.COM
$!        ATREAD.CLD
$!        ATREAD.Y
$!        TDUMP.C
$!
$!==============================================================================
$ 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.00 26-May-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"; 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 = "ATREAD.RNH"
$ CHECKSUM_IS = 1718947859
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X.flags accept ``
X.P0
X.ap
X.LM1.RM70
X.I-1
X.IF NAU
X2 ATREAD
X.ELSE NAU
X.hl 1 ATREAD
X.ENDIF NAU
X
XATREAD is an ANSI tape reading program.  The VAX directly supports
XANSI 'F' and 'D' ascii tapes.  There are times, however, when an ANSI
Xtape may be in EBCDIC, in 'V' format, or contains
Xnames that are invalid on VMS.  ATREAD was designed to read these types
Xof tapes.  Note that users of the VAX are expected to use COPY/NOHDR3
Xto write transportable ANSI tapes, so this utility does not attempt to
Xwrite ANSI tapes.
X
XATREAD reads from USER$TAPE, which may be either a tape drive or a file
Xcreated with the TDUMP utility (which dumps a tape image to disk).  If
Xyou have the disk space, you might want to use TDUMP first since it is
Xoften necessary to make multiple passes over a tape prior to extracting
Xthe desired information, since working with a TDUMP file is much faster.
X(If your tape is part of a multi-volume set then TDUMP is not an option.)
X
XIn addition to a number of qualifiers, ATREAD also allows you to select file
Xnames using an optional wild-card parameter.  ATREAD with no parameters
Xor qualifiers will unload the whole tape into the current directory.
X
X.I-1
X.IF NAU
X3 /DIRECTORY
X.ELSE NAU
X.hl 2 /DIRECTORY
X.ENDIF NAU
X
XATREAD/DIRECTORY will not create any files.  This command may be used to show
Xyou what files are stored on the tape (similar to a DIRECTORY USER$TAPE:
Xcommand for VMS supported ANSI tapes).
X
X.I-1
X.IF NAU
X3 /VERBOSE
X.ELSE NAU
X.hl 2 /VERBOSE
X.ENDIF NAU
X
XThe ATREAD/VERBOSE command will tell you of each block that is read off the
Xtape.  Since ANSI tapes are defined as containing VOL, HDR, EOF, EOV, and
XDATA tape blocks, this command will announce each as they are read in.
XThis qualifier is normally useless but may help shed some light on the
Xformat of a given tape.  Note that ATREAD itself expects a minimally
Xwell-formed ANSI tape.  If you are having trouble getting ATREAD to accept
Xa tape it is probably because it is not ANSI conforming.  You may wish to
Xuse TDUMP to analyze the tape further.
X
X
X.I-1
X.IF NAU
X3 /INTERACTIVE
X.ELSE NAU
X.hl 2 /INTERACTIVE
X.ENDIF NAU
X
XATREAD/INTERACTIVE will allow you to look at data off the tape and decide if
Xyou want to save the current data to a file.  The first 15 lines of data are
Xdisplayed and a prompt comes up asking if you want to "Skip" this file,
X"Write" this file to disk, or see "More" of the file.  This is useful when
Xyou don't have room for the whole tape on the disk and you wish to see what
Xeach file contains.  Note that in all modes, ATREAD displays the names of the
Xfiles; the /INTERACTIVE qualifier is needed only if the names are not enough.
X
X
X.I-1
X.IF NAU
X3 /EXCLUDE
X.ELSE NAU
X.hl 2 /EXCLUDE
X.ENDIF NAU
X
XATREAD/EXCLUDE=(*.FOR) will read and save only those files with names that do
Xnot end in ".FOR".  This is similar to the COPY/EXCLUDE command in VMS.  Often
Xit is easier to use an EXCLUSION list to designate desired files rather than
Xtrying to create a list of all the desired names in a parameter list.  Note
Xthat ATREAD/EXCLUDE=(*.FOR,*.DAT)#C* is a valid use of the exclude qualifier.
X
X.I-1
X.IF NAU
X3 /[NO]MOUNT
X.ELSE NAU
X.hl 2 /[NO]MOUNT
X.ENDIF NAU
X
XNormally ATREAD works by dismounting the tape you mounted on device USER$TAPE
Xand then mounting it foreign with a block size of 65534.  This has the effect
Xof rewinding the tape (as well as insuring the block size is as large as
Xpossible).  If you wish to position the tape head yourself (at the start of
Xa legal ANSI tape VOL1 tape record) then you may wish to use ATREAD/NOMOUNT.
XBe sure the tape was mounted foreign with a block size of 65534 before issuing
Xthis command.
X
X.I-1
X.IF NAU
X3 /DEBUG
X.ELSE NAU
X.hl 2 /DEBUG
X.ENDIF NAU
X
XThe qualifer /DEBUG is for use by maintainers of the ATREAD program.  The only
Xreason for mentioning it is so you won't try ATREAD/D--thinking that DIRECTORY
Xcan be abbreviated to /D.  Specifying the /DEBUG qualifer still allows ATREAD
Xto function, but the messages printed as the BISON grammar traverses its parse
Xtree will be extremely annoying and most likely meaningless.
X
X.I-1
X.IF NAU
X3 Wild-Card
X.ELSE NAU
X.hl 2 Wild-Card
X.ENDIF NAU
X
XATREAD supports wild-cards of the form ATREAD *.C,*.FOR,*.BAS.  This allows
Xyou to select only certain files from the tape without having to unload
Xeverything on the tape.  The qualifier /EXCLUDE may also be of help when
Xtrying to extract a subset of the data stored on the tape.
X
X.I-1
X.IF NAU
X3 Examples
X.ELSE NAU
X.hl 2 Examples
X.ENDIF NAU
X
XThe following ATREAD commands work either with USER$TAPE defined as a tape
Xdevice or as a disk file created with the TDUMP utility.  All files are created
Xin the current directory.
X
X(Read the whole tape and create separate disk files.)
X.br
XATREAD
X.br
X(Read only files ending in .FOR)
X.br
XATREAD *.FOR
X.br
X(Read the tape "interactively" deciding case by case to save files.)
X.br
XATREAD/INTERACTIVE *.FOR
X.br
X(Show a directory of the tape.)
X.br
XATREAD/DIRECTORY
$ GOSUB UNPACK_FILE
$ FILE_IS = "TDUMP.RNH"
$ CHECKSUM_IS = 941713606
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X.flags accept ``
X.P0
X.ap
X.LM1.RM70
X.I-1
X.IF NAU
X2 TDUMP
X.ELSE NAU
X.hl 1 TDUMP
X.ENDIF NAU
X
XTDUMP takes a tape mounted on device USER$TAPE (a logical name) and
Xcreates a disk file out of the tape.  The disk file is a fairly faithful
Ximage of what was stored on the tape.  Each tape PRU (block) is copied
Xas a single disk record.  As the tape is being copied a tape record count
Xand block size count is displayed.  TDUMP supports tape blocks up to 65534
Xbytes long.
X
XEach tape mark is converted into a single record consisting of an ascii
X26 (^Z).  The end result should be a 1-1 image of the tape in single disk
Xfile.  The name of the file will be TAPE.DUMP, unless a parameter is given
Xto TDUMP (e.g. TDUMP MYDUMP.TAPE).
X
XThe program ATREAD directly supports files created with TDUMP.  Also,
Xforeign tape conversions projects may be easier to work on if the file is
Xconverted first to the disk.   Finally, fixed length files may be simply
Xextracted using an editor macro once they have been placed on the disk with
XTDUMP.
X
X
X.I-1
X.IF NAU
X3 Examples
X.ELSE NAU
X.hl 2 Examples
X.ENDIF NAU
X
XThere are only two ways to use TDUMP:
X.br
XTDUMP
X.br
Xor
X.br
XTDUMP file.name
X.br
XThe first will create a disk file named TAPE.DUMP, the latter a disk file
Xnamed "FILE.NAME".  Once the disk file has been created it may be thought of
Xas a logical substitution for a tape image.  In fact, the command
XDEFINE#USER$TAPE#TAPE.DUMP will allow the program ATREAD to work directly
Xwith the disk file instead of a tape drive.
$ GOSUB UNPACK_FILE
$ FILE_IS = "BUILD.COM"
$ CHECKSUM_IS = 2105290238
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X$ ! VMS command file to build atread and tdump
X$ bison atread.y
X$ cc atread_tab /list
X$ link/exe=atread  atread_tab, sys$library:vaxcrtl/lib
X$ cc tdump.c /list
X$ link/exe=tdump tdump, sys$library:vaxcrtl/lib
X$ !
X$ ! Prepare ATREAD and TDUMP commands for testing.  (TDUMP is "foreign").
X$ !
X$ tdump == "$" + f$logical("SYS$DISK") + f$directory() + "TDUMP.EXE"
X$ set command atread
$ GOSUB UNPACK_FILE
$ FILE_IS = "ATREAD.CLD"
$ CHECKSUM_IS = 1614556929
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X! CLD file for ATREAD
X!
X! Verb
X!
Xdefine verb ATREAD
Ximage dua1:[campbell.source.tapesniff]atread
X!
X! Verb qualifiers
X!
Xqualifier directory
Xqualifier debug
Xqualifier verbose
Xqualifier interactive
Xqualifier exclude
X   value(list,type=$file)
Xqualifier mount
X   negatable
X
Xparameter p1
X   value(list,type=$file)
$ GOSUB UNPACK_FILE
$ FILE_IS = "ATREAD.Y"
$ CHECKSUM_IS = 523823669
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
X%{
X/* C code */
X/*-
X   atread.c                     Last Modified             24-May-88/JDC
X
X   This utility reads ansi tapes on VMS systems.  It can handle ASCII or
X   EBCDIC tapes of 'F', 'D', or 'V' types.  In addition, a minimal amount
X   of support for VMS HDR3 and HDR4 records exist--but users would normally
X   use VMS utilities to read tapes written with VMS.  Support is also
X   present for name translations, wild-card selection and exclusion.
X
X   Modification History:
X
X   24-May-88/JDC - Initial version finished.
X
X-*/
X#include <descrip>
X#include <stdio.h>
X#include <ssdef>
X#include <iodef>
X#include <file>
X#include <ctype.h>
X#include <climsgdef.h>
X#include <dvidef>
X#include <dcdef>
X#include <rmsdef>
X
X#define MNT$M_FOREIGN  1
X#define MNT$M_NOWRITE  1<<6
X#define MNT$_DEVNAM    1
X#define MNT$_BLOCKSIZE 8
X#define MNT$_COMMENT   0x14
X#define MNT$_RECORDSIZ 16
X#define MNT$_FLAGS     4
X
X#define DMT$M_NOUNLOAD 1
X
Xtypedef struct
X          {
X          short cond_value;
X          short count;
X          int info;
X          }  status_block;
X
Xtypedef struct
X          {
X          short buffer_len;
X          short item_code;
X          int buffer_addr;
X          int ret_len_addr;
X          }  item_desc;
X
X/* Changed to read from USER$TAPE (instead of a hard-coded tape drive). */
X/*
X   Eventually add an option to allow the user to choose what translation
X   table they want to use.  I found that the DEC tables didn't translate
X   things like '[' and ']' properly so I opted to use the CMS KERMIT
X   table--which follows.
X*/
Xglobalref LIB$AB_EBC_ASC_REV;  /* RTL translation table. */
X/*
XThis table is the same as the CMS KERMIT table--except for FF.
XDigital's LIB$AB_EBC_ASC table doesn't map things as expected (and
Xthe choice of '\' as the non-mapping character stinks.
X
XDifferences between LIB$AB_EBC_ASC and KERMIT's table:
X
X       ASCII   Character   EBCDIC
X       5C          \       4A,E0
X       7C          |       4F,FA
X       21          !       5A
X       7B          {       8B
X       7D          }       9B
X       5B          [       AD
X       5D          ]       BD
X*/
Xstatic unsigned char EBC_ASC_TABLE[] = {
X0x00, 0x01, 0x02, 0x03, 0x00, 0x09, 0x00, 0x7F,
X      0x00, 0x00, 0x00, 0x0B, 0x0C, 0x0D, 0x0E, 0x0F,
X0x10, 0x11, 0x12, 0x13, 0x00, 0x00, 0x08, 0x00,
X      0x18, 0x19, 0x00, 0x00, 0x1C, 0x1D, 0x1E, 0x1F,
X0x00, 0x00, 0x00, 0x00, 0x00, 0x0A, 0x17, 0x1B,
X      0x00, 0x00, 0x00, 0x00, 0x00, 0x05, 0x06, 0x07,
X0x00, 0x00, 0x16, 0x00, 0x00, 0x00, 0x00, 0x04,
X      0x00, 0x00, 0x00, 0x00, 0x14, 0x15, 0x00, 0x1A,
X0x20, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X      0x00, 0x00, 0x5C, 0x2E, 0x3C, 0x28, 0x2B, 0x7C,
X0x26, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X      0x00, 0x00, 0x21, 0x24, 0x2A, 0x29, 0x3B, 0x5E,
X0x2D, 0x2F, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X      0x00, 0x00, 0x7C, 0x2C, 0x25, 0x5F, 0x3E, 0x3F,
X0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00, 0x00,
X      0x00, 0x60, 0x3A, 0x23, 0x40, 0x27, 0x3D, 0x22,
X0x00, 0x61, 0x62, 0x63, 0x64, 0x65, 0x66, 0x67,
X      0x68, 0x69, 0x00, 0x7B, 0x00, 0x00, 0x00, 0x00,
X0x00, 0x6A, 0x6B, 0x6C, 0x6D, 0x6E, 0x6F, 0x70,
X      0x71, 0x72, 0x00, 0x7D, 0x00, 0x00, 0x00, 0x00,
X0x00, 0x7E, 0x73, 0x74, 0x75, 0x76, 0x77, 0x78,
-+-+-+-+-+ End of part 1 +-+-+-+-+-
-- 
	John Campbell               ...!arizona!naucse!jdc

	unix?  Sure send me a dozen, all different colors.

