diff options
author | 2001-11-07 11:54:13 +0000 | |
---|---|---|
committer | 2001-11-07 11:54:13 +0000 | |
commit | 2d71417605ec71f52c2da94ea8583e27bbf18560 (patch) | |
tree | 5d438675121a0fb04d580d43d5c51357c60c0c53 | |
parent | fix signal race (diff) | |
download | wireguard-openbsd-2d71417605ec71f52c2da94ea8583e27bbf18560.tar.xz wireguard-openbsd-2d71417605ec71f52c2da94ea8583e27bbf18560.zip |
more is no more. less has been used as more for more or less most of the
time OpenBSD has existed, so there is no point in keeping this code here
anymore.
-rw-r--r-- | usr.bin/more/Makefile | 13 | ||||
-rw-r--r-- | usr.bin/more/more.1 | 383 | ||||
-rw-r--r-- | usr.bin/more/more.c | 1875 | ||||
-rw-r--r-- | usr.bin/more/more.help | 24 | ||||
-rw-r--r-- | usr.bin/more/pathnames.h | 39 |
5 files changed, 0 insertions, 2334 deletions
diff --git a/usr.bin/more/Makefile b/usr.bin/more/Makefile deleted file mode 100644 index 1b4f23429f8..00000000000 --- a/usr.bin/more/Makefile +++ /dev/null @@ -1,13 +0,0 @@ -# $OpenBSD: Makefile,v 1.9 1998/07/24 00:10:55 millert Exp $ - -PROG= more -DPADD= ${LIBCURSES} ${LIBCOMPAT} -LDADD= -lcurses -lcompat -MLINKS= more.1 page.1 -LINKS= ${BINDIR}/more ${BINDIR}/page - -beforeinstall: - ${INSTALL} ${INSTALL_COPY} -o ${BINOWN} -g ${BINGRP} -m 444 \ - ${.CURDIR}/more.help ${DESTDIR}/usr/share/misc/more.help - -.include <bsd.prog.mk> diff --git a/usr.bin/more/more.1 b/usr.bin/more/more.1 deleted file mode 100644 index 61bc7f1b7bb..00000000000 --- a/usr.bin/more/more.1 +++ /dev/null @@ -1,383 +0,0 @@ -.\" $OpenBSD: more.1,v 1.9 2000/12/17 21:33:01 millert Exp $ -.\" Copyright (c) 1980 The Regents of the University of California. -.\" All rights reserved. -.\" -.\" Redistribution and use in source and binary forms, with or without -.\" modification, are permitted provided that the following conditions -.\" are met: -.\" 1. Redistributions of source code must retain the above copyright -.\" notice, this list of conditions and the following disclaimer. -.\" 2. Redistributions in binary form must reproduce the above copyright -.\" notice, this list of conditions and the following disclaimer in the -.\" documentation and/or other materials provided with the distribution. -.\" 3. All advertising materials mentioning features or use of this software -.\" must display the following acknowledgement: -.\" This product includes software developed by the University of -.\" California, Berkeley and its contributors. -.\" 4. Neither the name of the University nor the names of its contributors -.\" may be used to endorse or promote products derived from this software -.\" without specific prior written permission. -.\" -.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND -.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE -.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE -.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE -.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL -.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS -.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) -.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT -.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY -.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF -.\" SUCH DAMAGE. -.\" -.\" @(#)more.1 6.6 (Berkeley) 4/18/91 -.\" -.TH MORE 1 "October 14, 1996" -.UC 4 -.SH NAME -more, page \- file perusal filter for crt viewing -.SH SYNOPSIS -.B more -[ -.B \-cdflsu -] -[ -.B \-\fIn\fP -] -[ -.B +\fIlinenumber\fP -] -[ -.B +/\fIpattern\fP -] [ name ... ] -.LP -.B page -.I "more options" -.SH DESCRIPTION -.I More -is a filter which allows examination of a continuous text -one screenful at a time on a soft-copy terminal. -It normally pauses after each screenful, printing the current file name -at the bottom of the screen or --More-- if input is from a pipe. -If the user then types a carriage return, one more line is displayed. -If the user hits a space, -another screenful is displayed. Other possibilities are enumerated later. -.PP -The command line options are: -.TP -.I \-n -An integer which is the size (in lines) of the window which -.I more -will use instead of the default. -.TP -.B \-c -.I More -will draw each page by beginning at the top of the screen and erasing -each line just before it draws on it. -This avoids scrolling the screen, making it easier to read while -.I more -is writing. -This option will be ignored if the terminal does not have the ability -to clear to the end of a line. -.TP -.B \-d -.I More -will prompt the user with the message "Press -space to continue, \'q\' to quit." at the end of each screenful, -and will respond to subsequent illegal user input by -printing "Press \'h\' for instructions." instead of ringing the bell. -This is useful if -.I more -is being used as a filter in some setting, -such as a class, -where many users may be unsophisticated. -.TP -.B \-f -This causes -.I more -to count logical, rather than screen lines. -That is, long lines are not folded. -This option is recommended if -.I nroff -output is being piped through -.I ul, -since the latter may generate escape sequences. -These escape sequences contain characters which would ordinarily occupy -screen positions, but which do not print when they are sent to the -terminal as part of an escape sequence. -Thus -.I more -may think that lines are longer than they actually are, and fold -lines erroneously. -.TP -.B \-l -Do -not treat ^\&L (form feed) specially. -If this option is not given, -.I more -will pause after any line that contains a ^\&L, as if the end of a -screenful had been reached. -Also, if a file begins with a form feed, the screen will be cleared -before the file is printed. -.TP -.B \-s -Squeeze multiple blank lines from the output, producing only one blank -line. Especially helpful when viewing -.I nroff -output, this option maximizes the useful information present on the screen. -.TP -.B \-u -Normally, -.I more -will handle underlining such as produced by -.I nroff -in a manner appropriate to the particular terminal: if the terminal can -perform underlining or has a stand-out mode, -.I more -will output appropriate escape sequences to enable underlining or stand-out -mode for underlined information in the source file. The -.I \-u -option suppresses this processing. -.TP -.B +\fIlinenumber\fP -Start up at \fIlinenumber\fP. -.TP -.B +/\fIpattern\fP -Start up two lines before the line containing the -regular expression \fIpattern\fP. -.PP -If the program is invoked as -.I page, -then the screen is cleared before each screenful is printed (but only -if a full screenful is being printed), and -.I k -\- 1 rather -than -.I k -\- 2 lines are printed in each screenful, where -.I k -is the number of lines the terminal can display. -.PP -.I More -looks in the file -.I /usr/share/misc/termcap -to determine terminal characteristics, -and to determine the default window size. -On a terminal capable of displaying 24 lines, -the default window size is 22 lines. -.PP -.I More -looks in the environment variable -.I MORE -to pre-set any flags desired. For example, if you prefer to view files using -the -.I \-c -mode of operation, the -.I csh -command -.I "setenv MORE -c" -or the -.I sh -command sequence -.I "MORE='-c' ; export MORE" -would cause all invocations of -.I more , -including invocations by programs such as -.I man -and -.I msgs , -to use this mode. -Normally, the user will place the command sequence which sets up the -.I MORE -environment variable in the -.I .cshrc -or -.I .profile -file. -.PP -.I More -looks in the environment variable -.I EDITOR -to determine which editor the -.I v -command invokes. -If the editor specified is -.I vi -or -.I ex -it will start at the current -.I more -line number. -If no -.I EDITOR -environment variable is specified the default -.I vi -editor will be used. -.PP -If -.I more -is reading from a file, rather than a pipe, then a percentage is displayed -along with the current -.I filename -prompt. -This gives the fraction of the file (in characters, not lines) that has been -read so far. -.PP -Other sequences which may be typed when -.I more -pauses, and their effects, are as follows (\fIi\fP is an optional integer -argument, defaulting to 1) : -.PP -.IP \fIi\|\fP<space> -display -.I i -more lines, (or another screenful if no argument is given) -.PP -.IP ^D -display 11 more lines (a ``scroll''). -If -.I i -is given, then the scroll size is set to \fIi\|\fP. -.PP -.IP d -same as ^D (control-D) -.PP -.IP \fIi\|\fPz -same as typing a space except that \fIi\|\fP, if present, becomes the new -window size. -.PP -.IP \fIi\|\fPs -skip \fIi\|\fP lines and print a screenful of lines -.PP -.IP \fIi\|\fPf\ or\ \fIi\|\fP^F -skip \fIi\fP screenfuls and print a screenful of lines -.PP -.IP \fIi\|\fPb -skip back \fIi\fP screenfuls and print a screenful of lines -.PP -.IP \fIi\|\fP^B -same as b -.PP -.IP "q or Q" -Exit from -.I more. -.PP -.IP = -Display the current line number. -.PP -.IP v -Starts the editor at the current line number if editor is -.I vi -or -.I ex. -The environment variable -.I EDITOR -affects this command according to the rules outlined above. -.PP -.IP h -Help command; give a description of all the -.I more -commands. -.PP -.IP \fIi\|\fP/expr -search for the \fIi\|\fP-th occurrence of the regular expression \fIexpr.\fP -If there are less than \fIi\fP occurrences of \fIexpr\|\fP, -and the input is a file (rather than a pipe), -then the position in the file remains unchanged. -Otherwise, a screenful is displayed, starting two lines before the place -where the expression was found. -The user's erase and kill characters may be used to edit the regular -expression. -Erasing back past the first column cancels the search command. -.PP -.IP \fIi\|\fPn -search for the \fIi\|\fP-th occurrence of the last regular expression entered. -.PP -.IP \' -(single quote) Go to the point from which the last search started. -If no search has been performed in the current file, this command -goes back to the beginning of the file. -.PP -.IP !command -invoke a shell with \fIcommand\|\fP. -The characters `%' and `!' in "command" are replaced with the -current file name and the previous shell command respectively. -If there is no current file name, `%' is not expanded. -The sequences "\\%" and "\\!" are replaced by "%" and "!" respectively. -.PP -.IP \fIi\|\fP:n -skip to the \fIi\|\fP-th next file given in the command line -(skips to last file if n doesn't make sense) -.PP -.IP \fIi\|\fP:p -skip to the \fIi\|\fP-th previous file given in the command line. -If this command is given in the middle of printing out a -file, then -.I more -goes back to the beginning of the file. If \fIi\fP doesn't make sense, -.I more -skips back to the first file. -If -.I more -is not reading from a file, the bell is rung and nothing else happens. -.PP -.IP :f -display the current file name and line number. -.PP -.IP ":q or :Q" -exit from -.I more -(same as q or Q). -.PP -.IP . -(dot) repeat the previous command. -.PP -The commands take effect immediately, i.e., it is not necessary to -type a carriage return. -Up to the time when the command character itself is given, -the user may hit the line kill character to cancel the numerical -argument being formed. -In addition, the user may hit the erase character to redisplay the -filename (xx%) message. -.PP -At any time when output is being sent to the terminal, the user can -hit the quit key (normally control\-\\). -.I More -will stop sending output, and will display the usual -.I filename -prompt. -The user may then enter one of the above commands in the normal manner. -Unfortunately, some output is lost when this is done, due to the -fact that any characters waiting in the terminal's output queue -are flushed when the quit signal occurs. -.PP -The terminal is set to -.I noecho -mode by this program so that the output can be continuous. -What you type will thus not show on your terminal, except for the / and ! -commands. -.PP -If the standard output is not a teletype, then -.I more -acts just like -.I cat, -except that a header is printed before each file (if there is -more than one). -.PP -.DT -A sample usage of -.I more -in previewing -.I nroff -output would be -.PP - nroff \-ms +2 doc.n | more -s -.SH FILES -.DT -/usr/share/misc/termcap Terminal database -.br -/usr/share/misc/more.help Help file -.SH "SEE ALSO" -csh(1), man(1), msgs(1), script(1), sh(1), environ(7) -.SH BUGS -Skipping backwards is too slow on large files. diff --git a/usr.bin/more/more.c b/usr.bin/more/more.c deleted file mode 100644 index b3d4f4a3be5..00000000000 --- a/usr.bin/more/more.c +++ /dev/null @@ -1,1875 +0,0 @@ -/* $OpenBSD: more.c,v 1.14 2001/09/05 22:32:41 deraadt Exp $ */ -/*- - * Copyright (c) 1980 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - */ - -#ifndef lint -char copyright[] = -"@(#) Copyright (c) 1980 The Regents of the University of California.\n\ - All rights reserved.\n"; -#endif /* not lint */ - -#ifndef lint -static char sccsid[] = "@(#)more.c 5.28 (Berkeley) 3/1/93"; -#endif /* not lint */ - -/* -** more.c - General purpose tty output filter and file perusal program -** -** by Eric Shienbrood, UC Berkeley -** -** modified by Geoff Peck, UCB to add underlining, single spacing -** modified by John Foderaro, UCB to add -c and MORE environment variable -*/ - -#include <sys/param.h> -#include <sys/stat.h> -#include <signal.h> -#include <errno.h> -#include <fcntl.h> -#include <sgtty.h> -#include <setjmp.h> -#include <a.out.h> -#include <varargs.h> -#include <stdio.h> -#include <string.h> -#include <ctype.h> -#include "pathnames.h" - -#define Fopen(s,m) (Currline = 0,file_pos=0,fopen(s,m)) -#define Ftell(f) file_pos -#define Fseek(f,off) (file_pos=off,fseek(f,off,0)) -#define Getc(f) (++file_pos, getc(f)) -#define Ungetc(c,f) (--file_pos, ungetc(c,f)) - -#define MBIT CBREAK -#define stty(fd,argp) ioctl(fd,TIOCSETN,argp) - -#define TBUFSIZ 1024 -#define LINSIZ 256 -#define ctrl(letter) (letter & 077) -#define RUBOUT '\177' -#define ESC '\033' -#define QUIT '\034' - -struct sgttyb otty, savetty; -long file_pos, file_size; -int fnum, no_intty, no_tty, slow_tty; -int dum_opt, dlines; -void chgwinsz(), end_it(), onquit(), onsusp(); -int nscroll = 11; /* Number of lines scrolled by 'd' */ -int fold_opt = 1; /* Fold long lines */ -int stop_opt = 1; /* Stop after form feeds */ -int ssp_opt = 0; /* Suppress white space */ -int ul_opt = 1; /* Underline as best we can */ -int promptlen; -int Currline; /* Line we are currently at */ -int startup = 1; -int firstf = 1; -int notell = 1; -int docrterase = 0; -int docrtkill = 0; -int bad_so; /* True if overwriting does not turn off standout */ -int inwait, Pause, errors; -int within; /* true if we are within a file, - false if we are between files */ -int hard, dumb, noscroll, hardtabs, clreol, eatnl; -int catch_susp; /* We should catch the SIGTSTP signal */ -char **fnames; /* The list of file names */ -int nfiles; /* Number of files left to process */ -char *shell; /* The name of the shell to use */ -int shellp; /* A previous shell command exists */ -char ch; -jmp_buf restore; -char Line[LINSIZ]; /* Line buffer */ -int Lpp = 24; /* lines per page */ -char *Clear; /* clear screen */ -char *eraseln; /* erase line */ -char *Senter, *Sexit;/* enter and exit standout mode */ -char *ULenter, *ULexit; /* enter and exit underline mode */ -char *chUL; /* underline character */ -char *chBS; /* backspace character */ -char *Home; /* go to home */ -char *cursorm; /* cursor movement */ -char cursorhome[40]; /* contains cursor movement to home */ -char *EodClr; /* clear rest of screen */ -char *tgetstr(); -int Mcol = 80; /* number of columns */ -int Wrap = 1; /* set if automargins */ -int soglitch; /* terminal has standout mode glitch */ -int ulglitch; /* terminal has underline mode glitch */ -int pstate = 0; /* current UL state */ -char *getenv(); -struct { - long chrctr, line; -} context, screen_start; -extern char PC; /* pad character */ -extern short ospeed; - - -main(argc, argv) -int argc; -char *argv[]; -{ - register FILE *f; - register char *s; - register char *p; - register char ch; - register int left; - int prnames = 0; - int initopt = 0; - int srchopt = 0; - int clearit = 0; - int initline; - char initbuf[80]; - FILE *checkf(); - - nfiles = argc; - fnames = argv; - initterm (); - nscroll = Lpp/2 - 1; - if (nscroll <= 0) - nscroll = 1; - if(s = getenv("MORE")) argscan(s); - while (--nfiles > 0) { - if ((ch = (*++fnames)[0]) == '-') { - argscan(*fnames+1); - } - else if (ch == '+') { - s = *fnames; - if (*++s == '/') { - srchopt++; - for (++s, p = initbuf; p < initbuf + 79 && *s != '\0';) - *p++ = *s++; - *p = '\0'; - } - else { - initopt++; - for (initline = 0; *s != '\0'; s++) - if (isdigit (*s)) - initline = initline*10 + *s -'0'; - --initline; - } - } - else break; - } - /* allow clreol only if Home and eraseln and EodClr strings are - * defined, and in that case, make sure we are in noscroll mode - */ - if(clreol) - { - if((Home == NULL) || (*Home == '\0') || - (eraseln == NULL) || (*eraseln == '\0') || - (EodClr == NULL) || (*EodClr == '\0') ) - clreol = 0; - else noscroll = 1; - } - if (dlines == 0) -// dlines = Lpp - (noscroll ? 1 : 2); - dlines = Lpp - 1; /* XXX - maybe broken on dumb - terminals. */ - left = dlines; - if (nfiles > 1) - prnames++; - if (!no_intty && nfiles == 0) { - p = strrchr(argv[0], '/'); - fputs("usage: ",stderr); - fputs(p ? p + 1 : argv[0],stderr); - fputs(" [-dfln] [+linenum | +/pattern] name1 name2 ...\n",stderr); - exit(1); - } - else - f = stdin; - if (!no_tty) { - signal(SIGQUIT, onquit); - signal(SIGINT, end_it); - signal(SIGWINCH, chgwinsz); - if (signal (SIGTSTP, SIG_IGN) == SIG_DFL) { - signal(SIGTSTP, onsusp); - catch_susp++; - } - stty (fileno(stderr), &otty); - } - if (no_intty) { - if (no_tty) - copy_file (stdin); - else { - if ((ch = Getc (f)) == '\f') - doclear(); - else { - Ungetc (ch, f); - if (noscroll && (ch != EOF)) { - if (clreol) - home (); - else - doclear (); - } - } - if (srchopt) - { - search (initbuf, stdin, 1); - if (noscroll) - left--; - } - else if (initopt) - skiplns (initline, stdin); - screen (stdin, left); - } - no_intty = 0; - prnames++; - firstf = 0; - } - - while (fnum < nfiles) { - if ((f = checkf (fnames[fnum], &clearit)) != NULL) { - context.line = context.chrctr = 0; - Currline = 0; - if (firstf) setjmp (restore); - if (firstf) { - firstf = 0; - if (srchopt) - { - search (initbuf, f, 1); - if (noscroll) - left--; - } - else if (initopt) - skiplns (initline, f); - } - else if (fnum < nfiles && !no_tty) { - setjmp (restore); - left = command (fnames[fnum], f); - } - if (left != 0) { - if ((noscroll || clearit) && (file_size != LONG_MAX)) - if (clreol) - home (); - else - doclear (); - if (prnames) { - if (bad_so) - erase (0); - if (clreol) - cleareol (); - pr("::::::::::::::"); - if (promptlen > 14) - erase (14); - prtf ("\n"); - if(clreol) cleareol(); - prtf("%s\n", fnames[fnum]); - if(clreol) cleareol(); - prtf("::::::::::::::\n"); - if (left > Lpp - 4) - left = Lpp - 4; - } - if (no_tty) - copy_file (f); - else { - within++; - screen(f, left); - within = 0; - } - } - setjmp (restore); - fflush(stdout); - fclose(f); - screen_start.line = screen_start.chrctr = 0L; - context.line = context.chrctr = 0L; - } - fnum++; - firstf = 0; - } - reset_tty (); - exit(0); -} - -argscan(s) -char *s; -{ - int seen_num = 0; - - while (*s != '\0') { - switch (*s) { - case '0': case '1': case '2': - case '3': case '4': case '5': - case '6': case '7': case '8': - case '9': - if (!seen_num) { - dlines = 0; - seen_num = 1; - } - dlines = dlines*10 + *s - '0'; - break; - case 'd': - dum_opt = 1; - break; - case 'l': - stop_opt = 0; - break; - case 'f': - fold_opt = 0; - break; - case 'p': - noscroll++; - break; - case 'c': - clreol++; - break; - case 's': - ssp_opt = 1; - break; - case 'u': - ul_opt = 0; - break; - } - s++; - } -} - - -/* -** Check whether the file named by fs is an ASCII file which the user may -** access. If it is, return the opened file. Otherwise return NULL. -*/ - -FILE * -checkf (fs, clearfirst) - register char *fs; - int *clearfirst; -{ - struct stat stbuf; - register FILE *f; - char c; - - if (stat (fs, &stbuf) == -1) { - (void)fflush(stdout); - if (clreol) - cleareol (); - perror(fs); - return(NULL); - } - if ((stbuf.st_mode & S_IFMT) == S_IFDIR) { - prtf("\n*** %s: directory ***\n\n", fs); - return(NULL); - } - if ((f = Fopen(fs, "r")) == NULL) { - (void)fflush(stdout); - perror(fs); - return(NULL); - } - if (magic(f, fs)) - return(NULL); - c = Getc(f); - *clearfirst = c == '\f'; - Ungetc (c, f); - if ((file_size = stbuf.st_size) == 0) - file_size = LONG_MAX; - return(f); -} - -/* - * magic -- - * check for file magic numbers. This code would best be shared with - * the file(1) program or, perhaps, more should not try and be so smart? - */ -magic(f, fs) - FILE *f; - char *fs; -{ - struct exec ex; - - if (fread(&ex, sizeof(ex), 1, f) == 1) - switch(N_GETMAGIC(ex)) { - case OMAGIC: - case NMAGIC: - case ZMAGIC: - case 0405: - case 0411: - case 0177545: - prtf("\n******** %s: Not a text file ********\n\n", fs); - (void)fclose(f); - return(1); - } - (void)fseek(f, 0L, SEEK_SET); /* rewind() not necessary */ - return(0); -} - -/* -** A real function, for the tputs routine in termlib -*/ - -putch (ch) -char ch; -{ - putchar (ch); -} - -/* -** Print out the contents of the file f, one screenful at a time. -*/ - -#define STOP -10 - -screen (f, num_lines) -register FILE *f; -register int num_lines; -{ - register int c; - register int nchars; - int length; /* length of current line */ - static int prev_len = 1; /* length of previous line */ - - for (;;) { - while (num_lines > 0 && !Pause) { - if ((nchars = getline (f, &length)) == EOF) - { - if (clreol) - clreos(); - return; - } - if (ssp_opt && length == 0 && prev_len == 0) - continue; - prev_len = length; - if (bad_so || (Senter && *Senter == ' ') && promptlen > 0) - erase (0); - /* must clear before drawing line since tabs on some terminals - * do not erase what they tab over. - */ - if (clreol) - cleareol (); - prbuf (Line, length); - if (nchars < promptlen) - erase (nchars); /* erase () sets promptlen to 0 */ - else promptlen = 0; - /* is this needed? - * if (clreol) - * cleareol(); /* must clear again in case we wrapped * - */ - if (nchars < Mcol || !fold_opt) - prbuf("\n", 1); /* will turn off UL if necessary */ - if (nchars == STOP) - break; - num_lines--; - } - if (pstate) { - tputs(ULexit, 1, putch); - pstate = 0; - } - fflush(stdout); - if ((c = Getc(f)) == EOF) - { - if (clreol) - clreos (); - return; - } - - if (Pause && clreol) - clreos (); - Ungetc (c, f); - setjmp (restore); - Pause = 0; startup = 0; - if ((num_lines = command (NULL, f)) == 0) - return; - if (hard && promptlen > 0) - erase (0); - if (noscroll && num_lines >= dlines) - { - if (clreol) - home(); - else - doclear (); - } - screen_start.line = Currline; - screen_start.chrctr = Ftell (f); - } -} - -/* -** Come here if a quit signal is received -*/ - -void -onquit() -{ - signal(SIGQUIT, SIG_IGN); - if (!inwait) { - putchar ('\n'); - if (!startup) { - signal(SIGQUIT, onquit); - longjmp (restore, 1); - } - else - Pause++; - } - else if (!dum_opt && notell) { - write (2, "[Use q or Q to quit]", 20); - promptlen += 20; - notell = 0; - } - signal(SIGQUIT, onquit); -} - -/* -** Come here if a signal for a window size change is received -*/ - -void -chgwinsz() -{ - struct winsize win; - - (void) signal(SIGWINCH, SIG_IGN); - if (ioctl(fileno(stdout), TIOCGWINSZ, &win) != -1) { - if (win.ws_row != 0) { - Lpp = win.ws_row; - nscroll = Lpp/2 - 1; - if (nscroll <= 0) - nscroll = 1; - dlines = Lpp - (noscroll ? 1 : 2); - } - if (win.ws_col != 0) - Mcol = win.ws_col; - } - (void) signal(SIGWINCH, chgwinsz); -} - -/* -** Clean up terminal state and exit. Also come here if interrupt signal received -*/ - -void -end_it () -{ - - reset_tty (); - if (clreol) { - putchar ('\r'); - clreos (); - fflush (stdout); - } - else if (!clreol && (promptlen > 0)) { - kill_line (); - fflush (stdout); - } - else - write (2, "\n", 1); - _exit(0); -} - -copy_file(f) -register FILE *f; -{ - register int c; - - while ((c = getc(f)) != EOF) - putchar(c); -} - -/* Simplified printf function */ - -prtf (fmt, va_alist) -register char *fmt; -va_dcl -{ - va_list ap; - register char ch; - register int ccount; - - ccount = 0; - va_start(ap); - while (*fmt) { - while ((ch = *fmt++) != '%') { - if (ch == '\0') - return (ccount); - ccount++; - putchar (ch); - } - switch (*fmt++) { - case 'd': - ccount += printd (va_arg(ap, int)); - break; - case 's': - ccount += pr (va_arg(ap, char *)); - break; - case '%': - ccount++; - putchar ('%'); - break; - case '0': - return (ccount); - default: - break; - } - } - va_end(ap); - return (ccount); - -} - -/* -** Print an integer as a string of decimal digits, -** returning the length of the print representation. -*/ - -printd (n) -int n; -{ - int a, nchars; - - if (a = n/10) - nchars = 1 + printd(a); - else - nchars = 1; - putchar (n % 10 + '0'); - return (nchars); -} - -/* Put the print representation of an integer into a string */ -static char *sptr; - -scanstr (n, str) -int n; -char *str; -{ - sptr = str; - Sprintf (n); - *sptr = '\0'; -} - -Sprintf (n) -{ - int a; - - if (a = n/10) - Sprintf (a); - *sptr++ = n % 10 + '0'; -} - -static char bell = ctrl('G'); - -/* See whether the last component of the path name "path" is equal to the -** string "string" -*/ - -tailequ (path, string) -char *path; -register char *string; -{ - register char *tail; - - tail = path + strlen(path); - while (tail >= path) - if (*(--tail) == '/') - break; - ++tail; - while (*tail++ == *string++) - if (*tail == '\0') - return(1); - return(0); -} - -prompt (filename) -char *filename; -{ - if (clreol) - cleareol (); - else if (promptlen > 0) - kill_line (); - if (!hard) { - promptlen = 8; - if (Senter && Sexit) { - tputs (Senter, 1, putch); - promptlen += (2 * soglitch); - } - if (clreol) - cleareol (); - /* XXX - evil global vars */ - if(fnames[fnum] != NULL) { - promptlen += prtf ("%s ", fnames[fnum]); - } - else - pr("--More--"); - if (filename != NULL) { - promptlen += prtf ("(Next file: %s)", filename); - } - else if (!no_intty) { - promptlen += prtf ("(%d%%)", (int)((file_pos * 100) / file_size)); - } - if (dum_opt) { - promptlen += pr("[Press space to continue, 'q' to quit.]"); - } - if (Senter && Sexit) - tputs (Sexit, 1, putch); - if (clreol) - clreos (); - fflush(stdout); - } - else - write (2, &bell, 1); - inwait++; -} - -/* -** Get a logical line -*/ - -getline(f, length) -register FILE *f; -int *length; -{ - register int c; - register char *p; - register int column; - static int colflg; - - p = Line; - column = 0; - c = Getc (f); - if (colflg && c == '\n') { - Currline++; - c = Getc (f); - } - while (p < &Line[LINSIZ - 1]) { - if (c == EOF) { - if (p > Line) { - *p = '\0'; - *length = p - Line; - return (column); - } - *length = p - Line; - return (EOF); - } - if (c == '\n') { - Currline++; - break; - } - *p++ = c; - if (c == '\t') - if (!hardtabs || column < promptlen && !hard) { - if (hardtabs && eraseln && !dumb) { - column = 1 + (column | 7); - tputs (eraseln, 1, putch); - promptlen = 0; - } - else { - for (--p; p < &Line[LINSIZ - 1];) { - *p++ = ' '; - if ((++column & 7) == 0) - break; - } - if (column >= promptlen) promptlen = 0; - } - } - else - column = 1 + (column | 7); - else if (c == '\b' && column > 0) - column--; - else if (c == '\r') - column = 0; - else if (c == '\f' && stop_opt) { - p[-1] = '^'; - *p++ = 'L'; - column += 2; - Pause++; - } - else if (c == EOF) { - *length = p - Line; - return (column); - } - else if (c >= ' ' && c != RUBOUT) - column++; - if (column >= Mcol && fold_opt) break; - c = Getc (f); - } - if (column >= Mcol && Mcol > 0) { - if (!Wrap) { - *p++ = '\n'; - } - } - colflg = column == Mcol && fold_opt; - if (colflg && eatnl && Wrap) { - *p++ = '\n'; /* simulate normal wrap */ - } - *length = p - Line; - *p = 0; - return (column); -} - -/* -** Erase the rest of the prompt, assuming we are starting at column col. -*/ - -erase (col) -register int col; -{ - - if (promptlen == 0) - return; - if (hard) { - putchar ('\n'); - } - else { - if (col == 0) - putchar ('\r'); - if (!dumb && eraseln) - tputs (eraseln, 1, putch); - else - for (col = promptlen - col; col > 0; col--) - putchar (' '); - } - promptlen = 0; -} - -/* -** Erase the current line entirely -*/ - -kill_line () -{ - erase (0); - if (!eraseln || dumb) putchar ('\r'); -} - -/* - * force clear to end of line - */ -cleareol() -{ - tputs(eraseln, 1, putch); -} - -clreos() -{ - tputs(EodClr, 1, putch); -} - -/* -** Print string and return number of characters -*/ - -pr(s1) -char *s1; -{ - register char *s; - register char c; - - for (s = s1; c = *s++; ) - putchar(c); - return (s - s1 - 1); -} - - -/* Print a buffer of n characters */ - -prbuf (s, n) -register char *s; -register int n; -{ - register char c; /* next output character */ - register int state; /* next output char's UL state */ -#define wouldul(s,n) ((n) >= 2 && (((s)[0] == '_' && (s)[1] == '\b') || ((s)[1] == '\b' && (s)[2] == '_'))) - - while (--n >= 0) - if (!ul_opt) - putchar (*s++); - else { - if (*s == ' ' && pstate == 0 && ulglitch && wouldul(s+1, n-1)) { - s++; - continue; - } - if (state = wouldul(s, n)) { - c = (*s == '_')? s[2] : *s ; - n -= 2; - s += 3; - } else - c = *s++; - if (state != pstate) { - if (c == ' ' && state == 0 && ulglitch && wouldul(s, n-1)) - state = 1; - else - tputs(state ? ULenter : ULexit, 1, putch); - } - if (c != ' ' || pstate == 0 || state != 0 || ulglitch == 0) - putchar(c); - if (state && *chUL) { - pr(chBS); - tputs(chUL, 1, putch); - } - pstate = state; - } -} - -/* -** Clear the screen -*/ - -doclear() -{ - if (Clear && !hard) { - tputs(Clear, 1, putch); - - /* Put out carriage return so that system doesn't - ** get confused by escape sequences when expanding tabs - */ - putchar ('\r'); - promptlen = 0; - } -} - -/* - * Go to home position - */ -home() -{ - tputs(Home,1,putch); -} - -static int lastcmd, lastarg, lastp; -static int lastcolon; -char shell_line[132]; - -/* -** Read a command and do it. A command consists of an optional integer -** argument followed by the command character. Return the number of lines -** to display in the next screenful. If there is nothing more to display -** in the current file, zero is returned. -*/ - -command (filename, f) -char *filename; -register FILE *f; -{ - register int nlines; - register int retval; - register char c; - char colonch; - FILE *helpf; - int done; - char comchar, cmdbuf[80]; - char option[8]; - char *EDITOR; - char *editor; - -#define ret(val) retval=val;done++;break - - done = 0; - if (!errors) - prompt (filename); - else - errors = 0; - if (MBIT == RAW && slow_tty) { - otty.sg_flags |= MBIT; - stty(fileno(stderr), &otty); - } - for (;;) { - nlines = number (&comchar); - lastp = colonch = 0; - if (comchar == '.') { /* Repeat last command */ - lastp++; - comchar = lastcmd; - nlines = lastarg; - if (lastcmd == ':') - colonch = lastcolon; - } - lastcmd = comchar; - lastarg = nlines; - if (comchar == otty.sg_erase) { - kill_line (); - prompt (filename); - continue; - } - switch (comchar) { - case ':': - retval = colon (filename, colonch, nlines); - if (retval >= 0) - done++; - break; - case 'b': - case ctrl('B'): - { - register int initline; - - if (no_intty) { - write(2, &bell, 1); - return (-1); - } - - if (nlines == 0) nlines++; - - putchar ('\r'); - erase (0); - prtf ("\n"); - if (clreol) - cleareol (); - prtf ("...back %d page", nlines); - if (nlines > 1) - pr ("s\n"); - else - pr ("\n"); - - if (clreol) - cleareol (); - pr ("\n"); - - initline = Currline - dlines * (nlines + 1); - if (! noscroll) - --initline; - if (initline < 0) initline = 0; - Fseek(f, 0L); - Currline = 0; /* skiplns() will make Currline correct */ - skiplns(initline, f); - /* if (! noscroll) { - ret(dlines + 1); - } - else { - ret(dlines); - } */ - ret(dlines); /* XXX - Maybe broken on dumb - terminals */ - } - /* 4.3BSD more - Display next [count] lines of text */ - case ' ': - case 'z': - if (nlines == 0) nlines = dlines; - else if (comchar == 'z') - dlines = nlines; - ret (nlines); - case 'd': - case ctrl('D'): - if (nlines != 0) nscroll = nlines; - ret (nscroll); - case 'q': - case 'Q': - end_it (); - case 's': - /* POSIX.2 Move forward one screenfull */ - case 'f': /* POSIX.2 [count]f */ - case ctrl('F'): /* [count]control-F */ - if (nlines == 0) nlines++; - if (comchar == 'f') - nlines *= dlines; - putchar ('\r'); - erase (0); - prtf ("\n"); - if (clreol) - cleareol (); - prtf ("...skipping %d line", nlines); - if (nlines > 1) - pr ("s\n"); - else - pr ("\n"); - - if (clreol) - cleareol (); - pr ("\n"); - - while (nlines > 0) { - while ((c = Getc (f)) != '\n') - if (c == EOF) { - retval = 0; - done++; - goto endsw; - } - Currline++; - nlines--; - } - ret (dlines); - case '\n': - if (nlines != 0) - dlines = nlines; - else - nlines = 1; - ret (nlines); - case '\f': - if (!no_intty) { - doclear (); - Fseek (f, screen_start.chrctr); - Currline = screen_start.line; - ret (dlines); - } - else { - write (2, &bell, 1); - break; - } - case '\'': - if (!no_intty) { - kill_line (); - pr ("\n***Back***\n\n"); - Fseek (f, context.chrctr); - Currline = context.line; - ret (dlines); - } - else { - write (2, &bell, 1); - break; - } - case '=': - kill_line (); - promptlen = printd (Currline); - fflush (stdout); - break; - case 'n': - lastp++; - case '/': - if (nlines == 0) nlines++; - kill_line (); - pr ("/"); - promptlen = 1; - fflush (stdout); - if (lastp) { - write (2,"\r", 1); - search (NULL, f, nlines); /* Use previous r.e. */ - } - else { - ttyin (cmdbuf, 78, '/'); - write (2, "\r", 1); - search (cmdbuf, f, nlines); - } - ret (dlines-1); - case '!': - do_shell (filename); - break; - case '?': - case 'h': - if ((helpf = fopen (HELPFILE, "r")) == NULL) - error ("Can't open help file"); - if (noscroll) doclear (); - copy_file (helpf); - fclose (helpf); - prompt (filename); - break; - /* Run Editor */ - case 'v': /* This case should go right before default */ - if (!no_intty) { - kill_line (); - strcpy(cmdbuf, "-c"); - scanstr (Currline - dlines < 0 ? 0 - : Currline - (dlines + 1) / 2, option); - - /* POSIX.2 more EDITOR env. var. behavior */ - if ((EDITOR = getenv("EDITOR")) != NULL) { - - /* Need to look for vi or ex as - * we need to tell them the current - * line number - */ - if ((editor = strrchr(EDITOR, '/')) == NULL) - editor = EDITOR; - else - editor++; - if ((strcmp(editor, "vi") == 0) || - (strcmp(editor, "ex") == 0)) - execute (filename, EDITOR, EDITOR, cmdbuf, option, fnames[fnum], 0); - else /* must be some other editor */ - execute (filename, EDITOR, EDITOR, fnames[fnum], 0); - } - else { /* default editor */ - execute (filename, _PATH_VI, _PATH_VI, cmdbuf, option, fnames[fnum], 0); - } - - break; - } - default: - if (dum_opt) { - kill_line (); - if (Senter && Sexit) { - tputs (Senter, 1, putch); - promptlen = pr ("[Press 'h' for instructions.]") + (2 * soglitch); - tputs (Sexit, 1, putch); - } - else - promptlen = pr ("[Press 'h' for instructions.]"); - fflush (stdout); - } - else - write (2, &bell, 1); - break; - } - if (done) break; - } - putchar ('\r'); -endsw: - inwait = 0; - notell++; - if (MBIT == RAW && slow_tty) { - otty.sg_flags &= ~MBIT; - stty(fileno(stderr), &otty); - } - return (retval); -} - -char ch; - -/* - * Execute a colon-prefixed command. - * Returns <0 if not a command that should cause - * more of the file to be printed. - */ - -colon (filename, cmd, nlines) -char *filename; -int cmd; -int nlines; -{ - if (cmd == 0) - ch = readch (); - else - ch = cmd; - lastcolon = ch; - switch (ch) { - case 'f': - kill_line (); - if (!no_intty) - promptlen = prtf ("\"%s\" line %d", fnames[fnum], Currline); - else - promptlen = prtf ("[Not a file] line %d", Currline); - fflush (stdout); - return (-1); - case 'n': - if (nlines == 0) { - if (fnum >= nfiles - 1) - end_it (); - nlines++; - } - putchar ('\r'); - erase (0); - skipf (nlines); - return (0); - case 'p': - if (no_intty) { - write (2, &bell, 1); - return (-1); - } - putchar ('\r'); - erase (0); - if (nlines == 0) - nlines++; - skipf (-nlines); - return (0); - case '!': - do_shell (filename); - return (-1); - case 'q': - case 'Q': - end_it (); - default: - write (2, &bell, 1); - return (-1); - } -} - -/* -** Read a decimal number from the terminal. Set cmd to the non-digit which -** terminates the number. -*/ - -number(cmd) -char *cmd; -{ - register int i; - - i = 0; ch = otty.sg_kill; - for (;;) { - ch = readch (); - if (ch >= '0' && ch <= '9') - i = i*10 + ch - '0'; - else if (ch == otty.sg_kill) - i = 0; - else { - *cmd = ch; - break; - } - } - return (i); -} - -do_shell (filename) -char *filename; -{ - char cmdbuf[80]; - - kill_line (); - pr ("!"); - fflush (stdout); - promptlen = 1; - if (lastp) - pr (shell_line); - else { - ttyin (cmdbuf, 78, '!'); - if (expand (shell_line, cmdbuf)) { - kill_line (); - promptlen = prtf ("!%s", shell_line); - } - } - fflush (stdout); - write (2, "\n", 1); - promptlen = 0; - shellp = 1; - execute (filename, shell, shell, "-c", shell_line, 0); -} - -/* -** Search for nth ocurrence of regular expression contained in buf in the file -*/ - -search (buf, file, n) -char buf[]; -FILE *file; -register int n; -{ - long startline = Ftell (file); - register long line1 = startline; - register long line2 = startline; - register long line3 = startline; - register int lncount; - int saveln, rv, re_exec(); - char *s, *re_comp(); - - context.line = saveln = Currline; - context.chrctr = startline; - lncount = 0; - if ((s = re_comp (buf)) != 0) - error (s); - while (!feof (file)) { - line3 = line2; - line2 = line1; - line1 = Ftell (file); - rdline (file); - lncount++; - if ((rv = re_exec (Line)) == 1) - if (--n == 0) { - if (lncount > 3 || (lncount > 1 && no_intty)) - { - pr ("\n"); - if (clreol) - cleareol (); - pr("...skipping\n"); - } - if (!no_intty) { - Currline -= (lncount >= 3 ? 3 : lncount); - Fseek (file, line3); - if (noscroll) - if (clreol) { - home (); - cleareol (); - } - else - doclear (); - } - else { - kill_line (); - if (noscroll) - if (clreol) { - home (); - cleareol (); - } - else - doclear (); - pr (Line); - putchar ('\n'); - } - break; - } - else if (rv == -1) - error ("Regular expression botch"); - } - if (feof (file)) { - if (!no_intty) { - /* file->_flag &= ~_IOEOF; /* why doesn't fseek do this ??!!??! */ - Currline = saveln; - Fseek (file, startline); - } - else { - pr ("\nPattern not found\n"); - end_it (); - } - error ("Pattern not found"); - } -} - -/*VARARGS2*/ -execute (filename, cmd, va_alist) -char *filename; -char *cmd; -va_dcl -{ - int id; - int n; - va_list argp; - - fflush (stdout); - reset_tty (); - for (n = 10; (id = fork ()) < 0 && n > 0; n--) - sleep (5); - if (id == 0) { - if (!isatty(0)) { - close(0); - open(_PATH_TTY, O_RDONLY); - } - va_start(argp); - execvp (cmd, argp); - write (2, "exec failed\n", 12); - va_end(argp); /* balance {}'s for some UNIX's */ - exit (1); - } - if (id > 0) { - signal (SIGINT, SIG_IGN); - signal (SIGQUIT, SIG_IGN); - if (catch_susp) - signal(SIGTSTP, SIG_DFL); - while (wait(0) > 0); - signal (SIGINT, end_it); - signal (SIGQUIT, onquit); - if (catch_susp) - signal(SIGTSTP, onsusp); - } else - write(2, "can't fork\n", 11); - set_tty (); - /* pr ("------------------------\n"); */ - prompt (filename); -} -/* -** Skip n lines in the file f -*/ - -skiplns (n, f) -register int n; -register FILE *f; -{ - register char c; - - while (n > 0) { - while ((c = Getc (f)) != '\n') - if (c == EOF) - return; - n--; - Currline++; - } -} - -/* -** Skip nskip files in the file list (from the command line). Nskip may be -** negative. -*/ - -skipf (nskip) -register int nskip; -{ - if (nskip == 0) return; - if (nskip > 0) { - if (fnum + nskip > nfiles - 1) - nskip = nfiles - fnum - 1; - } - else if (within) - ++fnum; - fnum += nskip; - if (fnum < 0) - fnum = 0; - pr ("\n...Skipping "); - pr ("\n"); - if (clreol) - cleareol (); - pr ("...Skipping "); - pr (nskip > 0 ? "to file " : "back to file "); - pr (fnames[fnum]); - pr ("\n"); - if (clreol) - cleareol (); - pr ("\n"); - --fnum; -} - -/*----------------------------- Terminal I/O -------------------------------*/ - -initterm () -{ - char buf[TBUFSIZ]; - static char clearbuf[TBUFSIZ]; - char *clearptr, *padstr; - int ldisc; - int lmode; - char *term; - int tgrp; - struct winsize win; - char *tgoto(); - -retry: - if (!(no_tty = ioctl(fileno(stdout), TIOCGETP, &otty))) { - if (ioctl(fileno(stdout), TIOCLGET, &lmode) < 0) { - perror("TIOCLGET"); - exit(1); - } - docrterase = ((lmode & LCRTERA) != 0); - docrtkill = ((lmode & LCRTKIL) != 0); - /* - * Wait until we're in the foreground before we save the - * the terminal modes. - */ - if (ioctl(fileno(stdout), TIOCGPGRP, &tgrp) < 0) { - perror("TIOCGPGRP"); - exit(1); - } - if (tgrp != getpgrp(0)) { - kill(0, SIGTTOU); - goto retry; - } - if ((term = getenv("TERM")) == 0 || tgetent(buf, term) <= 0) { - dumb++; ul_opt = 0; - } - else { - if (ioctl(fileno(stdout), TIOCGWINSZ, &win) < 0) { - Lpp = tgetnum("li"); - Mcol = tgetnum("co"); - } else { - if ((Lpp = win.ws_row) == 0) - Lpp = tgetnum("li"); - if ((Mcol = win.ws_col) == 0) - Mcol = tgetnum("co"); - } - if ((Lpp <= 0) || tgetflag("hc")) { - hard++; /* Hard copy terminal */ - Lpp = 24; - } - if (tgetflag("xn")) - eatnl++; /* Eat newline at last column + 1; dec, concept */ - if (Mcol <= 0) - Mcol = 80; - - if (tailequ (fnames[0], "page") || !hard && tgetflag("ns")) - noscroll++; - Wrap = tgetflag("am"); - bad_so = tgetflag ("xs"); - clearptr = clearbuf; - eraseln = tgetstr("ce",&clearptr); - Clear = tgetstr("cl", &clearptr); - Senter = tgetstr("so", &clearptr); - Sexit = tgetstr("se", &clearptr); - if ((soglitch = tgetnum("sg")) < 0) - soglitch = 0; - - /* - * Set up for underlining: some terminals don't need it; - * others have start/stop sequences, still others have an - * underline char sequence which is assumed to move the - * cursor forward one character. If underline sequence - * isn't available, settle for standout sequence. - */ - - if (tgetflag("ul") || tgetflag("os")) - ul_opt = 0; - if ((chUL = tgetstr("uc", &clearptr)) == NULL ) - chUL = ""; - if (((ULenter = tgetstr("us", &clearptr)) == NULL || - (ULexit = tgetstr("ue", &clearptr)) == NULL) && !*chUL) { - if ((ULenter = Senter) == NULL || (ULexit = Sexit) == NULL) { - ULenter = ""; - ULexit = ""; - } else - ulglitch = soglitch; - } else { - if ((ulglitch = tgetnum("ug")) < 0) - ulglitch = 0; - } - - if (padstr = tgetstr("pc", &clearptr)) - PC = *padstr; - Home = tgetstr("ho",&clearptr); - if (Home == 0 || *Home == '\0') - { - if ((cursorm = tgetstr("cm", &clearptr)) != NULL) { - strcpy(cursorhome, tgoto(cursorm, 0, 0)); - Home = cursorhome; - } - } - EodClr = tgetstr("cd", &clearptr); - if ((chBS = tgetstr("bc", &clearptr)) == NULL) - chBS = "\b"; - - } - if ((shell = getenv("SHELL")) == NULL) - shell = "/bin/sh"; - } - no_intty = ioctl(fileno(stdin), TIOCGETP, &otty); - (void)ioctl(fileno(stderr), TIOCGETP, &otty); - savetty = otty; - ospeed = otty.sg_ospeed; - slow_tty = ospeed < B1200; - hardtabs = (otty.sg_flags & TBDELAY) != XTABS; - if (!no_tty) { - otty.sg_flags &= ~ECHO; - if (MBIT == CBREAK || !slow_tty) - otty.sg_flags |= MBIT; - } -} - -readch () -{ - char ch; - - errno = 0; - if (read (2, &ch, 1) <= 0) - if (errno != EINTR) - end_it(); - else - ch = otty.sg_kill; - return (ch); -} - -static char BS = '\b'; -static char *BSB = "\b \b"; -static char CARAT = '^'; -#define ERASEONECHAR \ - if (docrterase) \ - write (2, BSB, sizeof(BSB)); \ - else \ - write (2, &BS, sizeof(BS)); - -ttyin (buf, nmax, pchar) -char buf[]; -register int nmax; -char pchar; -{ - register char *sptr; - register char ch; - register int slash = 0; - int maxlen; - char cbuf; - - sptr = buf; - maxlen = 0; - while (sptr - buf < nmax) { - if (promptlen > maxlen) maxlen = promptlen; - ch = readch (); - if (ch == '\\') { - slash++; - } - else if ((ch == otty.sg_erase) && !slash) { - if (sptr > buf) { - --promptlen; - ERASEONECHAR - --sptr; - if ((*sptr < ' ' && *sptr != '\n') || *sptr == RUBOUT) { - --promptlen; - ERASEONECHAR - } - continue; - } - else { - if (!eraseln) promptlen = maxlen; - longjmp (restore, 1); - } - } - else if ((ch == otty.sg_kill) && !slash) { - if (hard) { - show (ch); - putchar ('\n'); - putchar (pchar); - } - else { - putchar ('\r'); - putchar (pchar); - if (eraseln) - erase (1); - else if (docrtkill) - while (promptlen-- > 1) - write (2, BSB, sizeof(BSB)); - promptlen = 1; - } - sptr = buf; - fflush (stdout); - continue; - } - if (slash && (ch == otty.sg_kill || ch == otty.sg_erase)) { - ERASEONECHAR - --sptr; - } - if (ch != '\\') - slash = 0; - *sptr++ = ch; - if ((ch < ' ' && ch != '\n' && ch != ESC) || ch == RUBOUT) { - ch += ch == RUBOUT ? -0100 : 0100; - write (2, &CARAT, 1); - promptlen++; - } - cbuf = ch; - if (ch != '\n' && ch != ESC) { - write (2, &cbuf, 1); - promptlen++; - } - else - break; - } - *--sptr = '\0'; - if (!eraseln) promptlen = maxlen; - if (sptr - buf >= nmax - 1) - error ("Line too long"); -} - -expand (outbuf, inbuf) -char *outbuf; -char *inbuf; -{ - register char *instr; - register char *outstr; - register char ch; - char temp[200]; - int changed = 0; - - instr = inbuf; - outstr = temp; - while ((ch = *instr++) != '\0') - switch (ch) { - case '%': - if (!no_intty) { - strcpy (outstr, fnames[fnum]); - outstr += strlen (fnames[fnum]); - changed++; - } - else - *outstr++ = ch; - break; - case '!': - if (!shellp) - error ("No previous command to substitute for"); - strcpy (outstr, shell_line); - outstr += strlen (shell_line); - changed++; - break; - case '\\': - if (*instr == '%' || *instr == '!') { - *outstr++ = *instr++; - break; - } - default: - *outstr++ = ch; - } - *outstr++ = '\0'; - strcpy (outbuf, temp); - return (changed); -} - -show (ch) -register char ch; -{ - char cbuf; - - if ((ch < ' ' && ch != '\n' && ch != ESC) || ch == RUBOUT) { - ch += ch == RUBOUT ? -0100 : 0100; - write (2, &CARAT, 1); - promptlen++; - } - cbuf = ch; - write (2, &cbuf, 1); - promptlen++; -} - -error (mess) -char *mess; -{ - if (clreol) - cleareol (); - else - kill_line (); - promptlen += strlen (mess); - if (Senter && Sexit) { - tputs (Senter, 1, putch); - pr(mess); - tputs (Sexit, 1, putch); - } - else - pr (mess); - fflush(stdout); - errors++; - longjmp (restore, 1); -} - - -set_tty () -{ - otty.sg_flags |= MBIT; - otty.sg_flags &= ~ECHO; - stty(fileno(stderr), &otty); -} - -reset_tty () -{ - if (no_tty) - return; - if (pstate) { - tputs(ULexit, 1, putch); - fflush(stdout); - pstate = 0; - } - otty.sg_flags |= ECHO; - otty.sg_flags &= ~MBIT; - stty(fileno(stderr), &savetty); -} - -rdline (f) -register FILE *f; -{ - register char c; - register char *p; - - p = Line; - while ((c = Getc (f)) != '\n' && c != EOF && p - Line < LINSIZ - 1) - *p++ = c; - if (c == '\n') - Currline++; - *p = '\0'; -} - -/* Come here when we get a suspend signal from the terminal */ - -void -onsusp () -{ - sigset_t mask; - - /* ignore SIGTTOU so we don't get stopped if csh grabs the tty */ - signal(SIGTTOU, SIG_IGN); - reset_tty (); - fflush (stdout); - signal(SIGTTOU, SIG_DFL); - /* Send the TSTP signal to suspend our process group */ - signal(SIGTSTP, SIG_DFL); - sigemptyset(&mask); - sigprocmask(SIG_SETMASK, &mask, NULL); - kill (0, SIGTSTP); - /* Pause for station break */ - - /* We're back */ - signal (SIGTSTP, onsusp); - set_tty (); - if (inwait) - longjmp (restore, 1); -} diff --git a/usr.bin/more/more.help b/usr.bin/more/more.help deleted file mode 100644 index f67805a1ff0..00000000000 --- a/usr.bin/more/more.help +++ /dev/null @@ -1,24 +0,0 @@ - -Most commands optionally preceded by integer argument k. Defaults in brackets. -Star (*) indicates argument becomes new default. -------------------------------------------------------------------------------- -<space> Display next k lines of text [current screen size] -z Display next k lines of text [current screen size]* -<return> Display next k lines of text [1]* -d or ctrl-D Scroll k lines [current scroll size, initially 11]* -q or Q or <interrupt> Exit from more -s Skip forward k lines of text [1] -f Skip forward k screenfuls of text [1] -b or ctrl-B Skip backwards k screenfuls of text [1] -' Go to place where previous search started -= Display current line number -/<regular expression> Search for kth occurrence of regular expression [1] -n Search for kth occurrence of last r.e [1] -!<cmd> or :!<cmd> Execute <cmd> in a subshell -v Starts $EDITOR or /usr/bin/vi at current line -ctrl-L Redraw screen -:n Go to kth next file [1] -:p Go to kth previous file [1] -:f Display current file name and line number -. Repeat previous command -------------------------------------------------------------------------------- diff --git a/usr.bin/more/pathnames.h b/usr.bin/more/pathnames.h deleted file mode 100644 index 78c0a158d9a..00000000000 --- a/usr.bin/more/pathnames.h +++ /dev/null @@ -1,39 +0,0 @@ -/* $OpenBSD: pathnames.h,v 1.4 1996/09/28 22:20:49 etheisen Exp $ */ -/*- - * Copyright (c) 1989 The Regents of the University of California. - * All rights reserved. - * - * Redistribution and use in source and binary forms, with or without - * modification, are permitted provided that the following conditions - * are met: - * 1. Redistributions of source code must retain the above copyright - * notice, this list of conditions and the following disclaimer. - * 2. Redistributions in binary form must reproduce the above copyright - * notice, this list of conditions and the following disclaimer in the - * documentation and/or other materials provided with the distribution. - * 3. All advertising materials mentioning features or use of this software - * must display the following acknowledgement: - * This product includes software developed by the University of - * California, Berkeley and its contributors. - * 4. Neither the name of the University nor the names of its contributors - * may be used to endorse or promote products derived from this software - * without specific prior written permission. - * - * THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND - * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE - * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE - * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE - * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL - * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS - * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) - * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT - * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY - * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF - * SUCH DAMAGE. - * - * @(#)pathnames.h 5.2 (Berkeley) 4/18/91 - */ - -#include <paths.h> - -#define HELPFILE "/usr/share/misc/more.help" |