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

Received: From KL.SRI.COM by CRVAX.SRI.COM with TCP; Thu,  3 AUG 89 20:49:22 PDT
Received: from ucbvax.Berkeley.EDU by KL.SRI.COM with TCP; Thu, 3 Aug 89 20:32:51 PDT
Received: by ucbvax.Berkeley.EDU (5.61/1.37)
	id AA15346; Thu, 3 Aug 89 20:26:52 -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:46:29 GMT
From: haven!aplcen!jhunix!ins_bxs@purdue.edu  (Xuning Shan)
Organization: The Johns Hopkins University - HCF
Subject: VMS MORE V1.0  3 of 5
Message-Id: <2193@jhunix.HCF.JHU.EDU>
Sender: info-vax-request@kl.sri.com
To: info-vax@kl.sri.com

VMS MORE V1.00  3 OF 5:

-+-+-+-+-+-+-+-+ START OF PART 3 -+-+-+-+-+-+-+-+
X`123
X        putchar('\r');
X        ClrEOL(); clrs();
X        printf ("\n\n\t<SPACE>\t\tnext screen\n");
X        puts ("\t<cr>, j, or + \tnext line");
X        puts ("\td\t\thalf a screen");
X        puts ("\tb\t\tskip backward");
X        puts ("\tt\t\ttop of the file");
X        printf ("\ts\t\tskip over next screen\n");
X        puts ("\th\t\tprint this message");
X        puts ("\t/string\t\tsearch forward");
X        puts ("\tn\t\trepeat last search");
X        puts ("\t.\t\trepeat last command");
X        puts ("\t=\t\tprint current line number");
X        puts ("\t:p\t\tprevious file");
X        puts ("\t:n\t\tnext file");
X     `009puts ("\t!\t\tspawn subprocess");
X        puts ("\t#\t\tnext file");
X        puts ("\tq\t\tquit\n");
X        printf("\tcommands <cr>, j, +, s, and b\n");
X        printf("\tcan be prefixed with an integer as factor.\n");
X        standout ();
X        printf (" press any key to continue ");
X        standend ();
X        putchar (' ');
X        getkey ();
X`125
X`032
X/* lower_str() --- Converts a string to lower case and terminates the
X *                      string at the first space. */
X`032
Xvoid lower_str (st)
Xchar *st;
X`123
X        while(*st && *st != ' ')
X        `123
X                *st = tolower(*st);
X                st += 1;
X        `125
X        if (*st == ' ')
X                *st = EOS;
X`125    /* end of lower_str () */
X`032
Xvoid descriptor(desc,string)   `032
Xstruct dsc$descriptor_s *desc;
Xchar *string;`032
X`123
X        desc->dsc$w_length=strlen(string);     `032
X        desc->dsc$b_dtype=DSC$K_DTYPE_T;        /* data type code */
X        desc->dsc$b_class=DSC$K_CLASS_S;        /* descriptor class code */
X        desc->dsc$a_pointer=string;     /* address of first byte of data ele
Vment
X */
X`125
$ CALL UNPACK MORE.C;1 1296416383
$ create/nolog 'f'
X  Documentation and Modification history:
X
X  More is ported utility from UNIX more/less. Its functions
Xare combinations of UNIX  more and less.  Certain UNIX functions
Xsuch as starting VI at current position is not applicable in
XVMS. `032
X
X  Please send your suggestions/modifications to ins_bxs@jhuvms.BITNET.
X
X   Commands (and their alternates):
X
X   <SPACE> ==> print next screen (f)
X   <CR>    ==> print next line (e, j, +). If with prefix i(interger),
X`009`009it will print next i lines.
X   s       ==> skip over next screen
X   t       ==> top of the file (g)
X   b       ==> skip backward
X   h       ==> help message (?)
X   #       ==> go to next file (if more than one specified)
X   q       ==> quit
X   !       ==> spawn subprocess
X   /string ==> search forward for string.  The search is case
X   sensitive
X   n       ==> next occurrence of last search string
X   .       ==> repeat last command
X   =       ==> print current line number `032
X   :p      ==> previous file
X   :n      ==> next file
X
X    s, b,j, and f can be prefixed with integer.
X
X=========Modification history===============================
XAuthor:`032
X
X
X   Xuning  Shan
X   ins_bxs@jhuvms.BITNET
X   Dept. of Chem. Engr, JHU   18/11/87
X
XModification history:
X    `032
X   Modified by Robert Drabek
X   Computer Science Department
X   University of Arizona, Tucson
X    `032
X   December 1987:
X   Added wild-card file searching.
X   Added screen routines using SMG.
X   Added raw key input.
X   Fixed window counting.
X   Fixed string search.
X   Fixed a multitude of other bugs and styled it up a bit.
X   Made it more like the Unix version.
X   Added #, N, and D commands.
X    `032
X   Modified by M. Warner Losh
X   System Manager HydroVAX
X   New Mexico Tech, Socorro NM.
X   ...!lanl!unm-la!unmvax!warner%hydrovax
X    `032
X   December 1987
X    `032
X   Fixed both t and b commands so that when they are at the top of the
X   file, they don't do anything
X   Fixed the spawn command so that it only spawns one job, instead of
X   spawning a spawn.
X   If no files are found, then it says no files were found.
X
X    Modified by Aaron Leonard
X    System Manager UACCIT VAXcluster
X    University of Arizona
X    leonard@rvax.ccit.arizona.edu
X    July 1988
X    `032
X   Unsupported use of fseek() and ftell() in module MORE broke with VMS
X   V5.0 VAXC Run-Time Library.  Fixed by replaceing with call to
X   fstat().  Also refrained from exiting on FALSE status retunred from
X   Terminal_Open, so as to work on UNKNOWN type terminals.
X    `032
X   Modified by Jan Trumbo
X   University of Arizona system programmer
X   trumbo@rvax.ccit.arizona.edu
X   November 1988
X    `032
X   Retrain from exiting if search string not found.
X   Mapped control characters to '.'
X   Fix the long line problem.
X    `032
X
X   Modified by M. Marner Losh
X   April 1989
X    `032
X   Merge changes posted to the net to make this program work on VMS 5.0.
X   Add some code to emulate some common UNIX file names.
X    `032
X   May 1989
X    `032
X   Added changes from Shan Xuning for factor and improved them for multiple
X   digits.  His changes cover only the s command.
X   Fix small bug in prline so that form feed stop messing with my terminal.
X   Added small fix to the 'b' command to reflect the factor code as well.
X
X   Modified by Shan Xuning
X   ins_bxs@jhuvms.BITNET
X
X   June 1989
X   added -c option to home cursor and clear screen before
X`009displaying each screen.
X   added . , =, :p, and :n commands
X   commands <cr>, j, +, s, b can be prefixed with an integer.  `032
X
$ CALL UNPACK MORE.DOC;1 1803499725
$ create/nolog 'f'
X/*  This file was from:
X`009Gerben Jansen,
X`009SARA (Academic Computing Services),
X`009Amsterdam.
X`009Bitnet:     gerben@hasara5.bitnet   `032
X`009Surfnet:    sara5::gerben
X`009Internet:   gerben@sara.nl
X`009Pattern-match search added by Gerben Jansen.
X
X---X. Shan /*
X
X/*
X * regex - Regular expression pattern matching and replacement
X * By:  Ozan S. Yigit (oz) Dept. of Computer Science York University
X * These routines are the PUBLIC DOMAIN equivalents of regex routines as fou
Vnd
X * in 4.nBSD UN*X, with minor extensions.
X * These routines are derived from various implementations found in software
X * tools books, and Conroy's grep. They are NOT derived from
X * licensed/restricted software. For more interesting/academic/complicated
X * implementations, see Henry Spencer's regexp routines, or GNU Emacs patter
Vn
X * matching module.
X * Routines: re_comp:        compile a regular expression into a DFA.
X * char *re_comp(s) char *s;
X * re_exec:        execute the DFA to match a pattern.
X * int re_exec(s) char *s;
X * re_modw        change re_exec's understanding of what a "word" looks like
X * (for \< and \>) by adding into the hidden word-character table.
X * void re_modw(s) char *s;
X * re_subs:    substitute the matched portions in a new string.
X * int re_subs(src, dst) char *src; char *dst;
X * re_fail:    failure routine for re_exec.
X * void re_fail(msg, op) char *msg; char op;
X * Regular Expressions:
X * `0911`093     char    matches itself, unless it is a special character (m
Vetachar):
X * . \ `091 `093 * + `094 $
X * `0912`093     .       matches any character.
X * `0913`093     \       matches the character following it, except when fol
Vlowed by a
X * left or right round bracket, a digit 1 to 9 or a left or right angle
X * bracket. (see `0917`093, `0918`093 and `0919`093) It is used as an escape
V character for all
X * other meta-characters, and itself. When used in a set (`0914`093), it is
V treated
X * as an ordinary character.
X * `0914`093     `091set`093   matches one of the characters in the set. If
V the first
X * character in the set is "`094", it matches a character NOT in the set. A
X * shorthand S-E is used to specify a set of characters S upto E, inclusive.
X * The special characters "`093" and "-" have no special meaning if they app
Vear
X * as the first chars in the set. examples:        match:
X * `091a-z`093    any lowercase alpha
X * `091`094`093-`093    any char except `093 and -
X * `091`094A-Z`093   any char except uppercase alpha
X * `091a-zA-Z`093 any alpha
X * `0915`093     *       any regular expression form `0911`093 to `0914`093,
V followed by closure
X * char (*) matches zero or more matches of that form.
X * `0916`093     +       same as `0915`093, except it matches one or more.
X * `0917`093             a regular expression in the form `0911`093 to `0911
V0`093, enclosed as
X * \(form\) matches what form matches. The enclosure creates a set of tags,
X * used for `0918`093 and for pattern substution. The tagged forms are numbe
Vred
X * starting from 1.
X * `0918`093             a \ followed by a digit 1 to 9 matches whatever a p
Vreviously
X * tagged regular expression (`0917`093) matched.
X * `0919`093    \<    a regular expression starting with a \< construct \>
V    and/or
X * ending with a \> construct, restricts the pattern matching to the
X * beginning of a word, and/or the end of a word. A word is defined to be a
X * character string beginning and/or ending with the characters A-Z a-z 0-9
X * and _. It must also be preceded and/or followed by any character outside
X * those mentioned.
X * `09110`093            a composite regular expression xy where x and y are
V in the
X * form `0911`093 to `09110`093 matches the longest match of x followed by a
V match for y.
X * `09111`093    `094    a regular expression starting with a `094 character
V $    and/or
X * ending with a $ character, restricts the pattern matching to the beginnin
Vg
X * of the line, or the end of line. `091anchors`093 Elsewhere in the pattern
V, `094 and
X * $ are treated as ordinary characters.
X * Acknowledgements:
X * HCR's Hugh Redelmeier has been most helpful in various stages of developm
Vent.
X * He convinced me to include BOW and EOW constructs, originally invented by
X * Rob Pike at the University of Toronto.
X * References: Software tools            Kernighan & Plauger Software tools
V in
X * Pascal        Kernighan & Plauger Grep `091rsx-11 C dist`093            D
Vavid
X * Conroy ed - text editor        Un*x Programmer's Manual Advanced editing
X * on Un*x    B. W. Kernighan RegExp routines            Henry Spencer
X * Notes:
X * This implementation uses a bit-set representation for character classes f
Vor
X * speed and compactness. Each character is represented by one bit in a
X * 128-bit block. Thus, CCL or NCL always takes a constant 16 bytes in the
X * internal dfa, and re_exec does a single bit comparison to locate the
X * character in the set.
X * Examples:
X * pattern:    foo*.* compile:    CHR f CHR o CLO CHR o END CLO ANY END END
X * matches:    fo foo fooo foobar fobar foxx ...
X * pattern:    fo`091ob`093a`091rz`093 compile:    CHR f CHR o CCL 2 o b CHR
V a CCL bitset
X * END matches:    fobar fooar fobaz fooaz
X * pattern:    foo\\+ compile:    CHR f CHR o CHR o CHR \ CLO CHR \ END END
X * matches:    foo\ foo\\ foo\\\  ...
X * pattern:    \(foo\)`0911-3`093\1    (same as foo`0911-3`093foo) compile:
V    BOT 1 CHR f
X * CHR o CHR o EOT 1 CCL bitset REF 1 END matches:    foo1foo foo2foo foo3fo
Vo
X * pattern:    \(fo.*\)-\1 compile:    BOT 1 CHR f CHR o CLO ANY END EOT 1 C
VHR -
X * REF 1 END matches:    foo-foo fo-fo fob-fob foobar-foobar ...
X *
X */
X#define MAXDFA  1024
X#define MAXTAG  10
X#define OKP     1
X#define NOP     0
X#define CHR     1
X#define ANY     2
X#define CCL     3
X#define NCL     4
X#define BOL     5
X#define EOL     6
X#define BOT     7
X#define EOT     8
X#define BOW    9
X#define EOW    10
X#define REF     11
X#define CLO     12
X#define END     0
X/* * The following defines are not meant to be changeable. They are for
X * readibility only. */
X#define MAXCHR    128
X#define CHRBIT    8
X#define BITBLK    MAXCHR/CHRBIT
X#define BLKIND    0170
X#define BITIND    07
X#define ASCIIB    0177
Xtypedef /* unsigned */ char CHAR;
Xnoshare static int tagstk`091MAXTAG`093;      /* subpat tag stack.. */
Xnoshare static CHAR dfa`091MAXDFA`093;/* automaton..       */
Xnoshare static int sta = NOP;   /* status of lastpat */
Xnoshare static CHAR bittab`091BITBLK`093;     /* bit table for CCL */
Xnoshare static void
Xnoshare chset(c)
Xregister CHAR   c;
X`123
X        bittab`091((c) & BLKIND) >> 3`093 `124= 1 << ((c) & BITIND);
X`125
X    `032
X#define badpat(x)    return(*dfa = END, x)
X#define store(x)    *mp++ = x
Xchar           *re_comp(pat)
Xchar           *pat;
X`123
X        register char  *p;      /* pattern pointer   */
X        register CHAR  *mp = dfa;       /* dfa pointer       */
X        register CHAR  *lp;     /* saved pointer..   */
X        register CHAR  *sp = dfa;       /* another one..     */
X    `032
X        register int    tagi = 0;       /* tag stack index   */
X        register int    tagc = 1;       /* actual tag count  */
X    `032
X        register int    n;
X        int             c1, c2;
X    `032
X        if (!pat `124`124 !*pat)
X                if (sta)
X                        return (0);
X                else
X                        badpat("No previous regular expression");
X        sta = NOP;
X        for (p = pat; *p; p++) `123
X                lp = mp;
X                switch (*p) `123
X                case '.':       /* match any char..  */
X                        store(ANY);
X                        break;
X                case '`094':       /* match beginning.. */
X                        if (p == pat)
X                                store(BOL);
X                        else `123
X                                store(CHR);
X                                store(*p);
X                        `125
X                        break;
X                case '$':       /* match endofline.. */
X                        if (!*(p + 1))
X                                store(EOL);
X                        else `123
X                                store(CHR);
X                                store(*p);
X                        `125
X                        break;
X    `032
X                case '`091':       /* match char class.. */
X    `032
X                        if (*++p == '`094') `123
X                                store(NCL);
X                                p++;
X                        `125 else
X                                store(CCL);
X                        if (*p == '-')  /* real dash */
X                                chset(*p++);
X                        if (*p == '`093')  /* real brac */
+-+-+-+-+-+-+-+-  END  OF PART 3 +-+-+-+-+-+-+-+-

