diff --exclude=*,v -r -U2 --entire less-237/Makefile.in less-252/Makefile.in --- less-237/Makefile.in Fri Sep 16 12:57:05 1994 +++ less-252/Makefile.in Sun Nov 6 19:04:04 1994 @@ -18,6 +18,6 @@ LIBS = @LIBS@ -prefix = /usr/local -exec_prefix = $(prefix) +prefix = @prefix@ +exec_prefix = @exec_prefix@ # Where the installed binary goes. @@ -26,5 +26,5 @@ # Where the help file goes. -datadir = $(prefix)/lib +datadir = $(prefix)/share mandir = $(prefix)/man/man$(manext) @@ -56,5 +56,5 @@ INSTALL Makefile.in Makefile.dos README NEWS \ configure configure.in doscreen.c acconfig.h lesskey.c \ - cmd.h defines.dos funcs.h less.h option.h position.h \ + cmd.h defines.dos 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 @@ -65,6 +65,6 @@ $(CC) $(LDFLAGS) -o $@ $(OBJ) $(LIBS) -lesskey: lesskey.$(O) - $(CC) $(LDFLAGS) -o $@ lesskey.$(O) +lesskey: lesskey.$(O) version.$(O) + $(CC) $(LDFLAGS) -o $@ lesskey.$(O) version.$(O) $(OBJ): less.h defines.h funcs.h @@ -110,4 +110,6 @@ lint: lint -I. $(CPPFLAGS) $(SRC) +newfuncs: + awk -f mkfuncs.awk $(SRC) >newfuncs clean: rm -f *.$(O) core less lesskey @@ -132,5 +134,3 @@ done; \ tar -chf - $$REL | gzip -c >release/$$REL/$$REL.tar.gz; \ - rm -rf $$REL; \ - echo "Creating release/$$REL/$$REL.shar.Z"; \ - shar ${DISTFILES} | compress -c >release/$$REL/$$REL.shar.Z + rm -rf $$REL diff --exclude=*,v -r -U2 --entire less-237/NEWS less-252/NEWS --- less-237/NEWS Fri Sep 30 15:02:07 1994 +++ less-252/NEWS Wed Nov 16 14:23:45 1994 @@ -1,3 +1,26 @@ + Major changes between "less" versions 237 and 252 + +* Changes in line-editing keys: + The literal key is now ^V or ^A rather than \ (backslash). + Filename completion commands (TAB and ^L) are disabled + when typing a search pattern. + +* Line-editing command keys can be redefined using lesskey. + +* Lesskey with no input file defaults to $HOME/.lesskey + rather than standard input. + +* New option -V displays version number of less. + +* New option -V displays version number of lesskey. + +* Help file less.hlp is now installed by default in /usr/local/share + rather than /usr/local/lib. + + +====================================================================== + + Major changes between "less" versions 170 and 237 diff --exclude=*,v -r -U2 --entire less-237/README less-252/README --- less-237/README Fri Sep 30 15:03:06 1994 +++ less-252/README Wed Nov 16 14:23:52 1994 @@ -1,4 +1,4 @@ ======================================================================= -=== NOTE: THIS IS A DISTRIBUTION OF less (version 237) === +=== NOTE: THIS IS A DISTRIBUTION OF less (version 252) === === PLEASE REPORT ANY PROBLEMS TO THE AUTHOR AT markn@3do.com. === ======================================================================= diff --exclude=*,v -r -U2 --entire less-237/acconfig.h less-252/acconfig.h --- less-237/acconfig.h Fri Sep 30 14:40:31 1994 +++ less-252/acconfig.h Thu Oct 27 15:18:19 1994 @@ -62,5 +62,5 @@ #undef MUST_DEFINE_OSPEED -/* Define HAVE_LOCALE you have locale.h and setlocale. */ +/* Define HAVE_LOCALE if you have locale.h and setlocale. */ #undef HAVE_LOCALE diff --exclude=*,v -r -U2 --entire less-237/charset.c less-252/charset.c --- less-237/charset.c Sun Aug 28 17:26:23 1994 +++ less-252/charset.c Sat Oct 15 03:16:44 1994 @@ -57,5 +57,5 @@ static char chardef[256]; static char *binfmt = NULL; -public int binattr = AT_BLINK; +public int binattr = AT_STANDOUT; diff --exclude=*,v -r -U2 --entire less-237/cmd.h less-252/cmd.h --- less-237/cmd.h Thu Aug 25 00:28:58 1994 +++ less-252/cmd.h Sat Oct 15 03:16:44 1994 @@ -83,4 +83,35 @@ #define A_NOACTION 101 #define A_UINVALID 102 +#define A_END_LIST 103 #define A_EXTRA 0200 + + +/* Line editting characters */ + +#define EC_BACKSPACE 1 +#define EC_LINEKILL 2 +#define EC_RIGHT 3 +#define EC_LEFT 4 +#define EC_W_LEFT 5 +#define EC_W_RIGHT 6 +#define EC_INSERT 7 +#define EC_DELETE 8 +#define EC_HOME 9 +#define EC_END 10 +#define EC_W_BACKSPACE 11 +#define EC_W_DELETE 12 +#define EC_UP 13 +#define EC_DOWN 14 +#define EC_EXPAND 15 +#define EC_F_COMPLETE 17 +#define EC_B_COMPLETE 18 +#define EC_LITERAL 19 + +#define EC_UINVALID 102 + +/* Flags for editchar() */ +#define EC_PEEK 01 +#define EC_NOHISTORY 02 +#define EC_NOCOMPLETE 04 + diff --exclude=*,v -r -U2 --entire less-237/cmdbuf.c less-252/cmdbuf.c --- less-237/cmdbuf.c Fri Sep 2 16:18:46 1994 +++ less-252/cmdbuf.c Tue Oct 25 18:33:38 1994 @@ -32,5 +32,5 @@ #include "less.h" -#define LITERAL ('\\') +#include "cmd.h" extern int sc_width; @@ -39,4 +39,5 @@ static int cmd_col; /* Current column of the multi-char command */ static char *cp; /* Pointer into cmdbuf */ +static int literal; #if TAB_COMPLETE_FILENAME @@ -96,4 +97,5 @@ *cp = '\0'; cmd_col = 0; + literal = 0; } @@ -467,19 +469,39 @@ { int action; + int flags; + +#if TAB_COMPLETE_FILENAME +#define not_in_completion() in_completion = 0 +#else +#define not_in_completion() +#endif /* * See if the char is indeed a line-editing command. */ - action = editchar(c, (curr_mlist == NULL) ? EC_NOHISTORY : 0); + flags = 0; + if (curr_mlist == NULL) + /* + * No current history; don't accept history manipulation cmds. + */ + flags |= EC_NOHISTORY; + if (curr_mlist == &mlist_search) + /* + * In a search command; don't accept file-completion cmds. + */ + flags |= EC_NOCOMPLETE; + + action = editchar(c, flags); + switch (action) { case EC_RIGHT: - in_completion = 0; + not_in_completion(); return (cmd_right()); case EC_LEFT: - in_completion = 0; + not_in_completion(); return (cmd_left()); case EC_W_RIGHT: - in_completion = 0; + not_in_completion(); while (*cp != '\0' && *cp != ' ') cmd_right(); @@ -488,5 +510,5 @@ return (CC_OK); case EC_W_LEFT: - in_completion = 0; + not_in_completion(); while (cp > cmdbuf && cp[-1] == ' ') cmd_left(); @@ -495,33 +517,36 @@ return (CC_OK); case EC_HOME: - in_completion = 0; + not_in_completion(); return (cmd_home()); case EC_END: - in_completion = 0; + not_in_completion(); while (*cp != '\0') cmd_right(); return (CC_OK); case EC_INSERT: - in_completion = 0; + not_in_completion(); return (CC_OK); case EC_BACKSPACE: - in_completion = 0; + not_in_completion(); return (cmd_erase()); case EC_LINEKILL: - in_completion = 0; + not_in_completion(); return (cmd_kill()); case EC_W_BACKSPACE: - in_completion = 0; + not_in_completion(); return (cmd_werase()); case EC_DELETE: - in_completion = 0; + not_in_completion(); return (cmd_delete()); case EC_W_DELETE: - in_completion = 0; + not_in_completion(); return (cmd_wdelete()); + case EC_LITERAL: + literal = 1; + return (CC_OK); #if CMD_HISTORY case EC_UP: case EC_DOWN: - in_completion = 0; + not_in_completion(); return (cmd_updown(action)); #endif @@ -533,5 +558,5 @@ #endif default: - in_completion = 0; + not_in_completion(); return (CC_PASS); } @@ -653,5 +678,5 @@ * Move cursor to end of word. */ - if (*cp != ' ') + if (*cp != ' ' && *cp != '\0') { /* @@ -661,5 +686,5 @@ while (*cp != ' ' && *cp != '\0') cmd_right(); - } else if (cp[-1] != ' ') + } else if (cp > cmdbuf && cp[-1] != ' ') { /* @@ -668,5 +693,5 @@ */ ; - } else /* (*cp == ' ' && cp[-1] == ' ') */ + } else { /* @@ -679,4 +704,6 @@ * Search backwards for beginning of the word. */ + if (cp == cmdbuf) + return (NULL); for (word = cp-1; word > cmdbuf; word--) if (word[-1] == ' ') @@ -849,10 +876,10 @@ int action; - if (*cp == LITERAL) + if (literal) { /* - * Delete the LITERAL char and insert the new char. + * Insert the char, even if it is a line-editing char. */ - cmd_delete(); + literal = 0; return (cmd_ichar(c)); } @@ -880,6 +907,4 @@ if (action != CC_OK) return (action); - if (c == LITERAL) - cmd_left(); return (CC_OK); } diff --exclude=*,v -r -U2 --entire less-237/command.c less-252/command.c --- less-237/command.c Fri Sep 2 16:19:24 1994 +++ less-252/command.c Sun Nov 6 18:56:19 1994 @@ -271,5 +271,6 @@ * Terminated by a non-digit. */ - if ((c < '0' || c > '9') && editchar(c, EC_PEEK|EC_NOHISTORY) == A_INVALID) + if ((c < '0' || c > '9') && + editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE) == A_INVALID) { /* @@ -474,4 +475,13 @@ } + public void +dispversion() +{ + PARG parg; + + parg.p_string = version; + error("less version %s", &parg); +} + /* * Get command character. @@ -692,5 +702,5 @@ /* * If we are in a multicharacter command, call mca_char. - * Otherwise we call cmd_decode to determine the + * Otherwise we call fcmd_decode to determine the * action to be performed. */ @@ -748,5 +758,5 @@ } s = NULL; - action = cmd_decode(cbuf, &s); + action = fcmd_decode(cbuf, &s); /* * If an "extra" string was returned, @@ -955,6 +965,5 @@ */ cmd_exec(); - parg.p_string = version+4; - error("%s", &parg); + dispversion(); break; diff --exclude=*,v -r -U2 --entire less-237/decode.c less-252/decode.c --- less-237/decode.c Thu Aug 25 00:28:26 1994 +++ less-252/decode.c Sat Oct 15 03:16:45 1994 @@ -49,4 +49,5 @@ #include "less.h" #include "cmd.h" +#include "lesskey.h" extern int erase_char, kill_char; @@ -158,4 +159,26 @@ }; +static char edittable[] = +{ + '\t',0, EC_F_COMPLETE, /* TAB */ + '\17',0, EC_B_COMPLETE, /* BACKTAB */ + '\14',0, EC_EXPAND, /* CTRL-L */ + CONTROL('V'),0, EC_LITERAL, /* BACKSLASH */ + CONTROL('A'),0, EC_LITERAL, /* BACKSLASH */ + ESC,'l',0, EC_RIGHT, /* ESC l */ + ESC,'h',0, EC_LEFT, /* ESC h */ + ESC,'b',0, EC_W_LEFT, /* ESC b */ + ESC,'w',0, EC_W_RIGHT, /* ESC w */ + ESC,'i',0, EC_INSERT, /* ESC i */ + ESC,'x',0, EC_DELETE, /* ESC x */ + ESC,'X',0, EC_W_DELETE, /* ESC X */ + ESC,'\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */ + ESC,'0',0, EC_HOME, /* ESC 0 */ + ESC,'$',0, EC_END, /* ESC $ */ + ESC,'k',0, EC_UP, /* ESC k */ + ESC,'j',0, EC_DOWN, /* ESC j */ + ESC,'\t',0, EC_B_COMPLETE /* ESC TAB */ +}; + /* * Structure to support a list of command tables. @@ -169,64 +192,73 @@ /* - * Structure for the default command table. + * List of command tables and list of line-edit tables. */ -static struct tablelist deftable = - { NULL, cmdtable, cmdtable+sizeof(cmdtable) }; - -/* - * List of tables; initially contains only the default table. - */ -static struct tablelist *tables = &deftable; +static struct tablelist *list_fcmd_tables = NULL; +static struct tablelist *list_ecmd_tables = NULL; /* - * + * Initialize the command lists. */ public void -cmd_init() +init_cmds() { - struct tablelist *t; - static struct tablelist klist; - extern char kcmdtable[]; - extern int sz_kcmdtable; - - klist.t_start = kcmdtable; - klist.t_end = kcmdtable + sz_kcmdtable; - /* - * Put the editkey command table at end of list of tables. - */ - klist.t_next = NULL; - for (t = tables; t->t_next != NULL; t = t->t_next) - continue; - t->t_next = &klist; + add_fcmd_table(cmdtable, sizeof(cmdtable)); + add_ecmd_table(edittable, sizeof(edittable)); } /* - * Decode a command character and return the associated action. - * The "extra" string, if any, is returned in sp. + * */ - public int -cmd_decode(cmd, sp) - char *cmd; - char **sp; + static int +add_cmd_table(tlist, buf, len) + struct tablelist **tlist; + char *buf; + int len; { register struct tablelist *t; - register int action = A_INVALID; /* - * Search thru all the command tables. - * Stop when we find an action which is not A_INVALID. + * Allocate a tablelist structure, initialize it, + * and link it into the list of tables. */ - for (t = tables; t != NULL; t = t->t_next) + if ((t = (struct tablelist *) + calloc(1, sizeof(struct tablelist))) == NULL) { - action = cmd_search(cmd, t->t_start, t->t_end, sp); - if (action != A_INVALID) - break; + return (-1); } - return (action); + t->t_start = buf; + t->t_end = buf + len; + t->t_next = *tlist; + *tlist = t; + return (0); } /* - * Search a command table for the current command string (in cmd). + * + */ + public void +add_fcmd_table(buf, len) + char *buf; + int len; +{ + if (add_cmd_table(&list_fcmd_tables, buf, len) < 0) + error("Warning: some commands disabled", NULL_PARG); +} + +/* + * + */ + public void +add_ecmd_table(buf, len) + char *buf; + int len; +{ + if (add_cmd_table(&list_ecmd_tables, buf, len) < 0) + error("Warning: some edit commands disabled", NULL_PARG); +} + +/* + * Search a single command table for the command string in cmd. */ public int @@ -255,4 +287,14 @@ { a = *++p & 0377; + if (a == A_END_LIST) + { + /* + * We get here only if the original + * cmd string passed in was empty (""). + * I don't think that can happen, + * but just in case ... + */ + return (A_UINVALID); + } /* * Check for an "extra" string. @@ -282,4 +324,12 @@ * to the beginning of the user's command. */ + if (*p == '\0' && p[1] == A_END_LIST) + { + /* + * A_END_LIST is a special marker that tells + * us to abort the cmd search. + */ + return (A_UINVALID); + } while (*p++ != '\0') ; if (*p & A_EXTRA) @@ -294,13 +344,136 @@ } +/* + * Decode a command character and return the associated action. + * The "extra" string, if any, is returned in sp. + */ + static int +cmd_decode(tlist, cmd, sp) + struct tablelist *tlist; + char *cmd; + char **sp; +{ + register struct tablelist *t; + register int action = A_INVALID; + + /* + * Search thru all the command tables. + * Stop when we find an action which is not A_INVALID. + */ + for (t = tlist; t != NULL; t = t->t_next) + { + action = cmd_search(cmd, t->t_start, t->t_end, sp); + if (action != A_INVALID) + break; + } + return (action); +} + +/* + * Decode a command from the cmdtables list. + */ + public int +fcmd_decode(cmd, sp) + char *cmd; + char **sp; +{ + return (cmd_decode(list_fcmd_tables, cmd, sp)); +} + +/* + * Decode a command from the edittables list. + */ + public int +ecmd_decode(cmd, sp) + char *cmd; + char **sp; +{ + return (cmd_decode(list_ecmd_tables, cmd, sp)); +} + #if USERFILE + static int +gint(sp) + char **sp; +{ + int n; + + n = *(*sp)++; + n += *(*sp)++ * KRADIX; + return (n); +} + + static int +old_lesskey(buf, len) + char *buf; + int len; +{ + /* + * Old-style lesskey file. + * The file must end with either + * ...,cmd,0,action + * or ...,cmd,0,action|A_EXTRA,string,0 + * So the last byte or the second to last byte must be zero. + */ + if (buf[len-1] != '\0' && buf[len-2] != '\0') + return (-1); + add_fcmd_table(buf, len); + return (0); +} + + static int +new_lesskey(buf, len) + char *buf; + int len; +{ + char *p; + register int c; + register int done; + register int n; + + /* + * New-style lesskey file. + * Extract the pieces. + */ + if (buf[len-3] != C0_END_LESSKEY_MAGIC || + buf[len-2] != C1_END_LESSKEY_MAGIC || + buf[len-1] != C2_END_LESSKEY_MAGIC) + return (-1); + p = buf + 4; + done = 0; + while (!done) + { + c = *p++; + switch (c) + { + case CMD_SECTION: + n = gint(&p); + add_fcmd_table(p, n); + p += n; + break; + case EDIT_SECTION: + n = gint(&p); + add_ecmd_table(p, n); + p += n; + break; + case END_SECTION: + done = 1; + break; + default: + free(buf); + return (-1); + } + } + return (0); +} + /* * Set up a user command table, based on a "lesskey" file. */ public int -add_cmdtable(filename) +lesskey(filename) char *filename; { - register struct tablelist *t; + register char *buf; register POSITION len; register long n; @@ -309,12 +482,11 @@ /* * Try to open the lesskey file. - * If we can't, return an error. */ f = open(filename, 0); if (f < 0) - return (-1); + return (1); /* - * Read the file into the user table. + * Read the file into a buffer. * We first figure out the size of the file and allocate space for it. * {{ Minimal error checking is done here. @@ -332,13 +504,6 @@ return (-1); } - if ((t = (struct tablelist *) - calloc(1, sizeof(struct tablelist))) == NULL) - { - close(f); - return (-1); - } - if ((t->t_start = (char *) calloc((int)len, sizeof(char))) == NULL) + if ((buf = (char *) calloc((int)len, sizeof(char))) == NULL) { - free((char *)t); close(f); return (-1); @@ -346,34 +511,28 @@ if (lseek(f, (off_t)0, 0) == BAD_LSEEK) { - free(t->t_start); - free((char *)t); + free(buf); close(f); return (-1); } - n = read(f, t->t_start, (unsigned int) len); + n = read(f, buf, (unsigned int) len); close(f); - - /* - * In a valid lesskey file, the last byte or - * the second to the last byte must be zero. - */ - if (n != len || (t->t_start[n-1] != '\0' && t->t_start[n-2] != '\0')) + if (n != len) { - free(t->t_start); - free((char *)t); + free(buf); return (-1); } - t->t_end = t->t_start + n; /* - * Link it into the list of tables. + * Figure out if this is an old-style (before version 241) + * or new-style lesskey file format. */ - t->t_next = tables; - tables = t; - return (0); + if (buf[0] != C0_LESSKEY_MAGIC || buf[1] != C1_LESSKEY_MAGIC || + buf[2] != C2_LESSKEY_MAGIC || buf[3] != C3_LESSKEY_MAGIC) + return (old_lesskey(buf, (int)len)); + return (new_lesskey(buf, (int)len)); } /* - * Try to add the lesskey file "$HOME/.less" + * Add the standard lesskey file "$HOME/.less" */ public void @@ -381,12 +540,14 @@ { char *filename; + PARG parg; filename = homefile(LESSKEYFILE); if (filename == NULL) return; - /* - * Ignore errors. - */ - (void) add_cmdtable(filename); + if (lesskey(filename) < 0) + { + parg.p_string = filename; + error("Cannot use lesskey file \"%s\"", &parg); + } free(filename); } @@ -404,16 +565,13 @@ int nch; char *s; - char usercmd[30]; + char usercmd[MAX_CMDLEN+1]; /* * An editing character could actually be a sequence of characters; * for example, an escape sequence sent by pressing the uparrow key. - * To match the editing string, we use the command decoder, cmd_search, - * but give it a special command table supplied by screen.c. + * To match the editing string, we use the command decoder + * but give it the edit-commands command table * This table is constructed to match the user's keyboard. */ - extern char edittable[]; - extern int sz_edittable; - if (c == erase_char) return (EC_BACKSPACE); @@ -432,5 +590,5 @@ usercmd[nch+1] = '\0'; nch++; - action = cmd_search(usercmd, edittable, edittable + sz_edittable, &s); + action = ecmd_decode(usercmd, &s); } while (action == A_PREFIX); @@ -449,7 +607,23 @@ } } + if (flags & EC_NOCOMPLETE) + { + /* + * The caller says we don't want any filename completion cmds. + * Reject them. + */ + switch (action) + { + case EC_F_COMPLETE: + case EC_B_COMPLETE: + case EC_EXPAND: + action = A_INVALID; + break; + } + } if ((flags & EC_PEEK) || action == A_INVALID) { /* + * We're just peeking, or we didn't understand the command. * Unget all the characters we read in the loop above. * This does NOT include the original character that was diff --exclude=*,v -r -U2 --entire less-237/defines.dos less-252/defines.dos --- less-237/defines.dos Mon Aug 29 14:34:29 1994 +++ less-252/defines.dos Wed Nov 16 14:22:22 1994 @@ -104,8 +104,11 @@ /* - * LESSKEYFILE is the filename of the default lesskey file + * LESSKEYFILE is the filename of the default lesskey output file + * (in the HOME directory). + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). */ -#define LESSKEYFILE "_less" +#define LESSKEYFILE "_less" +#define DEF_LESSKEYINFILE "_lesskey" /* @@ -193,7 +196,13 @@ #define MUST_DEFINE_OSPEED 0 -/* Define if you have locale.h and setlocale. */ +/* Define HAVE_LOCALE if you have locale.h and setlocale. */ #define HAVE_LOCALE 0 +/* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr */ +#define HAVE_TERMIOS_FUNCS 0 + +/* Define HAVE_UPPER_LOWER if you have isupper, islower, toupper, tolower */ +#define HAVE_UPPER_LOWER 1 + /* Define if you have _setjmp. */ #define HAVE__SETJMP 0 @@ -205,6 +214,12 @@ #define HAVE_SIGSETMASK 0 +/* Define if you have strchr. */ +#define HAVE_STRCHR 1 + /* Define if you have system. */ #define HAVE_SYSTEM 1 + +/* Define if you have the header file. */ +#define HAVE_CTYPE_H 1 /* Define if you have the header file. */ diff --exclude=*,v -r -U2 --entire less-237/defines.h.in less-252/defines.h.in --- less-237/defines.h.in Fri Sep 30 14:40:42 1994 +++ less-252/defines.h.in Wed Nov 16 14:24:53 1994 @@ -83,8 +83,12 @@ /* - * LESSKEYFILE is the filename of the default lesskey file + * LESSKEYFILE is the filename of the default lesskey output file + * (in the HOME directory). + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). */ -#define LESSKEYFILE ".less" +#define LESSKEYFILE ".less" +#define DEF_LESSKEYINFILE ".lesskey" + /* Settings always true on Unix. */ @@ -168,5 +172,5 @@ #undef MUST_DEFINE_OSPEED -/* Define HAVE_LOCALE you have locale.h and setlocale. */ +/* Define HAVE_LOCALE if you have locale.h and setlocale. */ #undef HAVE_LOCALE diff --exclude=*,v -r -U2 --entire less-237/defines.h.top less-252/defines.h.top --- less-237/defines.h.top Sun Aug 21 20:14:38 1994 +++ less-252/defines.h.top Wed Nov 16 14:22:06 1994 @@ -82,8 +82,12 @@ /* - * LESSKEYFILE is the filename of the default lesskey file + * LESSKEYFILE is the filename of the default lesskey output file + * (in the HOME directory). + * DEF_LESSKEYINFILE is the filename of the default lesskey input * (in the HOME directory). */ -#define LESSKEYFILE ".less" +#define LESSKEYFILE ".less" +#define DEF_LESSKEYINFILE ".lesskey" + /* Settings always true on Unix. */ diff --exclude=*,v -r -U2 --entire less-237/funcs.h less-252/funcs.h --- less-237/funcs.h Wed Sep 21 17:12:05 1994 +++ less-252/funcs.h Thu Oct 27 17:23:39 1994 @@ -1,2 +1,31 @@ + public void strtcpy (); + public char * save (); + public VOID_POINTER ecalloc (); + public char * skipsp (); + public void quit (); + public void raw_mode (); + public void scrsize (); + public void get_editkeys (); + public void get_term (); + public void init (); + public void deinit (); + public void home (); + public void add_line (); + public void lower_left (); + public void bell (); + public void vbell (); + public void clear (); + public void clear_eol (); + public void clear_bot (); + public void so_enter (); + public void so_exit (); + public void ul_enter (); + public void ul_exit (); + public void bo_enter (); + public void bo_exit (); + public void bl_enter (); + public void bl_exit (); + public void backspace (); + public void putbs (); public void match_brac (); public void end_logfile (); @@ -32,33 +61,13 @@ public void ungetsc (); public void commands (); - public void cmd_init (); - public int cmd_decode (); + public void init_cmds (); + public void add_fcmd_table (); + public void add_ecmd_table (); public int cmd_search (); - public int add_cmdtable (); + public int fcmd_decode (); + public int ecmd_decode (); + public int lesskey (); public void add_hometable (); public int editchar (); - public void raw_mode (); - public void scrsize (); - public void get_term (); - public void init (); - public void deinit (); - public void home (); - public void add_line (); - public void lower_left (); - public void vbell (); - public void bell (); - public void clear (); - public void clear_eol (); - public void clear_bot (); - public void so_enter (); - public void so_exit (); - public void ul_enter (); - public void ul_exit (); - public void bo_enter (); - public void bo_exit (); - public void bl_enter (); - public void bl_exit (); - public void backspace (); - public void putbs (); public void init_textlist (); public char * forw_textlist (); @@ -135,9 +144,4 @@ public int pipe_mark (); public int pipe_data (); - public void strtcpy (); - public char * save (); - public VOID_POINTER ecalloc (); - public char * skipsp (); - public void quit (); public void init_mark (); public int badmark (); @@ -157,4 +161,5 @@ public void opt_b (); public void opt_i (); + public void opt__V (); public void opt_D (); public void opt_query (); @@ -195,28 +200,4 @@ public char * eq_message (); public char * pr_string (); - public void raw_mode (); - public void scrsize (); - public void get_editkeys (); - public void get_term (); - public void init (); - public void deinit (); - public void home (); - public void add_line (); - public void lower_left (); - public void bell (); - public void vbell (); - public void clear (); - public void clear_eol (); - public void clear_bot (); - public void so_enter (); - public void so_exit (); - public void ul_enter (); - public void ul_exit (); - public void bo_enter (); - public void bo_exit (); - public void bl_enter (); - public void bl_exit (); - public void backspace (); - public void putbs (); public void undo_search (); public void chg_caseless (); diff --exclude=*,v -r -U2 --entire less-237/less.h less-252/less.h --- less-237/less.h Fri Sep 30 14:50:52 1994 +++ less-252/less.h Sat Oct 15 03:16:46 1994 @@ -188,27 +188,4 @@ #define ESC CONTROL('[') -/* Line editting characters */ -#define EC_BACKSPACE 1 -#define EC_LINEKILL 2 -#define EC_RIGHT 3 -#define EC_LEFT 4 -#define EC_W_LEFT 5 -#define EC_W_RIGHT 6 -#define EC_INSERT 7 -#define EC_DELETE 8 -#define EC_HOME 9 -#define EC_END 10 -#define EC_W_BACKSPACE 11 -#define EC_W_DELETE 12 -#define EC_UP 13 -#define EC_DOWN 14 -#define EC_EXPAND 15 -#define EC_F_COMPLETE 17 -#define EC_B_COMPLETE 18 - -/* Flags for editchar() */ -#define EC_PEEK 01 -#define EC_NOHISTORY 02 - #define SIGNAL(sig,func) signal(sig,func) @@ -219,3 +196,4 @@ #define ch_zero() ((POSITION)0) + #include "funcs.h" diff --exclude=*,v -r -U2 --entire less-237/less.hlp less-252/less.hlp --- less-237/less.hlp Tue Sep 6 12:41:15 1994 +++ less-252/less.hlp Thu Oct 27 17:33:18 1994 @@ -99,4 +99,5 @@ -T [_t_a_g_s_f_i_l_e] Use an alternate tags file. -u -U Change handling of backspaces. + -V Display the version number of "less". -w Display ~ for lines after end-of-file. -x [_N] Set tab stops. diff --exclude=*,v -r -U2 --entire less-237/less.man less-252/less.man --- less-237/less.man Fri Sep 30 13:18:58 1994 +++ less-252/less.man Tue Nov 1 15:53:12 1994 @@ -11,4 +11,5 @@ SYNOPSIS less -? + less -V less [-[+]aBcCdeEfHimMnNqQrsSuUw] [-b _b_u_f_s] [-h _l_i_n_e_s] [-j _l_i_n_e] [-k _k_e_y_f_i_l_e] @@ -56,6 +57,5 @@ are displayed, even if N is more than the screen size. - d or ^D - Scroll forward N lines, default one half of the screen + @@ -72,4 +72,6 @@ + d or ^D + Scroll forward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequent d and u commands. @@ -122,6 +124,4 @@ between 0 and 100. (This works if standard input is being read, but only if _l_e_s_s has already read to the - end of the file. It is always fast, but not always - useful.) @@ -138,4 +138,7 @@ + end of the file. It is always fast, but not always + useful.) + { If a left curly bracket appears in the top line displayed on the screen, the { command will go to the @@ -186,8 +189,5 @@ returns to the position which was previously marked with that letter. Followed by another single quote, - returns to the position at which the last "large" move- - ment command was executed. Followed by a ^ or $, jumps - to the beginning or end of the file respectively. - Marks are preserved when a new file is examined, so the + returns to the position at which the last "large" @@ -204,4 +204,7 @@ + movement command was executed. Followed by a ^ or $, + jumps to the beginning or end of the file respectively. + Marks are preserved when a new file is examined, so the ' command can be used to switch between input files. @@ -253,7 +256,4 @@ Same as "/*". - ESC-?pattern - Same as "?*". - @@ -270,4 +270,7 @@ + ESC-?pattern + Same as "?*". + n Repeat previous search, for N-th line containing the last pattern. If the previous search was modified by @@ -319,7 +322,4 @@ th next file is examined. - :p Examine the previous file in the command line list. If - a number N is specified, the N-th previous file is - examined. @@ -336,4 +336,8 @@ + :p Examine the previous file in the command line list. If + a number N is specified, the N-th previous file is + examined. + :x Examine the first file in the command line list. If a number N is specified, the N-th file in the list is @@ -383,9 +387,5 @@ V Prints the version number of _l_e_s_s being run. - q or :q or :Q or ZZ - Exits _l_e_s_s. - The following three commands may or may not be valid, - depending on your particular installation. @@ -402,4 +402,10 @@ + q or :q or :Q or ZZ + Exits _l_e_s_s. + + The following three commands may or may not be valid, + depending on your particular installation. + v Invokes an editor to edit the current file being viewed. The editor is taken from the environment vari- @@ -449,10 +455,4 @@ 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 - given, all other options are ignored, and _l_e_s_s exits - after the help screen is viewed. (Depending on how - your shell interprets the question mark, it may be - @@ -468,4 +468,9 @@ + -? This option displays a summary of the commands accepted + by _l_e_s_s (the same as the h command). If this option is + given, all other options are ignored, and _l_e_s_s exits + after the help screen is viewed. (Depending on how + your shell interprets the question mark, it may be necessary to quote the question mark, thus: "-\?".) @@ -516,9 +521,4 @@ _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. - - -f Forces non-regular files to be opened. (A non-regular - @@ -534,4 +534,8 @@ + -E Causes _l_e_s_s to automatically exit the first time it + reaches end-of-file. + + -f Forces non-regular files to be opened. (A non-regular file is a directory or a device special file.) Also suppresses the warning message when a binary file is @@ -582,8 +586,4 @@ -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. - Suppressing line numbers with the -n flag will avoid - this problem. Using line numbers means: the line @@ -600,4 +600,8 @@ + numbers) may cause _l_e_s_s to run more slowly in some + cases, especially with a very large input file. + Suppressing line numbers with the -n flag will avoid + this problem. Using line numbers means: the line number will be displayed in the verbose prompt and in the = command, and the v command will pass the current @@ -648,8 +652,4 @@ is not rung if an attempt is made to scroll past the end of the file or before the beginning of the file. - If the terminal has a "visual bell", it is used - instead. The bell will be rung on certain other - errors, such as typing an invalid character. The - default is to ring the terminal bell in all such cases. @@ -666,4 +666,9 @@ + If the terminal has a "visual bell", it is used + instead. The bell will be rung on certain other + errors, such as typing an invalid character. The + default is to ring the terminal bell in all such cases. + -Q Causes totally "quiet" operation: the terminal bell is never rung. @@ -713,9 +718,4 @@ treated specially: the underlined text is displayed using the terminal's hardware underlining capability. - Also, backspaces which appear between two identical - characters are treated specially: the overstruck text - is printed using the terminal's hardware boldface capa- - bility. Other backspaces are deleted, along with the - preceding character. Carriage returns immediately @@ -732,8 +732,14 @@ - 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. + Also, backspaces which appear between two identical + characters are treated specially: the overstruck text + is printed using the terminal's hardware boldface capa- + bility. Other backspaces are deleted, along with the + preceding character. Carriage returns immediately fol- + 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. + + -V Displays the version number of _l_e_s_s. -w Causes blank lines to be used to represent lines past @@ -778,10 +784,4 @@ applies to every file being viewed, not just the first one. The + command described previously may also be - used to set (or change) an initial command for every - file. - - -LINE EDITING - When entering command line at the bottom of the screen (for @@ -798,4 +798,10 @@ + used to set (or change) an initial command for every + file. + + +LINE EDITING + When entering command line at the bottom of the screen (for example, a filename for the :e command, or the pattern for a search command), certain keys can be used to manipulate the @@ -804,7 +810,7 @@ particular keyboard. (The bracketed forms do not work in the MS-DOS version.) Any of these special keys may be entered - literally by preceding it with a backslash. A backslash - itself may also be entered literally by entering two - backslashes. + literally by preceding it with the "literal" character, + either ^V or ^A. A backslash itself may also be entered + literally by entering two backslashes. LEFTARROW [ ESC-h ] @@ -844,10 +850,4 @@ UPARROW [ ESC-k ] - Retrieve the previous command line. - - DOWNARROW [ ESC-j ] - Retrieve the next command line. - - TAB Complete the partial filename to the left of the @@ -864,7 +864,13 @@ - cursor. 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. + Retrieve the previous command line. + + DOWNARROW [ ESC-j ] + Retrieve the next command line. + + TAB Complete the partial filename to the left of the cur- + 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. BACKTAB [ ESC-TAB ] @@ -887,6 +893,7 @@ _l_e_s_s_k_e_y (1) to create a file called ".less" in your home directory. This file specifies a set of command keys and an - action associated with each key. See the _l_e_s_s_k_e_y manual - page for more details. + action associated with each key. You may also use _l_e_s_s_k_e_y + to change the line-editing keys (see LINE EDITING). See the + _l_e_s_s_k_e_y manual page for more details. @@ -909,11 +916,4 @@ name of the replacement file to its standard output. If the input preprocessor does not output a replacement filename, - _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. - @@ -930,4 +930,11 @@ + _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. + When _l_e_s_s closes a file opened in such a way, it will call another program, called the input postprocessor, which may @@ -975,11 +982,4 @@ control characters should not be displayed directly, but are expected to - be found in ordinary text files (such as backspace and - tab). - - binary characters - should not be displayed directly and are not expected - to be found in text files. - @@ -996,4 +996,11 @@ + be found in ordinary text files (such as backspace and + tab). + + binary characters + should not be displayed directly and are not expected + to be found in text files. + A "character set" is simply a description of which charac- ters are to be considered normal, control, and binary. The @@ -1040,12 +1047,5 @@ ables. - Control and binary characters are displayed in standout - (reverse video). Each such character is displayed in caret - notation if possible (e.g. ^A for control-A). Caret nota- - tion is used only if inverting the 0100 bit results in a - normal printable character. Otherwise, the character is - displayed as a hex number in angle brackets. This format - can be changed by setting the LESSBINFMT environment vari- - able. LESSBINFMT may begin with a "*" and one character to + @@ -1062,4 +1062,12 @@ + Control and binary characters are displayed in standout + (reverse video). Each such character is displayed in caret + notation if possible (e.g. ^A for control-A). Caret nota- + tion is used only if inverting the 0100 bit results in a + normal printable character. Otherwise, the character is + displayed as a hex number in angle brackets. This format + can be changed by setting the LESSBINFMT environment vari- + able. LESSBINFMT may begin with a "*" and one character to select the display attribute: "*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout. If LESSBINFMT @@ -1106,12 +1114,4 @@ of input files. - %l_X Replaced by the line number of a line in the input - file. The line to be used is determined by the _X, as - with the %b option. - - %L Replaced by the line number of the last line in the - input file. - - %m Replaced by the total number of input files. @@ -1128,4 +1128,13 @@ + %l_X Replaced by the line number of a line in the input + file. The line to be used is determined by the _X, as + with the %b option. + + %L Replaced by the line number of the last line in the + input file. + + %m Replaced by the total number of input files. + %p_X Replaced by the percent into the current input file. The line used is determined by the _X as with the %b @@ -1171,26 +1180,26 @@ ?L True if the line number of the last line in the file is - known. - ?m True if there is more than one input file. - ?n True if this is the first prompt in a new input file. - ?p_X True if the percent into the current input file of the - specified line is known. + 18 - 18 +LESS(1) USER COMMANDS LESS(1) + known. -LESS(1) USER COMMANDS LESS(1) + ?m True if there is more than one input file. + ?n True if this is the first prompt in a new input file. + ?p_X True if the percent into the current input file of the + specified line is known. ?s Same as "?B". @@ -1237,27 +1246,27 @@ ?f%f .?n?m(file %i of %m) ..?ltline %lt?L/%L. :byte %bB?s/%s. . - ?e(END) ?x- Next\: %x.:?pB%pB\%..%t - And here is the default message produced by the = command: - ?f%f .?m(file %i of %m) .?ltline %lt?L/%L. . - byte %bB?s/%s. ?e(END) :?pB%pB\%..%t - The prompt expansion features are also used for another pur- - pose: if an environment variable LESSEDIT is defined, it is + 19 - 19 +LESS(1) USER COMMANDS LESS(1) -LESS(1) USER COMMANDS LESS(1) + ?e(END) ?x- Next\: %x.:?pB%pB\%..%t + And here is the default message produced by the = command: + ?f%f .?m(file %i of %m) .?ltline %lt?L/%L. . + byte %bB?s/%s. ?e(END) :?pB%pB\%..%t + The prompt expansion features are also used for another pur- + pose: if an environment variable LESSEDIT is defined, it is used as the command to be executed when the v command is invoked. The LESSEDIT string is expanded in the same way as @@ -1303,13 +1312,4 @@ LESSCHARSET - Selects a predefined character set. - - LESSCLOSE - Command line to invoke the (optional) input- - postprocessor. - - LESSEDIT - Editor prototype string (used for the v command). See - discussion under PROMPTS. @@ -1326,4 +1326,14 @@ + Selects a predefined character set. + + LESSCLOSE + Command line to invoke the (optional) input- + postprocessor. + + LESSEDIT + Editor prototype string (used for the v command). See + discussion under PROMPTS. + LESSHELP Name of the help file. @@ -1358,18 +1368,28 @@ files may be entered into the list in an unexpected order. - There is no way (yet) to modify key bindings for the line - editing commands. - 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. 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 + 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) + + + COPYRIGHT Copyright (c) 1984,1985,1989,1994 Mark Nudelman @@ -1381,5 +1401,51 @@ - 21 + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + + 22 diff --exclude=*,v -r -U2 --entire less-237/less.nro less-252/less.nro --- less-237/less.nro Fri Sep 30 13:17:58 1994 +++ less-252/less.nro Thu Oct 27 17:32:42 1994 @@ -5,4 +5,6 @@ .B "less -?" .br +.B "less -V" +.br .B "less [-[+]aBcCdeEfHimMnNqQrsSuUw]" .br @@ -650,4 +652,7 @@ Other carriage returns are handled as specified by the -r option. Text which is overstruck or underlined can be searched for. +.IP -V +Displays the version number of +.I less. .IP -w Causes blank lines to be used to represent lines @@ -709,5 +714,5 @@ (The bracketed forms do not work in the MS-DOS version.) Any of these special keys may be entered literally by preceding -it with a backslash. +it with the "literal" character, either ^V or ^A. A backslash itself may also be entered literally by entering two backslashes. .IP "LEFTARROW [ ESC-h ]" @@ -766,4 +771,7 @@ This file specifies a set of command keys and an action associated with each key. +You may also use +.I lesskey +to change the line-editing keys (see LINE EDITING). See the .I lesskey @@ -1135,6 +1143,4 @@ the new files may be entered into the list in an unexpected order. .PP -There is no way (yet) to modify key bindings for the line editing commands. -.PP If a line longer than the screen width is split (folded), and a search matches text which straddles the split, @@ -1142,4 +1148,5 @@ 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. diff --exclude=*,v -r -U2 --entire less-237/lesskey.c less-252/lesskey.c --- less-237/lesskey.c Thu Sep 29 15:36:25 1994 +++ less-252/lesskey.c Mon Nov 7 12:35:04 1994 @@ -29,4 +29,6 @@ * lesskey [-o output] [input] * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * Make a .less file. * If no input file is specified, standard input is used. @@ -37,4 +39,6 @@ * keystrokes may be bound to an existing less function. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * + * * The input file is an ascii file consisting of a * sequence of lines of the form: @@ -58,9 +62,23 @@ * as keyboard input after the command is executed. * - * Blank lines and lines which start with # are ignored. + * Blank lines and lines which start with # are ignored, + * except for the special control lines: + * #line-edit Signals the beginning of the line-editing + * keys section. + * #stop Stops command parsing in less; + * causes all default keys to be disabled. * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * - * The output file is a non-ascii file, consisting of - * zero or more byte sequences of the form: + * The output file is a non-ascii file, consisting of a header, + * one or more sections, and a trailer. + * Each section begins with a section header, a section length word + * and the section data. Normally there are three sections: + * CMD_SECTION Definition of command keys. + * EDIT_SECTION Definition of editing keys. + * END_SECTION A special section header, with no + * length word or section data. + * + * Section data consists of zero or more byte sequences of the form: * string <0> * or @@ -72,16 +90,19 @@ * If action is ORed with A_EXTRA, the action byte is followed * by the null-terminated "chars" string. + * + * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * */ #include "less.h" +#include "lesskey.h" #include "cmd.h" -char usertable[MAX_USERCMD]; - struct cmdname { char *cn_name; int cn_action; -} cmdnames[] = +}; + +struct cmdname cmdnames[] = { "back-bracket", A_B_BRACKET, @@ -137,8 +158,149 @@ }; +struct cmdname editnames[] = +{ + "back-complete", EC_B_COMPLETE, + "backspace", EC_BACKSPACE, + "delete", EC_DELETE, + "down", EC_DOWN, + "end", EC_END, + "expand", EC_EXPAND, + "forw-complete", EC_F_COMPLETE, + "home", EC_HOME, + "insert", EC_INSERT, + "invalid", EC_UINVALID, + "kill-line", EC_LINEKILL, + "left", EC_LEFT, + "literal", EC_LITERAL, + "right", EC_RIGHT, + "up", EC_UP, + "word-backspace", EC_W_BACKSPACE, + "word-delete", EC_W_DELETE, + "word-left", EC_W_RIGHT, + "word-right", EC_W_LEFT, + NULL, 0 +}; + +struct table +{ + struct cmdname *names; + char *pbuffer; + char buffer[MAX_USERCMD]; +}; + +struct table cmdtable; +struct table edittable; +struct table *currtable = &cmdtable; + +char fileheader[] = { + C0_LESSKEY_MAGIC, + C1_LESSKEY_MAGIC, + C2_LESSKEY_MAGIC, + C3_LESSKEY_MAGIC +}; +char filetrailer[] = { + C0_END_LESSKEY_MAGIC, + C1_END_LESSKEY_MAGIC, + C2_END_LESSKEY_MAGIC +}; +char cmdsection[] = { CMD_SECTION }; +char editsection[] = { EDIT_SECTION }; +char endsection[] = { END_SECTION }; + +char *infile = NULL; +char *outfile = NULL ; + +int linenum; +int errors; + +extern char version[]; + +/* + * Figure out the name of a default file (in the user's HOME directory). + */ + char * +homefile(filename) + char *filename; +{ + char *p; + char *pathname; + + p = getenv("HOME"); + if (p == NULL || *p == '\0') + { + fprintf(stderr, "cannot find $HOME - using current directory\n"); + pathname = calloc(strlen(filename) + 1, sizeof(char)); + strcpy(pathname, 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); + } + return (pathname); +} + +/* + * Parse command line arguments. + */ + void +parse_args(argc, argv) + int argc; + char **argv; +{ + outfile = NULL; + while (--argc > 0 && **(++argv) == '-' && argv[0][1] != '\0') + { + switch (argv[0][1]) + { + case 'o': + outfile = &argv[0][2]; + if (*outfile == '\0') + { + if (--argc <= 0) + usage(); + outfile = *(++argv); + } + break; + case 'V': + printf("lesskey version %s\n", version); + exit(0); + default: + usage(); + } + } + if (argc > 1) + usage(); + /* + * Open the input file, or use DEF_LESSKEYINFILE if none specified. + */ + if (argc > 0) + infile = *argv; + else + infile = homefile(DEF_LESSKEYINFILE); +} + +/* + * Initialize data structures. + */ + void +init_tables() +{ + cmdtable.names = cmdnames; + cmdtable.pbuffer = cmdtable.buffer; + + edittable.names = editnames; + edittable.pbuffer = edittable.buffer; +} + /* * Parse one character of a string. */ -int + int tchar(pp) char **pp; @@ -201,4 +363,143 @@ } +/* + * Skip leading spaces in a string. + */ + public char * +skipsp(s) + register char *s; +{ + while (*s == ' ' || *s == '\t') + s++; + return (s); +} + +/* + * Skip non-space characters in a string. + */ + public char * +skipnsp(s) + register char *s; +{ + while (*s != '\0' && *s != ' ' && *s != '\t') + s++; + return (s); +} + +/* + * Clean up an input line: + * strip off the trailing newline & any trailing # comment. + */ + char * +clean_line(s) + char *s; +{ + register int i; + + s = skipsp(s); + for (i = 0; s[i] != '\n' && s[i] != '\0'; i++) + if (s[i] == '#' && (i == 0 || s[i-1] != '\\')) + break; + s[i] = '\0'; + return (s); +} + +/* + * Add a byte to the output command table. + */ + void +add_cmd_char(c) + int c; +{ + if (currtable->pbuffer >= currtable->buffer + MAX_USERCMD) + { + error("too many commands"); + exit(1); + } + *(currtable->pbuffer)++ = c; +} + +/* + * See if we have a special "control" line. + */ + int +control_line(s) + char *s; +{ +#define PREFIX(str,pat) (strncmp(str,pat,strlen(pat)-1) == 0) + + if (PREFIX(s, "#line-edit")) + { + currtable = &edittable; + return (1); + } + if (PREFIX(s, "#command")) + { + currtable = &cmdtable; + return (1); + } + if (PREFIX(s, "#stop")) + { + add_cmd_char('\0'); + add_cmd_char(A_END_LIST); + return (1); + } + return (0); +} + +/* + * Output some bytes. + */ + void +fputbytes(fd, buf, len) + FILE *fd; + char *buf; + int len; +{ + while (len-- > 0) + { + fwrite(buf, sizeof(char), 1, fd); + buf++; + } +} + +/* + * Output an integer, in special KRADIX form. + */ + void +fputint(fd, val) + FILE *fd; + unsigned int val; +{ + char c; + + if (val >= KRADIX*KRADIX) + { + fprintf(stderr, "error: integer too big (%d > %d)\n", + val, KRADIX*KRADIX); + exit(1); + } + c = val % KRADIX; + fwrite(&c, sizeof(char), 1, fd); + c = val / KRADIX; + fwrite(&c, sizeof(char), 1, fd); +} + +/* + * Find an action, given the name of the action. + */ + int +findaction(actname) + char *actname; +{ + int i; + + for (i = 0; currtable->names[i].cn_name != NULL; i++) + if (strcmp(currtable->names[i].cn_name, actname) == 0) + return (currtable->names[i].cn_action); + error("unknown action"); + return (A_INVALID); +} + usage() { @@ -207,171 +508,133 @@ } -main(argc, argv) - int argc; - char *argv[]; + void +error(s) + char *s; { - char *p; /* {{ Can't be register since we use &p }} */ - register char *up; /* Pointer into usertable */ - FILE *desc; /* Description file (input) */ - FILE *out; /* Output file */ - int linenum; /* Line number in input file */ - char *currcmd; /* Start of current command string */ - int errors; - int i, j; - char line[200]; - char *outfile; + fprintf(stderr, "line %d: %s\n", linenum, s); + errors++; +} + + +/* + * Parse a line from the lesskey file. + */ + void +parse_line(line) + char *line; +{ + char *p; + int cmdlen; + char *actname; + int action; + int c; /* - * Process command line arguments. + * See if it is a control line. */ - outfile = NULL; - while (--argc > 0 && **(++argv) == '-') - { - switch (argv[0][1]) - { - case 'o': - outfile = &argv[0][2]; - if (*outfile == '\0') - { - if (--argc <= 0) - usage(); - outfile = *(++argv); - } - break; - default: - usage(); - } - } - if (argc > 1) - usage(); - + if (control_line(line)) + return; + /* + * Skip leading white space. + * Replace the final newline with a null byte. + * Ignore blank lines and comments. + */ + p = clean_line(line); + if (*p == '\0') + return; /* - * Open the input file, or use standard input if none specified. + * Parse the command string and store it in the current table. */ - if (argc > 0) + cmdlen = 0; + do { - if ((desc = fopen(*argv, "r")) == NULL) - { - perror(*argv); - exit(1); - } - } else - desc = stdin; + c = tchar(&p); + if (++cmdlen > MAX_CMDLEN) + error("command too long"); + else + add_cmd_char(c); + } while (*p != ' ' && *p != '\t' && *p != '\0'); + /* + * Terminate the command string with a null byte. + */ + add_cmd_char('\0'); /* - * Read the input file, one line at a time. - * Each line consists of a command string, - * followed by white space, followed by an action name. + * Skip white space between the command string + * and the action name. + * Terminate the action name with a null byte. */ - linenum = 0; - errors = 0; - up = usertable; - while (fgets(line, sizeof(line), desc) != NULL) + p = skipsp(p); + if (*p == '\0') { - ++linenum; - - /* - * Skip leading white space. - * Replace the final newline with a null byte. - * Ignore blank lines and comment lines. - */ - p = line; - while (*p == ' ' || *p == '\t') - ++p; - for (i = 0; p[i] != '\n' && p[i] != '\0'; i++) - if (p[i] == '#' && (i == 0 || p[i-1] != '\\')) - break; - p[i] = '\0'; - if (*p == '\0') - continue; - - /* - * Parse the command string and store it in the usertable. - */ - currcmd = up; - do - { - if (up >= usertable + MAX_USERCMD) - { - fprintf(stderr, "too many commands, line %d\n", - linenum); - exit(1); - } - if (up >= currcmd + MAX_CMDLEN) - { - fprintf(stderr, "command too long on line %d\n", - linenum); - errors++; - break; - } - - *up++ = tchar(&p); + error("missing action"); + return; + } + actname = p; + p = skipnsp(p); + c = *p; + *p = '\0'; - } while (*p != ' ' && *p != '\t' && *p != '\0'); + /* + * Parse the action name and store it in the current table. + */ + action = findaction(actname); + /* + * See if an extra string follows the action name. + */ + *p = c; + p = skipsp(p); + if (*p == '\0') + { + add_cmd_char(action); + } else + { /* - * Terminate the command string with a null byte. + * OR the special value A_EXTRA into the action byte. + * Put the extra string after the action byte. */ - *up++ = '\0'; + add_cmd_char(action | A_EXTRA); + while (*p != '\0') + add_cmd_char(tchar(&p)); + add_cmd_char('\0'); + } +} - /* - * Skip white space between the command string - * and the action name. - * Terminate the action name with a null byte if it - * is followed by whitespace or a # comment. - */ - if (*p == '\0') - { - fprintf(stderr, "missing whitespace on line %d\n", - linenum); - errors++; - continue; - } - while (*p == ' ' || *p == '\t') - ++p; - for (j = 0; p[j] != ' ' && p[j] != '\t' && - p[j] != '\0'; j++) - ; - p[j] = '\0'; +main(argc, argv) + int argc; + char *argv[]; +{ + FILE *desc; + FILE *out; + char line[200]; - /* - * Parse the action name and store it in the usertable. - */ - for (i = 0; cmdnames[i].cn_name != NULL; i++) - if (strcmp(cmdnames[i].cn_name, p) == 0) - break; - if (cmdnames[i].cn_name == NULL) - { - fprintf(stderr, "unknown action <%s> on line %d\n", - p, linenum); - errors++; - continue; - } - *up++ = cmdnames[i].cn_action; + /* + * Process command line arguments. + */ + parse_args(argc, argv); + init_tables(); - /* - * See if an extra string follows the action name. - */ - for (j = j+1; p[j] == ' ' || p[j] == '\t'; j++) - ; - p += j; - if (*p != '\0') - { - /* - * OR the special value A_EXTRA into the action byte. - * Put the extra string after the action byte. - */ - up[-1] |= A_EXTRA; - while (*p != '\0') - *up++ = tchar(&p); - *up++ = '\0'; - } + /* + * Open the input file. + */ + if (strcmp(infile, "-") == 0) + desc = stdin; + else if ((desc = fopen(infile, "r")) == NULL) + { + perror(infile); + exit(1); } - if (errors > 0) + /* + * Read and parse the input file, one line at a time. + */ + errors = 0; + linenum = 0; + while (fgets(line, sizeof(line), desc) != NULL) { - fprintf(stderr, "%d errors; no output produced\n", errors); - exit(1); + ++linenum; + parse_line(line); } @@ -380,28 +643,33 @@ * If no output file was specified, use "$HOME/.less" */ - if (outfile == NULL) + if (errors > 0) { - p = getenv("HOME"); - if (p == NULL || *p == '\0') - { - fprintf(stderr, "cannot find $HOME - using current directory\n"); - strcpy(line, LESSKEYFILE); - } else - { - strcpy(line, p); -#if MSOFTC - strcat(line, "\\"); -#else - strcat(line, "/"); -#endif - strcat(line, LESSKEYFILE); - } - outfile = line; + fprintf(stderr, "%d errors; no output produced\n", errors); + exit(1); } + + if (outfile == NULL) + outfile = homefile(LESSKEYFILE); if ((out = fopen(outfile, "w")) == NULL) + { perror(outfile); - else - fwrite((char *)usertable, 1, up-usertable, out); + exit(1); + } + + /* File header */ + fputbytes(out, fileheader, sizeof(fileheader)); + + /* Command key section */ + fputbytes(out, cmdsection, sizeof(cmdsection)); + fputint(out, cmdtable.pbuffer - cmdtable.buffer); + fputbytes(out, (char *)cmdtable.buffer, cmdtable.pbuffer-cmdtable.buffer); + /* Edit key section */ + fputbytes(out, editsection, sizeof(editsection)); + fputint(out, edittable.pbuffer - edittable.buffer); + fputbytes(out, (char *)edittable.buffer, edittable.pbuffer-edittable.buffer); + + /* File trailer */ + fputbytes(out, endsection, sizeof(endsection)); + fputbytes(out, filetrailer, sizeof(filetrailer)); exit(0); } - diff --exclude=*,v -r -U2 --entire less-237/lesskey.h less-252/lesskey.h --- less-237/lesskey.h Wed Dec 31 19:00:00 1969 +++ less-252/lesskey.h Thu Oct 13 02:47:53 1994 @@ -0,0 +1,28 @@ +/* + * Format of a lesskey file: + * + * LESSKEY_MAGIC (4 bytes) + * sections... + * END_LESSKEY_MAGIC (4 bytes) + * + * Each section is: + * + * section_MAGIC (1 byte) + * section_length (2 bytes) + * key table (section_length bytes) + */ +#define C0_LESSKEY_MAGIC '\0' +#define C1_LESSKEY_MAGIC 'M' +#define C2_LESSKEY_MAGIC '+' +#define C3_LESSKEY_MAGIC 'G' + +#define CMD_SECTION 'c' +#define EDIT_SECTION 'e' +#define END_SECTION 'x' + +#define C0_END_LESSKEY_MAGIC 'E' +#define C1_END_LESSKEY_MAGIC 'n' +#define C2_END_LESSKEY_MAGIC 'd' + +/* */ +#define KRADIX 64 diff --exclude=*,v -r -U2 --entire less-237/lesskey.man less-252/lesskey.man --- less-237/lesskey.man Fri Sep 30 13:08:31 1994 +++ less-252/lesskey.man Wed Nov 16 14:24:22 1994 @@ -11,12 +11,15 @@ SYNOPSIS lesskey [-o output] [input] + lesskey -V DESCRIPTION _L_e_s_s_k_e_y is used to specify a set of key bindings to be used by _l_e_s_s. The input file is a text file which describes the - key bindings, and the output file is a binary file which is - used by _l_e_s_s. If no input file is specified, standard input - is used. If no output file is specified, $HOME/.less is - used. + key bindings, If the input file is "-", standard input is + read. If no input file is specified, $HOME/.lesskey is + read. The output file is a binary file which is used by + _l_e_s_s. If no output file is specified, $HOME/.less is writ- + ten. If the output file already exists, _l_e_s_s_k_e_y will + overwrite it. The input file consists of lines of the form: @@ -29,5 +32,5 @@ sequence of up to 15 keys. The _a_c_t_i_o_n is the name of the less action, from the list below. The characters in the - _s_t_r_i_n_g may appear literally, or be prefixed by a carat to + _s_t_r_i_n_g may appear literally, or be prefixed by a caret to indicate a control key. A backslash followed by one to three octal digits may be used to specify a character by its @@ -36,19 +39,17 @@ tively. A backslash followed by any other character indi- cates that character is to be taken literally. Characters - which must be preceded by backslash include carat, space, + which must be preceded by backslash include caret, space, tab and the backslash itself. Blank lines and lines which start with a pound sign (#) are ignored. - An action may be followed by an extra string. This string - is parsed after the command is entered, just as if it were - entered on the command line. This feature can be used in - certain cases to extend the functionality of a command. For - example, these entries would create a pair of commands to - turn on/off line numbers using _v_i syntax: - - :set\ nu toggle-option -N - :set\ nonu toggle-option +N + An action may be followed by an "extra" string. When such a + command is entered while running _l_e_s_s, the action is per- + formed, and then the extra string is parsed, just as if it + were typed in to _l_e_s_s. This feature can be used in certain + cases to extend the functionality of a command. For exam- + ple, see the "{" and ":t" commands in the example below. - See also the ":t" command in the example below. + The -V flag causes _l_e_s_s_k_e_y to print its version number and + immediately exit. Other flags and arguments are ignored. @@ -57,5 +58,4 @@ mand keys used by less: - \r forw-line @@ -72,4 +72,5 @@ + \r forw-line \n forw-line e forw-line @@ -123,5 +124,4 @@ :f status / forw-search - ? back-search @@ -138,4 +138,5 @@ + ? back-search \e/ forw-search * \e? back-search * @@ -170,20 +171,83 @@ ZZ quit + +PRECEDENCE Commands specified by _l_e_s_s_k_e_y take precedence over the default commands. A default command key may be disabled by - including it in the key file with the action "invalid". A - key may be defined to do nothing by using the action "noac- - tion". This is similar to "invalid", but _l_e_s_s will give an - error beep for an "invalid" command, but not for a "noac- - tion" command. + including it in the input file with the action "invalid". + Alternatively, a key may be defined to do nothing by using + the action "noaction". "noaction" is similar to "invalid", + but _l_e_s_s will give an error beep for an "invalid" command, + but not for a "noaction" command. In addition, ALL default + commands may be disabled by adding this control line to the + input file: + + #stop + + This will cause all default commands to be ignored. The + #stop line should be the last line in that section of the + file. (Another section, introduced by #line-edit, may fol- + low the #stop line.) -SEE ALSO - less(1) -WARNINGS - If you already have a $HOME/.less file, running lesskey will - overwrite it. + 3 + + + + + + +LESSKEY(1) USER COMMANDS LESSKEY(1) + + + + Be aware that #stop can be dangerous. Since all default com- + mands are disabled, you must provide sufficient commands + before the #stop line to enable all necessary actions. For + example, failure to provide a "quit" command can lead to + frustration. + + +LINE EDITING + New key bindings may be specified for the line editing com- + mands, in a manner similar to the way key bindings for ordi- + nary commands are specified. This control line marks the + beginning of a section of line-editing commands: + + #line-edit + + Following this line is a list of keys and actions, one per + line as in the example below. + + +EXAMPLE + The following input file describes the set of default line- + editing keys used by less: + + #line-edit + \t forw-complete + \17 back-complete + \e\t back-complete + \14 expand + ^V literal + ^A literal + \el right + \eh left + \eb word-left + \ew word-right + \ei insert + \ex delete + \e\b word-backspace + \e0 home + \e$ end + \ek up + \ej down + + + +SEE ALSO + less(1) @@ -193,5 +257,7 @@ - 3 + + + 4 diff --exclude=*,v -r -U2 --entire less-237/lesskey.nro less-252/lesskey.nro --- less-237/lesskey.nro Fri Sep 30 13:07:54 1994 +++ less-252/lesskey.nro Wed Nov 16 14:24:14 1994 @@ -4,4 +4,6 @@ .SH SYNOPSIS .B "lesskey [-o output] [input]" +.br +.B "lesskey -V" .SH DESCRIPTION .I Lesskey @@ -9,8 +11,12 @@ .I less. The input file is a text file which describes the key bindings, -and the output file is a binary file which is used by +If the input file is "-", standard input is read. +If no input file is specified, $HOME/.lesskey is read. +The output file is a binary file which is used by .I less. -If no input file is specified, standard input is used. -If no output file is specified, $HOME/.less is used. +If no output file is specified, $HOME/.less is written. +If the output file already exists, +.I lesskey +will overwrite it. .PP The input file consists of lines of the form: @@ -23,5 +29,5 @@ The \fIaction\fP is the name of the less action, from the list below. The characters in the \fIstring\fP may appear literally, or be -prefixed by a carat to indicate a control key. +prefixed by a caret to indicate a control key. A backslash followed by one to three octal digits may be used to specify a character by its octal value. @@ -31,23 +37,21 @@ to be taken literally. Characters which must be preceded by backslash include -carat, space, tab and the backslash itself. +caret, space, tab and the backslash itself. Blank lines and lines which start with a pound sign (#) are ignored. .PP -An action may be followed by an extra string. -This string is parsed after the command is entered, -just as if it were entered on the command line. +An action may be followed by an "extra" string. +When such a command is entered while running +.I less, +the action is performed, and then the extra +string is parsed, just as if it were typed in to +.I less. This feature can be used in certain cases to extend the functionality of a command. -For example, these entries would create a pair of commands -to turn on/off line numbers using -.I vi -syntax: -.sp -.nf - :set\\ nu toggle-option -N - :set\\ nonu toggle-option +N -.fi -.sp -See also the ":t" command in the example below. +For example, see the "{" and ":t" commands in the example below. +.PP +The -V flag causes +.I lesskey +to print its version number and immediately exit. +Other flags and arguments are ignored. .SH EXAMPLE @@ -142,20 +146,70 @@ .fi .sp +.SH PRECEDENCE Commands specified by .I lesskey take precedence over the default commands. A default command key may be disabled by including it in the -key file with the action "invalid". -A key may be defined to do nothing by using the action "noaction". -This is similar to "invalid", but +input file with the action "invalid". +Alternatively, a key may be defined +to do nothing by using the action "noaction". +"noaction" is similar to "invalid", but .I less will give an error beep for an "invalid" command, but not for a "noaction" command. +In addition, ALL default commands may be disabled by +adding this control line to the input file: +.sp +#stop +.sp +This will cause all default commands to be ignored. +The #stop line should be the last line in that section of the file. +(Another section, introduced by #line-edit, may follow the #stop line.) +.PP +Be aware that #stop can be dangerous. +Since all default commands are disabled, +you must provide sufficient commands before the #stop line +to enable all necessary actions. +For example, failure to provide a "quit" command can lead to frustration. + +.SH "LINE EDITING" +New key bindings may be specified for the line editing commands, +in a manner similar to the way key bindings for +ordinary commands are specified. +This control line marks the beginning of a section of line-editing commands: +.sp +#line-edit +.sp +Following this line is a list of keys and actions, +one per line as in the example below. + +.SH EXAMPLE +The following input file describes the set of +default line-editing keys used by less: +.sp +.nf + #line-edit + \et forw-complete + \e17 back-complete + \ee\et back-complete + \e14 expand + ^V literal + ^A literal + \eel right + \eeh left + \eeb word-left + \eew word-right + \eei insert + \eex delete + \ee\eb word-backspace + \ee0 home + \ee$ end + \eek up + \eej down +.fi +.sp .SH "SEE ALSO" less(1) - -.SH "WARNINGS" -If you already have a $HOME/.less file, running lesskey will overwrite it. .SH COPYRIGHT diff --exclude=*,v -r -U2 --entire less-237/line.c less-252/line.c --- less-237/line.c Thu Sep 29 15:27:07 1994 +++ less-252/line.c Tue Oct 18 02:19:53 1994 @@ -41,4 +41,5 @@ static int column; /* Printable length, accounting for backspaces, etc. */ +static int lno_indent; /* Number of chars used for line number */ static int overstrike; /* Next char should overstrike previous char */ static int is_null_line; /* There is no current line */ @@ -70,4 +71,5 @@ overstrike = 0; is_null_line = 0; + lno_indent = 0; pendc = '\0'; } @@ -115,7 +117,8 @@ { linebuf[curr] = ' '; - attr[curr++] = 0; + attr[curr++] = AT_NORMAL; column++; } while ((column % tabstop) != 0); + lno_indent = column; } @@ -420,5 +423,6 @@ { linebuf[curr] = '\0'; - hlsearch(linebuf, attr, AT_STANDOUT); + hlsearch(linebuf + lno_indent, attr + lno_indent, + AT_STANDOUT); } } diff --exclude=*,v -r -U2 --entire less-237/main.c less-252/main.c --- less-237/main.c Wed Sep 21 17:05:21 1994 +++ less-252/main.c Sat Oct 15 03:16:47 1994 @@ -108,10 +108,4 @@ } -#if USERFILE - /* - * Try to use the lesskey file "$HOME/.less". - */ - add_hometable(); -#endif #if EDITOR editor = getenv("EDITOR"); @@ -177,10 +171,15 @@ 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(); - cmd_init(); - init_signals(1); diff --exclude=*,v -r -U2 --entire less-237/optfunc.c less-252/optfunc.c --- less-237/optfunc.c Wed Sep 21 17:05:31 1994 +++ less-252/optfunc.c Sun Nov 6 18:56:36 1994 @@ -187,5 +187,5 @@ { case INIT: - if (add_cmdtable(s)) + if (lesskey(s)) { parg.p_string = s; @@ -369,4 +369,25 @@ case QUERY: case INIT: + break; + } +} + +/* + * Handler for the -V option. + */ + /*ARGSUSED*/ + public void +opt__V(type, s) + int type; + char *s; +{ + switch (type) + { + case TOGGLE: + case QUERY: + case INIT: + dispversion(); + if (type == INIT) + quit(0); break; } diff --exclude=*,v -r -U2 --entire less-237/opttbl.c less-252/opttbl.c --- less-237/opttbl.c Fri Sep 30 14:36:29 1994 +++ less-252/opttbl.c Thu Oct 27 17:19:38 1994 @@ -206,4 +206,7 @@ "Print backspace as ^H" }, + { 'V', NOVAR, 0, NULL, opt__V, + NULL, NULL, NULL + }, { 'w', BOOL|REPAINT, 1, &twiddle, NULL, "Display nothing for lines after end-of-file", diff --exclude=*,v -r -U2 --entire less-237/screen.c less-252/screen.c --- less-237/screen.c Fri Sep 23 13:51:39 1994 +++ less-252/screen.c Wed Nov 9 12:41:22 1994 @@ -170,5 +170,62 @@ save_term = s; #if HAVE_OSPEED - ospeed = cfgetospeed(&s); + switch (cfgetospeed(&s)) + { +#ifdef B0 + case B0: ospeed = 0; break; +#endif +#ifdef B50 + case B50: ospeed = 1; break; +#endif +#ifdef B75 + case B75: ospeed = 2; break; +#endif +#ifdef B110 + case B110: ospeed = 3; break; +#endif +#ifdef B134 + case B134: ospeed = 4; break; +#endif +#ifdef B150 + case B150: ospeed = 5; break; +#endif +#ifdef B200 + case B200: ospeed = 6; break; +#endif +#ifdef B300 + case B300: ospeed = 7; break; +#endif +#ifdef B600 + case B600: ospeed = 8; break; +#endif +#ifdef B1200 + case B1200: ospeed = 9; break; +#endif +#ifdef B1800 + case B1800: ospeed = 10; break; +#endif +#ifdef B2400 + case B2400: ospeed = 11; break; +#endif +#ifdef B4800 + case B4800: ospeed = 12; break; +#endif +#ifdef B9600 + case B9600: ospeed = 13; break; +#endif +#ifdef EXTA + case EXTA: ospeed = 14; break; +#endif +#ifdef EXTB + case EXTB: ospeed = 15; break; +#endif +#ifdef B57600 + case B57600: ospeed = 16; break; +#endif +#ifdef B115200 + case B115200: ospeed = 17; break; +#endif + default: ; + } #endif erase_char = s.c_cc[VERASE]; @@ -392,34 +449,9 @@ /* - * Static table of command editting characters. - * These don't depend on the termcap. + * Take care of the "variable" keys. + * Certain keys send escape sequences which differ on different terminals + * (such as the arrow keys, INSERT, DELETE, etc.) + * Construct the commands based on these keys. */ -char st_edittable[] = -{ - '\t',0, EC_F_COMPLETE, /* TAB */ - '\17',0, EC_B_COMPLETE, /* BACKTAB */ - '\14',0, EC_EXPAND, /* CTRL-L */ - '\33','l',0, EC_RIGHT, /* ESC l */ - '\33','h',0, EC_LEFT, /* ESC h */ - '\33','b',0, EC_W_LEFT, /* ESC b */ - '\33','w',0, EC_W_RIGHT, /* ESC w */ - '\33','i',0, EC_INSERT, /* ESC i */ - '\33','x',0, EC_DELETE, /* ESC x */ - '\33','X',0, EC_W_DELETE, /* ESC X */ - '\33','\b',0, EC_W_BACKSPACE, /* ESC BACKSPACE */ - '\33','0',0, EC_HOME, /* ESC 0 */ - '\33','$',0, EC_END, /* ESC $ */ - '\33','k',0, EC_UP, /* ESC k */ - '\33','j',0, EC_DOWN, /* ESC j */ - '\33','\t',0, EC_B_COMPLETE, /* ESC TAB */ - 0 -}; - -char edittable[1024]; -int sz_edittable = 0; - -char kcmdtable[400]; -int sz_kcmdtable = 0; - public void get_editkeys() @@ -429,55 +461,71 @@ char tbuf[40]; -#define add_table(str,action,tbl,sz) { \ + static char kfcmdtable[400]; + int sz_kfcmdtable = 0; + static char kecmdtable[400]; + int sz_kecmdtable = 0; + +#define put_cmd(str,action,tbl,sz) { \ strcpy(tbl+sz, str); \ sz += strlen(str) + 1; \ tbl[sz++] = action; } - +#define put_esc_cmd(str,action,tbl,sz) { \ + tbl[sz++] = ESC; \ + put_cmd(str,action,tbl,sz); } + +#define put_fcmd(str,action) put_cmd(str,action,kfcmdtable,sz_kfcmdtable) +#define put_ecmd(str,action) put_cmd(str,action,kecmdtable,sz_kecmdtable) +#define put_esc_fcmd(str,action) put_esc_cmd(str,action,kfcmdtable,sz_kfcmdtable) +#define put_esc_ecmd(str,action) put_esc_cmd(str,action,kecmdtable,sz_kecmdtable) + + /* + * Look at some interesting keys and see what strings they send. + * Create commands (both command keys and line-edit keys). + */ + /* RIGHT ARROW */ - sp = tbuf+1; + sp = tbuf; if ((s = tgetstr("kr", &sp)) != NULL) { - add_table(s, EC_RIGHT, edittable, sz_edittable); - *--s = ESC; - add_table(s, EC_W_RIGHT, edittable, sz_edittable); + put_ecmd(s, EC_RIGHT); + put_esc_ecmd(s, EC_W_RIGHT); } /* LEFT ARROW */ - sp = tbuf+1; + sp = tbuf; if ((s = tgetstr("kl", &sp)) != NULL) { - add_table(s, EC_LEFT, edittable, sz_edittable); - *--s = ESC; - add_table(s, EC_W_LEFT, edittable, sz_edittable); + put_ecmd(s, EC_LEFT); + put_esc_ecmd(s, EC_W_LEFT); } /* UP ARROW */ - s = tbuf; + sp = tbuf; if ((s = tgetstr("ku", &sp)) != NULL) { - add_table(s, EC_UP, edittable, sz_edittable); - add_table(s, A_B_LINE, kcmdtable, sz_kcmdtable); + put_ecmd(s, EC_UP); + put_fcmd(s, A_B_LINE); } /* DOWN ARROW */ - s = tbuf; + sp = tbuf; if ((s = tgetstr("kd", &sp)) != NULL) { - add_table(s, EC_DOWN, edittable, sz_edittable); - add_table(s, A_F_LINE, kcmdtable, sz_kcmdtable); + put_ecmd(s, EC_DOWN); + put_fcmd(s, A_F_LINE); } /* PAGE UP */ - s = tbuf; + sp = tbuf; if ((s = tgetstr("kP", &sp)) != NULL) { - add_table(s, A_B_SCREEN, kcmdtable, sz_kcmdtable); + put_fcmd(s, A_B_SCREEN); } /* PAGE DOWN */ - s = tbuf; + sp = tbuf; if ((s = tgetstr("kN", &sp)) != NULL) { - add_table(s, A_F_SCREEN, kcmdtable, sz_kcmdtable); + put_fcmd(s, A_F_SCREEN); } @@ -486,5 +534,5 @@ if ((s = tgetstr("kh", &sp)) != NULL) { - add_table(s, EC_HOME, edittable, sz_edittable); + put_ecmd(s, EC_HOME); } @@ -493,9 +541,9 @@ if ((s = tgetstr("@7", &sp)) != NULL) { - add_table(s, EC_END, edittable, sz_edittable); + put_ecmd(s, EC_END); } /* DELETE */ - sp = tbuf+1; + sp = tbuf; if ((s = tgetstr("kD", &sp)) == NULL) { @@ -505,7 +553,6 @@ s = tbuf+1; } - add_table(s, EC_DELETE, edittable, sz_edittable); - *--s = ESC; - add_table(s, EC_W_DELETE, edittable, sz_edittable); + put_ecmd(s, EC_DELETE); + put_esc_ecmd(s, EC_W_DELETE); /* BACKSPACE */ @@ -513,11 +560,11 @@ tbuf[1] = erase_char; tbuf[2] = '\0'; - add_table(tbuf, EC_W_BACKSPACE, edittable, sz_edittable); + put_ecmd(tbuf, EC_W_BACKSPACE); /* - * Append the static edittable. + * Register the two tables. */ - memcpy(edittable + sz_edittable, st_edittable, sizeof(st_edittable)-1); - sz_edittable += sizeof(st_edittable)-1; + add_fcmd_table(kfcmdtable, sz_kfcmdtable); + add_ecmd_table(kecmdtable, sz_kecmdtable); } diff --exclude=*,v -r -U2 --entire less-237/version.c less-252/version.c --- less-237/version.c Fri Sep 30 14:37:51 1994 +++ less-252/version.c Wed Nov 16 14:23:28 1994 @@ -430,5 +430,29 @@ * (Fix for Solaris; thanks to Frank Kaefer) * v237: Use system isupper() etc if provided. 9/30/94 + * Posted to prep.ai.mit.edu + * ----------------------------------------------------------------- + * v238: Make binary non-blinking if LESSBINFMT 10/6/94 + * is set to a string without a *. + * v239: Don't let delimit_word run back past 10/7/94 + * beginning of cmdbuf. + * v240: Don't write into termcap buffer. 10/10/94 + * (Thanks to Benoit Speckel) + * v241: New lesskey file format. 10/13/94 + * Don't expand filenames in search command. + * v242: Allow lesskey specification of "literal". 10/14/94 + * v243: Add #stop command to lesskey. 10/14/94 + * v244: Add -f flag to lesskey. 10/16/94 + * v245: Allow TAB_COMPLETE_FILENAME to be undefd. 10/25/94 + * v246: Move help file to /usr/local/share. 10/27/94 + * v247: Add -V option. 10/27/94 + * v248: Add -V option to lesskey. 11/5/94 + * v249: Remove -f flag from lesskey; default 11/5/94 + * input file is ~/.lesskey.in, not stdin. + * v250: Lesskey input file "-" means stdin. 11/7/94 + * v251: Convert cfgetospeed result to ospeed. 11/9/94 + * (Thanks to Andrew Chernov) + * v252: Change default lesskey input file from 11/16/94 + * .lesskey.in to .lesskey. */ -char version[] = "@(#) less version 237"; +char version[] = "252";