diff -r -U2 less-252/Makefile.dos less-278/Makefile.dos --- less-252/Makefile.dos Sat Oct 15 03:16:44 1994 +++ less-278/Makefile.dos Tue Jan 31 18:55:16 1995 @@ -39,6 +39,10 @@ $(CC) $(LDFLAGS) -o $@ *.obj $(LIBS) -lesskey: lesskey.obj - $(CC) $(LDFLAGS) -o $@ lesskey.obj $(LIBS) +lesskey: lesskey.obj version.obj + $(CC) $(LDFLAGS) -o $@ lesskey.obj version.obj $(LIBS) + +defines.h: defines.dos + -del defines.h + -copy defines.dos defines.h $(OBJ): less.h defines.h diff -r -U2 less-252/Makefile.in less-278/Makefile.in --- less-252/Makefile.in Sun Nov 6 19:04:04 1994 +++ less-278/Makefile.in Tue Jan 31 18:55:17 1995 @@ -11,7 +11,7 @@ INSTALL_DATA = @INSTALL_DATA@ -CFLAGS = -O +CFLAGS = @CFLAGS@ CFLAGS_COMPILE_ONLY = -c -LDFLAGS = +LDFLAGS = @LDFLAGS@ O=o @@ -54,9 +54,11 @@ tags.$(O) ttyin.$(O) version.$(O) @REGEX_O@ DISTFILES = ${SRC} regexp.c regexp.h \ - INSTALL Makefile.in Makefile.dos README NEWS \ - configure configure.in doscreen.c acconfig.h lesskey.c \ - cmd.h defines.dos funcs.h less.h lesskey.h option.h position.h \ + INSTALL Makefile.in README NEWS \ + configure configure.in acconfig.h lesskey.c \ + cmd.h funcs.h less.h lesskey.h option.h position.h \ install.sh defines.h.in defines.h.top mkinstalldirs \ - less.nro lesskey.nro less.man lesskey.man less.hlp + less.nro lesskey.nro less.man lesskey.man less.hlp \ + Makefile.dos defines.dos doscreen.c \ + Makefile.os2 defines.os2 all: less lesskey @@ -101,8 +103,8 @@ defines.h: stamp-h stamp-h: defines.h.in config.status - test ! -f stamp-h || ./config.status + test ! -f stamp-h || CONFIG_FILES= CONFIG_HEADERS=defines.h ./config.status touch stamp-h Makefile: Makefile.in config.status - ./config.status + CONFIG_FILES=Makefile CONFIG_HEADERS= ./config.status config.status: configure ./config.status --recheck @@ -111,5 +113,6 @@ lint -I. $(CPPFLAGS) $(SRC) newfuncs: - awk -f mkfuncs.awk $(SRC) >newfuncs + mv -f funcs.h funcs.h.old + awk -f mkfuncs.awk $(SRC) >funcs.h clean: rm -f *.$(O) core less lesskey @@ -118,5 +121,5 @@ distclean: clean - rm -f Makefile config.status defines.h stamp-h + rm -f Makefile config.status config.log config.cache defines.h stamp-h realclean: distclean Only in less-278: Makefile.os2 diff -r -U2 less-252/NEWS less-278/NEWS --- less-252/NEWS Wed Nov 16 14:23:45 1994 +++ less-278/NEWS Wed Feb 15 01:13:44 1995 @@ -1,2 +1,25 @@ + Major changes between "less" versions 252 and 278 + +* A LESSOPEN preprocessor may now pipe the converted file data to less, + rather than writing it to a temporary file. + +* Search pattern highlighting has been fixed. It now highlights + reliably, even if a string is split across two screen lines, + contains TABs, etc. + +* The -F flag (which suppress search highlighting) has been changed + to -G. A new flag, -g, changes search highlighting to highlight + only the string found by the last search command, instead of all + strings which match the last search command. + +* New flag -I acts like -i, but ignores case even if the search + pattern contains uppercase letters. + +* Less now checks for the environment variable VISUAL before EDITOR. + +* Ported to OS/2. + +====================================================================== + Major changes between "less" versions 237 and 252 diff -r -U2 less-252/README less-278/README --- less-252/README Wed Nov 16 14:23:52 1994 +++ less-278/README Tue Feb 14 13:23:21 1995 @@ -1,4 +1,4 @@ ======================================================================= -=== NOTE: THIS IS A DISTRIBUTION OF less (version 252) === +=== NOTE: THIS IS A DISTRIBUTION OF less (version 278) === === PLEASE REPORT ANY PROBLEMS TO THE AUTHOR AT markn@3do.com. === ======================================================================= @@ -9,4 +9,5 @@ Major changes made since the last posted version are in NEWS. +======================================================================= INSTALLATION (Unix systems only): @@ -25,4 +26,7 @@ If you wish, you may edit defines.h to remove some optional features. + If you wish to build a "secure" version of less (which disables all + features which might allow a user to do unintended things to the system + on which less is running), edit defines.h and define SECURE to 1. If you choose not to include some features in your version, you may wish to edit the manual page "less.nro" and the help page "less.hlp" @@ -31,4 +35,8 @@ 4. Type "make" and watch the fun. + If you want less to find the help file in a directory other than + the default (/usr/local/share), define "datadir" to that directory. + For example: "make datadir=/usr/local/helpfiles" + 5. If the make succeeds, it will generate a program "less" in your current directory. Test the generated program. @@ -37,4 +45,12 @@ in a public place, type "make install". + The default install destinations are: + Executables (less, lesskey) in /usr/local/bin + Data files (less.hlp) in /usr/local/share + Documentation (less.nro, lesskey.nro) in /usr/local/man/man1 + If you want to install any of these files elsewhere, define + bindir, datadir, and/or mandir to the appropriate directories. + datadir must be defined the same as in step 4. + If you have any problems building or running "less", suggestions, complaints, etc., you may mail to the author at markn@3do.com @@ -45,4 +61,5 @@ +======================================================================= INSTALLATION (MS-DOS systems only) @@ -52,14 +69,13 @@ 2. Rename MAKEFILE.DOS to MAKEFILE. - Rename DEFINES.DOS to DEFINES.H. 3. Look at MAKEFILE to make sure that the definitions for CC and LIBDIR are correct. CC should be the name of your Microsoft C compiler and - LIBDIR should be the directory where the Microsoft C librarires + LIBDIR should be the directory where the Microsoft C libraries reside. If these definitions need to be changed, you can either modify the definitions directly in MAKEFILE, or set your environment variables CC and/or LIBDIR to override the definitions in MAKEFILE. -4. If you wish, you may edit defines.h to remove some optional features. +4. If you wish, you may edit DEFINES.DOS to remove some optional features. If you choose not to include some features in your version, you may wish to edit the manual page LESS.MAN and the help page LESS.HLP @@ -77,4 +93,35 @@ 7. When satisfied that it works, you may wish to install LESS.EXE, LESSKEY.EXE and LESS.HLP in a directory which is included in + your PATH. + + + +======================================================================= +INSTALLATION (OS/2 systems only) + +1. Move the distributed source to its own directory. + +2. Rename Makefile.os2 to Makefile. + +3. Check the Makefile to make sure the definitions look ok. + +4. If you wish, you may edit defines.os2 to remove some optional features. + If you choose not to include some features in your version, you may + wish to edit the manual page less.man and the help page less.hlp + to remove the descriptions of the features which you are removing. + +5. Type "make" and watch the fun. + +6. If the make succeeds, it will generate a program "less.exe" + in your current directory. Test the generated program. + +7. Make sure you have the emx runtime installed. You need the emx DLLs + emx.dll and emxlibcs.dll and also the termcap database, termcap.dat. + Make sure you have termcap.dat either in the default location or + somewhere in a directory listed in the PATH or INIT environment + variables. + +8. When satisfied that it works, you may wish to install less.exe, + lesskey.exe and less.hlp in a directory which is included in your PATH. diff -r -U2 less-252/acconfig.h less-278/acconfig.h --- less-252/acconfig.h Thu Oct 27 15:18:19 1994 +++ less-278/acconfig.h Tue Jan 31 18:55:25 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -49,4 +49,7 @@ /* Define HAVE_STRERROR if you have the strerror() function. */ #undef HAVE_STRERROR + +/* Define HAVE_FILENO if you have the fileno() macro. */ +#undef HAVE_FILENO /* Define HAVE_ERRNO if you have the errno variable */ diff -r -U2 less-252/brac.c less-278/brac.c --- less-252/brac.c Sat Oct 15 03:16:44 1994 +++ less-278/brac.c Tue Jan 31 18:55:26 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/ch.c less-278/ch.c --- less-252/ch.c Sat Oct 15 03:16:44 1994 +++ less-278/ch.c Tue Jan 31 18:55:27 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -34,9 +34,11 @@ #include "less.h" -public int file = -1; /* File descriptor of the input file */ public int ignore_eoi; /* * Pool of buffers holding the most recently used blocks of the input file. + * The buffer pool is kept as a doubly-linked circular list, + * in order from most- to least-recently used. + * The circular list is anchored by the file state "thisfile". */ #define LBUFSIZE 1024 @@ -49,19 +51,14 @@ /* - * The buffer pool is kept as a doubly-linked circular list, - * in order from most- to least-recently used. - * The circular list is anchored by the file state "thisfile". - * * The file state is maintained in a filestate structure. - * There are two such structures, one used when input is a pipe - * and the other when input is an ordinary file. - * This is so that we can leave a pipe, look and other files, - * and return to the pipe without losing buffered data. - * Buffered data can be reconstructed for a non-pipe file by - * simply re-reading the file, but a pipe cannot be re-read. + * A pointer to the filestate is kept in the ifile structure. */ - struct filestate { - struct buf *next, *prev; /* Must be first to match struct buf */ + /* -- Following members must match struct buf */ + struct buf *buf_next, *buf_prev; + long buf_block; + /* -- End of struct buf copy */ + int file; + int flags; POSITION fpos; int nbufs; @@ -71,7 +68,8 @@ }; + #define END_OF_CHAIN ((struct buf *)thisfile) -#define buf_head thisfile->next -#define buf_tail thisfile->prev +#define ch_bufhead thisfile->buf_next +#define ch_buftail thisfile->buf_prev #define ch_nbufs thisfile->nbufs #define ch_block thisfile->block @@ -79,16 +77,14 @@ #define ch_fpos thisfile->fpos #define ch_fsize thisfile->fsize - -static struct filestate pipefile = - { (struct buf *)&pipefile, (struct buf *)&pipefile }; - -static struct filestate nonpipefile = - { (struct buf *)&nonpipefile, (struct buf *)&nonpipefile }; +#define ch_flags thisfile->flags +#define ch_file thisfile->file static struct filestate *thisfile; +static int ch_ungotchar = -1; -extern int ispipe; extern int autobuf; extern int sigs; +extern int cbufs; +extern IFILE curr_ifile; #if LOGFILE extern int logfile; @@ -105,7 +101,7 @@ * that the block desired is at the head of the chain. */ -#define ch_get() ((ch_block == buf_head->block && \ - ch_offset < buf_head->datasize) ? \ - buf_head->data[ch_offset] : fch_get()) +#define ch_get() ((ch_block == ch_bufhead->block && \ + ch_offset < ch_bufhead->datasize) ? \ + ch_bufhead->data[ch_offset] : fch_get()) int fch_get() @@ -117,10 +113,10 @@ POSITION len; - slept = 0; + slept = FALSE; /* * Look for a buffer holding the desired block. */ - for (bp = buf_head; bp != END_OF_CHAIN; bp = bp->next) + for (bp = ch_bufhead; bp != END_OF_CHAIN; bp = bp->next) if (bp->block == ch_block) { @@ -137,14 +133,23 @@ * and read the desired block into it. * If the LRU buffer has data in it, - * and autobuf is true, and input is a pipe, - * then try to allocate a new buffer first. + * then maybe allocate a new buffer. */ - if (autobuf && ispipe && buf_tail->block != (long)(-1)) - if (ch_addbuf(1)) - /* - * Allocation failed: turn off autobuf. - */ - autobuf = 0; - bp = buf_tail; + if (ch_buftail == END_OF_CHAIN || ch_buftail->block != (long)(-1)) + { + /* + * There is no empty buffer to use. + * Allocate a new buffer if: + * 1. We can't seek on this file and -b is not in effect; or + * 2. We haven't allocated the max buffers for this file yet. + */ + if ((autobuf && !(ch_flags & CH_CANSEEK)) || + (cbufs == -1 || ch_nbufs < cbufs)) + if (ch_addbuf()) + /* + * Allocation failed: turn off autobuf. + */ + autobuf = OPT_OFF; + } + bp = ch_buftail; bp->block = ch_block; bp->datasize = 0; @@ -165,10 +170,11 @@ * Some data has been lost: just return "?". */ - if (ispipe) + if (!(ch_flags & CH_CANSEEK)) return ('?'); - if (lseek(file, (off_t)pos, 0) == BAD_LSEEK) + if (lseek(ch_file, (off_t)pos, 0) == BAD_LSEEK) { error("seek error", NULL_PARG); - quit(1); + clear_eol(); + return (EOI); } ch_fpos = pos; @@ -180,6 +186,15 @@ * We use partial block and pick up the rest next time. */ - n = iread(file, &bp->data[bp->datasize], - (unsigned int)(LBUFSIZE - bp->datasize)); + if (ch_ungotchar == -1) + { + n = iread(ch_file, &bp->data[bp->datasize], + (unsigned int)(LBUFSIZE - bp->datasize)); + } else + { + bp->data[bp->datasize] = ch_ungotchar; + n = 1; + ch_ungotchar = -1; + } + if (n == READ_INTR) return (EOI); @@ -187,7 +202,7 @@ { error("read error", NULL_PARG); - quit(1); + clear_eol(); + n = 0; } - ch_fpos += n; #if LOGFILE @@ -199,4 +214,5 @@ #endif + ch_fpos += n; bp->datasize += n; @@ -219,5 +235,5 @@ sleep(1); #endif - slept = 1; + slept = TRUE; } if (ABORT_SIGS()) @@ -226,5 +242,5 @@ found: - if (buf_head != bp) + if (ch_bufhead != bp) { /* @@ -235,8 +251,8 @@ bp->prev->next = bp->next; - bp->next = buf_head; + bp->next = ch_bufhead; bp->prev = END_OF_CHAIN; - buf_head->prev = bp; - buf_head = bp; + ch_bufhead->prev = bp; + ch_bufhead = bp; } @@ -251,4 +267,17 @@ } +/* + * ch_ungetchar is a rather kludgy and limited way to push + * a single char onto an input file descriptor. + */ + public void +ch_ungetchar(c) + int c; +{ + if (c != -1 && ch_ungotchar != -1) + error("ch_ungetchar overrun", NULL_PARG); + ch_ungotchar = c; +} + #if LOGFILE /* @@ -259,5 +288,5 @@ end_logfile() { - static int tried = 0; + static int tried = FALSE; if (logfile < 0) @@ -265,5 +294,5 @@ if (!tried && ch_fsize == NULL_POSITION) { - tried = 1; + tried = TRUE; ierror("Finishing logfile", NULL_PARG); while (ch_forw_get() != EOI) @@ -285,10 +314,23 @@ { register struct buf *bp; + int warned = FALSE; long block; - long last_block; + long nblocks; - last_block = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE; - for (block = 0; block <= last_block; block++) - for (bp = buf_head; bp != END_OF_CHAIN; bp = bp->next) + nblocks = (ch_fpos + LBUFSIZE - 1) / LBUFSIZE; + for (block = 0; block < nblocks; block++) + { + for (bp = ch_bufhead; ; bp = bp->next) + { + if (bp == END_OF_CHAIN) + { + if (!warned) + { + error("Warning: log file is incomplete", + NULL_PARG); + warned = TRUE; + } + break; + } if (bp->block == block) { @@ -296,4 +338,6 @@ break; } + } + } } @@ -309,8 +353,8 @@ register struct buf *bp; - for (bp = buf_head; bp != END_OF_CHAIN; bp = bp->next) + for (bp = ch_bufhead; bp != END_OF_CHAIN; bp = bp->next) if (bp->block == block) - return (1); - return (0); + return (TRUE); + return (FALSE); } @@ -331,6 +375,17 @@ new_block = pos / LBUFSIZE; - if (ispipe && pos != ch_fpos && !buffered(new_block)) - return (1); + if (!(ch_flags & CH_CANSEEK) && pos != ch_fpos && !buffered(new_block)) + { + if (ch_fpos > pos) + return (1); + while (ch_fpos < pos) + { + if (ch_forw_get() == EOI) + return (1); + if (ABORT_SIGS()) + return (1); + } + return (0); + } /* * Set read pointer. @@ -349,6 +404,6 @@ POSITION len; - if (!ispipe) - ch_fsize = filesize(file); + if (ch_flags & CH_CANSEEK) + ch_fsize = filesize(ch_file); len = ch_length(); @@ -385,5 +440,5 @@ * Look thru the buffers for the one closest to position 0. */ - firstbp = bp = buf_head; + firstbp = bp = ch_bufhead; if (bp == END_OF_CHAIN) return (1); @@ -433,9 +488,4 @@ else { -#if __ZOFFSET /* NOT WORKING */ - if (ch_fsize != NULL_POSITION && - tellpos(ch_block+1, 0) >= ch_fsize) - return (EOI); -#endif ch_block ++; ch_offset = 0; @@ -454,12 +504,7 @@ else { -#if __ZOFFSET /* NOT WORKING */ - if (tellpos(ch_block-1, LBUFSIZE-1) < ch_zero()) - return (EOI); -#else if (ch_block <= 0) return (EOI); -#endif - if (ispipe && !buffered(ch_block-1)) + if (!(ch_flags & CH_CANSEEK) && !buffered(ch_block-1)) return (EOI); ch_block--; @@ -479,15 +524,19 @@ PARG parg; - if (ch_nbufs < want_nbufs && ch_addbuf(want_nbufs - ch_nbufs)) + while (ch_nbufs < want_nbufs) { - /* - * Cannot allocate enough buffers. - * If we don't have ANY, then quit. - * Otherwise, just report the error and return. - */ - parg.p_int = want_nbufs - ch_nbufs; - error("Cannot allocate %d buffers", &parg); - if (ch_nbufs == 0) - quit(1); + if (ch_addbuf()) + { + /* + * Cannot allocate enough buffers. + * If we don't have ANY, then quit. + * Otherwise, just report the error and return. + */ + parg.p_int = want_nbufs - ch_nbufs; + error("Cannot allocate %d buffers", &parg); + if (ch_nbufs == 0) + quit(QUIT_ERROR); + break; + } } return (ch_nbufs); @@ -495,5 +544,5 @@ /* - * Flush any saved file state, including buffer contents. + * Flush (discard) any saved file state, including buffer contents. */ public void @@ -502,5 +551,5 @@ register struct buf *bp; - if (ispipe) + if (!(ch_flags & CH_CANSEEK)) { /* @@ -515,5 +564,5 @@ * Initialize all the buffers. */ - for (bp = buf_head; bp != END_OF_CHAIN; bp = bp->next) + for (bp = ch_bufhead; bp != END_OF_CHAIN; bp = bp->next) bp->block = (long)(-1); @@ -521,5 +570,5 @@ * Figure out the size of the file, if we can. */ - ch_fsize = filesize(file); + ch_fsize = filesize(ch_file); /* @@ -527,8 +576,8 @@ */ ch_fpos = 0; - ch_block = ch_fpos / LBUFSIZE; - ch_offset = ch_fpos % LBUFSIZE; + ch_block = 0; /* ch_fpos / LBUFSIZE; */ + ch_offset = 0; /* ch_fpos % LBUFSIZE; */ - if (lseek(file, (off_t)0, 0) == BAD_LSEEK) + if (lseek(ch_file, (off_t)0, 0) == BAD_LSEEK) { /* @@ -542,197 +591,173 @@ /* - * Allocate some new buffers. - * The buffers are added to the tail of the buffer chain. + * Allocate a new buffer. + * The buffer is added to the tail of the buffer chain. */ static int -ch_addbuf(nnew) - int nnew; +ch_addbuf() { register struct buf *bp; - register struct buf *newbufs; /* - * We don't have enough buffers. - * Allocate some new ones. + * Allocate and initialize a new buffer and link it + * onto the tail of the buffer list. */ - newbufs = (struct buf *) calloc(nnew, sizeof(struct buf)); - if (newbufs == NULL) + bp = (struct buf *) calloc(1, sizeof(struct buf)); + if (bp == NULL) return (1); + ch_nbufs++; + bp->block = (long)(-1); + bp->next = END_OF_CHAIN; + bp->prev = ch_buftail; + ch_buftail->next = bp; + ch_buftail = bp; + return (0); +} - /* - * Initialize the new buffers and link them together. - * Link them all onto the tail of the buffer list. - */ - ch_nbufs += nnew; - for (bp = &newbufs[0]; bp < &newbufs[nnew]; bp++) +/* + * Delete all buffers for this file. + */ + static void +ch_delbufs() +{ + register struct buf *bp; + + while (ch_bufhead != END_OF_CHAIN) { - bp->next = bp + 1; - bp->prev = bp - 1; - bp->block = (long)(-1); + bp = ch_bufhead; + bp->next->prev = bp->prev;; + bp->prev->next = bp->next; + free(bp); } - newbufs[nnew-1].next = END_OF_CHAIN; - newbufs[0].prev = buf_tail; - buf_tail->next = &newbufs[0]; - buf_tail = &newbufs[nnew-1]; - return (0); + ch_nbufs = 0; } /* - * Use the pipe file state. + * Is it possible to seek on a file descriptor? */ - public void -ch_pipe() + public int +seekable(f) + int f; { - thisfile = &pipefile; + return (lseek(f, (off_t)1, 0) != BAD_LSEEK); } /* - * Use the non-pipe file state. + * Initialize file state for a new file. */ public void -ch_nonpipe() +ch_init(f, flags) + int f; + int flags; { - thisfile = &nonpipefile; + /* + * See if we already have a filestate for this file. + */ + thisfile = (struct filestate *) get_filestate(curr_ifile); + if (thisfile == NULL) + { + /* + * Allocate and initialize a new filestate. + */ + thisfile = (struct filestate *) + calloc(1, sizeof(struct filestate)); + thisfile->buf_next = thisfile->buf_prev = END_OF_CHAIN; + thisfile->buf_block = (long)(-1); + thisfile->nbufs = 0; + thisfile->flags = 0; + thisfile->fpos = 0; + thisfile->block = 0; + thisfile->offset = 0; + thisfile->file = -1; + thisfile->fsize = NULL_POSITION; + ch_flags = flags; + /* + * Try to seek; set CH_CANSEEK if it works. + */ + if (seekable(f)) + ch_flags |= CH_CANSEEK; + set_filestate(curr_ifile, (void *) thisfile); + } + if (thisfile->file == -1) + thisfile->file = f; + ch_flush(); } -#if 0 -/* TESTING */ - -extern VOID_POINTER memchr(); -extern char linebuf[]; -extern int size_linebuf; - /* - * Analogous to forw_line(), but deals with "raw lines": - * lines which are not split for screen width. - * {{ This is supposed to be more efficient than forw_line(). }} + * Close a filestate. */ - public POSITION -forw_raw_line(curr_pos, linep) - POSITION curr_pos; - char **linep; -{ - register char *p; - register int bc; - register int avail; - register int space; - register char *q; - - if (curr_pos == NULL_POSITION || ch_seek(curr_pos) || fch_get() == EOI) - return (NULL_POSITION); - - p = linebuf; - space = size_linebuf - 1; + public void +ch_close() +{ + int keepstate = FALSE; - do + if (ch_flags & (CH_CANSEEK|CH_POPENED)) { /* - * avail = bytes available in data buffer. - * space = space left in line buffer. - * bc = byte count to move from data buffer to line buffer. + * We can seek or re-open, so we don't need to keep buffers. */ - bc = avail = buf_head->datasize - ch_offset; - if (avail <= 0) - break; + ch_delbufs(); + } else + keepstate = TRUE; + if (!(ch_flags & CH_KEEPOPEN)) + { /* - * Find the next newline in data buffer. + * We don't need to keep the file descriptor open + * (because we can re-open it.) + * But don't really close it if it was opened via popen(), + * because pclose() wants to close it. */ - q = (char *) memchr((char *) &buf_head->data[ch_offset], '\n', avail); - if (q != NULL) - { - /* - * Found a newline. - * Copy data buffer to line buffer and we're done. - */ - bc = q - (char *) &buf_head->data[ch_offset]; - if (bc > space) - bc = space; - memcpy(p, (char *) &buf_head->data[ch_offset], bc); - p += bc; - ch_offset += bc + 1; - if (ch_offset >= LBUFSIZE) - { - ch_offset = 0; - ch_block++; - } - break; - } + if (!(ch_flags & CH_POPENED)) + close(ch_file); + ch_file = -1; + } else + keepstate = TRUE; + if (!keepstate) + { /* - * Didn't find a newline. - * Copy data buffer to line buffer, - * get the next data buffer and try again. - */ - bc = avail; - if (bc > space) - bc = space; - memcpy(p, (char *) &buf_head->data[ch_offset], bc); - space -= bc; - p += bc; - ch_offset = 0; - ch_block++; - } while (fch_get() != EOI && space > 0); - - *p = '\0'; - if (linep != NULL) - *linep = linebuf; - return (ch_tell()); + * We don't even need to keep the filestate structure. + */ + free(thisfile); + thisfile = NULL; + set_filestate(curr_ifile, (void *) NULL); + } } /* - * Analogous to back_line(), but deals with "raw lines". - * {{ This is supposed to be more efficient than back_line(). }} + * Return ch_flags for the current file. */ - public POSITION -back_raw_line(curr_pos, linep) - POSITION curr_pos; - char **linep; -{ - register char *p; - register char *q; /* scratch pointer */ - register i; /* scratch index */ - register int bc; /* byte count to transfer */ - register int space; /* space left in linebuf */ - - if (curr_pos == NULL_POSITION || curr_pos <= (POSITION)1 || - ch_seek(curr_pos-2) || ch_get() == EOI) - return (NULL_POSITION); + public int +ch_getflags() +{ + return (ch_flags); +} - p = &linebuf[size_linebuf]; - *--p = '\0'; - space = size_linebuf - 1; - - do { - bc = ch_offset + 1; - if (bc > space) - bc = space; - /* - * Find the previous newline in data buffer. - */ - q = (char *) &buf_head->data[ch_offset] + 1; - for (i = bc; i > 0; i--) - if ((*--p = *--q) == '\n') - { - /* - * Found a newline. - * We're done. - */ - p++; - ch_offset -= bc - i; - ch_seek(ch_tell() + 1); - goto done; - } - /* - * Didn't find a newline. - */ - bc--; - ch_offset -= bc; - space -= bc; - } while (space > 0 && ch_block > 0 && ch_seek(ch_tell() - 1) == 0 && - fch_get() != EOI); - - done: - if (linep != NULL) - *linep = p; - return (ch_tell()); +#if 0 + public void +ch_dump(struct filestate *fs) +{ + struct buf *bp; + unsigned char *s; + + if (fs == NULL) + { + printf(" --no filestate\n"); + return; + } + printf(" file %d, flags %x, fpos %x, fsize %x, blk/off %x/%x\n", + fs->file, fs->flags, fs->fpos, + fs->fsize, fs->block, fs->offset); + printf(" %d bufs:\n", fs->nbufs); + for (bp = fs->buf_next; bp != (struct buf *)fs; bp = bp->next) + { + printf("%x: blk %x, size %x \"", + bp, bp->block, bp->datasize); + for (s = bp->data; s < bp->data + 30; s++) + if (*s >= ' ' && *s < 0x7F) + printf("%c", *s); + else + printf("."); + printf("\"\n"); + } } #endif diff -r -U2 less-252/charset.c less-278/charset.c --- less-252/charset.c Sat Oct 15 03:16:44 1994 +++ less-278/charset.c Tue Jan 31 18:55:28 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -47,6 +47,7 @@ { "ascii", "8bcccbcc18b95.b" }, { "latin1", "8bcccbcc18b95.33b." }, - { "dos", "8bcccbcc12bc5b95.98b.b" }, + { "dos", "8bcccbcc12bc5b95.b." }, { "koi8-r", "8bcccbcc18b95.b128." }, + { "next", "8bcccbcc18b95.bb125.bb" }, { NULL } }; @@ -106,5 +107,5 @@ default: error("invalid chardef", NULL_PARG); - quit(1); + quit(QUIT_ERROR); /*NOTREACHED*/ } @@ -115,5 +116,5 @@ { error("chardef longer than 256", NULL_PARG); - quit(1); + quit(QUIT_ERROR); /*NOTREACHED*/ } @@ -150,5 +151,5 @@ error("invalid charset name", NULL_PARG); - quit(1); + quit(QUIT_ERROR); /*NOTREACHED*/ } @@ -279,5 +280,5 @@ else if (c == ESC) sprintf(buf, "ESC"); - else if (!control_char(c ^ 0100)) + else if (c < 128 && !control_char(c ^ 0100)) sprintf(buf, "^%c", c ^ 0100); else diff -r -U2 less-252/cmd.h less-278/cmd.h --- less-252/cmd.h Sat Oct 15 03:16:44 1994 +++ less-278/cmd.h Tue Jan 31 18:55:29 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/cmdbuf.c less-278/cmdbuf.c --- less-252/cmdbuf.c Tue Oct 25 18:33:38 1994 +++ less-278/cmdbuf.c Tue Jan 31 18:55:31 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/command.c less-278/command.c --- less-252/command.c Sun Nov 6 18:56:19 1994 +++ less-278/command.c Tue Jan 31 18:55:32 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -36,5 +36,4 @@ extern int erase_char, kill_char; -extern int ispipe; extern int sigs; extern int quit_at_eof; @@ -128,13 +127,8 @@ mca_search() { - switch (SRCH_DIR(search_type)) - { - case SRCH_FORW: + if (search_type & SRCH_FORW) mca = A_F_SEARCH; - break; - case SRCH_BACK: + else mca = A_B_SEARCH; - break; - } clear_bot(); @@ -149,13 +143,8 @@ cmd_putstr("!"); - switch (SRCH_DIR(search_type)) - { - case SRCH_FORW: + if (search_type & SRCH_FORW) cmd_putstr("/"); - break; - case SRCH_BACK: + else cmd_putstr("?"); - break; - } #if CMD_HISTORY set_mlist(ml_search); @@ -203,7 +192,9 @@ match_brac(cbuf[1], cbuf[0], 0, number); break; +#if EXAMINE case A_EXAMINE: edit_list(cbuf); break; +#endif #if SHELL_ESCAPE case A_SHELL: @@ -456,7 +447,7 @@ * If the -E flag is set and we've hit EOF on the last file, quit. */ - if (quit_at_eof == 2 && hit_eof && + if (quit_at_eof == OPT_ONPLUS && hit_eof && next_ifile(curr_ifile) == NULL_IFILE) - quit(0); + quit(QUIT_OK); /* @@ -550,5 +541,5 @@ { error("ungetcc overflow", NULL_PARG); - quit(1); + quit(QUIT_ERROR); } *ungotp++ = c; @@ -592,5 +583,5 @@ * in the command line list. */ - if (SRCH_DIR(search_type) == SRCH_FORW) + if (search_type & SRCH_FORW) nomore = edit_first(); else @@ -626,8 +617,8 @@ * Move on to the next file. */ - if (SRCH_DIR(search_type) == SRCH_BACK) - nomore = edit_prev(1); - else + if (search_type & SRCH_FORW) nomore = edit_next(1); + else + nomore = edit_prev(1); if (nomore) break; @@ -648,5 +639,5 @@ */ if (edit_ifile(save_ifile)) - quit(-1); + quit(QUIT_ERROR); } } @@ -684,5 +675,5 @@ psignals(); if (quitting) - quit(-1); + quit(QUIT_SAVED_STATUS); } @@ -896,7 +887,9 @@ * Don't flush the buffers on a pipe! */ - ch_flush(); - if (!ispipe) + if (ch_getflags() & CH_CANSEEK) + { + ch_flush(); clr_linenum(); + } /* FALLTHRU */ case A_REPAINT: @@ -972,5 +965,5 @@ * Exit. */ - quit(0); + quit(QUIT_OK); /* @@ -1064,4 +1057,5 @@ case A_EXAMINE: +#if EXAMINE /* * Edit a new file. Get the filename. @@ -1070,4 +1064,8 @@ c = getcc(); goto again; +#else + error("Command not available", NULL_PARG); + break; +#endif case A_VISUAL: @@ -1093,5 +1091,5 @@ */ if (edit_ifile(curr_ifile)) - quit(-1); + quit(QUIT_ERROR); break; #else @@ -1109,5 +1107,5 @@ { if (quit_at_eof && hit_eof) - quit(0); + quit(QUIT_OK); parg.p_string = (number > 1) ? "(N-th) " : ""; error("No %snext file", &parg); @@ -1200,6 +1198,6 @@ break; -#if PIPEC case A_PIPE: +#if PIPEC start_mca(A_PIPE, "|mark: ", (void*)NULL); c = getcc(); @@ -1214,4 +1212,7 @@ c = getcc(); goto again; +#else + error("Command not available", NULL_PARG); + break; #endif diff -r -U2 less-252/configure less-278/configure --- less-252/configure Wed Nov 16 14:24:58 1994 +++ less-278/configure Wed Feb 15 01:16:39 1995 @@ -1,43 +1,15 @@ #!/bin/sh -# Guess values for system-dependent variables and create Makefiles. -# Generated automatically using autoconf version 1.11 -# Copyright (C) 1991, 1992, 1993, 1994 Free Software Foundation, Inc. - -# This configure script is free software; you can redistribute it and/or -# modify it under the terms of the GNU General Public License as published -# by the Free Software Foundation; either version 2, or (at your option) -# any later version. - -# This script is distributed in the hope that it will be useful, but -# WITHOUT ANY WARRANTY; without even the implied warranty of -# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General -# Public License for more details. - -# You should have received a copy of the GNU General Public License -# along with this program; if not, write to the Free Software -# Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. -# Save the original args to write them into config.status later. -configure_args="$*" +# Guess values for system-dependent variables and create Makefiles. +# Generated automatically using autoconf version 2.1 +# Copyright (C) 1992, 1993, 1994 Free Software Foundation, Inc. +# +# This configure script is free software; the Free Software Foundation +# gives unlimited permission to copy, distribute and modify it. -# Only options that might do something get documented. -ac_usage="Usage: configure [options] [host] -Options: [defaults in brackets after descriptions] ---build=BUILD configure for building on BUILD [BUILD=HOST] ---disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) ---enable-FEATURE[=ARG] include FEATURE [ARG=yes] ---exec-prefix=PREFIX install host dependent files in PREFIX [/usr/local] ---help print this message ---host=HOST configure for HOST [guessed] ---prefix=PREFIX install host independent files in PREFIX [/usr/local] ---quiet, --silent do not print \`checking for...' messages ---srcdir=DIR find the sources in DIR [configure dir or ..] ---target=TARGET configure for TARGET [TARGET=HOST] ---verbose print results of checks ---version print the version of autoconf that created configure ---with-PACKAGE[=ARG] use PACKAGE [ARG=yes] ---without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) ---x-includes=DIR X include files are in DIR ---x-libraries=DIR X library files are in DIR" +# Defaults: +ac_help= +ac_default_prefix=/usr/local +# Any additions from configure.in: # Initialize some variables set by options. @@ -45,19 +17,24 @@ # dashes changed to underlines. build=NONE -exec_prefix= +cache_file=./config.cache +exec_prefix=NONE host=NONE no_create= nonopt=NONE -norecursion= -prefix= -program_prefix= -program_suffix= -program_transform_name= +no_recursion= +prefix=NONE +program_prefix=NONE +program_suffix=NONE +program_transform_name=s,x,x, silent= +site= srcdir= target=NONE verbose= -x_includes= -x_libraries= +x_includes=NONE +x_libraries=NONE + +# Initialize some other variables. +subdirs= ac_prev= @@ -72,7 +49,4 @@ fi - # Accept (but ignore some of) the important Cygnus configure - # options, so we can diagnose typos. - case "$ac_option" in -*=*) ac_optarg=`echo "$ac_option" | sed 's/[-_a-zA-Z0-9]*=//'` ;; @@ -80,4 +54,6 @@ esac + # Accept the important Cygnus configure options, so we can diagnose typos. + case "$ac_option" in @@ -87,9 +63,16 @@ build="$ac_optarg" ;; + -cache-file | --cache-file | --cache-fil | --cache-fi \ + | --cache-f | --cache- | --cache | --cach | --cac | --ca | --c) + ac_prev=cache_file ;; + -cache-file=* | --cache-file=* | --cache-fil=* | --cache-fi=* \ + | --cache-f=* | --cache-=* | --cache=* | --cach=* | --cac=* | --ca=* | --c=*) + cache_file="$ac_optarg" ;; + -disable-* | --disable-*) ac_feature=`echo $ac_option|sed -e 's/-*disable-//'` - # Reject names that aren't valid shell variable names. + # Reject names that are not valid shell variable names. if test -n "`echo $ac_feature| sed 's/[-a-zA-Z0-9_]//g'`"; then - echo "configure: $ac_feature: invalid feature name" >&2; exit 1 + { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } fi ac_feature=`echo $ac_feature| sed 's/-/_/g'` @@ -98,7 +81,7 @@ -enable-* | --enable-*) ac_feature=`echo $ac_option|sed -e 's/-*enable-//' -e 's/=.*//'` - # Reject names that aren't valid shell variable names. + # Reject names that are not valid shell variable names. if test -n "`echo $ac_feature| sed 's/[-_a-zA-Z0-9]//g'`"; then - echo "configure: $ac_feature: invalid feature name" >&2; exit 1 + { echo "configure: error: $ac_feature: invalid feature name" 1>&2; exit 1; } fi ac_feature=`echo $ac_feature| sed 's/-/_/g'` @@ -109,5 +92,4 @@ eval "enable_${ac_feature}='$ac_optarg'" ;; - # For backward compatibility, recognize -exec-prefix and --exec_prefix. -exec-prefix | --exec_prefix | --exec-prefix | --exec-prefi \ | --exec-pref | --exec-pre | --exec-pr | --exec-p | --exec- \ @@ -120,9 +102,40 @@ -gas | --gas | --ga | --g) - with_gas=yes ;; # Obsolete; use --with-gas. + # Obsolete; use --with-gas. + with_gas=yes ;; -help | --help | --hel | --he) + # Omit some internal or obsolete options to make the list less imposing. + # This message is too long to be a string in the A/UX 3.1 sh. cat << EOF -$ac_usage +Usage: configure [options] [host] +Options: [defaults in brackets after descriptions] +Configuration: + --cache-file=FILE cache test results in FILE + --help print this message + --no-create do not create output files + --quiet, --silent do not print \`checking...' messages + --version print the version of autoconf that created configure +Directory and file names: + --prefix=PREFIX install architecture-independent files in PREFIX + [$ac_default_prefix] + --exec-prefix=PREFIX install architecture-dependent files in PREFIX + [same as prefix] + --srcdir=DIR find the sources in DIR [configure dir or ..] + --program-prefix=PREFIX prepend PREFIX to installed program names + --program-suffix=SUFFIX append SUFFIX to installed program names + --program-transform-name=PROGRAM run sed PROGRAM on installed program names +Host type: + --build=BUILD configure for building on BUILD [BUILD=HOST] + --host=HOST configure for HOST [guessed] + --target=TARGET configure for TARGET [TARGET=HOST] +Features and packages: + --disable-FEATURE do not include FEATURE (same as --enable-FEATURE=no) + --enable-FEATURE[=ARG] include FEATURE [ARG=yes] + --with-PACKAGE[=ARG] use PACKAGE [ARG=yes] + --without-PACKAGE do not use PACKAGE (same as --with-PACKAGE=no) + --x-includes=DIR X include files are in DIR + --x-libraries=DIR X library files are in DIR +--enable and --with options recognized:$ac_help EOF exit 0 ;; @@ -134,5 +147,6 @@ -nfp | --nfp | --nf) - with_fp=no ;; # Obsolete; use --without-fp. + # Obsolete; use --without-fp. + with_fp=no ;; -no-create | --no-create | --no-creat | --no-crea | --no-cre \ @@ -140,7 +154,7 @@ no_create=yes ;; - -norecursion | --norecursion | --norecursio | --norecursi \ - | --norecurs | --norecur | --norecu | --norec | --nore | --nor) - norecursion=yes ;; + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) + no_recursion=yes ;; -prefix | --prefix | --prefi | --pref | --pre | --pr | --p) @@ -184,4 +198,9 @@ silent=yes ;; + -site | --site | --sit) + ac_prev=site ;; + -site=* | --site=* | --sit=*) + site="$ac_optarg" ;; + -srcdir | --srcdir | --srcdi | --srcd | --src | --sr) ac_prev=srcdir ;; @@ -198,12 +217,12 @@ -version | --version | --versio | --versi | --vers) - echo "configure generated by autoconf version 1.11" + echo "configure generated by autoconf version 2.1" exit 0 ;; -with-* | --with-*) ac_package=`echo $ac_option|sed -e 's/-*with-//' -e 's/=.*//'` - # Reject names that aren't valid shell variable names. + # Reject names that are not valid shell variable names. if test -n "`echo $ac_package| sed 's/[-_a-zA-Z0-9]//g'`"; then - echo "configure: $ac_package: invalid package name" >&2; exit 1 + { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } fi ac_package=`echo $ac_package| sed 's/-/_/g'` @@ -216,12 +235,14 @@ -without-* | --without-*) ac_package=`echo $ac_option|sed -e 's/-*without-//'` - # Reject names that aren't valid shell variable names. + # Reject names that are not valid shell variable names. if test -n "`echo $ac_package| sed 's/[-a-zA-Z0-9_]//g'`"; then - echo "configure: $ac_package: invalid package name" >&2; exit 1 + { echo "configure: error: $ac_package: invalid package name" 1>&2; exit 1; } fi ac_package=`echo $ac_package| sed 's/-/_/g'` eval "with_${ac_package}=no" ;; - --x) with_x=yes ;; # Obsolete; use --with-x. + --x) + # Obsolete; use --with-x. + with_x=yes ;; -x-includes | --x-includes | --x-include | --x-includ | --x-inclu \ @@ -239,13 +260,13 @@ x_libraries="$ac_optarg" ;; - -*) echo "configure: $ac_option: invalid option; use --help to show usage" >&2; exit 1 + -*) { echo "configure: error: $ac_option: invalid option; use --help to show usage" 1>&2; exit 1; } ;; *) if test -n "`echo $ac_option| sed 's/[-a-z0-9.]//g'`"; then - echo "configure: warning: $ac_option: invalid host type" >&2 + echo "configure: warning: $ac_option: invalid host type" 1>&2 fi if test "x$nonopt" != xNONE; then - echo "configure: can only configure for one host and one target at a time" >&2; exit 1 + { echo "configure: error: can only configure for one host and one target at a time" 1>&2; exit 1; } fi nonopt="$ac_option" @@ -256,29 +277,50 @@ if test -n "$ac_prev"; then - echo "configure: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" >&2; exit 1 + { echo "configure: error: missing argument to --`echo $ac_prev | sed 's/_/-/g'`" 1>&2; exit 1; } fi trap 'rm -fr conftest* confdefs* core $ac_clean_files; exit 1' 1 2 15 -trap 'rm -fr confdefs* $ac_clean_files' 0 -# Save the original args if we used an alternate arg parser. -ac_configure_temp="${configure_args-$*}" -# Strip out --no-create and --norecursion so they don't pile up. -configure_args= -for ac_arg in $ac_configure_temp; do +# File descriptor usage: +# 0 unused; standard input +# 1 file creation +# 2 errors and warnings +# 3 unused; some systems may open it to /dev/tty +# 4 checking for... messages and results +# 5 compiler messages saved in config.log +if test "$silent" = yes; then + exec 4>/dev/null +else + exec 4>&1 +fi +exec 5>./config.log + +echo "\ +This file contains any messages produced by compilers while +running configure, to aid debugging if configure makes a mistake. +" 1>&5 + +# Strip out --no-create and --no-recursion so they do not pile up. +# Also quote any args containing shell metacharacters. +ac_configure_args= +for ac_arg +do case "$ac_arg" in -no-create | --no-create | --no-creat | --no-crea | --no-cre \ | --no-cr | --no-c) ;; - -norecursion | --norecursion | --norecursio | --norecursi \ - | --norecurs | --norecur | --norecu | --norec | --nore | --nor) ;; - *) configure_args="$configure_args $ac_arg" ;; + -no-recursion | --no-recursion | --no-recursio | --no-recursi \ + | --no-recurs | --no-recur | --no-recu | --no-rec | --no-re | --no-r) ;; + *" "*|*" "*|*[\[\]\~\#\$\^\&\*\(\)\{\}\\\|\;\<\>\?]*) + ac_configure_args="$ac_configure_args '$ac_arg'" ;; + *) ac_configure_args="$ac_configure_args $ac_arg" ;; esac done # NLS nuisances. +# Only set LANG and LC_ALL to C if already set. # These must not be set unconditionally because not all systems understand # e.g. LANG=C (notably SCO). -if test "${LC_ALL+set}" = 'set'; then LC_ALL=C; export LC_ALL; fi -if test "${LANG+set}" = 'set'; then LANG=C; export LANG; fi +if test "${LC_ALL+set}" = set; then LC_ALL=C; export LC_ALL; fi +if test "${LANG+set}" = set; then LANG=C; export LANG; fi # confdefs.h avoids OS command line length limits that DEFS can exceed. @@ -294,5 +336,5 @@ if test -z "$srcdir"; then ac_srcdir_defaulted=yes - # Try the directory containing this script, then `..'. + # Try the directory containing this script, then its parent. ac_prog=$0 ac_confdir=`echo $ac_prog|sed 's%/[^/][^/]*$%%'` @@ -302,79 +344,193 @@ srcdir=.. fi +else + ac_srcdir_defaulted=no fi if test ! -r $srcdir/$ac_unique_file; then - if test x$ac_srcdir_defaulted = xyes; then - echo "configure: can not find sources in ${ac_confdir} or .." >&2; exit 1 + if test "$ac_srcdir_defaulted" = yes; then + { echo "configure: error: can not find sources in $ac_confdir or .." 1>&2; exit 1; } else - echo "configure: can not find sources in ${srcdir}" >&2; exit 1 + { echo "configure: error: can not find sources in $srcdir" 1>&2; exit 1; } + fi +fi +srcdir=`echo "${srcdir}" | sed 's%\([^/]\)/*$%\1%'` + +# Prefer explicitly selected file to automatically selected ones. +if test -z "$CONFIG_SITE"; then + if test "x$prefix" != xNONE; then + CONFIG_SITE="$prefix/share/config.site $prefix/etc/config.site" + else + CONFIG_SITE="$ac_default_prefix/share/config.site $ac_default_prefix/etc/config.site" + fi +fi +for ac_site_file in $CONFIG_SITE; do + if test -r "$ac_site_file"; then + echo "loading site script $ac_site_file" + . "$ac_site_file" fi +done + +if test -r "$cache_file"; then + echo "loading cache $cache_file" + . $cache_file +else + echo "creating cache $cache_file" + > $cache_file fi + ac_ext=c # CFLAGS is not in ac_cpp because -g, -O, etc. are not valid cpp options. -ac_cpp='${CPP}' -ac_compile='${CC-cc} $CFLAGS $LDFLAGS conftest.${ac_ext} -o conftest $LIBS >/dev/null 2>&1' +ac_cpp='$CPP $CPPFLAGS' +ac_compile='${CC-cc} $CFLAGS $CPPFLAGS conftest.$ac_ext -c 1>&5 2>&5' +ac_link='${CC-cc} $CFLAGS $CPPFLAGS $LDFLAGS conftest.$ac_ext -o conftest $LIBS 1>&5 2>&5' + +if (echo "testing\c"; echo 1,2,3) | grep c >/dev/null; then + # Stardent Vistra SVR4 grep lacks -e, says ghazi@caip.rutgers.edu. + if (echo -n testing; echo 1,2,3) | sed s/-n/xn/ | grep xn >/dev/null; then + ac_n= ac_c=' +' ac_t=' ' + else + ac_n=-n ac_c= ac_t= + fi +else + ac_n= ac_c='\c' ac_t= +fi -if test -z "$CC"; then - # Extract the first word of `gcc', so it can be a program name with args. - set ac_dummy gcc; ac_word=$2 - test -n "$silent" || echo "checking for $ac_word" +# Extract the first word of "gcc", so it can be a program name with args. +set dummy gcc; ac_word=$2 +echo $ac_n "checking for $ac_word""... $ac_c" 1>&4 +if eval "test \"`echo '${'ac_cv_prog_CC'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + if test -n "$CC"; then + ac_cv_prog_CC="$CC" # Let the user override the test. +else IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do test -z "$ac_dir" && ac_dir=. if test -f $ac_dir/$ac_word; then - CC="gcc" + ac_cv_prog_CC="gcc" break fi done IFS="$ac_save_ifs" + test -z "$ac_cv_prog_CC" && ac_cv_prog_CC="cc" +fi fi -test -z "$CC" && CC="cc" -test -n "$CC" && test -n "$verbose" && echo " setting CC to $CC" +CC="$ac_cv_prog_CC" +if test -n "$CC"; then + echo "$ac_t""$CC" 1>&4 +else + echo "$ac_t""no" 1>&4 +fi + -# Find out if we are using GNU C, under whatever name. -cat > conftest.c <&4 +if eval "test \"`echo '${'ac_cv_prog_gcc'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.c < conftest.out 2>&1 -if egrep yes conftest.out >/dev/null 2>&1; then - GCC=1 # For later tests. +if ${CC-cc} -E conftest.c 2>&5 | egrep yes >/dev/null 2>&1; then + ac_cv_prog_gcc=yes +else + ac_cv_prog_gcc=no +fi +fi +echo "$ac_t""$ac_cv_prog_gcc" 1>&4 +if test $ac_cv_prog_gcc = yes; then + GCC=yes + if test "${CFLAGS+set}" != set; then + echo $ac_n "checking whether ${CC-cc} accepts -g""... $ac_c" 1>&4 +if eval "test \"`echo '${'ac_cv_prog_gcc_g'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + echo 'void f(){}' > conftest.c +if test -z "`${CC-cc} -g -c conftest.c 2>&1`"; then + ac_cv_prog_gcc_g=yes +else + ac_cv_prog_gcc_g=no fi rm -f conftest* -test -n "$silent" || echo "checking how to run the C preprocessor" +fi + echo "$ac_t""$ac_cv_prog_gcc_g" 1>&4 + if test $ac_cv_prog_gcc_g = yes; then + CFLAGS="-g -O" + else + CFLAGS="-O" + fi + fi +else + GCC= + test "${CFLAGS+set}" = set || CFLAGS="-g" +fi + +echo $ac_n "checking for POSIXized ISC""... $ac_c" 1>&4 +if test -d /etc/conf/kconfig.d && + grep _POSIX_VERSION /usr/include/sys/unistd.h >/dev/null 2>&1 +then + echo "$ac_t""yes" 1>&4 + ISC=yes # If later tests want to check for ISC. + cat >> confdefs.h <<\EOF +#define _POSIX_SOURCE 1 +EOF + + if test "$GCC" = yes; then + CC="$CC -posix" + else + CC="$CC -Xp" + fi +else + echo "$ac_t""no" 1>&4 + ISC= +fi + +echo $ac_n "checking how to run the C preprocessor""... $ac_c" 1>&4 +# On Suns, sometimes $CPP names a directory. +if test -n "$CPP" && test -d "$CPP"; then + CPP= +fi if test -z "$CPP"; then - # This must be in double quotes, not single quotes, because CPP may get - # substituted into the Makefile and ``${CC-cc}'' will simply confuse - # make. It must be expanded now. +if eval "test \"`echo '${'ac_cv_prog_CPP'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + # This must be in double quotes, not single quotes, because CPP may get + # substituted into the Makefile and "${CC-cc}" will confuse make. CPP="${CC-cc} -E" - cat > conftest.${ac_ext} < conftest.$ac_ext < +#include Syntax Error EOF -# Some shells (Coherent) do redirections in the wrong order, so need -# the parens. -ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"` +eval "$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : else + echo "$ac_err" >&5 rm -rf conftest* CPP="${CC-cc} -E -traditional-cpp" - cat > conftest.${ac_ext} < conftest.$ac_ext < +#include Syntax Error EOF -# Some shells (Coherent) do redirections in the wrong order, so need -# the parens. -ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"` +eval "$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then : else + echo "$ac_err" >&5 rm -rf conftest* CPP=/lib/cpp @@ -383,69 +539,96 @@ fi rm -f conftest* + ac_cv_prog_CPP="$CPP" fi -test -n "$verbose" && echo " setting CPP to $CPP" +fi +CPP="$ac_cv_prog_CPP" +echo "$ac_t""$CPP" 1>&4 -if test -n "$GCC"; then - test -n "$silent" || echo "checking whether -traditional is needed" - ac_pattern="Autoconf.*'x'" - ac_prog='#include -Autoconf TIOCGETP' - cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_prog_gcc_traditional'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + ac_pattern="Autoconf.*'x'" + cat > conftest.$ac_ext < +Autoconf TIOCGETP EOF -eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1" -if egrep "$ac_pattern" conftest.out >/dev/null 2>&1; then +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "$ac_pattern" >/dev/null 2>&1; then rm -rf conftest* - ac_need_trad=1 - + ac_cv_prog_gcc_traditional=yes +else + rm -rf conftest* + ac_cv_prog_gcc_traditional=no fi rm -f conftest* - if test -z "$ac_need_trad"; then - ac_prog='#include -Autoconf TCGETA' - cat > conftest.${ac_ext} < conftest.$ac_ext < +Autoconf TCGETA EOF -eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1" -if egrep "$ac_pattern" conftest.out >/dev/null 2>&1; then +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "$ac_pattern" >/dev/null 2>&1; then rm -rf conftest* - ac_need_trad=1 - + ac_cv_prog_gcc_traditional=yes fi rm -f conftest* fi - test -n "$ac_need_trad" && CC="$CC -traditional" +fi + echo "$ac_t""$ac_cv_prog_gcc_traditional" 1>&4 + if test $ac_cv_prog_gcc_traditional = yes; then + CC="$CC -traditional" + fi fi -# Make sure to not get the incompatible SysV /etc/install and -# /usr/sbin/install, which might be in PATH before a BSD-like install, -# or the SunOS /usr/etc/install directory, or the AIX /bin/install, -# or the AFS install, which mishandles nonexistent args, or -# /usr/ucb/install on SVR4, which tries to use the nonexistent group -# `staff', or /sbin/install on IRIX which has incompatible command-line -# syntax. Sigh. -# -# On most BSDish systems install is in /usr/bin, not /usr/ucb -# anyway. -# This turns out not to be true, so the mere pathname isn't an indication -# of whether the program works. What we really need is a set of tests for -# the install program to see if it actually works in all the required ways. -# -# Avoid using ./install, which might have been erroneously created -# by make from ./install.sh. -if test -z "${INSTALL}"; then - test -n "$silent" || echo "checking for a BSD compatible install" - IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" +ac_aux_dir= +for ac_dir in $srcdir $srcdir/.. $srcdir/../..; do + if test -f $ac_dir/install-sh; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install-sh -c" + break + elif test -f $ac_dir/install.sh; then + ac_aux_dir=$ac_dir + ac_install_sh="$ac_aux_dir/install.sh -c" + break + fi +done +if test -z "$ac_aux_dir"; then + { echo "configure: error: can not find install-sh or install.sh in $srcdir $srcdir/.. $srcdir/../.." 1>&2; exit 1; } +fi +ac_config_guess=$ac_aux_dir/config.guess +ac_config_sub=$ac_aux_dir/config.sub +ac_configure=$ac_aux_dir/configure # This should be Cygnus configure. + +# Find a good install program. We prefer a C program (faster), +# so one script is as good as another. But avoid the broken or +# incompatible versions: +# SysV /etc/install, /usr/sbin/install +# SunOS /usr/etc/install +# IRIX /sbin/install +# AIX /bin/install +# AFS /usr/afsws/bin/install, which mishandles nonexistent args +# SVR4 /usr/ucb/install, which tries to use the nonexistent group "staff" +# ./install, which can be erroneously created by make from ./install.sh. +echo $ac_n "checking for a BSD compatible install""... $ac_c" 1>&4 +if test -z "$INSTALL"; then +if eval "test \"`echo '${'ac_cv_path_install'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + IFS="${IFS= }"; ac_save_ifs="$IFS"; IFS="${IFS}:" for ac_dir in $PATH; do case "$ac_dir" in - ''|.|/etc|/sbin|/usr/sbin|/usr/etc|/usr/afsws/bin|/usr/ucb) ;; + ''|.|/etc|/usr/sbin|/usr/etc|/sbin|/usr/afsws/bin|/usr/ucb) ;; *) # OSF1 and SCO ODT 3.0 have their own names for install. - for ac_prog in installbsd scoinst install; do + for ac_prog in ginstall installbsd scoinst install; do if test -f $ac_dir/$ac_prog; then if test $ac_prog = install && @@ -455,5 +638,5 @@ : else - INSTALL="$ac_dir/$ac_prog -c" + ac_cv_path_install="$ac_dir/$ac_prog -c" break 2 fi @@ -464,158 +647,213 @@ done IFS="$ac_save_ifs" -fi - -if test -z "$INSTALL"; then # As a last resort, use the slow shell script. - for ac_dir in ${srcdir} ${srcdir}/.. ${srcdir}/../..; do - if test -f $ac_dir/install.sh; then - INSTALL="$ac_dir/install.sh -c"; break - fi - done + test -z "$ac_cv_path_install" && ac_cv_path_install="$ac_install_sh" fi -if test -z "$INSTALL"; then - echo "configure: can not find install.sh in ${srcdir} or ${srcdir}/.. or ${srcdir}/../.." >&2; exit 1 + INSTALL="$ac_cv_path_install" fi -test -n "$verbose" && echo " setting INSTALL to $INSTALL" +echo "$ac_t""$INSTALL" 1>&4 -# Use test -z because SunOS4 sh mishandles ${INSTALL_PROGRAM-'${INSTALL}'}. +# Use test -z because SunOS4 sh mishandles braces in ${var-val}. # It thinks the first close brace ends the variable substitution. test -z "$INSTALL_PROGRAM" && INSTALL_PROGRAM='${INSTALL}' -test -n "$verbose" && echo " setting INSTALL_PROGRAM to $INSTALL_PROGRAM" test -z "$INSTALL_DATA" && INSTALL_DATA='${INSTALL} -m 644' -test -n "$verbose" && echo " setting INSTALL_DATA to $INSTALL_DATA" TERMLIBS= -ac_save_LIBS="${LIBS}" -LIBS="${LIBS} -lcurses" -ac_have_lib="" -test -n "$silent" || echo "checking for -lcurses" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_lib_curses'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + ac_save_LIBS="$LIBS" +LIBS="$LIBS -lcurses " +cat > conftest.$ac_ext <&4 + TERMLIBS="$TERMLIBS -lcurses" else - :; + echo "$ac_t""no" 1>&4 fi -ac_save_LIBS="${LIBS}" -LIBS="${LIBS} -ltermcap" -ac_have_lib="" -test -n "$silent" || echo "checking for -ltermcap" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_lib_termcap'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + ac_save_LIBS="$LIBS" +LIBS="$LIBS -ltermcap " +cat > conftest.$ac_ext <&4 + TERMLIBS="$TERMLIBS -ltermcap" else - :; + echo "$ac_t""no" 1>&4 fi -ac_save_LIBS="${LIBS}" -LIBS="${LIBS} -ltermlib" -ac_have_lib="" -test -n "$silent" || echo "checking for -ltermlib" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_lib_termlib'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + ac_save_LIBS="$LIBS" +LIBS="$LIBS -ltermlib " +cat > conftest.$ac_ext <&4 + have_termlib=yes else - :; have_termlib=no + echo "$ac_t""no" 1>&4 +have_termlib=no fi -ac_save_LIBS="${LIBS}" -LIBS="${LIBS} -lgen" -ac_have_lib="" -test -n "$silent" || echo "checking for -lgen" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_lib_gen'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + ac_save_LIBS="$LIBS" +LIBS="$LIBS -lgen " +cat > conftest.$ac_ext <&4 + ac_tr_lib=HAVE_LIB`echo gen | tr '[a-z]' '[A-Z]'` + cat >> confdefs.h <&4 fi -ac_save_LIBS="${LIBS}" -LIBS="${LIBS} -lintl" -ac_have_lib="" -test -n "$silent" || echo "checking for -lintl" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_lib_intl'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + ac_save_LIBS="$LIBS" +LIBS="$LIBS -lintl " +cat > conftest.$ac_ext <&4 + ac_tr_lib=HAVE_LIB`echo intl | tr '[a-z]' '[A-Z]'` + cat >> confdefs.h <&4 fi -test -n "$silent" || echo "checking termlib" +echo $ac_n "checking for working terminal libraries""... $ac_c" 1>&4 SAVE_LIBS=$LIBS LIBS="$LIBS $TERMLIBS" -cat > conftest.${ac_ext} < conftest.$ac_ext <&4 +else LIBS="$SAVE_LIBS" if test $have_termlib = yes; then LIBS="$LIBS -ltermlib" + echo "$ac_t""using -ltermlib" 1>&4 + else + echo "$ac_t""TERMINAL LIBRARY BROKEN - configure failed" 1>&4 + exit 1 fi fi -test -n "$silent" || echo "checking for ANSI C header files" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_c_cross'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + if test "$cross_compiling" = yes; then + ac_cv_cross=yes +else +cat > conftest.$ac_ext </dev/null; then + ac_cv_c_cross=no +else + ac_cv_c_cross=yes +fi +fi +rm -fr conftest* +fi +cross_compiling=$ac_cv_c_cross +echo "$ac_t""$ac_cv_c_cross" 1>&4 + +echo $ac_n "checking for ANSI C header files""... $ac_c" 1>&4 +if eval "test \"`echo '${'ac_cv_header_stdc'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < @@ -639,22 +912,64 @@ #include EOF -# Some shells (Coherent) do redirections in the wrong order, so need -# the parens. -ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"` +eval "$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* + ac_cv_header_stdc=yes +else + echo "$ac_err" >&5 + rm -rf conftest* + ac_cv_header_stdc=no +fi +rm -f conftest* + +if test $ac_cv_header_stdc = yes; then # SunOS 4.x string.h does not declare mem*, contrary to ANSI. -echo '#include "confdefs.h" -#include ' > conftest.${ac_ext} -eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1" -if egrep "memchr" conftest.out >/dev/null 2>&1; then +cat > conftest.$ac_ext < +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "memchr" >/dev/null 2>&1; then + : +else + rm -rf conftest* + ac_cv_header_stdc=no +fi +rm -f conftest* + +fi + +if test $ac_cv_header_stdc = yes; then + # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. +cat > conftest.$ac_ext < +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "free" >/dev/null 2>&1; then + : +else rm -rf conftest* - # SGI's /bin/cc from Irix-4.0.5 gets non-ANSI ctype macros unless using -ansi. -cat > conftest.${ac_ext} < conftest.$ac_ext < #define ISLOWER(c) ('a' <= (c) && (c) <= 'z') #define TOUPPER(c) (ISLOWER(c) ? 'A' + ((c) - 'a') : (c)) -#define XOR(e,f) (((e) && !(f)) || (!(e) && (f))) +#define XOR(e, f) (((e) && !(f)) || (!(e) && (f))) int main () { int i; for (i = 0; i < 256; i++) if (XOR (islower (i), ISLOWER (i)) || toupper (i) != TOUPPER (i)) exit(2); @@ -662,146 +977,141 @@ EOF -eval $ac_compile +eval $ac_link if test -s conftest && (./conftest; exit) 2>/dev/null; then - # ISC 2.0.2 stdlib.h does not declare free, contrary to ANSI. -echo '#include "confdefs.h" -#include ' > conftest.${ac_ext} -eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1" -if egrep "free" conftest.out >/dev/null 2>&1; then - rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining STDC_HEADERS" -echo "#define" STDC_HEADERS "1" >> confdefs.h -DEFS="$DEFS -DSTDC_HEADERS=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}STDC_HEADERS\${ac_dB}STDC_HEADERS\${ac_dC}1\${ac_dD} -\${ac_uA}STDC_HEADERS\${ac_uB}STDC_HEADERS\${ac_uC}1\${ac_uD} -\${ac_eA}STDC_HEADERS\${ac_eB}STDC_HEADERS\${ac_eC}1\${ac_eD} -" -} - - + : +else + ac_cv_header_stdc=no fi -rm -f conftest* - - fi rm -fr conftest* - fi -rm -f conftest* - +fi +echo "$ac_t""$ac_cv_header_stdc" 1>&4 +if test $ac_cv_header_stdc = yes; then + cat >> confdefs.h <<\EOF +#define STDC_HEADERS 1 +EOF fi -rm -f conftest* for ac_hdr in ctype.h errno.h fcntl.h stdio.h termcap.h termio.h termios.h time.h unistd.h values.h sys/ioctl.h sys/stream.h sys/ptem.h do -ac_tr_hdr=HAVE_`echo $ac_hdr | tr '[a-z]./' '[A-Z]__'` -test -n "$silent" || echo "checking for ${ac_hdr}" -cat > conftest.${ac_ext} < -EOF -# Some shells (Coherent) do redirections in the wrong order, so need -# the parens. -ac_err=`eval "($ac_cpp conftest.${ac_ext} >/dev/null) 2>&1"` +ac_safe=`echo "$ac_hdr" | tr './\055' '___'` +echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&4 +if eval "test \"`echo '${'ac_cv_header_$ac_safe'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < +EOF +eval "$ac_cpp conftest.$ac_ext >/dev/null 2>conftest.out" +ac_err=`grep -v '^ *+' conftest.out` if test -z "$ac_err"; then rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining ${ac_tr_hdr}" -echo "#define" ${ac_tr_hdr} "1" >> confdefs.h -DEFS="$DEFS -D${ac_tr_hdr}=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}${ac_tr_hdr}\${ac_dB}${ac_tr_hdr}\${ac_dC}1\${ac_dD} -\${ac_uA}${ac_tr_hdr}\${ac_uB}${ac_tr_hdr}\${ac_uC}1\${ac_uD} -\${ac_eA}${ac_tr_hdr}\${ac_eB}${ac_tr_hdr}\${ac_eC}1\${ac_eD} -" -} - - + eval "ac_cv_header_$ac_safe=yes" +else + echo "$ac_err" >&5 + rm -rf conftest* + eval "ac_cv_header_$ac_safe=no" fi rm -f conftest* +fi +if eval "test \"`echo '$ac_cv_header_'$ac_safe`\" = yes"; then + echo "$ac_t""yes" 1>&4 + ac_tr_hdr=HAVE_`echo $ac_hdr | tr '[a-z]./\055' '[A-Z]___'` + cat >> confdefs.h <&4 +fi done -test -n "$silent" || echo "checking for off_t in sys/types.h" -echo '#include "confdefs.h" -#include ' > conftest.${ac_ext} -eval "$ac_cpp conftest.${ac_ext} > conftest.out 2>&1" -if egrep "off_t" conftest.out >/dev/null 2>&1; then - : +echo $ac_n "checking for off_t""... $ac_c" 1>&4 +if eval "test \"`echo '${'ac_cv_type_off_t'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < +#if STDC_HEADERS +#include +#endif +EOF +if (eval "$ac_cpp conftest.$ac_ext") 2>&5 | + egrep "off_t" >/dev/null 2>&1; then + rm -rf conftest* + ac_cv_type_off_t=yes else rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining" off_t to be "long" -echo "#define" off_t "long" >> confdefs.h -DEFS="$DEFS -Doff_t=long" -ac_sed_defs="${ac_sed_defs}\${ac_dA}off_t\${ac_dB}off_t\${ac_dC}long\${ac_dD} -\${ac_uA}off_t\${ac_uB}off_t\${ac_uC}long\${ac_uD} -\${ac_eA}off_t\${ac_eB}off_t\${ac_eC}long\${ac_eD} -" -} - + ac_cv_type_off_t=no fi rm -f conftest* -test -n "$silent" || echo "checking for void" -cat > conftest.${ac_ext} <&4 +if test $ac_cv_type_off_t = no; then + cat >> confdefs.h <<\EOF +#define off_t long +EOF + +fi + +echo $ac_n "checking for void""... $ac_c" 1>&4 +cat > conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_VOID=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_VOID\${ac_dB}HAVE_VOID\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_VOID\${ac_uB}HAVE_VOID\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_VOID\${ac_eB}HAVE_VOID\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_VOID 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -test -n "$silent" || echo "checking for time_t" -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext < int main() { return 0; } -int t() { time_t t = 0;; return 0; } +int t() { +time_t t = 0; +; return 0; } EOF if eval $ac_compile; then rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining HAVE_TIME_T" -echo "#define" HAVE_TIME_T "1" >> confdefs.h -DEFS="$DEFS -DHAVE_TIME_T=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_TIME_T\${ac_dB}HAVE_TIME_T\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_TIME_T\${ac_uB}HAVE_TIME_T\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_TIME_T\${ac_eB}HAVE_TIME_T\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_TIME_T 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -test -n "$silent" || echo "checking for return type of signal handlers" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_type_signal'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < @@ -812,83 +1122,87 @@ extern void (*signal ()) (); int main() { return 0; } -int t() { int i;; return 0; } +int t() { +int i; +; return 0; } EOF if eval $ac_compile; then rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining" RETSIGTYPE to be "void" -echo "#define" RETSIGTYPE "void" >> confdefs.h -DEFS="$DEFS -DRETSIGTYPE=void" -ac_sed_defs="${ac_sed_defs}\${ac_dA}RETSIGTYPE\${ac_dB}RETSIGTYPE\${ac_dC}void\${ac_dD} -\${ac_uA}RETSIGTYPE\${ac_uB}RETSIGTYPE\${ac_uC}void\${ac_uD} -\${ac_eA}RETSIGTYPE\${ac_eB}RETSIGTYPE\${ac_eC}void\${ac_eD} -" -} - - + ac_cv_type_signal=void else rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining" RETSIGTYPE to be "int" -echo "#define" RETSIGTYPE "int" >> confdefs.h -DEFS="$DEFS -DRETSIGTYPE=int" -ac_sed_defs="${ac_sed_defs}\${ac_dA}RETSIGTYPE\${ac_dB}RETSIGTYPE\${ac_dC}int\${ac_dD} -\${ac_uA}RETSIGTYPE\${ac_uB}RETSIGTYPE\${ac_uC}int\${ac_uD} -\${ac_eA}RETSIGTYPE\${ac_eB}RETSIGTYPE\${ac_eC}int\${ac_eD} -" -} - + ac_cv_type_signal=int fi rm -f conftest* +fi +echo "$ac_t""$ac_cv_type_signal" 1>&4 +cat >> confdefs.h < conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_func_$ac_func'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < +#include /* Arbitrary system header to define __stub macros. */ +/* Override any gcc2 internal prototype to avoid an error. */ +char $ac_func(); + int main() { return 0; } -int t() { +int t() { + /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named something starting with __ and the normal name is an alias. */ -#if defined (__stub_${ac_func}) || defined (__stub___${ac_func}) +#if defined (__stub_$ac_func) || defined (__stub___$ac_func) choke me #else -/* Override any gcc2 internal prototype to avoid an error. */ -extern char ${ac_func}(); ${ac_func}(); +$ac_func(); #endif + ; return 0; } EOF -if eval $ac_compile; then +if eval $ac_link; then rm -rf conftest* - { -test -n "$verbose" && \ -echo " defining ${ac_tr_func}" -echo "#define" ${ac_tr_func} "1" >> confdefs.h -DEFS="$DEFS -D${ac_tr_func}=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}${ac_tr_func}\${ac_dB}${ac_tr_func}\${ac_dC}1\${ac_dD} -\${ac_uA}${ac_tr_func}\${ac_uB}${ac_tr_func}\${ac_uC}1\${ac_uD} -\${ac_eA}${ac_tr_func}\${ac_eB}${ac_tr_func}\${ac_eC}1\${ac_eD} -" -} - - + eval "ac_cv_func_$ac_func=yes" +else + rm -rf conftest* + eval "ac_cv_func_$ac_func=no" fi rm -f conftest* + +fi +if eval "test \"`echo '$ac_cv_func_'$ac_func`\" = yes"; then + echo "$ac_t""yes" 1>&4 + ac_tr_func=HAVE_`echo $ac_func | tr '[a-z]' '[A-Z]'` + cat >> confdefs.h <&4 +fi done -test -n "$silent" || echo "checking for tcgetattr" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_func_tcgetattr'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < +#include /* Arbitrary system header to define __stub macros. */ +/* Override any gcc2 internal prototype to avoid an error. */ +char tcgetattr(); + int main() { return 0; } -int t() { +int t() { + /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named @@ -897,28 +1211,57 @@ choke me #else -/* Override any gcc2 internal prototype to avoid an error. */ -extern char tcgetattr(); tcgetattr(); +tcgetattr(); #endif + ; return 0; } EOF -if eval $ac_compile; then +if eval $ac_link; then rm -rf conftest* - { -test -n "$verbose" && \ -echo " defining HAVE_TERMIOS_FUNCS" -echo "#define" HAVE_TERMIOS_FUNCS "1" >> confdefs.h -DEFS="$DEFS -DHAVE_TERMIOS_FUNCS=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_TERMIOS_FUNCS\${ac_dB}HAVE_TERMIOS_FUNCS\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_TERMIOS_FUNCS\${ac_uB}HAVE_TERMIOS_FUNCS\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_TERMIOS_FUNCS\${ac_eB}HAVE_TERMIOS_FUNCS\${ac_eC}1\${ac_eD} -" -} + eval "ac_cv_func_tcgetattr=yes" +else + rm -rf conftest* + eval "ac_cv_func_tcgetattr=no" +fi +rm -f conftest* + +fi +if eval "test \"`echo '$ac_cv_func_'tcgetattr`\" = yes"; then + echo "$ac_t""yes" 1>&4 + cat >> confdefs.h <<\EOF +#define HAVE_TERMIOS_FUNCS 1 +EOF + +else + echo "$ac_t""no" 1>&4 +fi + +echo $ac_n "checking for fileno""... $ac_c" 1>&4 +cat > conftest.$ac_ext < +#endif +int main() { return 0; } +int t() { +static int x; x = fileno(stdin); +; return 0; } +EOF +if eval $ac_link; then + rm -rf conftest* + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_FILENO 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -test -n "$silent" || echo "checking for strerror" -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_STRERROR=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_STRERROR\${ac_dB}HAVE_STRERROR\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_STRERROR\${ac_uB}HAVE_STRERROR\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_STRERROR\${ac_eB}HAVE_STRERROR\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_STRERROR 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_SYS_ERRLIST=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_SYS_ERRLIST\${ac_dB}HAVE_SYS_ERRLIST\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_SYS_ERRLIST\${ac_uB}HAVE_SYS_ERRLIST\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_SYS_ERRLIST\${ac_eB}HAVE_SYS_ERRLIST\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_SYS_ERRLIST 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_ERRNO=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_ERRNO\${ac_dB}HAVE_ERRNO\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_ERRNO\${ac_uB}HAVE_ERRNO\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_ERRNO\${ac_eB}HAVE_ERRNO\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_ERRNO 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -test -n "$silent" || echo "checking for locale" -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext < #include int main() { return 0; } -int t() { setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);; return 0; } +int t() { +setlocale(LC_CTYPE,""); isprint(0); iscntrl(0); +; return 0; } EOF -if eval $ac_compile; then +if eval $ac_link; then rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining HAVE_LOCALE" -echo "#define" HAVE_LOCALE "1" >> confdefs.h -DEFS="$DEFS -DHAVE_LOCALE=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_LOCALE\${ac_dB}HAVE_LOCALE\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_LOCALE\${ac_uB}HAVE_LOCALE\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_LOCALE\${ac_eB}HAVE_LOCALE\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_LOCALE 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* -test -n "$silent" || echo "checking for ctype" -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_UPPER_LOWER=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_UPPER_LOWER\${ac_dB}HAVE_UPPER_LOWER\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_UPPER_LOWER\${ac_uB}HAVE_UPPER_LOWER\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_UPPER_LOWER\${ac_eB}HAVE_UPPER_LOWER\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_UPPER_LOWER 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* @@ -1057,6 +1386,7 @@ have_ospeed=no -test -n "$silent" || echo "checking termcap for ospeed" -cat > conftest.${ac_ext} <&4 +cat > conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_OSPEED=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_OSPEED\${ac_dB}HAVE_OSPEED\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_OSPEED\${ac_uB}HAVE_OSPEED\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_OSPEED\${ac_eB}HAVE_OSPEED\${ac_eC}1\${ac_eD} -" -} + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_OSPEED 1 +EOF have_ospeed=yes - fi rm -f conftest* if test $have_ospeed = no; then -cat > conftest.${ac_ext} < conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_OSPEED=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_OSPEED\${ac_dB}HAVE_OSPEED\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_OSPEED\${ac_uB}HAVE_OSPEED\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_OSPEED\${ac_eB}HAVE_OSPEED\${ac_eC}1\${ac_eD} -" -} - -{ -test -n "$verbose" && \ -echo " defining MUST_DEFINE_OSPEED" -echo "#define" MUST_DEFINE_OSPEED "1" >> confdefs.h -DEFS="$DEFS -DMUST_DEFINE_OSPEED=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}MUST_DEFINE_OSPEED\${ac_dB}MUST_DEFINE_OSPEED\${ac_dC}1\${ac_dD} -\${ac_uA}MUST_DEFINE_OSPEED\${ac_uB}MUST_DEFINE_OSPEED\${ac_uC}1\${ac_uD} -\${ac_eA}MUST_DEFINE_OSPEED\${ac_eB}MUST_DEFINE_OSPEED\${ac_eC}1\${ac_eD} -" -} - + echo "$ac_t""yes" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_OSPEED 1 +EOF + cat >> confdefs.h <<\EOF +#define MUST_DEFINE_OSPEED 1 +EOF +else + rm -rf conftest* + echo "$ac_t""no" 1>&4 fi rm -f conftest* @@ -1127,39 +1439,74 @@ fi - have_regex=no -test -n "$silent" || echo "checking for POSIX regex.h" -cat > conftest.${ac_ext} <&4 +if test "$cross_compiling" = yes; then + have_posix_regex=unknown +else +cat > conftest.$ac_ext < +#include +main() { regex_t r; regmatch_t rm; +if (regcomp(&r, "abc", 0)) exit(1); +if (regexec(&r, "xabcy", 1, &rm, 0)) exit(1); +exit(0); } +EOF +eval $ac_link +if test -s conftest && (./conftest; exit) 2>/dev/null; then + have_posix_regex=yes +else + have_posix_regex=no +fi +fi +rm -fr conftest* +if test $have_posix_regex = yes; then + echo "$ac_t""using POSIX regcomp" 1>&4 + cat >> confdefs.h <<\EOF +#define HAVE_POSIX_REGCOMP 1 +EOF + + have_regex=yes +elif test $have_posix_regex = unknown; then + cat > conftest.$ac_ext < #include int main() { return 0; } -int t() { regex_t *r; regfree(r);; return 0; } +int t() { +regex_t *r; regfree(r); +; return 0; } EOF -if eval $ac_compile; then +if eval $ac_link; then rm -rf conftest* - -{ -test -n "$verbose" && \ -echo " defining HAVE_POSIX_REGCOMP" -echo "#define" HAVE_POSIX_REGCOMP "1" >> confdefs.h -DEFS="$DEFS -DHAVE_POSIX_REGCOMP=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_POSIX_REGCOMP\${ac_dB}HAVE_POSIX_REGCOMP\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_POSIX_REGCOMP\${ac_uB}HAVE_POSIX_REGCOMP\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_POSIX_REGCOMP\${ac_eB}HAVE_POSIX_REGCOMP\${ac_eC}1\${ac_eD} -" -} + echo "$ac_t""using POSIX regcomp" 1>&4 + cat >> confdefs.h <<\EOF +#define HAVE_POSIX_REGCOMP 1 +EOF have_regex=yes - fi rm -f conftest* +fi if test $have_regex = no; then -test -n "$silent" || echo "checking for regcmp" -cat > conftest.${ac_ext} <&4 +if eval "test \"`echo '${'ac_cv_func_regcmp'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < +#include /* Arbitrary system header to define __stub macros. */ +/* Override any gcc2 internal prototype to avoid an error. */ +char regcmp(); + int main() { return 0; } -int t() { +int t() { + /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named @@ -1168,49 +1515,47 @@ choke me #else -/* Override any gcc2 internal prototype to avoid an error. */ -extern char regcmp(); regcmp(); +regcmp(); #endif + ; return 0; } EOF -if eval $ac_compile; then +if eval $ac_link; then rm -rf conftest* - { -test -n "$verbose" && \ -echo " defining HAVE_REGCMP" -echo "#define" HAVE_REGCMP "1" >> confdefs.h -DEFS="$DEFS -DHAVE_REGCMP=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_REGCMP\${ac_dB}HAVE_REGCMP\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_REGCMP\${ac_uB}HAVE_REGCMP\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_REGCMP\${ac_eB}HAVE_REGCMP\${ac_eC}1\${ac_eD} -" -} - have_regex=yes - + eval "ac_cv_func_regcmp=yes" +else + rm -rf conftest* + eval "ac_cv_func_regcmp=no" fi rm -f conftest* fi +if eval "test \"`echo '$ac_cv_func_'regcmp`\" = yes"; then + echo "$ac_t""yes" 1>&4 + echo "$ac_t""using regcmp" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_REGCMP 1 +EOF + have_regex=yes +else + echo "$ac_t""no" 1>&4 +fi + +fi if test $have_regex = no; then -cat > conftest.${ac_ext} < conftest.$ac_ext <> confdefs.h -DEFS="$DEFS -DHAVE_V8_REGCOMP=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_V8_REGCOMP\${ac_dB}HAVE_V8_REGCOMP\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_V8_REGCOMP\${ac_uB}HAVE_V8_REGCOMP\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_V8_REGCOMP\${ac_eB}HAVE_V8_REGCOMP\${ac_eC}1\${ac_eD} -" -} + echo "$ac_t""using V8 regcomp" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_V8_REGCOMP 1 +EOF have_regex=yes - fi rm -f conftest* @@ -1218,38 +1563,30 @@ fi if test $have_regex = no && test -f ${srcdir}/regex.c; then - -{ -test -n "$verbose" && \ -echo " defining HAVE_POSIX_REGCOMP" -echo "#define" HAVE_POSIX_REGCOMP "1" >> confdefs.h -DEFS="$DEFS -DHAVE_POSIX_REGCOMP=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_POSIX_REGCOMP\${ac_dB}HAVE_POSIX_REGCOMP\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_POSIX_REGCOMP\${ac_uB}HAVE_POSIX_REGCOMP\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_POSIX_REGCOMP\${ac_eB}HAVE_POSIX_REGCOMP\${ac_eC}1\${ac_eD} -" -} +echo "$ac_t""using POSIX regcomp -- local source" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_POSIX_REGCOMP 1 +EOF REGEX_O='regex.$(O)' have_regex=yes fi if test $have_regex = no && test -f ${srcdir}/regexp.c; then - -{ -test -n "$verbose" && \ -echo " defining HAVE_V8_REGCOMP" -echo "#define" HAVE_V8_REGCOMP "1" >> confdefs.h -DEFS="$DEFS -DHAVE_V8_REGCOMP=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_V8_REGCOMP\${ac_dB}HAVE_V8_REGCOMP\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_V8_REGCOMP\${ac_uB}HAVE_V8_REGCOMP\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_V8_REGCOMP\${ac_eB}HAVE_V8_REGCOMP\${ac_eC}1\${ac_eD} -" -} +echo "$ac_t""using V8 regcomp -- local source" 1>&4; cat >> confdefs.h <<\EOF +#define HAVE_V8_REGCOMP 1 +EOF REGEX_O='regexp.$(O)' have_regex=yes fi if test $have_regex = no; then -test -n "$silent" || echo "checking for re_comp" -cat > conftest.${ac_ext} <&4; echo $ac_n "checking for re_comp""... $ac_c" 1>&4 +if eval "test \"`echo '${'ac_cv_func_re_comp'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&4 +else + cat > conftest.$ac_ext < +#include /* Arbitrary system header to define __stub macros. */ +/* Override any gcc2 internal prototype to avoid an error. */ +char re_comp(); + int main() { return 0; } -int t() { +int t() { + /* The GNU C library defines this for functions which it implements to always fail with ENOSYS. Some functions are actually named @@ -1258,56 +1595,70 @@ choke me #else -/* Override any gcc2 internal prototype to avoid an error. */ -extern char re_comp(); re_comp(); +re_comp(); #endif + ; return 0; } EOF -if eval $ac_compile; then +if eval $ac_link; then rm -rf conftest* - { -test -n "$verbose" && \ -echo " defining HAVE_RE_COMP" -echo "#define" HAVE_RE_COMP "1" >> confdefs.h -DEFS="$DEFS -DHAVE_RE_COMP=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}HAVE_RE_COMP\${ac_dB}HAVE_RE_COMP\${ac_dC}1\${ac_dD} -\${ac_uA}HAVE_RE_COMP\${ac_uB}HAVE_RE_COMP\${ac_uC}1\${ac_uD} -\${ac_eA}HAVE_RE_COMP\${ac_eB}HAVE_RE_COMP\${ac_eC}1\${ac_eD} -" -} - have_regex=yes - + eval "ac_cv_func_re_comp=yes" +else + rm -rf conftest* + eval "ac_cv_func_re_comp=no" fi rm -f conftest* fi -if test $have_regex = no; then - -{ -test -n "$verbose" && \ -echo " defining NO_REGEX" -echo "#define" NO_REGEX "1" >> confdefs.h -DEFS="$DEFS -DNO_REGEX=1" -ac_sed_defs="${ac_sed_defs}\${ac_dA}NO_REGEX\${ac_dB}NO_REGEX\${ac_dC}1\${ac_dD} -\${ac_uA}NO_REGEX\${ac_uB}NO_REGEX\${ac_uC}1\${ac_uD} -\${ac_eA}NO_REGEX\${ac_eB}NO_REGEX\${ac_eC}1\${ac_eD} -" -} - +if eval "test \"`echo '$ac_cv_func_'re_comp`\" = yes"; then + echo "$ac_t""yes" 1>&4 + cat >> confdefs.h <<\EOF +#define HAVE_RE_COMP 1 +EOF + have_regex=yes +else + echo "$ac_t""no" 1>&4 fi +fi +if test $have_regex = no; then +echo "$ac_t""cannot find regular expression library" 1>&4; cat >> confdefs.h <<\EOF +#define NO_REGEX 1 +EOF -# The preferred way to propogate these variables is regular @ substitutions. -if test -n "$prefix"; then - ac_prsub="s%^prefix\\([ ]*\\)=\\([ ]*\\).*$%prefix\\1=\\2$prefix%" -else - prefix=/usr/local fi -if test -n "$exec_prefix"; then - ac_prsub="$ac_prsub -s%^exec_prefix\\([ ]*\\)=\\([ ]*\\).*$%exec_prefix\\1=\\2$exec_prefix%" + +trap '' 1 2 15 +if test -w $cache_file; then +echo "updating cache $cache_file" +cat > $cache_file <<\EOF +# This file is a shell script that caches the results of configure +# tests run on this system so they can be shared between configure +# scripts and configure runs. It is not useful on other systems. +# If it contains results you don't want to keep, you may remove or edit it. +# +# By default, configure uses ./config.cache as the cache file, +# creating it if it does not exist already. You can give configure +# the --cache-file=FILE option to use a different cache file; that is +# what configure does when it calls configure scripts in +# subdirectories, so they share the cache. +# Giving --cache-file=/dev/null disables caching, for debugging configure. +# config.status only pays attention to the cache file if you give it the +# --recheck option to rerun configure. +# +EOF +# Ultrix sh set writes to stderr and can't be redirected directly. +(set) 2>&1 | + sed -n "s/^\([a-zA-Z0-9_]*_cv_[a-zA-Z0-9_]*\)=\(.*\)/: \${\1='\2'}/p" \ + >> $cache_file else - exec_prefix='${prefix}' # Let make expand it. +echo "not updating unwritable cache $cache_file" fi +trap 'rm -fr conftest* confdefs* core $ac_clean_files; exit 1' 1 2 15 + +test "x$prefix" = xNONE && prefix=$ac_default_prefix +# Let make expand exec_prefix. +test "x$exec_prefix" = xNONE && exec_prefix='${prefix}' + # Any assignment to VPATH causes Sun make to only execute # the first set of double-colon rules, so remove it if not needed. @@ -1317,17 +1668,14 @@ fi -# Quote sed substitution magic chars in DEFS. -cat >conftest.def < config.status < $CONFIG_STATUS </dev/null | sed 1q`: # -# $0 $configure_args +# $0 $ac_configure_args +# +# Compiler output produced by configure, useful for debugging +# configure, is in ./config.log if it exists. -ac_cs_usage="Usage: config.status [--recheck] [--version] [--help]" +ac_cs_usage="Usage: $CONFIG_STATUS [--recheck] [--version] [--help]" for ac_option do case "\$ac_option" in -recheck | --recheck | --rechec | --reche | --rech | --rec | --re | --r) - echo running \${CONFIG_SHELL-/bin/sh} $0 $configure_args --no-create - exec \${CONFIG_SHELL-/bin/sh} $0 $configure_args --no-create ;; + echo "running \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion" + exec \${CONFIG_SHELL-/bin/sh} $0 $ac_configure_args --no-create --no-recursion ;; -version | --version | --versio | --versi | --vers | --ver | --ve | --v) - echo "config.status generated by autoconf version 1.11" + echo "$CONFIG_STATUS generated by autoconf version 2.1" exit 0 ;; -help | --help | --hel | --he | --h) @@ -1354,26 +1705,46 @@ done +ac_given_srcdir=$srcdir +ac_given_INSTALL="$INSTALL" + trap 'rm -fr Makefile defines.h conftest*; exit 1' 1 2 15 -CC='$CC' -CPP='$CPP' -INSTALL='$INSTALL' -INSTALL_PROGRAM='$INSTALL_PROGRAM' -INSTALL_DATA='$INSTALL_DATA' -REGEX_O='$REGEX_O' -LIBS='$LIBS' -srcdir='$srcdir' -top_srcdir='$top_srcdir' -prefix='$prefix' -exec_prefix='$exec_prefix' -ac_prsub='$ac_prsub' -ac_vpsub='$ac_vpsub' -extrasub='$extrasub' + +# Protect against being on the right side of a sed subst in config.status. +sed 's/%@/@@/; s/@%/@@/; s/%g$/@g/; /@g$/s/[\\\\&%]/\\\\&/g; + s/@@/%@/; s/@@/@%/; s/@g$/%g/' > conftest.subs <<\CEOF +$ac_vpsub +$extrasub +s%@CFLAGS@%$CFLAGS%g +s%@CPPFLAGS@%$CPPFLAGS%g +s%@CXXFLAGS@%$CXXFLAGS%g +s%@DEFS@%$DEFS%g +s%@LDFLAGS@%$LDFLAGS%g +s%@LIBS@%$LIBS%g +s%@exec_prefix@%$exec_prefix%g +s%@prefix@%$prefix%g +s%@program_transform_name@%$program_transform_name%g +s%@CC@%$CC%g +s%@CPP@%$CPP%g +s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g +s%@INSTALL_DATA@%$INSTALL_DATA%g +s%@REGEX_O@%$REGEX_O%g + +CEOF EOF -cat >> config.status <<\EOF +cat >> $CONFIG_STATUS <> $CONFIG_STATUS <<\EOF +for ac_file in .. $CONFIG_FILES; do if test "x$ac_file" != x..; then + # Support "outfile[:infile]", defaulting infile="outfile.in". + case "$ac_file" in + *:*) ac_file_in=`echo "$ac_file"|sed 's%.*:%%'` + ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; + *) ac_file_in="${ac_file}.in" ;; + esac + + # Adjust relative srcdir, etc. for subdirectories. -CONFIG_FILES=${CONFIG_FILES-"Makefile"} -for ac_file in .. ${CONFIG_FILES}; do if test "x$ac_file" != x..; then # Remove last slash and all that follows it. Not all systems have dirname. ac_dir=`echo $ac_file|sed 's%/[^/][^/]*$%%'` @@ -1382,13 +1753,13 @@ test ! -d "$ac_dir" && mkdir "$ac_dir" ac_dir_suffix="/$ac_dir" + # A "../" for each directory in $ac_dir_suffix. + ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` else - ac_dir_suffix= + ac_dir_suffix= ac_dots= fi - # A "../" for each directory in $ac_dir_suffix. - ac_dots=`echo $ac_dir_suffix|sed 's%/[^/]*%../%g'` case "$ac_given_srcdir" in .) srcdir=. - if test -z "$ac_dir_suffix"; then top_srcdir=. + if test -z "$ac_dots"; then top_srcdir=. else top_srcdir=`echo $ac_dots|sed 's%/$%%'`; fi ;; /*) srcdir="$ac_given_srcdir$ac_dir_suffix"; top_srcdir="$ac_given_srcdir" ;; @@ -1398,120 +1769,113 @@ esac + case "$ac_given_INSTALL" in + [/$]*) INSTALL="$ac_given_INSTALL" ;; + *) INSTALL="$ac_dots$ac_given_INSTALL" ;; + esac echo creating "$ac_file" rm -f "$ac_file" - comment_str="Generated automatically from `echo $ac_file|sed 's|.*/||'`.in by configure." + configure_input="Generated automatically from `echo $ac_file_in|sed 's%.*/%%'` by configure." case "$ac_file" in - *.c | *.h | *.C | *.cc | *.m ) echo "/* $comment_str */" > "$ac_file" ;; - * ) echo "# $comment_str" > "$ac_file" ;; + *Makefile*) ac_comsub="1i\\ +# $configure_input" ;; + *) ac_comsub= ;; esac - sed -e " -$ac_prsub -$ac_vpsub -$extrasub -s%@CC@%$CC%g -s%@CPP@%$CPP%g -s%@INSTALL@%$INSTALL%g -s%@INSTALL_PROGRAM@%$INSTALL_PROGRAM%g -s%@INSTALL_DATA@%$INSTALL_DATA%g -s%@REGEX_O@%$REGEX_O%g -s%@LIBS@%$LIBS%g + sed -e "$ac_comsub +s%@configure_input@%$configure_input%g s%@srcdir@%$srcdir%g s%@top_srcdir@%$top_srcdir%g -s%@prefix@%$prefix%g -s%@exec_prefix@%$exec_prefix%g -s%@DEFS@%-DHAVE_CONFIG_H%" $ac_given_srcdir/${ac_file}.in >> $ac_file +s%@INSTALL@%$INSTALL%g +" -f conftest.subs $ac_given_srcdir/$ac_file_in > $ac_file fi; done +rm -f conftest.subs -# These sed commands are put into ac_sed_defs when defining a macro. -# They are broken into pieces to make the sed script easier to manage. -# They are passed to sed as "A NAME B NAME C VALUE D", where NAME -# is the cpp macro being defined and VALUE is the value it is being given. -# Each defining turns into a single global substitution command. -# Hopefully no one uses "!" as a variable value. -# Other candidates for the sed separators, like , and @, do get used. +# These sed commands are passed to sed as "A NAME B NAME C VALUE D", where +# NAME is the cpp macro being defined and VALUE is the value it is being given. # # ac_d sets the value in "#define NAME VALUE" lines. -ac_dA='s!^\([ ]*\)#\([ ]*define[ ][ ]*\)' -ac_dB='\([ ][ ]*\)[^ ]*!\1#\2' +ac_dA='s%^\([ ]*\)#\([ ]*define[ ][ ]*\)' +ac_dB='\([ ][ ]*\)[^ ]*%\1#\2' ac_dC='\3' -ac_dD='!g' +ac_dD='%g' # ac_u turns "#undef NAME" with trailing blanks into "#define NAME VALUE". -ac_uA='s!^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_uB='\([ ]\)!\1#\2define\3' +ac_uA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_uB='\([ ]\)%\1#\2define\3' ac_uC=' ' -ac_uD='\4!g' +ac_uD='\4%g' # ac_e turns "#undef NAME" without trailing blanks into "#define NAME VALUE". -ac_eA='s!^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' -ac_eB='$!\1#\2define\3' +ac_eA='s%^\([ ]*\)#\([ ]*\)undef\([ ][ ]*\)' +ac_eB='$%\1#\2define\3' ac_eC=' ' -ac_eD='!g' -rm -f conftest.sed +ac_eD='%g' + +CONFIG_HEADERS=${CONFIG_HEADERS-"defines.h"} +for ac_file in .. $CONFIG_HEADERS; do if test "x$ac_file" != x..; then + # Support "outfile[:infile]", defaulting infile="outfile.in". + case "$ac_file" in + *:*) ac_file_in=`echo "$ac_file"|sed 's%.*:%%'` + ac_file=`echo "$ac_file"|sed 's%:.*%%'` ;; + *) ac_file_in="${ac_file}.in" ;; + esac + + echo creating $ac_file + + rm -f conftest.frag conftest.in conftest.out + cp $ac_given_srcdir/$ac_file_in conftest.in + EOF -# Turn off quoting long enough to insert the sed commands. -rm -f conftest.sh -cat > conftest.sh < conftest.hdr <<\EOF +s/[\\&%]/\\&/g +s%[\\$`]%\\&%g +s%#define \([A-Za-z_][A-Za-z0-9_]*\) \(.*\)%${ac_dA}\1${ac_dB}\1${ac_dC}\2${ac_dD}%gp +s%ac_d%ac_u%gp +s%ac_u%ac_e%gp EOF +sed -n -f conftest.hdr confdefs.h > conftest.vals +rm -f conftest.hdr -# Break up $ac_sed_defs (now in conftest.sh) because some shells have a limit -# on the size of here documents. +# This sed command replaces #undef with comments. This is necessary, for +# example, in the case of _POSIX_SOURCE, which is predefined and required +# on some systems where configure will not decide to define it. +cat >> conftest.vals <<\EOF +s%^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*%/* & */% +EOF +# Break up conftest.vals because some shells have a limit on +# the size of here documents, and old seds have small limits too. # Maximum number of lines to put in a single here document. -ac_max_sh_lines=9 +ac_max_here_lines=12 +rm -f conftest.tail while : do - # wc gives bogus results for an empty file on some AIX systems. - ac_lines=`grep -c . conftest.sh` + ac_lines=`grep -c . conftest.vals` + # grep -c gives empty output for an empty file on some AIX systems. if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi - rm -f conftest.s1 conftest.s2 - sed ${ac_max_sh_lines}q conftest.sh > conftest.s1 # Like head -9. - sed 1,${ac_max_sh_lines}d conftest.sh > conftest.s2 # Like tail +10. - # Write a limited-size here document to append to conftest.sed. - echo 'cat >> conftest.sed <> config.status - cat conftest.s1 >> config.status - echo 'CONFEOF' >> config.status - rm -f conftest.s1 conftest.sh - mv conftest.s2 conftest.sh + # Write a limited-size here document to conftest.frag. + echo ' cat > conftest.frag <> $CONFIG_STATUS + sed ${ac_max_here_lines}q conftest.vals >> $CONFIG_STATUS + echo 'CEOF + sed -f conftest.frag conftest.in > conftest.out + rm -f conftest.in + mv conftest.out conftest.in +' >> $CONFIG_STATUS + sed 1,${ac_max_here_lines}d conftest.vals > conftest.tail + rm -f conftest.vals + mv conftest.tail conftest.vals done -rm -f conftest.sh - -# Now back to your regularly scheduled config.status. -cat >> config.status <<\EOF -# This sed command replaces #undef's with comments. This is necessary, for -# example, in the case of _POSIX_SOURCE, which is predefined and required -# on some systems where configure will not decide to define it in -# defines.h. -cat >> conftest.sed <<\CONFEOF -s,^[ ]*#[ ]*undef[ ][ ]*[a-zA-Z_][a-zA-Z_0-9]*,/* & */, -CONFEOF -rm -f conftest.h -# Break up the sed commands because old seds have small limits. -ac_max_sed_lines=20 +rm -f conftest.vals -CONFIG_HEADERS=${CONFIG_HEADERS-"defines.h"} -for ac_file in .. ${CONFIG_HEADERS}; do if test "x$ac_file" != x..; then - echo creating $ac_file - - cp $ac_given_srcdir/$ac_file.in conftest.h1 - cp conftest.sed conftest.stm - while : - do - ac_lines=`grep -c . conftest.stm` - if test -z "$ac_lines" || test "$ac_lines" -eq 0; then break; fi - rm -f conftest.s1 conftest.s2 conftest.h2 - sed ${ac_max_sed_lines}q conftest.stm > conftest.s1 # Like head -20. - sed 1,${ac_max_sed_lines}d conftest.stm > conftest.s2 # Like tail +21. - sed -f conftest.s1 < conftest.h1 > conftest.h2 - rm -f conftest.s1 conftest.h1 conftest.stm - mv conftest.h2 conftest.h1 - mv conftest.s2 conftest.stm - done - rm -f conftest.stm conftest.h +cat >> $CONFIG_STATUS <<\EOF + rm -f conftest.frag conftest.h echo "/* $ac_file. Generated automatically by configure. */" > conftest.h - cat conftest.h1 >> conftest.h - rm -f conftest.h1 + cat conftest.in >> conftest.h + rm -f conftest.in if cmp -s $ac_file conftest.h 2>/dev/null; then - # The file exists and we would not be changing it. echo "$ac_file is unchanged" rm -f conftest.h @@ -1521,5 +1885,4 @@ fi fi; done -rm -f conftest.sed @@ -1527,6 +1890,6 @@ exit 0 EOF -chmod +x config.status -# Some shells look in PATH for config.status without the "./". -test -n "$no_create" || ${CONFIG_SHELL-/bin/sh} ./config.status +chmod +x $CONFIG_STATUS +rm -fr confdefs* $ac_clean_files +test "$no_create" = yes || ${CONFIG_SHELL-/bin/sh} $CONFIG_STATUS diff -r -U2 less-252/configure.in less-278/configure.in --- less-252/configure.in Sat Oct 15 03:16:45 1994 +++ less-278/configure.in Tue Jan 31 18:55:33 1995 @@ -5,49 +5,64 @@ dnl Checks for programs. AC_PROG_CC -AC_GCC_TRADITIONAL +AC_ISC_POSIX +AC_PROG_GCC_TRADITIONAL AC_PROG_INSTALL dnl Checks for libraries. TERMLIBS= -AC_HAVE_LIBRARY(curses, [TERMLIBS="$TERMLIBS -lcurses"]) -AC_HAVE_LIBRARY(termcap, [TERMLIBS="$TERMLIBS -ltermcap"]) -AC_HAVE_LIBRARY(termlib, [have_termlib=yes], [have_termlib=no]) +AC_CHECK_LIB(curses, initscr, [TERMLIBS="$TERMLIBS -lcurses"]) +AC_CHECK_LIB(termcap, tgetent, [TERMLIBS="$TERMLIBS -ltermcap"]) +AC_CHECK_LIB(termlib, tgetent, [have_termlib=yes], [have_termlib=no]) dnl Regular expressions (regcmp) are in -lgen on Solaris 2, dnl and in -lintl on SCO Unix. -AC_HAVE_LIBRARY(gen, [LIBS="$LIBS -lgen"]) -AC_HAVE_LIBRARY(intl, [LIBS="$LIBS -lintl"]) -dnl ??? AC_HAVE_LIBRARY(gnuregex, [LIBS="$LIBS -lgnuregex"]) +AC_CHECK_LIB(gen, regcmp) +AC_CHECK_LIB(intl, regcmp) dnl Solaris has curses & termcap, but they don't work without libucb dnl which is broken, so we use termlib. -AC_CHECKING(termlib) +AC_MSG_CHECKING(for working terminal libraries) SAVE_LIBS=$LIBS LIBS="$LIBS $TERMLIBS" -AC_COMPILE_CHECK(, , [tgetent(0); tgetflag(0); tgetnum(0); tgetstr(0);], +AC_TRY_LINK(, [tgetent(0); tgetflag(0); tgetnum(0); tgetstr(0);], [termok=yes], [termok=no]) -if test $termok = no; then +if test $termok = yes; then + AC_MSG_RESULT(using $TERMLIBS) +else LIBS="$SAVE_LIBS" if test $have_termlib = yes; then LIBS="$LIBS -ltermlib" + AC_MSG_RESULT(using -ltermlib) + else + AC_MSG_RESULT(TERMINAL LIBRARY BROKEN - configure failed) + exit 1 fi fi dnl Checks for header files. -AC_STDC_HEADERS -AC_HAVE_HEADERS(ctype.h errno.h fcntl.h stdio.h termcap.h termio.h termios.h time.h unistd.h values.h sys/ioctl.h sys/stream.h sys/ptem.h) +AC_HEADER_STDC +AC_CHECK_HEADERS(ctype.h errno.h fcntl.h stdio.h termcap.h termio.h termios.h time.h unistd.h values.h sys/ioctl.h sys/stream.h sys/ptem.h) dnl Checks for identifiers. -AC_OFF_T -AC_COMPILE_CHECK(void, , [void *foo = 0;], - [AC_DEFINE(HAVE_VOID)]) -AC_COMPILE_CHECK(time_t, [#include ], [time_t t = 0;], - [AC_DEFINE(HAVE_TIME_T)]) +AC_TYPE_OFF_T +AC_MSG_CHECKING(for void) +AC_TRY_COMPILE(, [void *foo = 0;], + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_VOID)], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(for time_t) +AC_TRY_COMPILE([#include ], [time_t t = 0;], + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_TIME_T)], [AC_MSG_RESULT(no)]) dnl Checks for functions and external variables. -AC_RETSIGTYPE -AC_HAVE_FUNCS(_setjmp system sigsetmask memcpy strchr) +AC_TYPE_SIGNAL +AC_CHECK_FUNCS(_setjmp system sigsetmask memcpy strchr) dnl Some systems have termios.h but not the corresponding functions. -AC_FUNC_CHECK(tcgetattr, AC_DEFINE(HAVE_TERMIOS_FUNCS)) -AC_COMPILE_CHECK(strerror, [ +AC_CHECK_FUNC(tcgetattr, AC_DEFINE(HAVE_TERMIOS_FUNCS)) +AC_MSG_CHECKING(for fileno) +AC_TRY_LINK([ +#if HAVE_STDIO_H +#include +#endif], [static int x; x = fileno(stdin);], + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_FILENO)], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(for strerror) +AC_TRY_LINK([ #if HAVE_STDIO_H #include @@ -59,21 +74,26 @@ #include #endif], [static char *x; x = strerror(0);], - [AC_DEFINE(HAVE_STRERROR)]) -AC_COMPILE_CHECK(, , [extern int sys_errlist; static int x; x = sys_errlist;], - [AC_DEFINE(HAVE_SYS_ERRLIST)]) -AC_COMPILE_CHECK(, , [extern int errno; static int x; x = errno;], - [AC_DEFINE(HAVE_ERRNO)]) -AC_COMPILE_CHECK(locale, [#include + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_STRERROR)], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(for sys_errlist) +AC_TRY_LINK(, [extern char *sys_errlist[]; static char **x; x = sys_errlist;], + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_SYS_ERRLIST)], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(for errno) +AC_TRY_LINK(, [extern int errno; static int x; x = errno;], + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_ERRNO)], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(for locale) +AC_TRY_LINK([#include #include ], [setlocale(LC_CTYPE,""); isprint(0); iscntrl(0);], - [AC_DEFINE(HAVE_LOCALE)]) -AC_COMPILE_CHECK(ctype, [ + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_LOCALE)], [AC_MSG_RESULT(no)]) +AC_MSG_CHECKING(for ctype functions) +AC_TRY_LINK([ #if HAVE_CTYPE_H #include #endif], [static int x; x = isupper(x); x = tolower(x); x = toupper(x);], - [AC_DEFINE(HAVE_UPPER_LOWER)]) + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_UPPER_LOWER)], [AC_MSG_RESULT(no)]) +dnl Checks for external variable ospeed in the termcap library. have_ospeed=no -AC_CHECKING(termcap for ospeed) -AC_COMPILE_CHECK(, [ +AC_MSG_CHECKING(termcap for ospeed) +AC_TRY_LINK([ #include #if HAVE_TERMIOS_H @@ -82,36 +102,58 @@ #if HAVE_TERMCAP_H #include -#endif], [ospeed = 0;], [AC_DEFINE(HAVE_OSPEED) have_ospeed=yes]) +#endif], [ospeed = 0;], +[AC_MSG_RESULT(yes); AC_DEFINE(HAVE_OSPEED) have_ospeed=yes]) if test $have_ospeed = no; then -AC_COMPILE_CHECK(, , [extern short ospeed; ospeed = 0;], - [AC_DEFINE(HAVE_OSPEED) AC_DEFINE(MUST_DEFINE_OSPEED)]) +AC_TRY_LINK(, [extern short ospeed; ospeed = 0;], + [AC_MSG_RESULT(yes); AC_DEFINE(HAVE_OSPEED) AC_DEFINE(MUST_DEFINE_OSPEED)], + [AC_MSG_RESULT(no)]) fi - dnl Checks for regular expression functions. have_regex=no -AC_CHECKING(for POSIX regex.h) -AC_COMPILE_CHECK(, [#include +have_posix_regex=unknown +AC_CHECKING(for regular expression library) +dnl Some versions of Solaris have a regcomp() function, but it doesn't work! +dnl So we run a test program. If we're cross-compiling, do it the old way. +AC_TRY_RUN([ +#include +#include +main() { regex_t r; regmatch_t rm; +if (regcomp(&r, "abc", 0)) exit(1); +if (regexec(&r, "xabcy", 1, &rm, 0)) exit(1); +exit(0); }], + have_posix_regex=yes, have_posix_regex=no, have_posix_regex=unknown) +if test $have_posix_regex = yes; then + AC_MSG_RESULT(using POSIX regcomp) + AC_DEFINE(HAVE_POSIX_REGCOMP) + have_regex=yes +elif test $have_posix_regex = unknown; then + AC_TRY_LINK([ +#include #include ], [regex_t *r; regfree(r);], + AC_MSG_RESULT(using POSIX regcomp) AC_DEFINE(HAVE_POSIX_REGCOMP) have_regex=yes) +fi if test $have_regex = no; then -AC_FUNC_CHECK(regcmp, AC_DEFINE(HAVE_REGCMP) have_regex=yes) +AC_CHECK_FUNC(regcmp, +AC_MSG_RESULT(using regcmp); AC_DEFINE(HAVE_REGCMP) have_regex=yes) fi if test $have_regex = no; then -AC_COMPILE_CHECK(, [#include "regexp.h"], [regcomp("");], -AC_DEFINE(HAVE_V8_REGCOMP) have_regex=yes) +AC_TRY_LINK([ +#include "regexp.h"], [regcomp("");], +AC_MSG_RESULT(using V8 regcomp); AC_DEFINE(HAVE_V8_REGCOMP) have_regex=yes) fi if test $have_regex = no && test -f ${srcdir}/regex.c; then -AC_DEFINE(HAVE_POSIX_REGCOMP) REGEX_O='regex.$(O)' AC_SUBST(REGEX_O) have_regex=yes +AC_MSG_RESULT(using POSIX regcomp -- local source); AC_DEFINE(HAVE_POSIX_REGCOMP) REGEX_O='regex.$(O)' AC_SUBST(REGEX_O) have_regex=yes fi if test $have_regex = no && test -f ${srcdir}/regexp.c; then -AC_DEFINE(HAVE_V8_REGCOMP) REGEX_O='regexp.$(O)' AC_SUBST(REGEX_O) have_regex=yes +AC_MSG_RESULT(using V8 regcomp -- local source); AC_DEFINE(HAVE_V8_REGCOMP) REGEX_O='regexp.$(O)' AC_SUBST(REGEX_O) have_regex=yes fi if test $have_regex = no; then -AC_FUNC_CHECK(re_comp, AC_DEFINE(HAVE_RE_COMP) have_regex=yes) +AC_MSG_RESULT(using re_comp); AC_CHECK_FUNC(re_comp, AC_DEFINE(HAVE_RE_COMP) have_regex=yes) fi if test $have_regex = no; then -AC_DEFINE(NO_REGEX) +AC_MSG_RESULT(cannot find regular expression library); AC_DEFINE(NO_REGEX) fi diff -r -U2 less-252/decode.c less-278/decode.c --- less-252/decode.c Sat Oct 15 03:16:45 1994 +++ less-278/decode.c Tue Jan 31 18:55:34 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -57,5 +57,5 @@ * frequency of use, so the common commands are near the beginning. */ -static char cmdtable[] = +static unsigned char cmdtable[] = { '\r',0, A_F_LINE, @@ -159,5 +159,5 @@ }; -static char edittable[] = +static unsigned char edittable[] = { '\t',0, EC_F_COMPLETE, /* TAB */ @@ -204,6 +204,15 @@ init_cmds() { - add_fcmd_table(cmdtable, sizeof(cmdtable)); - add_ecmd_table(edittable, sizeof(edittable)); + /* + * Add the default command tables. + */ + add_fcmd_table((char*)cmdtable, sizeof(cmdtable)); + add_ecmd_table((char*)edittable, sizeof(edittable)); +#if USERFILE + /* + * Try to add the tables in the standard lesskey file "$HOME/.less". + */ + add_hometable(); +#endif } @@ -219,4 +228,6 @@ register struct tablelist *t; + if (len == 0) + return (0); /* * Allocate a tablelist structure, initialize it, @@ -236,5 +247,5 @@ /* - * + * Add a command table. */ public void @@ -248,5 +259,5 @@ /* - * + * Add an editing command table. */ public void @@ -483,5 +494,5 @@ * Try to open the lesskey file. */ - f = open(filename, 0); + f = open(filename, OPEN_READ); if (f < 0) return (1); @@ -633,4 +644,8 @@ ungetcc(usercmd[--nch]); } + } else + { + if (s != NULL) + ungetsc(s); } return action; diff -r -U2 less-252/defines.dos less-278/defines.dos --- less-252/defines.dos Wed Nov 16 14:22:22 1994 +++ less-278/defines.dos Tue Jan 31 18:55:35 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -36,8 +36,19 @@ /* + * SECURE is 1 if you wish to disable a bunch of features in order to + * be safe to run by unprivileged users. + */ +#define SECURE 0 + +/* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE 1 +#define SHELL_ESCAPE (!SECURE) + +/* + * EXAMINE is 1 if you wish to allow examining files by name from within less. + */ +#define EXAMINE (!SECURE) /* @@ -45,5 +56,5 @@ * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME 1 +#define TAB_COMPLETE_FILENAME (!SECURE) /* @@ -64,5 +75,5 @@ * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR 1 +#define EDITOR (!SECURE) #define EDIT_PGM "vi" @@ -70,5 +81,5 @@ * TAGS is 1 if you wish to support tag files. */ -#define TAGS 1 +#define TAGS (!SECURE) /* @@ -76,5 +87,5 @@ * user-defined key bindings. */ -#define USERFILE 1 +#define USERFILE (!SECURE) /* @@ -94,5 +105,5 @@ * LOGFILE is 1 if you wish to allow the -l option (to create log files). */ -#define LOGFILE 1 +#define LOGFILE (!SECURE) /* @@ -132,5 +143,5 @@ * HAVE_STAT is 1 if your system has the stat() call. */ -#define HAVE_STAT 1 +#define HAVE_STAT 1 /* @@ -138,5 +149,5 @@ * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* @@ -154,5 +165,5 @@ /* Define as the return type of signal handlers (int or void). */ -#define RETSIGTYPE void +#define RETSIGTYPE void /* Define if you have the ANSI C header files. */ @@ -184,4 +195,7 @@ #define HAVE_STRERROR 0 +/* Define HAVE_FILENO if you have the fileno() macro. */ +#define HAVE_FILENO 0 + /* Define HAVE_ERRNO if you have the errno variable */ #define HAVE_ERRNO 0 @@ -205,17 +219,17 @@ #define HAVE_UPPER_LOWER 1 -/* Define if you have _setjmp. */ +/* Define if you have the _setjmp function. */ #define HAVE__SETJMP 0 -/* Define if you have memcpy. */ +/* Define if you have the memcpy function. */ #define HAVE_MEMCPY 1 -/* Define if you have sigsetmask. */ +/* Define if you have the sigsetmask function. */ #define HAVE_SIGSETMASK 0 -/* Define if you have strchr. */ +/* Define if you have the strchr function. */ #define HAVE_STRCHR 1 -/* Define if you have system. */ +/* Define if you have the system function. */ #define HAVE_SYSTEM 1 diff -r -U2 less-252/defines.h.in less-278/defines.h.in --- less-252/defines.h.in Wed Nov 16 14:24:53 1994 +++ less-278/defines.h.in Tue Jan 3 20:00:30 1995 @@ -15,8 +15,19 @@ /* + * SECURE is 1 if you wish to disable a bunch of features in order to + * be safe to run by unprivileged users. + */ +#define SECURE 0 + +/* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE 1 +#define SHELL_ESCAPE (!SECURE) + +/* + * EXAMINE is 1 if you wish to allow examining files by name from within less. + */ +#define EXAMINE (!SECURE) /* @@ -24,5 +35,5 @@ * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME 1 +#define TAB_COMPLETE_FILENAME (!SECURE) /* @@ -43,5 +54,5 @@ * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR 1 +#define EDITOR (!SECURE) #define EDIT_PGM "vi" @@ -49,5 +60,5 @@ * TAGS is 1 if you wish to support tag files. */ -#define TAGS 1 +#define TAGS (!SECURE) /* @@ -55,5 +66,5 @@ * user-defined key bindings. */ -#define USERFILE 1 +#define USERFILE (!SECURE) /* @@ -62,5 +73,5 @@ * and the "echo" shell command. */ -#define GLOB 1 +#define GLOB (!SECURE) /* @@ -68,10 +79,10 @@ * which allows the user to pipe data into a shell command. */ -#define PIPEC 1 +#define PIPEC (!SECURE) /* * LOGFILE is 1 if you wish to allow the -l option (to create log files). */ -#define LOGFILE 1 +#define LOGFILE (!SECURE) /* @@ -130,4 +141,7 @@ #undef off_t +/* Define if you need to in order for stat and other things to work. */ +#undef _POSIX_SOURCE + /* Define as the return type of signal handlers (int or void). */ #undef RETSIGTYPE @@ -160,4 +174,7 @@ #undef HAVE_STRERROR +/* Define HAVE_FILENO if you have the fileno() macro. */ +#undef HAVE_FILENO + /* Define HAVE_ERRNO if you have the errno variable */ #undef HAVE_ERRNO @@ -181,17 +198,17 @@ #undef HAVE_UPPER_LOWER -/* Define if you have _setjmp. */ +/* Define if you have the _setjmp function. */ #undef HAVE__SETJMP -/* Define if you have memcpy. */ +/* Define if you have the memcpy function. */ #undef HAVE_MEMCPY -/* Define if you have sigsetmask. */ +/* Define if you have the sigsetmask function. */ #undef HAVE_SIGSETMASK -/* Define if you have strchr. */ +/* Define if you have the strchr function. */ #undef HAVE_STRCHR -/* Define if you have system. */ +/* Define if you have the system function. */ #undef HAVE_SYSTEM @@ -234,2 +251,8 @@ /* Define if you have the header file. */ #undef HAVE_VALUES_H + +/* Define if you have the gen library (-lgen). */ +#undef HAVE_LIBGEN + +/* Define if you have the intl library (-lintl). */ +#undef HAVE_LIBINTL diff -r -U2 less-252/defines.h.top less-278/defines.h.top --- less-252/defines.h.top Wed Nov 16 14:22:06 1994 +++ less-278/defines.h.top Tue Jan 31 18:55:36 1995 @@ -14,8 +14,19 @@ /* + * SECURE is 1 if you wish to disable a bunch of features in order to + * be safe to run by unprivileged users. + */ +#define SECURE 0 + +/* * SHELL_ESCAPE is 1 if you wish to allow shell escapes. * (This is possible only if your system supplies the system() function.) */ -#define SHELL_ESCAPE 1 +#define SHELL_ESCAPE (!SECURE) + +/* + * EXAMINE is 1 if you wish to allow examining files by name from within less. + */ +#define EXAMINE (!SECURE) /* @@ -23,5 +34,5 @@ * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME 1 +#define TAB_COMPLETE_FILENAME (!SECURE) /* @@ -42,5 +53,5 @@ * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR 1 +#define EDITOR (!SECURE) #define EDIT_PGM "vi" @@ -48,5 +59,5 @@ * TAGS is 1 if you wish to support tag files. */ -#define TAGS 1 +#define TAGS (!SECURE) /* @@ -54,5 +65,5 @@ * user-defined key bindings. */ -#define USERFILE 1 +#define USERFILE (!SECURE) /* @@ -61,5 +72,5 @@ * and the "echo" shell command. */ -#define GLOB 1 +#define GLOB (!SECURE) /* @@ -67,10 +78,10 @@ * which allows the user to pipe data into a shell command. */ -#define PIPEC 1 +#define PIPEC (!SECURE) /* * LOGFILE is 1 if you wish to allow the -l option (to create log files). */ -#define LOGFILE 1 +#define LOGFILE (!SECURE) /* Only in less-278: defines.os2 diff -r -U2 less-252/doscreen.c less-278/doscreen.c --- less-252/doscreen.c Sat Oct 15 03:16:45 1994 +++ less-278/doscreen.c Tue Jan 31 18:55:37 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/edit.c less-278/edit.c --- less-252/edit.c Sat Oct 15 03:16:45 1994 +++ less-278/edit.c Tue Jan 31 18:55:38 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -28,16 +28,9 @@ #include "less.h" -#if HAVE_FCNTL_H -#include -#endif - public int fd0 = 0; -#define ISPIPE(fd) ((fd)==fd0) -extern int ispipe; extern int new_file; extern int errmsgs; extern int quit_at_eof; -extern int file; extern int cbufs; extern char *every_first_cmd; @@ -56,4 +49,5 @@ static char *curr_altfilename = NULL; +static void *curr_altpipe; @@ -131,5 +125,7 @@ } - +/* + * Close the current input file. + */ static void close_file() @@ -150,11 +146,7 @@ } /* - * Close the current file, unless it is a pipe. + * Close the file descriptor, unless it is a pipe. */ - if (!ISPIPE(file)) - { - close(file); - file = -1; - } + ch_close(); /* * If we opened a file using an alternate name, @@ -163,5 +155,6 @@ if (curr_altfilename != NULL) { - close_altfile(curr_altfilename, get_filename(curr_ifile)); + close_altfile(curr_altfilename, get_filename(curr_ifile), + curr_altpipe); free(curr_altfilename); curr_altfilename = NULL; @@ -171,5 +164,5 @@ /* - * Edit a new file. + * Edit a new file (given its name). * Filename == "-" means standard input. * Filename == NULL means just close the current file. @@ -184,4 +177,8 @@ } +/* + * Edit a new file (given its IFILE). + * ifile == NULL means just close the current file. + */ public int edit_ifile(ifile) @@ -191,39 +188,73 @@ int answer; int no_display; + int chflags; char *filename; char *open_filename; char *alt_filename; + void *alt_pipe; PARG parg; - if (ifile == NULL_IFILE) + if (ifile == curr_ifile) { /* - * Close the current file, but don't open a new one. + * Already have the correct file open. */ + return (0); + } + + /* + * We must close the currently open file now. + * This is necessary to make the open_altfile/close_altfile pairs + * nest properly (or rather to avoid nesting at all). + * {{ Some stupid implementations of popen() mess up if you do: + * fA = popen("A"); fB = popen("B"); pclose(fA); pclose(fB); }} + */ #if LOGFILE - end_logfile(); + end_logfile(); #endif + if (curr_ifile != NULL_IFILE) + { + old_ifile = curr_ifile; close_file(); - return (0); } - if (ifile == curr_ifile) - { + + if (ifile == NULL_IFILE) /* - * Already have the correct file open. + * No new file to open. */ return (0); - } + filename = get_filename(ifile); - alt_filename = open_altfile(filename); + /* + * See if LESSOPEN specifies an "alternate" file to open. + */ + alt_pipe = NULL; + alt_filename = open_altfile(filename, &f, &alt_pipe); open_filename = (alt_filename != NULL) ? alt_filename : filename; - - if (strcmp(open_filename, "-") == 0) + + chflags = 0; + if (alt_pipe != NULL) + { + /* + * The alternate "file" is actually a pipe. + * f has already been set to the file descriptor of the pipe + * in the call to open_altfile above. + * Keep the file descriptor open because it was opened + * via popen(), and pclose() wants to close it. + */ + chflags |= CH_POPENED; + } else if (strcmp(open_filename, "-") == 0) { /* * Use standard input. + * Keep the file descriptor open because we can't reopen it. */ f = fd0; + chflags |= CH_KEEPOPEN; } else if ((parg.p_string = bad_file(open_filename)) != NULL) { + /* + * It looks like a bad file. Don't try to open it. + */ error("%s", &parg); free(parg.p_string); @@ -231,16 +262,18 @@ if (alt_filename != NULL) { - close_altfile(alt_filename, filename); + close_altfile(alt_filename, filename, alt_pipe); free(alt_filename); } del_ifile(ifile); + /* + * Re-open the current file. + */ + (void) edit_ifile(old_ifile); return (1); - } -#if MSOFTC - else if ((f = open(open_filename, O_RDONLY|O_BINARY)) < 0) -#else - else if ((f = open(open_filename, 0)) < 0) -#endif + } else if ((f = open(open_filename, OPEN_READ)) < 0) { + /* + * Got an error trying to open it. + */ parg.p_string = errno_message(filename); error("%s", &parg); @@ -249,4 +282,7 @@ } else if (!force_open && !opened(ifile) && bin_file(f)) { + /* + * Looks like a binary file. Ask user if we should proceed. + */ parg.p_string = filename; answer = query("\"%s\" may be a binary file. See it anyway? ", @@ -259,28 +295,4 @@ } - ispipe = ISPIPE(f); -#if LOGFILE -{ - char *s; - - /* - * - */ - s = namelogfile; - end_logfile(); - if (f >= 0 && ispipe && s != NULL && is_tty) - use_logfile(s); -} -#endif - - /* - * We are now committed to using the new file. - * Close the current input file and set up to use the new one. - */ - if (curr_ifile != NULL_IFILE) - { - old_ifile = curr_ifile; - close_file(); - } /* * Get the new ifile. @@ -288,17 +300,14 @@ */ curr_ifile = ifile; - file = f; curr_altfilename = alt_filename; + curr_altpipe = alt_pipe; set_open(curr_ifile); /* File has been opened */ get_pos(curr_ifile, &initial_scrpos); - - if (ispipe) - ch_pipe(); - else - ch_nonpipe(); - (void) ch_nbuf(cbufs); - ch_flush(); - - new_file = 1; + new_file = TRUE; + ch_init(f, chflags); +#if LOGFILE + if (namelogfile != NULL && is_tty) + use_logfile(namelogfile); +#endif if (every_first_cmd != NULL) @@ -307,5 +316,5 @@ no_display = !any_display; flush(); - any_display = 1; + any_display = TRUE; if (is_tty) @@ -320,4 +329,7 @@ pos_clear(); clr_linenum(); +#if HILITE_SEARCH + clr_hilite(); +#endif if (no_display && errmsgs > 0) { @@ -393,5 +405,5 @@ return (0); if (edit_ifile(save_curr_ifile)) - quit(-1); + quit(QUIT_ERROR); return (edit(good_filename)); } @@ -516,4 +528,7 @@ } +/* + * Edit standard input. + */ public int edit_stdin() @@ -521,10 +536,10 @@ if (isatty(fd0)) { -#if MSOFTC +#if MSOFTC || OS2 error("Missing filename (\"less -?\" for help)", NULL_PARG); #else error("Missing filename (\"less -\\?\" for help)", NULL_PARG); #endif - quit(0); + quit(QUIT_OK); } return (edit("-")); @@ -560,8 +575,14 @@ PARG parg; + if (ch_getflags() & CH_CANSEEK) + /* + * Can't currently use a log file on a file that can seek. + */ + return; + /* * {{ We could use access() here. }} */ - exists = open(filename, 0); + exists = open(filename, OPEN_READ); close(exists); exists = (exists >= 0); @@ -569,5 +590,5 @@ /* * Decide whether to overwrite the log file or append to it. - * (If it doesn't exist we "overwrite" it. + * If it doesn't exist we "overwrite" it. */ if (!exists || force_logfile) @@ -599,9 +620,5 @@ * Append: open the file and seek to the end. */ -#if MSOFTC - logfile = open(filename, O_APPEND|O_WRONLY); -#else - logfile = open(filename, 1); -#endif + logfile = open(filename, OPEN_APPEND); if (lseek(logfile, (off_t)0, 2) == BAD_LSEEK) { @@ -616,5 +633,5 @@ return; case 'q': - quit(0); + quit(QUIT_OK); /*NOTREACHED*/ default: @@ -622,5 +639,5 @@ * Eh? */ - answer = query("Overwrite, Append, or Don't log? ", NULL_PARG); + answer = query("Overwrite, Append, or Don't log? (Type \"O\", \"A\", \"D\" or \"q\") ", NULL_PARG); goto loop; } diff -r -U2 less-252/filename.c less-278/filename.c --- less-252/filename.c Sat Oct 15 03:16:45 1994 +++ less-278/filename.c Tue Jan 31 18:55:39 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -50,9 +50,9 @@ register char *homedir; - homedir = getenv("HOME"); #if MSOFTC /* * If $HOME is not defined, look for the file anywhere on search path. */ + homedir = getenv("HOME"); pathname = NULL; if (homedir != NULL) @@ -86,4 +86,18 @@ #else +#if OS2 + pathname = (char *) calloc(256, sizeof(char)); + if (pathname == NULL) + return (NULL); + _searchenv(filename, "INIT", pathname); + if (pathname[0] == '\0') + _searchenv(filename, "PATH", pathname); + if (pathname[0] == '\0') + { + free(pathname); + return (NULL); + } +#else + homedir = getenv("HOME"); if (homedir == NULL) return (NULL); @@ -94,4 +108,5 @@ sprintf(pathname, "%s/%s", homedir, filename); #endif +#endif return (pathname); } @@ -107,5 +122,5 @@ if ((helpfile = getenv("LESSHELP")) != NULL) return (save(helpfile)); -#if MSOFTC +#if MSOFTC || OS2 return (homefile(HELPFILE)); #else @@ -218,4 +233,7 @@ if (s != NULL && strcmp(s,fpat) == 0) { + /* + * The filename didn't expand. + */ free(s); s = NULL; @@ -238,4 +256,8 @@ unsigned char data[64]; + if (!seekable(f)) + return (0); + if (lseek(f, (off_t)0, 0) == BAD_LSEEK) + return (0); n = read(f, data, sizeof(data)); for (i = 0; i < n; i++) @@ -260,11 +282,12 @@ } -/* - * Expand a filename, substituting any environment variables, etc. - */ #if GLOB FILE *popen(); +/* + * Read a string from a file. + * Return a pointer to the string in memory. + */ static char * readfd(fd) @@ -276,4 +299,8 @@ char *p; + /* + * Make a guess about how many chars in the string + * and allocate a buffer to hold it. + */ len = 100; buf = (char *) ecalloc(len, sizeof(char)); @@ -284,4 +311,8 @@ if (p - buf >= len-1) { + /* + * The string is too big to fit in the buffer we have. + * Allocate a new buffer, twice as big. + */ len *= 2; *p = '\0'; @@ -298,4 +329,8 @@ } +/* + * Execute a shell command. + * Return a pointer to a pipe connected to the shell command's standard output. + */ static FILE * shellcmd(cmd, s1, s2) @@ -315,4 +350,5 @@ scmd = (char *) ecalloc(len, sizeof(char)); sprintf(scmd, cmd, s1, s2); +#if HAVE_SHELL shell = getenv("SHELL"); if (shell != NULL && *shell != '\0') @@ -327,5 +363,5 @@ scmd = scmd2; } - +#endif fd = popen(scmd, "r"); free(scmd); @@ -333,9 +369,11 @@ } +/* + * Expand a filename, doing any shell-level substitutions. + */ public char * glob(filename) char *filename; { - FILE *fd; char *gfilename; @@ -343,4 +381,25 @@ if (filename == NULL) return (NULL); +#if OS2 +{ + char **list; + int cnt; + int length; + + list = _fnexplode(filename); + length = 0; + for (cnt = 0; list[cnt] != NULL; cnt++) + length += strlen(list[cnt]) + 1; + gfilename = (char *) ecalloc(length, sizeof(char)); + for (cnt = 0; list[cnt] != NULL; cnt++) + { + strcat(gfilename, list[cnt]); + strcat(gfilename, " "); + } + _fnexplodefree(list); +} +#else +{ + FILE *fd; /* @@ -362,20 +421,38 @@ if (*gfilename == '\0') return (NULL); +} +#endif return (gfilename); } +/* + * See if we should open a "replacement file" + * instead of the file we're about to open. + */ public char * -open_altfile(filename) +open_altfile(filename, pf, pfd) char *filename; + int *pf; + void **pfd; { char *lessopen; char *gfilename; + int returnfd = 0; FILE *fd; + ch_ungetchar(-1); if ((lessopen = getenv("LESSOPEN")) == NULL) return (NULL); - filename = fexpand(filename); - if (filename == NULL) + if (strcmp(filename, "-") == 0) return (NULL); + if (*lessopen == '|') + { + /* + * If LESSOPEN starts with a |, it indicates + * a "pipe preprocessor". + */ + lessopen++; + returnfd = 1; + } fd = shellcmd(lessopen, filename, (char*)NULL); if (fd == NULL) @@ -386,20 +463,53 @@ return (NULL); } - free(filename); + if (returnfd) + { +#if HAVE_FILENO + int f; + char c; + + /* + * Read one char to see if the pipe will produce any data. + * If it does, push the char back on the pipe. + */ + f = fileno(fd); + if (read(f, &c, 1) != 1) + /* + * Pipe is empty. This means there is no alt file. + */ + return (NULL); + ch_ungetchar(c); + *pfd = (void *) fd; + *pf = f; + return (save("-")); +#else + error("LESSOPEN pipe is not supported", NULL_PARG); + return (NULL); +#endif + } gfilename = readfd(fd); pclose(fd); if (*gfilename == '\0') + /* + * Pipe is empty. This means there is no alt file. + */ return (NULL); return (gfilename); } +/* + * Close a replacement file. + */ public void -close_altfile(altfilename, filename) +close_altfile(altfilename, filename, pipefd) char *altfilename; char *filename; + void *pipefd; { char *lessclose; FILE *fd; + if (pipefd != NULL) + pclose((FILE*) pipefd); if ((lessclose = getenv("LESSCLOSE")) == NULL) return; @@ -501,4 +611,10 @@ #include +#ifndef S_ISDIR +#define S_ISDIR(m) (((m) & S_IFMT) == S_IFDIR) +#endif +#ifndef S_ISREG +#define S_ISREG(m) (((m) & S_IFMT) == S_IFREG) +#endif /* @@ -520,5 +636,5 @@ return (NULL); - if ((statbuf.st_mode & S_IFMT) == S_IFDIR) + if (S_ISDIR(statbuf.st_mode)) { static char is_dir[] = " is a directory"; @@ -529,5 +645,5 @@ return (m); } - if ((statbuf.st_mode & S_IFMT) != S_IFREG) + if (!S_ISREG(statbuf.st_mode)) { static char not_reg[] = " is not a regular file"; diff -r -U2 less-252/forwback.c less-278/forwback.c --- less-252/forwback.c Sat Oct 15 03:16:45 1994 +++ less-278/forwback.c Tue Jan 31 18:55:40 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -147,5 +147,5 @@ * but we don't yet know if that will happen. }} */ - if (top_scroll == 2 || first_time) + if (top_scroll == OPT_ONPLUS || first_time) clear(); home(); @@ -168,5 +168,5 @@ if (top_scroll) { - if (top_scroll == 2) + if (top_scroll == OPT_ONPLUS) clear(); home(); @@ -327,5 +327,5 @@ */ if (edit_next(1)) - quit(0); + quit(QUIT_OK); return; } diff -r -U2 less-252/funcs.h less-278/funcs.h --- less-252/funcs.h Thu Oct 27 17:23:39 1994 +++ less-278/funcs.h Tue Jan 31 18:55:41 1995 @@ -13,4 +13,5 @@ public void add_line (); public void lower_left (); + public void goto_line (); public void bell (); public void vbell (); @@ -29,4 +30,5 @@ public void putbs (); public void match_brac (); + public void ch_ungetchar (); public void end_logfile (); public void sync_logfile (); @@ -40,8 +42,9 @@ public int ch_nbuf (); public void ch_flush (); - public void ch_pipe (); - public void ch_nonpipe (); - public POSITION forw_raw_line (); - public POSITION back_raw_line (); + public int seekable (); + public void ch_init (); + public void ch_close (); + public int ch_getflags (); + public void ch_dump (); public void init_charset (); public int binary_char (); @@ -57,4 +60,5 @@ public char * get_cmdbuf (); public int in_mca (); + public void dispversion (); public int getcc (); public void ungetcc (); @@ -120,4 +124,7 @@ public void set_open (); public int opened (); + public void * get_filestate (); + public void set_filestate (); + public void if_dump (); public POSITION forw_line (); public POSITION back_line (); @@ -153,5 +160,4 @@ public void opt__O (); public void opt_l (); - public void opt__L (); public void opt_k (); public void opt_t (); @@ -200,8 +206,13 @@ public char * eq_message (); public char * pr_string (); + public void repaint_hilite (); public void undo_search (); + public void clr_hilite (); + public void add_hilite (); + public int is_hilited (); public void chg_caseless (); + public void chg_hilite (); public int search (); - public void hlsearch (); + public void prep_hilite (); public void fake_interrupt (); public RETSIGTYPE winch (); diff -r -U2 less-252/help.c less-278/help.c --- less-252/help.c Sat Oct 15 03:16:46 1994 +++ less-278/help.c Tue Jan 31 18:55:42 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -70,7 +70,13 @@ cmd = (char *) ecalloc(strlen(helpfile) + strlen(progname) + 150, sizeof(char)); +#if OS2 + sprintf(cmd, + "-%s -m -H -+E -+s \"-PmHELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done \" %s", + progname, helpfile); +#else sprintf(cmd, "-%s -m -H -+E -+s '-PmHELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done ' %s", progname, helpfile); +#endif #endif free(helpfile); diff -r -U2 less-252/ifile.c less-278/ifile.c --- less-252/ifile.c Sat Oct 15 03:16:46 1994 +++ less-278/ifile.c Tue Jan 31 18:55:43 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -45,4 +45,5 @@ struct ifile *h_prev; char *h_filename; /* Name of the file */ + void *h_filestate; /* File state (used in ch.c) */ int h_index; /* Index within command line list */ int h_opened; /* Only need one bit */ @@ -304,3 +305,32 @@ } + public void * +get_filestate(ifile) + IFILE ifile; +{ + return (int_ifile(ifile)->h_filestate); +} + + public void +set_filestate(ifile, filestate) + IFILE ifile; + void *filestate; +{ + int_ifile(ifile)->h_filestate = filestate; +} +#if 0 + public void +if_dump() +{ + register struct ifile *p; + + for (p = anchor.h_next; p != &anchor; p = p->h_next) + { + printf("%x: %d. <%s> pos %d,%x\n", + p, p->h_index, p->h_filename, + p->h_scrpos.ln, p->h_scrpos.pos); + ch_dump(p->h_filestate); + } +} +#endif diff -r -U2 less-252/input.c less-278/input.c --- less-252/input.c Sat Oct 15 03:16:46 1994 +++ less-278/input.c Tue Jan 31 18:55:44 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -41,4 +41,8 @@ extern int chopline; extern int sigs; +#if HILITE_SEARCH +extern int hilite_search; +extern int size_linebuf; +#endif /* @@ -58,5 +62,14 @@ int endline; - if (curr_pos == NULL_POSITION || ch_seek(curr_pos)) + if (curr_pos == NULL_POSITION) + { + null_line(); + return (NULL_POSITION); + } +#if HILITE_SEARCH + if (hilite_search == OPT_ONPLUS) + prep_hilite(curr_pos, curr_pos + 3*size_linebuf); +#endif + if (ch_seek(curr_pos)) { null_line(); @@ -96,5 +109,5 @@ * Append the char to the line and get the next char. */ - if (pappend(c)) + if (pappend(c, ch_tell()-1)) { /* @@ -158,6 +171,15 @@ int endline; - if (curr_pos == NULL_POSITION || curr_pos <= ch_zero() || - ch_seek(curr_pos-1)) + if (curr_pos == NULL_POSITION || curr_pos <= ch_zero()) + { + null_line(); + return (NULL_POSITION); + } +#if HILITE_SEARCH + if (hilite_search == OPT_ONPLUS) + prep_hilite((curr_pos < 3*size_linebuf) ? + 0 : curr_pos - 3*size_linebuf, curr_pos); +#endif + if (ch_seek(curr_pos-1)) { null_line(); @@ -264,5 +286,5 @@ break; } - if (pappend(c)) + if (pappend(c, ch_tell()-1)) { /* diff -r -U2 less-252/jump.c less-278/jump.c --- less-252/jump.c Sat Oct 15 03:16:46 1994 +++ less-278/jump.c Tue Jan 31 18:55:45 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/less.h less-278/less.h --- less-252/less.h Sat Oct 15 03:16:46 1994 +++ less-278/less.h Tue Jan 31 18:55:46 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -56,4 +56,7 @@ #include #endif +#if HAVE_FCNTL_H +#include +#endif #if HAVE_UNISTD_H #include @@ -85,4 +88,15 @@ #endif +#ifndef TRUE +#define TRUE 1 +#endif +#ifndef FALSE +#define FALSE 0 +#endif + +#define OPT_OFF 0 +#define OPT_ON 1 +#define OPT_ONPLUS 2 + #ifndef HAVE_MEMCPY #ifndef memcpy @@ -106,4 +120,24 @@ /* + * Flags for open() + */ +#if MSOFTC || OS2 +#define OPEN_READ (O_RDONLY|O_BINARY) +#else +#define OPEN_READ (0) +#endif +#if MSOFTC || OS2 +#define OPEN_APPEND (O_APPEND|O_WRONLY) +#else +#define OPEN_APPEND (1) +#endif + +#if MSOFTC || OS2 +#define OPEN_TTYIN() open("CON", O_TEXT|O_RDONLY) +#else +#define OPEN_TTYIN() open("/dev/tty", 0) +#endif + +/* * An IFILE represents an input file. */ @@ -158,12 +192,14 @@ /* How should we search? */ -#define SRCH_FORW 0 /* Search forward from current position */ -#define SRCH_BACK 1 /* Search backward from current position */ +#define SRCH_FORW 0001 /* Search forward from current position */ +#define SRCH_BACK 0002 /* Search backward from current position */ +#define SRCH_FIND_ALL 0010 /* Find and highlight all matches */ #define SRCH_NOMATCH 0100 /* Search for non-matching lines */ #define SRCH_PAST_EOF 0200 /* Search past end-of-file, into next file */ #define SRCH_FIRST_FILE 0400 /* Search starting at the first file */ -#define SRCH_DIR(t) ((t) & 01) -#define SRCH_REVERSE(t) ((t) ^ 01) +#define SRCH_REVERSE(t) (((t) & SRCH_FORW) ? \ + (((t) & ~SRCH_FORW) | SRCH_BACK) : \ + (((t) & ~SRCH_BACK) | SRCH_FORW)) /* */ @@ -194,4 +230,13 @@ #define S_WINCH 04 #define ABORT_SIGS() (sigs & (S_INTERRUPT|S_STOP)) + +#define QUIT_OK 0 +#define QUIT_ERROR 1 +#define QUIT_SAVED_STATUS (-1) + +/* filestate flags */ +#define CH_CANSEEK 001 +#define CH_KEEPOPEN 002 +#define CH_POPENED 004 #define ch_zero() ((POSITION)0) diff -r -U2 less-252/less.hlp less-278/less.hlp --- less-252/less.hlp Thu Oct 27 17:33:18 1994 +++ less-278/less.hlp Tue Jan 31 18:55:47 1995 @@ -66,5 +66,5 @@ !_c_o_m_m_a_n_d Passes the command to $SHELL to be executed. |XX_c_o_m_m_a_n_d Pipe file between current pos & mark XX to shell command. - v Edit the current file with $EDITOR. + v Edit the current file with $VISUAL or $EDITOR. --------------------------------------------------- FLAGS @@ -74,14 +74,16 @@ -? Display help (from command line). - -a Set forward search starting location. + -a Forward search skips current screen. -b [_N] Number of buffers. - -B Automatically allocate buffers. + -B Don't automatically allocate buffers for pipes. -c -C Repaint by scrolling/clearing. -d Dumb terminal. -e -E Quit at end of file. -f Force open non-regular files. - -F Don't highlight matches for previous search pattern. + -g Don't highlight matches for previous search pattern. + -G Highlight ALL matches for previous search pattern. -h [_N] Backward scroll limit. -i Ignore case in searches. + -I Ignore case in searches and in search patterns. -j [_N] Screen position of target lines. -k [_f_i_l_e] Use a lesskey file. @@ -93,5 +95,5 @@ -P [_p_r_o_m_p_t] Define new prompt. -q -Q Quiet the terminal bell. - -r Translate control characters. + -r Output "raw" control characters. -s Squeeze multiple blank lines. -S Chop long lines. diff -r -U2 less-252/less.man less-278/less.man --- less-252/less.man Tue Nov 1 15:53:12 1994 +++ less-278/less.man Tue Feb 14 13:22:00 1995 @@ -12,8 +12,8 @@ less -? less -V - less [-[+]aBcCdeEfHimMnNqQrsSuUw] + less [-[+]aBcCdeEfgGHiImMnNqQrsSuUw] [-b _b_u_f_s] [-h _l_i_n_e_s] [-j _l_i_n_e] [-k _k_e_y_f_i_l_e] [-{oO} _l_o_g_f_i_l_e] [-p _p_a_t_t_e_r_n] [-P _p_r_o_m_p_t] [-t _t_a_g] - [-T _t_a_g_f_i_l_e] [-x _t_a_b] [-y _l_i_n_e_s] [-[z] _l_i_n_e_s] + [-T _t_a_g_s_f_i_l_e] [-x _t_a_b] [-y _l_i_n_e_s] [-[z] _l_i_n_e_s] [+[+]_c_m_d] [_f_i_l_e_n_a_m_e]... @@ -298,5 +298,5 @@ command, turn highlighting back on. Any search command will also turn highlighting back on. (Highlighting can - also be disabled by toggling the -F flag; in that case + also be disabled by toggling the -G flag; in that case search commands do not turn highlighting back on.) @@ -410,6 +410,8 @@ v Invokes an editor to edit the current file being viewed. The editor is taken from the environment vari- - able EDITOR, or defaults to "vi". See also the discus- - sion of LESSEDIT under the section on PROMPTS below. + able VISUAL if defined, or EDITOR if VISUAL is not + defined, or defaults to "vi" if neither VISUAL nor EDI- + TOR is defined. See also the discussion of LESSEDIT + under the section on PROMPTS below. ! shell-command @@ -452,6 +454,4 @@ A dollar sign ($) may be used to signal the end of an option - string. This is important only for options like -P which - take a following string. @@ -468,4 +468,7 @@ + string. This is important only for options like -P which + take a following string. + -? This option displays a summary of the commands accepted by _l_e_s_s (the same as the h command). If this option is @@ -481,16 +484,20 @@ option). - -b_n Causes _l_e_s_s to use a non-standard number of buffers. - Buffers are 1K, and by default 10 buffers are used - (except if data in coming from standard input; see the - -B option). The number _n specifies a different number - of buffers to use. - - -B Disables automatic allocation of buffers, so that only - the default number of buffers are used. If more data - is read than will fit in the buffers, the oldest data - is discarded. By default, when data is coming from - standard input, buffers are allocated automatically as - needed to avoid loss of data. + -b_n Specifies the number of buffers _l_e_s_s will use for each + file. Buffers are 1K, and by default 10 buffers are + used for each file (except if the file is a pipe; see + the -B option). The number _n specifies a different + number of buffers to use. + + -B By default, when data is read from a pipe, buffers are + allocated automatically as needed. If a large amount + of data is read from the pipe, this can cause a large + amount of memory to be allocated. The -B option dis- + ables this automatic allocation of buffers for pipes, + so that only the number of buffers specified by the -b + option are used. Warning: use of -B can result in + erroneous display, since only the most recently viewed + part of the file is kept in memory; any earlier data is + lost. -c Causes full screen repaints to be painted from the top @@ -513,11 +520,4 @@ u=underlined, k=blink. _c_o_l_o_r is a pair of numbers separated by a period. The first number selects the - foreground color and the second selects the background - color of the text. A single number _N is the same as - _N._0. - - -e Causes _l_e_s_s to automatically exit the second time it - reaches end-of-file. By default, the only way to exit - _l_e_s_s is via the "q" command. @@ -534,4 +534,12 @@ + foreground color and the second selects the background + color of the text. A single number _N is the same as + _N._0. + + -e Causes _l_e_s_s to automatically exit the second time it + reaches end-of-file. By default, the only way to exit + _l_e_s_s is via the "q" command. + -E Causes _l_e_s_s to automatically exit the first time it reaches end-of-file. @@ -543,7 +551,12 @@ regular files. - -F Normally, _l_e_s_s will highlight all strings which match - the current search pattern, by displaying them in stan- - dout mode. The -F flag suppresses this highlighting. + -g Normally, _l_e_s_s will highlight ALL strings which match + the last search command. The -g flag changes this + behavior to highlight only the particular string which + was found by the last search command. This can cause + _l_e_s_s to run somewhat faster than the default. + + -G The -G flag suppresses all highlighting of strings + found by search commands. -h_n Specifies a maximum number of lines to scroll backward. @@ -556,48 +569,51 @@ lowercase are considered identical. This option is ignored if any uppercase letters appear in the search - pattern. + pattern; in other words, if a pattern contains upper- + case letters, then that search does not ignore case. - -j_n Specifies a line on the screen where "target" lines are - to be positioned. Target lines are the object of text - searches, tag searches, jumps to a line number, jumps - to a file percentage, and jumps to a marked position. - The screen line is specified by a number: the top line - on the screen is 1, the next is 2, and so on. The - number may be negative to specify a line relative to - the bottom of the screen: the bottom line on the screen - is -1, the second to the bottom is -2, and so on. If - the -j option is used, searches begin at the line - immediately after the target line. For example, if "- - j4" is used, the target line is the fourth line on the - screen, so searches begin at the fifth line on the - screen. + -I Like -i, but searches ignore case even if the pattern + contains uppercase letters. - -k_f_i_l_e_n_a_m_e - Causes _l_e_s_s to open and interpret the named file as a - _l_e_s_s_k_e_y (1) file. Multiple -k options may be speci- - fied. If a file called .less exists in the user's home - directory, this file is also used as a _l_e_s_s_k_e_y file. + -j_n Specifies a line on the screen where the "target" line + is to be positioned. A target line is the object of a + text search, tag search, jump to a line number, jump to + a file percentage, or jump to a marked position. The + screen line is specified by a number: the top line on + the screen is 1, the next is 2, and so on. The number + may be negative to specify a line relative to the bot- + tom of the screen: the bottom line on the screen is -1, + the second to the bottom is -2, and so on. If the -j + option is used, searches begin at the line immediately + after the target line. For example, if "-j4" is used, - -m Causes _l_e_s_s to prompt verbosely (like _m_o_r_e), with the - percent into the file. By default, _l_e_s_s prompts with a - colon. - -M Causes _l_e_s_s to prompt even more verbosely than _m_o_r_e. - -n Suppresses line numbers. The default (to use line + 9 - 9 +LESS(1) USER COMMANDS LESS(1) -LESS(1) USER COMMANDS LESS(1) + the target line is the fourth line on the screen, so + searches begin at the fifth line on the screen. + -k_f_i_l_e_n_a_m_e + Causes _l_e_s_s to open and interpret the named file as a + _l_e_s_s_k_e_y (1) file. Multiple -k options may be speci- + fied. If a file called .less exists in the user's home + directory, this file is also used as a _l_e_s_s_k_e_y file. + -m Causes _l_e_s_s to prompt verbosely (like _m_o_r_e), with the + percent into the file. By default, _l_e_s_s prompts with a + colon. + -M Causes _l_e_s_s to prompt even more verbosely than _m_o_r_e. + + -n Suppresses line numbers. The default (to use line numbers) may cause _l_e_s_s to run more slowly in some cases, especially with a very large input file. @@ -632,8 +648,22 @@ The -p option on the command line is equivalent to specifying +/_p_a_t_t_e_r_n; that is, it tells _l_e_s_s to start - at the first occurence of _p_a_t_t_e_r_n in the file. + at the first occurrence of _p_a_t_t_e_r_n in the file. -P_p_r_o_m_p_t Provides a way to tailor the three prompt styles to + + + + 10 + + + + + + +LESS(1) USER COMMANDS LESS(1) + + + your own preference. This option would normally be put in the LESS environment variable, rather than being @@ -652,18 +682,4 @@ is not rung if an attempt is made to scroll past the end of the file or before the beginning of the file. - - - - 10 - - - - - - -LESS(1) USER COMMANDS LESS(1) - - - If the terminal has a "visual bell", it is used instead. The bell will be rung on certain other @@ -703,4 +719,17 @@ within _l_e_s_s. + + + 11 + + + + + + +LESS(1) USER COMMANDS LESS(1) + + + -T_t_a_g_s_f_i_l_e Specifies a tags file to be used instead of "tags". @@ -718,18 +747,4 @@ treated specially: the underlined text is displayed using the terminal's hardware underlining capability. - - - - 11 - - - - - - -LESS(1) USER COMMANDS LESS(1) - - - Also, backspaces which appear between two identical characters are treated specially: the overstruck text @@ -739,11 +754,12 @@ lowed by a newline are deleted. Other carriage returns are handled as specified by the -r option. Text which - is overstruck or underlined can be searched for. + is overstruck or underlined can be searched for if nei- + ther -u nor -U is in effect. -V Displays the version number of _l_e_s_s. -w Causes blank lines to be used to represent lines past - the end of the file. By default, a tilde character is - used. + the end of the file. By default, a tilde character (~) + is used. -x_n Sets tab stops every _n positions. The default for _n is @@ -768,4 +784,18 @@ omitted for compatibility with _m_o_r_e. If the number _n is negative, it indicates _n lines less than the current + + + + 12 + + + + + + +LESS(1) USER COMMANDS LESS(1) + + + screen size. For example, if the screen is 24 lines, -_z-_4 sets the scrolling window to 20 lines. If the @@ -784,18 +814,4 @@ applies to every file being viewed, not just the first one. The + command described previously may also be - - - - 12 - - - - - - -LESS(1) USER COMMANDS LESS(1) - - - used to set (or change) an initial command for every file. @@ -834,34 +850,34 @@ Move the cursor to the end of the line. - BACKSPACE - Delete the char to the left of the cursor, or cancel - the command if the command line is empty. - DELETE or [ ESC-x ] - Delete the char under the cursor. - ^BACKSPACE [ ESC-BACKSPACE ] - (That is, CONTROL and BACKSPACE simultaneously.) Delete - the word to the left of the cursor. - ^DELETE [ ESC-X or ESC-DELETE ] - (That is, CONTROL and DELETE simultaneously.) Delete - the word under the cursor. + 13 - UPARROW [ ESC-k ] - 13 +LESS(1) USER COMMANDS LESS(1) + BACKSPACE + Delete the character to the left of the cursor, or can- + cel the command if the command line is empty. -LESS(1) USER COMMANDS LESS(1) + DELETE or [ ESC-x ] + Delete the character under the cursor. + ^BACKSPACE [ ESC-BACKSPACE ] + (That is, CONTROL and BACKSPACE simultaneously.) Delete + the word to the left of the cursor. + ^DELETE [ ESC-X or ESC-DELETE ] + (That is, CONTROL and DELETE simultaneously.) Delete + the word under the cursor. + UPARROW [ ESC-k ] Retrieve the previous command line. @@ -872,5 +888,5 @@ sor. If it matches more than one filename, the first match is entered into the command line. Repeated TABs - will cycle thru the other matching filesnames. + will cycle thru the other matching filenames. BACKTAB [ ESC-TAB ] @@ -900,4 +916,18 @@ INPUT PREPROCESSOR You may define an "input preprocessor" for _l_e_s_s. Before _l_e_s_s + + + + 14 + + + + + + +LESS(1) USER COMMANDS LESS(1) + + + opens a file, it first gives your input preprocessor a chance to modify the way the contents of the file are @@ -916,24 +946,11 @@ name of the replacement file to its standard output. If the input preprocessor does not output a replacement filename, - - - - 14 - - - - - - -LESS(1) USER COMMANDS LESS(1) - - - - _l_e_s_s uses the original file, as normal. To set up an input - preprocessor, set the LESSOPEN environment variable to a - command line which will invoke your input preprocessor. - This command line should include one occurence of the string - "%s", which will be replaced by the filename when the input - preprocessor command is invoked. + _l_e_s_s uses the original file, as normal. The input prepro- + cessor is not called when viewing standard input. To set up + an input preprocessor, set the LESSOPEN environment variable + to a command line which will invoke your input preprocessor. + This command line should include one occurrence of the + string "%s", which will be replaced by the filename when the + input preprocessor command is invoked. When _l_e_s_s closes a file opened in such a way, it will call @@ -945,5 +962,5 @@ file. To set up an input postprocessor, set the LESSCLOSE environment variable to a command line which will invoke - your input postprocessor. It may include two occurences of + your input postprocessor. It may include two occurrences of the string "%s"; the first is replaced with the original name of the file and the second with the name of the @@ -952,13 +969,30 @@ For example, on many Unix systems, these two scripts will allow you to keep files in compressed format, but still let - _l_e_s_s view them directly (by giving _l_e_s_s the name of the file - without the .Z suffix): + _l_e_s_s view them directly: lessopen.sh: #! /bin/sh - if [ -f "$1.Z" ]; then - uncompress -c $1.Z >$1.tmp - echo $1.tmp - fi + case "$1" in + *.Z) uncompress -c $1 >/tmp/less.$$ 2>/dev/null + if [ -s /tmp/less.$$ ]; then + echo /tmp/less.$$ + else + rm -f /tmp/less.$$ + fi + ;; + esac + + + + 15 + + + + + + +LESS(1) USER COMMANDS LESS(1) + + lessclose.sh: @@ -969,7 +1003,37 @@ cuted and set LESSOPEN="lessopen.sh %s", and LESSCLOSE="lessclose.sh %s %s". More complex LESSOPEN and - LESSCLOSE scripts may be written to also accept the filename - either with or without the .Z suffix, or to accept other - types of compressed files, and so on. + LESSCLOSE scripts may be written to accept other types of + compressed files, and so on. + + It is also possible to set up an input preprocessor to pipe + the file data directly to _l_e_s_s, rather than putting the data + into a replacement file. This avoids the need to decompress + the entire file before starting to view it. An input + preprocessor that works this way is called an input pipe. + An input pipe, instead of writing the name of a replacement + file on its standard output, writes the entire contents of + the replacement file on its standard output. If the input + pipe does not write any characters on its standard output, + then there is no replacement file and _l_e_s_s uses the original + file, as normal. To use an input pipe, make the first char- + acter in the LESSOPEN environment variable a vertical bar + (|) to signify that the input preprocessor is an input pipe. + + For example, on many Unix systems, this script will work + like the previous example scripts: + + lesspipe.sh: + !# /bin/sh + case "$1" in + *.Z) uncompress -c $1 2>/dev/null + ;; + esac + + To use this script, put it where it can be executed and set + LESSOPEN="|lesspipe.sh %s". When an input pipe is used, a + LESSCLOSE postprocessor can be used, but it is usually not + necessary since there is no replacement file to clean up. + In this case, the replacement file name passed to the LESS- + CLOSE postprocessor is "-". @@ -982,8 +1046,10 @@ control characters should not be displayed directly, but are expected to + be found in ordinary text files (such as backspace and + tab). - 15 + 16 @@ -996,7 +1062,4 @@ - be found in ordinary text files (such as backspace and - tab). - binary characters should not be displayed directly and are not expected @@ -1021,4 +1084,9 @@ dos Selects a character set appropriate for MS-DOS. + koi8-r + Selects a Russian character set. + + next Selects a character set appropriate for NeXT computers. + In special cases, it may be desired to tailor _l_e_s_s to use a character set other than the ones definable by LESSCHARSET. @@ -1036,14 +1104,12 @@ character set.) - Setting LESSCHARDEF to "8bcccbcc18b95.b" is the same as set- - ting LESSCHARSET to "ascii". Setting LESSCHARDEF to - "8bcccbcc18b95.33b." is the same as setting LESSCHARSET to - "latin1". + This table shows the value of LESSCHARDEF which is + equivalent to each of the possible values for LESSCHARSET: - If neither LESSCHARSET nor LESSCHARDEF is set, but your sys- - tem supports the _s_e_t_l_o_c_a_l_e interface, _l_e_s_s will use setlo- - cale to determine the character set. setlocale is con- - trolled by setting the LANG or LC_CTYPE environment vari- - ables. + ascii 8bcccbcc18b95.b + latin1 8bcccbcc18b95.33b. + dos 8bcccbcc12bc5b95.b. + koi8-r 8bcccbcc18b95.b128. + next 8bcccbcc18b95.bb125.bb @@ -1051,5 +1117,5 @@ - 16 + 17 @@ -1062,4 +1128,10 @@ + If neither LESSCHARSET nor LESSCHARDEF is set, but your sys- + tem supports the _s_e_t_l_o_c_a_l_e interface, _l_e_s_s will use setlo- + cale to determine the character set. setlocale is con- + trolled by setting the LANG or LC_CTYPE environment vari- + ables. + Control and binary characters are displayed in standout (reverse video). Each such character is displayed in caret @@ -1105,26 +1177,27 @@ %B Replaced by the size of the current input file. - %E Replaced by the name of the editor (from the EDITOR - environment variable). See the discussion of the - LESSEDIT feature below. + %E Replaced by the name of the editor (from the VISUAL + environment variable, or the EDITOR environment vari- + able if VISUAL is not defined). See the discussion of - %f Replaced by the name of the current input file. - %i Replaced by the index of the current file in the list - of input files. + 18 - 17 +LESS(1) USER COMMANDS LESS(1) -LESS(1) USER COMMANDS LESS(1) + the LESSEDIT feature below. + %f Replaced by the name of the current input file. + %i Replaced by the index of the current file in the list + of input files. %l_X Replaced by the line number of a line in the input @@ -1174,24 +1247,23 @@ ?e True if at end-of-file. - ?f True if there is an input filename (that is, if input - is not a pipe). - ?l_X True if the line number of the specified line is known. - - ?L True if the line number of the last line in the file is + 19 - 18 +LESS(1) USER COMMANDS LESS(1) -LESS(1) USER COMMANDS LESS(1) + ?f True if there is an input filename (that is, if input + is not a pipe). + ?l_X True if the line number of the specified line is known. + ?L True if the line number of the last line in the file is known. @@ -1239,25 +1311,25 @@ truncated. This is the default prompt. For reference, here are the defaults for the other two prompts (-m and -M - respectively). Each is broken into two lines here for rea- - dability only. + respectively). Each is broken into two lines here for - ?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\: %x.: - ?pB%pB\%:byte %bB?s/%s...%t - ?f%f .?n?m(file %i of %m) ..?ltline %lt?L/%L. :byte %bB?s/%s. . + 20 - 19 +LESS(1) USER COMMANDS LESS(1) -LESS(1) USER COMMANDS LESS(1) + readability only. + ?n?f%f .?m(file %i of %m) ..?e(END) ?x- Next\: %x.: + ?pB%pB\%:byte %bB?s/%s...%t + ?f%f .?n?m(file %i of %m) ..?ltline %lt?L/%L. :byte %bB?s/%s. . ?e(END) ?x- Next\: %x.:?pB%pB\%..%t @@ -1305,25 +1377,25 @@ LESSBINFMT - Format for displaying non-printable, non-control char- - acters. + Format for displaying non-printable, non-control - LESSCHARDEF - Defines a character set. - LESSCHARSET + 21 - 20 +LESS(1) USER COMMANDS LESS(1) -LESS(1) USER COMMANDS LESS(1) + characters. + LESSCHARDEF + Defines a character set. + LESSCHARSET Selects a predefined character set. @@ -1354,4 +1426,7 @@ TERM The type of terminal on which _l_e_s_s is being run. + VISUAL + The name of the editor (used for the v command). + SEE ALSO @@ -1368,30 +1443,10 @@ files may be entered into the list in an unexpected order. - If a line longer than the screen width is split (folded), - and a search matches text which straddles the split, the - matching text will not be highlighted. In certain cases, - patterns beginning with a ^ may not be highlighted - correctly. Patterns which include a TAB character may not - be highlighted correctly. If a search is done using the ! - operator for text NOT matching a pattern, the strings which - do match the pattern are highlighted. In all cases, even if - the highlighting is incorrect, the text will nevertheless be - found correctly by the search. - - - - 21 - - -LESS(1) USER COMMANDS LESS(1) - - + 22 -COPYRIGHT - Copyright (c) 1984,1985,1989,1994 Mark Nudelman @@ -1399,10 +1454,21 @@ +LESS(1) USER COMMANDS LESS(1) + On certain older terminals (the so-called "magic cookie" + terminals), search highlighting will cause an erroneous + display. On such terminals, search highlighting is disabled + by default to avoid possible problems. + + In certain cases, when search highlighting is enabled and a + search pattern begins with a ^, more text than the matching + string may be highlighted. +COPYRIGHT + Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman @@ -1447,5 +1513,5 @@ - 22 + 23 diff -r -U2 less-252/less.nro less-278/less.nro --- less-252/less.nro Thu Oct 27 17:32:42 1994 +++ less-278/less.nro Tue Feb 14 13:21:46 1995 @@ -7,5 +7,5 @@ .B "less -V" .br -.B "less [-[+]aBcCdeEfHimMnNqQrsSuUw]" +.B "less [-[+]aBcCdeEfgGHiImMnNqQrsSuUw]" .br .B " [-b \fIbufs\fP] [-h \fIlines\fP] [-j \fIline\fP] [-k \fIkeyfile\fP]" @@ -13,5 +13,5 @@ .B " [-{oO} \fIlogfile\fP] [-p \fIpattern\fP] [-P \fIprompt\fP] [-t \fItag\fP]" .br -.B " [-T \fItagfile\fP] [-x \fItab\fP] [-y \fIlines\fP] [-[z] \fIlines\fP]" +.B " [-T \fItagsfile\fP] [-x \fItab\fP] [-y \fIlines\fP] [-[z] \fIlines\fP]" .br .B " [+[+]\fIcmd\fP] [\fIfilename\fP]..." @@ -256,5 +256,5 @@ turn highlighting back on. Any search command will also turn highlighting back on. -(Highlighting can also be disabled by toggling the -F flag; +(Highlighting can also be disabled by toggling the -G flag; in that case search commands do not turn highlighting back on.) .PP @@ -349,6 +349,7 @@ .IP v Invokes an editor to edit the current file being viewed. -The editor is taken from the environment variable EDITOR, -or defaults to "vi". +The editor is taken from the environment variable VISUAL if defined, +or EDITOR if VISUAL is not defined, +or defaults to "vi" if neither VISUAL nor EDITOR is defined. See also the discussion of LESSEDIT under the section on PROMPTS below. .PP @@ -416,18 +417,20 @@ (or after the last found line; see the -j option). .IP -b\fIn\fP -Causes +Specifies the number of buffers .I less -to use a non-standard number of buffers. -Buffers are 1K, and by default 10 buffers are used -(except if data in coming from standard input; see the -B option). +will use for each file. +Buffers are 1K, and by default 10 buffers are used for each file +(except if the file is a pipe; see the -B option). The number \fIn\fP specifies a different number of buffers to use. .IP -B -Disables automatic allocation of buffers, -so that only the default number of buffers are used. -If more data is read than will fit in the buffers, the oldest -data is discarded. -By default, when data is coming from standard input, -buffers are allocated automatically as needed -to avoid loss of data. +By default, when data is read from a pipe, +buffers are allocated automatically as needed. +If a large amount of data is read from the pipe, this can cause +a large amount of memory to be allocated. +The -B option disables this automatic allocation of buffers for pipes, +so that only the number of buffers specified by the -b option are used. +Warning: use of -B can result in erroneous display, since only the +most recently viewed part of the file is kept in memory; +any earlier data is lost. .IP -c Causes full screen repaints to be painted from the top line down. @@ -472,10 +475,15 @@ .I less will refuse to open non-regular files. -.IP -F +.IP -g Normally, .I less -will highlight all strings which match the current -search pattern, by displaying them in standout mode. -The -F flag suppresses this highlighting. +will highlight ALL strings which match the last search command. +The -g flag changes this behavior to highlight only the particular string +which was found by the last search command. +This can cause +.I less +to run somewhat faster than the default. +.IP -G +The -G flag suppresses all highlighting of strings found by search commands. .IP -h\fIn\fP Specifies a maximum number of lines to scroll backward. @@ -488,11 +496,16 @@ uppercase and lowercase are considered identical. This option is ignored if any uppercase letters -appear in the search pattern. +appear in the search pattern; +in other words, +if a pattern contains uppercase letters, then that search does not ignore case. +.IP -I +Like -i, but searches ignore case even if +the pattern contains uppercase letters. .IP -j\fIn\fP -Specifies a line on the screen where "target" lines -are to be positioned. -Target lines are the object of text searches, -tag searches, jumps to a line number, -jumps to a file percentage, and jumps to a marked position. +Specifies a line on the screen where the "target" line +is to be positioned. +A target line is the object of a text search, +tag search, jump to a line number, +jump to a file percentage, or jump to a marked position. The screen line is specified by a number: the top line on the screen is 1, the next is 2, and so on. @@ -567,5 +580,5 @@ that is, it tells .I less -to start at the first occurence of \fIpattern\fP in the file. +to start at the first occurrence of \fIpattern\fP in the file. .IP -P\fIprompt\fP Provides a way to tailor the three prompt @@ -651,5 +664,6 @@ Carriage returns immediately followed by a newline are deleted. Other carriage returns are handled as specified by the -r option. -Text which is overstruck or underlined can be searched for. +Text which is overstruck or underlined can be searched for +if neither -u nor -U is in effect. .IP -V Displays the version number of @@ -659,5 +673,5 @@ past the end of the file. By default, -a tilde character is used. +a tilde character (~) is used. .IP -x\fIn\fP Sets tab stops every \fIn\fP positions. @@ -731,8 +745,8 @@ Move the cursor to the end of the line. .IP "BACKSPACE" -Delete the char to the left of the cursor, +Delete the character to the left of the cursor, or cancel the command if the command line is empty. .IP "DELETE or [ ESC-x ]" -Delete the char under the cursor. +Delete the character under the cursor. .IP "^BACKSPACE [ ESC-BACKSPACE ]" (That is, CONTROL and BACKSPACE simultaneously.) @@ -749,5 +763,5 @@ If it matches more than one filename, the first match is entered into the command line. -Repeated TABs will cycle thru the other matching filesnames. +Repeated TABs will cycle thru the other matching filenames. .IP "BACKTAB [ ESC-TAB ]" Like, TAB, but cycles in the reverse direction thru the matching filenames. @@ -802,7 +816,8 @@ .I less uses the original file, as normal. +The input preprocessor is not called when viewing standard input. To set up an input preprocessor, set the LESSOPEN environment variable to a command line which will invoke your input preprocessor. -This command line should include one occurence of the string "%s", +This command line should include one occurrence of the string "%s", which will be replaced by the filename when the input preprocessor command is invoked. @@ -818,5 +833,5 @@ To set up an input postprocessor, set the LESSCLOSE environment variable to a command line which will invoke your input postprocessor. -It may include two occurences of the string "%s"; +It may include two occurrences of the string "%s"; the first is replaced with the original name of the file and the second with the name of the replacement file, @@ -826,7 +841,5 @@ to keep files in compressed format, but still let .I less -view them directly (by giving -.I less -the name of the file without the .Z suffix): +view them directly: .PP lessopen.sh: @@ -834,11 +847,21 @@ #! /bin/sh .br - if [ -f "$1.Z" ]; then + case "$1" in +.br + *.Z) uncompress -c $1 >/tmp/less.$$ 2>/dev/null +.br + if [ -s /tmp/less.$$ ]; then +.br + echo /tmp/less.$$ +.br + else .br - uncompress -c $1.Z >$1.tmp + rm -f /tmp/less.$$ .br - echo $1.tmp + fi .br - fi + ;; +.br + esac .PP lessclose.sh: @@ -852,6 +875,47 @@ LESSCLOSE="lessclose.sh\ %s\ %s". More complex LESSOPEN and LESSCLOSE scripts may be written -to also accept the filename either with or without the .Z suffix, -or to accept other types of compressed files, and so on. +to accept other types of compressed files, and so on. +.PP +It is also possible to set up an input preprocessor to +pipe the file data directly to +.I less, +rather than putting the data into a replacement file. +This avoids the need to decompress the entire file before +starting to view it. +An input preprocessor that works this way is called an input pipe. +An input pipe, instead of writing the name of a replacement file on +its standard output, +writes the entire contents of the replacement file on its standard output. +If the input pipe does not write any characters on its standard output, +then there is no replacement file and +.I less +uses the original file, as normal. +To use an input pipe, +make the first character in the LESSOPEN environment variable a +vertical bar (|) to signify that the input preprocessor is an input pipe. +.PP +For example, on many Unix systems, this script will work like the +previous example scripts: +.PP +lesspipe.sh: +.br + !# /bin/sh +.br + case "$1" in +.br + *.Z) uncompress -c $1 2>/dev/null +.br + ;; +.br + esac +.br +.PP +To use this script, put it where it can be executed and set +LESSOPEN="|lesspipe.sh %s". +When an input pipe is used, a LESSCLOSE postprocessor can be used, +but it is usually not necessary since there is no replacement file +to clean up. +In this case, the replacement file name passed to the LESSCLOSE +postprocessor is "-". .SH "NATIONAL CHARACTER SETS" @@ -881,4 +945,8 @@ .IP dos Selects a character set appropriate for MS-DOS. +.IP koi8-r +Selects a Russian character set. +.IP next +Selects a character set appropriate for NeXT computers. .PP In special cases, it may be desired to tailor @@ -899,8 +967,16 @@ represent any real character set.) .PP -Setting LESSCHARDEF to "8bcccbcc18b95.b" is the same as setting -LESSCHARSET to "ascii". -Setting LESSCHARDEF to "8bcccbcc18b95.33b." is the same as setting -LESSCHARSET to "latin1". +This table shows the value of LESSCHARDEF which is equivalent +to each of the possible values for LESSCHARSET: +.sp + ascii\ 8bcccbcc18b95.b +.br + latin1 8bcccbcc18b95.33b. +.br + dos\ \ \ 8bcccbcc12bc5b95.b. +.br + koi8-r 8bcccbcc18b95.b128. +.br + next\ \ 8bcccbcc18b95.bb125.bb .PP If neither LESSCHARSET nor LESSCHARDEF is set, @@ -952,5 +1028,6 @@ Replaced by the size of the current input file. .IP "%E" -Replaced by the name of the editor (from the EDITOR environment variable). +Replaced by the name of the editor (from the VISUAL environment variable, +or the EDITOR environment variable if VISUAL is not defined). See the discussion of the LESSEDIT feature below. .IP "%f" @@ -1130,4 +1207,6 @@ .I less is being run. +.IP VISUAL +The name of the editor (used for the v command). .SH "SEE ALSO" @@ -1143,15 +1222,14 @@ the new files may be entered into the list in an unexpected order. .PP -If a line longer than the screen width is split (folded), -and a search matches text which straddles the split, -the matching text will not be highlighted. -In certain cases, patterns beginning with a ^ may not be -highlighted correctly. -Patterns which include a TAB character may not be highlighted correctly. -If a search is done using the ! operator for text NOT matching a pattern, -the strings which do match the pattern are highlighted. -In all cases, even if the highlighting is incorrect, -the text will nevertheless be found correctly by the search. +On certain older terminals (the so-called "magic cookie" terminals), +search highlighting will cause an erroneous display. +On such terminals, search highlighting is disabled by default +to avoid possible problems. +.PP +In certain cases, when search highlighting is enabled and +a search pattern begins with a ^, +more text than the matching string may be highlighted. + .SH COPYRIGHT -Copyright (c) 1984,1985,1989,1994 Mark Nudelman +Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman diff -r -U2 less-252/lesskey.c less-278/lesskey.c --- less-252/lesskey.c Mon Nov 7 12:35:04 1994 +++ less-278/lesskey.c Tue Jan 31 18:55:52 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -216,4 +216,22 @@ extern char version[]; + char * +mkpathname(dirname, filename) + char *dirname; + char *filename; +{ + char *pathname; + + pathname = calloc(strlen(dirname) + strlen(filename) + 2, sizeof(char)); + strcpy(pathname, dirname); +#if MSOFTC || OS2 + strcat(pathname, "\\"); +#else + strcat(pathname, "/"); +#endif + strcat(pathname, filename); + return (pathname); +} + /* * Figure out the name of a default file (in the user's HOME directory). @@ -226,20 +244,16 @@ char *pathname; - p = getenv("HOME"); - if (p == NULL || *p == '\0') +#if OS2 + if ((p = getenv("INIT")) != NULL && *p != '\0') + pathname = mkpathname(p, filename); + else +#endif + if ((p = getenv("HOME")) != NULL && *p != '\0') { - fprintf(stderr, "cannot find $HOME - using current directory\n"); - pathname = calloc(strlen(filename) + 1, sizeof(char)); - strcpy(pathname, filename); + pathname = mkpathname(p, filename); } else { - pathname = calloc(strlen(filename) + strlen(p) + 2, sizeof(char)); - strcpy(pathname, p); -#if MSOFTC - strcat(pathname, "\\"); -#else - strcat(pathname, "/"); -#endif - strcat(pathname, filename); + fprintf(stderr, "cannot find $HOME - using current directory\n"); + pathname = mkpathname(".", filename); } return (pathname); diff -r -U2 less-252/lesskey.man less-278/lesskey.man --- less-252/lesskey.man Wed Nov 16 14:24:22 1994 +++ less-278/lesskey.man Tue Jan 31 18:55:54 1995 @@ -253,5 +253,5 @@ COPYRIGHT - Copyright (c) 1984,1985,1989,1994 Mark Nudelman + Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman diff -r -U2 less-252/lesskey.nro less-278/lesskey.nro --- less-252/lesskey.nro Wed Nov 16 14:24:14 1994 +++ less-278/lesskey.nro Tue Jan 31 18:55:56 1995 @@ -214,3 +214,3 @@ .SH COPYRIGHT -Copyright (c) 1984,1985,1989,1994 Mark Nudelman +Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman diff -r -U2 less-252/line.c less-278/line.c --- less-252/line.c Tue Oct 18 02:19:53 1994 +++ less-278/line.c Tue Jan 31 18:55:57 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -45,4 +45,5 @@ static int is_null_line; /* There is no current line */ static char pendc; +static POSITION pendpos; static int do_append(); @@ -90,5 +91,5 @@ * only if the -N option is set. */ - if (linenums != 2) + if (linenums != OPT_ONPLUS) return; @@ -212,10 +213,19 @@ */ static int -storec(c, a) +storec(c, a, pos) int c; int a; + POSITION pos; { register int w; +#if HILITE_SEARCH + if (is_hilited(pos, pos+1, 0)) + /* + * This character should be highlighted. + * Override the attribute passed in. + */ + a = AT_STANDOUT; +#endif w = pwidth(c, a); if (ctldisp > 0 && column + w + attr_ewidth(a) > sc_width) @@ -276,10 +286,11 @@ */ public int -pappend(c) +pappend(c, pos) register int c; + POSITION pos; { if (pendc) { - if (do_append(pendc)) + if (do_append(pendc, pendpos)) /* * Oops. We've probably lost the char which @@ -298,18 +309,21 @@ */ pendc = c; + pendpos = pos; return (0); } - return (do_append(c)); + return (do_append(c, pos)); } static int -do_append(c) +do_append(c, pos) int c; + POSITION pos; { register char *s; register int a; -#define STOREC(c,a) if (storec((c),(a))) return (1); else curr++ +#define STOREC(c,a) \ + if (storec((c),(a),pos)) return (1); else curr++ if (overstrike) @@ -409,24 +423,6 @@ * (that is, discard the CR in a CR/LF sequence). */ - (void) do_append(pendc); + (void) do_append(pendc, pendpos); -#if HILITE_SEARCH - /* - * Modify the attribute for matched strings; do this before we - * add a newline so that '$' will match end of line properly. - * {{ If a matched string is broken at the end of the line, - * we won't mark it. This is difficlt to fix. }} - */ - { - extern int hilite_search; - if (hilite_search) - { - linebuf[curr] = '\0'; - hlsearch(linebuf + lno_indent, attr + lno_indent, - AT_STANDOUT); - } - } -#endif - /* * Add a newline if necessary, diff -r -U2 less-252/linenum.c less-278/linenum.c --- less-252/linenum.c Sat Oct 15 03:16:47 1994 +++ less-278/linenum.c Tue Jan 31 18:55:58 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/lsystem.c less-278/lsystem.c --- less-252/lsystem.c Sat Oct 15 03:16:47 1994 +++ less-278/lsystem.c Tue Jan 31 18:55:59 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -35,7 +35,4 @@ #include "position.h" -#if HAVE_FCNTL_H -#include -#endif #if MSOFTC #include @@ -57,5 +54,5 @@ { register int inp; -#if MSOFTC +#if MSOFTC || OS2 register int inp2; #endif @@ -101,14 +98,8 @@ * is coming from a pipe. */ -#if MSOFTC - inp = dup(0); - inp2 = open("CON", O_TEXT|O_RDONLY); - dup2(0,inp2); -#else inp = dup(0); close(0); - if (open("/dev/tty", 0) < 0) + if (OPEN_TTYIN() < 0) dup(inp); -#endif /* @@ -142,4 +133,8 @@ free(p); #else +#if OS2 + if (*cmd == '\0') + cmd = "cmd.exe"; +#endif system(cmd); #endif @@ -148,13 +143,7 @@ * Restore standard input, reset signals, raw mode, etc. */ -#if MSOFTC - close(inp2); - dup2(0,inp); - close(inp); -#else close(0); dup(inp); close(inp); -#endif init_signals(1); @@ -167,5 +156,5 @@ */ if (edit_ifile(save_ifile)) - quit(-1); + quit(QUIT_ERROR); #if defined(SIGWINCH) || defined(SIGWIND) diff -r -U2 less-252/main.c less-278/main.c --- less-252/main.c Sat Oct 15 03:16:47 1994 +++ less-278/main.c Tue Jan 31 18:56:00 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -33,5 +33,4 @@ #include "position.h" -public int ispipe; public char * every_first_cmd = NULL; public int new_file; @@ -40,11 +39,9 @@ public IFILE old_ifile = NULL_IFILE; public struct scrpos initial_scrpos; -public int any_display = 0; +public int any_display = FALSE; public int wscroll; public char * progname; public int quitting; -extern int file; -extern int fd0; extern int quit_at_eof; extern int cbufs; @@ -55,5 +52,5 @@ #if LOGFILE public int logfile = -1; -public int force_logfile = 0; +public int force_logfile = FALSE; public char * namelogfile = NULL; #endif @@ -82,4 +79,9 @@ IFILE ifile; +#ifdef __EMX__ + _response(&argc, &argv); + _wildcard(&argc, &argv); +#endif + progname = *argv++; @@ -88,4 +90,5 @@ * Command line arguments override environment arguments. */ + init_cmds(); init_prompt(); init_charset(); @@ -105,11 +108,15 @@ */ nopendopt(); - quit(0); + quit(QUIT_OK); } #if EDITOR - editor = getenv("EDITOR"); + editor = getenv("VISUAL"); if (editor == NULL || *editor == '\0') - editor = EDIT_PGM; + { + editor = getenv("EDITOR"); + if (editor == NULL || *editor == '\0') + editor = EDIT_PGM; + } editproto = getenv("LESSEDIT"); if (editproto == NULL || *editproto == '\0') @@ -124,5 +131,5 @@ while (--argc >= 0) { -#if MSOFTC +#if MSOFTC || OS2 /* * Because the "shell" doesn't expand filename patterns, @@ -131,16 +138,16 @@ * Expand the pattern and iterate over the expanded list. */ - { - struct textlist tlist; - char *gfilename; - char *filename; - - gfilename = glob(*argv++); - init_textlist(&tlist, gfilename); - filename = NULL; - while ((filename = forw_textlist(&tlist, filename)) != NULL) - ifile = get_ifile(filename, ifile); - free(gfilename); - } + struct textlist tlist; + char *gfilename; + char *filename; + + gfilename = glob(*argv++); + if (gfilename == NULL) + continue; + init_textlist(&tlist, gfilename); + filename = NULL; + while ((filename = forw_textlist(&tlist, filename)) != NULL) + ifile = get_ifile(filename, ifile); + free(gfilename); #else ifile = get_ifile(*argv++, ifile); @@ -167,18 +174,11 @@ } while (edit_next(1) == 0); } - quit(0); + quit(QUIT_OK); } init_mark(); - init_cmds(); raw_mode(1); get_term(); get_editkeys(); -#if USERFILE - /* - * Try to use the lesskey file "$HOME/.less". - */ - add_hometable(); -#endif open_getchr(); init_signals(1); @@ -199,11 +199,11 @@ { error("No filenames allowed with -t option", NULL_PARG); - quit(1); + quit(QUIT_ERROR); } findtag(tagoption); if (tagfile == NULL) - quit(1); + quit(QUIT_ERROR); if (edit(tagfile)) /* Edit file which contains the tag */ - quit(1); + quit(QUIT_ERROR); /* * Search for the line which contains the tag. @@ -212,5 +212,5 @@ initial_scrpos.pos = tagsearch(); if (initial_scrpos.pos == NULL_POSITION) - quit(1); + quit(QUIT_ERROR); initial_scrpos.ln = jump_sline; } else @@ -219,14 +219,14 @@ { if (edit_stdin()) /* Edit standard input */ - quit(1); + quit(QUIT_ERROR); } else { if (edit_first()) /* Edit first valid file in cmd line */ - quit(1); + quit(QUIT_ERROR); } init(); commands(); - quit(0); + quit(QUIT_OK); /*NOTREACHED*/ } @@ -276,5 +276,5 @@ return (p); error("Cannot allocate memory", NULL_PARG); - quit(1); + quit(QUIT_ERROR); /*NOTREACHED*/ } diff -r -U2 less-252/mark.c less-278/mark.c --- less-252/mark.c Sat Oct 15 03:16:47 1994 +++ less-278/mark.c Tue Jan 31 18:56:01 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/optfunc.c less-278/optfunc.c --- less-252/optfunc.c Sun Nov 6 18:56:36 1994 +++ less-278/optfunc.c Tue Jan 31 18:56:03 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -46,5 +46,4 @@ extern int nbufs; -extern int ispipe; extern int cbufs; extern int pr_type; @@ -95,5 +94,5 @@ break; case TOGGLE: - if (!ispipe) + if (ch_getflags() & CH_CANSEEK) { error("Input is not a pipe", NULL_PARG); @@ -132,10 +131,11 @@ char *s; { - force_logfile = 1; + force_logfile = TRUE; opt_o(type, s); } +#endif /* - * Handlers for obsolete -l and -L options. + * Handlers for -l option. */ public void @@ -145,4 +145,5 @@ { int err; + int n; char *t; @@ -151,29 +152,16 @@ case INIT: t = s; - (void) getnum(&t, 'l', &err); - if (err || *t != '\0') + n = getnum(&t, 'l', &err); + if (err || n <= 0) { - error("The -l option is obsolete. Use -o", NULL_PARG); + error("Line number is required after -l", NULL_PARG); return; } - plusoption = 1; + plusoption = TRUE; ungetsc(s); break; - case QUERY: - error("Line number is required after -l", NULL_PARG); - break; } } - /*ARGSUSED*/ - public void -opt__L(type, s) - int type; - char *s; -{ - error("The -L option is obsolete. Use -O", NULL_PARG); -} -#endif - #if USERFILE public void @@ -193,8 +181,4 @@ } break; - case QUERY: - case TOGGLE: - error("Cannot query the -k flag", NULL_PARG); - break; } } @@ -229,12 +213,9 @@ { if (edit_ifile(save_ifile)) - quit(-1); + quit(QUIT_ERROR); break; } jump_loc(pos, jump_sline); break; - case QUERY: - error("Tag is required after -t", NULL_PARG); - break; } } @@ -285,11 +266,8 @@ * changed or invalidated by a .lesskey file. }} */ - plusoption = 1; + plusoption = TRUE; ungetsc(s); ungetsc("/"); break; - case QUERY: - error("Pattern is required after -p", NULL_PARG); - break; } } @@ -389,5 +367,5 @@ dispversion(); if (type == INIT) - quit(0); + quit(QUIT_OK); break; } @@ -504,7 +482,7 @@ open_getchr(); init(); - any_display = 1; + any_display = TRUE; help(1); - quit(0); + quit(QUIT_OK); /*NOTREACHED*/ } diff -r -U2 less-252/option.c less-278/option.c --- less-252/option.c Sat Oct 15 03:16:48 1994 +++ less-278/option.c Tue Jan 31 18:56:05 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -39,5 +39,5 @@ static struct option *pendopt; -public int plusoption; +public int plusoption = FALSE; static char *propt(); @@ -78,5 +78,5 @@ } - set_default = 0; + set_default = FALSE; while (*s != '\0') @@ -108,5 +108,5 @@ * EVERY input file. */ - plusoption = 1; + plusoption = TRUE; if (*s == '+') every_first_cmd = save(++s); @@ -135,7 +135,12 @@ { parg.p_string = propt(c); +#if MSOFTC || OS2 + error("There is no %s flag (\"less -?\" for help)", + &parg); +#else error("There is no %s flag (\"less -\\?\" for help)", &parg); - quit(1); +#endif + quit(QUIT_ERROR); } @@ -224,4 +229,11 @@ } + if (how_toggle == OPT_NO_TOGGLE && (o->otype & NO_QUERY)) + { + parg.p_string = propt(c); + error("Cannot query the %s flag", &parg); + return; + } + /* * Check for something which appears to be a do_toggle @@ -239,4 +251,9 @@ } +#if HILITE_SEARCH + if (how_toggle != OPT_NO_TOGGLE && (o->otype & HL_REPAINT)) + repaint_hilite(0); +#endif + /* * Now actually toggle (change) the variable. @@ -330,4 +347,9 @@ (*o->ofunc)((how_toggle==OPT_NO_TOGGLE) ? QUERY : TOGGLE, s); +#if HILITE_SEARCH + if (how_toggle != OPT_NO_TOGGLE && (o->otype & HL_REPAINT)) + chg_hilite(); +#endif + /* * Print a message describing the new setting. @@ -358,5 +380,5 @@ if (how_toggle != OPT_NO_TOGGLE && (o->otype & REPAINT)) - screen_trashed = 1; + screen_trashed = TRUE; } @@ -370,7 +392,7 @@ { if (lc) - return ((val == 1) ? 0 : 1); + return ((val == OPT_ON) ? OPT_OFF : OPT_ON); else - return ((val == 2) ? 0 : 2); + return ((val == OPT_ONPLUS) ? OPT_OFF : OPT_ONPLUS); } @@ -401,6 +423,6 @@ o = findopt(c); if (o == NULL) - return (1); - return (o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)); + return (TRUE); + return ((o->otype & (BOOL|TRIPLE|NOVAR|NO_TOGGLE)) != 0); } @@ -470,5 +492,5 @@ { nostring(c); - quit(1); + quit(QUIT_ERROR); } for (p = s; *p != '\0'; p++) @@ -498,8 +520,8 @@ s = skipsp(*sp); - neg = 0; + neg = FALSE; if (*s == '-') { - neg = 1; + neg = TRUE; s++; } @@ -508,10 +530,10 @@ if (errp != NULL) { - *errp = 1; + *errp = TRUE; return (-1); } parg.p_string = propt(c); error("Number is required after %s", &parg); - quit(1); + quit(QUIT_ERROR); } @@ -521,5 +543,5 @@ *sp = s; if (errp != NULL) - *errp = 0; + *errp = FALSE; if (neg) n = -n; diff -r -U2 less-252/option.h less-278/option.h --- less-252/option.h Sat Oct 15 03:16:48 1994 +++ less-278/option.h Tue Jan 31 18:56:05 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -38,4 +38,6 @@ #define REPAINT 040 /* Repaint screen after toggling option */ #define NO_TOGGLE 0100 /* Option cannot be toggled with "-" cmd */ +#define HL_REPAINT 0200 /* Repaint hilites after toggling option */ +#define NO_QUERY 0400 /* Option cannot be queried with "_" cmd */ #define OTYPE (BOOL|TRIPLE|NUMBER|STRING|NOVAR) @@ -57,5 +59,5 @@ { char oletter; /* The controlling letter (a-z) */ - char otype; /* Type of the option */ + int otype; /* Type of the option */ int odefault; /* Default value */ int *ovar; /* Pointer to the associated variable */ diff -r -U2 less-252/opttbl.c less-278/opttbl.c --- less-252/opttbl.c Thu Oct 27 17:19:38 1994 +++ less-278/opttbl.c Tue Feb 14 13:15:02 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -69,5 +69,5 @@ static struct option option[] = { - { 'a', BOOL, 0, &how_search, NULL, + { 'a', BOOL, OPT_OFF, &how_search, NULL, "Search includes displayed screen", "Search skips displayed screen", @@ -79,15 +79,15 @@ NULL }, - { 'B', BOOL, 1, &autobuf, NULL, + { 'B', BOOL, OPT_ON, &autobuf, NULL, "Don't automatically allocate buffers", "Automatically allocate buffers when needed", NULL }, - { 'c', TRIPLE, 0, &top_scroll, NULL, + { 'c', TRIPLE, OPT_OFF, &top_scroll, NULL, "Repaint by scrolling from bottom of screen", "Repaint by clearing each line", "Repaint by painting from top of screen" }, - { 'd', BOOL|NO_TOGGLE, 0, &know_dumb, NULL, + { 'd', BOOL|NO_TOGGLE, OPT_OFF, &know_dumb, NULL, "Assume intelligent terminal", "Assume dumb terminal", @@ -99,10 +99,10 @@ }, #endif - { 'e', TRIPLE, 0, &quit_at_eof, NULL, + { 'e', TRIPLE, OPT_OFF, &quit_at_eof, NULL, "Don't quit at end-of-file", "Quit at end-of-file", "Quit immediately at end-of-file" }, - { 'f', BOOL, 0, &force_open, NULL, + { 'f', BOOL, OPT_OFF, &force_open, NULL, "Open only regular files", "Open even non-regular files", @@ -110,8 +110,8 @@ }, #if HILITE_SEARCH - { 'F', BOOL|REPAINT, 1, &hilite_search, NULL, - "Don't highlight matches for previous search pattern", + { 'g', TRIPLE|HL_REPAINT, OPT_ONPLUS, &hilite_search, NULL, + "Don't highlight search matches", + "Highlight matches for previous search only", "Highlight all matches for previous search pattern", - NULL }, #endif @@ -121,13 +121,13 @@ NULL }, - { 'H', BOOL|NO_TOGGLE, 0, &nohelp, NULL, + { 'H', BOOL|NO_TOGGLE, OPT_OFF, &nohelp, NULL, "Allow help command", "Don't allow help command", NULL }, - { 'i', BOOL|REPAINT, 0, &caseless, opt_i, + { 'i', TRIPLE|HL_REPAINT, OPT_OFF, &caseless, opt_i, "Case is significant in searches", "Ignore case in searches", - NULL + "Ignore case in searches and in patterns" }, { 'j', NUMBER, 1, &jump_sline, NULL, @@ -137,22 +137,17 @@ }, #if USERFILE - { 'k', STRING|NO_TOGGLE, 0, NULL, opt_k, + { 'k', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_k, NULL, NULL, NULL }, #endif -#if LOGFILE - { 'l', STRING|NO_TOGGLE, 0, NULL, opt_l, + { 'l', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_l, NULL, NULL, NULL }, - { 'L', STRING, 0, NULL, opt__L, - NULL, NULL, NULL - }, -#endif - { 'm', TRIPLE, 0, &pr_type, NULL, + { 'm', TRIPLE, OPT_OFF, &pr_type, NULL, "Short prompt", "Medium prompt", "Long prompt" }, - { 'n', TRIPLE|REPAINT, 1, &linenums, NULL, + { 'n', TRIPLE|REPAINT, OPT_ON, &linenums, NULL, "Don't use line numbers", "Use line numbers", @@ -167,5 +162,5 @@ }, #endif - { 'p', STRING|NO_TOGGLE, 0, NULL, opt_p, + { 'p', STRING|NO_TOGGLE|NO_QUERY, 0, NULL, opt_p, NULL, NULL, NULL }, @@ -173,20 +168,20 @@ "prompt: ", NULL, NULL }, - { 'q', TRIPLE, 0, &quiet, NULL, + { 'q', TRIPLE, OPT_OFF, &quiet, NULL, "Ring the bell for errors AND at eof/bof", "Ring the bell for errors but not at eof/bof", "Never ring the bell" }, - { 'r', BOOL|REPAINT, 1, &ctldisp, NULL, + { 'r', BOOL|REPAINT, OPT_ON, &ctldisp, NULL, "Display control characters directly", "Display control characters as ^X", NULL }, - { 's', BOOL|REPAINT, 0, &squeeze, NULL, + { 's', BOOL|REPAINT, OPT_OFF, &squeeze, NULL, "Display all blank lines", "Squeeze multiple blank lines", NULL }, - { 'S', BOOL|REPAINT, 0, &chopline, NULL, + { 'S', BOOL|REPAINT, OPT_OFF, &chopline, NULL, "Fold long lines", "Chop long lines", @@ -194,5 +189,5 @@ }, #if TAGS - { 't', STRING, 0, NULL, opt_t, + { 't', STRING|NO_QUERY, 0, NULL, opt_t, "tag: ", NULL, NULL }, @@ -201,5 +196,5 @@ }, #endif - { 'u', TRIPLE|REPAINT, 0, &bs_mode, NULL, + { 'u', TRIPLE|REPAINT, OPT_OFF, &bs_mode, NULL, "Display underlined text in underline mode", "Backspaces cause overstrike", @@ -209,5 +204,5 @@ NULL, NULL, NULL }, - { 'w', BOOL|REPAINT, 1, &twiddle, NULL, + { 'w', BOOL|REPAINT, OPT_ON, &twiddle, NULL, "Display nothing for lines after end-of-file", "Display ~ for lines after end-of-file", @@ -219,5 +214,5 @@ NULL }, - { 'X', BOOL|NO_TOGGLE, 0, &no_init, NULL, + { 'X', BOOL|NO_TOGGLE, OPT_OFF, &no_init, NULL, "Send init/deinit strings to terminal", "Don't use init/deinit strings", diff -r -U2 less-252/os.c less-278/os.c --- less-252/os.c Sat Oct 15 03:16:48 1994 +++ less-278/os.c Tue Jan 31 18:56:07 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/output.c less-278/output.c --- less-252/output.c Sat Oct 15 03:16:48 1994 +++ less-278/output.c Tue Jan 31 18:56:08 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/position.c less-278/position.c --- less-252/position.c Sat Oct 15 03:16:48 1994 +++ less-278/position.c Tue Jan 31 18:56:09 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/position.h less-278/position.h --- less-252/position.h Sat Oct 15 03:16:48 1994 +++ less-278/position.h Tue Jan 31 18:56:10 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/prompt.c less-278/prompt.c --- less-252/prompt.c Sat Oct 15 03:16:48 1994 +++ less-278/prompt.c Tue Jan 31 18:56:11 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * diff -r -U2 less-252/screen.c less-278/screen.c --- less-252/screen.c Wed Nov 9 12:41:22 1994 +++ less-278/screen.c Tue Jan 31 18:56:14 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -74,4 +74,9 @@ #endif +#if OS2 +#define DEFAULT_TERM "ansi" +#else +#define DEFAULT_TERM "unknown" +#endif /* @@ -107,4 +112,5 @@ public int ignaw; /* Terminal ignores \n immediately after wrap */ public int erase_char, kill_char; /* The user's erase and line-kill chars */ +public int werase_char; /* The user's word-erase char */ public int sc_width, sc_height; /* Height & width of screen */ public int bo_s_width, bo_e_width; /* Printing width of boldface seq */ @@ -113,4 +119,5 @@ public int bl_s_width, bl_e_width; /* Printing width of blink seq */ public int above_mem, below_mem; /* Memory retained above/below screen */ +public int can_goto_line; /* Can move cursor to any line */ static char *cheaper(); @@ -130,4 +137,8 @@ extern int swindow; extern int no_init; +#if HILITE_SEARCH +extern int hilite_search; +#endif + extern char *tgetstr(); extern char *tgoto(); @@ -153,4 +164,9 @@ if (on == curr_on) return; +#if OS2 + signal(SIGINT, SIG_IGN); + erase_char = '\b'; + kill_char = '\033'; +#else #if HAVE_TERMIOS_H && HAVE_TERMIOS_FUNCS { @@ -231,4 +247,9 @@ erase_char = s.c_cc[VERASE]; kill_char = s.c_cc[VKILL]; +#ifdef VWERASE + werase_char = s.c_cc[VWERASE]; +#else + werase_char = 0; +#endif /* @@ -320,4 +341,9 @@ erase_char = s.c_cc[VERASE]; kill_char = s.c_cc[VKILL]; +#ifdef VWERASE + werase_char = s.c_cc[VWERASE]; +#else + werase_char = 0; +#endif /* @@ -359,4 +385,5 @@ erase_char = s.sg_erase; kill_char = s.sg_kill; + werase_char = 0; /* @@ -376,4 +403,5 @@ #endif #endif +#endif curr_on = on; } @@ -398,4 +426,17 @@ * Get size of the output screen. */ +#if OS2 + public void +scrsize() +{ + int s[2]; + + _scrsize(s); + sc_width = s[0]; + sc_height = s[1]; +} + +#else + public void scrsize() @@ -447,4 +488,5 @@ sc_width = 80; } +#endif /* OS2 */ /* @@ -562,4 +604,11 @@ put_ecmd(tbuf, EC_W_BACKSPACE); + if (werase_char != 0) + { + tbuf[0] = werase_char; + tbuf[1] = '\0'; + put_ecmd(tbuf, EC_W_BACKSPACE); + } + /* * Register the two tables. @@ -569,4 +618,38 @@ } +#if DEBUG + static void +get_debug_term() +{ + auto_wrap = 1; + ignaw = 1; + so_s_width = so_e_width = 0; + bo_s_width = bo_e_width = 0; + ul_s_width = ul_e_width = 0; + bl_s_width = bl_e_width = 0; + sc_s_keypad = "(InitKey)"; + sc_e_keypad = "(DeinitKey)"; + sc_init = "(InitTerm)"; + sc_deinit = "(DeinitTerm)"; + sc_eol_clear = "(ClearEOL)"; + sc_eos_clear = "(ClearEOS)"; + sc_clear = "(ClearScreen)"; + sc_move = "(Move<%d,%d>)"; + sc_s_in = "(SO+)"; + sc_s_out = "(SO-)"; + sc_u_in = "(UL+)"; + sc_u_out = "(UL-)"; + sc_b_in = "(BO+)"; + sc_b_out = "(BO-)"; + sc_bl_in = "(BL+)"; + sc_bl_out = "(BL-)"; + sc_visual_bell ="(VBell)"; + sc_backspace = "(BS)"; + sc_home = "(Home)"; + sc_lower_left = "(LL)"; + sc_addline = "(AddLine)"; +} +#endif + /* * Get terminal capabilities via termcap. @@ -583,9 +666,26 @@ static char sbuf[1024]; +#ifdef OS2 + /* + * Make sure the termcap database is available. + */ + sp = getenv("TERMCAP"); + if (sp == NULL || *sp == '\0') + { + char *termcap; + if ((sp = homefile("termcap.dat")) != NULL) + { + termcap = (char *) ecalloc(strlen(sp)+9, sizeof(char)); + sprintf(termcap, "TERMCAP=%s", sp); + free(sp); + putenv(termcap); + } + } +#endif /* * Find out what kind of terminal this is. */ if ((term = getenv("TERM")) == NULL) - term = "unknown"; + term = DEFAULT_TERM; if (tgetent(termbuf, term) <= 0) strcpy(termbuf, "dumb:hc:"); @@ -599,4 +699,12 @@ pos_init(); +#if DEBUG + if (strncmp(term,"LESSDEBUG",9) == 0) + { + get_debug_term(); + return; + } +#endif /* DEBUG */ + auto_wrap = tgetflag("am"); ignaw = tgetflag("xn"); @@ -618,4 +726,16 @@ bl_s_width = bl_e_width = so_s_width; +#if HILITE_SEARCH + if (so_s_width > 0 || so_e_width > 0) + /* + * Disable highlighting by default on magic cookie terminals. + * Turning on highlighting might change the displayed width + * of a line, causing the display to get messed up. + * The user can turn it back on with -g, + * but she won't like the results. + */ + hilite_search = 0; +#endif + /* * Get various string-valued capabilities. @@ -675,5 +795,7 @@ */ sc_move = ""; - } + can_goto_line = 0; + } else + can_goto_line = 1; sc_s_in = tgetstr("so", &sp); @@ -775,4 +897,9 @@ if (hard || t2 == NULL) t2 = ""; +#if OS2 + if (*t1 == '\0' && *t2 == '\0') + sc_addline = ""; + else +#endif if (above_mem) sc_addline = t1; @@ -901,4 +1028,17 @@ { tputs(sc_lower_left, 1, putchr); +} + +/* + * Goto a specific line on the screen. + */ + public void +goto_line(slinenum) + int slinenum; +{ + char *sc_goto; + + sc_goto = tgoto(sc_move, 0, slinenum); + tputs(sc_goto, 1, putchr); } diff -r -U2 less-252/search.c less-278/search.c --- less-252/search.c Sat Oct 15 03:16:49 1994 +++ less-278/search.c Tue Jan 31 18:56:16 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -33,4 +33,7 @@ #include "position.h" +#define MINPOS(a,b) (((a) < (b)) ? (a) : (b)) +#define MAXPOS(a,b) (((a) > (b)) ? (a) : (b)) + #if HAVE_POSIX_REGCOMP #include @@ -56,4 +59,5 @@ extern int caseless; extern int linenums; +extern int sc_height; extern int jump_sline; extern int bs_mode; @@ -61,4 +65,16 @@ extern int hilite_search; extern int screen_trashed; +extern int size_linebuf; +static int hide_hilite; +static POSITION prep_startpos; +static POSITION prep_endpos; + +struct hilite +{ + struct hilite *hl_next; + POSITION hl_startpos; + POSITION hl_endpos; +}; +static struct hilite hilite_anchor = { NULL }; #endif @@ -85,7 +101,4 @@ static int is_caseless; static int is_ucase_pattern; -#if HILITE_SEARCH -static int no_hilite_search; -#endif /* @@ -157,6 +170,58 @@ } +#if HILITE_SEARCH +/* + * Repaint the hilites currently displayed on the screen. + * Repaint each line which contains highlighted text. + * If on==0, force all hilites off. + */ + public void +repaint_hilite(on) + int on; +{ + int slinenum; + POSITION pos; + POSITION epos; + int save_hide_hilite; + extern int can_goto_line; + + save_hide_hilite = hide_hilite; + if (!on) + { + if (hide_hilite) + return; + hide_hilite = 1; + } + + if (!can_goto_line) + { + repaint(); + hide_hilite = save_hide_hilite; + return; + } + + for (slinenum = TOP; slinenum < TOP + sc_height-1; slinenum++) + { + pos = position(slinenum); + if (pos == NULL_POSITION) + continue; + epos = position(slinenum+1); + /* + * If any character in the line is highlighted, + * repaint the line. + */ + if (is_hilited(pos, epos, 1)) + { + (void) forw_line(pos); + goto_line(slinenum); + put_line(); + } + } + hide_hilite = save_hide_hilite; +} +#endif + /* - * Undo search string highlighting. + * Hide search string highlighting. */ public void @@ -169,11 +234,11 @@ } #if HILITE_SEARCH - no_hilite_search = !no_hilite_search; - screen_trashed = 1; + hide_hilite = !hide_hilite; + repaint_hilite(1); #endif } /* - * Compile a pattern in preparation for a pattern match. + * Compile a search pattern, for future use by match_pattern. */ static int @@ -235,28 +300,310 @@ /* + * Forget that we have a compiled pattern. + */ + static void +uncompile_pattern() +{ +#if HAVE_POSIX_REGCOMP + if (regpattern != NULL) + regfree(regpattern); + regpattern = NULL; +#endif +#if HAVE_RE_COMP + re_pattern = 0; +#endif +#if HAVE_REGCMP + if (cpattern != NULL) + free(cpattern); + cpattern = NULL; +#endif +#if HAVE_V8_REGCOMP + if (regpattern != NULL) + free(regpattern); + regpattern = NULL; +#endif +#if NO_REGEX + last_pattern = NULL; +#endif +} + +/* * Perform a pattern match with the previously compiled pattern. + * Set sp and ep to the start and end of the matched string. */ static int -match_pattern(line) +match_pattern(line, sp, ep) char *line; + char **sp; + char **ep; { + int matched; #if HAVE_POSIX_REGCOMP - return (!regexec(regpattern, line, 0, NULL, 0)); + regmatch_t rm; + matched = !regexec(regpattern, line, 1, &rm, 0); + if (!matched) + return (0); + *sp = line + rm.rm_so; + *ep = line + rm.rm_eo; #endif #if HAVE_RE_COMP - return (re_exec(line) == 1); + matched = (re_exec(line) == 1); + /* + * re_exec doesn't seem to provide a way to get the matched string. + */ + *sp = *ep = NULL; #endif #if HAVE_REGCMP - return (regex(cpattern, line) != NULL); + *ep = regex(cpattern, line); + matched = (*ep != NULL); + if (!matched) + return (0); + *sp = __loc1; #endif #if HAVE_V8_REGCOMP - return (regexec(regpattern, line)); + matched = regexec(regpattern, line); + if (!matched) + return (0); + *sp = regpattern->startp[0]; + *ep = regpattern->endp[0]; #endif #if NO_REGEX - return (match(last_pattern, line, (char*)NULL, (char*)NULL)); + matched = match(last_pattern, line, sp, ep); #endif + return (matched); +} + +#if HILITE_SEARCH +/* + * Clear the hilite list. + */ + public void +clr_hilite() +{ + struct hilite *hl; + struct hilite *nexthl; + + for (hl = hilite_anchor.hl_next; hl != NULL; hl = nexthl) + { + nexthl = hl->hl_next; + free((void*)hl); + } + hilite_anchor.hl_next = NULL; + prep_startpos = prep_endpos = NULL_POSITION; +} + +/* + * Add a new hilite to the hilite list. + */ + public void +add_hilite(startpos, endpos) + POSITION startpos; + POSITION endpos; +{ + struct hilite *hl; + struct hilite *ihl; + + /* + * Hilites are sorted in the list; find where new one belongs. + * Insert new one after ihl. + */ + for (ihl = &hilite_anchor; ihl->hl_next != NULL; ihl = ihl->hl_next) + { + if (ihl->hl_next->hl_startpos > startpos) + break; + } + + if (ihl != &hilite_anchor && startpos <= ihl->hl_endpos) + { + /* + * New hilite starts within existing ihl. + * Just extend ihl to end at the new hilite's end. + */ + ihl->hl_endpos = MAXPOS(endpos, ihl->hl_endpos); + } else + { + /* + * Add new hilite after ihl. + */ + hl = (struct hilite *) ecalloc(1, sizeof(struct hilite)); + hl->hl_startpos = startpos; + /* + * If new hilite ends within the one after ihl, + * truncate it to end at the start of that one. + */ + if (ihl->hl_next == NULL) + hl->hl_endpos = endpos; + else + hl->hl_endpos = MINPOS(endpos, ihl->hl_next->hl_startpos); + hl->hl_next = ihl->hl_next; + ihl->hl_next = hl; + } +} + +/* + * Should any characters in a specified range be highlighted? + * If nohide is nonzero, don't consider hide_hilite. + */ + public int +is_hilited(pos, epos, nohide) + POSITION pos; + POSITION epos; + int nohide; +{ + struct hilite *hl; + + if (hilite_search == 0) + /* + * Not doing highlighting. + */ + return (0); + + if (!nohide && hide_hilite) + /* + * Highlighting is hidden. + */ + return (0); + + /* + * Look at each highlight and see if any part of it falls in the range. + */ + for (hl = hilite_anchor.hl_next; hl != NULL; hl = hl->hl_next) + { + if (hl->hl_endpos > pos && + (epos == NULL_POSITION || epos > hl->hl_startpos)) + return (1); + } + return (0); +} + +/* + * Adjust hl_startpos & hl_endpos to account for backspace processing. + */ + static void +adj_hilite(linepos) + POSITION linepos; +{ + char *line; + struct hilite *hl; + int checkstart; + POSITION opos; + POSITION npos; + + /* + * The line was already scanned and hilites were added (in hilite_line). + * But it was assumed that each char position in the line + * correponds to one char position in the file. + * This may not be true if there are backspaces in the line. + * Get the raw line again. Look at each character. + */ + (void) forw_raw_line(linepos, &line); + opos = npos = linepos; + /* + * Find the first hilite in (or after) this line. + */ + for (hl = hilite_anchor.hl_next; hl != NULL; hl = hl->hl_next) + if (hl->hl_startpos >= linepos) + break; + checkstart = 1; + while (hl != NULL) + { + /* + * See if we need to adjust the current hl_startpos or + * hl_endpos. After adjusting startpos[i], move to endpos[i]. + * After adjusting endpos[i], move to startpos[i+1]. + * The hilite list must be sorted thus: + * startpos[0] < endpos[0] <= startpos[1] < endpos[1] <= etc. + */ + if (checkstart && hl->hl_startpos == opos) + { + hl->hl_startpos = npos; + checkstart = 0; + continue; /* {{ not really necessary }} */ + } else if (!checkstart && hl->hl_endpos == opos) + { + hl->hl_endpos = npos; + checkstart = 1; + hl = hl->hl_next; + continue; /* {{ necessary }} */ + } + if (*line == '\0') + break; + opos++; + npos++; + line++; + if (line[0] == '\b' && line[1] != '\0') + { + /* + * Found a backspace. The file position moves + * forward by 2 relative to the processed line + * which was searched in hilite_line. + */ + npos += 2; + line += 2; + } + } } /* + * Make a hilite for each string in a physical line which matches + * the current pattern. + * sp,ep delimit the first match already found. + */ + static void +hilite_line(linepos, line, sp, ep) + POSITION linepos; + char *line; + char *sp; + char *ep; +{ + char *searchp; + + if (sp == NULL || ep == NULL) + return; + /* + * sp and ep delimit the first match in the line. + * Mark the corresponding file positions, then + * look for further matches and mark them. + * {{ This technique, of calling match_pattern on subsequent + * substrings of the line, may mark more than is correct + * if, for example, the pattern starts with "^". }} + */ + searchp = line; + do { + if (ep > sp) + { + /* + * Assume that each char position in the "line" + * buffer corresponds to one char position in the file. + * This is not quite true; we need to adjust later. + */ + add_hilite(linepos + (sp-line), linepos + (ep-line)); + } + /* + * If we matched more than zero characters, + * move to the first char after the string we matched. + * If we matched zero, just move to the next char. + */ + if (ep > searchp) + searchp = ep; + else if (*searchp != '\0') + searchp++; + else /* end of line */ + break; + } while (match_pattern(searchp, &sp, &ep)); + + if (bs_mode == BS_SPECIAL) + { + /* + * If there were backspaces in the original line, they + * were removed, and hl_startpos/hl_endpos are not correct. + * {{ This is very ugly. }} + */ + adj_hilite(linepos); + } +} +#endif + +/* * Change the caseless-ness of searches. * Updates the internal search state to reflect a change in the -i flag. @@ -266,13 +613,59 @@ { if (!is_ucase_pattern) + /* + * Pattern did not have uppercase. + * Just set the search caselessness to the global caselessness. + */ is_caseless = caseless; + else + /* + * Pattern did have uppercase. + * Discard the pattern; we can't change search caselessness now. + */ + uncompile_pattern(); } +#if HILITE_SEARCH +/* + * Find matching text which is currently on screen and highlight it. + */ + static void +hilite_screen() +{ + struct scrpos scrpos; + + get_scrpos(&scrpos); + if (scrpos.pos == NULL_POSITION) + return; + prep_hilite(scrpos.pos, position(BOTTOM_PLUS_ONE)); + repaint_hilite(1); +} + +/* + * Change highlighting parameters. + */ + public void +chg_hilite() +{ + /* + * Erase any highlights currently on screen. + */ + clr_hilite(); + hide_hilite = 0; + + if (hilite_search == OPT_ONPLUS) + /* + * Display highlights. + */ + hilite_screen(); +} +#endif + /* * Figure out where to start a search. */ static POSITION -search_pos(goforw) - int goforw; +search_pos(search_type) + int search_type; { POSITION pos; @@ -283,9 +676,10 @@ /* * Start at the beginning (or end) of the file. - * (The empty_screen() case is mainly for + * The empty_screen() case is mainly for * command line initiated searches; - * for example, "+/xyz" on the command line.) + * for example, "+/xyz" on the command line. + * Also for multi-file (SRCH_PAST_EOF) searches. */ - if (goforw) + if (search_type & SRCH_FORW) { return (ch_zero()); @@ -294,5 +688,8 @@ pos = ch_length(); if (pos == NULL_POSITION) - return (ch_zero()); + { + (void) ch_end_seek(); + pos = ch_length(); + } return (pos); } @@ -303,5 +700,5 @@ * Search does not include current screen. */ - if (goforw) + if (search_type & SRCH_FORW) linenum = BOTTOM_PLUS_ONE; else @@ -317,5 +714,5 @@ linenum = adjsline(jump_sline); pos = position(linenum); - if (goforw) + if (search_type & SRCH_FORW) pos = forw_raw_line(pos, (char **)NULL); } @@ -324,88 +721,20 @@ /* - * Search for the n-th occurrence of a specified pattern, - * either forward or backward. - * Return the number of matches not yet found in this file - * (that is, n minus the number of matches found). - * Return -1 if the search should be aborted. - * Caller may continue the search in another file - * if less than n matches are found in this file. + * Search a subset of the file, specified by start/end position. */ - public int -search(search_type, pattern, n) + static int +search_range(pos, endpos, search_type, n, plinepos, pendpos) + POSITION pos; + POSITION endpos; int search_type; - char *pattern; int n; + POSITION *plinepos; + POSITION *pendpos; { - POSITION pos, linepos, oldpos; - register int goforw; - register int want_match; char *line; int linenum; + char *sp, *ep; int line_match; - - /* - * Extract flags and type of search. - */ - goforw = (SRCH_DIR(search_type) == SRCH_FORW); - want_match = !(search_type & SRCH_NOMATCH); - - if (pattern == NULL || *pattern == '\0') - { - /* - * A null pattern means use the previously compiled pattern. - */ - if (!prev_pattern()) - { - error("No previous regular expression", NULL_PARG); - return (-1); - } - } else - { - /* - * Ignore case if -i is set AND - * the pattern is all lowercase. - */ - is_ucase_pattern = is_ucase(pattern); - if (is_ucase_pattern) - is_caseless = 0; - else - is_caseless = caseless; - - /* - * Compile the pattern. - */ - if (compile_pattern(pattern) < 0) - return (-1); -#if HILITE_SEARCH - /* - * If our current screen *might be* displaying highlighted - * search targets, we need to repaint. - */ - if (hilite_search) - screen_trashed = 1; -#endif - } - - /* - * Figure out where to start the search. - */ - pos = search_pos(goforw); - if (pos == NULL_POSITION) - { - /* - * Can't find anyplace to start searching from. - */ - if (search_type & SRCH_PAST_EOF) - return (n); - error("Nothing to search", NULL_PARG); - return (-1); - } - -#if HILITE_SEARCH - if (no_hilite_search) - screen_trashed = 1; - no_hilite_search = 0; -#endif + POSITION linepos, oldpos; linenum = find_linenum(pos); @@ -414,15 +743,27 @@ { /* - * Get lines until we find a matching one or - * until we hit end-of-file (or beginning-of-file - * if we're going backwards). + * Get lines until we find a matching one or until + * we hit end-of-file (or beginning-of-file if we're + * going backwards), or until we hit the end position. */ if (ABORT_SIGS()) + { /* * A signal aborts the search. */ return (-1); + } - if (goforw) + if (endpos != NULL_POSITION && pos >= endpos) + { + /* + * Reached end position without a match. + */ + if (pendpos != NULL) + *pendpos = pos; + return (n); + } + + if (search_type & SRCH_FORW) { /* @@ -449,6 +790,8 @@ { /* - * We hit EOF/BOF without a match. + * Reached EOF/BOF without a match. */ + if (pendpos != NULL) + *pendpos = NULL_POSITION; return (n); } @@ -468,4 +811,8 @@ } + /* + * If it's a caseless search, convert the line to lowercase. + * If we're doing backspace processing, delete backspaces. + */ if (is_caseless || bs_mode == BS_SPECIAL) { @@ -480,125 +827,292 @@ /* * Test the next line to see if we have a match. - * We are successful if want_match and line_match are - * both true (want a match and got it), - * or both false (want a non-match and got it). - */ - line_match = match_pattern(line); - if (((want_match && line_match) || (!want_match && !line_match)) && - --n <= 0) + * We are successful if we either want a match and got one, + * or if we want a non-match and got one. + */ + line_match = match_pattern(line, &sp, &ep); + line_match = (!(search_type & SRCH_NOMATCH) && line_match) || + ((search_type & SRCH_NOMATCH) && !line_match); + if (!line_match) + continue; + /* + * Got a match. + */ + if (search_type & SRCH_FIND_ALL) + { +#if HILITE_SEARCH /* - * Found the line. + * We are supposed to find all matches in the range. + * Just add the matches in this line to the + * hilite list and keep searching. */ - break; + if (line_match) + hilite_line(linepos, line, sp, ep); +#endif + } else if (--n <= 0) + { + /* + * Found the one match we're looking for. + * Return it. + */ +#if HILITE_SEARCH + if (hilite_search == 1) + { + /* + * Clear the hilite list and add only + * the matches in this one line. + */ + clr_hilite(); + if (line_match) + hilite_line(linepos, line, sp, ep); + } +#endif + if (plinepos != NULL) + *plinepos = linepos; + return (0); + } } - - jump_loc(linepos, jump_sline); - return (0); } -#if HILITE_SEARCH /* - * Search for all occurrences of the previous pattern - * within a line. Mark all matches found. - * "Marking" a match is done by copying "marker" into the chars whose - * positions in the "found" string are equal to the positions of - * the matching string in the "line" string. + * Search for the n-th occurrence of a specified pattern, + * either forward or backward. + * Return the number of matches not yet found in this file + * (that is, n minus the number of matches found). + * Return -1 if the search should be aborted. + * Caller may continue the search in another file + * if less than n matches are found in this file. */ - public void -hlsearch(line, found, marker) - char *line; - char *found; - int marker; + public int +search(search_type, pattern, n) + int search_type; + char *pattern; + int n; { - char *buf; - register char *p; + POSITION pos; + int ucase; - if (!prev_pattern()) - return; - if (no_hilite_search) - return; + if (pattern == NULL || *pattern == '\0') + { + /* + * A null pattern means use the previously compiled pattern. + */ + if (!prev_pattern()) + { + error("No previous regular expression", NULL_PARG); + return (-1); + } +#if HILITE_SEARCH + if (hilite_search == 1) + { + /* + * Erase the highlights currently on screen. + * If the search fails, we'll redisplay them later. + */ + repaint_hilite(0); + hide_hilite = 0; + } +#endif + } else + { + /* + * Compile the pattern. + */ + ucase = is_ucase(pattern); + if (caseless == OPT_ONPLUS) + cvt_text(pattern, pattern, CVT_TO_LC); + if (compile_pattern(pattern) < 0) + return (-1); + /* + * Ignore case if -I is set OR + * -i is set AND the pattern is all lowercase. + */ + is_ucase_pattern = ucase; + if (is_ucase_pattern && caseless != OPT_ONPLUS) + is_caseless = 0; + else + is_caseless = caseless; +#if HILITE_SEARCH + if (hilite_search) + { + /* + * Erase the highlights currently on screen. + * Also permanently delete them from the hilite list. + */ + repaint_hilite(0); + hide_hilite = 0; + clr_hilite(); + } + if (hilite_search == OPT_ONPLUS) + { + /* + * Highlight any matches currently on screen, + * before we actually start the search. + */ + hilite_screen(); + } +#endif + } /* - * If the last search was caseless, convert - * uppercase from the input line to lowercase - * in a temporary buffer. + * Figure out where to start the search. */ - buf = line; - if (is_caseless) + pos = search_pos(search_type); + if (pos == NULL_POSITION) { /* - * {{ Yikes, a calloc for every line displayed (with -i)! - * Is this worth optimizing? }} + * Can't find anyplace to start searching from. */ - buf = save(line); - cvt_text(buf, line, CVT_TO_LC); + if (search_type & SRCH_PAST_EOF) + return (n); + error("Nothing to search", NULL_PARG); + return (-1); } + n = search_range(pos, NULL_POSITION, search_type, n, + &pos, (POSITION*)NULL); + if (n != 0) { /* - * Now depending on what type of pattern matching function - * we have, define the macro NEXT_MATCH(p). - * This will look for the first match in "p"; - * if it finds one it sets sp and ep to the start and - * end of the matching string and returns 1. - * If there is no match, it returns 0. + * Search was unsuccessful. */ - -#if HAVE_POSIX_REGCOMP -regmatch_t rm; -#define NEXT_MATCH(p) (!regexec(regpattern,p,1,&rm,0)) -#define sp (p+rm.rm_so) -#define ep (p+rm.rm_eo) +#if HILITE_SEARCH + if (hilite_search == OPT_ON && n > 0) + /* + * Redisplay old hilites. + */ + repaint_hilite(1); #endif + return (n); + } -#if HAVE_RE_COMP -@@@ Sorry, re_comp does not support HILITE_SEARCH. -@@@ Either undefine HILITE_SEARCH, or use the regexp.c that is -@@@ distributed with "less" (and set HAVE_V8_REGCOMP). -#endif + /* + * Go to the matching line. + */ + jump_loc(pos, jump_sline); -#if HAVE_REGCMP -#define sp __loc1 -char *ep; -#define NEXT_MATCH(p) (ep = regex(cpattern, p)) +#if HILITE_SEARCH + if (hilite_search == OPT_ON) + /* + * Display new hilites in the matching line. + */ + repaint_hilite(1); #endif + return (0); +} -#if HAVE_V8_REGCOMP -#define sp (regpattern->startp[0]) -#define ep (regpattern->endp[0]) -#define NEXT_MATCH(p) (regexec(regpattern, p)) -#endif +#if HILITE_SEARCH +/* + * Prepare hilites in a given range of the file. + * + * The pair (prep_startpos,prep_endpos) delimits a contiguous region + * of the file that has been "prepared"; that is, scanned for matches for + * the current search pattern, and hilites have been created for such matches. + * If prep_startpos == NULL_POSITION, the prep region is empty. + * If prep_endpos == NULL_POSITION, the prep region extends to EOF. + * prep_hilite asks that the range (spos,epos) be covered by the prep region. + */ + public void +prep_hilite(spos, epos) + POSITION spos; + POSITION epos; +{ + POSITION nprep_startpos = prep_startpos; + POSITION nprep_endpos = prep_endpos; +/* + * Search beyond where we're asked to search, so the prep region covers + * more than we need. Do one big search instead of a bunch of small ones. + */ +#define SEARCH_MORE (3*size_linebuf) -#if NO_REGEX -char *sp, *ep; -#define NEXT_MATCH(p) (match(last_pattern,p,&sp,&ep)) -#endif + if (!prev_pattern()) + return; + /* + * Find two ranges: + * The range that we need to search (spos,epos); and the range that + * the "prep" region will then cover (nprep_startpos,nprep_endpos). + */ - for (p = buf; NEXT_MATCH(p); ) + if (prep_startpos == NULL_POSITION || + (epos != NULL_POSITION && epos < prep_startpos) || + (prep_endpos != NULL_POSITION && spos > prep_endpos)) + { + /* + * New range is not contiguous with old prep region. + * Discard the old prep region and start a new one. + */ + clr_hilite(); + if (epos != NULL_POSITION) + epos += SEARCH_MORE; + nprep_startpos = spos; + nprep_endpos = epos; + } else + { + /* + * New range partially or completely overlaps old prep region. + */ + if (epos == NULL_POSITION) + { + /* + * New range goes to end of file. + */ + nprep_endpos = NULL_POSITION; + } else if (epos > prep_endpos) { - register char *fsp = &found[sp-buf]; - register char *fep = &found[ep-buf]; + /* + * New range ends after old prep region. + * Extend prep region to end at end of new range. + */ + epos += SEARCH_MORE; + nprep_endpos = epos; + } else /* (epos <= prep_endpos) */ + { + /* + * New range ends within old prep region. + * Truncate search to end at start of old prep region. + */ + epos = prep_startpos; + } - while (fsp < fep) - *fsp++ = marker; - + if (spos < prep_startpos) + { /* - * Move past current match to see if there - * are any more matches. (But don't loop - * forever if we matched zero characters.) + * New range starts before old prep region. + * Extend old prep region backwards to start at + * start of new range. */ - if (ep > p) - p = ep; - else if (*p != '\0') - p++; + if (spos < SEARCH_MORE) + spos = 0; else - break; + spos -= SEARCH_MORE; + nprep_startpos = spos; + } else /* (spos >= prep_startpos) */ + { + /* + * New range starts within or after old prep region. + * Trim search to start near end of old prep region + * (actually, one linebuf before end of old range). + */ + if (prep_endpos == NULL_POSITION) + return; + else if (prep_endpos < size_linebuf) + spos = 0; + else + spos = prep_endpos - size_linebuf; } } - if (buf != line) - free(buf); + if (epos == NULL_POSITION || epos > spos) + { + if (search_range(spos, epos, SRCH_FORW|SRCH_FIND_ALL, 0, + (POSITION*)NULL, &epos) >= 0) + { + if (epos == NULL_POSITION || epos > nprep_endpos) + nprep_endpos = epos; + } + } + prep_startpos = nprep_startpos; + prep_endpos = nprep_endpos; } -#endif /* HILITE_SEARCH */ +#endif #if NO_REGEX @@ -642,5 +1156,8 @@ char *s; { - error(s, NULL_PARG); + PARG parg; + + parg.p_string = s; + error("%s", &parg); } #endif diff -r -U2 less-252/signal.c less-278/signal.c --- less-252/signal.c Sat Oct 15 03:16:49 1994 +++ less-278/signal.c Tue Jan 31 18:56:17 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -59,14 +59,11 @@ int type; { +#if OS2 + SIGNAL(SIGINT, SIG_ACK); +#endif SIGNAL(SIGINT, u_interrupt); sigs |= S_INTERRUPT; if (reading) intread(); -} - - public void -fake_interrupt() -{ - sigs |= S_INTERRUPT; } diff -r -U2 less-252/tags.c less-278/tags.c --- less-252/tags.c Sat Oct 15 03:16:49 1994 +++ less-278/tags.c Tue Jan 31 18:56:18 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -53,4 +53,5 @@ { char *p; + char *q; register FILE *f; register int taglen; @@ -118,4 +119,5 @@ * Delete the initial "^" (if present) and * the final "$" from the pattern. + * Delete any backslash in the pattern. */ taglinenum = 0; @@ -123,10 +125,14 @@ if (*p == '^') p++; - tagpattern = p; + tagpattern = q = p; while (*p != search_char && *p != '\0') - p++; - if (p[-1] == '$') - p--; - *p = '\0'; + { + if (*p == '\\') + p++; + *q++ = *p++; + } + if (q[-1] == '$') + q--; + *q = '\0'; } diff -r -U2 less-252/ttyin.c less-278/ttyin.c --- less-252/ttyin.c Sat Oct 15 03:16:49 1994 +++ less-278/ttyin.c Tue Jan 31 18:56:18 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -31,7 +31,4 @@ #include "less.h" -#if HAVE_FCNTL_H -#include -#endif static int tty; @@ -43,5 +40,5 @@ open_getchr() { -#if MSOFTC +#if MSOFTC || OS2 extern int fd0; /* @@ -51,5 +48,5 @@ fd0 = dup(0); close(0); - tty = open("CON", O_RDONLY|O_BINARY); + tty = OPEN_TTYIN(); #else /* @@ -59,5 +56,5 @@ * but also usually lets you read from the keyboard. */ - tty = open("/dev/tty", 0); + tty = OPEN_TTYIN(); if (tty < 0) tty = 2; @@ -86,4 +83,12 @@ return (READ_INTR); #else +#if OS2 + flush(); + while (_read_kbd(0, 0, 0) != -1) + continue; + if ((c = _read_kbd(0, 1, 0)) == -1) + return (READ_INTR); + result = 1; +#else result = iread(tty, &c, sizeof(char)); if (result == READ_INTR) @@ -95,6 +100,7 @@ * because error calls getchr! */ - quit(1); + quit(QUIT_ERROR); } +#endif #endif /* diff -r -U2 less-252/version.c less-278/version.c --- less-252/version.c Wed Nov 16 14:23:28 1994 +++ less-278/version.c Wed Feb 15 01:15:36 1995 @@ -1,4 +1,4 @@ /* - * Copyright (c) 1984,1985,1989,1994 Mark Nudelman + * Copyright (c) 1984,1985,1989,1994,1995 Mark Nudelman * All rights reserved. * @@ -454,5 +454,41 @@ * v252: Change default lesskey input file from 11/16/94 * .lesskey.in to .lesskey. + * Posted to prep.ai.mit.edu + * ----------------------------------------------------------------- + * v253: Fix bug when tags file has a backslash. 11/21/94 + * v254: Fix -k option. 12/6/94 + * v255: Add #define EXAMINE to disable :e etc. 12/8/94 + * v256: Change highlighting: only highlite search 12/10/94 + * results (but now it is reliable). + * v257: Add goto_line and repaint_highlight 12/10/94 + * to optimize highlight repaints. + * v258: Fixup in hilite_line if BS_SPECIAL. 12/12/94 + * v259: Convert to autoconf 2.0. 12/12/94 + * v260: Add SECURE define. 12/13/94 + * v261: Use system WERASE char as EC_W_BACKSPACE. 12/14/94 + * v262: Add -g/-G flag and screen_hilite. 12/16/94 + * v263: Reimplement/optimize -G flag behavior. 12/20/94 + * v264: Allow EXTRA string after line-edit cmd 12/23/94 + * in lesskey file. + * v265: Add LESSOPEN=|cmd syntax. 12/24/94 + * v266: Add -I flag. 12/26/94 + * v267: Formalize the four-byte header emitted 12/28/94 + * by a LESSOPEN pipe. + * v268: Get rid of four-byte header. 12/28/94 + * v269: Close alt file before open new one. 1/2/95 + * Avoids multiple popen(). + * v270: Use VISUAL; use S_ISDIR/S_ISREG; fix 1/3/95 + * config problem with Solaris POSIX regcomp. + * v271: Don't quit on read error. 1/4/95 + * v272: Get rid of -L. 1/5/95 + * v273: Fix ch_ungetchar bug; don't call 1/6/95 + * LESSOPEN on a pipe. + * v274: Ported to OS/2 (thanks to Kai Uwe Rommel) 1/6/95 + * v275: Fix bug if toggle -G at EOF. 1/18/95 + * v276: Fix OS/2 version. 1/30/95 + * v277: Add "next" charset; don't display ^X 1/31/95 + * for X > 128. + * v278: Change default for -G. 2/14/95 */ -char version[] = "252"; +char version[] = "278";