From:	AITGW::"FILESERV@WKUVX1.BITNET" 16-MAR-1992 10:28:02.27
To:	ARISIA::EVERHART
CC:	
Subj:	LOOK.01_OF_04

Received: by AITGW.DECnet (utk-mail11 v1.5) ; Mon, 16 Mar 92 10:27:15 EST
Received: from ukcc.uky.edu by aitgw.ge.com (5.65/GE Gateway 1.5)
	id AA02451; Mon, 16 Mar 92 10:27:03 -0500
Message-Id: <9203161527.AA02451@aitgw.ge.com>
Received: from ukcc.uky.edu by UKCC.uky.edu (IBM VM SMTP V2R2)
   with BSMTP id 6871; Mon, 16 Mar 92 10:23:38 EST
Received: from UKCC by ukcc.uky.edu (Mailer R2.08) with BSMTP id 6587; Mon, 16
 Mar 92 10:23:36 EST
Received: from WKUVX1.BITNET by ukcc.uky.edu (Mailer R2.08) with BSMTP id 6577;
 Mon, 16 Mar 92 10:23:33 EST
Received: by WKUVX1.BITNET (MX V3.0A) id 16028; Mon, 16 Mar 1992 08:32:31 CST
Date: Mon, 16 Mar 1992 08:32:31 CST
From: FILESERV-Mgr@WKUVX1.BITNET
Reply-To: FILESERV@WKUVX1.BITNET
Subject: LOOK.01_OF_04
To: ARISIA::EVERHART
 
$! ------------------ CUT HERE -----------------------
$ v='f$verify(f$trnlnm("SHARE_VERIFY"))'
$!
$! This archive created by VMS_SHARE Version 7.2-007  22-FEB-1990
$!   On 12-MAR-1992 07:38:45.58   By user GOATHUNTER (@WKUVX1.BITNET)
$!
$! This VMS_SHARE Written by:
$!    Andy Harper, Kings College London UK
$!
$! Acknowledgements to:
$!    James Gray       - Original VMS_SHARE
$!    Michael Bednarek - Original Concept and implementation
$!
$!+ THIS PACKAGE DISTRIBUTED IN 4 PARTS, TO KEEP EACH PART
$!  BELOW 30 BLOCKS
$!
$! TO UNPACK THIS SHARE FILE, CONCATENATE ALL PARTS IN ORDER
$! AND EXECUTE AS A COMMAND PROCEDURE  (  @name  )
$!
$! THE FOLLOWING FILE(S) WILL BE CREATED AFTER UNPACKING:
$!       1. [.LOOK]BUILDLOOK.COM;1
$!       2. [.LOOK]LOOK.C;1
$!       3. [.LOOK]README.1ST;1
$!       4. [.LOOK]VIEW$VIEW_HLP.VIEW$HLP;1
$!
$set="set"
$set symbol/scope=(nolocal,noglobal)
$f=f$parse("SHARE_TEMP","SYS$SCRATCH:.TMP_"+f$getjpi("","PID"))
$e="write sys$error  ""%UNPACK"", "
$w="write sys$output ""%UNPACK"", "
$ if f$trnlnm("SHARE_LOG") then $ w = "!"
$ ve=f$getsyi("version")
$ if ve-f$extract(0,1,ve) .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ v=f$verify(v)
$ exit 44
$UNPACK: SUBROUTINE ! P1=filename, P2=checksum
$ if f$search(P1) .eqs. "" then $ goto file_absent
$ e "-W-EXISTS, File ''P1' exists. Skipped."
$ delete 'f'*
$ exit
$file_absent:
$ if f$parse(P1) .nes. "" then $ goto dirok
$ dn=f$parse(P1,,,"DIRECTORY")
$ w "-I-CREDIR, Creating directory ''dn'."
$ create/dir 'dn'
$ if $status then $ goto dirok
$ e "-E-CREDIRFAIL, Unable to create ''dn'. File skipped."
$ delete 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ if .not. f$verify() then $ define/user sys$output nl:
$ EDIT/TPU/NOSEC/NODIS/COM=SYS$INPUT 'f'/OUT='P1'
PROCEDURE Unpacker ON_ERROR ENDON_ERROR;SET(FACILITY_NAME,"UNPACK");SET(
SUCCESS,OFF);SET(INFORMATIONAL,OFF);f:=GET_INFO(COMMAND_LINE,"file_name");b:=
CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(b));
LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(b));g:=0;LOOP EXITIF MARK(NONE)=END_OF(b);x:=ERASE_CHARACTER(1);
IF g=0 THEN IF x="X" THEN MOVE_VERTICAL(1);ENDIF;IF x="V" THEN APPEND_LINE;
MOVE_HORIZONTAL(-CURRENT_OFFSET);MOVE_VERTICAL(1);ENDIF;IF x="+" THEN g:=1;
ERASE_LINE;ENDIF;ELSE IF x="-" THEN IF INDEX(CURRENT_LINE,"+-+-+-+-+-+-+-+")=
1 THEN g:=0;ENDIF;ENDIF;ERASE_LINE;ENDIF;ENDLOOP;t:="0123456789ABCDEF";
POSITION(BEGINNING_OF(b));LOOP r:=SEARCH("`",FORWARD);EXITIF r=0;POSITION(r);
ERASE(r);x1:=INDEX(t,ERASE_CHARACTER(1))-1;x2:=INDEX(t,ERASE_CHARACTER(1))-1;
COPY_TEXT(ASCII(16*x1+x2));ENDLOOP;WRITE_FILE(b,GET_INFO(COMMAND_LINE,
"output_file"));ENDPROCEDURE;Unpacker;QUIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create 'f'
X$!
X$!     This is the command file to compile & link LOOK software and
X$!     define logical & symbolical names needed.
X$!
X$!     Serge Kovalyov, March, 12, 1992.
X$!
X$ write sys$output "Compiling..."
X$ cc look
X$ write sys$output "Linking..."
X$ link look,sys$input:/opt
Xsys$share:vaxcrtl.exe/share
X$ write sys$output "Defining environment..."
X$ look:==$'f$environment("DEFAULT")'look
X$ define LOOK$HELP "look view$view_hlp.view$hlp"
X$ define LOOK$EDIT "ed/tpu %s"
X$ write sys$output ""
X$ write sys$output "Usage:"
X$ write sys$output "  $ look`5B file-spec`5D`5B file-spec...`5D "
X$ write sys$output "or (for help)"
X$ write sys$output "  $ look ?"
$ CALL UNPACK [.LOOK]BUILDLOOK.COM;1 1009722020
$ create 'f'
X/*
X *  This is VAX/VMS fast file viewer. Author - S. Kovalyov, INP.
X *
X *  Filetype-sensitive! (distinguishes text/binary files).
X *  Wildcard is allowed!
X */
X
X#include <iodef.h>
X#include <rmsdef.h>
X#include <smgdef.h>
X#include <ssdef.h>
X#include <fab.h>
X#include <nam.h>
X#include <rab.h>
X#include <xab.h>
X#include <smgmsg.h>
X#include <smg$routines.h>
X#include <lib$routines.h>
X#include <descrip.h>
X#include <ctype.h>
X#include <stdio.h>
X#include <stdlib.h>
X
X
X#define UNPRINTABLE '.'
X
X#define VBLOCKLEN   512
X#define BINRECLEN   16
X#define BINTXTLEN   64
X#define LONGWORDLEN 4
X#define FNAMLEN`09    NAM$C_MAXRSS
X
X#define UP`09    SMG$K_TRM_UP
X#define DOWN`09    SMG$K_TRM_DOWN
X#define RIGHT`09    SMG$K_TRM_RIGHT
X#define LEFT`09    SMG$K_TRM_LEFT
X
X#define TAB`09    SMG$K_TRM_CTRLI
X#define PREV`09    SMG$K_TRM_E5
X#define NEXT`09    SMG$K_TRM_E6
X
X#define eNTER`09    SMG$K_TRM_ENTER
X#define ENTER`09    SMG$K_TRM_CTRLM
X#define enTER`09    SMG$K_TRM_CTRLJ
X#define DEL`09    127
X#define hELP`09    SMG$K_TRM_F15
X#define EXIT`09    SMG$K_TRM_F10
X#define BREAK`09    SMG$K_TRM_CTRLZ
X#define FIND`09    SMG$K_TRM_FIND
X#define REFRESH`09    SMG$K_TRM_CTRLW
X#define REREAD`09    SMG$K_TRM_CTRLR
X
X#define HLPFLLNM`09"LOOK$HELP"
X#define EDTFLLNM`09"LOOK$EDIT"
X#define HELPCOMMAND`09"look view$view_hlp.view$hlp"
X#define EDITCOMMAND`09"ed/tpu %s"
X#define DEFAULT_OUTPUT`09"sys$output"
X#define DEFAULT_INPUT`09"sys$input"
X#define HELPLINE`09"helP eXit Quit Home End scrRight scrLeft Find findNxt eD
V Go Spawn chWid Txt/hex "
X#define INVITE_FIND`09"Find : "
X#define INVITE_LINE`09"Line number or percentage : "
X#define NOTHING_FOUND`09"Nothing found.  PRESS ANY KEY  "
X#define WORKING_FORMAT`09" %3d%% processing... (Press \'X\' to cancel) "
X#define PLEASE_WAIT`09" Wait please... "
X#define HEADLINE_FORMAT`09"File: %s  Row: %4d  Col: %3d  (%3d%%)"
X
X#define $_ABNORMAL`09-1
X#define EXIT_NORMAL`092
X#define NO_CLOSE`093
X#define RELOOK`09`094
X
X#define SCREENVER`0920
X#define SCREENMAX`09132
X#define SCREENMIN`0980
X#define SCREENCHNG`0913
X#define BORDERFIELD`090
X#define LASTLINE`0924
X#define MAXLINE`09`09256
X#define BUFDEPTH`0920
X#define BUFQ`09`092
X#define TOFIND`09`090
X#define TOLINE`09`091
X#define`09WORKING_STEP`09100
X#define READKEY_STEP`0910
X
X#define CHECKRESULT(x)`09`7B if ((x) != SS$_NORMAL) return $_ABNORMAL; `7D
X#define`09FBEG(y)`09`09`7B if (sh_seek(vf_inf.home`5By`5D) == -1) return $_A
VBNORMAL; `7D
X#define BEEP`09`09CHECKRESULT(smg$ring_bell(&vdisp.id))
X
X
Xstruct`20
X`7B
X    int bintxt;
X    unsigned int *home;
X    unsigned int current, end, all;
X    struct
X    `7B
X`09unsigned int pos;
X`09int beg;
X`09unsigned int rend;
X`09char sline`5BSCREENMAX + 1`5D;
X    `7D head, inv;
X`7D vf_inf =
X`7B   0,
X    NULL,
X    0, 0, 0,
X    `7B SMG$K_TOP, 1, SMG$M_REVERSE, 0 `7D,
X    `7B SMG$K_BOTTOM, 1, SMG$M_REVERSE, 0 `7D
X`7D;
X
Xstruct
X`7B
X    unsigned long id;
X    long          firstrow, firstcol, len, wid;
X    struct `7Blong  firstcol, firstrow, len, curcol;`7D vport;
X    struct `7Blong  row, col;`7D cursor;
X    char *f_spec;
X`7D vdisp =
X`7B
X    0, 2, 1, MAXLINE, SCREENVER,
X    `7B 1, 1, 0, 1 `7D, `7B 1, 1 `7D,
X    `7B '\0' `7D
X`7D;
X
Xstruct
X`7B
X    unsigned long id;
X    long firstrow, firstcol, len, wid, rend;
X`7D k_bar =
X`7B
X    0, LASTLINE, 1, SCREENMAX, 1, SMG$M_REVERSE
X`7D;
X
Xchar`09line`5BMAXLINE + 1`5D, no_line`5BMAXLINE + 1`5D;
X$DESCRIPTOR(outstr, INVITE_FIND);
X$DESCRIPTOR(hlnm, HLPFLLNM);
X$DESCRIPTOR(elnm, EDTFLLNM);
Xint wn = 0;
Xunsigned int`09rpt = 0;
Xunsigned int`09lnmlen = 0;
Xunsigned int`09p_id = 0, k_id = 0;
Xunsigned int`09screensize = 0;
X
Xstruct`09`7B char fline`5BSCREENMAX + 1`5D; int flen; `7D linebuf`5BBUFQ`5D`
V5BBUFDEPTH + 1`5D;
Xint`09fbc`5BBUFQ`5D = `7B 1, 1 `7D;
X
Xunsigned int timeout`09= 0;
Xunsigned int rend_find`09= SMG$M_BOLD;
Xunsigned int c_off`09= SMG$M_CURSOR_OFF;
Xunsigned int c_on`09= SMG$M_CURSOR_ON;
Xunsigned int pscroll`09= SMG$M_DOWN;
Xunsigned int scrright`09= SMG$M_RIGHT;
Xunsigned int scrleft`09= SMG$M_LEFT;
X
X
X    /* RMS file I/O routines */
X
Xstruct FAB fab_of_name, fab_of_file;
Xstruct NAM nam_file;
Xstruct RAB several_bytes;
Xstruct XABFHC file_header;
X
Xint inner_ptr = VBLOCKLEN;
Xchar v_block`5BVBLOCKLEN`5D;
X
Xchar res_name`5BFNAMLEN`5D;
Xchar rnm`5BFNAMLEN`5D;
Xchar outname`5BFNAMLEN`5D;
X
Xint asy_stop = 0;
X
Xint v_rec_len`09= 0;
Xint align_byte`09= 0;
X
X`09/* Asynchronious operation completion indication */
X
Xvoid
Xast_stop(void)
X`7B
X    asy_stop = 1;
X`7D
X
X`09/* Expand file name */
X
Xchar *
Xsh_fname(char *name_of_file)
X`7B
X    if (name_of_file != NULL)
X    `7B
X`09nam_file.nam$b_bid = NAM$C_BID;
X`09nam_file.nam$b_bln = NAM$C_BLN;
X`09nam_file.nam$b_ess = FNAMLEN;
X`09nam_file.nam$b_esl = FNAMLEN;
X`09nam_file.nam$l_esa = res_name;
X`09nam_file.nam$b_nop = 0;
X`09nam_file.nam$b_rss = FNAMLEN;
X`09nam_file.nam$b_rsl = FNAMLEN;
X`09nam_file.nam$l_rsa = rnm;
X
X`09fab_of_name.fab$b_bid = FAB$C_BID;`20
X`09fab_of_name.fab$b_bln = FAB$C_BLN;`20
X`09fab_of_name.fab$l_nam = &nam_file;
X`09fab_of_name.fab$l_fna = name_of_file;
X`09fab_of_name.fab$b_fns = strlen(name_of_file);
X`09fab_of_name.fab$l_fop = FAB$M_OFP;
X
X`09fab_of_name.fab$l_sts = 0;
X`09asy_stop = 0;
X`09sys$parse(&fab_of_name, ast_stop, ast_stop);
X`09while(asy_stop == 0);
X`09if (fab_of_name.fab$l_sts != RMS$_NORMAL) return NULL;
X    `7D
X
X    fab_of_name.fab$w_ifi = 0;
X    fab_of_name.fab$l_sts = 0;
X    asy_stop = 0;
X    sys$search(&fab_of_name, ast_stop, ast_stop);
X    while(asy_stop == 0);
X    if (fab_of_name.fab$l_sts != RMS$_NORMAL) return NULL;
X    strncpy(outname, rnm, nam_file.nam$b_rsl);
X    outname`5Bnam_file.nam$b_rsl`5D = '\0';
X    return outname;
X`7D
X
X`09/* File name only */
X
Xchar *
Xsh_onlyname(void)
X`7B
X    return &outname`5B(int)(nam_file.nam$l_name - nam_file.nam$l_rsa)`5D;
X`7D
X
X`09/* Open file */
X
Xint
Xsh_open(char *name_of_file)
X`7B
X    if (name_of_file == NULL) return -1;
X
X    inner_ptr = VBLOCKLEN;
X
X    fab_of_file.fab$b_bid = FAB$C_BID;
X    fab_of_file.fab$b_bln = FAB$C_BLN;
X    fab_of_file.fab$w_ifi = 0;
X    fab_of_file.fab$b_fac = FAB$M_GET `7C FAB$M_BIO;
X    fab_of_file.fab$l_fna = name_of_file;
X    fab_of_file.fab$b_fns = strlen(name_of_file);
X    fab_of_file.fab$l_fop = FAB$M_SQO `7C FAB$M_CIF;
X    fab_of_file.fab$b_shr = FAB$M_SHRGET `7C FAB$M_SHRPUT `7C FAB$M_UPI;
X    fab_of_file.fab$b_rtv = 0;
X    fab_of_file.fab$l_xab = &file_header;
X
X    file_header.xab$b_cod = XAB$C_FHC;
X    file_header.xab$b_bln = XAB$C_FHCLEN;
X    file_header.xab$l_nxt = 0;
X
X    asy_stop = 0;
X    fab_of_file.fab$l_sts = 0;
X    sys$open(&fab_of_file, ast_stop, ast_stop);
X    while(asy_stop == 0);
X    if (fab_of_file.fab$l_sts != RMS$_NORMAL) return -1;
X
X    several_bytes.rab$b_bid = RAB$C_BID;
X    several_bytes.rab$b_bln = RAB$C_BLN;
X    several_bytes.rab$w_isi = 0;
X    several_bytes.rab$l_rop = RAB$M_RAH `7C RAB$M_BIO;
X    several_bytes.rab$l_fab = &fab_of_file;
X    several_bytes.rab$l_xab = 0;
X
X    if (sys$connect(&several_bytes) != RMS$_NORMAL) return -1;
X
X    several_bytes.rab$l_bkt = 0;
X    several_bytes.rab$l_rop = 0;
X    several_bytes.rab$w_usz = (unsigned short)VBLOCKLEN;
X    several_bytes.rab$l_ubf = v_block;
X
X    v_rec_len`09= 0;
X    return 0;
X`7D
X
X`09/* Read some bytes */
X
Xint
Xsh_read(char *buf, int buflen)
X`7B
X    int rest_blk = VBLOCKLEN - inner_ptr;
X    int actual_rest = buflen;
X
X    while (actual_rest > rest_blk)
X    `7B
X`09if (rest_blk > 0)
X`09    memcpy(buf + (buflen - actual_rest),
X`09`09several_bytes.rab$l_ubf + inner_ptr, (size_t)rest_blk);
X
X`09several_bytes.rab$l_bkt++;`09/* Next virtual block */
X
X`09if (sys$read(&several_bytes) != RMS$_NORMAL)
X`09    return buflen - actual_rest;
X
X`09actual_rest -= rest_blk;
X`09rest_blk = VBLOCKLEN;
X`09inner_ptr = 0;
X    `7D
X    if (actual_rest == 0) return buflen;
X    memcpy(buf + (buflen - actual_rest),
X`09several_bytes.rab$l_ubf + inner_ptr, (size_t)actual_rest);
X    inner_ptr += actual_rest;
X    return buflen;
X`7D
X
X`09/* Calculate byte offset */
X
Xunsigned int
Xsh_tell(void)
X`7B
X    return (unsigned int)(several_bytes.rab$l_bkt * VBLOCKLEN
X`09+ inner_ptr - VBLOCKLEN);
X`7D
X
X`09/* End of file offset */
X
Xunsigned int
Xsh_eof(void)
X`7B
X    return VBLOCKLEN * (file_header.xab$l_ebk - 1) + file_header.xab$w_ffb;
X`7D
X
X`09/* Find position under offset */
X
Xint
Xsh_seek(unsigned int offset)
X`7B
X    if (several_bytes.rab$l_bkt != offset / VBLOCKLEN + 1)
X    `7B
X`09several_bytes.rab$l_bkt = offset / VBLOCKLEN + 1;
X`09if (sys$read(&several_bytes) != RMS$_NORMAL) return -1;
X    `7D
X    inner_ptr = offset % VBLOCKLEN;
X    return 0;
X`7D
X
X`09/* Retrieve binary line with given length */
Xint
Xbin_fgets(char *str, int charnum, int mode)
X`7B
X    int i = 0;
X    int txt_offset = charnum * 2 + LONGWORDLEN;
X    int str_len = txt_offset + LONGWORDLEN + charnum + 1;
X    char ch = '\0';
X    char hex_ch`5B3`5D;
X    char *hex_ptr, *txt_ptr;
X
X    if (mode != SS$_NORMAL)
X    `7B
X`09if  (sh_read(str, charnum) != charnum) return -1;
X`09return 0;
X    `7D
X    memset(str, ' ', (size_t)str_len);
X    hex_ptr = str + txt_offset;
X    txt_ptr = hex_ptr + LONGWORDLEN;
X    for (i = 0; i < BINRECLEN; i++)
X    `7B
X`09if  (sh_read(&ch, 1) != 1) return -1;
X`09sprintf(hex_ch, "%02X", (unsigned char)ch);
X`09if ((i % LONGWORDLEN) == 0) hex_ptr--;
X`09*hex_ptr = hex_ch`5B1`5D;
X`09hex_ptr--;
X`09*hex_ptr = hex_ch`5B0`5D;
X`09hex_ptr--;
X`09*txt_ptr = (isprint(ch) == 0) ? '.' : ch;
X`09txt_ptr++;
X    `7D
X    *txt_ptr = '\0';
X    return 0;
X`7D
X
X`09/* Retrieve text line with given length */
Xint
Xtxt_fgets(char *str, int charnum, int mode)
X`7B
X    int p = 0;
X
X    if (sh_read(str, charnum) != charnum) return -1;
X    if (mode == SS$_NORMAL)
X    `7B
X`09for (p = 0; p < charnum; p++)
X`09    if (isprint(str`5Bp`5D) == 0) str`5Bp`5D = '.';
X`09str`5Bp`5D = '\0';`09    /* Terminator */
X    `7D
X    return 0;
X`7D
X
X`09/* Retrieve a line considering RMS file organization */
X
Xint
Xsh_fgets(char *str, int maxchar, int mode)
X`7B
X    int i = 0;
X    char ctrl_byte = '\0';
X    char *rest_rec = NULL;
X
X    if (maxchar <= 0) return -1;
X    if (sh_tell() >= sh_eof()) return -1;
X    if (vf_inf.bintxt == $_ABNORMAL) return bin_fgets(str, BINRECLEN, mode);
X    switch(fab_of_file.fab$b_rfm)
X    `7B
X    case FAB$C_VAR:`09`09    /* Usual VMS text files */
X    case FAB$C_VFC:`09`09    /* Printer format files */
X
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-
