From:	CSBVAX::MRGATE!RELAY-INFO-VAX@CRVAX.SRI.COM@SMTP  5-OCT-1988 16:37
To:	ARISIA::EVERHART
Subj:	Re: Two requests - TAIL for VMS, modem configuration


Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Tue,  4 OCT 88 22:38:26 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Tue, 4 Oct 88 22:18:27 PDT
Received: by ucbvax.Berkeley.EDU (5.59/1.31)
	id AA08133; Tue, 4 Oct 88 17:51:39 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: 1 Oct 88 14:04:15 GMT
From: mcmi!hdr!unocss!fritz@uunet.uu.net  (Tim Russell)
Organization: U. of Nebraska at Omaha
Subject: Re: Two requests - TAIL for VMS, modem configuration
Message-Id: <426@unocss.UUCP>
References: <6441@ut-emx.UUCP>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

In article <6441@ut-emx.UUCP>, mike@ut-emx.UUCP (Mike) writes:
> I am looking for a VMS version of the TAIL program.  We are running a MicroVAX
> and will not be up to 5.0 for some time, so TECO based solutions will not
> work.  Any source in Macro, Fortran, C , TPU, etc will be appreciated.
> 

      Here's a TAIL program that a friend of mine wrote in Pascal a couple
of years ago.  To use, just edit the .CLD file to point to your executable
and then SET COMMAND TAIL.CLD, or just set it up as a foreign command as
described in the start of the program. If you're a manager and would like
to install it systemwide:

       $ set command/tables=sys$library:dcltables.exe -
       _$ /output=sys$library:dcltables.exe tail.cld
       $ install :== $install/command
       $ install replace sys$library:dcltables.exe

and re-login to get it.  I'll send executables to Bitnet sites with no Pascal
compiler - just mail to me at the address at the end of this post.

$!.............................................................................
$! 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 CONSLT32
$! on  1-OCT-1988 08:44:31.88.
$!
$! It contains the following 2 files:
$!        TAIL.PAS
$!        TAIL.CLD
$!
$!==============================================================================
$ 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 = "TAIL.PAS"
$ CHECKSUM_IS = 156327612
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XProgram Tail (Output, In_File);
X
X
V(******************************************************************************
X)
V(*                                                                            *
X)
V(*   Program TAIL                                                             *
X)
V(*                                                                            *
X)
V(*   Version 1.0                                                              *
X)
V(*                                                                            *
X)
V(*   By Jon Scheer  (C) 1986                                                  *
X)
V(*                                                                            *
X)
V(*   This program displays the 'tail' (last lines) of a file(s).  The         *
X)
V(*   number of lines shown can be specified by the user, or if no value is    *
X)
V(*   given, the program will show DEF_LINES lines.                            *
X)
V(*                                                                            *
X)
V(*   The usage of this program is based on the Unix command 'tail'.  The      *
X)
V(*   format of the command is:                                                *
X)
V(*                                                                            *
X)
V(*      $ TAIL [-#] filename                                                  *
X)
V(*                                                                            *
X)
V(*   Where:                                                                   *
X)
V(*      -#        is the optional number of lines to be displayed.            *
X)
V(*      filename  is the name of the file to be parsed.  Note that            *
X)
V(*                wildcards ARE accepted.                                     *
X)
V(*                                                                            *
X)
V(*   Examples:                   What is shown:                               *
X)
V(*      $ TAIL FOO.BAR              The last 15 lines of FOO.BAR.             *
X)
V(*      $ TAIL -5 FOO.BAR           The last 5 lines of FOO.BAR.              *
X)
V(*      $ TAIL *.PAS                The last 15 lines of all .PAS files.      *
X)
V(*                                                                            *
X)
V(*   NOTE:  Because this program uses LIB$GET_FORIEGN to get the filename     *
X)
V(*          off of the command line, the program can be setup as a symbol     *
X)
V(*          using the format:                                                 *
X)
V(*                                                                            *
X)
V(*             $ TAIL :== <disk & directory>:TAIL                             *
X)
V(*                                                                            *
X)
V(*          Or it can be setup as a command by using the .CLD file.           *
X)
V(*                                                                            *
X)
V(******************************************************************************
X)
X
X`012
XConst
X   Def_Lines = 15;
X
XType
X   $Word  = [Word] -32768..32767;
X   Var132 = Varying [132] of Char;
X
XVar
X   New_Name  ,
X   Old_Name  ,
X   File_Name : Var132;
X   Done      : Boolean;
X   G_Dummy   : Integer;
X   Num_Lines : Integer;
X   In_File   : Text;
X
X
X
X
V[External (Sys$Exit)] Function $Exit (%Ref Code : $Word := 1) : Integer; Extern
Xal;
X
V[External (Lib$Get_Foreign)] Function $Get_Foreign (%Descr Line : Var132) : Int
Xeger; External;
X
X[External (Lib$Find_File)] Function $Find_File (%Descr File_1, File_2 : Var132;
V                                                Var    Dummy : Integer) : Integ
Xer; External;
X
X
X
X
XFunction Find_First (File_Name : Var132) : Var132;
X
X   Var
X      Temp   : Var132;
X      Status : Integer;
X
X   Begin
X   G_Dummy := 0;
X   Status := $Find_File (File_Name, Temp, G_Dummy);
X   If Not Odd(Status) then
X      Find_First := ''
X   Else
X      Find_First := Temp;
X   End;  (* Find_First *)
X
X
X
XFunction Find_Next (File_Name : Var132) : Var132;
X
X   Var
X      Temp   : Var132;
X      Status : Integer;
X
X   Begin
X   Status := $Find_File (File_Name, Temp, G_Dummy);
X   If Not Odd(Status) then
X      Find_Next := ''
X   Else
X      Find_Next := Temp;
X   End;  (* Find_Next *)
X
X
X
XFunction Open_Read (File_Name : Var132; Var File_Variable : Text) : Boolean;
X
X   Begin
X   Open (File_Variable := File_Variable,
X         File_Name     := File_Name,
X         History       := ReadOnly,
X         Error         := Continue);
X   Reset (File_Variable := File_Variable,
X          Error         := Continue);
X   If UFB(File_Variable) then
X      Open_Read := False
X   Else
X      Open_Read := True;
X   End;  (* Open_Read *)
X
X`012
XProcedure Do_Tail (File_Name : Var132);
X
X   Var
X      Line    : Var132;
X      Count   : Integer;
X      L_Count : Integer;
X
X   Begin
X   Writeln;
X   Writeln;
X   Writeln ('>>> ', File_Name, ' <<<');
X   Writeln;
X   If Not Open_Read(File_Name, In_File) then
X      Writeln ('    *** Unable to Open File ***')
X   Else
X      Begin
X      L_Count := 0;
X      While Not EOF(In_File) do
X         Begin
X         While Not EOLN(In_File) do
X            Read (In_File, Line);
X         If Not EOF(In_File) then
X            Readln (In_File);
X         L_Count := L_Count + 1;
X         End;  (* While *)
X      Close (In_File);
X      Open_Read (File_Name, In_File);
X      For Count := 1 to (L_Count - Num_Lines) do
X         Readln (In_File);
X      While Not EOF(In_File) do
X         Begin
X         While Not EOLN(In_File) do
X            Begin
X            Read (In_File, Line);
X            Write (Line);
X            End;  (* While *)
X         If Not EOF(In_File) then
X            Readln (In_File);
X         Writeln;
X         End;  (* While *)
X      Close (In_File);
X      End;
X   Writeln;
X   End;  (* Do_Tail *)
X
X
X`012
X[Initialize] Procedure Initialize;
X
X   Begin
X   $Get_Foreign (File_Name);
X   Num_Lines := Def_Lines;
X   If Length(File_Name) > 1 then
X      Begin
X      If File_Name[1] = '-' then
X         Begin
X         File_Name := Substr(File_Name,2,Length(File_Name)-1);
X         ReadV (File_Name, Num_Lines, File_Name,
X                Error := Continue);
X         End;
X      End;
X   If Length(File_Name) = 0 then
X      Begin
X      Write ('usage:  tail [-#] filename');
X      $Exit(1);
X      End;
X   End;  (* Initialize *)
X
X
XBegin
XDone := False;
XNew_Name := Find_First(File_Name);
XIf Length(New_Name) = 0 then
X   Write ('No such file.')
XElse
X   Begin
X   Repeat
X      Do_Tail (New_Name);
X      Old_Name := New_Name;
X      New_Name := Find_Next(File_Name);
X      If Length(New_Name) = 0 then
X         Done := True;
X   Until Done;
X   End;
XEnd.
$ GOSUB UNPACK_FILE
$ FILE_IS = "TAIL.CLD"
$ CHECKSUM_IS = 1497178734
$ COPY SYS$INPUT VMS_SHARE_DUMMY.DUMMY
XDefine`009Verb Tail
XImage`009Bin:Tail.Exe
X`009Parameter P1
X`009Parameter P2
X
$ GOSUB UNPACK_FILE
$ EXIT


-- 
---------------------------------+--------------------------------------------
 Tim Russell, Computer Operator  | Internet: fritz@fergvax.unl.edu
 Campus Computing                | Bitnet:   russell@unoma1
 University of Nebraska at Omaha | UUCP:     uunet!btni!unocss!fritz

