From:	CRDGW2::CRDGW2::MRGATE::"SMTP::CRVAX.SRI.COM::RELAY-INFO-VAX"  4-AUG-1989 01:41
To:	MRGATE::"ARISIA::EVERHART"
Subj:	VMS MORE V1.00  1 of 5

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Thu,  3 AUG 89 13:48:21 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Thu, 3 Aug 89 13:33:05 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.37)
	id AA23206; Thu, 3 Aug 89 13:05:03 -0700
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: 3 Aug 89 19:38:40 GMT
From: rex!uflorida!haven!aplcen!jhunix!ins_bxs@ames.arc.nasa.gov  (Xuning Shan)
Organization: The Johns Hopkins University - HCF
Subject: VMS MORE V1.00  1 of 5
Message-Id: <2191@jhunix.HCF.JHU.EDU>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com



    VMS MORE V1.00 is posted in 5 parts of VMS shar
format.  A version number was  specified to keep 
track of the source code. 
    A netter has proposed to put  the source in
VMSSERV file server.  Please let me know  how I can submit
to it.
    I'm not a system manager anymore.-:) So I can
not provide anonymous FTP. If anyone would like
to do so, please let me know.

Xuning Shan
ins_bxs@jhuvms.bitnet

 
$!-----------------------------------------------------
$! ------------------ CUT HERE -----------------------
$!
$! This archive created by VMS_SHARE Version 7.1-001  26-JUN-1989
$!   On  3-AUG-1989 15:16:10.03   By user SHAN 
$!
$! 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 5 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. BUILDMORE.COM;1
$!       2. MORE.C;1
$!       3. MORE.DOC;1
$!       4. REG.C;2
$!       5. UNIX2VMS.C;1
$!
$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 = "!"
$ if f$getsyi("version") .ges. "4.4" then $ goto START
$ e "-E-OLDVER, Must run at least VMS 4.4"
$ 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/nolog '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/nolog 'f'*
$ exit
$dirok:
$ w "-I-PROCESS, Processing file ''P1'."
$ 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");
buff:=CREATE_BUFFER(f,f);p:=SPAN(" ")@r&LINE_END;POSITION(BEGINNING_OF(buff))
;LOOP EXITIF SEARCH(p,FORWARD)=0;POSITION(r);ERASE(r);ENDLOOP;POSITION(
BEGINNING_OF(buff));g:=0;LOOP EXITIF MARK(NONE)=END_OF(buff);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 g:=0;ENDIF;ERASE_LINE;
ENDIF;ENDLOOP;p:="`";POSITION(BEGINNING_OF(buff));LOOP r:=SEARCH(p,FORWARD);
EXITIF r=0;POSITION(r);ERASE(r);COPY_TEXT(ASCII(INT(ERASE_CHARACTER(3))));
ENDLOOP;o:=GET_INFO(COMMAND_LINE,"output_file");WRITE_FILE(buff,o);
ENDPROCEDURE;Unpacker;EXIT;
$ delete/nolog 'f'*
$ CHECKSUM 'P1'
$ IF CHECKSUM$CHECKSUM .eqs. P2 THEN $ EXIT
$ e "-E-CHKSMFAIL, Checksum of ''P1' failed."
$ ENDSUBROUTINE
$START:
$ create/nolog 'f'
X$!VMS file brower V1.00: compiled  with conditions.
X$!
X$!define link libraries
X$define lnk$library      sys$library:vaxccurse
X$define lnk$library_1    sys$library:vaxcrtlg
X$define lnk$library_2    sys$library:vaxcrtl
X$!
X$!UNCOMMENT  ONE OF THE NEXT FOUR LINES`032
X$!If you need UNIX to VMS file name conversion, define UNIX_TO_VMS.
X$!If you need regular expression in search,     define REXPRESSIONS.
X$!cc/optimize                                  more
X$!cc/define=(REXPRESSIONS)/optimize            more
X$!cc/define=(UNIX_TO_VMS)/optimize             more
X$cc/define=(REXPRESSIONS,UNIX_TO_VMS)/optimize more
X$cc reg
X$cc unix2vms
X$link/exe=more more,reg,unix2vms
$ CALL UNPACK BUILDMORE.COM;1 303045530
$ create/nolog 'f'
X/* - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -
X`009VMS MORE: V1.00
X`009Author: Xuning Shan
X`009`009Dept. of Chemical Engineering
X`009`009The Johns Hopkins Univ.
X`009Email : ins_bxs@jhuvms.BITNET
X`009`009shan%che2@jhmail.hcf.jhu.edu
X
X`009Documentation and modification histroy is in file more.doc`009`009
X */
X`032
X#include stdio
X#include ctype
X#include descrip
X#include stat
X`032
Xtypedef char bool;
X#define TRUE  1
X#define FALSE 0
X#define BELL '\007'    `032
X#define EOS '\0'
X`032
X#define MAXNAME    254
X#define MAXWINDOWS 200
X#define MAXFILES   200
X`032
X#define ding() putchar(BELL)
X`032
Xbool Terminal_Open();
Xvoid clrs();
Xvoid ClrEOL();
Xvoid standend();
Xvoid descriptor();
Xvoid standout();
Xint  getkey();
X
X#ifdef UNIX_TO_VMS
Xchar *convert_unix_to_vms();
X#endif UNIX_TO_VMS
X
Xchar *strchr();
Xchar *malloc();
Xchar *strrchr();
X`032
Xint more();
Xbool prwindow();
Xbool prline();
Xvoid lower_str();
Xvoid fix_string();
Xint  str_lines();
Xint  flag=FALSE;    `032
Xint  search=FALSE;
Xint  Screen_Height = 24; /* may be changed below */
Xint  Screen_Width  = 80;
Xint  line_ct;
X`032
X`032
Xmain(argc, argv)
Xint argc;
Xchar **argv;
X`123
X        int i, j , first=1;
X        char *pn;
X        FILE *fp;
X        int nargc;`032
X        char *nargv`091MAXFILES + 1`093;
X        bool file_found;
X`032
X        /* next few lines to deal with lib$find_file() */
X        static char name`091MAXNAME`093;
X        $DESCRIPTOR(result,name);
X        struct dsc$descriptor_s name_desc; `032
X        long context;
X        Terminal_Open();
X`032
X        if(argc==1)`123                    /*if no file, prompt for it */
X                argv`0911`093=malloc(40);
X                printf("File:");
X                scanf("%s",argv`0911`093);
X                argc++;
X        `125
X        if(strcmp(argv`0911`093,"-c")==0)`123
X                flag=TRUE;
X                first=2;
X                if(argc==2)`123
X                        argv`0912`093=malloc(40);
X                        printf("File:");
X                        scanf("%s",argv`0912`093);
X                        argc++;
X                `125
X        `125
X        for (i = first, nargc = 0; i < argc && nargc <= MAXFILES; i++)
X        `123
X                context = 0;
X#ifdef UNIX_TO_VMS
X                if (strchr (argv`091i`093, '/') != (char *) NULL)
X                        argv`091i`093 = convert_unix_to_vms (argv`091i`093);
X#endif UNIX_TO_VMS
X`032
X                descriptor(&name_desc,argv`091i`093);
X                file_found = FALSE;
X                while (lib$find_file(&name_desc, &result, &context) & 1)
X                `123
X                        file_found = TRUE;
X                        if (nargc >= MAXFILES)`123
X                                fprintf(stderr, "Only %d files will be read\
Vn",
X                                MAXFILES);
X                                break;
X                        `125
X                        nargv`091++nargc`093 = malloc((unsigned)strlen(name)
V + 1);
X                        strcpy(nargv`091nargc`093, name);
X                `125
X                if (!file_found)
X                        fprintf (stderr, "Couldn't find file %s\n", argv`091
Vi`093);
X                lib$find_file_end(&context);
X        `125
X`032
X        for (i=1; i<=nargc; i++)
X        `123
X                lower_str(nargv`091i`093);
X                if ((fp = fopen(nargv`091i`093, "r")) == NULL)`123
X                        perror(nargv`091i`093);
X                        continue;
X                `125
X                for (pn = nargv`091i`093; *pn != EOS && *pn != '`093'; pn++)
V;
X                if (*pn == '`093') pn++;  /*get file name without path*/
X                switch(more(fp, pn))
X                `123    `032
X                  case 112:  /* ASCII p: previous file */
X                        if((i==1) `124`124(nargc==1))`123
X                          putchar('\r');ClrEOL();
X                          standout();
X                          printf("No previous file.\n");
X                          standend();
X                          i--;
X                          printf("press any key to continue...");
X                          getkey();
X                        `125
X                        else`123
X                           i -=2; /*reset file counter */
X                          putchar('\r');ClrEOL();
X                          standout();
X                          printf("previous file:");
X                          standend();
X                          printf("%s\n",nargv`091i+1`093);
X                          printf("press any key to continue...");
X                          getkey();
X                        `125
X                        break;
X                  case 101:  /* ASCII e: end of file */
X                        standout();
X                        printf("End of File:");
X                        standend();
X                        printf("%s\n",nargv`091i`093);
X                        if(i!=nargc)`123
X                                printf("press any key to continue...");
X                                getkey();
X                        `125
X                        break;
X                default:
X                        if(i<nargc)`123
X                          lower_str(nargv`091i+1`093);
X                          putchar('\r'),ClrEOL();
X                          printf("\nNext file:%s\n",nargv`091i+1`093);
X                          printf("press any key to continue...");
X                          getkey();
X`032
X                        `125
X                `125/*switch*/
X                               `032
X                fclose(fp);
X        `125/*for*/
X`032
X`125  /* main */
X`032
Xint more(fp, fname)
XFILE *fp;
Xchar *fname;
X`123
X        char pattern`091BUFSIZ`093, a_line`091BUFSIZ`093, tmp`09120`093;
X        int  i=0, ch, lastcommand,wc=0, wc_save, line_count, pat_found;
X        long win`091MAXWINDOWS`093, file_size;
X        struct stat status_block;
X        long ftell();
X        int  find(), fseek();
X#ifdef REXPRESSIONS
X        char *re_comp(),*pmsg;
X#endif REXPRESSIONS
X        int factor=1;
X        line_ct=0;
X        win`0910`093 = 0;
X        fstat (fileno (fp), &status_block);
X        file_size = status_block.st_size;
X        line_ct +=(Screen_Height-1);
X        clrs();
X        if (!prwindow(fp, Screen_Height - 1, Screen_Width))
X                return(101); /* window #0 */
X        while(TRUE)
X        `123
X                standout();
X                printf("\r--More--(%s, %d%%)", fname,
X                feof(fp) ? 100 : (int)((double)ftell(fp)/
X                    (double)file_size*100.0));
X                standend();
X                i=0;
X                tmp`0910`093='\0';
X                while (isdigit(ch = getkey()))
X                `123      `032
X                        tmp`091i++`093=ch;
X                        tmp`091i`093='\0';
X                `125
X                if(tmp`0910`093!='\0') `123
X                        factor=atoi(tmp);
X                        tmp`0910`093='\0';
X                `125
X                ch=tolower(ch);
X                if( ch == '.' ) ch=lastcommand;
X                if( ch == ':') `123
X                        ch=getkey();
X                        if(ch=='p') return (112);
X                        if(ch=='n') return(110);/*ASCII n next file*/
X                `125
X                switch ( ch,lastcommand=ch )
X                `123
X                case '\r':
X                case '+':
X                case 'e':
X                case 'j':
X/*                      win`091++wc`093 = ftell(fp);  Not counting as window
V */
X                        line_ct +=factor;
X                        if (!prline(fp,factor))
X                                return(101);
X                        factor=1;
X                        break;
X                case ' ':
X                case 'f':
X                        win`091++wc`093 = ftell(fp);
X                        line_ct +=(Screen_Height-2);
X                        if (!prwindow(fp, Screen_Height - 2, Screen_Width))
X                                return;
X                        break;
X                case 'd':
X                        win`091++wc`093 = ftell(fp);
X                        line_ct +=(Screen_Height/2);
X                        if (!prwindow(fp, Screen_Height / 2, Screen_Width))
X                                return(101);
X                        break;
X                case 's':
X                        standout();
X                        printf("\nSkipping forward %d lines.\n",
X                        factor * (Screen_Height - 1));
X                        standend();
X                        line_ct +=(factor*(Screen_Height-1));
X                        win`091++wc`093 = ftell(fp);
X                        while (factor--)
X                        `123
X                                for (i = 0; i < Screen_Height - 2; i++)
X                                `123
X                                        if (fgets(a_line, BUFSIZ, fp)==NULL)
X                                                return(101);
X                                `125
X                                win`091++wc`093 = ftell(fp);
X                        `125
X                        factor=1;
X                        line_ct +=(Screen_Height-1);
X                        if (!prwindow(fp, Screen_Height - 1, Screen_Width))
X                                return(101);
X                        break;
X                case '/':
X                        putchar('\r');
X                        ClrEOL();
X                        putchar('/');
X                        get_pattern(pattern);
X#ifdef REXPRESSIONS
X                        if(pmsg=re_comp(pattern))`123
X                                fprintf(stdout,"\n%s\n",pmsg);
X                                break;
X                        `125
X#endif REXPRESSIONS
X                case 'n':
X                        search=TRUE;
X                        wc_save = wc;
X                        fgets(a_line, BUFSIZ, fp);
X                        line_ct++;
X                        line_count = 1;
X                        while (!(pat_found=find(pattern, a_line)))
X                        `123
X                                if (fgets(a_line, BUFSIZ, fp) == NULL)
X                                `123
X                                        wc = wc_save;
X                                        clearerr (fp);
X                                        fseek(fp, win`091wc`093, 0);
X                                        standout();
X                                        fputs("\nPattern not found.\n",
X                                        stdout);
X                                        standend();
X                                        break;
X                                `125
X                                line_ct++;
X                                line_count++;
X                                if (line_count > Screen_Height - 1)
+-+-+-+-+-+-+-+-  END  OF PART 1 +-+-+-+-+-+-+-+-

