Path: utzoo!mnetor!uunet!lll-winken!lll-tis!ames!mailrus!umix!umich!mibte!gamma!pyuxp!lcuxb!lcuxa!mike2 From: mike2@lcuxa.UUCP (M S Slomin) Newsgroups: comp.binaries.ibm.pc Subject: Less for DOS (source 3 of 3) Message-ID: <200@lcuxa.UUCP> Date: 22 Apr 88 18:21:17 GMT Organization: Bell Communications Research Lines: 2137 Keywords: Less ---------------------------Part 3 of 3------------------------- #! /bin/sh # This is a shell archive, meaning: # 1. Remove everything above the #! /bin/sh line. # 2. Save the resulting text in a file # 3. Execute the file with /bin/sh (not csh) to create the files: # # readme # regerror.c # regexp.c # regexp.h # regmagic.h # scrn.c # scrn.h # signal.c # # Created on 'date' # if test -f 'readme' then echo shar: will not over-write existing file "'readme'" else echo extracting "'readme'" sed 's/^X//' >readme <<'SHAR_EOF' XPort of less to msdos: X XLess is a program similar to the Unix more command but is much more Xuseful. Read less.man for a good description of less and what it can Xdo for you. X XA. Dick Keily's original porting information for MSC 4.0: X XThe files included here will result in a full version of less Xfor use on msdos. This version of less has been tested on all the pc Xsystems that I could get my hands on. This includes monochrome, graphics, X(that includes systems with graphics cards and mono monitors), and color Xgraphics. X XThe following must be done to have less.exe work in its full glory: X X 1. Nothing if you don't want color when using a color monitor. X To get the color use the set command such as: X X set less=C (Case sensitive; c is another option) X X Do this prior to calling less. A command line option X less -C will also get you color. X X NOTE: Only use the color option when using a color monitor. X All other configurations need no special action. X X There are other less settings that can be used using the X set command. Read less.man. The one I use is less=mC on X an AT with enhanced monitor and ega card. X X 2. Less also has a v command that lets you can an editor from X within less to edit the file that you are viewing at the X time. The default is memacs which was taken from the Unix X mod.sources. If you don't have it use the dos set command X as follows to let less know which it is: X X set editor=your_editor X X 4. It is best to include the set commands in your autoexec.bat X which will be executed when you boot up your system. X X 5. Less is a very useful utility. Read less.man and when in X less the h command will put a description of the commands X on the screen for you. X X 6. This version of less is named less13.exe for distribution. X It replaces and other version that you have obtained from X my posting of the executable. Accept no substitutes. When X I get the time I will incorporate the changes to get up X the distributed Unix version 61. If you post this to any X bulletin board name any files associated with it with the X version 13.(referring to the MSDOS control). X X [N.B. No longer correct. This version is X somewhere between version 61 and 73 in its X capabilities.] X X 7. Less version 1.3 uses the system function but looks to see X if you are using the swchar program that allows you to use X the / rather than the \ character. The swchar state is changed X before the system call if you are and then resets it so that X it all becomes transparent to the user. X X [N.B. This is still correct.] X X 8. The source code for less is being posted to Net.sources. X It is all ifdef'd so that it should compile on Unix systems X also as is. X X [N.B. Probably not anymore. The ctrlbrk() X function will fail on Unix.] X X 9. Version 1.3 corrects the following: X The latest known to me fixes have been incorporated X in the regexpression routines written by Henry X Spencer and posted on the Unix news net. X X Dick Keily X Eastman Kodak Company X work: (716)477-1001 X unix: ...!seismo!rochester!kodak!keily X--------------------------------------------------------------------------- X--------------------------------------------------------------------------- X XB. Revised port to TurboC: X X 1. The port now incorporates boldface and underline (useful X for viewing documents created with nroff -man). I've X chosen the monochrome attributes for these, 0x01 and 0xf0, X and for CGA color, 0x06 (yellow) and 0xf0 (bright white). X If you wish to use others, revise the SCRN.H and/or SCRN.C X file(s) appropriately. X X 2. This will compile in the "tiny" model, and the resulting X file can be converted to a '.com' file for loading and X execution speed. An appropriate 'LESS.PRJ' file is X included; be certain to define DOSPORT in 'Options/Compiler' X (interactive mode). X X 3. A bug was fixed in the 'v' command (escape X to the editor): on return to less, the original unmodified X file in memory was displayed, not the edited one. This X is worked around in command.c by causing an 'E\n' command X to be executed on return. 'E' (Examine) loads in a new X file, and if no filename is given it loads in the previous X file. (Indeed, this is useful if 'E' is used normally. X After examining a different file, you can return to the X previous one by invoking 'E' with no file name.) X X 4. A new command, 'L', is implemented. 'L' gives X all of the information that '^G' and '=' give (i.e., X file name, number of bytes, approximate percentage into X the file) and in addition gives the number of the first X line appearing on the screen. This information is useful X if you wish to edit the file subsequently with a line- X oriented editor (e.g., vi, EDLIN, etc.); you know what X line to jump to. Unfortunately, it is a bit slow because X long ints are used in the calculation -- but a file might X exceed 65,000 lines!. X X 5. Sorry, I've not bothered to maintain downward compatibility X with Mr. Keily's MSC 4.0 port. I tried it both ways, and the X TurboC one is smaller and faster. If you want to do it with X MSC 4.0: (1) replace the ctrlbrk() command with an appropriate X signal() and interrupt handler; (2) compile it in the small X model; and (3) link with a /stack:4096 flag, linking in the X ssetargv.obj (small model) object file supplied by Microsoft X instead of the included setargv.c file. X X 6. If you haven't updated to TurboC 1.5, read the comments in X SETARGV.C. The variables _argc and _argv must be changed X throughout that file to __argc and __argv to work properly X in version 1.0. In any event, the SETARGV function is X needed only for DOS wildcard expansion, which is useful if X you want to specify multiple files for viewing with wildcards X and flip back and forth among them with 'N' and 'P'. If X you don't need the wildcard capability, omit SETARGV. X X 7. The public-domain REGEXP.C file supplied by Dick Keily X implements full regular expression matching a la X 'egrep' (i.e., using the '+' for one or more matches and X the '|' for disjunctive matches) in addition to the more X limited 'ed'/'sed' pattern match metacharacters. This is X useful, and better than classical Unix REGEXP. X X Mike Slomin X !bellcore!lcuxa!mike2 X X X SHAR_EOF if test 6263 -ne "`wc -c < 'readme'`" then echo shar: error transmitting "'readme'" '(should have been 6263 characters)' fi fi if test -f 'regerror.c' then echo shar: will not over-write existing file "'regerror.c'" else echo extracting "'regerror.c'" sed 's/^X//' >regerror.c <<'SHAR_EOF' X#include X Xvoid Xregerror(s) Xchar *s; X{ X#ifndef DOSPORT X#ifdef ERRAVAIL X error("regexp: %s", s); X#else X fprintf(stderr, "regexp(3): %s", s); X exit(1); X#endif X /* NOTREACHED */ X#endif /* ifdef'd out for less's sake when reporting error inside less */ X} SHAR_EOF if test 260 -ne "`wc -c < 'regerror.c'`" then echo shar: error transmitting "'regerror.c'" '(should have been 260 characters)' fi fi if test -f 'regexp.c' then echo shar: will not over-write existing file "'regexp.c'" else echo extracting "'regexp.c'" sed 's/^X//' >regexp.c <<'SHAR_EOF' X/* X * regcomp and regexec -- regsub and regerror are elsewhere X * X * Copyright (c) 1986 by University of Toronto. X * Written by Henry Spencer. Not derived from licensed software. X * X * Permission is granted to anyone to use this software for any X * purpose on any computer system, and to redistribute it freely, X * subject to the following restrictions: X * X * 1. The author is not responsible for the consequences of use of X * this software, no matter how awful, even if they arise X * from defects in it. X * X * 2. The origin of this software must not be misrepresented, either X * by explicit claim or by omission. X * X * 3. Altered versions must be plainly marked as such, and must not X * be misrepresented as being the original software. X * X * Beware that some of this code is subtly aware of the way operator X * precedence is structured in regular expressions. Serious changes in X * regular-expression syntax might require a total rethink. X */ X#include X#include "regexp.h" X#include "regmagic.h" X X/* X * The "internal use only" fields in regexp.h are present to pass info from X * compile to execute that permits the execute phase to run lots faster on X * simple cases. They are: X * X * regstart char that must begin a match; '\0' if none obvious X * reganch is the match anchored (at beginning-of-line only)? X * regmust string (pointer into program) that match must include, or NULL X * regmlen length of regmust string X * X * Regstart and reganch permit very fast decisions on suitable starting points X * for a match, cutting down the work a lot. Regmust permits fast rejection X * of lines that cannot possibly match. The regmust tests are costly enough X * that regcomp() supplies a regmust only if the r.e. contains something X * potentially expensive (at present, the only such thing detected is * or + X * at the start of the r.e., which can involve a lot of backup). Regmlen is X * supplied because the test in regexec() needs it and regcomp() is computing X * it anyway. X */ X X/* X * Structure for regexp "program". This is essentially a linear encoding X * of a nondeterministic finite-state machine (aka syntax charts or X * "railroad normal form" in parsing technology). Each node is an opcode X * plus a "next" pointer, possibly plus an operand. "Next" pointers of X * all nodes except BRANCH implement concatenation; a "next" pointer with X * a BRANCH on both ends of it is connecting two alternatives. (Here we X * have one of the subtle syntax dependencies: an individual BRANCH (as X * opposed to a collection of them) is never concatenated with anything X * because of operator precedence.) The operand of some types of node is X * a literal string; for others, it is a node leading into a sub-FSM. In X * particular, the operand of a BRANCH node is the first node of the branch. X * (NB this is *not* a tree structure: the tail of the branch connects X * to the thing following the set of BRANCHes.) The opcodes are: X */ X X/* definition number opnd? meaning */ X#define END 0 /* no End of program. */ X#define BOL 1 /* no Match "" at beginning of line. */ X#define EOL 2 /* no Match "" at end of line. */ X#define ANY 3 /* no Match any one character. */ X#define ANYOF 4 /* str Match any character in this string. */ X#define ANYBUT 5 /* str Match any character not in this string. */ X#define BRANCH 6 /* node Match this alternative, or the next... */ X#define BACK 7 /* no Match "", "next" ptr points backward. */ X#define EXACTLY 8 /* str Match this string. */ X#define NOTHING 9 /* no Match empty string. */ X#define STAR 10 /* node Match this (simple) thing 0 or more times. */ X#define PLUS 11 /* node Match this (simple) thing 1 or more times. */ X#define OPEN 20 /* no Mark this point in input as start of #n. */ X /* OPEN+1 is number 1, etc. */ X#define CLOSE 30 /* no Analogous to OPEN. */ X X/* X * Opcode notes: X * X * BRANCH The set of branches constituting a single choice are hooked X * together with their "next" pointers, since precedence prevents X * anything being concatenated to any individual branch. The X * "next" pointer of the last BRANCH in a choice points to the X * thing following the whole choice. This is also where the X * final "next" pointer of each individual branch points; each X * branch starts with the operand node of a BRANCH node. X * X * BACK Normal "next" pointers all implicitly point forward; BACK X * exists to make loop structures possible. X * X * STAR,PLUS '?', and complex '*' and '+', are implemented as circular X * BRANCH structures using BACK. Simple cases (one character X * per match) are implemented with STAR and PLUS for speed X * and to minimize recursive plunges. X * X * OPEN,CLOSE ...are numbered at compile time. X */ X X/* X * A node is one char of opcode followed by two chars of "next" pointer. X * "Next" pointers are stored as two 8-bit pieces, high order first. The X * value is a positive offset from the opcode of the node containing it. X * An operand, if any, simply follows the node. (Note that much of the X * code generation knows about this implicit relationship.) X * X * Using two bytes for the "next" pointer is vast overkill for most things, X * but allows patterns to get big without disasters. X */ X#define OP(p) (*(p)) X#define NEXT(p) (((*((p)+1)&0377)<<8) + *((p)+2)&0377) X#define OPERAND(p) ((p) + 3) X X/* X * See regmagic.h for one further detail of program structure. X */ X X X/* X * Utility definitions. X */ X#ifndef CHARBITS X#define UCHARAT(p) ((int)*(unsigned char *)(p)) X#else X#define UCHARAT(p) ((int)*(p)&CHARBITS) X#endif X X#define FAIL(m) { regerror(m); return(NULL); } X#define ISMULT(c) ((c) == '*' || (c) == '+' || (c) == '?') X#define META "^$.[()|?+*\\" X X/* X * Flags to be passed up and down. X */ X#define HASWIDTH 01 /* Known never to match null string. */ X#define SIMPLE 02 /* Simple enough to be STAR/PLUS operand. */ X#define SPSTART 04 /* Starts with * or +. */ X#define WORST 0 /* Worst case. */ X X/* X * Global work variables for regcomp(). X */ Xstatic char *regparse; /* Input-scan pointer. */ Xstatic int regnpar; /* () count. */ Xstatic char regdummy; Xstatic char *regcode; /* Code-emit pointer; ®dummy = don't. */ Xstatic long regsize; /* Code size. */ X X/* X * Forward declarations for regcomp()'s friends. X */ X#ifndef STATIC X#define STATIC static X#endif XSTATIC char *reg(); XSTATIC char *regbranch(); XSTATIC char *regpiece(); XSTATIC char *regatom(); XSTATIC char *regnode(); XSTATIC char *regnext(); XSTATIC void regc(); XSTATIC void reginsert(); XSTATIC void regtail(); XSTATIC void regoptail(); X#ifdef STRCSPN XSTATIC int strcspn(); X#endif X X/* X - regcomp - compile a regular expression into internal code X * X * We can't allocate space until we know how big the compiled form will be, X * but we can't compile it (and thus know how big it is) until we've got a X * place to put the code. So we cheat: we compile it twice, once with code X * generation turned off and size counting turned on, and once "for real". X * This also means that we don't allocate space until we are sure that the X * thing really will compile successfully, and we never have to move the X * code and thus invalidate pointers into it. (Note that it has to be in X * one piece because free() must be able to free it all.) X * X * Beware that the optimization-preparation code in here knows about some X * of the structure of the compiled regexp. X */ Xregexp * Xregcomp(exp) Xchar *exp; X{ X register regexp *r; X register char *scan; X register char *longest; X register int len; X int flags; X extern char *malloc(); X X if (exp == NULL) X FAIL("NULL argument"); X X /* First pass: determine size, legality. */ X regparse = exp; X regnpar = 1; X regsize = 0L; X regcode = ®dummy; X regc(MAGIC); X if (reg(0, &flags) == NULL) X return(NULL); X X /* Small enough for pointer-storage convention? */ X if (regsize >= 32767L) /* Probably could be 65535L. */ X FAIL("regexp too big"); X X /* Allocate space. */ X r = (regexp *)malloc(sizeof(regexp) + (unsigned)regsize); X if (r == NULL) X FAIL("out of space"); X X /* Second pass: emit code. */ X regparse = exp; X regnpar = 1; X regcode = r->program; X regc(MAGIC); X if (reg(0, &flags) == NULL) X return(NULL); X X /* Dig out information for optimizations. */ X r->regstart = '\0'; /* Worst-case defaults. */ X r->reganch = 0; X r->regmust = NULL; X r->regmlen = 0; X scan = r->program+1; /* First BRANCH. */ X if (OP(regnext(scan)) == END) { /* Only one top-level choice. */ X scan = OPERAND(scan); X X /* Starting-point info. */ X if (OP(scan) == EXACTLY) X r->regstart = *OPERAND(scan); X else if (OP(scan) == BOL) X r->reganch++; X X /* X * If there's something expensive in the r.e., find the X * longest literal string that must appear and make it the X * regmust. Resolve ties in favor of later strings, since X * the regstart check works with the beginning of the r.e. X * and avoiding duplication strengthens checking. Not a X * strong reason, but sufficient in the absence of others. X */ X if (flags&SPSTART) { X longest = NULL; X len = 0; X for (; scan != NULL; scan = regnext(scan)) X if (OP(scan) == EXACTLY && strlen(OPERAND(scan)) >= len) { X longest = OPERAND(scan); X len = strlen(OPERAND(scan)); X } X r->regmust = longest; X r->regmlen = len; X } X } X X return(r); X} X X/* X - reg - regular expression, i.e. main body or parenthesized thing X * X * Caller must absorb opening parenthesis. X * X * Combining parenthesis handling with the base level of regular expression X * is a trifle forced, but the need to tie the tails of the branches to what X * follows makes it hard to avoid. X */ Xstatic char * Xreg(paren, flagp) Xint paren; /* Parenthesized? */ Xint *flagp; X{ X register char *ret; X register char *br; X register char *ender; X register int parno; X int flags; X X *flagp = HASWIDTH; /* Tentatively. */ X X /* Make an OPEN node, if parenthesized. */ X if (paren) { X if (regnpar >= NSUBEXP) X FAIL("too many ()"); X parno = regnpar; X regnpar++; X ret = regnode(OPEN+parno); X } else X ret = NULL; X X /* Pick up the branches, linking them together. */ X br = regbranch(&flags); X if (br == NULL) X return(NULL); X if (ret != NULL) X regtail(ret, br); /* OPEN -> first. */ X else X ret = br; X if (!(flags&HASWIDTH)) X *flagp &= ~HASWIDTH; X *flagp |= flags&SPSTART; X while (*regparse == '|') { X regparse++; X br = regbranch(&flags); X if (br == NULL) X return(NULL); X regtail(ret, br); /* BRANCH -> BRANCH. */ X if (!(flags&HASWIDTH)) X *flagp &= ~HASWIDTH; X *flagp |= flags&SPSTART; X } X X /* Make a closing node, and hook it on the end. */ X ender = regnode((paren) ? CLOSE+parno : END); X regtail(ret, ender); X X /* Hook the tails of the branches to the closing node. */ X for (br = ret; br != NULL; br = regnext(br)) X regoptail(br, ender); X X /* Check for proper termination. */ X if (paren && *regparse++ != ')') { X FAIL("unmatched ()"); X } else if (!paren && *regparse != '\0') { X if (*regparse == ')') { X FAIL("unmatched ()"); X } else X FAIL("junk on end"); /* "Can't happen". */ X /* NOTREACHED */ X } X X return(ret); X} X X/* X - regbranch - one alternative of an | operator X * X * Implements the concatenation operator. X */ Xstatic char * Xregbranch(flagp) Xint *flagp; X{ X register char *ret; X register char *chain; X register char *latest; X int flags; X X *flagp = WORST; /* Tentatively. */ X X ret = regnode(BRANCH); X chain = NULL; X while (*regparse != '\0' && *regparse != '|' && *regparse != ')') { X latest = regpiece(&flags); X if (latest == NULL) X return(NULL); X *flagp |= flags&HASWIDTH; X if (chain == NULL) /* First piece. */ X *flagp |= flags&SPSTART; X else X regtail(chain, latest); X chain = latest; X } X if (chain == NULL) /* Loop ran zero times. */ X (void) regnode(NOTHING); X X return(ret); X} X X/* X - regpiece - something followed by possible [*+?] X * X * Note that the branching code sequences used for ? and the general cases X * of * and + are somewhat optimized: they use the same NOTHING node as X * both the endmarker for their branch list and the body of the last branch. X * It might seem that this node could be dispensed with entirely, but the X * endmarker role is not redundant. X */ Xstatic char * Xregpiece(flagp) Xint *flagp; X{ X register char *ret; X register char op; X register char *next; X int flags; X X ret = regatom(&flags); X if (ret == NULL) X return(NULL); X X op = *regparse; X if (!ISMULT(op)) { X *flagp = flags; X return(ret); X } X X if (!(flags&HASWIDTH) && op != '?') X FAIL("*+ operand could be empty"); X *flagp = (op != '+') ? (WORST|SPSTART) : (WORST|HASWIDTH); X X if (op == '*' && (flags&SIMPLE)) X reginsert(STAR, ret); X else if (op == '*') { X /* Emit x* as (x&|), where & means "self". */ X reginsert(BRANCH, ret); /* Either x */ X regoptail(ret, regnode(BACK)); /* and loop */ X regoptail(ret, ret); /* back */ X regtail(ret, regnode(BRANCH)); /* or */ X regtail(ret, regnode(NOTHING)); /* null. */ X } else if (op == '+' && (flags&SIMPLE)) X reginsert(PLUS, ret); X else if (op == '+') { X /* Emit x+ as x(&|), where & means "self". */ X next = regnode(BRANCH); /* Either */ X regtail(ret, next); X regtail(regnode(BACK), ret); /* loop back */ X regtail(next, regnode(BRANCH)); /* or */ X regtail(ret, regnode(NOTHING)); /* null. */ X } else if (op == '?') { X /* Emit x? as (x|) */ X reginsert(BRANCH, ret); /* Either x */ X regtail(ret, regnode(BRANCH)); /* or */ X next = regnode(NOTHING); /* null. */ X regtail(ret, next); X regoptail(ret, next); X } X regparse++; X if (ISMULT(*regparse)) X FAIL("nested *?+"); X X return(ret); X} X X/* X - regatom - the lowest level X * X * Optimization: gobbles an entire sequence of ordinary characters so that X * it can turn them into a single node, which is smaller to store and X * faster to run. Backslashed characters are exceptions, each becoming a X * separate node; the code is simpler that way and it's not worth fixing. X */ Xstatic char * Xregatom(flagp) Xint *flagp; X{ X register char *ret; X int flags; X X *flagp = WORST; /* Tentatively. */ X X switch (*regparse++) { X case '^': X ret = regnode(BOL); X break; X case '$': X ret = regnode(EOL); X break; X case '.': X ret = regnode(ANY); X *flagp |= HASWIDTH|SIMPLE; X break; X case '[': { X register int class; X register int classend; X X if (*regparse == '^') { /* Complement of range. */ X ret = regnode(ANYBUT); X regparse++; X } else X ret = regnode(ANYOF); X if (*regparse == ']' || *regparse == '-') X regc(*regparse++); X while (*regparse != '\0' && *regparse != ']') { X if (*regparse == '-') { X regparse++; X if (*regparse == ']' || *regparse == '\0') X regc('-'); X else { X class = UCHARAT(regparse-2)+1; X classend = UCHARAT(regparse); X if (class > classend+1) X FAIL("invalid [] range"); X for (; class <= classend; class++) X regc(class); X regparse++; X } X } else X regc(*regparse++); X } X regc('\0'); X if (*regparse != ']') X FAIL("unmatched []"); X regparse++; X *flagp |= HASWIDTH|SIMPLE; X } X break; X case '(': X ret = reg(1, &flags); X if (ret == NULL) X return(NULL); X *flagp |= flags&(HASWIDTH|SPSTART); X break; X case '\0': X case '|': X case ')': X FAIL("internal urp"); /* Supposed to be caught earlier. */ X break; X case '?': X case '+': X case '*': X FAIL("?+* follows nothing"); X break; X case '\\': X if (*regparse == '\0') X FAIL("trailing \\"); X ret = regnode(EXACTLY); X regc(*regparse++); X regc('\0'); X *flagp |= HASWIDTH|SIMPLE; X break; X default: { X register int len; X register char ender; X X regparse--; X len = strcspn(regparse, META); X if (len <= 0) X FAIL("internal disaster"); X ender = *(regparse+len); X if (len > 1 && ISMULT(ender)) X len--; /* Back off clear of ?+* operand. */ X *flagp |= HASWIDTH; X if (len == 1) X *flagp |= SIMPLE; X ret = regnode(EXACTLY); X while (len > 0) { X regc(*regparse++); X len--; X } X regc('\0'); X } X break; X } X X return(ret); X} X X/* X - regnode - emit a node X */ Xstatic char * /* Location. */ Xregnode(op) Xchar op; X{ X register char *ret; X register char *ptr; X X ret = regcode; X if (ret == ®dummy) { X regsize += 3; X return(ret); X } X X ptr = ret; X *ptr++ = op; X *ptr++ = '\0'; /* Null "next" pointer. */ X *ptr++ = '\0'; X regcode = ptr; X X return(ret); X} X X/* X - regc - emit (if appropriate) a byte of code X */ Xstatic void Xregc(b) Xchar b; X{ X if (regcode != ®dummy) X *regcode++ = b; X else X regsize++; X} X X/* X - reginsert - insert an operator in front of already-emitted operand X * X * Means relocating the operand. X */ Xstatic void Xreginsert(op, opnd) Xchar op; Xchar *opnd; X{ X register char *src; X register char *dst; X register char *place; X X if (regcode == ®dummy) { X regsize += 3; X return; X } X X src = regcode; X regcode += 3; X dst = regcode; X while (src > opnd) X *--dst = *--src; X X place = opnd; /* Op node, where operand used to be. */ X *place++ = op; X *place++ = '\0'; X *place++ = '\0'; X} X X/* X - regtail - set the next-pointer at the end of a node chain X */ Xstatic void Xregtail(p, val) Xchar *p; Xchar *val; X{ X register char *scan; X register char *temp; X register int offset; X X if (p == ®dummy) X return; X X /* Find last node. */ X scan = p; X for (;;) { X temp = regnext(scan); X if (temp == NULL) X break; X scan = temp; X } X X if (OP(scan) == BACK) X offset = scan - val; X else X offset = val - scan; X *(scan+1) = (offset>>8)&0377; X *(scan+2) = offset&0377; X} X X/* X - regoptail - regtail on operand of first argument; nop if operandless X */ Xstatic void Xregoptail(p, val) Xchar *p; Xchar *val; X{ X /* "Operandless" and "op != BRANCH" are synonymous in practice. */ X if (p == NULL || p == ®dummy || OP(p) != BRANCH) X return; X regtail(OPERAND(p), val); X} X X/* X * regexec and friends X */ X X/* X * Global work variables for regexec(). X */ Xstatic char *reginput; /* String-input pointer. */ Xstatic char *regbol; /* Beginning of input, for ^ check. */ Xstatic char **regstartp; /* Pointer to startp array. */ Xstatic char **regendp; /* Ditto for endp. */ X X/* X * Forwards. X */ XSTATIC int regtry(); XSTATIC int regmatch(); XSTATIC int regrepeat(); X X#ifdef DEBUG Xint regnarrate = 0; Xvoid regdump(); XSTATIC char *regprop(); X#endif X X/* X - regexec - match a regexp against a string X */ Xint Xregexec(prog, string) Xregister regexp *prog; Xregister char *string; X{ X register char *s; X extern char *strchr(); X X /* Be paranoid... */ X if (prog == NULL || string == NULL) { X regerror("NULL parameter"); X return(0); X } X X /* Check validity of program. */ X if (UCHARAT(prog->program) != MAGIC) { X regerror("corrupted program"); X return(0); X } X X /* If there is a "must appear" string, look for it. */ X if (prog->regmust != NULL) { X s = string; X while ((s = strchr(s, prog->regmust[0])) != NULL) { X if (strncmp(s, prog->regmust, prog->regmlen) == 0) X break; /* Found it. */ X s++; X } X if (s == NULL) /* Not present. */ X return(0); X } X X /* Mark beginning of line for ^ . */ X regbol = string; X X /* Simplest case: anchored match need be tried only once. */ X if (prog->reganch) X return(regtry(prog, string)); X X /* Messy cases: unanchored match. */ X s = string; X if (prog->regstart != '\0') X /* We know what char it must start with. */ X while ((s = strchr(s, prog->regstart)) != NULL) { X if (regtry(prog, s)) X return(1); X s++; X } X else X /* We don't -- general case. */ X do { X if (regtry(prog, s)) X return(1); X } while (*s++ != '\0'); X X /* Failure. */ X return(0); X} X X/* X - regtry - try match at specific point X */ Xstatic int /* 0 failure, 1 success */ Xregtry(prog, string) Xregexp *prog; Xchar *string; X{ X register int i; X register char **sp; X register char **ep; X X reginput = string; X regstartp = prog->startp; X regendp = prog->endp; X X sp = prog->startp; X ep = prog->endp; X for (i = NSUBEXP; i > 0; i--) { X *sp++ = NULL; X *ep++ = NULL; X } X if (regmatch(prog->program + 1)) { X prog->startp[0] = string; X prog->endp[0] = reginput; X return(1); X } else X return(0); X} X X/* X - regmatch - main matching routine X * X * Conceptually the strategy is simple: check to see whether the current X * node matches, call self recursively to see whether the rest matches, X * and then act accordingly. In practice we make some effort to avoid X * recursion, in particular by going through "ordinary" nodes (that don't X * need to know whether the rest of the match failed) by a loop instead of X * by recursion. X */ Xstatic int /* 0 failure, 1 success */ Xregmatch(prog) Xchar *prog; X{ X register char *scan; /* Current node. */ X char *next; /* Next node. */ X extern char *strchr(); X X scan = prog; X#ifdef DEBUG X if (scan != NULL && regnarrate) X fprintf(stderr, "%s(\n", regprop(scan)); X#endif X while (scan != NULL) { X#ifdef DEBUG X if (regnarrate) X fprintf(stderr, "%s...\n", regprop(scan)); X#endif X next = regnext(scan); X X switch (OP(scan)) { X case BOL: X if (reginput != regbol) X return(0); X break; X case EOL: X if (*reginput != '\0') X return(0); X break; X case ANY: X if (*reginput == '\0') X return(0); X reginput++; X break; X case EXACTLY: { X register int len; X register char *opnd; X X opnd = OPERAND(scan); X /* Inline the first character, for speed. */ X if (*opnd != *reginput) X return(0); X len = strlen(opnd); X if (len > 1 && strncmp(opnd, reginput, len) != 0) X return(0); X reginput += len; X } X break; X case ANYOF: X if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) == NULL) X return(0); X reginput++; X break; X case ANYBUT: X if (*reginput == '\0' || strchr(OPERAND(scan), *reginput) != NULL) X return(0); X reginput++; X break; X case NOTHING: X break; X case BACK: X break; X case OPEN+1: X case OPEN+2: X case OPEN+3: X case OPEN+4: X case OPEN+5: X case OPEN+6: X case OPEN+7: X case OPEN+8: X case OPEN+9: { X register int no; X register char *save; X X no = OP(scan) - OPEN; X save = reginput; X X if (regmatch(next)) { X /* X * Don't set startp if some later X * invocation of the same parentheses X * already has. X */ X if (regstartp[no] == NULL) X regstartp[no] = save; X return(1); X } else X return(0); X } X break; X case CLOSE+1: X case CLOSE+2: X case CLOSE+3: X case CLOSE+4: X case CLOSE+5: X case CLOSE+6: X case CLOSE+7: X case CLOSE+8: X case CLOSE+9: { X register int no; X register char *save; X X no = OP(scan) - CLOSE; X save = reginput; X X if (regmatch(next)) { X /* X * Don't set endp if some later X * invocation of the same parentheses X * already has. X */ X if (regendp[no] == NULL) X regendp[no] = save; X return(1); X } else X return(0); X } X break; X case BRANCH: { X register char *save; X X if (OP(next) != BRANCH) /* No choice. */ X next = OPERAND(scan); /* Avoid recursion. */ X else { X do { X save = reginput; X if (regmatch(OPERAND(scan))) X return(1); X reginput = save; X scan = regnext(scan); X } while (scan != NULL && OP(scan) == BRANCH); X return(0); X /* NOTREACHED */ X } X } X break; X case STAR: X case PLUS: { X register char nextch; X register int no; X register char *save; X register int min; X X /* X * Lookahead to avoid useless match attempts X * when we know what character comes next. X */ X nextch = '\0'; X if (OP(next) == EXACTLY) X nextch = *OPERAND(next); X min = (OP(scan) == STAR) ? 0 : 1; X save = reginput; X no = regrepeat(OPERAND(scan)); X while (no >= min) { X /* If it could work, try it. */ X if (nextch == '\0' || *reginput == nextch) X if (regmatch(next)) X return(1); X /* Couldn't or didn't -- back up. */ X no--; X reginput = save + no; X } X return(0); X } X break; X case END: X return(1); /* Success! */ X break; X default: X regerror("memory corruption"); X return(0); X break; X } X X scan = next; X } X X /* X * We get here only if there's trouble -- normally "case END" is X * the terminating point. X */ X regerror("corrupted pointers"); X return(0); X} X X/* X - regrepeat - repeatedly match something simple, report how many X */ Xstatic int Xregrepeat(p) Xchar *p; X{ X register int count = 0; X register char *scan; X register char *opnd; X extern char * strchr(); X X scan = reginput; X opnd = OPERAND(p); X switch (OP(p)) { X case ANY: X count = strlen(scan); X scan += count; X break; X case EXACTLY: X while (*opnd == *scan) { X count++; X scan++; X } X break; X case ANYOF: X while (*scan != '\0' && strchr(opnd, *scan) != NULL) { X count++; X scan++; X } X break; X case ANYBUT: X while (*scan != '\0' && strchr(opnd, *scan) == NULL) { X count++; X scan++; X } X break; X default: /* Oh dear. Called inappropriately. */ X regerror("internal foulup"); X count = 0; /* Best compromise. */ X break; X } X reginput = scan; X X return(count); X} X X/* X - regnext - dig the "next" pointer out of a node X */ Xstatic char * Xregnext(p) Xregister char *p; X{ X register int offset; X X if (p == ®dummy) X return(NULL); X X offset = NEXT(p); X if (offset == 0) X return(NULL); X X if (OP(p) == BACK) X return(p-offset); X else X return(p+offset); X} X X#ifdef DEBUG X XSTATIC char *regprop(); X X/* X - regdump - dump a regexp onto stdout in vaguely comprehensible form X */ Xvoid Xregdump(r) Xregexp *r; X{ X register char *s; X register char op = EXACTLY; /* Arbitrary non-END op. */ X register char *next; X extern char *strchr(); X X X s = r->program + 1; X while (op != END) { /* While that wasn't END last time... */ X op = OP(s); X printf("%2d%s", s-r->program, regprop(s)); /* Where, what. */ X next = regnext(s); X if (next == NULL) /* Next ptr. */ X printf("(0)"); X else X printf("(%d)", (s-r->program)+(next-s)); X s += 3; X if (op == ANYOF || op == ANYBUT || op == EXACTLY) { X /* Literal string, where present. */ X while (*s != '\0') { X putchar(*s); X s++; X } X s++; X } X putchar('\n'); X } X X /* Header fields of interest. */ X if (r->regstart != '\0') X printf("start `%c' ", r->regstart); X if (r->reganch) X printf("anchored "); X if (r->regmust != NULL) X printf("must have \"%s\"", r->regmust); X printf("\n"); X} X X/* X - regprop - printable representation of opcode X */ Xstatic char * Xregprop(op) Xchar *op; X{ X register char *p; X static char buf[50]; X X (void) strcpy(buf, ":"); X X switch (OP(op)) { X case BOL: X p = "BOL"; X break; X case EOL: X p = "EOL"; X break; X case ANY: X p = "ANY"; X break; X case ANYOF: X p = "ANYOF"; X break; X case ANYBUT: X p = "ANYBUT"; X break; X case BRANCH: X p = "BRANCH"; X break; X case EXACTLY: X p = "EXACTLY"; X break; X case NOTHING: X p = "NOTHING"; X break; X case BACK: X p = "BACK"; X break; X case END: X p = "END"; X break; X case OPEN+1: X case OPEN+2: X case OPEN+3: X case OPEN+4: X case OPEN+5: X case OPEN+6: X case OPEN+7: X case OPEN+8: X case OPEN+9: X sprintf(buf+strlen(buf), "OPEN%d", OP(op)-OPEN); X p = NULL; X break; X case CLOSE+1: X case CLOSE+2: X case CLOSE+3: X case CLOSE+4: X case CLOSE+5: X case CLOSE+6: X case CLOSE+7: X case CLOSE+8: X case CLOSE+9: X sprintf(buf+strlen(buf), "CLOSE%d", OP(op)-CLOSE); X p = NULL; X break; X case STAR: X p = "STAR"; X break; X case PLUS: X p = "PLUS"; X break; X default: X regerror("corrupted opcode"); X break; X } X if (p != NULL) X (void) strcat(buf, p); X return(buf); X} X#endif X X/* X * The following is provided for those people who do not have strcspn() in X * their C libraries. They should get off their butts and do something X * about it; at least one public-domain implementation of those (highly X * useful) string routines has been published on Usenet. X */ X#ifdef STRCSPN X/* X * strcspn - find length of initial segment of s1 consisting entirely X * of characters not from s2 X */ X Xstatic int Xstrcspn(s1, s2) Xchar *s1; Xchar *s2; X{ X register char *scan1; X register char *scan2; X register int count; X X count = 0; X for (scan1 = s1; *scan1 != '\0'; scan1++) { X for (scan2 = s2; *scan2 != '\0';) /* ++ moved down. */ X if (*scan1 == *scan2++) X return(count); X count++; X } X return(count); X} X#endif SHAR_EOF if test 27639 -ne "`wc -c < 'regexp.c'`" then echo shar: error transmitting "'regexp.c'" '(should have been 27639 characters)' fi fi if test -f 'regexp.h' then echo shar: will not over-write existing file "'regexp.h'" else echo extracting "'regexp.h'" sed 's/^X//' >regexp.h <<'SHAR_EOF' X/* X * Definitions etc. for regexp(3) routines. X * X * Caveat: this is V8 regexp(3) [actually, a reimplementation thereof], X * not the System V one. X */ X#define NSUBEXP 10 Xtypedef struct regexp { X char *startp[NSUBEXP]; X char *endp[NSUBEXP]; X char regstart; /* Internal use only. */ X char reganch; /* Internal use only. */ X char *regmust; /* Internal use only. */ X int regmlen; /* Internal use only. */ X char program[1]; /* Unwarranted chumminess with compiler. */ X} regexp; X Xextern regexp *regcomp(); Xextern int regexec(); Xextern void regsub(); Xextern void regerror(); SHAR_EOF if test 574 -ne "`wc -c < 'regexp.h'`" then echo shar: error transmitting "'regexp.h'" '(should have been 574 characters)' fi fi if test -f 'regmagic.h' then echo shar: will not over-write existing file "'regmagic.h'" else echo extracting "'regmagic.h'" sed 's/^X//' >regmagic.h <<'SHAR_EOF' X/* X * The first byte of the regexp internal "program" is actually this magic X * number; the start node begins in the second byte. X */ X#define MAGIC 0234 SHAR_EOF if test 153 -ne "`wc -c < 'regmagic.h'`" then echo shar: error transmitting "'regmagic.h'" '(should have been 153 characters)' fi fi if test -f 'scrn.c' then echo shar: will not over-write existing file "'scrn.c'" else echo extracting "'scrn.c'" sed 's/^X//' >scrn.c <<'SHAR_EOF' X/* Scrn.c replaces screen.c that was in the net distribution. Module contains X * PC screen routines plus whatever was in screen.c that had to be kept for X * linking with the other modules at link time. X */ X X#include X#include X#include X#include "scrn.h" X X#define CNTL_H 0x08 X#define CNTL_U 0x15 X#define NL 0x0a X#define CR 0x0d X#define TAB 0x09 X#define BELL 0x07 X#define ROWS 25 X#define COLUMS 80 X X#define NOT_QUIET 0 /* Ring bell at eof and for errors */ X#define LITTLE_QUIET 1 /* Ring bell only for errors */ X#define VERY_QUIET 2 /* Never ring bell */ X Xextern int quiet; /* If VERY_QUIET, use visual bell for bell */ Xextern int scrn_in_color; /* When using color monitor */ Xint erase_char, kill_char; /* The user's erase and line-kill chars */ Xint sc_height, sc_width, se_width, ue_width, ul_width, bo_width, be_width, so_width; Xint auto_wrap, ignaw; Xvoid init(), dinit(), get_term(), home(), bell(), vbell(), add_line(); Xvoid lower_left(), clear(), clear_eol(), so_enter(), so_exit(), ul_enter(); Xvoid ul_exit(), bo_enter(), bo_exit(), backspace(), putbs(), raw_mode(); Xint ulflag = 0, boflag = 0; X Xcls() /* move cursor home and clear the screen */ X{ X union REGS REG; X int mode; X X gotoxy(0, 0); X REG.x.ax = 0x0600; X if (scrn_in_color == 1) X REG.h.bh = WHITE_ON_BLUE; X else X REG.h.bh = BW; X REG.x.cx = 0x0000; X REG.x.dx = 0x184f; X int86(0x10, ®, ®); X} X Xera_eol() X{ X union REGS REG; X int hold[4]; X int column; X X getxy(hold); X column = hold[1]; X if (scrn_in_color == 1) X REG.x.bx = WHITE_ON_BLUE; X else X REG.x.bx = BW; X REG.x.ax = 0x0900; /* ah = 10; al = null char to write */ X REG.x.cx = 80 - column; /* cx = no. of nulls to write */ X int86(0x10, ®, ®); X restorxy(hold); /* retore cursor to original position */ X return; X} X Xgotoxy(row, col) /* Position cursor at x,y on screen */ Xint row, col; X{ X union REGS REG; X X REG.h.ah = 02; X REG.h.bh = 00; X REG.h.dh = row; X REG.h.dl = col; X int86(0x10, ®, ®); X} X Xgetxy(hold) /* Get cursor coordinates */ Xint *hold; X{ X union REGS REG; X X REG.h.ah = 03; X REG.h.bh = 00; X int86(0x10, ®, ®); X hold[0] = REG.h.dh; X hold[1] = REG.h.dl; X hold[2] = REG.h.ch; X hold[3] = REG.h.cl; X} X X Xrestorxy(hold) /* Restore cursor gotten above */ Xint *hold; X{ X union REGS REG; X X gotoxy(hold[0], hold[1]); X REG.h.ah = 01; X REG.h.bh = 00; X REG.h.ch = hold[2]; X REG.h.cl = hold[3]; X int86(0x10, ®, ®); X} X Xcurs_r(n) /* move cursor right n places */ Xint n; X{ X int hold[4]; X int row, column; X X getxy(hold); X row = hold[0]; X column = hold[1]; X if (column < 0) X if (n < 0) X return(0); X if (column > 79) X if (n > 0) X return(0); X column = column + n; X gotoxy(row, column); X} X Xcurs_l(n) /* move cursor left n places */ Xint n; X{ X curs_r(-n); X} X Xscroll_up(n) Xint n; X{ X union REGS REG; X X REG.h.ah = 0x06; X if (scrn_in_color == 1) X REG.h.bh = WHITE_ON_BLUE; X else X REG.h.bh = BW; X REG.h.al = n; X REG.x.cx = 0x0000; X REG.x.dx = 256 * 24 + 79; X int86(0x10, ®, ®); X return(1); X} X Xget_mode() /* Check for Monochrome mode 7 */ X{ X union REGS REG; X X REG.h.ah = 15; X int86(0x10, ®, ®); X return(REG.h.al); X} X X X/* X * Set cursor checking for current cursor size parameters. X */ X Xset_cur() X{ X union REGS INREG, OUTREG; X X if (get_mode() == 7) X { X INREG.h.ah = 1; X INREG.h.bh = 0x00; X INREG.h.ch = 12; X INREG.h.cl = 13; X int86(0x10, &INREG, &OUTREG); X } X else X { X INREG.h.ah = 0x03; X INREG.h.bh = 0x00; X int86(0x10, &INREG, &OUTREG); X INREG.h.ah = 0x01; X INREG.h.bh = 0x00; X INREG.h.ch = OUTREG.h.ch; X INREG.h.cl = OUTREG.h.cl; X int86(0x10, &INREG, &OUTREG); X } X} X Xchr_put(c, attribute) Xint c; Xint attribute; X{ X union REGS REG; X int hold[4]; X int i, row, column; X X if (c == CR) X { X getxy(hold); X row = hold[0]; X column = 0; X gotoxy(row, column); X return(1); X } X if (c == TAB) X { X for (i = 0;i <= 7;++i) X chr_put(' ', attribute); X return(1); X } X if (c == BELL) X { X putch(7); X return(1); X } X if (c == NL) X { X getxy(hold); X row = hold[0]; X if (row >= 24) X scroll_up(1); X else X ++row; X column = 0; X gotoxy(row, column); X return(1); X } X REG.h.ah = 0x9; X REG.h.al = c; X if (ulflag || boflag) X REG.h.bl = (ulflag | boflag); X else X REG.h.bl = attribute; X REG.h.bh = 00; X REG.x.cx = 1; X int86(0x10, ®, ®); X curs_r(1); X return(REG.x.ax); X} X Xstr_put(str, attribute) Xchar *str; Xint attribute; X{ X int i; X X if (scrn_in_color == 1) X attribute = WHITE_ON_RED; X else X attribute = REV_VID; X for (i = 0;i < strlen(str);++i) X chr_put(*(str + i), attribute); X} X X X/* X * Add a blank line (called with cursor at home). X * Should scroll the display down. X */ X Xvoid Xadd_line() X{ X union REGS REG; X int hold[4]; X int row, column; X X REG.h.ah = 0x07; X if (scrn_in_color == 1) X REG.h.bh = WHITE_ON_BLUE; X else X REG.h.bh = BW; X REG.h.al = 1; X getxy(hold); X row = hold[0]; X column = hold[1]; X REG.h.ch = row; X REG.h.cl = 0; X REG.h.dh = 24; X REG.h.dl = 79; X int86(0x10, ®, ®); X} X X/* X * Below are the functions which perform all the "less terminal-specific" X * screen manipulation functions. They are taken from screen.c that was X * in the distribution of less on the news. X */ X X/* X * Initialize terminal X */ Xvoid Xinit() X{ X set_cur(); X} X X/* X * Deinitialize terminal X */ Xvoid Xdeinit() X{ X} X Xvoid Xget_term() X{ X sc_height = ROWS; X sc_width = COLUMS; X se_width = 0; X ue_width = 0; X ul_width = 0; X be_width = 0; X bo_width = 0; X so_width = 0; X auto_wrap = 0; /* chr_put doesn't autowrap */ X ignaw = 0; X /* sneak in kill and erase characters for command line editing */ X kill_char = CNTL_U; /* use ctrl-u as kill chararcter */ X erase_char = CNTL_H; /* use ctrl-h as erase character */ X} X Xvoid Xraw_mode(on) Xint on; X{ X /* left here in case there is a desire */ X /* to put terminal in raw_mode vs cooked */ X} X X/* X * Home cursor (move to upper left corner of screen). X */ X Xvoid Xhome() X{ X gotoxy(0, 0); X} X X/* X * Move cursor to lower left corner of screen. X */ Xvoid Xlower_left() X{ X gotoxy(24, 0); X} X X/* X * Ring the terminal bell. X */ Xvoid Xbell() X{ X if (quiet == VERY_QUIET) X vbell(); X else X putch(BELL); X} X X/* X * Output the "visual bell", if there is one. X */ Xvoid Xvbell() X{ X /* there is no visual bell at this time */ X return; X} X X/* X * Clear the screen. X */ Xvoid Xclear() X{ X cls(); X} X X/* X * Clear from the cursor to the end of the cursor's line. X * {{ This must not move the cursor. }} X */ Xvoid Xclear_eol() X{ X era_eol(); X} X X/* X * Begin "standout" (bold, underline, or whatever). X */ Xvoid Xso_enter() X{ X} X X/* X * End "standout". X */ Xvoid Xso_exit() X{ X} X/* X * Begin bold X*/ Xvoid Xbo_enter() X{ X boflag = BOLDFACE; X} X/* X * End bold X */ Xvoid Xbo_exit() X{ X boflag = 0; X} X X/* X * Begin "underline" (hopefully real underlining, X * otherwise whatever the terminal provides). X */ Xvoid Xul_enter() X{ X if (scrn_in_color == 1) X ulflag = COLOR_UL; X else X ulflag = UNDERLINE; X} X X/* X * End "underline". X */ Xvoid Xul_exit() X{ X ulflag = 0; X} X X/* X * Erase the character to the left of the cursor X * and move the cursor left. X */ Xvoid Xbackspace() X{ X /* X * Try to erase the previous character by overstriking with a space. X */ X curs_l(1); X putc(' '); X curs_l(1); X} X X/* X * Output a plain backspace, without erasing the previous char. X */ Xvoid Xputbs() X{ X curs_l(1); X} X SHAR_EOF if test 7306 -ne "`wc -c < 'scrn.c'`" then echo shar: error transmitting "'scrn.c'" '(should have been 7306 characters)' fi fi if test -f 'scrn.h' then echo shar: will not over-write existing file "'scrn.h'" else echo extracting "'scrn.h'" sed 's/^X//' >scrn.h <<'SHAR_EOF' X#define WHITE_ON_RED 0x47 X#define WHITE_ON_BLUE 0x17 X#define BW 0x07 X#define REV_VID 0x70 X#define BOLDFACE 0x0f X#define UNDERLINE 0x01 X#define COLOR_UL 0x06 X SHAR_EOF if test 160 -ne "`wc -c < 'scrn.h'`" then echo shar: error transmitting "'scrn.h'" '(should have been 160 characters)' fi fi if test -f 'signal.c' then echo shar: will not over-write existing file "'signal.c'" else echo extracting "'signal.c'" sed 's/^X//' >signal.c <<'SHAR_EOF' X/* X * Routines dealing with signals. X * X * A signal usually merely causes a bit to be set in the "signals" word. X * At some convenient time, the mainline code checks to see if any X * signals need processing by calling psignal(). X * An exception is made if we are reading from the keyboard when the X * signal is received. Some operating systems will simply call the X * signal handler and NOT return from the read (with EINTR). X * To handle this case, we service the interrupt directly from X * the handler if we are reading from the keyboard. X */ X X#include "less.h" X#ifdef MSDOS Xchar get_swchar(); Xvoid swchar_to_dos(); Xvoid swchar_to_unix(); X#include X#include X#endif X Xextern char *first_cmd; Xint result; Xchar sw_char; Xpublic int sigs; X X/* X * Pass the specified command to a shell to be executed. X * Like plain "system()", but handles resetting terminal modes, etc. X */ Xvoid lsystem(cmd) X char *cmd; X{ X int inp; X X /* X * Print the command which is to be executed. X */ X lower_left(); X clear_eol(); X puts("!"); X puts(cmd); X puts("\n"); X X /* X * De-initialize the terminal and take out of raw mode. X */ X#ifndef MSDOS X deinit(); X flush(); X raw_mode(0); X#endif X /* X * Pass the command to the system to be executed. X */ X#ifndef MSDOS X inp = dup(0); X close(0); X open("/dev/tty", 0); X#endif X#ifdef MSDOS X sw_char = get_swchar(); X swchar_to_dos(); X result = system(cmd); X if (result != 0) X perror("Less"); X if (sw_char == '-') X swchar_to_unix(); X#else X system(cmd); X#endif X#ifndef MSDOS X close(0); X dup(inp); X close(inp); X#endif X /* X * Reset signals, raw mode, etc. X */ X#ifndef MSDOS X init_signals(); X raw_mode(1); X init(); X#endif X} X X#ifdef MSDOS Xchar Xget_swchar() X{ X union REGS inregs; X union REGS outregs; X X inregs.h.ah = 0x37; X inregs.h.al = 0; X intdos(&inregs, &outregs); X return(outregs.h.dl); X} X X Xvoid Xswchar_to_dos() X{ X union REGS inregs; X union REGS outregs; X X inregs.h.ah = 0x37; X inregs.h.al = 0x01; X inregs.h.dl = '/'; X intdos(&inregs, &outregs); X return; X} X Xvoid Xswchar_to_unix() X{ X union REGS inregs; X union REGS outregs; X X inregs.h.ah = 0x37; X inregs.h.al = 0x01; X inregs.h.dl = '-'; X intdos(&inregs, &outregs); X return; X} X X#endif X X SHAR_EOF if test 2167 -ne "`wc -c < 'signal.c'`" then echo shar: error transmitting "'signal.c'" '(should have been 2167 characters)' fi fi # end of shell archive exit 0 --- No warranties whatsoever. Mike Slomin !bellcore!lcuxa!mike2