diff options
| author | Xin LI <delphij@FreeBSD.org> | 2026-02-02 20:50:35 +0000 |
|---|---|---|
| committer | Xin LI <delphij@FreeBSD.org> | 2026-02-02 20:50:35 +0000 |
| commit | dafba19e42e78cd3d7c9264ece49ddd3d7d70da5 (patch) | |
| tree | 38e7418d9ac76555890d8f712c0767e785c31660 | |
| parent | 69f535564125f6c59b02616c806ab7fcf9563878 (diff) | |
| parent | c408e7413bcfb3bc52ed8b36e87e5be847dcb950 (diff) | |
MFV less v691
Relnotes: yes
MFC after: 2 weeks
49 files changed, 2651 insertions, 1384 deletions
diff --git a/contrib/less/NEWS b/contrib/less/NEWS index 442fe21e406a..11022fcb5bf1 100644 --- a/contrib/less/NEWS +++ b/contrib/less/NEWS @@ -11,6 +11,68 @@ ====================================================================== + Major changes between "less" versions 685 and 691 + +* Add --autosave option (github #678). + +* Add ESC-f command (github #680). + +* Add column number to long prompt and = message. + +* Add prompt prototype sequences %C, %W, %Q and ?Q (github #685). + +* Map keypad keys, and use terminfo rather than termcap since keypad + definitions don't exist in termcap (github #650). + +* Change HOME key to scroll fully left and END key to scroll fully right. + Add shift-HOME and ctrl-HOME to scroll left and jump to top, and + add shift-END and ctrl-END to scroll right and jump to end (github #658). + +* Add LESSNOCONFIG environment variable. + +* Add --without-termlib to configure (github #701). + +* When setting line number colors (-DN), don't force bold attribute. + To set bold, you must append "d" or "*" to the color string (github #684). + +* While waiting for file data, only ^C or ^X will interrupt, not any command. + This reverts to behavior that existed before less-670 (github #700). + +* When --save-marks is not used, retain any marks saved in the history file + (github #662). + +* Defer sending the terminal init string until the first char is read + from the input file (github #682). + +* Make SIGHUP do an orderly exit like SIGTERM. + +* Implement modeline handling in Windows build. + +* Fix bugs and improve behavior of screen resize on Windows. + +* Fix bug when entering search modifier key at start of non-empty + search string (github #668). + +* Fix bug repainting screen with --form-feed (github #672). + +* Fix bugs passing invalid negative values to some command line + options (github #675). + +* Fix incorrect display of Lit indicator (github #670). + +* Fix incorrect display when returning to a mark after resizeing window + (github #681). + +* Fix bug using --pattern with --incsearch (github #696). + +* Disallow mouse click to open OSC8 link in SECURE mode (github #676). + +* Add SECURE_COMPILE environment variable for Windows builds. + +* Update Unicode tables. + +====================================================================== + Major changes between "less" versions 679 and 685 * Add --cmd option (github #624). diff --git a/contrib/less/README b/contrib/less/README index 4bfdc5e5a67f..a6954eb67c1e 100644 --- a/contrib/less/README +++ b/contrib/less/README @@ -84,7 +84,7 @@ INSTALLATION (Unix & Linux systems only): Makefile now. Take particular notice of the list of "terminal" libraries in the LIBS definition in the Makefile; these may need to be edited. The terminal libraries will be some subset of - -lncurses -lcurses -ltermcap -ltermlib + -ltinfo -ltinfow -lxcurses -lncursesw -lncurses -lcurses -ltermcap -ltermlib If you wish, you may edit defines.h to remove some optional features. If you choose not to include some features in your version, you may @@ -118,6 +118,29 @@ programmers", not "persons who attempt to circumvent computer security".) ======================================================================= +INSTALLATION (Windows-95, Windows-98 and Windows-NT systems only, + with Microsoft Visual C++, mingw, or Borland C) + +1. Move the distributed source to its own directory. + +2. If you wish, you may edit defines.wn 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 help.c + to remove the descriptions of the features which you are removing. + +3. If you are using Microsoft Visual C++, run "nmake -f Makefile.wnm". + If you are using mingw, run "make -f Makefile.wng". + If you are using Borland C, run "make -f Makefile.wnb". + + If the environment variable SECURE_COMPILE is to 1 during the make, + a "secure" version of less is built, with some features disabled. + +4. If the make succeeds, it will generate the programs "less.exe" and + "lesskey.exe" in your current directory. Test the generated programs. + + + +======================================================================= INSTALLATION (MS-DOS systems only, with Microsoft C, Borland C, or DJGPP) @@ -157,34 +180,6 @@ INSTALLATION (MS-DOS systems only, ======================================================================= -INSTALLATION (Windows-95, Windows-98 and Windows-NT systems only, - with Borland C or Microsoft Visual C++) - -1. Move the distributed source to its own directory. - -2. If you are using Borland C, rename Makefile.wnb to Makefile. - If you are using Microsoft Visual C++, rename Makefile.wnm to Makefile. - -3. Check the Makefile to make sure the definitions look ok. - -4. If you wish, you may edit defines.wn 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 help.c - 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 the programs "less.exe" and - "lesskey.exe" in your current directory. Test the generated programs. - -7. When satisfied that it works, if you wish to install it - in a public place, type "make install". - See step 6 of the Unix installation instructions for details - on how to change the default installation directories. - - - -======================================================================= INSTALLATION (OS/2 systems only, with EMX C) @@ -245,10 +240,3 @@ INSTALLATION (OS-9 systems only, See step 6 of the Unix installation instructions for details on how to change the default installation directories. -======================================================================= -ACKNOWLEDGMENTS: - Some versions of the less distribution are packaged using - Info-ZIP's compression utility. - Info-ZIP's software is free and can be obtained as source - code or executables from various anonymous-ftp sites, - including ftp.uu.net:/pub/archiving/zip. diff --git a/contrib/less/ch.c b/contrib/less/ch.c index fb7572e7f88a..a0796bd5cd63 100644 --- a/contrib/less/ch.c +++ b/contrib/less/ch.c @@ -22,7 +22,7 @@ typedef POSITION BLOCKNUM; -public int ignore_eoi; +public lbool ignore_eoi = FALSE; /* * Pool of buffers holding the most recently used blocks of the input file. @@ -883,13 +883,13 @@ public void ch_init(int f, int flags, ssize_t nread) */ ch_fsize = (flags & CH_HELPFILE) ? size_helpdata : filesize(ch_file); - /* - * This is a kludge to workaround a Linux kernel bug: files in some - * pseudo filesystems like /proc and tracefs have a size of 0 according - * to fstat() but have readable data. - */ if (ch_fsize == 0 && nread > 0) { + /* + * This is a kludge to workaround a Linux kernel bug: files in some + * pseudo filesystems like /proc and tracefs have a size of 0 according + * to fstat() but have readable data. + */ ch_flags |= CH_NOTRUSTSIZE; } diff --git a/contrib/less/charset.c b/contrib/less/charset.c index 0f62739bc88d..de1c27bdc61e 100644 --- a/contrib/less/charset.c +++ b/contrib/less/charset.c @@ -202,20 +202,20 @@ static void ichardef_utf(constant char *s) switch (*s++) { case 'b': - xbuf_add_data(&user_ubin_array, (unsigned char *) &range, sizeof(range)); + xbuf_add_data(&user_ubin_array, &range, sizeof(range)); break; case 'c': - xbuf_add_data(&user_compose_array, (unsigned char *) &range, sizeof(range)); + xbuf_add_data(&user_compose_array, &range, sizeof(range)); break; case 'd': - xbuf_add_data(&user_omit_array, (unsigned char *) &range, sizeof(range)); + xbuf_add_data(&user_omit_array, &range, sizeof(range)); break; case 'w': - xbuf_add_data(&user_wide_array, (unsigned char *) &range, sizeof(range)); - xbuf_add_data(&user_prt_array, (unsigned char *) &range, sizeof(range)); + xbuf_add_data(&user_wide_array, &range, sizeof(range)); + xbuf_add_data(&user_prt_array, &range, sizeof(range)); break; case 'p': case '.': - xbuf_add_data(&user_prt_array, (unsigned char *) &range, sizeof(range)); + xbuf_add_data(&user_prt_array, &range, sizeof(range)); break; case '\0': s--; @@ -435,7 +435,6 @@ static void set_charset(void) #endif #endif -#if HAVE_STRSTR /* * Check whether LC_ALL, LC_CTYPE or LANG look like UTF-8 is used. */ @@ -448,7 +447,6 @@ static void set_charset(void) if (icharset("utf-8", 1)) return; } -#endif #if HAVE_LOCALE /* diff --git a/contrib/less/cmd.h b/contrib/less/cmd.h index 07c57b111aee..570ab167b2b7 100644 --- a/contrib/less/cmd.h +++ b/contrib/less/cmd.h @@ -86,6 +86,7 @@ #define A_OSC8_JUMP 74 #define A_START_PASTE 75 /* must not overlap EC_* */ #define A_END_PASTE 76 /* must not overlap EC_* */ +#define A_F_FOREVER_BELL 77 /* These values must not conflict with any A_* or EC_* value. */ #define A_INVALID 100 @@ -155,4 +156,25 @@ #define SK_BACKTAB 15 #define SK_CTL_BACKSPACE 16 #define SK_BACKSPACE 17 +#define SK_PAD_U 18 +#define SK_PAD_D 19 +#define SK_PAD_R 20 +#define SK_PAD_L 21 +#define SK_PAD_UR 22 +#define SK_PAD_UL 23 +#define SK_PAD_DR 24 +#define SK_PAD_DL 25 +#define SK_PAD_CENTER 26 +#define SK_PAD_STAR 27 +#define SK_PAD_SLASH 28 +#define SK_PAD_DASH 29 +#define SK_PAD_PLUS 30 +#define SK_PAD_DOT 31 +#define SK_PAD_COMMA 32 +#define SK_PAD_ZERO 33 +#define SK_SHIFT_HOME 34 +#define SK_SHIFT_END 35 +#define SK_CTL_HOME 36 +#define SK_CTL_END 37 + #define SK_CONTROL_K 40 diff --git a/contrib/less/cmdbuf.c b/contrib/less/cmdbuf.c index f2963cf4c9da..6869045f6886 100644 --- a/contrib/less/cmdbuf.c +++ b/contrib/less/cmdbuf.c @@ -23,7 +23,7 @@ extern int sc_width; extern int utf_mode; extern int no_hist_dups; -extern int marks_modified; +extern lbool marks_modified; extern int no_paste; public lbool pasting = FALSE; @@ -35,6 +35,9 @@ static int cmd_offset; /* Index into cmdbuf of first displayed char */ static lbool literal; /* Next input char should not be interpreted */ static size_t updown_match; /* Prefix length in up/down movement */ static lbool have_updown_match = FALSE; +#if LESS_INSERT_MODE +static lbool insert_mode = TRUE; +#endif static int cmd_complete(int action); /* @@ -189,7 +192,7 @@ public int len_cmdbuf(void) */ public lbool cmdbuf_empty(void) { - return cp == cmdbuf && cmd_mbc_buf_len == 0; + return cmdbuf[0] == '\0' && cmd_mbc_buf_len == 0; } /* @@ -455,39 +458,6 @@ static int cmd_left(void) } /* - * Insert a char into the command buffer, at the current position. - */ -static int cmd_ichar(constant char *cs, size_t clen) -{ - char *s; - - if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1) - { - /* No room in the command buffer for another char. */ - bell(); - return (CC_ERROR); - } - - /* - * Make room for the new character (shift the tail of the buffer right). - */ - for (s = &cmdbuf[strlen(cmdbuf)]; s >= cp; s--) - s[clen] = s[0]; - /* - * Insert the character into the buffer. - */ - for (s = cp; s < cp + clen; s++) - *s = *cs++; - /* - * Reprint the tail of the line from the inserted char. - */ - have_updown_match = FALSE; - cmd_repaint(cp); - cmd_right(); - return (CC_OK); -} - -/* * Backspace in the command buffer. * Delete the char to the left of the cursor. */ @@ -502,7 +472,7 @@ static int cmd_erase(void) * Backspace past beginning of the buffer: * this usually means abort the command. */ - return (CC_QUIT); + return CC_QUIT; } /* * Move cursor left (to the char being erased). @@ -532,7 +502,7 @@ static int cmd_erase(void) * to abort the current command, if CF_QUIT_ON_ERASE is set. */ if ((curr_cmdflags & CF_QUIT_ON_ERASE) && cp == cmdbuf && *cp == '\0') - return (CC_QUIT); + return CC_QUIT; return (CC_OK); } @@ -555,6 +525,43 @@ static int cmd_delete(void) } /* + * Insert a char into the command buffer, at the current position. + */ +static int cmd_ichar(constant char *cs, size_t clen) +{ + char *s; + + if (strlen(cmdbuf) + clen >= sizeof(cmdbuf)-1) + { + /* No room in the command buffer for another char. */ + lbell(); + return (CC_ERROR); + } + +#if LESS_INSERT_MODE + if (!insert_mode) + cmd_delete(); +#endif + /* + * Make room for the new character (shift the tail of the buffer right). + */ + for (s = &cmdbuf[strlen(cmdbuf)]; s >= cp; s--) + s[clen] = s[0]; + /* + * Insert the character into the buffer. + */ + for (s = cp; s < cp + clen; s++) + *s = *cs++; + /* + * Reprint the tail of the line from the inserted char. + */ + have_updown_match = FALSE; + cmd_repaint(cp); + cmd_right(); + return (CC_OK); +} + +/* * Delete the "word" to the left of the cursor. */ static int cmd_werase(void) @@ -612,7 +619,7 @@ static int cmd_kill(void) if (cmdbuf[0] == '\0') { /* Buffer is already empty; abort the current command. */ - return (CC_QUIT); + return CC_QUIT; } cmd_offset = 0; cmd_home(); @@ -625,7 +632,7 @@ static int cmd_kill(void) * to abort the current command, if CF_QUIT_ON_ERASE is set. */ if (curr_cmdflags & CF_QUIT_ON_ERASE) - return (CC_QUIT); + return CC_QUIT; return (CC_OK); } @@ -660,7 +667,7 @@ static int cmd_updown(int action) /* * The current command has no history list. */ - bell(); + lbell(); return (CC_OK); } @@ -705,7 +712,7 @@ static int cmd_updown(int action) /* * We didn't find a history entry that matches. */ - bell(); + lbell(); return (CC_OK); } @@ -796,6 +803,15 @@ public void cmd_addhist(struct mlist *mlist, constant char *cmd, lbool modified) * Thus, an UPARROW will always retrieve the previous command. */ mlist->curr_mp = ml->next; + if (modified) + { + if (mlist == &mlist_search && autosave_action('/')) + save_cmdhist(); +#if SHELL_ESCAPE || PIPEC + else if (mlist == &mlist_shell && autosave_action('!')) + save_cmdhist(); +#endif + } #endif } @@ -904,6 +920,9 @@ static int cmd_edit(char c, lbool stay_in_completion) return (CC_OK); case EC_INSERT: not_in_completion(); +#if LESS_INSERT_MODE + insert_mode = !insert_mode; +#endif return (CC_OK); case EC_BACKSPACE: not_in_completion(); @@ -914,7 +933,7 @@ static int cmd_edit(char c, lbool stay_in_completion) case EC_ABORT: not_in_completion(); (void) cmd_kill(); - return (CC_QUIT); + return CC_QUIT; case EC_W_BACKSPACE: not_in_completion(); return (cmd_werase()); @@ -950,17 +969,23 @@ static int cmd_istr(constant char *str) { constant char *endline = str + strlen(str); constant char *s; - int action; - + int action = CC_OK; +#if LESS_INSERT_MODE + lbool save_insert_mode = insert_mode; + insert_mode = TRUE; +#endif for (s = str; *s != '\0'; ) { constant char *os = s; step_charc(&s, +1, endline); action = cmd_ichar(os, ptr_diff(s, os)); if (action != CC_OK) - return (action); + break; } - return (CC_OK); +#if LESS_INSERT_MODE + insert_mode = save_insert_mode; +#endif + return (action); } /* @@ -1171,7 +1196,7 @@ static int cmd_complete(int action) #endif /* TAB_COMPLETE_FILENAME */ if (tk_text == NULL) { - bell(); + lbell(); return (CC_OK); } if (action == EC_EXPAND) @@ -1239,7 +1264,7 @@ static int cmd_complete(int action) fail: in_completion = FALSE; - bell(); + lbell(); return (CC_OK); } @@ -1281,7 +1306,7 @@ static int cmd_uchar(char c, size_t *plen) } else { /* UTF8_INVALID or stray UTF8_TRAIL */ - bell(); + lbell(); return (CC_ERROR); } } else if (IS_UTF8_TRAIL(c)) @@ -1293,14 +1318,14 @@ static int cmd_uchar(char c, size_t *plen) { /* complete, but not well formed (non-shortest form), sequence */ cmd_mbc_buf_len = 0; - bell(); + lbell(); return (CC_ERROR); } } else { /* Flush incomplete (truncated) sequence. */ cmd_mbc_buf_len = 0; - bell(); + lbell(); /* Handle new char. */ goto retry; } @@ -1388,7 +1413,6 @@ public LINENUM cmd_int(mutable long *frac) { constant char *p; LINENUM n = 0; - lbool err; for (p = cmdbuf; *p >= '0' && *p <= '9'; p++) { @@ -1401,8 +1425,8 @@ public LINENUM cmd_int(mutable long *frac) *frac = 0; if (*p++ == '.') { - *frac = getfraction(&p, NULL, &err); - /* {{ do something if err is set? }} */ + /* {{ Just ignore error in fractional part. }} */ + (void) getfraction(&p, frac); } return (n); } @@ -1447,7 +1471,7 @@ static int mlist_size(struct mlist *ml) static char * histfile_find(lbool must_exist) { constant char *home = lgetenv("HOME"); - char *name = NULL; + char *name; /* Try in $XDG_STATE_HOME, then in $HOME/.local/state, then in $XDG_DATA_HOME, then in $HOME. */ #if OS2 @@ -1738,7 +1762,7 @@ public void save_cmdhist(void) int skip_shell; struct save_ctx ctx; constant char *s; - FILE *fout = NULL; + FILE *fout; int histsize = 0; if (!secure_allow(SF_HISTORY) || !histfile_modified()) diff --git a/contrib/less/command.c b/contrib/less/command.c index 390385547385..4784cf45daa6 100644 --- a/contrib/less/command.c +++ b/contrib/less/command.c @@ -32,7 +32,7 @@ extern int jump_sline; extern lbool quitting; extern int wscroll; extern int top_scroll; -extern int ignore_eoi; +extern lbool ignore_eoi; extern int hshift; extern int bs_mode; extern int proc_backspace; @@ -49,7 +49,6 @@ extern void *ml_examine; extern int wheel_lines; extern int def_search_type; extern lbool search_wrapped; -extern lbool no_poll; extern int no_paste; extern lbool pasting; extern int no_edit_warn; @@ -154,7 +153,7 @@ static void start_mca(int action, constant char *prompt, void *mlist, int cmdfla set_mlist(mlist, cmdflags); } -public int in_mca(void) +public lbool in_mca(void) { return (mca != 0 && mca != A_PREFIX); } @@ -476,7 +475,7 @@ static int mca_opt_nonfirst_char(char c) } } else if (!ambig) { - bell(); + lbell(); } return (MCA_MORE); } @@ -575,7 +574,10 @@ static int mca_search_char(char c) */ if (!cmdbuf_empty() || literal_char) { + lbool was_literal_char = literal_char; literal_char = FALSE; + if (was_literal_char) + mca_search1(); return (NO_MCA); } @@ -640,6 +642,17 @@ static int mca_search_char(char c) } /* + * Jump back to the starting position of an incremental search. + */ +static void jump_search_incr_pos(void) +{ + if (search_incr_pos.pos == NULL_POSITION) + return; + hshift = search_incr_hshift; + jump_loc(search_incr_pos.pos, search_incr_pos.ln); +} + +/* * Handle a character of a multi-character command. */ static int mca_char(char c) @@ -772,30 +785,21 @@ static int mca_char(char c) if (*pattern == '\0') { /* User has backspaced to an empty pattern. */ - undo_search(1); - hshift = search_incr_hshift; - jump_loc(search_incr_pos.pos, search_incr_pos.ln); + undo_search(TRUE); + jump_search_incr_pos(); } else { - /* - * Suppress tty polling while searching. - * This avoids a problem where tty input - * can cause the search to be interrupted. - */ - no_poll = TRUE; if (search(st | SRCH_INCR, pattern, 1) != 0) { /* No match, invalid pattern, etc. */ - undo_search(1); - hshift = search_incr_hshift; - jump_loc(search_incr_pos.pos, search_incr_pos.ln); + undo_search(TRUE); + jump_search_incr_pos(); } - no_poll = FALSE; } /* Redraw the search prompt and search string. */ if (is_screen_trashed() || !full_screen) { - clear(); + lclear(); repaint(); } mca_search1(); @@ -851,7 +855,7 @@ static void make_display(void) * We need to clear and repaint screen before any change. */ if (!full_screen && !(quit_if_one_screen && one_screen)) - clear(); + lclear(); /* * If nothing is displayed yet, display starting from initial_scrpos. */ @@ -864,9 +868,9 @@ static void make_display(void) } else if (is_screen_trashed() || !full_screen) { int save_top_scroll = top_scroll; - int save_ignore_eoi = ignore_eoi; + lbool save_ignore_eoi = ignore_eoi; top_scroll = 1; - ignore_eoi = 0; + ignore_eoi = FALSE; if (is_screen_trashed() == 2) { /* Special case used by ignore_eoi: re-open the input file @@ -1304,29 +1308,31 @@ static void multi_search(constant char *pattern, int n, int silent) /* * Forward forever, or until a highlighted line appears. */ -static int forw_loop(int until_hilite) +static int forw_loop(int action) { - POSITION curr_len; + POSITION prev_hilite; if (ch_getflags() & CH_HELPFILE) return (A_NOACTION); cmd_exec(); jump_forw_buffered(); - curr_len = ch_length(); - highest_hilite = until_hilite ? curr_len : NULL_POSITION; - ignore_eoi = 1; + highest_hilite = prev_hilite = 0; + ignore_eoi = TRUE; while (!sigs) { - if (until_hilite && highest_hilite > curr_len) + if (action != A_F_FOREVER && highest_hilite > prev_hilite) { - bell(); - break; + lbell(); + if (action == A_F_UNTIL_HILITE) + break; + prev_hilite = highest_hilite; } make_display(); forward(1, FALSE, FALSE, FALSE); } - ignore_eoi = 0; + highest_hilite = NULL_POSITION; + ignore_eoi = FALSE; ch_set_eof(); /* @@ -1334,7 +1340,7 @@ static int forw_loop(int until_hilite) * a non-abort signal (e.g. window-change). */ if (sigs && !ABORT_SIGS()) - return (until_hilite ? A_F_UNTIL_HILITE : A_F_FOREVER); + return (action); return (A_NOACTION); } @@ -1401,7 +1407,6 @@ public void commands(void) #endif search_type = SRCH_FORW; - wscroll = (sc_height + 1) / 2; newaction = A_NOACTION; for (;;) @@ -1507,7 +1512,9 @@ public void commands(void) * want erase_char/kill_char to be treated * as line editing characters. */ - constant char tbuf[2] = { c, '\0' }; + char tbuf[2]; + tbuf[0] = c; + tbuf[1] = '\0'; action = fcmd_decode(tbuf, &extra); } /* @@ -1664,6 +1671,8 @@ public void commands(void) break; case A_F_FOREVER: + case A_F_FOREVER_BELL: + case A_F_UNTIL_HILITE: /* * Forward forever, ignoring EOF. */ @@ -1671,11 +1680,7 @@ public void commands(void) error("Warning: command may not work correctly when file is viewed via LESSOPEN", NULL_PARG); if (show_attn) set_attnpos(bottompos); - newaction = forw_loop(0); - break; - - case A_F_UNTIL_HILITE: - newaction = forw_loop(1); + newaction = forw_loop(action); break; case A_F_SCROLL: @@ -2143,7 +2148,7 @@ public void commands(void) cmd_exec(); if (new_ifile == NULL_IFILE) { - bell(); + lbell(); break; } if (edit_ifile(new_ifile) != 0) @@ -2353,7 +2358,7 @@ public void commands(void) break; default: - bell(); + lbell(); break; } } diff --git a/contrib/less/compose.uni b/contrib/less/compose.uni index 6b4458efc4b4..aaf8d2ec6ee5 100644 --- a/contrib/less/compose.uni +++ b/contrib/less/compose.uni @@ -1,4 +1,4 @@ -/* Generated by "./mkutable -f2 Mn Me -- unicode/UnicodeData.txt" on Aug 11 0:27:25 GMT 2025 */ +/* Generated by "./mkutable -f2 Mn Me -- unicode/UnicodeData.txt" on Nov 28 1:30:11 GMT 2025 */ { 0x0300, 0x036f }, /* Mn */ { 0x0483, 0x0487 }, /* Mn */ { 0x0488, 0x0489 }, /* Me */ @@ -144,7 +144,8 @@ { 0x1a7f, 0x1a7f }, /* Mn */ { 0x1ab0, 0x1abd }, /* Mn */ { 0x1abe, 0x1abe }, /* Me */ - { 0x1abf, 0x1ace }, /* Mn */ + { 0x1abf, 0x1add }, /* Mn */ + { 0x1ae0, 0x1aeb }, /* Mn */ { 0x1b00, 0x1b03 }, /* Mn */ { 0x1b34, 0x1b34 }, /* Mn */ { 0x1b36, 0x1b3a }, /* Mn */ @@ -230,7 +231,7 @@ { 0x10d24, 0x10d27 }, /* Mn */ { 0x10d69, 0x10d6d }, /* Mn */ { 0x10eab, 0x10eac }, /* Mn */ - { 0x10efc, 0x10eff }, /* Mn */ + { 0x10efa, 0x10eff }, /* Mn */ { 0x10f46, 0x10f50 }, /* Mn */ { 0x10f82, 0x10f85 }, /* Mn */ { 0x11001, 0x11001 }, /* Mn */ @@ -305,6 +306,9 @@ { 0x11a59, 0x11a5b }, /* Mn */ { 0x11a8a, 0x11a96 }, /* Mn */ { 0x11a98, 0x11a99 }, /* Mn */ + { 0x11b60, 0x11b60 }, /* Mn */ + { 0x11b62, 0x11b64 }, /* Mn */ + { 0x11b66, 0x11b66 }, /* Mn */ { 0x11c30, 0x11c36 }, /* Mn */ { 0x11c38, 0x11c3d }, /* Mn */ { 0x11c3f, 0x11c3f }, /* Mn */ @@ -360,5 +364,9 @@ { 0x1e2ec, 0x1e2ef }, /* Mn */ { 0x1e4ec, 0x1e4ef }, /* Mn */ { 0x1e5ee, 0x1e5ef }, /* Mn */ + { 0x1e6e3, 0x1e6e3 }, /* Mn */ + { 0x1e6e6, 0x1e6e6 }, /* Mn */ + { 0x1e6ee, 0x1e6ef }, /* Mn */ + { 0x1e6f5, 0x1e6f5 }, /* Mn */ { 0x1e8d0, 0x1e8d6 }, /* Mn */ { 0x1e944, 0x1e94a }, /* Mn */ diff --git a/contrib/less/decode.c b/contrib/less/decode.c index 1d80d126c207..e76a111f7b75 100644 --- a/contrib/less/decode.c +++ b/contrib/less/decode.c @@ -36,6 +36,7 @@ extern int erase_char, erase2_char, kill_char; extern int mousecap; extern int sc_height; +extern char *no_config; static constant lbool allow_drag = TRUE; @@ -92,6 +93,7 @@ static unsigned char cmdtable[] = ESC,'j',0, A_F_NEWLINE, ESC,'k',0, A_B_NEWLINE, 'F',0, A_F_FOREVER, + ESC,'f',0, A_F_FOREVER_BELL, ESC,'F',0, A_F_UNTIL_HILITE, 'R',0, A_FREPAINT, 'r',0, A_REPAINT, @@ -100,7 +102,12 @@ static unsigned char cmdtable[] = ESC,'u',0, A_UNDO_SEARCH, ESC,'U',0, A_CLR_SEARCH, 'g',0, A_GOLINE, - SK(SK_HOME),0, A_GOLINE, + SK(SK_HOME),0, A_LLSHIFT, + SK(SK_SHIFT_HOME),0, A_GOLINE|A_EXTRA, ESC,'{',0, + SK(SK_CTL_HOME),0, A_GOLINE|A_EXTRA, ESC,'{',0, + SK(SK_END),0, A_RRSHIFT, + SK(SK_SHIFT_END),0, A_GOEND|A_EXTRA, ESC,'}',0, + SK(SK_CTL_END),0, A_GOEND|A_EXTRA, ESC,'}',0, '<',0, A_GOLINE, ESC,'<',0, A_GOLINE, 'p',0, A_PERCENT, @@ -125,7 +132,6 @@ static unsigned char cmdtable[] = ESC,'G',0, A_GOEND_BUF, ESC,'>',0, A_GOEND, '>',0, A_GOEND, - SK(SK_END),0, A_GOEND, 'P',0, A_GOPOS, '0',0, A_DIGIT, @@ -183,6 +189,24 @@ static unsigned char cmdtable[] = '!',0, A_SHELL, '#',0, A_PSHELL, '+',0, A_FIRSTCMD, + + SK(SK_PAD_U),0, A_B_LINE, + SK(SK_PAD_D),0, A_F_LINE, + SK(SK_PAD_R),0, A_RSHIFT, + SK(SK_PAD_L),0, A_LSHIFT, + SK(SK_PAD_UR),0, A_B_SCREEN, + SK(SK_PAD_UL),0, A_LLSHIFT, + SK(SK_PAD_DR),0, A_RRSHIFT, + SK(SK_PAD_DL),0, A_GOEND, + SK(SK_PAD_STAR),0, A_NOACTION|A_EXTRA, '*',0, + SK(SK_PAD_SLASH),0, A_NOACTION|A_EXTRA, '/',0, + SK(SK_PAD_DASH),0, A_NOACTION|A_EXTRA, '-',0, + SK(SK_PAD_PLUS),0, A_NOACTION|A_EXTRA, '+',0, + SK(SK_PAD_DOT),0, A_NOACTION|A_EXTRA, '.',0, + SK(SK_PAD_COMMA),0, A_NOACTION, + SK(SK_PAD_ZERO),0, A_NOACTION|A_EXTRA, '0',0, + SK(SK_PAD_CENTER),0, A_NOACTION, + ESC,'[','2','0','0','~',0, A_START_PASTE, ESC,'[','2','0','1','~',0, A_END_PASTE, @@ -227,13 +251,33 @@ static unsigned char edittable[] = ESC,SK(SK_BACKSPACE),0, EC_W_BACKSPACE, /* ESC BACKSPACE */ ESC,'0',0, EC_HOME, /* ESC 0 */ SK(SK_HOME),0, EC_HOME, /* HOME */ + SK(SK_SHIFT_HOME),0, EC_HOME, /* SHIFT-HOME */ + SK(SK_CTL_HOME),0, EC_HOME, /* CTRL-HOME */ ESC,'$',0, EC_END, /* ESC $ */ SK(SK_END),0, EC_END, /* END */ + SK(SK_SHIFT_END),0, EC_END, /* SHIFT-END */ + SK(SK_CTL_END),0, EC_END, /* CTRL-END */ ESC,'k',0, EC_UP, /* ESC k */ SK(SK_UP_ARROW),0, EC_UP, /* UPARROW */ ESC,'j',0, EC_DOWN, /* ESC j */ SK(SK_DOWN_ARROW),0, EC_DOWN, /* DOWNARROW */ CONTROL('G'),0, EC_ABORT, /* CTRL-G */ + SK(SK_PAD_U),0, EC_UP, + SK(SK_PAD_D),0, EC_DOWN, + SK(SK_PAD_R),0, EC_RIGHT, + SK(SK_PAD_L),0, EC_LEFT, + SK(SK_PAD_UR),0, A_NOACTION, + SK(SK_PAD_UL),0, EC_HOME, + SK(SK_PAD_DR),0, A_NOACTION, + SK(SK_PAD_DL),0, EC_END, + SK(SK_PAD_STAR),0, A_NOACTION|A_EXTRA, '*',0, + SK(SK_PAD_SLASH),0, A_NOACTION|A_EXTRA, '/',0, + SK(SK_PAD_DASH),0, A_NOACTION|A_EXTRA, '-',0, + SK(SK_PAD_PLUS),0, A_NOACTION|A_EXTRA, '+',0, + SK(SK_PAD_DOT),0, A_NOACTION|A_EXTRA, '.',0, + SK(SK_PAD_COMMA),0, A_NOACTION|A_EXTRA, ',',0, + SK(SK_PAD_ZERO),0, A_NOACTION|A_EXTRA, '0',0, + SK(SK_PAD_CENTER),0, A_NOACTION, ESC,'[','M',0, EC_X11MOUSE, /* X11 mouse report */ ESC,'[','<',0, EC_X116MOUSE, /* X11 1006 mouse report */ ESC,'[','2','0','0','~',0, A_START_PASTE, /* open paste bracket */ @@ -549,8 +593,11 @@ static int mouse_button_left(int x, int y, lbool down, lbool drag) } else if (!down) { #if OSC8_LINK - if (osc8_click(y, x)) - return (A_NOACTION); + if (secure_allow(SF_OSC8_OPEN)) + { + if (osc8_click(y, x)) + return (A_NOACTION); + } #else (void) x; #endif /* OSC8_LINK */ @@ -738,7 +785,7 @@ static int cmd_search(constant char *cmd, constant unsigned char *table, constan while (table < endtable) { int taction; - const unsigned char *textra; + constant unsigned char *textra; size_t cmdlen; size_t match = cmd_match((constant char *) table, cmd); table = cmd_next_entry(table, &taction, &textra, &cmdlen); @@ -821,6 +868,44 @@ public int ecmd_decode(constant char *cmd, constant char **sp) return (cmd_decode(list_ecmd_tables, cmd, sp)); } +/* + * Parse a comma-separated list. + * Call func repeatedly, passing each item in the list. + * Stop and return FALSE if func ever returns FALSE, + * otherwise parse the entire list and return TRUE. + */ +public lbool parse_csl(lbool (*func)(constant char *word, size_t wlen, void *arg), constant char *str, void *arg) +{ + for (;;) + { + constant char *estr; + while (*str == ' ' || *str == ',') ++str; /* skip leading spaces/commas */ + if (*str == '\0') break; + estr = strchr(str, ','); + if (estr == NULL) estr = str + strlen(str); + while (estr > str && estr[-1] == ' ') --estr; /* trim trailing spaces */ + if (!(*func)(str, ptr_diff(estr, str), arg)) + return FALSE; + str = estr; + } + return TRUE; +} + +/* + * Should we ignore the setting of an environment variable? + */ +static lbool word_no_match(constant char *word, size_t wlen, void *arg) +{ + constant char *var = (constant char *) arg; + return !(wlen == strlen(var) && strncmp(var, word, wlen) == 0); +} +static lbool ignore_env(constant char *var) +{ + if (isnullenv(no_config)) + return FALSE; /* no_config is not set; don't ignore anything */ + /* no_config is set; ignore any var that does not appear in no_config */ + return parse_csl(word_no_match, no_config, (void*) var); +} /* * Get the value of an environment variable. @@ -831,6 +916,8 @@ public constant char * lgetenv(constant char *var) int a; constant char *s; + if (ignore_env(var)) + return (NULL); a = cmd_decode(list_var_tables, var, &s); if (a == EV_OK) return (s); @@ -986,7 +1073,7 @@ public int lesskey(constant char *filename, lbool sysvar) ssize_t n; int f; - if (!secure_allow(SF_LESSKEY)) + if (!secure_allow(SF_LESSKEY) || !isnullenv(no_config)) return (1); /* * Try to open the lesskey file. @@ -1048,7 +1135,7 @@ static int lesskey_text(constant char *filename, lbool sysvar, lbool content) int r; static struct lesskey_tables tables; - if (!secure_allow(SF_LESSKEY)) + if (!secure_allow(SF_LESSKEY) || !isnullenv(no_config)) return (1); r = content ? parse_lesskey_content(filename, &tables) : parse_lesskey(filename, &tables); if (r != 0) diff --git a/contrib/less/edit.c b/contrib/less/edit.c index 1816e6f9f9bc..3a8f4eb41aec 100644 --- a/contrib/less/edit.c +++ b/contrib/less/edit.c @@ -77,20 +77,20 @@ public void init_textlist(struct textlist *tlist, mutable char *str) #if SPACES_IN_FILENAMES if (meta_quoted) { - meta_quoted = 0; + meta_quoted = FALSE; } else if (esclen > 0 && s + esclen < tlist->endstring && strncmp(s, esc, esclen) == 0) { - meta_quoted = 1; + meta_quoted = TRUE; s += esclen - 1; } else if (delim_quoted) { if (*s == closequote) - delim_quoted = 0; + delim_quoted = FALSE; } else /* (!delim_quoted) */ { if (*s == openquote) - delim_quoted = 1; + delim_quoted = TRUE; else if (*s == ' ') *s = '\0'; } @@ -101,7 +101,7 @@ public void init_textlist(struct textlist *tlist, mutable char *str) } } -public constant char * forw_textlist(struct textlist *tlist, constant char *prev) +public constant char * forw_textlist(constant struct textlist *tlist, constant char *prev) { constant char *s; @@ -120,7 +120,7 @@ public constant char * forw_textlist(struct textlist *tlist, constant char *prev return (s); } -public constant char * back_textlist(struct textlist *tlist, constant char *prev) +public constant char * back_textlist(constant struct textlist *tlist, constant char *prev) { constant char *s; @@ -210,7 +210,6 @@ static void modeline_options(constant char *str, char end_char) */ static void check_modeline(constant char *line) { -#if HAVE_STRSTR static constant char *pgms[] = { "less:", "vim:", "vi:", "ex:", NULL }; constant char **pgm; for (pgm = pgms; *pgm != NULL; ++pgm) @@ -235,7 +234,6 @@ static void check_modeline(constant char *line) pline = str; } } -#endif /* HAVE_STRSTR */ } /* diff --git a/contrib/less/filename.c b/contrib/less/filename.c index 28ff25e4dcb8..d9d824be6f50 100644 --- a/contrib/less/filename.c +++ b/contrib/less/filename.c @@ -469,7 +469,7 @@ public char * fcomplete(constant char *s) * be used later to compare to st_size from stat(2) to see if the file * is lying about its size. */ -public int bin_file(int f, ssize_t *n) +public lbool bin_file(int f, ssize_t *n) { int bin_count = 0; char data[256]; @@ -477,12 +477,12 @@ public int bin_file(int f, ssize_t *n) constant char* edata; if (!seekable(f)) - return (0); + return FALSE; if (less_lseek(f, (less_off_t)0, SEEK_SET) == BAD_LSEEK) - return (0); + return FALSE; *n = read(f, data, sizeof(data)); if (*n <= 0) - return (0); + return FALSE; edata = &data[*n]; for (p = data; p < edata; ) { @@ -569,9 +569,10 @@ static FILE * shellcmd(constant char *cmd) fd = popen(cmd, "r"); } else { - size_t len = strlen(shell) + strlen(esccmd) + 5; + constant char *copt = shell_coption(); + size_t len = strlen(shell) + strlen(esccmd) + strlen(copt) + 3; scmd = (char *) ecalloc(len, sizeof(char)); - SNPRINTF3(scmd, len, "%s %s %s", shell, shell_coption(), esccmd); + SNPRINTF3(scmd, len, "%s %s %s", shell, copt, esccmd); free(esccmd); fd = popen(scmd, "r"); free(scmd); diff --git a/contrib/less/fmt.uni b/contrib/less/fmt.uni index c861e1908360..7b6726ffd2ad 100644 --- a/contrib/less/fmt.uni +++ b/contrib/less/fmt.uni @@ -1,4 +1,4 @@ -/* Generated by "./mkutable -f2 Cf -- unicode/UnicodeData.txt" on Jul 27 19:38:50 GMT 2025 */ +/* Generated by "./mkutable -f2 Cf -- unicode/UnicodeData.txt" on Nov 28 1:30:12 GMT 2025 */ { 0x0600, 0x0605 }, /* Cf */ { 0x061c, 0x061c }, /* Cf */ { 0x06dd, 0x06dd }, /* Cf */ diff --git a/contrib/less/forwback.c b/contrib/less/forwback.c index e77c0d4ce198..5daf98b7b705 100644 --- a/contrib/less/forwback.c +++ b/contrib/less/forwback.c @@ -36,7 +36,7 @@ extern int auto_wrap; extern lbool plusoption; extern int forw_scroll; extern int back_scroll; -extern int ignore_eoi; +extern lbool ignore_eoi; extern int header_lines; extern int header_cols; extern int full_screen; @@ -66,7 +66,7 @@ public void eof_bell(void) } #endif if (quiet == NOT_QUIET) - bell(); + lbell(); else vbell(); } @@ -218,12 +218,13 @@ public int overlay_header(void) * The first real line after the blanks will start at ch_zero(). * "to_newline" means count file lines rather than screen lines. */ -public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline, int nblank) +public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline, lbool do_stop_on_form_feed, int nblank) { int nlines = 0; lbool do_repaint; lbool newline; lbool first_line = TRUE; + lbool need_home = FALSE; if (pos != NULL_POSITION) pos = after_header_pos(pos); @@ -252,10 +253,7 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_new */ pos_clear(); force = TRUE; - if (less_is_more == 0) { - clear(); - home(); - } + need_home = (less_is_more == 0) ? TRUE : FALSE; } if (pos != position(BOTTOM_PLUS_ONE) || empty_screen()) @@ -269,8 +267,7 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_new force = TRUE; if (top_scroll) { - clear(); - home(); + need_home = TRUE; } else if (!first_time && !is_filtering() && full_screen) { putstr("...skipping...\n"); @@ -331,6 +328,12 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_new nlines++; if (do_repaint) continue; + if (need_home) + { + lclear(); + home(); + need_home = FALSE; + } /* * If this is the first screen displayed and * we hit an early EOF (i.e. before the requested @@ -353,13 +356,13 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_new continue; } put_line(TRUE); - if (stop_on_form_feed && !do_repaint && line_is_ff() && position(TOP) != NULL_POSITION) + if (do_stop_on_form_feed && !do_repaint && line_is_ff() && position(TOP) != NULL_POSITION) break; forw_prompt = 1; } if (!first_line) add_forw_pos(pos, FALSE); - if (nlines == 0 && !ignore_eoi && !ABORT_SIGS()) + if (nlines == 0 && !ignore_eoi) eof_bell(); else if (do_repaint) repaint(); @@ -375,7 +378,7 @@ public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_new /* * Display n lines, scrolling backward. */ -public void back(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline) +public void back(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline, lbool do_stop_on_form_feed) { int nlines = 0; lbool do_repaint; @@ -418,7 +421,7 @@ public void back(int n, POSITION pos, lbool force, lbool only_last, lbool to_new home(); add_line(); put_line(FALSE); - if (stop_on_form_feed && line_is_ff()) + if (do_stop_on_form_feed && line_is_ff()) break; } } @@ -469,7 +472,7 @@ public void forward(int n, lbool force, lbool only_last, lbool to_newline) { do { - back(1, position(TOP), TRUE, FALSE, FALSE); + back(1, position(TOP), TRUE, FALSE, FALSE, stop_on_form_feed); pos = position(BOTTOM_PLUS_ONE); } while (pos == NULL_POSITION && !ABORT_SIGS()); } @@ -479,7 +482,7 @@ public void forward(int n, lbool force, lbool only_last, lbool to_newline) return; } } - forw(n, pos, force, only_last, to_newline, 0); + forw(n, pos, force, only_last, to_newline, stop_on_form_feed, 0); } /* @@ -496,7 +499,7 @@ public void backward(int n, lbool force, lbool only_last, lbool to_newline) eof_bell(); return; } - back(n, pos, force, only_last, to_newline); + back(n, pos, force, only_last, to_newline, stop_on_form_feed); } /* diff --git a/contrib/less/funcs.h b/contrib/less/funcs.h index 11605acc8b3b..903087785b0b 100644 --- a/contrib/less/funcs.h +++ b/contrib/less/funcs.h @@ -8,17 +8,18 @@ public size_t sprefix(constant char *ps, constant char *s, int uppercase); public void quit(int status); public int secure_allow(int features); public void raw_mode(int on); +public void scrsize(void); public void screen_size_changed(void); public constant char * special_key_str(int key); public void init_win_colors(void); -public void get_term(void); +public void get_term(); public void init_mouse(void); public void deinit_mouse(void); public void suspend_screen(void); public void resume_screen(void); -public void init(void); -public void deinit(void); -public int interactive(void); +public void term_init(void); +public void term_deinit(void); +public lbool interactive(void); public void home(void); public void dump_screen(void); public void add_line(void); @@ -29,8 +30,8 @@ public void line_left(void); public void check_winch(void); public void goto_line(int sindex); public void vbell(void); -public void bell(void); -public void clear(void); +public void lbell(void); +public void lclear(void); public void clear_eol(void); public void clear_bot(void); public void init_bracketed_paste(void); @@ -45,7 +46,7 @@ public void putbs(void); public void WIN32ungetch(int ch); public lbool win32_kbhit2(lbool no_queued); public lbool win32_kbhit(void); -public char WIN32getch(void); +public int WIN32getch(void); public void win32_getch_clear(void); public void WIN32setcolors(int fg, int bg); public void WIN32textout(constant char *text, size_t len); @@ -106,7 +107,7 @@ public constant char * cmd_lastpattern(void); public void init_cmdhist(void); public void save_cmdhist(void); public void cmd_exec(void); -public int in_mca(void); +public lbool in_mca(void); public int norm_search_type(int st); public void screen_trashed_num(int trashed); public void screen_trashed(void); @@ -134,6 +135,7 @@ public void add_uvar_table(unsigned char *buf, size_t len); public void add_sysvar_table(unsigned char *buf, size_t len); public int fcmd_decode(constant char *cmd, constant char **sp); public int ecmd_decode(constant char *cmd, constant char **sp); +public lbool parse_csl(lbool (*func)(constant char *word, size_t wlen, void *arg), constant char *str, void *arg); public constant char * lgetenv(constant char *var); public constant char * lgetenv_ext(constant char *var, unsigned char *env_buf, size_t env_buf_len); public lbool isnullenv(constant char *s); @@ -142,8 +144,8 @@ public int lesskey_src(constant char *filename, lbool sysvar); public int lesskey_content(constant char *content, lbool sysvar); public int editchar(char c, int flags); public void init_textlist(struct textlist *tlist, mutable char *str); -public constant char * forw_textlist(struct textlist *tlist, constant char *prev); -public constant char * back_textlist(struct textlist *tlist, constant char *prev); +public constant char * forw_textlist(constant struct textlist *tlist, constant char *prev); +public constant char * back_textlist(constant struct textlist *tlist, constant char *prev); public void close_altpipe(IFILE ifile); public void check_altpipe_error(void); public int edit(constant char *filename); @@ -170,7 +172,7 @@ public char * dirfile(constant char *dirname, constant char *filename, int must_ public char * homefile(constant char *filename); public char * fexpand(constant char *s); public char * fcomplete(constant char *s); -public int bin_file(int f, ssize_t *n); +public lbool bin_file(int f, ssize_t *n); public char * readfd(FILE *fd); public char * lglob(constant char *afilename); public lbool is_fake_pathname(constant char *path); @@ -188,8 +190,8 @@ public lbool eof_displayed(lbool offset); public lbool entire_file_displayed(void); public void squish_check(void); public int overlay_header(void); -public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline, int nblank); -public void back(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline); +public void forw(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline, lbool do_stop_on_form_feed, int nblank); +public void back(int n, POSITION pos, lbool force, lbool only_last, lbool to_newline, lbool do_stop_on_form_feed); public void forward(int n, lbool force, lbool only_last, lbool to_newline); public void backward(int n, lbool force, lbool only_last, lbool to_newline); public int get_back_scroll(void); @@ -203,10 +205,10 @@ public IFILE get_ifile(constant char *filename, IFILE prev); public constant char * get_filename(IFILE ifile); public constant char * get_real_filename(IFILE ifile); public int get_index(IFILE ifile); -public void store_pos(IFILE ifile, struct scrpos *scrpos); +public void store_pos(IFILE ifile, constant struct scrpos *scrpos); public void get_pos(IFILE ifile, struct scrpos *scrpos); public void set_open(IFILE ifile); -public int opened(IFILE ifile); +public lbool opened(IFILE ifile); public void hold_ifile(IFILE ifile, int incr); public int held_ifile(IFILE ifile); public void * get_filestate(IFILE ifile); @@ -264,6 +266,7 @@ public POSITION forw_raw_line(POSITION curr_pos, constant char **linep, size_t * public POSITION back_raw_line(POSITION curr_pos, constant char **linep, size_t *line_lenp); public int skip_columns(int cols, constant char **linep, size_t *line_lenp); public void load_line(constant char *str); +public int longest_line_width(void); public int rrshift(void); public int set_color_map(int attr, constant char *colorstr); public constant char * get_color_map(int attr); @@ -278,7 +281,7 @@ public void lsystem(constant char *cmd, constant char *donemsg); public int pipe_mark(char c, constant char *cmd); public int pipe_data(constant char *cmd, POSITION spos, POSITION epos); public void init_mark(void); -public int badmark(char c); +public lbool badmark(char c); public void setmark(char c, int where); public void clrmark(char c); public void lastmark(void); @@ -303,6 +306,7 @@ public void opt_t(int type, constant char *s); public void opt__T(int type, constant char *s); public void opt_p(int type, constant char *s); public void opt__P(int type, constant char *s); +public void opt_autosave(int type, constant char *s); public void opt_b(int type, constant char *s); public void opt_i(int type, constant char *s); public void opt__V(int type, constant char *s); @@ -321,7 +325,6 @@ public void opt_status_col_width(int type, constant char *s); public void opt_filesize(int type, constant char *s); public void opt_first_cmd_at_prompt(int type, constant char *s); public void opt_intr(int type, constant char *s); -public int next_cnum(constant char **sp, constant char *printopt, constant char *errmsg, lbool *errp); public void opt_header(int type, constant char *s); public void opt_search_type(int type, constant char *s); public void opt_nosearch_headers(int type, constant char *s); @@ -331,17 +334,18 @@ public void opt_no_paste(int type, constant char *s); public void opt_ttyin_name(int type, constant char *s); public int chop_line(void); public int get_swindow(void); +public lbool autosave_action(char act); public constant char * propt(char c); public void scan_option(constant char *s, lbool is_env); -public void toggle_option(struct loption *o, lbool lower, constant char *s, int how_toggle); -public int opt_has_param(struct loption *o); -public constant char * opt_prompt(struct loption *o); +public lbool toggle_option(struct loption *o, lbool lower, constant char *s, int how_toggle); +public lbool opt_has_param(constant struct loption *o); +public constant char * opt_prompt(constant struct loption *o); public constant char * opt_toggle_disallowed(int c); public lbool isoptpending(void); public void nopendopt(void); -public int getnumc(constant char **sp, constant char *printopt, lbool *errp); -public int getnum(char **sp, constant char *printopt, lbool *errp); -public long getfraction(constant char **sp, constant char *printopt, lbool *errp); +public lbool getnumc(constant char **sp, constant char *printopt, lbool neg_ok, mutable int *p_num); +public lbool getnum(char **sp, constant char *printopt, lbool neg_ok, mutable int *p_num); +public lbool getfraction(constant char **sp, mutable long *p_frac); public void init_unsupport(void); public int get_quit_at_eof(void); public void init_option(void); @@ -350,10 +354,11 @@ public struct loption * findopt_name(constant char **p_optname, constant char ** public char * findopts_name(constant char *pfx); public void init_poll(void); public lbool ttyin_ready(void); -public int supports_ctrl_x(void); +public lbool supports_ctrl_x(void); public ssize_t iread(int fd, unsigned char *buf, size_t len); public int iopen(constant char *filename, int flags); public void intio(void); +public void polling_ok(void); public time_type get_time(void); public char * errno_message(constant char *filename); public constant char * signal_message(int sig); @@ -364,16 +369,16 @@ public int os9_signal(int type, RETSIGTYPE (*handler)()); public void sleep_ms(int ms); public void put_line(lbool forw_scroll); public void flush(void); -public void set_output(int fd); +public void set_output(int fd, lbool no_term_init); public int putchr(int ch); public void clear_bot_if_needed(void); public void putstr(constant char *s); -public int less_printf(constant char *fmt, PARG *parg); +public int less_printf(constant char *fmt, constant PARG *parg); public void get_return(void); -public void error(constant char *fmt, PARG *parg); -public void ierror(constant char *fmt, PARG *parg); -public void ixerror(constant char *fmt, PARG *parg); -public int query(constant char *fmt, PARG *parg); +public void error(constant char *fmt, constant PARG *parg); +public void ierror(constant char *fmt, constant PARG *parg); +public void ixerror(constant char *fmt, constant PARG *parg); +public int query(constant char *fmt, constant PARG *parg); public int compile_pattern(constant char *pattern, int search_type, int show_error, PATTERN_TYPE *comp_pattern); public void uncompile_pattern(PATTERN_TYPE *pattern); public int valid_pattern(char *pattern); @@ -386,8 +391,8 @@ public void add_back_pos(POSITION pos); public void pos_clear(void); public void pos_init(void); public int onscreen(POSITION pos); -public int empty_screen(void); -public int empty_lines(int s, int e); +public lbool empty_screen(void); +public lbool empty_lines(int s, int e); public void get_scrpos(struct scrpos *scrpos, int where); public int sindex_from_sline(int sline); public void pos_rehead(void); @@ -401,7 +406,7 @@ public int get_cvt_ops(int search_type); public void repaint_hilite(lbool on); public void clear_attn(void); public void undo_search(lbool clear); -public void undo_osc8(void); +public lbool undo_osc8(void); public void clr_hlist(struct hilite_tree *anchor); public void clr_hilite(void); public void clr_filter(void); @@ -420,7 +425,7 @@ public int search(int search_type, constant char *pattern, int n); public void prep_hilite(POSITION spos, POSITION epos, int maxlines); public void set_filter_pattern(constant char *pattern, int search_type); public lbool is_filtering(void); -public RETSIGTYPE winch(int type); +public RETSIGTYPE lwinch(int type); public void init_signals(int on); public void psignals(void); public void cleantags(void); @@ -445,7 +450,7 @@ public void xbuf_deinit(struct xbuffer *xbuf); public void xbuf_reset(struct xbuffer *xbuf); public void xbuf_add_byte(struct xbuffer *xbuf, unsigned char b); public void xbuf_add_char(struct xbuffer *xbuf, char c); -public void xbuf_add_data(struct xbuffer *xbuf, constant unsigned char *data, size_t len); +public void xbuf_add_data(struct xbuffer *xbuf, constant void *vdata, size_t len); public int xbuf_pop(struct xbuffer *buf); public void xbuf_set(struct xbuffer *dst, constant struct xbuffer *src); public constant char * xbuf_char_data(constant struct xbuffer *xbuf); diff --git a/contrib/less/help.c b/contrib/less/help.c index ed9465ad9560..ca6e81fd70f6 100644 --- a/contrib/less/help.c +++ b/contrib/less/help.c @@ -1,4 +1,4 @@ -/* This file was generated by mkhelp.pl from less.hlp at 18:02 on 2025/10/4 */ +/* This file was generated by mkhelp.pl from less.hlp at 16:50 on 2026/1/10 */ #include "less.h" constant char helpdata[] = { '\n', @@ -32,6 +32,7 @@ constant char helpdata[] = { ' ',' ','E','S','C','-','{',' ',' ','^','L','e','f','t','A','r','r','o','w',' ',' ',' ',' ','L','e','f','t',' ',' ','t','o',' ','f','i','r','s','t',' ','c','o','l','u','m','n','.','\n', ' ',' ','F',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','F','o','r','w','a','r','d',' ','f','o','r','e','v','e','r',';',' ','l','i','k','e',' ','"','t','a','i','l',' ','-','f','"','.','\n', ' ',' ','E','S','C','-','F',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','L','i','k','e',' ','F',' ','b','u','t',' ','s','t','o','p',' ','w','h','e','n',' ','s','e','a','r','c','h',' ','p','a','t','t','e','r','n',' ','i','s',' ','f','o','u','n','d','.','\n', +' ',' ','E','S','C','-','f',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','L','i','k','e',' ','F',' ','b','u','t',' ','r','i','n','g',' ','t','h','e',' ','b','e','l','l',' ','w','h','e','n',' ','s','e','a','r','c','h',' ','p','a','t','t','e','r','n',' ','i','s',' ','f','o','u','n','d','.','\n', ' ',' ','r',' ',' ','^','R',' ',' ','^','L',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','R','e','p','a','i','n','t',' ','s','c','r','e','e','n','.','\n', ' ',' ','R',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','R','e','p','a','i','n','t',' ','s','c','r','e','e','n',',',' ','d','i','s','c','a','r','d','i','n','g',' ','b','u','f','f','e','r','e','d',' ','i','n','p','u','t','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','-','\n', @@ -222,6 +223,8 @@ constant char helpdata[] = { ' ',' ','-','#',' ','[','_','\b','N',']',' ',' ','.','.','.','.',' ',' ','-','-','s','h','i','f','t','=','[','_','\b','N',']','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','S','e','t',' ','h','o','r','i','z','o','n','t','a','l',' ','s','c','r','o','l','l',' ','a','m','o','u','n','t',' ','(','0',' ','=',' ','o','n','e',' ','h','a','l','f',' ','s','c','r','e','e','n',' ','w','i','d','t','h',')','.','\n', '\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','a','u','t','o','s','a','v','e','=','[','_','\b','m','_','\b','/','_','\b','!','_','\b','*',']','\n', +' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','A','c','t','i','o','n','s',' ','w','h','i','c','h',' ','c','a','u','s','e',' ','t','h','e',' ','h','i','s','t','o','r','y',' ','f','i','l','e',' ','t','o',' ','b','e',' ','s','a','v','e','d','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','e','x','i','t','-','f','o','l','l','o','w','-','o','n','-','c','l','o','s','e','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','E','x','i','t',' ','F',' ','c','o','m','m','a','n','d',' ','o','n',' ','a',' ','p','i','p','e',' ','w','h','e','n',' ','w','r','i','t','e','r',' ','c','l','o','s','e','s',' ','p','i','p','e','.','\n', ' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ',' ','-','-','f','i','l','e','-','s','i','z','e','\n', diff --git a/contrib/less/ifile.c b/contrib/less/ifile.c index e32ca6520d80..7d516b612e01 100644 --- a/contrib/less/ifile.c +++ b/contrib/less/ifile.c @@ -31,7 +31,7 @@ struct ifile { void *h_filestate; /* File state (used in ch.c) */ int h_index; /* Index within command line list */ int h_hold; /* Hold count */ - char h_opened; /* Has this ifile been opened? */ + lbool h_opened; /* Has this ifile been opened? */ struct scrpos h_scrpos; /* Saved position within the file */ void *h_altpipe; /* Alt pipe */ char *h_altfilename; /* Alt filename */ @@ -108,7 +108,7 @@ static struct ifile * new_ifile(constant char *filename, struct ifile *prev) p->h_filename = save(filename); p->h_rfilename = lrealpath(filename); p->h_scrpos.pos = NULL_POSITION; - p->h_opened = 0; + p->h_opened = FALSE; p->h_hold = 0; p->h_filestate = NULL; p->h_altfilename = NULL; @@ -269,7 +269,7 @@ public int get_index(IFILE ifile) /* * Save the file position to be associated with a given file. */ -public void store_pos(IFILE ifile, struct scrpos *scrpos) +public void store_pos(IFILE ifile, constant struct scrpos *scrpos) { int_ifile(ifile)->h_scrpos = *scrpos; } @@ -288,13 +288,13 @@ public void get_pos(IFILE ifile, struct scrpos *scrpos) */ public void set_open(IFILE ifile) { - int_ifile(ifile)->h_opened = 1; + int_ifile(ifile)->h_opened = TRUE; } /* * Return whether the ifile has been opened previously. */ -public int opened(IFILE ifile) +public lbool opened(IFILE ifile) { return (int_ifile(ifile)->h_opened); } diff --git a/contrib/less/input.c b/contrib/less/input.c index dda039b21a27..ac9316fe38c0 100644 --- a/contrib/less/input.c +++ b/contrib/less/input.c @@ -22,7 +22,6 @@ extern int squeeze; extern int hshift; extern int quit_if_one_screen; -extern int ignore_eoi; extern int status_col; extern int wordwrap; extern POSITION start_attnpos; diff --git a/contrib/less/jump.c b/contrib/less/jump.c index c2cd3bbb4795..472929c5c6af 100644 --- a/contrib/less/jump.c +++ b/contrib/less/jump.c @@ -194,7 +194,7 @@ static void after_header_message(void) return; last_msg = now; #endif - bell(); + lbell(); /* {{ This message displays before the file text is updated, which is not a good UX. }} */ /** error("Cannot display text before header; use --header=- to disable header", NULL_PARG); */ } @@ -243,9 +243,9 @@ public void jump_loc(POSITION pos, int sline) */ nline -= sindex; if (nline > 0) - forw(nline, position(BOTTOM_PLUS_ONE), TRUE, FALSE, FALSE, 0); + forw(nline, position(BOTTOM_PLUS_ONE), TRUE, FALSE, FALSE, FALSE, 0); else - back(-nline, position(TOP), TRUE, FALSE, FALSE); + back(-nline, position(TOP), TRUE, FALSE, FALSE, FALSE); #if HILITE_SEARCH if (show_attn) repaint_hilite(TRUE); @@ -286,7 +286,7 @@ public void jump_loc(POSITION pos, int sline) * close enough to the current screen * that we can just scroll there after all. */ - forw(sc_height-sindex+nline-1, bpos, TRUE, FALSE, FALSE, 0); + forw(sc_height-sindex+nline-1, bpos, TRUE, FALSE, FALSE, FALSE, 0); #if HILITE_SEARCH if (show_attn) repaint_hilite(TRUE); @@ -308,7 +308,7 @@ public void jump_loc(POSITION pos, int sline) lastmark(); squished = FALSE; screen_trashed_num(0); - forw(sc_height-1, pos, TRUE, FALSE, FALSE, sindex-nline); + forw(sc_height-1, pos, TRUE, FALSE, FALSE, FALSE, sindex-nline); } else { /* @@ -337,7 +337,7 @@ public void jump_loc(POSITION pos, int sline) * close enough to the current screen * that we can just scroll there after all. */ - back(nline, tpos, TRUE, FALSE, FALSE); + back(nline, tpos, TRUE, FALSE, FALSE, FALSE); #if HILITE_SEARCH if (show_attn) repaint_hilite(TRUE); @@ -347,11 +347,11 @@ public void jump_loc(POSITION pos, int sline) } lastmark(); if (!top_scroll) - clear(); + lclear(); else home(); screen_trashed_num(0); add_back_pos(pos); - back(sc_height-1, pos, TRUE, FALSE, FALSE); + back(sc_height-1, pos, TRUE, FALSE, FALSE, FALSE); } } diff --git a/contrib/less/lang.h b/contrib/less/lang.h index eef2eb7930ee..6559c720e98b 100644 --- a/contrib/less/lang.h +++ b/contrib/less/lang.h @@ -53,5 +53,8 @@ typedef __int64 ssize_t; typedef __int32 ssize_t; #endif #endif +#ifdef __BORLANDC__ +typedef long ssize_t; +#endif #endif // LESS_LANG_H_ diff --git a/contrib/less/less.h b/contrib/less/less.h index a30693a35a7a..5dd04b6cdcb9 100644 --- a/contrib/less/less.h +++ b/contrib/less/less.h @@ -52,9 +52,6 @@ #if HAVE_CTYPE_H #include <ctype.h> #endif -#if HAVE_WCTYPE_H -#include <wctype.h> -#endif #if HAVE_LIMITS_H #include <limits.h> #endif @@ -266,6 +263,11 @@ typedef off_t LINENUM; #endif #endif +/* Use iread() to read tty? */ +#if !MSDOS_COMPILER || MSDOS_COMPILER == DJGPPC +#define LESS_IREAD_TTY 1 +#endif + /* * Flags for creat() */ @@ -675,3 +677,12 @@ unsigned long lstrtoulc(constant char*, constant char**, int); #if MSDOS_COMPILER==WIN32C int pclose(FILE*); #endif +#if !HAVE_STRCHR +char * strchr(char *s, char c); +#endif +#if !HAVE_MEMCPY +void * memcpy(void *dst, constant void *src, size_t len); +#endif +#if !HAVE_STRSTR +char * strstr(constant char *haystack, constant char *needle); +#endif diff --git a/contrib/less/less.hlp b/contrib/less/less.hlp index 74570f663980..8fb524936fcd 100644 --- a/contrib/less/less.hlp +++ b/contrib/less/less.hlp @@ -29,6 +29,7 @@ ESC-{ ^LeftArrow Left to first column. F Forward forever; like "tail -f". ESC-F Like F but stop when search pattern is found. + ESC-f Like F but ring the bell when search pattern is found. r ^R ^L Repaint screen. R Repaint screen, discarding buffered input. --------------------------------------------------- @@ -219,6 +220,8 @@ -# [_N] .... --shift=[_N] Set horizontal scroll amount (0 = one half screen width). + --autosave=[_m_/_!_*] + Actions which cause the history file to be saved. --exit-follow-on-close Exit F command on a pipe when writer closes pipe. --file-size diff --git a/contrib/less/less.nro b/contrib/less/less.nro index ae43e8851d0e..8638df0de5b2 100644 --- a/contrib/less/less.nro +++ b/contrib/less/less.nro @@ -1,26 +1,81 @@ '\" t -.TH LESS 1 "Version 685: 04 Oct 2025" +.TH LESS 1 "10 Jan 2026" "less 691" +.\" Define a string for the caret ("hat") as portably as possible. +.ie \n(.g .ds ^ \(ha +.el .ds ^ ^ +.\" Define a string for the tilde as portably as possible. +.ie \n(.g .ds ~ \(ti +.el .ds ~ ~ +.\" Define a string for the neutral apostrophe as portably as possible. +.ie \n(.g .ds ' \(aq +.el .ds ' ' +.\" Define a string to interpolate the hyphenless break point escape +.\" sequence (for URLs and similar) if the formatter claims groff +.\" compatibility, else interpolate nothing. +.ie \n(.g .ds : \: +.el .ds : \" empty .SH NAME less \- display the contents of a file in a terminal .SH SYNOPSIS +.HP +.nr sA \n(.j \" Save the adjustment mode. +.na +.B less +.\" AT&T man(7) macros accept six arguments at most. +.RB [ \- [ + ] aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX\*~\c +] +.RB [ \-b\ \c +.IR size ] +.RB [ \-D\ \c +.IR color ] +.RB [ \-h\ \c +.IR lines ] +.RB [ \-j\ \c +.IR line ] +.RB [ \-k\ \c +.IR key-file ] +.RB [ \- { o | O\c +} +.IR log-file ] +.RB [ \-p\ \c +.I pattern ] +.RB [ \-P\ \c +.IR prompt ] +.RB [ \-t\ \c +.IR tag ] +.RB [ \-T\ \c +.IR tags-file ] +.RB [ \-x\ \c +.IR tab [{\c +.BI , tab\c +}.\|.\|.]]\& +.RB [ \-y\ \c +.IR lines ] +.RB [ \-z\ \c +.IR lines ] +.RB [ \-\c +.IR lines ] +.\" Work around bugs in the man(7) font selection macros in Solaris 10, +.\" Plan 9, and DWB 3.3 troffs. +.\".RB [ "\-\[dq]\c"\" works with groff, mandoc, and Heirloom Doctools +[\fB\-"\c +.IR cc ] +.RB [ \-#\ \c +.IR shift ] +.RB [ +\c +.IR less-command ] +.RB [ \-\- ] +.RI [ file \ .\|.\|.] +.ad \n(sA \" Restore the adjustment mode. +.PP .B "less \-?" .br .B "less \-\-help" -.br +.PP .B "less \-V" .br .B "less \-\-version" -.br -.B "less [\-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX\(ti]" -.br -.B " [\-b \fIspace\/\fP] [\-h \fIlines\/\fP] [\-j \fIline\/\fP] [\-k \fIkeyfile\/\fP]" -.br -.B " [\-{oO} \fIlogfile\/\fP] [\-p \fIpattern\/\fP] [\-P \fIprompt\/\fP] [\-t \fItag\/\fP]" -.br -.B " [\-T \fItagsfile\/\fP] [\-x \fItab\/\fP,...] [\-y \fIlines\/\fP] [\-[z] \fIlines\/\fP]" -.br -.B " [\-# \fIshift\/\fP] [+[+]\fIcmd\/\fP] [\-\-] [\fIfilename\/\fP]..." -.br +.PP (See the OPTIONS section for alternate option syntax with long option names.) . .SH DESCRIPTION @@ -47,35 +102,39 @@ Commands may be preceded by a decimal number, called N in the descriptions below. The number is used by some commands, as indicated. .PP -In the following descriptions, \(haX means control-X. +In the following descriptions, \*^X means control-X. ESC stands for the ESCAPE key; for example ESC-v means the two character sequence "ESCAPE", then "v". .IP "h or H" Help: display a summary of these commands. If you forget all the other commands, remember this one. -.IP "SPACE or \(haV or f or \(haF" -Scroll forward N lines, default one window (see option \-z below). +.IP "SPACE or \*^V or f or \*^F" +Scroll forward N lines, default one window (see option +.B \-z +below). If N is more than the screen size, only the final screenful is displayed. -Warning: some systems use \(haV as a special literalization character. +Warning: some systems use \*^V as a special literalization character. .IP "z" Like SPACE, but if N is specified, it becomes the new window size. -.IP "ENTER or RETURN or \(haN or e or \(haE or j or \(haJ" +.IP "ENTER or RETURN or \*^N or e or \*^E or j or \*^J" Scroll forward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size. -.IP "d or \(haD" +.IP "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. -.IP "b or \(haB or ESC-v" -Scroll backward N lines, default one window (see option \-z below). +.IP "b or \*^B or ESC-v" +Scroll backward N lines, default one window (see option +.B "\-z" +below). If N is more than the screen size, only the final screenful is displayed. .IP "w" Like ESC-v, but if N is specified, it becomes the new window size. -.IP "y or \(haY or \(haP or k or \(haK" +.IP "y or \*^Y or \*^P or k or \*^K" Scroll backward N lines, default 1. The entire N lines are displayed, even if N is more than the screen size. -Warning: some systems use \(haY as a special job control character. -.IP "u or \(haU" +Warning: some systems use \*^Y as a special job control character. +.IP "u or \*^U" Scroll backward N lines, default one half of the screen size. If N is specified, it becomes the new default for subsequent d and u commands. @@ -96,21 +155,33 @@ A file line is a complete line in the file, terminated by a newline. Scroll backwards N file lines, default 1. .IP "ESC-) or RIGHTARROW" Scroll horizontally right N characters, default half the screen width -(see the \-# option). +(see the +.B "\-#" +option). If a number N is specified, it becomes the default for future RIGHTARROW and LEFTARROW commands. -While the text is scrolled, it acts as though the \-S option +While the text is scrolled, it acts as though the +.B "\-S" +option (chop lines) were in effect. .IP "ESC-( or LEFTARROW" Scroll horizontally left N characters, default half the screen width -(see the \-# option). +(see the +.B "\-#" +option). If a number N is specified, it becomes the default for future RIGHTARROW and LEFTARROW commands. -.IP "ESC-} or \(haRIGHTARROW" +.IP "ESC-} or \*^RIGHTARROW or END" Scroll horizontally right to show the end of the longest displayed line. -.IP "ESC-{ or \(haLEFTARROW" +.IP "ESC-{ or \*^LEFTARROW or HOME" Scroll horizontally left back to the first column. -.IP "r or \(haR or \(haL" +.IP "\*^END or SHIFT-END" +Go to line N in the file, default the end of the file, and +scroll horizontally right to show the end of the longest displayed line. +.IP "\*^HOME or SHIFT-HOME" +Go to line N in the file, default 1 (beginning of file), +and scroll horizontally left back to the first column. +.IP "r or \*^R or \*^L" Repaint the screen. .IP R Repaint the screen, discarding any buffered input. @@ -123,14 +194,21 @@ Normally this command would be used when already at the end of the file. It is a way to monitor the tail of a file which is growing while it is being viewed. (The behavior is similar to the "tail \-f" command.) -To stop waiting for more data, enter the interrupt character (usually \(haC). +To stop waiting for more data, enter the interrupt character (usually \*^C). On systems which support .BR poll (2) -you can also use \(haX or the character specified by the \-\-intr option. -If the input is a pipe and the \-\-exit-follow-on-close option is in effect, +you can also use \*^X or the character specified by the +.B "\-\-intr" +option. +If the input is a pipe and the +.B "\-\-exit\-follow\-on\-close" +option is in effect, .B less will automatically stop waiting for data when the input side of the pipe is closed. +.IP "ESC-f" +Like F, but each time a line is found which matches +the last search pattern, the terminal bell is rung. .IP "ESC-F" Like F, but as soon as a line is found which matches the last search pattern, the terminal bell is rung @@ -175,40 +253,44 @@ Like }, but applies to parentheses rather than curly brackets. Like {, but applies to square brackets rather than curly brackets. .IP "]" Like }, but applies to square brackets rather than curly brackets. -.IP "ESC-\(haF" +.IP "ESC-\*^F" Followed by two characters, acts like {, but uses the two characters as open and close brackets, respectively. -For example, "ESC \(haF < >" could be used to +For example, "ESC \*^F < >" could be used to go forward to the > which matches the < in the top displayed line. -.IP "ESC-\(haB" +.IP "ESC-\*^B" Followed by two characters, acts like }, but uses the two characters as open and close brackets, respectively. -For example, "ESC \(haB < >" could be used to +For example, "ESC \*^B < >" could be used to go backward to the < which matches the > in the bottom displayed line. .IP m Followed by any lowercase or uppercase letter, marks the first displayed line with that letter. -If the status column is enabled via the \-J option, +If the status column is enabled via the +.B "\-J" +option, the status column shows the marked line. .IP M Acts like m, except the last displayed line is marked rather than the first displayed line. -.IP "\(aq" +.IP "\*'" (Single quote.) Followed by any lowercase or uppercase letter, 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" movement command was executed. -Followed by a \(ha or $, jumps to the beginning or end of the +Followed by a \*^ or $, jumps to the beginning or end of the file respectively. Marks are preserved when a new file is examined within a single invocation of .BR less , -so the \(aq command can be used to switch between input files. -The \-\-save-marks option causes marks to be preserved across different invocations of +so the \*' command can be used to switch between input files. +The +.B "\-\-save\-marks" +option causes marks to be preserved across different invocations of .BR less . -.IP "\(haX\(haX" +.IP "\*^X\*^X" Same as single quote. .IP "ESC-m" Followed by any lowercase or uppercase letter, @@ -219,86 +301,104 @@ N defaults to 1. The pattern is a regular expression, as recognized by the regular expression library supplied by your system. By default, searching is case-sensitive (uppercase and lowercase -are considered different); the \-i option can be used to change this. +are considered different); the +.B "\-i" +option can be used to change this. The search starts at the first line displayed -(but see the \-a and \-j options, which change this). -.sp +(but see the +.B "\-a" +and +.B "\-j" +options, which change this). +.IP Certain characters are special if entered at the beginning of the pattern; they modify the type of search rather than become part of the pattern: .RS -.IP "\(haN or !" +.IP "\*^N or !" Search for lines which do NOT match the pattern. -.IP "\(haE or *" +.IP "\*^E or *" Search multiple files. That is, if the search reaches the END of the current file without finding a match, the search continues in the next file in the command line list. -.IP "\(haF or @" +.IP "\*^F or @" Begin the search at the first line of the FIRST file in the command line list, regardless of what is currently displayed on the screen -or the settings of the \-a or \-j options. -.IP "\(haK" +or the settings of the +.B "\-a" +or +.B "\-j" +options. +.IP "\*^K" Highlight any text which matches the pattern on the current screen, but don't move to the first match (KEEP current position). -.IP "\(haR" +.IP "\*^R" Don't interpret regular expression metacharacters; that is, do a simple textual comparison. -.IP "\(haS" +.IP "\*^S" Followed by a digit N between 1 and 5. Only text which has a non-empty match for the N-th parenthesized SUB-PATTERN will be considered to match the pattern. -For example, searching for "(abc)|(def)" modified with \(haS1 +For example, searching for "(abc)|(def)" modified with \*^S1 would search for instances of "abc", but would highlight instances of both "abc" and "def". (Supported only if .B less is built with one of the regular expression libraries .BR posix ", " pcre ", or " pcre2 ".)" -Multiple \(haS modifiers can be specified, +Multiple \*^S modifiers can be specified, to match more than one sub-pattern. -.IP "\(haW" +.IP "\*^W" WRAP around the current file. That is, if the search reaches the end of the current file without finding a match, the search continues from the first line of the current file up to the line where it started. -If the \(haW modifier is set, the \(haE modifier is ignored. -.IP "\(haL" +If the \*^W modifier is set, the \*^E modifier is ignored. +.IP "\*^L" The next character is taken literally; that is, it becomes part of the pattern even if it is one of the above search modifier characters. .RE .IP ?pattern Search backward in the file for the N-th line containing the pattern. The search starts at the last line displayed -(but see the \-a and \-j options, which change this). -.sp +(but see the +.B "\-a" +and +.B "\-j" +options, which change this). +.IP Certain characters are special as in the / command: .RS -.IP "\(haN or !" +.IP "\*^N or !" Search for lines which do NOT match the pattern. -.IP "\(haE or *" +.IP "\*^E or *" Search multiple files. That is, if the search reaches the beginning of the current file without finding a match, the search continues in the previous file in the command line list. -.IP "\(haF or @" +.IP "\*^F or @" Begin the search at the last line of the last file in the command line list, regardless of what is currently displayed on the screen -or the settings of the \-a or \-j options. -.IP "\(haK" +or the settings of the +.B "\-a" +or +.B "\-j" +options. +.IP "\*^K" As in forward searches. -.IP "\(haR" +.IP "\*^R" As in forward searches. -.IP "\(haS" +.IP "\*^S" As in forward searches. -.IP "\(haW" +.IP "\*^W" WRAP around the current file. That is, if the search reaches the beginning of the current file without finding a match, the search continues from the last line of the current file up to the line where it started. -.IP "\(haL" +.IP "\*^L" As in forward searches. .RE .IP "ESC-/pattern" @@ -307,15 +407,15 @@ Same as "/*". Same as "?*". .IP n Repeat previous search, for N-th line containing the last pattern. -If the previous search was modified by \(haN, the search is made for the +If the previous search was modified by \*^N, the search is made for the N-th line NOT containing the pattern. -If the previous search was modified by \(haE, the search continues +If the previous search was modified by \*^E, the search continues in the next (or previous) file if not satisfied in the current file. -If the previous search was modified by \(haR, the search is done +If the previous search was modified by \*^R, the search is done without using regular expressions. -If the previous search was modified by \(haW, the search wraps at +If the previous search was modified by \*^W, the search wraps at the end (or beginning) of the file. -There is no effect if the previous search was modified by \(haF or \(haK. +There is no effect if the previous search was modified by \*^F or \*^K. .IP N Repeat previous search, but in the reverse direction. .IP "ESC-n" @@ -330,11 +430,15 @@ Turn off highlighting of strings matching the current search pattern. If highlighting is already off because of a previous ESC-u command, turn highlighting back on. Any search command will also turn highlighting back on. -(Highlighting can also be disabled by toggling the \-G option; +(Highlighting can also be disabled by toggling the +.B "\-G" +option; in that case search commands do not turn highlighting back on.) .IP "ESC-U" Like ESC-u but also clears the saved search pattern. -If the status column is enabled via the \-J option, +If the status column is enabled via the +.B "\-J" +option, this clears all search matches marked in the status column. .IP "&pattern" Display only lines which match the pattern; @@ -346,12 +450,12 @@ beginning of the prompt, as a reminder that some lines in the file may be hidden. Multiple & commands may be entered, in which case only lines which match all of the patterns will be displayed. -.sp +.IP Certain characters are special as in the / command: .RS -.IP "\(haN or !" +.IP "\*^N or !" Display only lines which do NOT match the pattern. -.IP "\(haR" +.IP "\*^R" Don't interpret regular expression metacharacters; that is, do a simple textual comparison. .RE @@ -373,11 +477,13 @@ If the filename consists of several files, they are all inserted into the list of files and the first one is examined. If the filename contains one or more spaces, the entire filename should be enclosed in double quotes -(also see the \-" option). -.IP "\(haX\(haV or E" +(also see the +.B "\-\[dq]" +option). +.IP "\*^X\*^V or E" Same as :e. -Warning: some systems use \(haV as a special literalization character. -On such systems, you may not be able to use \(haV. +Warning: some systems use \*^V as a special literalization character. +On such systems, you may not be able to use \*^V. .IP ":n" Examine the next file (from the list of files given in the command line). If a number N is specified, the N-th next file is examined. @@ -391,16 +497,18 @@ If a number N is specified, the N-th file in the list is examined. Remove the current file from the list of files. .IP "t" Go to the next tag, if there were more than one matches for the current tag. -See the \-t option for more details about tags. +See the +.B "\-t" +option for more details about tags. .IP "T" Go to the previous tag, if there were more than one matches for the current tag. -.IP "\(haO\(haN or \(haOn" +.IP "\*^O\*^N or \*^On" Search forward in the file for the N-th next OSC 8 hyperlink. -.IP "\(haO\(haP or \(haOp" +.IP "\*^O\*^P or \*^Op" Search backward in the file for the N-th previous OSC 8 hyperlink. -.IP "\(haO\(haL or \(haOl" +.IP "\*^O\*^L or \*^Ol" Jump to the currently selected OSC 8 hyperlink. -.IP "= or \(haG or :f" +.IP "= or \*^G or :f" Prints some information about the file being viewed, including its name and the line number and byte offset of the bottom line being displayed. @@ -411,10 +519,16 @@ and the percent of the file above the last displayed line. Followed by one of the command line option letters (see OPTIONS below), this will change the setting of that option and print a message describing the new setting. -If a \(haP (CONTROL-P) is entered immediately after the dash, +If a \*^P (CONTROL-P) is entered immediately after the dash, the setting of the option is changed but no message is printed. -If the option letter has a numeric value (such as \-b or \-h), -or a string value (such as \-P or \-t), +If the option letter has a numeric value (such as +.B "\-b" +or +.BR "\-h" ")," +or a string value (such as +.B "\-P" +or +.BR "\-t" ")," a new value may be entered after the option letter. If no new value is entered, a message describing the current setting is printed and nothing is changed. @@ -424,14 +538,16 @@ rather than a single option letter. Press ENTER or RETURN after typing the option name to change it. You can enter just the beginning of an option name, then press TAB to find all option names which begin with that string. -A \(haP immediately after the second dash suppresses printing of a +A \*^P immediately after the second dash suppresses printing of a message describing the new setting, as in the \- command. .IP \-+ Followed by one of the command line option letters this will reset the option to its default setting and print a message describing the new setting. (The "\-+\fIX\fP" command does the same thing -as "\-+\fIX\fP" on the command line.) +as +.RB "\[dq]" "\-+X" "\[dq]" +on the command line.) This does not work for string-valued options. .IP \-\-+ Like the \-+ command, but takes a long option name @@ -485,7 +601,7 @@ current file. A pound sign (#) is replaced by the name of the previously examined file. "!!" repeats the last shell command. "!" with no shell command invokes an interactive shell. -If a \(haP (CONTROL-P) is entered immediately after the !, +If a \*^P (CONTROL-P) is entered immediately after the !, no "done" message is printed after the shell command is executed. On Unix systems, the shell is taken from the environment variable SHELL, or defaults to "sh". @@ -501,17 +617,17 @@ The section of the file to be piped is between the position marked by the letter and the current screen. The entire current screen is included, regardless of whether the marked position is before or after the current screen. -<m> may also be \(ha or $ to indicate beginning or end of file respectively. +<m> may also be \*^ or $ to indicate beginning or end of file respectively. If <m> is \&.\& or newline, the current screen is piped. -If a \(haP (CONTROL-P) is entered immediately after the mark letter, +If a \*^P (CONTROL-P) is entered immediately after the mark letter, no "done" message is printed after the shell command is executed. .IP "s filename" Save the input to a file. This works only if the input is a pipe, not an ordinary file. -.IP "\(haO\(haO" +.IP "\*^O\*^O" .RS Run a shell command to open the URI in the current OSC 8 hyperlink, -selected by a previous \(haO\(haN or \(haO\(haP command. +selected by a previous \*^O\*^N or \*^O\*^P command. To find the shell command, the environment variable named "LESS_OSC8_xxx" is read, where "xxx" is the scheme from the URI (the part before the first colon), @@ -527,7 +643,7 @@ There are two special cases: .IP 1. If the URI begins with "#", the remainder of the URI is taken to be the value of the id parameter in another OSC 8 link in the same file, -and \(haO\(haO will simply jump to that link. +and \*^O\*^O will simply jump to that link. .IP 2. If the opener begins with the characters ":e" followed by whitespace and a filename, @@ -538,11 +654,13 @@ the specified filename is opened in the current instance of .PP In a simple case where the opener accepts the complete URI as a command line parameter, the handler may be as simple as +.PP +.EX .nf -.sp -echo mybrowser '%o' -.sp +echo mybrowser \*'%o\*' .fi +.EE +.PP In other cases, the URI may need to be modified, so the handler may have to do some manipulation of the %o value. .PP @@ -557,7 +675,7 @@ which should work on systems which provide the command and a shell with syntax compatible with the Bourne shell .BR sh (1). If you use LESS_OSC8_ANY to override LESS_OSC8_file, you must -set LESS_OSC8_file to "-" to indicate that the default value +set LESS_OSC8_file to "\-" to indicate that the default value should not be used, and likewise for LESS_OSC8_man. .PP The URI passed to an OSC8 handler via %o is guaranteed not to contain any single quote @@ -571,9 +689,9 @@ any metacharacters interpreted by prompt expansion (such as percent, dot, colon, backslash, etc.) must be escaped with a backslash (see the PROMPTS section for details). .RE -.IP "\(haX" +.IP "\*^X" When the "Waiting for data" message is displayed, -such as while in the F command, pressing \(haX +such as while in the F command, pressing \*^X will stop .B less from waiting and return to a prompt. @@ -581,14 +699,16 @@ This may cause .B less to think that the file ends at the current position, so it may be necessary to use the R or F command to see more data. -The \-\-intr option can be used to specify a different character -to use instead of \(haX. +The +.B "\-\-intr" +option can be used to specify a different character +to use instead of \*^X. This command works only on systems that support the .BR poll (2) function. On systems without .BR poll (2), -the interrupt character (usually \(haC) can be used instead. +the interrupt character (usually \*^C) can be used instead. . .SH OPTIONS Command line options are described below. @@ -601,13 +721,30 @@ either a dash followed by a single letter, or two dashes followed by a long option name. A long option name may be abbreviated as long as the abbreviation is unambiguous. -For example, \-\-mouse may be abbreviated \-\-mou, but not -\-\-mo, since both \-\-mouse and \-\-modelines begin with \-\-mo. -Some long option names are in uppercase, such as \-\-QUIT-AT-EOF, as -distinct from \-\-quit-at-eof. +For example, +.B "\-\-mouse" +may be abbreviated +.BR "\-\-mou" "," +but not +.BR "\-\-mo" "," +since both +.B "\-\-mouse" +and +.B "\-\-modelines" +begin with +.BR "\-\-mo" "." + +Some long option names are in uppercase, such as +.BR "\-\-QUIT\-AT\-EOF" "," +as +distinct from +.BR "\-\-quit\-at\-eof" "." Such option names need only have their first letter capitalized; the remainder of the name may be in either case. -For example, \-\-Quit-at-eof is equivalent to \-\-QUIT-AT-EOF. +For example, +.B "\-\-Quit\-at\-eof" +is equivalent to +.BR "\-\-QUIT\-AT\-EOF" "." .PP Options are also taken from the environment variable "LESS". For example, @@ -615,53 +752,70 @@ to avoid typing "less \-options \&...\&" each time .B less is invoked, you might tell .BR csh : -.sp +.PP setenv LESS "\-options" -.sp +.PP or if you use .BR sh : -.sp +.PP LESS="\-options"; export LESS -.sp +.PP On MS-DOS and Windows, you don't need the quotes, but you should be careful that any percent signs in the options string are not interpreted as an environment variable expansion. -.sp +.PP The environment variable is parsed before the command line, so command line options override the LESS environment variable. If an option appears in the LESS variable, it can be reset to its default value on the command line by beginning the command -line option with "\-+". -.sp -Some options like \-k or \-D require a string to follow the option letter. +line option with +.RB "\[dq]" "\-+" "\[dq]." +.PP +Some options like +.B "\-k" +or +.B "\-D" +require a string to follow the option letter. The string for that option is considered to end when a dollar sign ($) is found. -For example, you can set two \-D options like this: -.sp +For example, you can set two +.B "\-D" +options like this: +.PP +.EX LESS="Dnwb$Dsbw" -.sp -If the \-\-use-backslash option appears earlier in the options, then +.EE +.PP +If the +.B "\-\-use\-backslash" +option appears earlier in the options, then a dollar sign or backslash may be included literally in an option string by preceding it with a backslash. -If the \-\-use-backslash option is not in effect, then backslashes are +If the +.B "\-\-use\-backslash" +option is not in effect, then backslashes are not treated specially, and there is no way to include a dollar sign in the option string. -.IP "\-? or \-\-help" +.IP "\fB\-?\fP or \fB\-\-help\fP" This option displays a summary of the commands accepted by .B less (the same as the h command). (Depending on how your shell interprets the question mark, -it may be necessary to quote the question mark, thus: "\-\e?".) -.IP "\-a or \-\-search-skip-screen" +it may be necessary to quote the question mark, thus: "\fB\-\e?\fP".) +.IP "\fB\-a\fP or \fB\-\-search\-skip\-screen\fP" By default, forward searches start at the top of the displayed screen and backwards searches start at the bottom of the displayed screen (except for repeated searches invoked by the n or N commands, which start after or before the "target" line respectively; -see the \-j option for more about the target line). -The \-a option causes forward searches to instead start at +see the +.B "\-j" +option for more about the target line). +The +.B "\-a" +option causes forward searches to instead start at the bottom of the screen and backward searches to start at the top of the screen, thus skipping all lines displayed on the screen. -.IP "\-A or \-\-SEARCH-SKIP-SCREEN" +.IP "\fB\-A\fP or \fB\-\-SEARCH\-SKIP\-SCREEN\fP" Causes all forward searches (not just non-repeated searches) to start just after the target line, and all backward searches to start just before the target line. @@ -670,45 +824,61 @@ Thus, forward searches will skip part of the displayed screen Similarly backwards searches will skip the displayed screen from the last line up to and including the target line. This was the default behavior in less versions prior to 441. -.IP "\-b\fIn\fP or \-\-buffers=\fIn\fP" +.IP "\fB\-b\fP\fIn\fP or \fB\-\-buffers=\fP\fIn\fP" Specifies the amount of buffer space .B less will use for each file, in units of kilobytes (1024 bytes). By default 64\ KB of buffer space is used for each file -(unless the file is a pipe; see the \-B option). -The \-b option specifies instead that \fIn\fP kilobytes of +(unless the file is a pipe; see the +.B "\-B" +option). +The +.B "\-b" +option specifies instead that \fIn\fP kilobytes of buffer space should be used for each file. If \fIn\fP is \-1, buffer space is unlimited; that is, the entire file can be read into memory. -.IP "\-B or \-\-auto-buffers" +.IP "\fB\-B\fP or \fB\-\-auto\-buffers\fP" 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, +The +.B "\-B" +option disables this automatic allocation of buffers for pipes, so that only 64\ KB -(or the amount of space specified by the \-b option) +(or the amount of space specified by the +.B "\-b" +option) is used for the pipe. -Warning: use of \-B can result in erroneous display, since only the +Warning: use of +.B "\-B" +can result in erroneous display, since only the most recently viewed part of the piped data is kept in memory; any earlier data is lost. Lost characters are displayed as question marks. -.IP "\-c or \-\-clear-screen" +.IP "\fB\-c\fP or \fB\-\-clear\-screen\fP" Causes full screen repaints to be painted from the top line down. By default, full screen repaints are done by scrolling from the bottom of the screen. -.IP "\-C or \-\-CLEAR-SCREEN" -Same as \-c, for compatibility with older versions of +.IP "\fB\-C\fP or \fB\-\-CLEAR\-SCREEN\fP" +Same as +.BR "\-c" "," +for compatibility with older versions of .BR less . -.IP "\-d or \-\-dumb" -The \-d option suppresses the error message +.IP "\fB\-d\fP or \fB\-\-dumb\fP" +The +.B "\-d" +option suppresses the error message normally displayed if the terminal is dumb; that is, lacks some important capability, such as the ability to clear the screen or scroll backward. -The \-d option does not otherwise change the behavior of +The +.B "\-d" +option does not otherwise change the behavior of .B less on a dumb terminal. -.IP "\-D\fBx\fP\fIcolor\fP or \-\-color=\fBx\fP\fIcolor\fP" +.IP "\fB\-Dx\fP\fIcolor\fP or \fB\-\-color=x\fP\fIcolor\fP" Changes the color of different parts of the displayed text. \fBx\fP is a single character which selects the type of text whose color is being set: @@ -720,11 +890,15 @@ Control characters. .IP "E" Errors and informational messages. .IP "H" -Header lines and columns, set via the \-\-header option. +Header lines and columns, set via the +.B "\-\-header" +option. .IP "M" Mark letters in the status column. .IP "N" -Line numbers enabled via the \-N option. +Line numbers enabled via the +.B "\-N" +option. .IP "P" Prompts. .IP "R" @@ -732,8 +906,10 @@ The rscroll character. .IP "S" Search results. .IP "W" -The highlight enabled via the \-w option. -.IP "1-5" +The highlight enabled via the +.B "\-w" +option. +.IP "1\-5" The text in a search result which matches the first through fifth parenthesized sub-pattern. Sub-pattern coloring works only if @@ -749,25 +925,35 @@ Standout text. .IP "u" Underlined text. .RE - +.PP .RS -The uppercase letters and digits can be used only when the \-\-use-color option is enabled. +The uppercase letters and digits can be used only when the +.B "\-\-use\-color" +option is enabled. When text color is specified by both an uppercase letter and a lowercase letter, the uppercase letter takes precedence. For example, error messages are normally displayed as standout text. So if both "s" and "E" are given a color, the "E" color applies to error messages, and the "s" color applies to other standout text. The lowercase letters refer to bold and underline text formed by -overstriking with backspaces (see the \-U option) and to non-content +overstriking with backspaces (see the +.B "\-U" +option) and to non-content text (such as line numbers and prompts), -but not to text formatted using ANSI escape sequences with the \-R option +but not to text formatted using ANSI escape sequences with the +.B "\-R" +option (but see the note below for different behavior on Windows and MS-DOS). .PP A lowercase letter may be followed by a + to indicate that the normal format change and the specified color should both be used. -For example, \-Dug displays underlined text as green without underlining; +For example, +.B "\-Dug" +displays underlined text as green without underlining; the green color has replaced the usual underline formatting. -But \-Du+g displays underlined text as both green and in underlined format. +But +.B "\-Du+g" +displays underlined text as both green and in underlined format. .PP \fIcolor\fP is either a 4-bit color string or an 8-bit color string: .PP @@ -792,10 +978,14 @@ White Yellow .PP The corresponding uppercase letter denotes a brighter shade of the color. -For example, \-DNGk displays line numbers as bright green text on a black -background, and \-DEbR displays error messages as blue text on a +For example, +.B "\-DNGk" +displays line numbers as bright green text on a black +background, and +.B "\-DEbR" +displays error messages as blue text on a bright red background. -If either character is a "-" or is omitted, the corresponding color +If either character is a "\-" or is omitted, the corresponding color is set to that of normal text. .PP An 8-bit color string is one or two decimal integers separated by a dot, @@ -804,9 +994,9 @@ the second specifies the background color. Each integer is a value between 0 and 255 inclusive which selects a "CSI 38;5" color value (see .nh -https://en.wikipedia.org/wiki/ANSI_escape_code#SGR). +https://\*:en\*:.wikipedia\*:.org/\*:wiki/\*:ANSI_escape_code\*:#SGR). .hy -If either integer is a "-" or is omitted, +If either integer is a "\-" or is omitted, the corresponding color is set to that of normal text. .PP A 4-bit or 8-bit color string may be followed by one or more of the @@ -820,15 +1010,19 @@ Bold .IP "l or &" Blinking .PP -On MS-DOS and Windows, the \-\-color option behaves +On MS-DOS and Windows, the +.B "\-\-color" +option behaves differently from what is described above in these ways: .IP \(bu The bold (d and *) and blinking (l and &) text attributes at the end of a color string are not supported. .IP \(bu Lowercase color selector letters refer to text formatted by ANSI -escape sequences with \-R, -in addition to overstruck and non-content text (but see \-Da). +escape sequences with +.BR "\-R" "," +in addition to overstruck and non-content text (but see +.BR "\-Da" ")." .IP \(bu For historical reasons, when a lowercase color selector letter is followed by a numeric color value, @@ -840,9 +1034,9 @@ CHAR_INFO.Attributes value, between 0 and 15 inclusive (see .nh -https://learn.microsoft.com/en-us/windows/console/char-info-str). +https://\*:learn\*:.microsoft\*:.com/\*:en\-us/\*:windows/\*:console/\*:char\-info\-str). .hy - +.IP To avoid confusion, it is recommended that the equivalent letters rather than numbers be used after a lowercase color selector on MS-DOS/Windows. .IP \(bu @@ -852,15 +1046,19 @@ are not supported on systems earlier than Windows 10. Only a limited set of ANSI escape sequences to set color in the content work correctly. 4-bit color sequences work, but "CSI 38;5" color sequences do not. .IP \(bu -The \-Da option makes the behavior of \-\-color +The +.B "\-Da" +option makes the behavior of +.B "\-\-color" more similar to its behavior on non-MS-DOS/Windows systems by (1) making lowercase color selector letters not affect text formatted with ANSI escape sequences, and (2) allowing "CSI 38;5" color sequences in the content work by passing them to the terminal (only on Windows 10 and later; on -earlier Windows systems, such sequences do not work regardless of the setting of \-Da). +earlier Windows systems, such sequences do not work regardless of the setting of +.BR "\-Da" ")." .RE -.IP "\-e or \-\-quit-at-eof" +.IP "\fB\-e\fP or \fB\-\-quit\-at\-eof\fP" Causes .B less to automatically exit @@ -868,11 +1066,11 @@ the second time it reaches end-of-file. By default, the only way to exit .B less is via the "q" command. -.IP "\-E or \-\-QUIT-AT-EOF" +.IP "\fB\-E\fP or \fB\-\-QUIT\-AT\-EOF\fP" Causes .B less to automatically exit the first time it reaches end-of-file. -.IP "\-f or \-\-force" +.IP "\fB\-f\fP or \fB\-\-force\fP" 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 opened. @@ -880,41 +1078,49 @@ By default, .B less will refuse to open non-regular files. Note that some operating systems will not allow directories -to be read, even if \-f is set. -.IP "\-F or \-\-quit-if-one-screen" +to be read, even if +.B "\-f" +is set. +.IP "\fB\-F\fP or \fB\-\-quit\-if\-one\-screen\fP" Causes .B less to automatically exit if the entire file can be displayed on the first screen. Also see the description of the LESS_SHELL_LINES environment variable below. -.IP "\-g or \-\-hilite-search" +.IP "\fB\-g\fP or \fB\-\-hilite\-search\fP" Normally, .B less will highlight ALL strings which match the last search command. -The \-g option changes this behavior to highlight only the particular string +The +.B "\-g" +option changes this behavior to highlight only the particular string which was found by the last search command. This can cause .B less to run somewhat faster than the default. -.IP "\-G or \-\-HILITE-SEARCH" +.IP "\fB\-G\fP or \fB\-\-HILITE\-SEARCH\fP" The \-G option suppresses all highlighting of strings found by search commands. -.IP "\-h\fIn\fP or \-\-max-back-scroll=\fIn\fP" +.IP "\fB\-h\fP\fIn\fP or \fB\-\-max\-back\-scroll=\fP\fIn\fP" Specifies a maximum number of lines to scroll backward. If it is necessary to scroll backward more than \fIn\fP lines, the screen is repainted in a forward direction instead. (If the terminal does not have the ability to scroll -backward, \-h0 is implied.) -.IP "\-i or \-\-ignore-case" +backward, +.B "\-h0" +is implied.) +.IP "\fB\-i\fP or \fB\-\-ignore\-case\fP" Causes searches to ignore case; that is, uppercase and lowercase are considered identical. This option is ignored if any uppercase letters appear in the search pattern; in other words, if a pattern contains uppercase letters, then that search does not ignore case. -.IP "\-I or \-\-IGNORE-CASE" -Like \-i, but searches ignore case even if +.IP "\fB\-I\fP or \fB\-\-IGNORE\-CASE\fP" +Like +.BR "\-i" "," +but searches ignore case even if the pattern contains uppercase letters. -.IP "\-j\fIn\fP or \-\-jump-target=\fIn\fP" +.IP "\fB\-j\fP\fIn\fP or \fB\-\-jump\-target=\fP\fIn\fP" Specifies a line on the screen where the "target" line is to be positioned. The target line is the line specified by any command to @@ -930,28 +1136,40 @@ of the screen, starting with a decimal point: \&.5 is in the middle of the screen, \&.3 is three tenths down from the first line, and so on. If the line is specified as a fraction, the actual line number is recalculated if the terminal window is resized. -If the \-\-header option is used and the target line specified by \-j +If the +.B "\-\-header" +option is used and the target line specified by +.B "\-j" would be obscured by the header, the target line is moved to the first line after the header. .RS .PP -If any form of the \-j option is used, +If any form of the +.B "\-j" +option is used, repeated forward searches (invoked with "n" or "N") begin at the line immediately after the target line, and repeated backward searches begin at the target line, -unless changed by \-a or \-A. -For example, if "\-j4" is used, the target line is the +unless changed by +.B "\-a" +or +.BR "\-A" "." +For example, if +.RB "\[dq]" "\-j4" "\[dq]" +is used, the target line is the fourth line on the screen, so forward searches begin at the fifth line on the screen. However nonrepeated searches (invoked with "/" or "?") -always begin at the start or end of the current screen respectively. +always begin at the first or last line on the screen respectively. .RE -.IP "\-J or \-\-status-column" +.IP "\fB\-J\fP or \fB\-\-status\-column\fP" Displays a status column at the left edge of the screen. The character displayed in the status column may be one of: .RS .IP ">" -The line is chopped with the \-S option, and +The line is chopped with the +.B "\-S" +option, and the text that is chopped off beyond the right edge of the screen contains a match for the current search. .IP "<" @@ -966,21 +1184,30 @@ There are matches in the visible part of the line but none to the right or left of it. .IP "a-z, A-Z" The line has been marked with the corresponding letter via the m or M command. +.IP "#" +The line has been marked by left-clicking it with the mouse +when the +.B "\-\-mouse" +option is in effect. .RE -.IP "\-k\fIfilename\fP or \-\-lesskey-file=\fIfilename\fP" +.IP "\fB\-k\fP\fIfilename\fP or \fB\-\-lesskey\-file=\fP\fIfilename\fP" Causes .B less to open and interpret the named file as a .BR lesskey (1) binary file. -Multiple \-k options may be specified. +Multiple +.B "\-k" +options may be specified. If the LESSKEY or LESSKEY_SYSTEM environment variable is set, or if a lesskey file is found in a standard place (see KEY BINDINGS), it is also used as a .B lesskey file. -Note the warning under "\-\-lesskey-content" below. -.IP "\-\-lesskey-src=\fIfilename\fP" +Note the warning under +.B "\-\-lesskey\-content" +below. +.IP "\fB\-\-lesskey\-src=\fP\fIfilename\fP" Causes .B less to open and interpret the named file as a @@ -1002,8 +1229,10 @@ Newer versions of .B less read the lesskey source file directly and ignore the binary file if the source file exists. -Note the warning under "\-\-lesskey-content" below. -.IP "\-\-lesskey-content=\fItext\fP" +Note the warning under +.B "\-\-lesskey\-content" +below. +.IP "\fB\-\-lesskey\-content=\fP\fItext\fP" Causes .B less to interpret the specified text as the contents of a @@ -1013,35 +1242,34 @@ In the text, .B lesskey lines may be separated by either newlines as usual, or by semicolons. A literal semicolon may be represented by a backslash followed by a semicolon. -.sp +.IP Warning: certain environment variables such as LESS, LESSSECURE, LESSCHARSET and others, which are used early in startup, cannot be set in a file specified by a command line option -(\-\-lesskey, \-\-lesskey-src or \-\-lesskey-content). When using a +.RB "(" "\-\-lesskey" "," "\-\-lesskey\-src" " or " "\-\-lesskey\-content" ")." +When using a .B lesskey file to set environment variables, it is safer to use the default lesskey file, or to specify the file using the LESSKEYIN or LESSKEY_CONTENT environment variables rather than using a command line option. -.IP "\-K or \-\-quit-on-intr" +.IP "\fB\-K\fP or \fB\-\-quit\-on\-intr\fP" Causes .B less to exit immediately (with status 2) -when an interrupt character (usually \(haC) is typed. +when an interrupt character (usually \*^C) is typed. Normally, an interrupt character causes .B less to stop whatever it is doing and return to its command prompt. -Note that use of this option makes it impossible to return to the -command prompt from the "F" command. -.IP "\-L or \-\-no-lessopen" +.IP "\fB\-L\fP or \fB\-\-no\-lessopen\fP" Ignore the LESSOPEN environment variable (see the INPUT PREPROCESSOR section below). This option can be set from within .BR less , but it will apply only to files opened subsequently, not to the file which is currently open. -.IP "\-m or \-\-long-prompt" +.IP "\fB\-m\fP or \fB\-\-long\-prompt\fP" Causes .B less to prompt verbosely (like @@ -1050,12 +1278,12 @@ with the percent into the file. By default, .B less prompts with a colon. -.IP "\-M or \-\-LONG-PROMPT" +.IP "\fB\-M\fP or \fB\-\-LONG\-PROMPT\fP" Causes .B less to prompt even more verbosely than .BR more (1). -.IP "\-n or \-\-line-numbers" +.IP "\fB\-n\fP or \fB\-\-line\-numbers\fP" Suppresses line numbers. The default (to use line numbers) may cause .B less @@ -1064,10 +1292,10 @@ 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 line number to the editor (see also the discussion of LESSEDIT in PROMPTS below). -.IP "\-N or \-\-LINE-NUMBERS" +.IP "\fB\-N\fP or \fB\-\-LINE\-NUMBERS\fP" Causes a line number to be displayed at the beginning of each line in the display. -.IP "\-o\fIfilename\fP or \-\-log-file=\fIfilename\fP" +.IP "\fB\-o\fP\fIfilename\fP or \fB\-\-log\-file=\fP\fIfilename\fP" Causes .B less to copy its input to the named file as it is being viewed. @@ -1076,24 +1304,34 @@ not an ordinary file. If the file already exists, .B less will ask for confirmation before overwriting it. -.IP "\-O\fIfilename\fP or \-\-LOG-FILE=\fIfilename\fP" -The \-O option is like \-o, but it will overwrite an existing +.IP "\fB\-O\fP\fIfilename\fP or \fB\-\-LOG\-FILE=\fP\fIfilename\fP" +The +.B "\-O" +option is like +.B "\-o," +but it will overwrite an existing file without asking for confirmation. -.sp +.IP If no log file has been specified, -the \-o and \-O options can be used from within +the +.B "\-o" +and +.B "\-O" +options can be used from within .B less to specify a log file. Without a file name, they will simply report the name of the log file. -The "s" command is equivalent to specifying \-o from within +The "s" command is equivalent to specifying +.B "\-o" +from within .BR less . -.IP "\-p\fIpattern\fP or \-\-pattern=\fIpattern\fP" +.IP "\fB\-p\fP\fIpattern\fP or \fB\-\-pattern=\fP\fIpattern\fP" The \-p option on the command line is equivalent to specifying +/\fIpattern\fP; that is, it tells .B less to start at the first occurrence of \fIpattern\fP in the file. -.IP "\-P\fIprompt\fP or \-\-prompt=\fIprompt\fP" +.IP "\fB\-P\fP\fIprompt\fP or \fB\-\-prompt=\fP\fIprompt\fP" Provides a way to tailor the three prompt styles to your own preference. This option would normally be put in the LESS environment @@ -1102,18 +1340,37 @@ variable, rather than being typed in with each command. Such an option must either be the last option in the LESS variable, or be terminated by a dollar sign. - \-Ps followed by a string changes the default (short) prompt +.PP +.RS +.TP +\fB\-Ps\fP +followed by a string changes the default (short) prompt to that string. - \-Pm changes the medium (\-m) prompt. - \-PM changes the long (\-M) prompt. - \-Ph changes the prompt for the help screen. - \-P= changes the message printed by the = command. - \-Pw changes the message printed while waiting for data (in the "F" command). -.sp 1 +.TP +\fB\-Pm\fP +changes the medium +.RB "(" "\-m" ")" +prompt. +.TP +\fB\-PM\fP +changes the long +.RB "(" "\-M" ")" +prompt. +.TP +\fB\-Ph\fP +changes the prompt for the help screen. +.TP +\fB\-P=\fP +changes the message printed by the = command. +.TP +\fB\-Pw\fP +changes the message printed while waiting for data (in the "F" command). +.RE +.IP All prompt strings consist of a sequence of letters and special escape sequences. See the section on PROMPTS for more details. -.IP "\-q or \-\-quiet or \-\-silent" +.IP "\fB\-q\fP or \fB\-\-quiet\fP or \fB\-\-silent\fP" Causes moderately "quiet" operation: the terminal bell is not rung if an attempt is made to scroll past the end of the file @@ -1122,56 +1379,73 @@ 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. -.IP "\-Q or \-\-QUIET or \-\-SILENT" +.IP "\fB\-Q\fP or \fB\-\-QUIET\fP or \fB\-\-SILENT\fP" Causes totally "quiet" operation: the terminal bell is never rung. If the terminal has a "visual bell", it is used in all cases where the terminal bell would have been rung. -.IP "\-r or \-\-raw-control-chars" +.IP "\fB\-r\fP or \fB\-\-raw\-control\-chars\fP" Causes "raw" control characters to be displayed. The default is to display control characters using the caret notation; -for example, a control-A (octal 001) is displayed as "\(haA" -(with some exceptions as described under the \-U option). -Warning: when the \-r option is used, +for example, a control-A (octal 001) is displayed as "\*^A" +(with some exceptions as described under the +.B "\-U" +option). +Warning: when the +.B "\-r" +option is used, .B less cannot keep track of the actual appearance of the screen (since this depends on how the screen responds to each type of control character). Thus, various display problems may result, such as long lines being split in the wrong place. -.sp -USE OF THE \-r OPTION IS DANGEROUS AND IS NOT RECOMMENDED. +.IP +USE OF THE +.B "\-r" +OPTION IS DANGEROUS AND IS NOT RECOMMENDED. .br -The \-r option can be set on the command line or via the \- command, +The +.B "\-r" +option can be set on the command line or via the \- command, but to avoid unintentional use, it cannot be set in a LESS environment variable. -If \-r appears in a LESS environment variable, it is treated as if it were \-R. -.IP "\-R or \-\-RAW-CONTROL-CHARS" -Like \-r, but only a limited set of escape +If +.B "\-r" +appears in a LESS environment variable, it is treated as if it were +.BR "\-R" "." +.IP "\fB\-R\fP or \fB\-\-RAW\-CONTROL\-CHARS\fP" +Like +.BR "\-r" "," +but only a limited set of escape sequences are output in "raw" form. -Unlike \-r, the screen appearance is maintained correctly. +Unlike +.BR "\-r" "," +the screen appearance is maintained correctly. The sequences which are output raw are: -.sp +.IP 1. ANSI SGR ("color") sequences -.sp +.IP 2. OSC 8 hyperlinks -.sp +.IP 3. Other OSC sequences, if the OSC type number is listed in the LESSANSIOSCALLOW environment variable -.sp +.IP 4. OSC sequences starting with a non-standard introductory character (that is, something other than "]"), if the character is listed in the LESSANSIOSCCHARS environment variable followed by an asterisk -.sp +.IP ANSI color escape sequences are sequences of the form: -.sp +.IP +.EX ESC [ \&...\& m -.sp +.EE +.IP where the "...\&" is zero or more color specification characters. Color escape sequences are only supported when the color is changed within one line, not across lines. In other words, the beginning of each line is assumed to be normal (non-colored), regardless of any escape sequences in previous lines. -.sp +.IP You can make .B less think that characters other than "m" can end ANSI color escape sequences @@ -1182,31 +1456,41 @@ And you can make think that characters other than the standard ones may appear between the ESC and the m by setting the environment variable LESSANSIMIDCHARS to the list of characters which can appear. -.sp +.IP OSC sequences are of the form: -.sp - ESC ] N ; \&...\& \\7 -.sp +.IP +.EX + ESC ] N ; \&...\& \e7 +.EE +.IP where the OSC type number N is a decimal integer. -The terminating sequence may be either a BEL character (\\7) -as above, or the two-character sequence "ESC \\". -.IP "\-s or \-\-squeeze-blank-lines" +The terminating sequence may be either a BEL character (\e7) +as above, or the two-character sequence "ESC \e". +.IP "\fB\-s\fP or \fB\-\-squeeze\-blank\-lines\fP" Causes consecutive blank lines to be squeezed into a single blank line. This is useful when viewing .BR nroff (1) output. -.IP "\-S or \-\-chop-long-lines" +.IP "\fB\-S\fP or \fB\-\-chop\-long\-lines\fP" Causes lines longer than the screen width to be chopped (truncated) rather than wrapped. That is, the portion of a long line that does not fit in the screen width is not displayed until you press RIGHT-ARROW. The default is to wrap long lines; that is, display the remainder on the next line. -See also the \-\-wordwrap option. -While the \-\-header option is active, the \-S option is ignored, +See also the +.B "\-\-wordwrap" +option. +While the +.B "\-\-header" +option is active, the +.B "\-S" +option is ignored, and lines longer than the screen width are truncated. -.IP "\-t\fItag\fP or \-\-tag=\fItag\fP" -The \-t option, followed immediately by a TAG, +.IP "\fB\-t\fP\fItag\fP or \fB\-\-tag=\fP\fItag\fP" +The +.B "\-t" +option, followed immediately by a TAG, will edit the file containing that tag. For this to work, tag information must be available; for example, there may be a file in the current directory called "tags", @@ -1219,24 +1503,34 @@ the name of a command compatible with and that command is executed to find the tag. (See .nh -http://www.gnu.org/software/global/global.html). +http://\*:www\*:.gnu\*:.org/\*:software/\*:global/\*:global\*:.html). .hy -The \-t option may also be specified from within +The +.B "\-t" +option may also be specified from within .B less (using the \- command) as a way of examining a new file. -The command ":t" is equivalent to specifying \-t from within +The command ":t" is equivalent to specifying +.B "\-t" +from within .BR less . -.IP "\-T\fItagsfile\fP or \-\-tag-file=\fItagsfile\fP" +.IP "\fB\-T\fP\fItagsfile\fP or \fB\-\-tag\-file=\fP\fItagsfile\fP" Specifies a tags file to be used instead of "tags". -.IP "\-u or \-\-underline-special" +.IP "\fB\-u\fP or \fB\-\-underline\-special\fP" Causes backspaces and carriage returns to be treated as printable characters; that is, they are sent to the terminal when they appear in the input. -.IP "\-U or \-\-UNDERLINE-SPECIAL" +.IP "\fB\-U\fP or \fB\-\-UNDERLINE\-SPECIAL\fP" Causes backspaces, tabs, carriage returns and "formatting characters" (as defined by Unicode) to be treated as control characters; -that is, they are handled as specified by the \-r option. -.sp -By default, if neither \-u nor \-U is given, +that is, they are handled as specified by the +.B "\-r" +option. +.IP +By default, if neither +.B "\-u" +nor +.B "\-U" +is given, backspaces which appear adjacent to an underscore character are treated specially: the underlined text is displayed @@ -1247,53 +1541,76 @@ the overstruck text is printed using the terminal's hardware boldface capability. Other backspaces are deleted, along with the preceding character. Carriage returns immediately followed by a newline are deleted. -Other carriage returns are handled as specified by the \-r option. +Other carriage returns are handled as specified by the +.B "\-r" +option. Unicode formatting characters, such as the Byte Order Mark, are sent to the terminal. Text which is overstruck or underlined can be searched for -if neither \-u nor \-U is in effect. -.sp -See also the \-\-proc-backspace, \-\-proc-tab, -and \-\-proc-return options. -.IP "\-V or \-\-version" +if neither +.B "\-u" +nor +.B "\-U" +is in effect. +.IP +See also the +.BR "\-\-proc\-backspace" "," "\-\-proc\-tab" ", and " "\-\-proc\-return" +options. +.IP "\fB\-V\fP or \fB\-\-version\fP" Displays the version number of .BR less . -.IP "\-w or \-\-hilite-unread" +.IP "\fB\-w\fP or \fB\-\-hilite\-unread\fP" Temporarily highlights the first "new" line after a forward movement of a full page. The first "new" line is the line immediately following the line previously at the bottom of the screen. Also highlights the target line after a g or p command. The highlight is removed at the next command which causes movement. -If the \-\-status-line option is in effect, the entire line +If the +.B "\-\-status\-line" +option is in effect, the entire line (the width of the screen) is highlighted. Otherwise, only the text in the line is highlighted, -unless the \-J option is in effect, +unless the +.B "\-J" +option is in effect, in which case only the status column is highlighted. -.IP "\-W or \-\-HILITE-UNREAD" -Like \-w, but temporarily highlights the first new line after any +.IP "\fB\-W\fP or \fB\-\-HILITE\-UNREAD\fP" +Like +.BR "\-w" "," +but temporarily highlights the first new line after any forward movement command larger than one line. -.IP "\-x\fIn\fP,...\& or \-\-tabs=\fIn\fP,..." +.IP "\fB\-x\fP\fIn\fP,...\& or \fB\-\-tabs=\fP\fIn\fP,..." Sets tab stops. If only one \fIn\fP is specified, tab stops are set at multiples of \fIn\fP. If multiple values separated by commas are specified, tab stops are set at those positions, and then continue with the same spacing as the last two. -For example, "-x9,17" will set tabs at positions 9, 17, 25, 33, etc. +For example, +.RB "\[dq]" "\-x9,17" "\[dq]" +will set tabs at positions 9, 17, 25, 33, etc. The default for \fIn\fP is 8. -.IP "\-X or \-\-no-init" +.IP "\fB\-X\fP or \fB\-\-no\-init\fP" Disables sending the termcap initialization and deinitialization strings to the terminal. -This is sometimes desirable if the deinitialization string does +This is sometimes desirable if initialization or deinitialization does something unnecessary, like clearing the screen. -.IP "\-y\fIn\fP or \-\-max-forw-scroll=\fIn\fP" +Note that some terminals require the initialization string for proper +operation, so they may not behave completely correctly when +.B "\-X" +is used. +.IP "\fB\-y\fP\fIn\fP or \fB\-\-max\-forw\-scroll=\fP\fIn\fP" Specifies a maximum number of lines to scroll forward. If it is necessary to scroll forward more than \fIn\fP lines, the screen is repainted instead. -The \-c or \-C option may be used to repaint from the top of +The +.B "\-c" +or +.B "\-C" +option may be used to repaint from the top of the screen if desired. By default, any forward movement causes scrolling. -.IP "\-z\fIn\fP or \-\-window=\fIn\fP or \-\fIn\fP" +.IP "\fB\-z\fP\fIn\fP or \fB\-\-window=\fP\fIn\fP or \-\fIn\fP" Changes the default scrolling window size to \fIn\fP lines. The default is one screenful. The z and w commands can also be used to change the window size. @@ -1304,10 +1621,12 @@ If the number is negative, it indicates .I n lines less than the current screen size. -For example, if the screen is 24 lines, \fI\-z\-4\fP sets the +For example, if the screen is 24 lines, +.B "\-z\-4" +sets the scrolling window to 20 lines. If the screen is resized to 40 lines, the scrolling window automatically changes to 36 lines. -.IP "\-\(dq\fIcc\fP\ or\ \-\-quotes=\fIcc\fP" +.IP "\fB\-""\fP\fIcc\fP\ or\ \fB\-\-quotes=\fP\fIcc\fP" Changes the filename quoting character. This may be necessary if you are trying to name a file which contains both spaces and quote characters. @@ -1321,10 +1640,10 @@ Filenames containing a space should then be preceded by the open quote character and followed by the close quote character. Note that even after the quote characters are changed, this option remains \-" (a dash followed by a double quote). -.IP "\-\(ti or \-\-tilde" -Normally lines after end of file are displayed as a single tilde (\(ti). +.IP "\fB\-\*~\fP or \fB\-\-tilde\fP" +Normally lines after end of file are displayed as a single tilde (\*~). This option causes lines after end of file to be displayed as blank lines. -.IP "\-# or \-\-shift" +.IP "\fB\-#\fP or \fB\-\-shift\fP" Specifies the default number of positions to scroll horizontally in the RIGHTARROW and LEFTARROW commands. If the number specified is zero, it sets the default number of @@ -1334,35 +1653,69 @@ of the screen, starting with a decimal point: \&.5 is half of the screen width, \&.3 is three tenths of the screen width, and so on. If the number is specified as a fraction, the actual number of scroll positions is recalculated if the terminal window is resized. -.IP "\-\-cmd=\fIcommands\fP +.IP "\fB\-\-autosave=\fP\fIactions\fP +Normally the history file is saved only when +.B less +exits. +This option specifies other actions which will cause the history file to be saved. +Each action is defined by a single character in the \fIactions\fP string: +.RS +.IP "m" +Setting or clearing a mark while +.B "\-\-save-marks" +is in effect. +.IP "/" +Searching. +.IP "!" +Running a shell command. +.IP "*" +Any action; same as "m/!". +.RE +.IP +Can be set to "-" to specify the default, that only exiting +.B less +will cause the history file to be saved. +Note that, depending on your shell, if you specify this option on the +command line, the "!" and "*" characters may need to be escaped or quoted. +.IP "\fB\-\-cmd=\fP\fIcommands\fP The specified string is taken to be an initial command to .BR less . This is similar to specifying "+\fIcommands\fP", except that -commands specified by \-\-cmd are not executed if -.B less -exits immediately due to the use of the \-E or \-F option, while +commands specified by +.B "\-\-cmd" +are not executed if +.B less +exits immediately due to the use of the +.B "\-E" +or +.B "\-F" +option, while commands specified by the \fB+\fP option are executed even if .B less exits immediately. -.IP "\-\-exit-follow-on-close" +.IP "\fB\-\-exit\-follow\-on\-close\fP" When using the "F" command on a pipe, .B less will automatically stop waiting for more data when the input side of the pipe is closed. -.IP "\-\-file-size" -If \-\-file-size is specified, +.IP "\fB\-\-file\-size\fP" +If +.B "\-\-file\-size" +is specified, .B less will determine the size of the file immediately after opening the file. Then the "=" command will display the number of lines in the file. Normally this is not done, because it can be slow if the input file is non-seekable (such as a pipe) and is large. -.IP "\-\-follow-name" +.IP "\fB\-\-follow\-name\fP" Normally, if the input file is renamed while an F command is executing, .B less will continue to display the contents of the original file despite its name change. -If \-\-follow-name is specified, during an F command +If +.B "\-\-follow\-name" +is specified, during an F command .B less will periodically attempt to reopen the file by name. If the reopen succeeds and the file is a different file from the original @@ -1370,11 +1723,11 @@ If the reopen succeeds and the file is a different file from the original with the same name as the original (now renamed) file), .B less will display the contents of that new file. -.IP "\-\-form-feed" +.IP "\fB\-\-form\-feed\fP" When scrolling forward or backward in the file, -stop if a line beginning with a form feed character (\(haL) is reached. +stop if a line beginning with a form feed character (\*^L) is reached. This can be useful when viewing a file which uses form feeds between pages. -.IP "\-\-header=\fIL\fP,\fIC\fP,\fIN\fP" +.IP "\fB\-\-header=\fP\fIL\fP,\fIC\fP,\fIN\fP" .RS Sets the number of header lines and columns displayed on the screen. The number of header lines is set to \fIL\fP. @@ -1386,11 +1739,18 @@ If \fIC\fP is empty or missing, the number of header columns is unchanged. The first header line is set to line number \fIN\fP in the file. If \fIN\fP is empty or missing, it is taken to be the number of the line currently displayed in the first line of the screen -(if the \-\-header command has been issued from within +(if the +.B "\-\-header" +command has been issued from within .BR less ")," -or 1 (if the \-\-header option has been given on the command line). -The special form "\-\-header=\-" disables header lines and header columns, -and is equivalent to "\-\-header=0,0". +or 1 (if the +.B "\-\-header" +option has been given on the command line). +The special form +.RB "\[dq]" "\-\-header=\-" "\[dq]" +disables header lines and header columns, +and is equivalent to +.RB "\[dq]" "\-\-header=0,0" "\[dq]." .PP When \fIL\fP is nonzero, the first \fIL\fP lines at the top of the screen are replaced with the \fIL\fP lines of the file beginning at line \fIN\fP, @@ -1400,28 +1760,34 @@ When \fIC\fP is nonzero, the first \fIC\fP characters displayed at the beginning of each line are replaced with the first \fIC\fP characters of the line, even if the rest of the line is scrolled horizontally. .PP -While the \-\-header option is active, +While the +.B "\-\-header" +option is active, lines longer than the screen width are truncated, -and the \-S option is ignored. +and the +.B "\-S" +option is ignored. .RE -.IP "\-\-incsearch" +.IP "\fB\-\-incsearch\fP" Subsequent search commands will be "incremental"; that is, .B less will advance to the next line containing the search pattern as each character of the pattern is typed in. -.IP "\-\-intr=\fIc\fP" -Use the character \fIc\fP instead of \(haX to interrupt a read +.IP "\fB\-\-intr=\fP\fIc\fP" +Use the character \fIc\fP instead of \*^X to interrupt a read when the "Waiting for data" message is displayed. \fIc\fP must be an ASCII character; that is, one with a value between 1 and 127 inclusive. A caret followed by a single character can be used to specify a control character. -.IP "\-\-line-num-width=\fIn\fP" +.IP "\fB\-\-line\-num\-width=\fP\fIn\fP" Sets the minimum width of the line number field when the \-N option is in effect to \fIn\fP characters. The default is 7. -.IP "\-\-match-shift=\fIn\fP" -When \-S is in effect, if a search match is not visible +.IP "\fB\-\-match\-shift=\fP\fIn\fP" +When +.B "\-S" +is in effect, if a search match is not visible because it is shifted to the left or right of the currently visible screen, the text will horizontally shift to ensure that the search match is visible. @@ -1429,13 +1795,13 @@ This option selects the column in which the first character of the search match will be placed after the shift. In other words, there will be \fIn\fP characters visible to the left of the search match. - +.IP Alternately, the number may be specified as a fraction of the width of the screen, starting with a decimal point: \&.5 is half of the screen width, \&.3 is three tenths of the screen width, and so on. If the number is specified as a fraction, the actual number of scroll positions is recalculated if the terminal window is resized. -.IP "\-\-modelines=\fIn\fP" +.IP "\fB\-\-modelines=\fP\fIn\fP" .RS Before displaying a file, .B less @@ -1459,10 +1825,14 @@ option settings may be separated by either spaces or colons. The word "set" is required if the program name is "less" but optional if any of the other three names are used. If any option setting is of the form "tabstop=\fIn\fP" or "ts=\fIn\fP", -then tab stops are automatically set as if \-\-tabs=\fIn\fP had been given. -See the \-\-tabs description for acceptable values of \fIn\fP. +then tab stops are automatically set as if +.BI "\-\-tabs=" "n" +had been given. +See the +.B "\-\-tabs" +description for acceptable values of \fIn\fP. .RE -.IP "\-\-mouse" +.IP "\fB\-\-mouse\fP" Enables mouse input: scrolling the mouse wheel down moves forward in the file, scrolling the mouse wheel up moves backwards in the file, @@ -1470,83 +1840,125 @@ left-click sets the "#" mark to the line where the mouse is clicked, and right-click (or any other) returns to the "#" mark position. Holding down the left button and dragging also moves in the file. If a left-click is performed with the mouse cursor on an OSC 8 hyperlink, -the hyperlink is selected as if by the \(haO\(haN command. +the hyperlink is selected as if by the \*^O\*^N command. If a left-click is performed with the mouse cursor on an OSC 8 hyperlink -which is already selected, the hyperlink is opened as if by the \(haO\(haO command. +which is already selected, the hyperlink is opened as if by the \*^O\*^O command. The number of lines to scroll when the wheel is moved -can be set by the \-\-wheel-lines option. +can be set by the +.B "\-\-wheel\-lines" +option. Mouse input works only on terminals which support X11 mouse reporting, -and on the Windows version of -.BR less . -.IP "\-\-MOUSE" -Like \-\-mouse, except the direction scrolled +and on Windows. +.IP "\fB\-\-MOUSE\fP" +Like +.BR "\-\-mouse" "," +except the direction scrolled on mouse wheel movement is reversed. -.IP "\-\-no-edit-warn" +.IP "\fB\-\-no\-edit\-warn\fP" Don't print a warning message when using the v command on a file which was opened using a LESSOPEN preprocessor (see the INPUT PREPROCESSOR section below). -.IP "\-\-no-keypad" +.IP "\fB\-\-no\-keypad\fP" Disables sending the keypad initialization and deinitialization strings to the terminal. This is sometimes useful if the keypad strings make the numeric keypad behave in an undesirable manner. -.IP "\-\-no-histdups" +.IP "\fB\-\-no\-histdups\fP" This option changes the behavior so that if a search string or file name is typed in, and the same string is already in the history list, the existing copy is removed from the history list before the new one is added. Thus, a given string will appear only once in the history list. Normally, a string may appear multiple times. -.IP "\-\-no-number-headers" -Header lines (defined via the \-\-header option) are not assigned line numbers. +.IP "\fB\-\-no\-number\-headers\fP" +Header lines (defined via the +.B "\-\-header" +option) are not assigned line numbers. Line number 1 is assigned to the first line after any header lines. -.IP "\-\-no-paste" -If the terminal supports xterm-compatible "bracketed paste", -any text pasted into +.IP "\fB\-\-no\-paste\fP" +If the terminal supports +.BR xterm -compatible +"bracketed paste", any text pasted into .B less is ignored, except that one line of text may be pasted into the command line at the bottom of the screen (search strings, file names, etc). That is, the first newline of text pasted into the command line and any text that follows it is ignored. -.IP "\-\-no-search-header-lines" +.IP "\fB\-\-no\-search\-header\-lines\fP" Searches do not include header lines, but still include header columns. -.IP "\-\-no-search-header-columns" +.IP "\fB\-\-no\-search\-header\-columns\fP" Searches do not include header columns, but still include header lines. -.IP "\-\-no-search-headers" +.IP "\fB\-\-no\-search\-headers\fP" Searches do not include header lines or header columns. -.IP "\-\-no-vbell" +.IP "\fB\-\-no\-vbell\fP" Disables the terminal's visual bell. -.IP "\-\-proc-backspace" -If set, backspaces are handled as if neither the \-u option -nor the \-U option were set. +.IP "\fB\-\-proc\-backspace\fP" +If set, backspaces are handled as if neither the +.B "\-u" +option +nor the +.B "\-U" +option were set. That is, a backspace adjacent to an underscore causes text to be displayed in underline mode, and a backspace between identical characters cause text to be displayed in boldface mode. -This option overrides the \-u and \-U options, so that display of +This option overrides the +.B "\-u" +and +.B "\-U" +options, so that display of backspaces can be controlled separate from tabs and carriage returns. -If not set, backspace display is controlled by the \-u and \-U options. -.IP "\-\-PROC-BACKSPACE" -If set, backspaces are handled as if the \-U option were set; +If not set, backspace display is controlled by the +.B "\-u" +and +.B "\-U" +options. +.IP "\fB\-\-PROC\-BACKSPACE\fP" +If set, backspaces are handled as if the +.B "\-U" +option were set; that is backspaces are treated as control characters. -.IP "\-\-proc-return" -If set, carriage returns are handled as if neither the \-u option -nor the \-U option were set. +.IP "\fB\-\-proc\-return\fP" +If set, carriage returns are handled as if neither the +.B "\-u" +option +nor the +.B "\-U" +option were set. That is, a carriage return immediately before a newline is deleted. -This option overrides the \-u and \-U options, so that display of +This option overrides the +.B "\-u" +and +.B "\-U" +options, so that display of carriage returns can be controlled separate from that of backspaces and tabs. -If not set, carriage return display is controlled by the \-u and \-U options. -.IP "\-\-PROC-RETURN" -If set, carriage returns are handled as if the \-U option were set; +If not set, carriage return display is controlled by the +.B "\-u" +and +.B "\-U" +options. +.IP "\fB\-\-PROC\-RETURN\fP" +If set, carriage returns are handled as if the +.B "\-U" +option were set; that is carriage returns are treated as control characters. -.IP "\-\-proc-tab" -If set, tabs are handled as if the \-U option were not set. +.IP "\fB\-\-proc\-tab\fP" +If set, tabs are handled as if the +.B "\-U" +option were not set. That is, tabs are expanded to spaces. -This option overrides the \-U option, so that display of +This option overrides the +.B "\-U" +option, so that display of tabs can be controlled separate from that of backspaces and carriage returns. -If not set, tab display is controlled by the \-U option. -.IP "\-\-PROC-TAB" -If set, tabs are handled as if the \-U option were set; +If not set, tab display is controlled by the +.B "\-U" +option. +.IP "\fB\-\-PROC\-TAB\fP" +If set, tabs are handled as if the +.B "\-U" +option were set; that is tabs are treated as control characters. -.IP "\-\-redraw-on-quit" +.IP "\fB\-\-redraw\-on\-quit\fP" When quitting, after sending the terminal deinitialization string, redraws the entire last screen. On terminals whose terminal deinitialization string causes the @@ -1554,65 +1966,85 @@ terminal to switch from an alternate screen, this makes the last screenful of the current file remain visible after .B less has quit. -.IP "\-\-rscroll=\fIc\fP" +.IP "\fB\-\-rscroll=\fP\fIc\fP" This option changes the character used to mark truncated lines. It may begin with a two-character attribute indicator like LESSBINFMT does. If there is no attribute indicator, standout is used. If set to "\-", truncated lines are not marked. -.IP "\-\-save-marks" +.IP "\fB\-\-save\-marks\fP" Save marks in the history file, so marks are retained across different invocations of .BR less . -.IP "\-\-search-options=\fI...\fP" +.IP "\fB\-\-search\-options=\fP\fI...\fP" Sets default search modifiers. The value is a string of one or more of the characters E, F, K, N, R or W. Setting any of these has the same effect as typing that control character at the beginning of every search pattern. -For example, setting \-\-search-options=W is the same as -typing \(haW at the beginning of every pattern. +For example, setting +.B "\-\-search\-options=\fIW\fP" +is the same as +typing \*^W at the beginning of every pattern. The value may also contain a digit between 1 and 5, -which has the same effect as typing \(haS followed by that digit +which has the same effect as typing \*^S followed by that digit at the beginning of every search pattern. -The value "-" disables all default search modifiers. -.IP "\-\-show-preproc-errors" -If a preprocessor produces data, +The value "\-" disables all default search modifiers. +.IP "\fB\-\-show\-preproc\-errors\fP" +If a LESSOPEN preprocessor produces data, then exits with a non-zero exit code, .B less will display a warning. -.IP "\-\-status-col-width=\fIn\fP" -Sets the width of the status column when the \-J option is in effect. +.IP "\fB\-\-status\-col\-width=\fP\fIn\fP" +Sets the width of the status column when the +.B "\-J" +option is in effect. The default is 2 characters. -.IP "\-\-status-line" +.IP "\fB\-\-status\-line\fP" If a line is marked, the entire line (rather than just the status column) is highlighted. -Also lines highlighted due to the \-w option will have +Also lines highlighted due to the +.B "\-w" +option will have the entire line highlighted. -If \-\-use-color is set, the line is colored rather than highlighted. -.IP "\-\-use-backslash" +If +.B "\-\-use\-color" +is set, the line is colored rather than highlighted. +.IP "\fB\-\-use\-backslash\fP" This option changes the interpretations of options which follow this one. -After the \-\-use-backslash option, any backslash in an option string is +After the +.B "\-\-use\-backslash" +option, any backslash in an option string is removed and the following character is taken literally. This allows a dollar sign to be included in option strings. -.IP "\-\-use-color" +.IP "\fB\-\-use\-color\fP" Enables colored text in various places. -The \-D option can be used to change the colors. +The +.B "\-D" +option can be used to change the colors. Colored text works only if the terminal supports ANSI color escape sequences (as defined in .nh -https://www.ecma-international.org/publications-and-standards/standards/ecma-48). +https://\*:www\*:.ecma\-international\*:.org/\*:publications\-and\-standards/\*:standards/\*:ecma\-48). .hy -.IP "\-\-wheel-lines=\fIn\fP" +.IP "\fB\-\-wheel\-lines=\fP\fIn\fP" Set the number of lines to scroll when the mouse wheel is scrolled -and the \-\-mouse or \-\-MOUSE option is in effect. +and the +.B "\-\-mouse" +or +.B "\-\-MOUSE" +option is in effect. The default is 1 line. -.IP "\-\-wordwrap" -When the \-S option is not in use, +.IP "\fB\-\-wordwrap\fP" +When the +.B "\-S" +option is not in use, wrap each line at a space or tab if possible, so that a word is not split between two lines. The default is to wrap at any character. -.IP \-\- -A command line argument of "\-\-" marks the end of option arguments. +.IP \fB\-\-\fP +A command line argument of +.RB "\[dq]" "\-\-" "\[dq]" +marks the end of option arguments. Any arguments following this are interpreted as filenames. This can be useful when viewing a file whose name begins with a "\-" or "+". Otherwise, option arguments and filename arguments can be intermixed; @@ -1633,7 +2065,9 @@ If the option starts with ++, the initial command 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. -Also see the \-\-cmd option. +Also see the +.B "\-\-cmd" +option. . .SH "LINE EDITING" When entering a command line at the bottom of the screen @@ -1645,16 +2079,16 @@ a key does not exist on a particular keyboard. (Note that the forms beginning with ESC do not work on some MS-DOS and Windows systems because ESC is the line erase character.) Any of these special keys may be entered literally by preceding -it with the "literal" character, either \(haV or \(haA. +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 ]" Move the cursor one space to the left. .IP "RIGHTARROW [ ESC-l ]" Move the cursor one space to the right. -.IP "\(haLEFTARROW [ ESC-b or ESC-LEFTARROW ]" +.IP "\*^LEFTARROW [ ESC-b or ESC-LEFTARROW ]" (That is, CONTROL and LEFTARROW simultaneously.) Move the cursor one word to the left. -.IP "\(haRIGHTARROW [ ESC-w or ESC-RIGHTARROW ]" +.IP "\*^RIGHTARROW [ ESC-w or ESC-RIGHTARROW ]" (That is, CONTROL and RIGHTARROW simultaneously.) Move the cursor one word to the right. .IP "HOME [ ESC-0 ]" @@ -1666,10 +2100,10 @@ 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 character under the cursor. -.IP "\(haBACKSPACE [ ESC-BACKSPACE ]" +.IP "\*^BACKSPACE [ ESC-BACKSPACE ]" (That is, CONTROL and BACKSPACE simultaneously.) Delete the word to the left of the cursor. -.IP "\(haDELETE [ ESC-X or ESC-DELETE ]" +.IP "\*^DELETE [ ESC-X or ESC-DELETE ]" (That is, CONTROL and DELETE simultaneously.) Delete the word under the cursor. .IP "UPARROW [ ESC-k ]" @@ -1689,18 +2123,18 @@ If the completed filename is a directory, a "/" is appended to the filename. (On MS-DOS and Windows systems, a "\e" is appended.) The environment variable LESSSEPARATOR can be used to specify a different character to append to a directory name. -.IP "BACKTAB [ ESC-TAB ]" -Like, TAB, but cycles in the reverse direction thru the matching filenames. -.IP "\(haL" +.IP "BACKTAB (SHIFT-TAB) [ ESC-TAB ]" +Like TAB, but cycles in the reverse direction thru the matching filenames. +.IP "\*^L" Complete the partial filename to the left of the cursor. If it matches more than one filename, all matches are entered into the command line (if they fit). -.IP "\(haU (Unix and OS/2) or ESC (MS-DOS and Windows)" +.IP "\*^U (Unix and OS/2) or ESC (MS-DOS and Windows)" Delete the entire command line, or cancel the command if the cursor is at the beginning of the command line. If you have changed your line-kill character in Unix to something -other than \(haU, that character is used instead of \(haU. -.IP "\(haG" +other than \*^U, that character is used instead of \*^U. +.IP "\*^G" Delete the entire command line and return to the main prompt. . .SH "KEY BINDINGS" @@ -1950,8 +2384,8 @@ preceding character. (Only when LESSCHARSET is "utf8".) are simply deleted from the input and not displayed. (Only when LESSCHARSET is "utf8".) .PP -A "character set" is simply a description of which characters are to -be considered normal, control, and binary. +A "character set" is a description of which of these categories +each character belongs to. The LESSCHARSET environment variable may be used to select a character set. Possible values for LESSCHARSET are: .IP ascii @@ -1970,16 +2404,16 @@ Same as iso8859. Selects a character set appropriate for MS-DOS. .IP ebcdic Selects an EBCDIC character set. -.IP IBM-1047 +.IP IBM\-1047 Selects an EBCDIC character set used by OS/390 Unix Services. This is the EBCDIC analogue of latin1. You get similar results -by setting either LESSCHARSET=IBM-1047 or LC_CTYPE=en_US +by setting either LESSCHARSET=IBM\-1047 or LC_CTYPE=en_US in your environment. -.IP koi8-r +.IP koi8\-r Selects a Russian character set. .IP next Selects a character set appropriate for NeXT computers. -.IP utf-8 +.IP utf\-8 Selects the UTF-8 encoding of the ISO 10646 character set. UTF-8 is special in that it supports multi-byte characters in the input file. It is the only character set that supports multi-byte characters. @@ -2013,22 +2447,22 @@ ascii 8bcccbcc18b95.b dos 8bcccbcc12bc5b95.b. ebcdic 5bc6bcc7bcc41b.9b7.9b5.b..8b6.10b6.b9.7b 9.8b8.17b3.3b9.7b9.8b8.6b10.b.b.b. -IBM-1047 4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc +IBM\-1047 4cbcbc3b9cbccbccbb4c6bcc5b3cbbc4bc4bccbc 191.b iso8859 8bcccbcc18b95.33b. -koi8-r 8bcccbcc18b95.b128. +koi8\-r 8bcccbcc18b95.b128. latin1 8bcccbcc18b95.33b. next 8bcccbcc18b95.bb125.bb .TE .RE .PP If neither LESSCHARSET nor LESSCHARDEF is set, -but any of the strings "UTF-8", "UTF8", "utf-8" or "utf8" +but any of the strings "UTF\-8", "UTF8", "utf\-8" or "utf8" is found in the LC_ALL, LC_CTYPE or LANG -environment variables, then the default character set is utf-8. +environment variables, then the default character set is utf\-8. .PP If that string is not found, but your system supports the -.B setlocale +.BR setlocale (3) interface, .B less will use setlocale to determine the character set. @@ -2036,12 +2470,12 @@ setlocale is controlled by setting the LANG or LC_CTYPE environment variables. .PP Finally, if the -.I setlocale -interface is also not available, the default character set is utf-8. +.B setlocale +interface is also not available, the default character set is utf\-8. .PP Control and binary characters are displayed in standout (reverse video). Each such character is displayed in caret notation if possible -(e.g.\& \(haA for control-A). Caret notation is used only if +(e.g.\& \*^A for control-A). Caret notation 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 @@ -2059,7 +2493,7 @@ The default if no LESSBINFMT is specified is "*s<%02X>". Warning: the result of expanding the character via LESSBINFMT must be less than 31 characters. .PP -When the character set is utf-8, the LESSUTFBINFMT environment variable +When the character set is utf\-8, the LESSUTFBINFMT environment variable acts similarly to LESSBINFMT but it applies to Unicode code points that were successfully decoded but are unsuitable for display (e.g., unassigned code points). @@ -2074,7 +2508,7 @@ and stray trailing octets) are displayed individually using LESSBINFMT so as to facilitate diagnostic of how the UTF-8 file is ill-formed. .PP -When the character set is utf-8, in rare cases it may be desirable to +When the character set is utf\-8, in rare cases it may be desirable to override the Unicode definition of the type of certain characters. For example, characters in a Private Use Area are normally treated as binary characters, but if you are using a custom font with printable characters @@ -2108,32 +2542,39 @@ A deleted character (deleted from the input and not displayed). .RE .PP For example, setting LESSUTFCHARDEF to +.PP +.EX .nf -.sp - E000-F8FF:p,F0000-FFFFD:p,100000-10FFFD:p -.sp + E000\-F8FF:p,F0000\-FFFFD:p,100000\-10FFFD:p .fi +.EE +.PP would make all Private Use Area characters be treated as printable. .PP By default, emoji modifiers, components and variation selectors are deleted because many terminals do not display them correctly. If you use a terminal which does display some or all of them correctly, -you can cause to be displayed by setting LESSUTFCHARDEF +you can cause them to be displayed by setting LESSUTFCHARDEF to treat them as composing characters. For example, this sets them all to composing characters: +.PP +.EX .nf -.sp - FE00-FE0F:c,1F3FB-1F3FF:c,1F9B0-1F9B3:c,E0100-E01EF:c -.sp + FE00\-FE0F:c,1F3FB\-1F3FF:c,1F9B0\-1F9B3:c,E0100\-E01EF:c .fi +.EE .SH "PROMPTS" -The \-P option allows you to tailor the prompt to your preference. -The string given to the \-P option replaces the specified prompt string. +The +.B "\-P" +option allows you to tailor the prompt to your preference. +The string given to the +.B "\-P" +option replaces the specified prompt string. Certain characters in the string are interpreted specially. The prompt mechanism is rather complicated to provide flexibility, but the ordinary user need not understand the details of constructing personalized prompt strings. -.sp +.PP A percent sign followed by a single character is expanded according to what the following character is. (References to the input file size below refer to the preprocessed size, @@ -2147,11 +2588,16 @@ display is used, an "m" means use the middle line, a "b" means use the bottom line, a "B" means use the line just after the bottom line, -and a "j" means use the "target" line, as specified by the \-j option. +and a "j" means use the "target" line, as specified by the +.B "\-j" +option. .IP "%B" Replaced by the size of the current input file. .IP "%c" -Replaced by the column number of the text appearing in the first +Replaced by the column number of the text which appears in the first +column of the screen. +.IP "%C" +Replaced by the column number of the text which appears (or would appear) in the last column of the screen. .IP "%d\fIX\fP" Replaced by the page number of a line in the input file. @@ -2184,13 +2630,18 @@ Replaced by the total number of input files. .IP "%o" Replaced by the URI of the currently selected OSC 8 hyperlink, or a question mark if no hyperlink is selected. -This is used by OSC 8 handlers as explained in the \(haO\(haO command description. +This is used by OSC 8 handlers as explained in the \*^O\*^O command description. .IP "%p\fIX\fP" Replaced by the percent into the current input file, based on byte offsets. The line used is determined by the \fIX\fP as with the %b option. .IP "%P\fIX\fP" Replaced by the percent into the current input file, based on line numbers. The line used is determined by the \fIX\fP as with the %b option. +.IP "%Q" +Replaced by the percent of the last column of text displayed on the screen +compared to the length of the longest line currently displayed +(that is, %C divided by %W). +Note that using this sequence can make displaying the prompt be slower than usual. .IP "%s" Same as %B. .IP "%t" @@ -2198,8 +2649,13 @@ Causes any trailing spaces to be removed. Usually used at the end of the string, but may appear anywhere. .IP "%T" Normally expands to the word "file". -However if viewing files via a tags list using the \-t option, +However if viewing files via a tags list using the +.B "\-t" +option, it expands to the word "tag". +.IP "%W" +Replaced by the width of the longest line currently displayed on the screen. +Note that using this sequence can make displaying the prompt be slower than usual. .IP "%x" Replaced by the name of the next input file in the list. .PP @@ -2247,6 +2703,9 @@ of the specified line is known. .IP "?P\fIX\fP" True if the percent into the current input file, based on line numbers, of the specified line is known. +.IP "?Q" +True if %Q is less than 100. +Note that using this sequence can make displaying the prompt be slower than usual. .IP "?s" Same as "?B". .IP "?x" @@ -2260,14 +2719,18 @@ Any of the special characters may be included in the prompt literally by preceding it with a backslash. .PP Some examples: -.sp +.PP +.EX ?f%f:Standard input. -.sp +.EE +.PP This prompt prints the filename, if known; otherwise the string "Standard input". -.sp -?f%f \&.?ltLine %lt:?pt%pt\e%:?btByte %bt:-... -.sp +.PP +.EX +?f%f \&.?ltLine %lt:?pt%pt\e%:?btByte %bt:\-... +.EE +.PP This prompt would print the filename, if known. The filename is followed by the line number, if known, otherwise the percent if known, otherwise the byte offset if known. @@ -2275,9 +2738,11 @@ Otherwise, a dash is printed. Notice how each question mark has a matching period, and how the % after the %pt is included literally by escaping it with a backslash. -.sp -?n?f%f\ .?m(%T %i of %m)\ ..?e(END)\ ?x-\ Next\e:\ %x..%t -.sp +.PP +.EX +?n?f%f\ .?m(%T %i of %m)\ ..?e(END)\ ?x\-\ Next\e:\ %x..%t +.EE +.PP This prints the filename if this is the first prompt in a file, followed by the "file N of N" message if there is more than one input file. @@ -2286,34 +2751,44 @@ followed by the name of the next file, if there is one. Finally, any trailing spaces are truncated. This is the default prompt. For reference, here are the defaults for -the other two prompts (\-m and \-M respectively). +the other two prompts +.B "\-m" +and +.B "\-M" +respectively). Each is broken into two lines here for readability only. +.PP +.EX .nf -.sp -?n?f%f\ .?m(%T\ %i\ of\ %m)\ ..?e(END)\ ?x-\ Next\e:\ %x.: +?n?f%f\ .?m(%T\ %i\ of\ %m)\ ..?e(END)\ ?x\-\ Next\e:\ %x.: ?pB%pB\e%:byte\ %bB?s/%s...%t -.sp -?f%f\ .?n?m(%T\ %i\ of\ %m)\ ..?ltlines\ %lt-%lb?L/%L.\ : - byte\ %bB?s/%s.\ .?e(END)\ ?x-\ Next\e:\ %x.:?pB%pB\e%..%t -.sp +.PP +?f%f\ .?n?m(%T\ %i\ of\ %m)\ ..?ltlines\ %lt\-%lb?L/%L.\ : + byte\ %bB?s/%s.\ .?e(END)\ ?x\-\ Next\e:\ %x.:?pB%pB\e%..?c\ (column\ %c).%t .fi +.EE +.PP And here is the default message produced by the = command: +.PP +.EX .nf -.sp -?f%f\ .?m(%T\ %i\ of\ %m)\ .?ltlines\ %lt-%lb?L/%L.\ . - byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..%t +?f%f\ .?m(%T\ %i\ of\ %m)\ .?ltlines\ %lt\-%lb?L/%L.\ . + byte\ %bB?s/%s.\ ?e(END)\ :?pB%pB\e%..?c\ (column\ %c).%t .fi +.EE .PP The prompt expansion features are also used for another purpose: 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 the prompt strings. The default value for LESSEDIT is: +.PP +.EX .nf -.sp %E\ ?lm+%lm.\ %g -.sp .fi +.EE +.PP Note that this expands to the editor name, followed by a + and the line number, followed by the shell-escaped file name. If your editor does not accept the "+linenumber" syntax, or has other @@ -2332,17 +2807,21 @@ the examine command (:e) .IP "glob" metacharacters such as * in filenames, .br -and filename completion (TAB, \(haL) +and filename completion (TAB, \*^L) .IP "history" history file .IP "lesskey" -use of lesskey files (-k and \-\-lesskey-src) +use of lesskey files +.B "\-k" +and +.BR "\-\-lesskey\-src" ")" .IP "lessopen" input preprocessor (LESSOPEN environment variable) .IP "logfile" -log files (s and \-o) +log files (s and +.BR "\-o" ")" .IP "osc8" -opening OSC 8 links (\(haO\(haO) +opening OSC 8 links (\*^O\*^O) .IP "pipe" the pipe command (|) .IP "shell" @@ -2352,7 +2831,8 @@ stopping .B less via a SIGTSTP signal .IP "tags" -use of tags files (-t) +use of tags files +.RB "(" "\-t" ")" .PP The LESSSECURE_ALLOW environment variable can be set to a comma-separated list of names of features which are selectively enabled when LESSSECURE is set. @@ -2380,25 +2860,51 @@ and the environment variable LESS_IS_MORE is not set to 0, behaves (mostly) in conformance with the POSIX .BR more (1) command specification. -In this mode, less behaves differently in these ways: -.PP -The \-e option works differently. -If the \-e option is not set, -.B less -behaves as if the \-e option were set. -If the \-e option is set, +In this mode, .B less -behaves as if the \-E option were set. +behaves differently in these ways: .PP -The \-m option works differently. -If the \-m option is not set, the medium prompt is used, +The +.B "\-e" +option works differently. +If the +.B "\-e" +option is not set, +.B less +behaves as if the +.B "\-e" +option were set. +If the +.B "\-e" +option is set, +.B less +behaves as if the +.B "\-E" +option were set. +.PP +The +.B "\-m" +option works differently. +If the +.B "\-m" +option is not set, the medium prompt is used, and it is prefixed with the string "\-\-More\-\-". -If the \-m option is set, the short prompt is used. +If the +.B "\-m" +option is set, the short prompt is used. .PP -The \-n option acts like the \-z option. -The normal behavior of the \-n option is unavailable in this mode. +The +.B "\-n" +option acts like the +.B "\-z" +option. +The normal behavior of the +.B "\-n" +option is unavailable in this mode. .PP -The parameter to the \-p option is taken to be a +The parameter to the +.B "\-p" +option is taken to be a .B less command rather than a search pattern. .PP @@ -2445,10 +2951,12 @@ Characters which may end an ANSI color escape sequence .IP LESSANSIMIDCHARS Characters which may appear between the ESC character and the end character in an ANSI color escape sequence -(default "0123456789:;[?!"\(aq#%()*+\ "). +(default "0123456789:;[?!"\*'#%()*+\ "). .IP LESSANSIOSCALLOW A comma-separated list of OSC types which are output directly to the -terminal when \-R is in effect +terminal when +.B "\-R" +is in effect (default "8"; that is, only OSC 8 sequences are output directly). .IP LESSANSIOSCCHARS Characters which may follow an ESC character to mark the start @@ -2477,7 +2985,9 @@ in filenames on Unix systems. Editor prototype string (used for the v command). See discussion under PROMPTS. .IP LESSGLOBALTAGS -Name of the command used by the \-t option to find global tags. +Name of the command used by the +.B "\-t" +option to find global tags. Normally should be set to "global" if your system has the .BR global (1) command. If not set, global tags are not used. @@ -2508,7 +3018,9 @@ Name of the default .I "lesskey binary" file. (Not used if "$LESSKEYIN" exists.) .IP LESSKEY_CONTENT -The value is parsed as if it were the parameter of a \-\-lesskey-content option. +The value is parsed as if it were the parameter of a +.B "\-\-lesskey\-content" +option. .IP LESSKEYIN_SYSTEM Name of the default system-wide .I "lesskey source" @@ -2521,7 +3033,15 @@ file. (Not used if "$LESSKEYIN_SYSTEM" exists.) List of characters which are considered "metacharacters" by the shell. .IP LESSMETAESCAPE Prefix which less will add before each metacharacter in a -command sent to the shell (default "\\"). +command sent to the shell (default "\e"). +.IP LESSNOCONFIG +If set to "\-", all environment variables except TERM are ignored +(treated as if they were not set). +If set to a comma-separated list of environment variable names, +all environment variables except TERM and those in the list are ignored. +In either case (if set to any non-empty value), all +.B lesskey +files are also ignored. .IP LESSOPEN Command line to invoke the (optional) input-preprocessor. .IP LESSSECURE @@ -2532,7 +3052,7 @@ Enables individual features which are normally disabled by LESSSECURE. See discussion under SECURITY. .IP LESSSEPARATOR String to be appended to a directory name in filename completion -(default "\\" on MS-DOS, Windows, and OS/2; otherwise "/"). +(default "\e" on MS-DOS, Windows, and OS/2; otherwise "/"). .IP LESSUTFBINFMT Format for displaying non-printable Unicode code points. .IP LESSUTFCHARDEF @@ -2572,14 +3092,18 @@ sets an OSC 8 handler for opening OSC 8 links containing a URI with that scheme. Sets an OSC 8 handler for opening OSC 8 links for which there is no specific LESS_OSC8_xxx handler set for the "xxx" scheme. .IP LESS_SHELL_LINES -When the \-F option is set, +When the +.B "\-F" +option is set, .B less exits automatically if the number of screen lines used to display the file is less than or equal to the screen height minus the value of the LESS_SHELL_LINES variable. Thus, if you use a shell prompt which occupies more than one screen line, this variable can be set to the number of lines used by your prompt, -to ensure that the entire file can be seen when \-F is used. +to ensure that the entire file can be seen when +.B "\-F" +is used. If not set, LESS_SHELL_LINES is assumed to be 1. .IP LESS_SIGUSR1 If set to a string of one or more @@ -2590,14 +3114,31 @@ receives a SIGUSR1 signal. .IP LESS_TERMCAP_xx Where "xx" is any two characters, overrides the definition of the termcap "xx" capability for the terminal. +No escape sequences in the string are processed, so any +nonprintable characters such as ESC must be in the string literally. +.IP LESS_TERMINFO_xxxx +Where "xxxx" is any string of characters, overrides the definition +of the terminfo "xxxx" capability for the terminal. +You can use either LESS_TERMCAP_xx or LESS_TERMINFO_xxxx to override +a terminal capability, regardless of whether +.B less +is built with the +.B termcap +or the +.B terminfo +library. .IP LESS_TERMCAP_BRACKETED_PASTE_START Overrides the standard ANSI escape sequence to enable bracketed paste. -This is used when the \-\-no-paste option is in effect. +This is used when the +.B "\-\-no\-paste" +option is in effect. .IP LESS_TERMCAP_BRACKETED_PASTE_END Overrides the standard ANSI escape sequence to disable bracketed paste. .IP LESS_TERMCAP_MOUSE_START Overrides the standard ANSI escape sequence to enable mouse reporting. -This is used when the \-\-mouse option is in effect. +This is used when the +.B "\-\-mouse" +option is in effect. .IP LESS_TERMCAP_MOUSE_END Overrides the standard ANSI escape sequence to disable mouse reporting. .IP LESS_TERMCAP_SUSPEND @@ -2684,11 +3225,11 @@ Mark Nudelman .br Report bugs at .nh -https://github.com/gwsw/less/issues. +https://\*:github\*:.com/\*:gwsw/\*:less/\*:issues. .hy .br For more information, see the less homepage at .br .nh -https://greenwoodsoftware.com/less. +https://\*:greenwoodsoftware\*:.com/\*:less. .hy diff --git a/contrib/less/lessecho.nro b/contrib/less/lessecho.nro index 71e029fe81c4..3013644b6a56 100644 --- a/contrib/less/lessecho.nro +++ b/contrib/less/lessecho.nro @@ -1,9 +1,33 @@ -.TH LESSECHO 1 "Version 685: 04 Oct 2025" +.TH LESSECHO 1 "10 Jan 2026" "less 691" +.\" Define a string to interpolate the hyphenless break point escape +.\" sequence (for URLs and similar) if the formatter claims groff +.\" compatibility, else interpolate nothing. +.ie \n(.g .ds : \: +.el .ds : \" empty .SH NAME lessecho \- expand metacharacters .SH SYNOPSIS +.HP .B lessecho -.I "[-ox] [-cx] [-pn] [-dn] [-mx] [-nn] [-ex] [-a] file ..." +.RB [ \-a ] +.RB [ \-o\c +.IR x ] +.RB [ \-c\c +.IR x ] +.RB [ \-p\c +.IR n ] +.RB [ \-d\c +.IR n ] +.RB [ \-m\c +.IR x ] +.RB [ \-n\c +.IR n ] +.RB [ \-e\c +.IR x ] +.I file +\&.\|.\|. +.PP +.B "lessecho \-\-version" .SH "DESCRIPTION" .B lessecho is a program that simply echos its arguments on standard output. @@ -18,12 +42,12 @@ A summary of options is included below. .TP .B \-e\fIx\fP Specifies "\fIx\fP", rather than backslash, to be the escape char for metachars. -If \fIx\fP is "-", no escape char is used and arguments containing metachars +If \fIx\fP is "\-", no escape char is used and arguments containing metachars are surrounded by quotes instead. .TP .B \-o\fIx\fP Specifies "\fIx\fP", rather than double-quote, to be the open quote character, -which is used if the \-e- option is specified. +which is used if the \-e\- option is specified. .TP .B \-c\fIx\fP Specifies "\fIx\fP" to be the close quote character. @@ -53,4 +77,7 @@ The default is that only arguments containing metacharacters are quoted. This manual page was written by Thomas Schoepf <schoepf@debian.org>, for the Debian GNU/Linux system (but may be used by others). .PP -Report bugs at https://github.com/gwsw/less/issues. +Report bugs at +.nh +https://\*:github\*:.com/\*:gwsw/\*:less/\*:issues. +.hy diff --git a/contrib/less/lesskey.nro b/contrib/less/lesskey.nro index b829c062cdb4..b397a6724e59 100644 --- a/contrib/less/lesskey.nro +++ b/contrib/less/lesskey.nro @@ -1,12 +1,31 @@ '\" t -.TH LESSKEY 1 "Version 685: 04 Oct 2025" +.TH LESSKEY 1 "10 Jan 2026" "less 691" +.\" Define a string for the caret ("hat") as portably as possible. +.ie \n(.g .ds ^ \(ha +.el .ds ^ ^ +.\" Define a string for the neutral apostrophe as portably as possible. +.ie \n(.g .ds ' \(aq +.el .ds ' ' +.\" Define a string to interpolate the hyphenless break point escape +.\" sequence (for URLs and similar) if the formatter claims groff +.\" compatibility, else interpolate nothing. +.ie \n(.g .ds : \: +.el .ds : \" empty .SH NAME lesskey \- customize key bindings for less .SH "SYNOPSIS (deprecated)" -.B "lesskey [\-o output] [\-\-] [input]" -.br -.B "lesskey [\-\-output=output] [\-\-] [input]" +.B lesskey +.RB [ \-o +.IR output ] +.B \-\- +.I input .br +.B lesskey +.RB [ \-\-output=\c +.IR output ] +.B \-\- +.I input +.PP .B "lesskey \-V" .br .B "lesskey \-\-version" @@ -43,7 +62,7 @@ Each section starts with a line that identifies the type of section. Possible sections are: .IP #command Customizes command key bindings. -.IP #line-edit +.IP #line\-edit Customizes line-editing key bindings. .IP #env Defines environment variables. @@ -54,15 +73,15 @@ except as noted below. . .SH "COMMAND SECTION" The command section begins with the line -.sp +.PP #command -.sp +.PP If the command section is the first section in the file, this line may be omitted. The command section consists of lines of the form: -.sp +.PP \fIstring\fP <whitespace> \fIaction\fP <whitespace> [extra-string] <newline> -.sp +.PP Whitespace is any sequence of one or more spaces and/or tabs. The \fIstring\fP is the command key(s) which invoke the action. The \fIstring\fP may be a single command key, or a sequence of up to 15 keys. @@ -84,8 +103,9 @@ l l l. \et TAB (0x09) .TE .RE -.sp -\ek followed by a single character represents the char(s) produced when one of these keys is pressed: +.PP +\ek followed by one or two characters represents the char(s) produced +when one of these keys is pressed: .RS 5m .TS l l. @@ -106,6 +126,22 @@ l l. \ekx DELETE \ekX ctrl-DELETE \ek1 F1 +\ekp1 lower left key on the numeric keypad +\ekp2 lower center key on the numeric keypad +\ekp3 lower right key on the numeric keypad +\ekp4 center left key on the numeric keypad +\ekp5 center key on the numeric keypad +\ekp6 center right key on the numeric keypad +\ekp7 upper left key on the numeric keypad +\ekp8 upper center key on the numeric keypad +\ekp9 upper right key on the numeric keypad +\ekp0 0 on the numeric keypad +\ekp* * on the numeric keypad +\ekp/ / on the numeric keypad +\ekp\- \- on the numeric keypad +\ekp+ + on the numeric keypad +\ekp. . on the numeric keypad +\ekp, , on the numeric keypad .TE .RE .PP @@ -126,11 +162,13 @@ For example, see the "{" and ":t" commands in the example below. It can also be used to execute more than one command when a key is pressed. For example, if this line were in a lesskey file, pressing the "B" key would first set the "b" mark and then search for the string "next": -.sp +.PP +.EX .nf - B set-mark b/next\en + B set\-mark b/next\en .fi -.sp +.EE +.PP The extra string has a special meaning for the "quit" action: when .B less @@ -144,116 +182,131 @@ default command keys used by Documentation on each command can be found in the .B less man page, under the key sequence which invokes the command. -.sp +.PP .RS 5m .TS l l. #command -\er forw-line -\en forw-line -e forw-line -j forw-line -\ekd forw-line -^E forw-line -^N forw-line -k back-line -y back-line -^Y back-line -^K back-line -^P back-line -J forw-line-force -K back-line-force -Y back-line-force -\eej forw-newline -\eek back-newline -d forw-scroll -^D forw-scroll -u back-scroll -^U back-scroll -\e40 forw-screen -f forw-screen -^F forw-screen -^V forw-screen -\ekD forw-screen -b back-screen -^B back-screen -\eev back-screen -\ekU back-screen -z forw-window -w back-window -\ee\e40 forw-screen-force -\eeb back-screen-force -F forw-forever -\eeF forw-until-hilite -R repaint-flush +\er forw\-line +\en forw\-line +e forw\-line +j forw\-line +\ekd forw\-line +\*^E forw\-line +\*^N forw\-line +k back\-line +y back\-line +\*^Y back\-line +\*^K back\-line +\*^P back\-line +J forw\-line\-force +K back\-line\-force +Y back\-line\-force +\eej forw\-newline +\eek back\-newline +d forw\-scroll +\*^D forw\-scroll +u back\-scroll +\*^U back\-scroll +\e40 forw\-screen +f forw\-screen +\*^F forw\-screen +\*^V forw\-screen +\ekD forw\-screen +b back\-screen +\*^B back\-screen +\eev back\-screen +\ekU back\-screen +z forw\-window +w back\-window +\ee\e40 forw\-screen\-force +\eeb back\-screen\-force +F forw\-forever +\eeF forw\-until\-hilite +R repaint\-flush r repaint -^R repaint -^L repaint -\eeu undo-hilite -\eeU clear-search -g goto-line -\ekh goto-line -< goto-line -\ee< goto-line +\*^R repaint +\*^L repaint +\eeu undo\-hilite +\eeU clear\-search +g goto\-line +\ekh goto\-line +< goto\-line +\ee< goto\-line p percent % percent -\ee( left-scroll -\ee) right-scroll -\ekl left-scroll -\ekr right-scroll -\ee{ no-scroll -\ee} end-scroll -{ forw-bracket {} -} back-bracket {} -( forw-bracket () -) back-bracket () -[ forw-bracket [] -] back-bracket [] -\ee^F forw-bracket -\ee^B back-bracket -G goto-end -\ee> goto-end -> goto-end -\eke goto-end -\eeG goto-end-buffered +\ee( left\-scroll +\ee) right\-scroll +\ekl left\-scroll +\ekr right\-scroll +\ee{ no\-scroll +\ee} end\-scroll +{ forw\-bracket {} +} back\-bracket {} +( forw\-bracket () +) back\-bracket () +[ forw\-bracket [] +] back\-bracket [] +\ee\*^F forw\-bracket +\ee\*^B back\-bracket +G goto\-end +\ee> goto\-end +> goto\-end +\eke goto\-end +\eeG goto\-end\-buffered \&= status -^G status +\*^G status :f status -/ forw-search -? back-search -\ee/ forw-search * -\ee? back-search * -n repeat-search -\een repeat-search-all -N reverse-search -\eeN reverse-search-all -^O^N osc8-forw-search -^On osc8-forw-search -^O^P osc8-back-search -^Op osc8-back-search -^O^O osc8-open +/ forw\-search +? back\-search +\ee/ forw\-search * +\ee? back\-search * +n repeat\-search +\een repeat\-search\-all +N reverse\-search +\eeN reverse\-search\-all +\*^O\*^N osc8\-forw\-search +\*^On osc8\-forw\-search +\*^O\*^P osc8\-back\-search +\*^Op osc8\-back\-search +\*^O\*^O osc8\-open & filter -m set-mark -M set-mark-bottom -\eem clear-mark -\&' goto-mark -^X^X goto-mark +m set\-mark +M set\-mark\-bottom +\eem clear\-mark +\&\*' goto\-mark +\*^X\*^X goto\-mark E examine :e examine -^X^V examine -:n next-file -:p prev-file -t next-tag -T prev-tag -:x index-file -:d remove-file -- toggle-option -:t toggle-option t -s toggle-option o +\*^X\*^V examine +:n next\-file +:p prev\-file +t next\-tag +T prev\-tag +:x index\-file +:d remove\-file +\- toggle\-option +:t toggle\-option t +s toggle\-option o ## Use a long option name by starting the ## extra string with ONE dash; eg: - ## s toggle-option -log-file\en -\&_ display-option + ## s toggle\-option \-log\-file\en +\&_ display\-option +\ekp1 goto\-end +\ekp2 forw\-line +\ekp3 forw\-screen +\ekp4 left\-scroll +\ekp6 right\-scroll +\ekp7 goto\-line +\ekp8 back\-line +\ekp9 back\-screen +\ekp0 noaction 0 +\ekp* noaction * +\ekp/ noaction / +\ekp\- noaction \- +\ekp+ noaction + +\ekp. noaction . +\ekp, noaction , | pipe v visual ! shell @@ -281,7 +334,6 @@ Q quit ZZ quit .TE .RE -.sp .SH PRECEDENCE Commands specified by .B lesskey @@ -296,9 +348,9 @@ 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 +.PP #stop -.sp +.PP This will cause all default commands to be ignored. The #stop line should be the last line in that section of the file. .PP @@ -310,9 +362,11 @@ For example, failure to provide a "quit" command can lead to frustration. . .SH "LINE EDITING SECTION" The line-editing section begins with the line: -.sp -#line-edit -.sp +.PP +.EX +#line\-edit +.EE +.PP This section specifies new key bindings for the line editing commands, in a manner similar to the way key bindings for ordinary commands are specified in the #command section. @@ -323,14 +377,14 @@ one per line as in the example below. The following input file describes the set of default line-editing keys used by .BR less : -.sp +.PP .RS 5m .TS l l. -#line-edit -\et forw-complete -\e17 back-complete -\ee\et back-complete +#line\-edit +\et forw\-complete +\e17 back\-complete +\ee\et back\-complete ^L expand ^V literal ^A literal @@ -338,16 +392,16 @@ l l. \ekr right \eeh left \ekl left -\eeb word-left -\ee\ekl word-left -\eew word-right -\ee\ekr word-right +\eeb word\-left +\ee\ekl word\-left +\eew word\-right +\ee\ekr word\-right \eei insert \eex delete \ekx delete -\eeX word-delete -\eekx word-delete -\ee\eb word-backspace +\eeX word\-delete +\eekx word\-delete +\ee\eb word\-backspace \ee0 home \ekh home \ee$ end @@ -356,17 +410,29 @@ l l. \eku up \eej down ^G abort +\ekp1 end +\ekp2 down +\ekp4 left +\ekp6 right +\ekp7 home +\ekp8 up +\ekp0 noaction 0 +\ekp* noaction * +\ekp/ noaction / +\ekp\- noaction \- +\ekp+ noaction + +\ekp. noaction . +\ekp, noaction , \ee[M mouse \ee[< mouse6 .TE .RE -.sp . .SH "LESS ENVIRONMENT VARIABLES" The environment variable section begins with the line -.sp +.PP #env -.sp +.PP Following this line is a list of environment variable assignments. Each line consists of an environment variable name, an equals sign (=) and the value to be assigned to the environment variable. @@ -376,7 +442,7 @@ Variables assigned in this way are visible only to If a variable is specified in the system environment and also in a lesskey file, the value in the lesskey file takes precedence. . -.sp +.PP If the variable name is followed by += rather than =, the string is appended to the variable's existing value. This currently works only if any += lines immediately follow @@ -390,7 +456,7 @@ it should be appended to the end of the preceding line. (It cannot be added to the beginning of the += string because space after the equals sign is ignored, as noted above.) . -.sp +.PP In the string after the = sign, a substring of the form ${NAME} is replaced with the value of the environment variable "NAME". The value of the variable may come from either the system environment, @@ -417,18 +483,20 @@ the remainder of the line is parsed if and only if the running version of matches the operator. This can be helpful if a lesskey file is used by different versions of .BR less . -.sp -For example, suppose that a new command named 'sideways-search' is added in +.PP +For example, suppose that a new command named 'sideways\-search' is added in .B less version 777. Then the following line would assign the command to the Q key, but only in versions of .B less which support it. The line would be ignored by versions earlier than 777. -.sp +.PP +.EX .nf - #version >= 777 Q sideways-search + #version >= 777 Q sideways\-search .fi -.sp +.EE +.PP These six operators are supported: .RS 5m .TS @@ -441,7 +509,7 @@ l l. != Not equal to .TE .RE -.sp +.PP The #version feature is not supported in .B less and @@ -453,14 +521,16 @@ In those older versions, all #version lines are ignored. The following input file sets the \-i and \-S options when .B less is run and, on version 595 and higher, adds a \-\-color option. -.sp +.PP +.EX .nf #env ## (Note that there must be a space at the end of the next line, - ## to separate the --color option from the -S option.) + ## to separate the \-\-color option from the \-S option.) LESS = \-i\ \-S\ #version\ >=\ 595\ \ LESS\ +=\ \-\-color=Hkc .fi +.EE . .SH "SEE ALSO" .BR less (1) @@ -496,4 +566,7 @@ See the GNU General Public License for more details. . Mark Nudelman .br -Report bugs at https://github.com/gwsw/less/issues. +Report bugs at +.nh +https://\*:github\*:.com/\*:gwsw/\*:less/\*:issues. +.hy diff --git a/contrib/less/lesskey_parse.c b/contrib/less/lesskey_parse.c index 23f09b259aca..d844be960817 100644 --- a/contrib/less/lesskey_parse.c +++ b/contrib/less/lesskey_parse.c @@ -247,6 +247,7 @@ static constant char * tstr(char **pp, int xlate) case 'k': if (xlate) { + ch = 0; switch (*++p) { case 'b': ch = SK_BACKSPACE; break; @@ -266,7 +267,30 @@ static constant char * tstr(char **pp, int xlate) case 'x': ch = SK_DELETE; break; case 'X': ch = SK_CTL_DELETE; break; case '1': ch = SK_F1; break; - default: + case 'p': + switch (*++p) + { + case '1': ch = SK_PAD_DL; break; + case '2': ch = SK_PAD_D; break; + case '3': ch = SK_PAD_DR; break; + case '4': ch = SK_PAD_L; break; + case '5': ch = SK_PAD_CENTER; break; + case '6': ch = SK_PAD_R; break; + case '7': ch = SK_PAD_UL; break; + case '8': ch = SK_PAD_U; break; + case '9': ch = SK_PAD_UR; break; + case '0': ch = SK_PAD_ZERO; break; + case '*': ch = SK_PAD_STAR; break; + case '/': ch = SK_PAD_SLASH; break; + case '-': ch = SK_PAD_DASH; break; + case '+': ch = SK_PAD_PLUS; break; + case '.': ch = SK_PAD_DOT; break; + case ',': ch = SK_PAD_COMMA; break; + } + break; + } + if (ch == 0) + { parse_error("invalid escape sequence \"\\k%s\"", char_string(buf, *p, 0)); *pp = increment_pointer(p); return (""); diff --git a/contrib/less/line.c b/contrib/less/line.c index fc5d18abf4d2..e554fce69fa9 100644 --- a/contrib/less/line.c +++ b/contrib/less/line.c @@ -97,7 +97,7 @@ extern int twiddle; extern int status_col; extern int status_col_width; extern int linenum_width; -extern int auto_wrap, ignaw; +extern int auto_wrap, defer_wrap; extern int bo_s_width, bo_e_width; extern int ul_s_width, ul_e_width; extern int bl_s_width, bl_e_width; @@ -129,7 +129,7 @@ static struct color_map color_map[] = { { AT_COLOR_BIN, "kR" }, { AT_COLOR_CTRL, "kR" }, { AT_COLOR_ERROR, "kY" }, - { AT_COLOR_LINENUM, "c" }, + { AT_COLOR_LINENUM, "c*" }, { AT_COLOR_MARK, "Wb" }, { AT_COLOR_PROMPT, "kC" }, { AT_COLOR_RSCROLL, "kc" }, @@ -185,7 +185,7 @@ public void init_line(void) s = skipspc(s); if (*s == ',') ++s; - xbuf_add_data(&xbuf, (constant void *) &num, sizeof(num)); + xbuf_add_data(&xbuf, &num, sizeof(num)); ++osc_ansi_allow_count; } osc_ansi_allow = (long *) xbuf.data; @@ -436,7 +436,7 @@ public void plinestart(POSITION pos) for (i = 0; i + len < (size_t) linenum_width; i++) add_pfx(' ', AT_NORMAL); for (i = 0; i < len; i++) - add_pfx(buf[i], AT_BOLD|AT_COLOR_LINENUM); + add_pfx(buf[i], use_color ? AT_COLOR_LINENUM : AT_BOLD); add_pfx(' ', AT_NORMAL); } end_column = (int) linebuf.pfx_end; /*{{type-issue}}*/ @@ -1480,14 +1480,14 @@ public void pdone(lbool endline, lbool chopped, lbool forw) * the next line is blank. In that case the single newline output for * that blank line would be ignored!) */ - if (end_column < sc_width + cshift || !auto_wrap || (endline && ignaw) || ctldisp == OPT_ON) + if (end_column < sc_width + cshift || !auto_wrap || (endline && defer_wrap) || ctldisp == OPT_ON) { add_linebuf('\n', AT_NORMAL, 0); } - else if (ignaw && end_column >= sc_width + cshift && forw) + else if (defer_wrap && end_column >= sc_width + cshift && forw) { /* - * Terminals with "ignaw" don't wrap until they *really* need + * Terminals with "defer_wrap" don't wrap until they *really* need * to, i.e. when the character *after* the last one to fit on a * line is output. But they are too hard to deal with when they * get in the state where a full screen width of characters @@ -1509,7 +1509,7 @@ public void pdone(lbool endline, lbool chopped, lbool forw) * colored with the last char's background color before the color * reset sequence is sent. Clear the line to reset the background color. */ - if (auto_wrap && !ignaw && end_column >= sc_width + cshift) + if (auto_wrap && !defer_wrap && end_column >= sc_width + cshift) clear_after_line = TRUE; set_linebuf(linebuf.end, '\0', AT_NORMAL); } @@ -1915,27 +1915,36 @@ public void load_line(constant char *str) } /* - * Find the shift necessary to show the end of the longest displayed line. + * Find the length of the longest displayed line on the screen. */ -public int rrshift(void) +public int longest_line_width(void) { POSITION pos; int save_width; - int sline; + int sindex; int longest = 0; save_width = sc_width; sc_width = INT_MAX; /* so forw_line() won't chop */ - for (sline = TOP; sline < sc_height; sline++) - if ((pos = position(sline)) != NULL_POSITION) + for (sindex = TOP; sindex < sc_height-1; sindex++) + if ((pos = position(sindex)) != NULL_POSITION) break; - for (; sline < sc_height && pos != NULL_POSITION; sline++) + for (; sindex < sc_height-1 && pos != NULL_POSITION; sindex++) { pos = forw_line(pos, NULL, NULL); if (end_column > longest) longest = end_column; } sc_width = save_width; + return longest; +} + +/* + * Find the shift necessary to show the end of the longest displayed line. + */ +public int rrshift(void) +{ + int longest = longest_line_width(); if (longest < sc_width) return 0; return longest - sc_width; diff --git a/contrib/less/lsystem.c b/contrib/less/lsystem.c index a56f8238e480..0d55241eae85 100644 --- a/contrib/less/lsystem.c +++ b/contrib/less/lsystem.c @@ -32,6 +32,7 @@ #endif #endif +extern int sigs; extern IFILE curr_ifile; @@ -92,7 +93,7 @@ public void lsystem(constant char *cmd, constant char *donemsg) /* * De-initialize the terminal and take out of raw mode. */ - deinit(); + term_deinit(); flush(); /* Make sure the deinit chars get out */ raw_mode(0); #if MSDOS_COMPILER==WIN32C @@ -135,9 +136,10 @@ public void lsystem(constant char *cmd, constant char *donemsg) char *esccmd = shell_quote(cmd); if (esccmd != NULL) { - size_t len = strlen(shell) + strlen(esccmd) + 5; + constant char *copt = shell_coption(); + size_t len = strlen(shell) + strlen(esccmd) + strlen(copt) + 3; p = (char *) ecalloc(len, sizeof(char)); - SNPRINTF3(p, len, "%s %s %s", shell, shell_coption(), esccmd); + SNPRINTF3(p, len, "%s %s %s", shell, copt, esccmd); free(esccmd); } } @@ -191,7 +193,7 @@ public void lsystem(constant char *cmd, constant char *donemsg) putchr('\n'); flush(); } - init(); + term_init(); screen_trashed(); #if MSDOS_COMPILER && MSDOS_COMPILER!=WIN32C @@ -220,15 +222,13 @@ public void lsystem(constant char *cmd, constant char *donemsg) */ reedit_ifile(save_ifile); -#if defined(SIGWINCH) || defined(SIGWIND) /* * Since we were ignoring window change signals while we executed * the system command, we must assume the window changed. * Warning: this leaves a signal pending (in "sigs"), * so psignals() should be called soon after lsystem(). */ - winch(0); -#endif + sigs |= S_WINCH; } #endif @@ -305,7 +305,7 @@ public int pipe_data(constant char *cmd, POSITION spos, POSITION epos) putstr(cmd); putstr("\n"); - deinit(); + term_deinit(); flush(); raw_mode(0); init_signals(0); @@ -351,11 +351,11 @@ public int pipe_data(constant char *cmd, POSITION spos, POSITION epos) #endif init_signals(1); raw_mode(1); - init(); + term_init(); screen_trashed(); #if defined(SIGWINCH) || defined(SIGWIND) /* {{ Probably don't need this here. }} */ - winch(0); + lwinch(0); #endif return (0); } diff --git a/contrib/less/main.c b/contrib/less/main.c index e3a546d7084d..312c19af28e1 100644 --- a/contrib/less/main.c +++ b/contrib/less/main.c @@ -40,6 +40,7 @@ public constant char *progname; public lbool quitting = FALSE; public int dohelp; public char * init_header = NULL; +public char * no_config = NULL; static int secure_allow_features; #if LOGFILE @@ -75,8 +76,9 @@ extern int quit_if_one_screen; extern int no_init; extern int errmsgs; extern int redraw_on_quit; -extern int term_init_done; +extern int term_addrs; extern lbool first_time; +extern lbool term_init_ever; #if MSDOS_COMPILER==WIN32C && (defined(__MINGW32__) || defined(_MSC_VER)) /* malloc'ed 0-terminated utf8 of 0-terminated wide ws, or null on errors */ @@ -205,6 +207,12 @@ static int security_feature(constant char *name, size_t len) return security_feature_error("invalid", len, name); return features[match].sf_value; } + +static lbool set_security_feature(constant char *word, size_t wlen, void *arg) +{ + secure_allow_features |= security_feature(word, wlen); + return TRUE; +} #endif /* !SECURE */ /* @@ -224,19 +232,7 @@ static void init_secure(void) str = lgetenv("LESSSECURE_ALLOW"); if (!isnullenv(str)) - { - for (;;) - { - constant char *estr; - while (*str == ' ' || *str == ',') ++str; /* skip leading spaces/commas */ - if (*str == '\0') break; - estr = strchr(str, ','); - if (estr == NULL) estr = str + strlen(str); - while (estr > str && estr[-1] == ' ') --estr; /* trim trailing spaces */ - secure_allow_features |= security_feature(str, ptr_diff(estr, str)); - str = estr; - } - } + parse_csl(set_security_feature, str, NULL); #endif } @@ -251,8 +247,11 @@ int main(int argc, constant char *argv[]) struct xbuffer xfiles; constant int *files; size_t num_files; + size_t f; lbool end_opts = FALSE; - lbool posixly_correct = FALSE; + lbool posixly_correct; + + no_config = getenv("LESSNOCONFIG"); #if MSDOS_COMPILER==WIN32C && (defined(__MINGW32__) || defined(_MSC_VER)) if (GetACP() != CP_UTF8) /* not using a UTF-8 manifest */ @@ -325,7 +324,7 @@ int main(int argc, constant char *argv[]) #define isoptstring(s) less_is_more ? (((s)[0] == '-') && (s)[1] != '\0') : \ (((s)[0] == '-' || (s)[0] == '+') && (s)[1] != '\0') xbuf_init(&xfiles); - posixly_correct = (getenv("POSIXLY_CORRECT") != NULL); + posixly_correct = (lgetenv("POSIXLY_CORRECT") != NULL); for (i = 0; i < argc; i++) { if (strcmp(argv[i], "--") == 0) @@ -336,7 +335,7 @@ int main(int argc, constant char *argv[]) { if (posixly_correct) end_opts = TRUE; - xbuf_add_data(&xfiles, (constant unsigned char *) &i, sizeof(i)); + xbuf_add_data(&xfiles, &i, sizeof(i)); } } #undef isoptstring @@ -379,7 +378,7 @@ int main(int argc, constant char *argv[]) ifile = get_ifile(FAKE_HELPFILE, ifile); files = (constant int *) xfiles.data; num_files = xfiles.end / sizeof(int); - for (i = 0; i < num_files; i++) + for (f = 0; f < num_files; f++) { #if (MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC) /* @@ -393,7 +392,7 @@ int main(int argc, constant char *argv[]) char *gfilename; char *qfilename; - gfilename = lglob(argv[files[i]]); + gfilename = lglob(argv[files[f]]); init_textlist(&tlist, gfilename); filename = NULL; while ((filename = forw_textlist(&tlist, filename)) != NULL) @@ -405,7 +404,7 @@ int main(int argc, constant char *argv[]) } free(gfilename); #else - (void) get_ifile(argv[files[i]], ifile); + (void) get_ifile(argv[files[f]], ifile); ifile = prev_ifile(NULL_IFILE); #endif } @@ -420,7 +419,7 @@ int main(int argc, constant char *argv[]) * Output is not a tty. * Just copy the input file(s) to output. */ - set_output(1); /* write to stdout */ + set_output(1, TRUE); /* write to stdout */ SET_BINARY(1); if (edit_first() == 0) { @@ -476,7 +475,7 @@ int main(int argc, constant char *argv[]) /* * See if file fits on one screen to decide whether * to send terminal init. But don't need this - * if -X (no_init) overrides this (see init()). + * if -X (no_init) overrides this (see term_init()). */ if (quit_if_one_screen) { @@ -504,8 +503,10 @@ int main(int argc, constant char *argv[]) get_return(); putchr('\n'); } - set_output(1); - init(); + set_output(1, FALSE); +#if MSDOS_COMPILER + term_init(); +#endif commands(); quit(QUIT_OK); /*NOTREACHED*/ @@ -617,9 +618,9 @@ public void quit(int status) check_altpipe_error(); if (interactive()) clear_bot(); - deinit(); + term_deinit(); flush(); - if (redraw_on_quit && term_init_done) + if (redraw_on_quit && term_addrs) { /* * The last file text displayed might have been on an diff --git a/contrib/less/mark.c b/contrib/less/mark.c index 858209605948..b15ff0f12a9d 100644 --- a/contrib/less/mark.c +++ b/contrib/less/mark.c @@ -27,7 +27,6 @@ struct mark * because we don't want to create an ifile until the * user explicitly requests the file (by name or mark). */ - char m_letter; /* Associated character */ IFILE m_ifile; /* Input file being marked */ char *m_filename; /* Name of the input file */ struct scrpos m_scrpos; /* Position of the mark */ @@ -39,12 +38,14 @@ struct mark * The final one is lmark, for the "last mark"; addressed by the apostrophe. */ #define NMARKS ((2*26)+2) /* a-z, A-Z, mousemark, lastmark */ -#define NUMARKS ((2*26)+1) /* user marks (not lastmark) */ -#define MOUSEMARK (NMARKS-2) +#define NUMARKS (NMARKS-1) /* user marks (not lastmark) */ #define LASTMARK (NMARKS-1) +#define MOUSEMARK (LASTMARK-1) static struct mark marks[NMARKS]; -public int marks_modified = 0; - +public lbool marks_modified = FALSE; +#if CMD_HISTORY +static struct mark file_marks[NMARKS]; +#endif /* * Initialize a mark struct. @@ -69,17 +70,23 @@ public void init_mark(void) for (i = 0; i < NMARKS; i++) { - char letter; - switch (i) { - case MOUSEMARK: letter = '#'; break; - case LASTMARK: letter = '\''; break; - default: letter = (char) ((i < 26) ? 'a'+i : 'A'+i-26); break; - } - marks[i].m_letter = letter; cmark(&marks[i], NULL_IFILE, NULL_POSITION, -1); +#if CMD_HISTORY + cmark(&file_marks[i], NULL_IFILE, NULL_POSITION, -1); +#endif } } +static void mark_clear(struct mark *m) +{ + m->m_scrpos.pos = NULL_POSITION; +} + +static lbool mark_is_set(struct mark *m) +{ + return m->m_scrpos.pos != NULL_POSITION; +} + /* * Set m_ifile and clear m_filename. */ @@ -102,22 +109,47 @@ static void mark_get_ifile(struct mark *m) } /* - * Return the user mark struct identified by a character. + * Return the letter associated with a mark index. */ -static struct mark * getumark(char c) +static char mark_letter(int index) +{ + switch (index) { + case LASTMARK: return '\''; + case MOUSEMARK: return '#'; + default: return (char) ((index < 26) ? 'a'+index : 'A'+index-26); + } +} + +/* + * Return the mark table index identified by a character. + */ +static int mark_index(char c) { - PARG parg; if (c >= 'a' && c <= 'z') - return (&marks[c-'a']); + return c-'a'; if (c >= 'A' && c <= 'Z') - return (&marks[c-'A'+26]); + return c-'A'+26; if (c == '\'') - return (&marks[LASTMARK]); + return LASTMARK; if (c == '#') - return (&marks[MOUSEMARK]); - parg.p_char = (char) c; - error("Invalid mark letter %c", &parg); - return (NULL); + return MOUSEMARK; + return -1; +} + +/* + * Return the user mark struct identified by a character. + */ +static struct mark * getumark(char c) +{ + int index = mark_index(c); + if (index < 0 || index >= NUMARKS) + { + PARG parg; + parg.p_char = (char) c; + error("Invalid mark letter %c", &parg); + return NULL; + } + return &marks[index]; } /* @@ -172,7 +204,7 @@ static struct mark * getmark(char c) m = getumark(c); if (m == NULL) break; - if (m->m_scrpos.pos == NULL_POSITION) + if (!mark_is_set(m)) { error("Mark not set", NULL_PARG); return (NULL); @@ -185,7 +217,7 @@ static struct mark * getmark(char c) /* * Is a mark letter invalid? */ -public int badmark(char c) +public lbool badmark(char c) { return (getmark(c) == NULL); } @@ -204,11 +236,13 @@ public void setmark(char c, int where) get_scrpos(&scrpos, where); if (scrpos.pos == NULL_POSITION) { - bell(); + lbell(); return; } cmark(m, curr_ifile, scrpos.pos, scrpos.ln); - marks_modified = 1; + marks_modified = TRUE; + if (perma_marks && autosave_action('m')) + save_cmdhist(); } /* @@ -223,11 +257,13 @@ public void clrmark(char c) return; if (m->m_scrpos.pos == NULL_POSITION) { - bell(); + lbell(); return; } m->m_scrpos.pos = NULL_POSITION; - marks_modified = 1; + marks_modified = TRUE; + if (perma_marks && autosave_action('m')) + save_cmdhist(); } /* @@ -243,7 +279,7 @@ public void lastmark(void) if (scrpos.pos == NULL_POSITION) return; cmark(&marks[LASTMARK], curr_ifile, scrpos.pos, scrpos.ln); - marks_modified = 1; + marks_modified = TRUE; } /* @@ -264,7 +300,7 @@ public void gomark(char c) * set it to the beginning of the current file. * {{ Couldn't we instead set marks[LASTMARK] in edit()? }} */ - if (m == &marks[LASTMARK] && m->m_scrpos.pos == NULL_POSITION) + if (m == &marks[LASTMARK] && !mark_is_set(m)) cmark(m, curr_ifile, ch_zero(), jump_sline); mark_get_ifile(m); @@ -316,14 +352,11 @@ public char posmark(POSITION pos) /* Only user marks */ for (i = 0; i < NUMARKS; i++) { - if (marks[i].m_ifile == curr_ifile && marks[i].m_scrpos.pos == pos) - { - if (i < 26) return (char) ('a' + i); - if (i < 26*2) return (char) ('A' + (i - 26)); - return '#'; - } + struct mark *m = &marks[i]; + if (m->m_ifile == curr_ifile && m->m_scrpos.pos == pos) + return mark_letter(i); } - return 0; + return '\0'; } /* @@ -335,7 +368,7 @@ public void unmark(IFILE ifile) for (i = 0; i < NMARKS; i++) if (marks[i].m_ifile == ifile) - marks[i].m_scrpos.pos = NULL_POSITION; + mark_clear(&marks[i]); } /* @@ -364,22 +397,44 @@ public void mark_check_ifile(IFILE ifile) #if CMD_HISTORY /* + * Initialize a mark struct, including the filename. + */ +static void cmarkf(struct mark *m, IFILE ifile, POSITION pos, int ln, constant char *filename) +{ + cmark(m, ifile, pos, ln); + m->m_filename = (filename == NULL) ? NULL : save(filename); +} + +/* * Save marks to history file. */ public void save_marks(FILE *fout, constant char *hdr) { int i; - if (!perma_marks) - return; + if (perma_marks) + { + /* Copy active marks to file_marks. */ + for (i = 0; i < NMARKS; i++) + { + struct mark *m = &marks[i]; + if (mark_is_set(m)) + cmarkf(&file_marks[i], m->m_ifile, m->m_scrpos.pos, m->m_scrpos.ln, m->m_filename); + } + } + /* + * Save file_marks to the history file. + * These may have been read from the history file at startup + * (in restore_mark), or copied from the active marks above. + */ fprintf(fout, "%s\n", hdr); for (i = 0; i < NMARKS; i++) { constant char *filename; - struct mark *m = &marks[i]; + struct mark *m = &file_marks[i]; char pos_str[INT_STRLEN_BOUND(m->m_scrpos.pos) + 2]; - if (m->m_scrpos.pos == NULL_POSITION) + if (!mark_is_set(m)) continue; postoa(m->m_scrpos.pos, pos_str, 10); filename = m->m_filename; @@ -387,7 +442,7 @@ public void save_marks(FILE *fout, constant char *hdr) filename = get_real_filename(m->m_ifile); if (strcmp(filename, "-") != 0) fprintf(fout, "m %c %d %s %s\n", - m->m_letter, m->m_scrpos.ln, pos_str, filename); + mark_letter(i), m->m_scrpos.ln, pos_str, filename); } } @@ -396,7 +451,7 @@ public void save_marks(FILE *fout, constant char *hdr) */ public void restore_mark(constant char *line) { - struct mark *m; + int index; int ln; POSITION pos; @@ -404,8 +459,8 @@ public void restore_mark(constant char *line) if (*line++ != 'm') return; skip_whitespace; - m = getumark(*line++); - if (m == NULL) + index = mark_index(*line++); + if (index < 0) return; skip_whitespace; ln = lstrtoic(line, &line, 10); @@ -420,8 +475,9 @@ public void restore_mark(constant char *line) if (pos < 0) return; skip_whitespace; - cmark(m, NULL_IFILE, pos, ln); - m->m_filename = save(line); + /* Save in both active marks table and file_marks table. */ + cmarkf(&marks[index], NULL_IFILE, pos, ln, line); + cmarkf(&file_marks[index], NULL_IFILE, pos, ln, line); } #endif /* CMD_HISTORY */ diff --git a/contrib/less/omit.uni b/contrib/less/omit.uni index 9977ec403f3d..dd6c2b841792 100644 --- a/contrib/less/omit.uni +++ b/contrib/less/omit.uni @@ -1,4 +1,4 @@ -/* Generated by "./mkutable -f2 Xx -- unicode/UnicodeData.txt" on Aug 19 1:16:32 GMT 2025 */ +/* Generated by "./mkutable -f2 Xx -- unicode/UnicodeData.txt" on Nov 28 1:30:12 GMT 2025 */ { 0x00ad, 0x00ad }, /* Xx */ { 0x200d, 0x200d }, /* Xx */ { 0xfe00, 0xfe0f }, /* Xx */ diff --git a/contrib/less/optfunc.c b/contrib/less/optfunc.c index 9c0117cc84ff..29d2748bc935 100644 --- a/contrib/less/optfunc.c +++ b/contrib/less/optfunc.c @@ -44,6 +44,7 @@ extern char *wproto; extern char *every_first_cmd; extern IFILE curr_ifile; extern char version[]; +extern int jump_sline_arg; extern int jump_sline; extern long jump_sline_fraction; extern int shift_count; @@ -73,6 +74,7 @@ extern int nosearch_header_cols; extern POSITION header_start_pos; extern char *init_header; extern char *first_cmd_at_prompt; +extern char *autosave; #if LOGFILE extern char *namelogfile; extern lbool force_logfile; @@ -166,36 +168,27 @@ public void opt__O(int type, constant char *s) } #endif -static int toggle_fraction(int *num, long *frac, constant char *s, constant char *printopt, void (*calc)(void)) +static void toggle_fraction(int *num, long *frac, constant char *s, constant char *printopt, lbool neg_ok, void (*calc)(void)) { - lbool err; if (s == NULL) { - (*calc)(); } else if (*s == '.') { - long tfrac; s++; - tfrac = getfraction(&s, printopt, &err); - if (err) + if (!getfraction(&s, frac)) { - error("Invalid fraction", NULL_PARG); - return -1; + PARG parg; + parg.p_string = printopt; + error("Invalid fraction in %s", &parg); + return; } - *frac = tfrac; - (*calc)(); } else { - int tnum = getnumc(&s, printopt, &err); - if (err) - { - error("Invalid number", NULL_PARG); - return -1; - } + if (!getnumc(&s, printopt, neg_ok, num)) + return; *frac = -1; - *num = tnum; } - return 0; + (*calc)(); } static void query_fraction(int value, long fraction, constant char *int_msg, constant char *frac_msg) @@ -229,11 +222,11 @@ public void opt_j(int type, constant char *s) { case INIT: case TOGGLE: - toggle_fraction(&jump_sline, &jump_sline_fraction, - s, "j", calc_jump_sline); + toggle_fraction(&jump_sline_arg, &jump_sline_fraction, + s, "-j", TRUE, calc_jump_sline); break; case QUERY: - query_fraction(jump_sline, jump_sline_fraction, + query_fraction(jump_sline_arg, jump_sline_fraction, "Position target at screen line %d", "Position target at screen position %s"); break; } @@ -241,10 +234,19 @@ public void opt_j(int type, constant char *s) public void calc_jump_sline(void) { + jump_sline = jump_sline_arg; + /* If jump_sline_fraction is set, calculate jump_sline from it. */ if (jump_sline_fraction >= 0) jump_sline = (int) muldiv(sc_height, jump_sline_fraction, NUM_FRAC_DENOM); + /* Negative jump_sline means relative to bottom of screen. */ + if (jump_sline < 0) + jump_sline += sc_height; + /* If jump_sline is obscured by header, move it after the header. */ if (jump_sline <= header_lines) jump_sline = header_lines + 1; + /* If jump_sline is past bottom of screen, move it to the bottom. */ + if (jump_sline >= sc_height) + jump_sline = sc_height - 1; } /* @@ -257,7 +259,7 @@ public void opt_shift(int type, constant char *s) case INIT: case TOGGLE: toggle_fraction(&shift_count, &shift_count_fraction, - s, "#", calc_shift_count); + s, "-#", FALSE, calc_shift_count); break; case QUERY: query_fraction(shift_count, shift_count_fraction, @@ -473,6 +475,30 @@ public void opt__P(int type, constant char *s) } /* + * Handler for --autosave option. + */ +public void opt_autosave(int type, constant char *s) +{ + PARG parg; + + switch (type) + { + case INIT: + case TOGGLE: + if (s == NULL) + s = "-"; + if (autosave != NULL) + free(autosave); + autosave = save(s); + break; + case QUERY: + parg.p_string = (autosave != NULL) ? autosave : "-"; + error("Autosave actions: %s", &parg); + break; + } +} + +/* * Handler for the -b option. */ /*ARGSUSED*/ @@ -522,7 +548,7 @@ public void opt__V(int type, constant char *s) dispversion(); break; case INIT: - set_output(1); /* Force output to stdout per GNU standard for --version output. */ + set_output(1, TRUE); /* Force output to stdout per GNU standard for --version output. */ putstr("less "); putstr(version); putstr(" ("); @@ -854,7 +880,7 @@ public void opt_match_shift(int type, constant char *s) case INIT: case TOGGLE: toggle_fraction(&match_shift, &match_shift_fraction, - s, "--match-shift", calc_match_shift); + s, "--match-shift", FALSE, calc_match_shift); break; case QUERY: query_fraction(match_shift, match_shift_fraction, @@ -1019,28 +1045,24 @@ public void opt_intr(int type, constant char *s) * Return -1 if the list entry is missing or empty. * Updates *sp to point to the first char of the next number in the list. */ -public int next_cnum(constant char **sp, constant char *printopt, constant char *errmsg, lbool *errp) +static lbool next_cnum(constant char **sp, constant char *printopt, mutable int *p_num) { - int n; - *errp = FALSE; if (**sp == '\0') /* at end of line */ - return -1; - if (**sp == ',') /* that's the next comma; we have an empty string */ { - ++(*sp); - return -1; + *p_num = -1; + return TRUE; } - n = getnumc(sp, printopt, errp); - if (*errp) + if (**sp == ',') /* that's the next comma; we have an empty string */ { - PARG parg; - parg.p_string = errmsg; - error("invalid %s", &parg); - return -1; + ++(*sp); + *p_num = -1; + return TRUE; } + if (!getnumc(sp, printopt, FALSE, p_num)) + return FALSE; if (**sp == ',') ++(*sp); - return n; + return TRUE; } /* @@ -1050,26 +1072,21 @@ public int next_cnum(constant char **sp, constant char *printopt, constant char static lbool parse_header(constant char *s, int *lines, int *cols, POSITION *start_pos) { int n; - lbool err; if (*s == '-') s = "0,0"; - - n = next_cnum(&s, "header", "number of lines", &err); - if (err) return FALSE; + if (!next_cnum(&s, "--header", &n)) + return FALSE; if (n >= 0) *lines = n; - - n = next_cnum(&s, "header", "number of columns", &err); - if (err) return FALSE; + if (!next_cnum(&s, "--header", &n)) + return FALSE; if (n >= 0) *cols = n; - - n = next_cnum(&s, "header", "line number", &err); - if (err) return FALSE; - if (n > 0) + if (!next_cnum(&s, "--header", &n)) + return FALSE; + if (n > 0) { - LINENUM lnum = (LINENUM) n; - if (lnum < 1) lnum = 1; - *start_pos = find_pos(lnum); + if (n < 1) n = 1; + *start_pos = find_pos((LINENUM)n); } return TRUE; } @@ -1264,3 +1281,10 @@ public int get_swindow(void) return (sc_height - header_lines + swindow); } +/* + * Should an action initiate an autosave? + */ +public lbool autosave_action(char act) +{ + return strchr(autosave, act) != NULL || strchr(autosave, '*') != NULL; +} diff --git a/contrib/less/option.c b/contrib/less/option.c index 3c3465e82017..77ab1b305cdf 100644 --- a/contrib/less/option.c +++ b/contrib/less/option.c @@ -70,7 +70,6 @@ public void scan_option(constant char *s, lbool is_env) char *str; lbool set_default; lbool lc; - lbool ambig; PARG parg; if (s == NULL) @@ -94,7 +93,7 @@ public void scan_option(constant char *s, lbool is_env) break; case O_NUMBER: printopt = opt_desc(pendopt); - *(pendopt->ovar) = getnumc(&s, printopt, NULL); + getnumc(&s, printopt, FALSE, pendopt->ovar); break; } } @@ -179,14 +178,20 @@ public void scan_option(constant char *s, lbool is_env) * Not a special case. * Look up the option letter in the option table. */ - ambig = FALSE; if (optname == NULL) { printopt = propt(optc); lc = ASCII_IS_LOWER(optc); o = findopt(optc); + if (o == NULL) + { + parg.p_string = printopt; + error("There is no %s option (\"less --help\" for help)", &parg); + return; + } } else { + lbool ambig = FALSE; printopt = optname; lc = ASCII_IS_LOWER(optname[0]); o = findopt_name(&optname, NULL, &ambig); @@ -208,7 +213,7 @@ public void scan_option(constant char *s, lbool is_env) (o->otype & OTYPE) != O_NUMBER) { parg.p_string = printopt; - error("The %s option should not be followed by =", + error("The --%s option should not be followed by =", &parg); return; } @@ -221,17 +226,15 @@ public void scan_option(constant char *s, lbool is_env) */ o = NULL; } - } - if (o == NULL) - { - parg.p_string = printopt; - if (ambig) - error("%s is an ambiguous abbreviation (\"less --help\" for help)", - &parg); - else - error("There is no %s option (\"less --help\" for help)", - &parg); - return; + if (o == NULL) + { + parg.p_string = printopt; + if (ambig) + error("--%s is an ambiguous abbreviation (\"less --help\" for help)", &parg); + else + error("There is no --%s option (\"less --help\" for help)", &parg); + return; + } } str = NULL; @@ -292,7 +295,7 @@ public void scan_option(constant char *s, lbool is_env) } if (o->otype & O_UNSUPPORTED) break; - *(o->ovar) = getnumc(&s, printopt, NULL); + getnumc(&s, printopt, FALSE, o->ovar); break; } /* @@ -314,11 +317,9 @@ public void scan_option(constant char *s, lbool is_env) * OPT_UNSET set to the default value * OPT_SET set to the inverse of the default value */ -public void toggle_option(struct loption *o, lbool lower, constant char *s, int how_toggle) +public lbool toggle_option(struct loption *o, lbool lower, constant char *s, int how_toggle) { - int num; int no_prompt; - lbool err; PARG parg; no_prompt = (how_toggle & OPT_NO_PROMPT); @@ -327,21 +328,21 @@ public void toggle_option(struct loption *o, lbool lower, constant char *s, int if (o == NULL) { error("No such option", NULL_PARG); - return; + return FALSE; } if (how_toggle == OPT_TOGGLE && (o->otype & O_NO_TOGGLE)) { parg.p_string = opt_desc(o); error("Cannot change the %s option", &parg); - return; + return FALSE; } if (how_toggle == OPT_NO_TOGGLE && (o->otype & O_NO_QUERY)) { parg.p_string = opt_desc(o); error("Cannot query the %s option", &parg); - return; + return FALSE; } /* @@ -426,7 +427,7 @@ public void toggle_option(struct loption *o, lbool lower, constant char *s, int case OPT_UNSET: error("Cannot use \"-+\" or \"-!\" for a string option", NULL_PARG); - return; + return FALSE; } break; case O_NUMBER: @@ -436,9 +437,8 @@ public void toggle_option(struct loption *o, lbool lower, constant char *s, int switch (how_toggle) { case OPT_TOGGLE: - num = getnumc(&s, NULL, &err); - if (!err) - *(o->ovar) = num; + if (!getnumc(&s, opt_desc(o), FALSE, o->ovar)) + return FALSE; break; case OPT_UNSET: *(o->ovar) = o->odefault; @@ -446,7 +446,7 @@ public void toggle_option(struct loption *o, lbool lower, constant char *s, int case OPT_SET: error("Can't use \"-!\" for a numeric option", NULL_PARG); - return; + return FALSE; } break; } @@ -488,15 +488,15 @@ public void toggle_option(struct loption *o, lbool lower, constant char *s, int error(o->odesc[1], &parg); break; case O_STRING: - /* - * Message was already printed by the handling function. - */ + if (how_toggle != OPT_NO_TOGGLE && o->ofunc != NULL) + (*o->ofunc)(QUERY, NULL); break; } } if (how_toggle != OPT_NO_TOGGLE && (o->otype & O_REPAINT)) screen_trashed(); + return TRUE; } /* @@ -513,20 +513,20 @@ static int flip_triple(int val, lbool lc) /* * Determine if an option takes a parameter. */ -public int opt_has_param(struct loption *o) +public lbool opt_has_param(constant struct loption *o) { if (o == NULL) - return (0); + return FALSE; if (o->otype & (O_BOOL|O_TRIPLE|O_NOVAR|O_NO_TOGGLE)) - return (0); - return (1); + return FALSE; + return TRUE; } /* * Return the prompt to be used for a given option letter. * Only string and number valued options have prompts. */ -public constant char * opt_prompt(struct loption *o) +public constant char * opt_prompt(constant struct loption *o) { if (o == NULL || (o->otype & (O_STRING|O_NUMBER)) == 0) return ("?"); @@ -653,26 +653,29 @@ static constant char * optstring(constant char *s, char **p_str, constant char * return (p); } +typedef enum { + NUM_ERR_NONE, NUM_ERR_OVERFLOW, NUM_ERR_NEG, NUM_ERR_MISSING +} num_error_type; + /* + * Display error message for invalid number. */ -static int num_error(constant char *printopt, lbool *errp, lbool overflow) +static lbool num_error(constant char *printopt, num_error_type error_type) { - PARG parg; - - if (errp != NULL) - { - *errp = TRUE; - return (-1); - } if (printopt != NULL) { + constant char *msg; + PARG parg; + switch (error_type) + { + case NUM_ERR_OVERFLOW: msg = "Number too large in %s"; break; + case NUM_ERR_NEG: msg = "Negative number not allowed in %s"; break; + default: msg = "Number is required after %s"; break; + } parg.p_string = printopt; - error((overflow - ? "Number too large in '%s'" - : "Number is required after %s"), - &parg); + error(msg, &parg); } - return (-1); + return FALSE; } /* @@ -680,38 +683,38 @@ static int num_error(constant char *printopt, lbool *errp, lbool overflow) * Like atoi(), but takes a pointer to a char *, and updates * the char * to point after the translated number. */ -public int getnumc(constant char **sp, constant char *printopt, lbool *errp) +public lbool getnumc(constant char **sp, constant char *printopt, lbool neg_ok, mutable int *p_num) { constant char *s = *sp; int n; - lbool neg; + lbool neg = FALSE; s = skipspc(s); - neg = FALSE; if (*s == '-') { + if (!neg_ok) + return num_error(printopt, NUM_ERR_NEG); neg = TRUE; s++; } if (*s < '0' || *s > '9') - return (num_error(printopt, errp, FALSE)); - + return num_error(printopt, NUM_ERR_MISSING); n = lstrtoic(s, sp, 10); if (n < 0) - return (num_error(printopt, errp, TRUE)); - if (errp != NULL) - *errp = FALSE; + return num_error(printopt, NUM_ERR_OVERFLOW); if (neg) n = -n; - return (n); + *p_num = n; + return TRUE; } -public int getnum(char **sp, constant char *printopt, lbool *errp) +public lbool getnum(char **sp, constant char *printopt, lbool neg_ok, mutable int *p_num) { constant char *cs = *sp; - int r = getnumc(&cs, printopt, errp); + if (!getnumc(&cs, printopt, neg_ok, p_num)) + return FALSE; *sp = (char *) cs; - return r; + return TRUE; } /* @@ -720,7 +723,7 @@ public int getnum(char **sp, constant char *printopt, lbool *errp) * The value of the fraction is returned as parts per NUM_FRAC_DENOM. * That is, if "n" is returned, the fraction intended is n/NUM_FRAC_DENOM. */ -public long getfraction(constant char **sp, constant char *printopt, lbool *errp) +public lbool getfraction(constant char **sp, mutable long *p_frac) { constant char *s; long frac = 0; @@ -728,7 +731,7 @@ public long getfraction(constant char **sp, constant char *printopt, lbool *errp s = skipspc(*sp); if (*s < '0' || *s > '9') - return (num_error(printopt, errp, FALSE)); + return FALSE; for ( ; *s >= '0' && *s <= '9'; s++) { @@ -740,9 +743,8 @@ public long getfraction(constant char **sp, constant char *printopt, lbool *errp while (fraclen++ < NUM_LOG_FRAC_DENOM) frac *= 10; *sp = s; - if (errp != NULL) - *errp = FALSE; - return (frac); + *p_frac = frac; + return TRUE; } /* diff --git a/contrib/less/opttbl.c b/contrib/less/opttbl.c index 292a8be15d1e..cf790125a976 100644 --- a/contrib/less/opttbl.c +++ b/contrib/less/opttbl.c @@ -40,6 +40,7 @@ public int ctldisp; /* Send control chars to screen untranslated */ public int force_open; /* Open the file even if not regular file */ public int swindow; /* Size of scrolling window */ public int jump_sline; /* Screen line of "jump target" */ +public int jump_sline_arg; public long jump_sline_fraction = -1; public int shift_count; /* Number of positions to shift horizontally */ public long shift_count_fraction = -1; @@ -87,6 +88,7 @@ public int stop_on_form_feed; /* Stop scrolling on a line starting with form f public long match_shift_fraction = NUM_FRAC_DENOM/2; /* 1/2 of screen width */ public char intr_char = CONTROL('X'); /* Char to interrupt reads */ public char *first_cmd_at_prompt = NULL; /* Command to exec before first prompt */ +public char *autosave; /* Actions which do autosave of history file */ #if HILITE_SEARCH public int hilite_search; /* Highlight matched search patterns? */ #endif @@ -186,6 +188,7 @@ static struct optname proc_tab_optname = { "proc-tab", NULL }; static struct optname proc_return_optname = { "proc-return", NULL }; static struct optname match_shift_optname = { "match-shift", NULL }; static struct optname first_cmd_at_prompt_optname = { "cmd", NULL }; +static struct optname autosave_optname = { "autosave", NULL }; #if LESSTEST static struct optname ttyin_name_optname = { "tty", NULL }; #endif /*LESSTEST*/ @@ -762,6 +765,10 @@ static struct loption option[] = NULL } }, + { OLETTER_NONE, &autosave_optname, + O_STRING|O_INIT_HANDLER, 0, NULL, opt_autosave, + { "Autosave actions: ", "s", NULL } + }, #if LESSTEST { OLETTER_NONE, &ttyin_name_optname, O_STRING|O_NO_TOGGLE, 0, NULL, opt_ttyin_name, diff --git a/contrib/less/os.c b/contrib/less/os.c index 3bac7a61a7be..208a9724e362 100644 --- a/contrib/less/os.c +++ b/contrib/less/os.c @@ -82,7 +82,6 @@ static lbool opening; public lbool waiting_for_data; public int consecutive_nulls = 0; public lbool getting_one_screen = FALSE; -public lbool no_poll = FALSE; /* Milliseconds to wait for data before displaying "waiting for data" message. */ static int waiting_for_data_delay = 4000; @@ -93,7 +92,7 @@ static JUMP_BUF read_label; static JUMP_BUF open_label; extern int sigs; -extern int ignore_eoi; +extern lbool ignore_eoi; extern int exit_F_on_close; extern int follow_mode; extern int scanning_eof; @@ -104,7 +103,7 @@ extern int one_screen; #if HAVE_TIME extern time_type less_start_time; #endif -#if !MSDOS_COMPILER +#if LESS_IREAD_TTY extern int tty; #endif @@ -164,8 +163,6 @@ static int check_poll(int fd, int tty) /* Break out of "waiting for data". */ return (READ_INTR); ungetcc_back((char) ch); - if (!no_poll) - return (READ_INTR); } } if (ignore_eoi && exit_F_on_close && (poller[0].revents & (POLLHUP|POLLIN)) == POLLHUP) @@ -198,6 +195,7 @@ public lbool ttyin_ready(void) if (!use_poll) return FALSE; { + /* {{ assert LESS_IREAD_TTY }} */ struct pollfd poller[1] = { { tty, POLLIN, 0 } }; poll(poller, 1, 0); return ((poller[0].revents & POLLIN) != 0); @@ -209,7 +207,7 @@ public lbool ttyin_ready(void) #endif } -public int supports_ctrl_x(void) +public lbool supports_ctrl_x(void) { #if MSDOS_COMPILER==WIN32C return (TRUE); @@ -269,7 +267,7 @@ start: #endif #endif #endif -#if !MSDOS_COMPILER +#if !MSDOS_COMPILER /* {{ LESS_IREAD_TTY? }} */ if (fd != tty && !ABORT_SIGS()) /* Non-interrupt signal like SIGWINCH. */ return (READ_AGAIN); @@ -316,19 +314,14 @@ start: #if MSDOS_COMPILER==WIN32C if (!(quit_if_one_screen && one_screen) && win32_kbhit2(TRUE)) { - int c; - lbool intr; - - c = WIN32getch(); - intr = (c == CONTROL('C') || c == intr_char); - if (!intr) - WIN32ungetch((char) c); - if (intr || !no_poll) + int c = WIN32getch(); + if (c == CONTROL('C') || c == intr_char) { sigs |= S_SWINTERRUPT; reading = FALSE; return (READ_INTR); } + WIN32ungetch(c); } #endif #endif @@ -369,10 +362,13 @@ start: #endif return (READ_ERR); } -#if USE_POLL - if (fd != tty && n > 0) - any_data = TRUE; +#if LESS_IREAD_TTY + if (fd != tty) #endif + { + if (n > 0) + polling_ok(); + } return (n); } @@ -419,6 +415,16 @@ public void intio(void) } /* + * We can start polling the input file. + */ +public void polling_ok(void) +{ +#if USE_POLL + any_data = TRUE; +#endif +} + +/* * Return the current time. */ #if HAVE_TIME @@ -548,7 +554,7 @@ char * strchr(char *s, char c) #endif #if !HAVE_MEMCPY -void * memcpy(void *dst, void *src, size_t len) +void * memcpy(void *dst, constant void *src, size_t len) { char *dstp = (char *) dst; char *srcp = (char *) src; @@ -560,6 +566,25 @@ void * memcpy(void *dst, void *src, size_t len) } #endif +#if !HAVE_STRSTR +char * strstr(constant char *haystack, constant char *needle) +{ + if (*needle == '\0') + return (char *) haystack; + for (; *haystack; haystack++) { + constant char *h = haystack; + constant char *n = needle; + while (*h != '\0' && *n != '\0' && *h == *n) { + h++; + n++; + } + if (*n == '\0') + return (char *) haystack; + } + return NULL; +} +#endif + #ifdef _OSK_MWC32 /* diff --git a/contrib/less/output.c b/contrib/less/output.c index 6a1521a552e6..57c54eebe160 100644 --- a/contrib/less/output.c +++ b/contrib/less/output.c @@ -23,7 +23,6 @@ public int errmsgs; /* Count of messages displayed by error() */ public int need_clr; public int final_attr; -public int at_prompt; extern int sigs; extern int sc_width; @@ -32,6 +31,7 @@ extern int is_tty; extern int oldbot; extern int utf_mode; extern char intr_char; +extern lbool term_init_ever; #if MSDOS_COMPILER==WIN32C || MSDOS_COMPILER==BORLANDC || MSDOS_COMPILER==DJGPPC extern int ctldisp; @@ -84,7 +84,7 @@ public void put_line(lbool forw_scroll) /* * win_flush has at least one non-critical issue when an escape sequence * begins at the last char of the buffer, and possibly more issues. - * as a temporary measure to reduce likelyhood of encountering end-of-buffer + * as a temporary measure to reduce likelihood of encountering end-of-buffer * issues till the SGR parser is replaced, OUTBUF_SIZE is 8K on Windows. */ static char obuf[OUTBUF_SIZE]; @@ -435,17 +435,19 @@ public void flush(void) #endif #endif - if (write(outfd, obuf, n) != n) + if (write(outfd, obuf, n) != (ssize_t) n) screen_trashed(); } /* * Set the output file descriptor (1=stdout or 2=stderr). */ -public void set_output(int fd) +public void set_output(int fd, lbool no_term_init) { flush(); outfd = fd; + if (no_term_init) + term_init_ever = TRUE; /* don't init terminal in putchr */ } /* @@ -455,8 +457,17 @@ public void set_output(int fd) public int putchr(int ch) { char c = (char) ch; + + /* + * Init the terminal if this is the first byte written to stdout + * (rather than stderr), and the terminal has never been initted. + * If it has previously been initted, it will be reinitted explicitly + * as part of a term_deinit/term_init pair, so we shouldn't do it here. + */ + if (!term_init_ever && outfd == 1) + term_init(); + #if 0 /* fake UTF-8 output for testing */ - extern int utf_mode; if (utf_mode) { static char ubuf[MAX_UTF_CHAR_LEN]; @@ -494,7 +505,6 @@ public int putchr(int ch) if (ob >= &obuf[sizeof(obuf)-1]) flush(); *ob++ = c; - at_prompt = 0; return (c); } @@ -590,7 +600,7 @@ IPRINT_FUNC(iprint_linenum, LINENUM, linenumtoa) * {{ This paranoia about the portability of printf dates from experiences * with systems in the 1980s and is of course no longer necessary. }} */ -public int less_printf(constant char *fmt, PARG *parg) +public int less_printf(constant char *fmt, constant PARG *parg) { constant char *s; constant char *es; @@ -664,7 +674,7 @@ public void get_return(void) #if ONLY_RETURN while ((c = getchr()) != '\n' && c != '\r') - bell(); + lbell(); #else c = getchr(); if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR) @@ -676,7 +686,7 @@ public void get_return(void) * Output a message in the lower left corner of the screen * and wait for carriage return. */ -public void error(constant char *fmt, PARG *parg) +public void error(constant char *fmt, constant PARG *parg) { int col = 0; static char return_to_continue[] = " (press RETURN)"; @@ -722,7 +732,7 @@ public void error(constant char *fmt, PARG *parg) * Usually used to warn that we are beginning a potentially * time-consuming operation. */ -static void ierror_suffix(constant char *fmt, PARG *parg, constant char *suffix1, constant char *suffix2, constant char *suffix3) +static void ierror_suffix(constant char *fmt, constant PARG *parg, constant char *suffix1, constant char *suffix2, constant char *suffix3) { at_exit(); clear_bot(); @@ -736,12 +746,12 @@ static void ierror_suffix(constant char *fmt, PARG *parg, constant char *suffix1 need_clr = 1; } -public void ierror(constant char *fmt, PARG *parg) +public void ierror(constant char *fmt, constant PARG *parg) { ierror_suffix(fmt, parg, "... (interrupt to abort)", "", ""); } -public void ixerror(constant char *fmt, PARG *parg) +public void ixerror(constant char *fmt, constant PARG *parg) { if (!supports_ctrl_x()) ierror(fmt, parg); @@ -757,7 +767,7 @@ public void ixerror(constant char *fmt, PARG *parg) * Output a message in the lower left corner of the screen * and return a single-character response. */ -public int query(constant char *fmt, PARG *parg) +public int query(constant char *fmt, constant PARG *parg) { int c; int col = 0; diff --git a/contrib/less/pckeys.h b/contrib/less/pckeys.h index 93957d0e1151..335863511b08 100644 --- a/contrib/less/pckeys.h +++ b/contrib/less/pckeys.h @@ -13,21 +13,26 @@ * Special (non-ASCII) keys on the PC send a two-byte sequence, * where the first byte is 0 and the second is as defined below. */ -#define PCK_SHIFT_TAB '\017' -#define PCK_ALT_E '\022' -#define PCK_CAPS_LOCK '\072' -#define PCK_F1 '\073' -#define PCK_NUM_LOCK '\105' -#define PCK_HOME '\107' -#define PCK_UP '\110' -#define PCK_PAGEUP '\111' -#define PCK_LEFT '\113' -#define PCK_RIGHT '\115' -#define PCK_END '\117' -#define PCK_DOWN '\120' -#define PCK_PAGEDOWN '\121' -#define PCK_INSERT '\122' -#define PCK_DELETE '\123' -#define PCK_CTL_LEFT '\163' -#define PCK_CTL_RIGHT '\164' -#define PCK_CTL_DELETE '\223' +#define PCK_SHIFT_TAB '\x0f' +#define PCK_ALT_E '\x12' +#define PCK_CAPS_LOCK '\x3a' +#define PCK_F1 '\x3b' +#define PCK_NUM_LOCK '\x45' +#define PCK_HOME '\x47' +#define PCK_UP '\x48' +#define PCK_PAGEUP '\x49' +#define PCK_LEFT '\x4b' +#define PCK_RIGHT '\x4d' +#define PCK_END '\x4f' +#define PCK_DOWN '\x50' +#define PCK_PAGEDOWN '\x51' +#define PCK_INSERT '\x52' +#define PCK_DELETE '\x53' +/* The following are nonstandard and internal to less. */ +#define PCK_SHIFT_END '\x61' +#define PCK_CTL_DELETE '\x62' +#define PCK_CTL_LEFT '\x63' +#define PCK_CTL_RIGHT '\x74' +#define PCK_CTL_HOME '\x7a' +#define PCK_CTL_END '\x7c' +#define PCK_SHIFT_HOME '\x7d' diff --git a/contrib/less/position.c b/contrib/less/position.c index 66e501c09060..3de034c17af4 100644 --- a/contrib/less/position.c +++ b/contrib/less/position.c @@ -147,19 +147,19 @@ public int onscreen(POSITION pos) /* * See if the entire screen is empty. */ -public int empty_screen(void) +public lbool empty_screen(void) { return (empty_lines(0, sc_height-1)); } -public int empty_lines(int s, int e) +public lbool empty_lines(int s, int e) { int i; for (i = s; i <= e; i++) if (table[i] != NULL_POSITION && table[i] != 0) - return (0); - return (1); + return FALSE; + return TRUE; } /* @@ -232,12 +232,12 @@ public int sindex_from_sline(int sline) if (sline < 0) sline += sc_height; /* - * Can't be less than 1 or greater than sc_height. + * Can't be less than 1 or greater than sc_height-1. */ if (sline <= 0) sline = 1; - if (sline > sc_height) - sline = sc_height; + if (sline >= sc_height) + sline = sc_height-1; /* * Return zero-based line number, not one-based. */ diff --git a/contrib/less/prompt.c b/contrib/less/prompt.c index a77783a458f1..b37d09a346a8 100644 --- a/contrib/less/prompt.c +++ b/contrib/less/prompt.c @@ -24,6 +24,7 @@ extern int pr_type; extern lbool new_file; extern int linenums; extern int hshift; +extern int sc_width; extern int sc_height; extern int jump_sline; extern int less_is_more; @@ -47,9 +48,9 @@ static constant char s_proto[] = static constant char m_proto[] = "?n?f%f .?m(%T %i of %m) ..?e(END) ?x- Next\\: %x.:?pB%pB\\%:byte %bB?s/%s...%t"; static constant char M_proto[] = - "?f%f .?n?m(%T %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..%t"; + "?f%f .?n?m(%T %i of %m) ..?ltlines %lt-%lb?L/%L. :byte %bB?s/%s. .?e(END) ?x- Next\\: %x.:?pB%pB\\%..?c (column %c).%t"; static constant char e_proto[] = - "?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..%t"; + "?f%f .?m(%T %i of %m) .?ltlines %lt-%lb?L/%L. .byte %bB?s/%s. ?e(END) :?pB%pB\\%..?c (column %c).%t"; static constant char h_proto[] = "HELP -- ?eEND -- Press g to see it again:Press RETURN for more., or q when done"; static constant char w_proto[] = @@ -64,6 +65,7 @@ public char constant *wproto = w_proto; static char message[PROMPT_SIZE]; static char *mp; +static int longest_line; /* * Initialize the prompt prototype strings. @@ -79,6 +81,18 @@ public void init_prompt(void) } /* + * Get width of longest line currently on screen. + * Calling longest_line_width() is expensive, so we cache its value here + * in case it is called more than once per prompt expansion. + */ +static int pr_longest_line(void) +{ + if (longest_line < 0) + longest_line = longest_line_width(); + return longest_line; +} + +/* * Append a string to the end of the message. * nprt means the character *may* be nonprintable * and should be converted to printable form. @@ -233,6 +247,8 @@ static lbool cond(char c, int where) return (currline(where) != 0 && (len = ch_length()) > 0 && find_linenum(len) != 0); + case 'Q': /* Any on-screen line truncated? */ + return (hshift + sc_width < pr_longest_line()); case 's': /* Size of file known? */ case 'B': return (ch_length() != NULL_POSITION); @@ -275,7 +291,10 @@ static void protochar(char c, int where) ap_quest(); break; case 'c': - ap_int(hshift); + ap_int(hshift+1); + break; + case 'C': + ap_int(hshift + sc_width); break; case 'd': /* Current page number */ linenum = currline(where); @@ -374,6 +393,9 @@ static void protochar(char c, int where) else ap_int(percentage(linenum, last_linenum)); break; + case 'Q': /* Percent shifted horizontally */ + ap_int(percentage(hshift + sc_width, pr_longest_line())); + break; case 's': /* Size of file */ case 'B': len = ch_length(); @@ -395,6 +417,9 @@ static void protochar(char c, int where) #endif ap_str("file"); break; + case 'W': /* Width of longest line on screen */ + ap_int(pr_longest_line()); + break; case 'x': /* Name of next file */ h = next_ifile(curr_ifile); if (h != NULL_IFILE) @@ -496,11 +521,12 @@ public constant char * pr_expand(constant char *proto) char c; int where; - mp = message; - if (*proto == '\0') return (""); + mp = message; + longest_line = -1; + for (p = proto; *p != '\0'; p++) { switch (*p) diff --git a/contrib/less/screen.c b/contrib/less/screen.c index 7b91cbb63bbe..ee75503fc780 100644 --- a/contrib/less/screen.c +++ b/contrib/less/screen.c @@ -68,6 +68,14 @@ extern int fd0; #endif #endif +#if HAVE_TERMINFO && !USE_TERMCAP +#define USE_TERMINFO 1 +#endif + +#if USE_TERMINFO +#include <curses.h> +#include <term.h> +#else #if HAVE_NCURSESW_TERMCAP_H #include <ncursesw/termcap.h> #else @@ -79,6 +87,7 @@ extern int fd0; #endif #endif #endif +#endif #ifdef _OSK #include <signal.h> #endif @@ -193,10 +202,29 @@ public int vt_enabled = -1; /* Is virtual terminal processing available? */ #else /* + * These two variables are sometimes defined in, + * and needed by, the termcap library. + */ +#if USE_TERMINFO +#undef HAVE_OSPEED +#else +#if MUST_DEFINE_OSPEED +extern short ospeed; /* Terminal output baud rate */ +extern char PC; /* Pad character */ +#endif +#ifdef _OSK +short ospeed; +char PC_, *UP, *BC; +#endif +#endif + +/* * Strings passed to tputs() to do various terminal functions. */ static constant char +#if HAVE_OSPEED *sc_pad, /* Pad string */ +#endif *sc_home, /* Cursor home */ *sc_addline, /* Add line, scroll down following lines */ *sc_lower_left, /* Cursor to last line, first column */ @@ -229,10 +257,12 @@ static constant char static int attrcolor = -1; #endif -static int init_done = 0; +/* term_init has been called; terminal is ready for use by less */ +static lbool term_init_done = FALSE; +public lbool term_init_ever = FALSE; public int auto_wrap; /* Terminal does \r\n when write past margin */ -public int ignaw; /* Terminal ignores \n immediately after wrap */ +public int defer_wrap; /* After printing char in last column, doesn't wrap until next char */ public int erase_char; /* The user's erase char */ public int erase2_char; /* The user's other erase char */ public int kill_char; /* The user's line-kill char */ @@ -247,8 +277,8 @@ public int can_goto_line; /* Can move cursor to any line */ public int clear_bg; /* Clear fills with background color */ public lbool missing_cap = FALSE; /* Some capability is missing */ public constant char *kent = NULL; /* Keypad ENTER sequence */ -public lbool term_init_done = FALSE; -public lbool full_screen = TRUE; +public lbool term_addrs = FALSE; /* "ti" has been sent to terminal */ +public lbool full_screen = TRUE; /* We're using all lines of terminal */ static int attrmode = AT_NORMAL; static int termcap_debug = -1; @@ -259,23 +289,10 @@ extern int shell_lines; #if !MSDOS_COMPILER static constant char *cheaper(constant char *t1, constant char *t2, constant char *def); -static void tmodes(constant char *incap, constant char *outcap, constant char **instr, +static void tmodes(constant char *inti, constant char *outti, constant char *intc, constant char *outtc, constant char **instr, constant char **outstr, constant char *def_instr, constant char *def_outstr, char **spp); #endif -/* - * These two variables are sometimes defined in, - * and needed by, the termcap library. - */ -#if MUST_DEFINE_OSPEED -extern short ospeed; /* Terminal output baud rate */ -extern char PC; /* Pad character */ -#endif -#ifdef _OSK -short ospeed; -char PC_, *UP, *BC; -#endif - extern int quiet; /* If VERY_QUIET, use visual bell for bell */ extern int no_vbell; extern int no_back_scroll; @@ -289,11 +306,11 @@ extern int mousecap; extern int is_tty; extern int use_color; extern int no_paste; +extern int wscroll; #if HILITE_SEARCH extern int hilite_search; #endif #if MSDOS_COMPILER==WIN32C -extern int wscroll; extern HANDLE tty; #else extern int tty; @@ -701,18 +718,21 @@ public void raw_mode(int on) } #if !MSDOS_COMPILER + /* * Some glue to prevent calling termcap functions if tgetent() failed. */ static int hardcopy; -static constant char * ltget_env(constant char *capname) +static constant char * ltget_env(constant char *tiname, constant char *tcname) { - char name[64]; + char envname[64]; + constant char *s; if (termcap_debug) { struct env { struct env *next; char *name; char *value; }; + constant char *capname = tcname != NULL ? tcname : tiname; static struct env *envs = NULL; struct env *p; for (p = envs; p != NULL; p = p->next) @@ -726,48 +746,80 @@ static constant char * ltget_env(constant char *capname) envs = p; return p->value; } - SNPRINTF1(name, sizeof(name), "LESS_TERMCAP_%s", capname); - return (lgetenv(name)); + if (tiname != NULL) + { + SNPRINTF1(envname, sizeof(envname), "LESS_TERMINFO_%s", tiname); + s = lgetenv(envname); + if (!isnullenv(s)) + return s; + } + if (tcname != NULL) + { + SNPRINTF1(envname, sizeof(envname), "LESS_TERMCAP_%s", tcname); + s = lgetenv(envname); + if (!isnullenv(s)) + return s; + } + return NULL; } -static int ltgetflag(constant char *capname) +static int ltgetflag(constant char *tiname, constant char *tcname) { constant char *s; - if ((s = ltget_env(capname)) != NULL) + if ((s = ltget_env(tiname, tcname)) != NULL) return (*s != '\0' && *s != '0'); if (hardcopy) return (0); - return (tgetflag(capname)); +#if USE_TERMINFO + return tiname == NULL ? 0 : tigetflag(tiname); +#else + return tcname == NULL ? 0 : tgetflag(tcname); +#endif } -static int ltgetnum(constant char *capname) +static int ltgetnum(constant char *tiname, constant char *tcname) { constant char *s; - if ((s = ltget_env(capname)) != NULL) + if ((s = ltget_env(tiname, tcname)) != NULL) return (atoi(s)); if (hardcopy) return (-1); - return (tgetnum(capname)); +#if USE_TERMINFO + return tiname == NULL ? -1 : tigetnum(tiname); +#else + return tcname == NULL ? -1 : tgetnum(tcname); +#endif } -static constant char * ltgetstr(constant char *capname, char **pp) +static constant char * ltgetstr(constant char *tiname, constant char *tcname, char **pp) { constant char *s; - if ((s = ltget_env(capname)) != NULL) + if ((s = ltget_env(tiname, tcname)) != NULL) return (s); if (hardcopy) return (NULL); - return (tgetstr(capname, pp)); +#if USE_TERMINFO + if (tiname == NULL) + return (NULL); + s = tigetstr(tiname); + if (s == (constant char *)-1) + s = NULL; + return (s); +#else + if (tcname == NULL) + return (NULL); + return tgetstr(tcname, pp); +#endif } #endif /* MSDOS_COMPILER */ /* * Get size of the output screen. */ -static void scrsize(void) +public void scrsize(void) { constant char *s; int sys_height; @@ -783,7 +835,6 @@ static void scrsize(void) #define DEF_SC_HEIGHT 24 #endif - sys_width = sys_height = 0; #if LESSTEST @@ -879,7 +930,7 @@ static void scrsize(void) else if ((s = lgetenv("LINES")) != NULL) sc_height = atoi(s); #if !MSDOS_COMPILER - else if ((n = ltgetnum("li")) > 0) + else if ((n = ltgetnum("lines", "li")) > 0) sc_height = n; #endif if ((s = lgetenv("LESS_LINES")) != NULL) @@ -896,7 +947,7 @@ static void scrsize(void) else if ((s = lgetenv("COLUMNS")) != NULL) sc_width = atoi(s); #if !MSDOS_COMPILER - else if ((n = ltgetnum("co")) > 0) + else if ((n = ltgetnum("cols", "co")) > 0) sc_width = n; #endif if ((s = lgetenv("LESS_COLUMNS")) != NULL) @@ -914,6 +965,11 @@ static void scrsize(void) */ public void screen_size_changed(void) { + constant char *env = lgetenv("LESS_SHELL_LINES"); + shell_lines = isnullenv(env) ? 1 : atoi(env); + if (shell_lines >= sc_height) + shell_lines = sc_height - 1; + wscroll = (sc_height + 1) / 2; calc_jump_sline(); calc_shift_count(); calc_match_shift(); @@ -986,6 +1042,10 @@ public constant char * special_key_str(int key) static char k_backtab[] = { '\340', PCK_SHIFT_TAB, 0 }; static char k_pagedown[] = { '\340', PCK_PAGEDOWN, 0 }; static char k_pageup[] = { '\340', PCK_PAGEUP, 0 }; + static char k_ctl_home[] = { '\340', PCK_CTL_HOME, 0 }; + static char k_ctl_end[] = { '\340', PCK_CTL_END, 0 }; + static char k_shift_home[] = { '\340', PCK_SHIFT_HOME, 0 }; + static char k_shift_end[] = { '\340', PCK_SHIFT_END, 0 }; static char k_f1[] = { '\340', PCK_F1, 0 }; #endif #if !MSDOS_COMPILER @@ -1000,31 +1060,34 @@ public constant char * special_key_str(int key) * the XFree86 environment. */ case SK_RIGHT_ARROW: - s = windowid ? ltgetstr("kr", &sp) : k_right; + s = windowid ? ltgetstr("kcuf1", "kr", &sp) : k_right; break; case SK_LEFT_ARROW: - s = windowid ? ltgetstr("kl", &sp) : k_left; + s = windowid ? ltgetstr("kcub1", "kl", &sp) : k_left; break; case SK_UP_ARROW: - s = windowid ? ltgetstr("ku", &sp) : k_up; + s = windowid ? ltgetstr("kcuu1", "ku", &sp) : k_up; break; case SK_DOWN_ARROW: - s = windowid ? ltgetstr("kd", &sp) : k_down; + s = windowid ? ltgetstr("kcud1", "kd", &sp) : k_down; break; case SK_PAGE_UP: - s = windowid ? ltgetstr("kP", &sp) : k_pageup; + s = windowid ? ltgetstr("kpp", "kP", &sp) : k_pageup; break; case SK_PAGE_DOWN: - s = windowid ? ltgetstr("kN", &sp) : k_pagedown; + s = windowid ? ltgetstr("knp", "kN", &sp) : k_pagedown; break; case SK_HOME: - s = windowid ? ltgetstr("kh", &sp) : k_home; + s = windowid ? ltgetstr("khome", "kh", &sp) : k_home; break; case SK_END: - s = windowid ? ltgetstr("@7", &sp) : k_end; + s = windowid ? ltgetstr("kend", "@7", &sp) : k_end; + break; + case SK_F1: + s = windowid ? ltgetstr("kf1", "k1", &sp) : k_f1; break; case SK_DELETE: - s = windowid ? ltgetstr("kD", &sp) : k_delete; + s = windowid ? ltgetstr("kdch1", "kD", &sp) : k_delete; if (s == NULL) { tbuf[0] = '\177'; @@ -1087,33 +1150,120 @@ public constant char * special_key_str(int key) case SK_BACKTAB: s = k_backtab; break; + case SK_SHIFT_HOME: + s = k_shift_home; + break; + case SK_CTL_HOME: + s = k_ctl_home; + break; + case SK_SHIFT_END: + s = k_shift_end; + break; + case SK_CTL_END: + s = k_ctl_end; + break; #else case SK_RIGHT_ARROW: - s = ltgetstr("kr", &sp); + s = ltgetstr("kcuf1", "kr", &sp); break; case SK_LEFT_ARROW: - s = ltgetstr("kl", &sp); + s = ltgetstr("kcub1", "kl", &sp); break; case SK_UP_ARROW: - s = ltgetstr("ku", &sp); + s = ltgetstr("kcuu1", "ku", &sp); break; case SK_DOWN_ARROW: - s = ltgetstr("kd", &sp); + s = ltgetstr("kcud1", "kd", &sp); break; case SK_PAGE_UP: - s = ltgetstr("kP", &sp); + s = ltgetstr("kpp", "kP", &sp); break; case SK_PAGE_DOWN: - s = ltgetstr("kN", &sp); + s = ltgetstr("knp", "kN", &sp); break; case SK_HOME: - s = ltgetstr("kh", &sp); + s = ltgetstr("khome", "kh", &sp); + break; + case SK_SHIFT_HOME: + s = ltgetstr("kHOM", "#2", &sp); + break; + case SK_CTL_HOME: + s = ltgetstr("kHOM5", NULL, &sp); break; case SK_END: - s = ltgetstr("@7", &sp); + s = ltgetstr("kend", "@7", &sp); + break; + case SK_SHIFT_END: + s = ltgetstr("kEND", "#7", &sp); + break; + case SK_CTL_END: + s = ltgetstr("kEND5", NULL, &sp); + break; + case SK_INSERT: + s = ltgetstr("kich1", "kI", &sp); + break; + case SK_BACKTAB: + s = ltgetstr("kcbt", "kB", &sp); + break; + case SK_CTL_RIGHT_ARROW: + s = ltgetstr("kRIT5", NULL, &sp); + break; + case SK_CTL_LEFT_ARROW: + s = ltgetstr("kLFT5", NULL, &sp); + break; + case SK_F1: + s = ltgetstr("kf1", "k1", &sp); + break; + case SK_PAD_UL: + s = ltgetstr("ka1", "K1", &sp); + break; + case SK_PAD_U: + s = ltgetstr("ka2", NULL, &sp); + break; + case SK_PAD_UR: + s = ltgetstr("ka3", "K3", &sp); + break; + case SK_PAD_L: + s = ltgetstr("kb1", NULL, &sp); + break; + case SK_PAD_CENTER: + s = ltgetstr("kb2", "K2", &sp); + break; + case SK_PAD_R: + s = ltgetstr("kb3", NULL, &sp); + break; + case SK_PAD_DL: + s = ltgetstr("kc1", "K4", &sp); + break; + case SK_PAD_D: + s = ltgetstr("kc2", NULL, &sp); + break; + case SK_PAD_DR: + s = ltgetstr("kc3", "K5", &sp); + break; + case SK_PAD_STAR: + s = ltgetstr("kpMUL", NULL, &sp); + break; + case SK_PAD_SLASH: + s = ltgetstr("kpDIV", NULL, &sp); + break; + case SK_PAD_DASH: + s = ltgetstr("kpSUB", NULL, &sp); + break; + case SK_PAD_PLUS: + s = ltgetstr("kpADD", NULL, &sp); + break; + case SK_PAD_DOT: + s = ltgetstr("kpDOT", NULL, &sp); + break; + case SK_PAD_COMMA: + s = ltgetstr("kpCMA", NULL, &sp); + break; + case SK_PAD_ZERO: + s = ltgetstr("kpZRO", NULL, &sp); break; case SK_DELETE: - s = ltgetstr("kD", &sp); + s = ltgetstr("kdch1", "kD", &sp); if (s == NULL) { tbuf[0] = '\177'; @@ -1122,7 +1272,7 @@ public constant char * special_key_str(int key) } break; case SK_BACKSPACE: - s = ltgetstr("kb", &sp); + s = ltgetstr("kbs", "kb", &sp); if (s == NULL) { tbuf[0] = '\b'; @@ -1142,6 +1292,17 @@ public constant char * special_key_str(int key) return (s); } +#if !MSDOS_COMPILER +static constant char *ltgoto(constant char *cap, int col, int line) +{ +#if USE_TERMINFO + return tparm(cap, line, col); +#else + return tgoto(cap, col, line); +#endif +} +#endif /* MSDOS_COMPILER */ + #if MSDOS_COMPILER public void init_win_colors(void) { @@ -1166,12 +1327,12 @@ public void init_win_colors(void) /* * Get terminal capabilities via termcap. */ -public void get_term(void) +public void get_term() { termcap_debug = !isnullenv(lgetenv("LESS_TERMCAP_DEBUG")); #if MSDOS_COMPILER auto_wrap = 1; - ignaw = 0; + defer_wrap = 0; can_goto_line = 1; clear_bg = 1; /* @@ -1220,15 +1381,17 @@ public void get_term(void) #else /* !MSDOS_COMPILER */ { - char *sp; constant char *t1; constant char *t2; constant char *term; + char *sp; /* * Some termcap libraries assume termbuf is static * (accessible after tgetent returns). */ +#if !USE_TERMINFO static char termbuf[TERMBUF_SIZE]; +#endif static char sbuf[TERMSBUF_SIZE]; #if OS2 @@ -1251,13 +1414,17 @@ public void get_term(void) /* * Find out what kind of terminal this is. */ - if ((term = lgetenv("TERM")) == NULL) + if ((term = lgetenv("TERM")) == NULL && (term = getenv("TERM")) == NULL) term = DEFAULT_TERM; hardcopy = 0; - /* {{ Should probably just pass NULL instead of termbuf. }} */ +#if USE_TERMINFO + if (setupterm(term, -1, NULL) != OK) + hardcopy = 1; +#else if (tgetent(termbuf, term) != TGETENT_OK) hardcopy = 1; - if (ltgetflag("hc")) +#endif + if (!hardcopy && ltgetflag("hc", "hc")) hardcopy = 1; /* @@ -1266,12 +1433,12 @@ public void get_term(void) scrsize(); pos_init(); - auto_wrap = ltgetflag("am"); - ignaw = ltgetflag("xn"); - above_mem = ltgetflag("da"); - below_mem = ltgetflag("db"); - clear_bg = ltgetflag("ut"); - no_alt_screen = ltgetflag("NR"); + auto_wrap = ltgetflag("am", "am"); + defer_wrap = ltgetflag("xenl", "xn"); + above_mem = ltgetflag("da", "da"); + below_mem = ltgetflag("db", "db"); + clear_bg = ltgetflag("bce", "ut"); + no_alt_screen = ltgetflag("nrrmc", "NR"); /* * Assumes termcap variable "sg" is the printing width of: @@ -1279,7 +1446,7 @@ public void get_term(void) * the underline sequence, the end underline sequence, * the boldface sequence, and the end boldface sequence. */ - if ((so_s_width = ltgetnum("sg")) < 0) + if ((so_s_width = ltgetnum("xmc", "sg")) < 0) so_s_width = 0; so_e_width = so_s_width; @@ -1305,70 +1472,70 @@ public void get_term(void) sp = sbuf; #if HAVE_OSPEED - sc_pad = ltgetstr("pc", &sp); + sc_pad = ltgetstr("pad", "pc", &sp); if (sc_pad != NULL) PC = *sc_pad; #endif - sc_s_keypad = ltgetstr("ks", &sp); + sc_s_keypad = ltgetstr("smkx", "ks", &sp); if (sc_s_keypad == NULL) sc_s_keypad = ""; - sc_e_keypad = ltgetstr("ke", &sp); + sc_e_keypad = ltgetstr("rmkx", "ke", &sp); if (sc_e_keypad == NULL) sc_e_keypad = ""; - kent = ltgetstr("@8", &sp); + kent = ltgetstr("kent", "@8", &sp); - sc_s_mousecap = ltgetstr("MOUSE_START", &sp); + sc_s_mousecap = ltgetstr("MOUSE_START", "MOUSE_START", &sp); if (sc_s_mousecap == NULL) sc_s_mousecap = ESCS "[?1000h" ESCS "[?1002h" ESCS "[?1006h"; - sc_e_mousecap = ltgetstr("MOUSE_END", &sp); + sc_e_mousecap = ltgetstr("MOUSE_END", "MOUSE_END", &sp); if (sc_e_mousecap == NULL) sc_e_mousecap = ESCS "[?1006l" ESCS "[?1002l" ESCS "[?1000l"; - sc_s_bracketed_paste = ltgetstr("BRACKETED_PASTE_START", &sp); + sc_s_bracketed_paste = ltgetstr("BRACKETED_PASTE_START", "BRACKETED_PASTE_START", &sp); if (sc_s_bracketed_paste == NULL) sc_s_bracketed_paste = ESCS"[?2004h"; - sc_e_bracketed_paste = ltgetstr("BRACKETED_PASTE_END", &sp); + sc_e_bracketed_paste = ltgetstr("BRACKETED_PASTE_END", "BRACKETED_PASTE_END", &sp); if (sc_e_bracketed_paste == NULL) sc_e_bracketed_paste = ESCS"[?2004l"; - sc_suspend = ltgetstr("SUSPEND", &sp); + sc_suspend = ltgetstr("SUSPEND", "SUSPEND", &sp); if (sc_suspend == NULL) sc_suspend = ""; - sc_resume = ltgetstr("RESUME", &sp); + sc_resume = ltgetstr("RESUME", "RESUME", &sp); if (sc_resume == NULL) sc_resume = ""; - sc_init = ltgetstr("ti", &sp); + sc_init = ltgetstr("smcup", "ti", &sp); if (sc_init == NULL) sc_init = ""; - sc_deinit= ltgetstr("te", &sp); + sc_deinit= ltgetstr("rmcup", "te", &sp); if (sc_deinit == NULL) sc_deinit = ""; - sc_eol_clear = ltgetstr("ce", &sp); + sc_eol_clear = ltgetstr("el", "ce", &sp); if (sc_eol_clear == NULL || *sc_eol_clear == '\0') { missing_cap = TRUE; sc_eol_clear = ""; } - sc_eos_clear = ltgetstr("cd", &sp); + sc_eos_clear = ltgetstr("ed", "cd", &sp); if (below_mem && (sc_eos_clear == NULL || *sc_eos_clear == '\0')) { missing_cap = TRUE; sc_eos_clear = ""; } - sc_clear = ltgetstr("cl", &sp); + sc_clear = ltgetstr("clear", "cl", &sp); if (sc_clear == NULL || *sc_clear == '\0') { missing_cap = TRUE; sc_clear = "\n\n"; } - sc_move = ltgetstr("cm", &sp); + sc_move = ltgetstr("cup", "cm", &sp); if (sc_move == NULL || *sc_move == '\0') { /* @@ -1381,20 +1548,20 @@ public void get_term(void) } else can_goto_line = 1; - tmodes("so", "se", &sc_s_in, &sc_s_out, "", "", &sp); - tmodes("us", "ue", &sc_u_in, &sc_u_out, sc_s_in, sc_s_out, &sp); - tmodes("md", "me", &sc_b_in, &sc_b_out, sc_s_in, sc_s_out, &sp); - tmodes("mb", "me", &sc_bl_in, &sc_bl_out, sc_s_in, sc_s_out, &sp); + tmodes("smso", "rmso", "so", "se", &sc_s_in, &sc_s_out, "", "", &sp); + tmodes("smul", "rmul", "us", "ue", &sc_u_in, &sc_u_out, sc_s_in, sc_s_out, &sp); + tmodes("bold", "sgr0", "md", "me", &sc_b_in, &sc_b_out, sc_s_in, sc_s_out, &sp); + tmodes("blink", "sgr0", "mb", "me", &sc_bl_in, &sc_bl_out, sc_s_in, sc_s_out, &sp); - sc_visual_bell = ltgetstr("vb", &sp); + sc_visual_bell = ltgetstr("flash", "vb", &sp); if (sc_visual_bell == NULL) sc_visual_bell = ""; - if (ltgetflag("bs")) + if (ltgetflag(NULL, "bs")) sc_backspace = "\b"; else { - sc_backspace = ltgetstr("bc", &sp); + sc_backspace = ltgetstr("OTbc", "bc", &sp); if (sc_backspace == NULL || *sc_backspace == '\0') sc_backspace = "\b"; } @@ -1403,14 +1570,14 @@ public void get_term(void) * Choose between using "ho" and "cm" ("home" and "cursor move") * to move the cursor to the upper left corner of the screen. */ - t1 = ltgetstr("ho", &sp); + t1 = ltgetstr("home", "ho", &sp); if (t1 == NULL) t1 = ""; if (*sc_move == '\0') t2 = ""; else { - strcpy(sp, tgoto(sc_move, 0, 0)); + strcpy(sp, ltgoto(sc_move, 0, 0)); t2 = sp; sp += strlen(sp) + 1; } @@ -1420,14 +1587,14 @@ public void get_term(void) * Choose between using "ll" and "cm" ("lower left" and "cursor move") * to move the cursor to the lower left corner of the screen. */ - t1 = ltgetstr("ll", &sp); + t1 = ltgetstr("ll", "ll", &sp); if (t1 == NULL || !full_screen) t1 = ""; if (*sc_move == '\0') t2 = ""; else { - strcpy(sp, tgoto(sc_move, 0, sc_height-1)); + strcpy(sp, ltgoto(sc_move, 0, sc_height-1)); t2 = sp; sp += strlen(sp) + 1; } @@ -1436,7 +1603,7 @@ public void get_term(void) /* * Get carriage return string. */ - sc_return = ltgetstr("cr", &sp); + sc_return = ltgetstr("cr", "cr", &sp); if (sc_return == NULL) sc_return = "\r"; @@ -1444,10 +1611,10 @@ public void get_term(void) * Choose between using "al" or "sr" ("add line" or "scroll reverse") * to add a line at the top of the screen. */ - t1 = ltgetstr("al", &sp); + t1 = ltgetstr("ill", "al", &sp); if (t1 == NULL) t1 = ""; - t2 = ltgetstr("sr", &sp); + t2 = ltgetstr("ri", "sr", &sp); if (t2 == NULL) t2 = ""; if (*t1 == '\0' && *t2 == '\0') @@ -1465,12 +1632,6 @@ public void get_term(void) } } #endif /* MSDOS_COMPILER */ - { - const char *env = lgetenv("LESS_SHELL_LINES"); - shell_lines = isnullenv(env) ? 1 : atoi(env); - if (shell_lines >= sc_height) - shell_lines = sc_height - 1; - } } #if !MSDOS_COMPILER @@ -1479,7 +1640,6 @@ public void get_term(void) * We use the trick of calling tputs, but as a char printing function * we give it inc_costcount, which just increments "costcount". * This tells us how many chars would be printed by using this string. - * {{ Couldn't we just use strlen? }} */ static int costcount; @@ -1518,9 +1678,9 @@ static constant char * cheaper(constant char *t1, constant char *t2, constant ch return (t2); } -static void tmodes(constant char *incap, constant char *outcap, constant char **instr, constant char **outstr, constant char *def_instr, constant char *def_outstr, char **spp) +static void tmodes(constant char *inti, constant char *outti, constant char *intc, constant char *outtc, constant char **instr, constant char **outstr, constant char *def_instr, constant char *def_outstr, char **spp) { - *instr = ltgetstr(incap, spp); + *instr = ltgetstr(inti, intc, spp); if (*instr == NULL) { /* Use defaults. */ @@ -1529,10 +1689,10 @@ static void tmodes(constant char *incap, constant char *outcap, constant char ** return; } - *outstr = ltgetstr(outcap, spp); + *outstr = ltgetstr(outti, outtc, spp); if (*outstr == NULL) /* No specific out capability; use "me". */ - *outstr = ltgetstr("me", spp); + *outstr = ltgetstr("sgr0", "me", spp); if (*outstr == NULL) /* Don't even have "me"; use a null string. */ *outstr = ""; @@ -1603,16 +1763,16 @@ static void initcolor(void) static void win32_init_vt_term(void) { if (vt_enabled == 0 || (vt_enabled == 1 && con_out == con_out_ours)) - return; // already initialized + return; /* already initialized */ /* don't care about the initial mode, and win VT hard-enables am+xn */ vt_enabled = SetConsoleMode(con_out, ENABLE_PROCESSED_OUTPUT | ENABLE_VIRTUAL_TERMINAL_PROCESSING | - ENABLE_WRAP_AT_EOL_OUTPUT); + ENABLE_WRAP_AT_EOL_OUTPUT); if (vt_enabled) { auto_wrap = 1; - ignaw = 1; + defer_wrap = 1; } } @@ -1648,9 +1808,11 @@ static void win32_init_term(void) CONSOLE_TEXTMODE_BUFFER, (LPVOID) NULL); - // we don't care about the initial state. we need processed - // output without anything else (no wrap at EOL, no VT, - // no disabled auto-return). + /* + * We don't care about the initial state. We need processed + * output without anything else (no wrap at EOL, no VT, + * no disabled auto-return). + */ if (SetConsoleMode(con_out_ours, ENABLE_PROCESSED_OUTPUT)) auto_wrap = 0; } @@ -1696,7 +1858,6 @@ static void ltputs(constant char *str, int affcnt, int (*f_putc)(int)) { while (str != NULL && *str != '\0') { -#if HAVE_STRSTR constant char *obrac = strstr(str, "$<"); if (obrac != NULL) { @@ -1724,7 +1885,6 @@ static void ltputs(constant char *str, int affcnt, int (*f_putc)(int)) continue; } } -#endif /* Pass the rest of the string to tputs and we're done. */ do_tputs(str, affcnt, f_putc); break; @@ -1787,8 +1947,11 @@ public void resume_screen(void) /* * Initialize terminal */ -public void init(void) +public void term_init(void) { + if (term_init_done) + return; + term_init_done = term_init_ever = TRUE; clear_bot_if_needed(); #if !MSDOS_COMPILER if (!(quit_if_one_screen && one_screen)) @@ -1804,7 +1967,7 @@ public void init(void) */ if (*sc_init != '\0' && *sc_deinit != '\0' && !no_alt_screen) lower_left(); - term_init_done = 1; + term_addrs = TRUE; } if (!no_keypad) ltputs(sc_s_keypad, sc_height, putchr); @@ -1813,7 +1976,6 @@ public void init(void) if (no_paste) init_bracketed_paste(); } - init_done = 1; if (top_scroll) { int i; @@ -1835,7 +1997,7 @@ public void init(void) if (!no_init) { win32_init_term(); - term_init_done = 1; + term_addrs = TRUE; } if (mousecap) init_mouse(); @@ -1843,7 +2005,6 @@ public void init(void) } win32_init_vt_term(); #endif - init_done = 1; initcolor(); flush(); #endif @@ -1852,17 +2013,17 @@ public void init(void) /* * Deinitialize terminal */ -public void deinit(void) +public void term_deinit(void) { - if (!init_done) + if (!term_init_done) return; #if !MSDOS_COMPILER if (!(quit_if_one_screen && one_screen)) { if (mousecap) deinit_mouse(); - if (no_paste) - deinit_bracketed_paste(); + if (no_paste) + deinit_bracketed_paste(); if (!no_keypad) ltputs(sc_e_keypad, sc_height, putchr); if (!no_init) @@ -1885,21 +2046,19 @@ public void deinit(void) clreol(); #endif #endif - init_done = 0; + term_init_done = FALSE; } /* * Are we interactive (ie. writing to an initialized tty)? */ -public int interactive(void) +public lbool interactive(void) { - return (is_tty && init_done); + return (is_tty && term_init_done); } static void assert_interactive(void) { - if (interactive()) return; - /* abort(); */ } /* @@ -1998,7 +2157,7 @@ public void remove_top(int n) if (n >= sc_height - 1) { - clear(); + lclear(); home(); return; } @@ -2202,7 +2361,7 @@ public void check_winch(void) if (!no_init && con_out_ours == con_out) SetConsoleScreenBufferSize(con_out, size); pos_init(); - wscroll = (sc_height + 1) / 2; + screen_size_changed(); screen_trashed(); } #endif @@ -2215,7 +2374,7 @@ public void goto_line(int sindex) { assert_interactive(); #if !MSDOS_COMPILER - ltputs(tgoto(sc_move, 0, sindex), 1, putchr); + ltputs(ltgoto(sc_move, 0, sindex), 1, putchr); #else flush(); _settextposition(sindex+1, 1); @@ -2323,7 +2482,7 @@ public void vbell(void) #else #if MSDOS_COMPILER==WIN32C /* paint screen with an inverse color */ - clear(); + lclear(); /* leave it displayed for 100 msec. */ Sleep(100); @@ -2340,7 +2499,7 @@ public void vbell(void) /* * Make a noise. */ -static void beep(void) +static void lbeep(void) { #if !MSDOS_COMPILER putchr(CONTROL('G')); @@ -2356,18 +2515,18 @@ static void beep(void) /* * Ring the terminal bell. */ -public void bell(void) +public void lbell(void) { if (quiet == VERY_QUIET) vbell(); else - beep(); + lbeep(); } /* * Clear the screen. */ -public void clear(void) +public void lclear(void) { assert_interactive(); suspend_screen(); @@ -2495,14 +2654,14 @@ public void clear_bot(void) public void init_bracketed_paste(void) { #if !MSDOS_COMPILER - ltputs(sc_s_bracketed_paste, 1, putchr); + ltputs(sc_s_bracketed_paste, 1, putchr); #endif } public void deinit_bracketed_paste(void) { #if !MSDOS_COMPILER - ltputs(sc_e_bracketed_paste, 1, putchr); + ltputs(sc_e_bracketed_paste, 1, putchr); #endif } @@ -2952,7 +3111,7 @@ typedef struct XINPUT_RECORD { typedef struct WIN32_CHAR { struct WIN32_CHAR *wc_next; - char wc_ch; + int wc_ch; } WIN32_CHAR; static WIN32_CHAR *win32_queue = NULL; @@ -2960,7 +3119,7 @@ static WIN32_CHAR *win32_queue = NULL; /* * Is the win32_queue nonempty? */ -static int win32_queued_char(void) +static lbool win32_queued_char(void) { return (win32_queue != NULL); } @@ -2968,7 +3127,7 @@ static int win32_queued_char(void) /* * Push a char onto the back of the win32_queue. */ -static void win32_enqueue(char ch) +static void win32_enqueue(int ch) { WIN32_CHAR *wch = (WIN32_CHAR *) ecalloc(1, sizeof(WIN32_CHAR)); wch->wc_ch = ch; @@ -2999,10 +3158,10 @@ public void WIN32ungetch(int ch) /* * Get a char from the front of the win32_queue. */ -static char win32_get_queue(void) +static int win32_get_queue(void) { WIN32_CHAR *wch = win32_queue; - char ch = wch->wc_ch; + int ch = wch->wc_ch; win32_queue = wch->wc_next; free(wch); return ch; @@ -3126,11 +3285,29 @@ static lbool win32_scan_code(XINPUT_RECORD *xip) case PCK_DELETE: /* delete */ scan = PCK_CTL_DELETE; break; + case PCK_HOME: + scan = PCK_CTL_HOME; + break; + case PCK_END: + scan = PCK_CTL_END; + break; } } else if (xip->ir.Event.KeyEvent.dwControlKeyState & SHIFT_PRESSED) { if (xip->ichar == '\t') scan = PCK_SHIFT_TAB; + else + { + switch (xip->ir.Event.KeyEvent.wVirtualScanCode) + { + case PCK_HOME: + scan = PCK_SHIFT_HOME; + break; + case PCK_END: + scan = PCK_SHIFT_END; + break; + } + } } if (scan < 0 && xip->ichar == 0) scan = xip->ir.Event.KeyEvent.wVirtualScanCode; @@ -3182,12 +3359,23 @@ static lbool win32_key_event(XINPUT_RECORD *xip) { constant char *p; for (p = utf8; p < up; ++p) - win32_enqueue(*p); + win32_enqueue(*p & 0xFF); } return (TRUE); } /* + * Handle a window input event. + */ +static lbool win32_window_event(XINPUT_RECORD *xip) +{ + if (xip->ir.EventType != WINDOW_BUFFER_SIZE_EVENT) + return (FALSE); + win32_enqueue(READ_AGAIN); + return (TRUE); +} + +/* * Determine whether an input character is waiting to be read. */ public lbool win32_kbhit2(lbool no_queued) @@ -3213,7 +3401,7 @@ public lbool win32_kbhit2(lbool no_queued) ReadConsoleInputW(tty, &xip.ir, 1, &nread); if (nread == 0) return (FALSE); - if (win32_mouse_event(&xip) || win32_key_event(&xip)) + if (win32_mouse_event(&xip) || win32_key_event(&xip) || win32_window_event(&xip)) break; } return (TRUE); @@ -3227,7 +3415,7 @@ public lbool win32_kbhit(void) /* * Read a character from the keyboard. */ -public char WIN32getch(void) +public int WIN32getch(void) { while (!win32_kbhit()) { diff --git a/contrib/less/search.c b/contrib/less/search.c index 75f7efee0535..68122f163964 100644 --- a/contrib/less/search.c +++ b/contrib/less/search.c @@ -354,32 +354,37 @@ public void clear_attn(void) */ public void undo_search(lbool clear) { - clear_pattern(&search_info); - undo_osc8(); #if HILITE_SEARCH + lbool osc8_active = undo_osc8(); + lbool has_pattern = prev_pattern(&search_info); if (clear) { + clear_pattern(&search_info); clr_hilite(); } else { - if (hilite_anchor.first == NULL) - { + if (has_pattern) + hide_hilite = !hide_hilite; + else if (!osc8_active) error("No previous regular expression", NULL_PARG); - return; - } - hide_hilite = !hide_hilite; } repaint_hilite(TRUE); +#else + undo_osc8(); + clear_pattern(&search_info); #endif } /* */ -public void undo_osc8(void) +public lbool undo_osc8(void) { + lbool was_active = FALSE; #if OSC8_LINK + was_active = (osc8_linepos != NULL_POSITION); osc8_linepos = NULL_POSITION; #endif + return was_active; } #if HILITE_SEARCH diff --git a/contrib/less/signal.c b/contrib/less/signal.c index 8d860768fe81..b4df6c7daeda 100644 --- a/contrib/less/signal.c +++ b/contrib/less/signal.c @@ -44,7 +44,7 @@ extern int less_is_more; static RETSIGTYPE u_interrupt(int type) { (void) type; - bell(); + lbell(); #if OS2 LSIGNAL(SIGINT, SIG_ACK); #endif @@ -64,6 +64,7 @@ static RETSIGTYPE u_interrupt(int type) #if HILITE_SEARCH set_filter_pattern(NULL, 0); #endif + polling_ok(); intio(); } #endif @@ -96,10 +97,10 @@ static RETSIGTYPE stop(int type) * "Window" change handler */ /* ARGSUSED*/ -public RETSIGTYPE winch(int type) +public RETSIGTYPE lwinch(int type) { (void) type; - LSIGNAL(SIG_LESSWINDOW, winch); + LSIGNAL(SIG_LESSWINDOW, lwinch); #if LESSTEST /* * Ignore window changes during lesstest. @@ -185,10 +186,10 @@ public void init_signals(int on) (void) LSIGNAL(SIGTSTP, !secure_allow(SF_STOP) ? SIG_IGN : stop); #endif #ifdef SIGWINCH - (void) LSIGNAL(SIGWINCH, winch); + (void) LSIGNAL(SIGWINCH, lwinch); #endif #ifdef SIGWIND - (void) LSIGNAL(SIGWIND, winch); + (void) LSIGNAL(SIGWIND, lwinch); #endif #ifdef SIGQUIT (void) LSIGNAL(SIGQUIT, SIG_IGN); @@ -196,6 +197,9 @@ public void init_signals(int on) #ifdef SIGTERM (void) LSIGNAL(SIGTERM, terminate); #endif +#ifdef SIGHUP + (void) LSIGNAL(SIGHUP, terminate); +#endif #ifdef SIGUSR1 (void) LSIGNAL(SIGUSR1, sigusr1); #endif @@ -224,6 +228,9 @@ public void init_signals(int on) #ifdef SIGTERM (void) LSIGNAL(SIGTERM, SIG_DFL); #endif +#ifdef SIGHUP + (void) LSIGNAL(SIGHUP, SIG_DFL); +#endif #ifdef SIGUSR1 (void) LSIGNAL(SIGUSR1, SIG_DFL); #endif @@ -252,7 +259,7 @@ public void psignals(void) LSIGNAL(SIGTTOU, SIG_IGN); #endif clear_bot(); - deinit(); + term_deinit(); flush(); raw_mode(0); #ifdef SIGTTOU @@ -268,7 +275,7 @@ public void psignals(void) */ LSIGNAL(SIGTSTP, stop); raw_mode(1); - init(); + term_init(); screen_trashed(); tsignals |= S_WINCH; } @@ -284,10 +291,7 @@ public void psignals(void) old_height = sc_height; get_term(); if (sc_width != old_width || sc_height != old_height) - { - wscroll = (sc_height + 1) / 2; screen_size_changed(); - } screen_trashed(); } #endif @@ -295,5 +299,9 @@ public void psignals(void) { if (quit_on_intr) quit(QUIT_INTERRUPT); + getcc_clear(); +#if MSDOS_COMPILER==WIN32C + win32_getch_clear(); +#endif } } diff --git a/contrib/less/tags.c b/contrib/less/tags.c index 6c37f7db240c..e707a618d214 100644 --- a/contrib/less/tags.c +++ b/contrib/less/tags.c @@ -256,12 +256,12 @@ static enum tag_result findctag(constant char *tag) char *q; FILE *f; size_t taglen; + int n; LINENUM taglinenum; char *tagfile; char *tagpattern; lbool tagendline; int search_char; - lbool err; char tline[TAGLINE_SIZE]; struct tag *tp; @@ -321,8 +321,9 @@ static enum tag_result findctag(constant char *tag) * First see if it is a line number. */ tagendline = FALSE; - taglinenum = getnum(&p, 0, &err); - if (err) + if (getnum(&p, NULL, FALSE, &n)) + taglinenum = n; + else { /* * No, it must be a pattern. diff --git a/contrib/less/ttyin.c b/contrib/less/ttyin.c index 402d62dcd78f..f3411cf1dd56 100644 --- a/contrib/less/ttyin.c +++ b/contrib/less/ttyin.c @@ -192,7 +192,7 @@ public int getchr(void) do { flush(); -#if MSDOS_COMPILER && MSDOS_COMPILER != DJGPPC +#if !LESS_IREAD_TTY /* * In raw read, we don't see ^C so look here for it. */ @@ -208,7 +208,7 @@ public int getchr(void) result = 1; if (c == '\003') return (READ_INTR); -#else +#else /* LESS_IREAD_TTY */ { unsigned char uc; result = iread(tty, &uc, sizeof(char)); diff --git a/contrib/less/ubin.uni b/contrib/less/ubin.uni index 5d6f97c237ad..1ffaa279f97c 100644 --- a/contrib/less/ubin.uni +++ b/contrib/less/ubin.uni @@ -1,4 +1,4 @@ -/* Generated by "./mkutable -f2 Cc Cs Co Zl Zp -- unicode/UnicodeData.txt" on Aug 19 1:16:32 GMT 2025 */ +/* Generated by "./mkutable -f2 Cc Cs Co Zl Zp -- unicode/UnicodeData.txt" on Nov 28 1:30:13 GMT 2025 */ { 0x0000, 0x0007 }, /* Cc */ { 0x000b, 0x000b }, /* Cc */ { 0x000e, 0x001f }, /* Cc */ diff --git a/contrib/less/version.c b/contrib/less/version.c index a5925c335a8f..9d7fa034d78c 100644 --- a/contrib/less/version.c +++ b/contrib/less/version.c @@ -1061,6 +1061,19 @@ v684 9/18/25 Allow mixing of options and filenames on command line; add LESS_TERMCAP_SUSPEND & LESS_TERMCAP_RESUME. v685 10/4/25 Make --incsearch return to same column as well as same line; fix some problems reported by valgrind. +v686 10/30/25 Map keypad keys; make HOME/END scroll horizontally; + retain saved marks even if --save-marks is not specified; + fix repaint bug with --form-feed; fix bugs passing negative + values to cmd line options. +v687 11/17/25 Disallow opening OSC8 link via mouse in secure mode; + add --autosave; make SIGHUP act like SIGTERM; add ESC-f. +v688 11/28/25 Add LESSNOCONFIG; defer "ti" until first char received; + don't auto-bold line numbers. +v689 12/27/25 Add prompt seqs %C, %W, %Q, ?Q; don't allow any command to + interrupt waiting for data; fix screen resize on Windows; + add --without-termlib. +v690 12/31/25 Cleanup. +v691 1/10/26 Fix mingw build. */ -char version[] = "685"; +char version[] = "691"; diff --git a/contrib/less/wide.uni b/contrib/less/wide.uni index 7ac89653987b..1af0e23210a4 100644 --- a/contrib/less/wide.uni +++ b/contrib/less/wide.uni @@ -1,4 +1,4 @@ -/* Generated by "./mkutable -f1 W F -- unicode/EastAsianWidth.txt" on Aug 10 20:15:03 GMT 2025 */ +/* Generated by "./mkutable -f1 W F -- unicode/EastAsianWidth.txt" on Nov 28 1:30:13 GMT 2025 */ { 0x1100, 0x115f }, /* W */ { 0x231a, 0x231b }, /* W */ { 0x2329, 0x232a }, /* W */ @@ -61,10 +61,10 @@ { 0xff01, 0xff60 }, /* F */ { 0xffe0, 0xffe6 }, /* F */ { 0x16fe0, 0x16fe4 }, /* W */ - { 0x16ff0, 0x16ff1 }, /* W */ - { 0x17000, 0x187f7 }, /* W */ - { 0x18800, 0x18cd5 }, /* W */ - { 0x18cff, 0x18d08 }, /* W */ + { 0x16ff0, 0x16ff6 }, /* W */ + { 0x17000, 0x18cd5 }, /* W */ + { 0x18cff, 0x18d1e }, /* W */ + { 0x18d80, 0x18df2 }, /* W */ { 0x1aff0, 0x1aff3 }, /* W */ { 0x1aff5, 0x1affb }, /* W */ { 0x1affd, 0x1affe }, /* W */ @@ -107,7 +107,7 @@ { 0x1f680, 0x1f6c5 }, /* W */ { 0x1f6cc, 0x1f6cc }, /* W */ { 0x1f6d0, 0x1f6d2 }, /* W */ - { 0x1f6d5, 0x1f6d7 }, /* W */ + { 0x1f6d5, 0x1f6d8 }, /* W */ { 0x1f6dc, 0x1f6df }, /* W */ { 0x1f6eb, 0x1f6ec }, /* W */ { 0x1f6f4, 0x1f6fc }, /* W */ @@ -118,10 +118,11 @@ { 0x1f947, 0x1f9af }, /* W */ { 0x1f9b4, 0x1f9ff }, /* W */ { 0x1fa70, 0x1fa7c }, /* W */ - { 0x1fa80, 0x1fa89 }, /* W */ - { 0x1fa8f, 0x1fac6 }, /* W */ - { 0x1face, 0x1fadc }, /* W */ - { 0x1fadf, 0x1fae9 }, /* W */ - { 0x1faf0, 0x1faf8 }, /* W */ + { 0x1fa80, 0x1fa8a }, /* W */ + { 0x1fa8e, 0x1fac6 }, /* W */ + { 0x1fac8, 0x1fac8 }, /* W */ + { 0x1facd, 0x1fadc }, /* W */ + { 0x1fadf, 0x1faea }, /* W */ + { 0x1faef, 0x1faf8 }, /* W */ { 0x20000, 0x2fffd }, /* W */ { 0x30000, 0x3fffd }, /* W */ diff --git a/contrib/less/xbuf.c b/contrib/less/xbuf.c index 8c940c41c8a9..89ef2fafeccd 100644 --- a/contrib/less/xbuf.c +++ b/contrib/less/xbuf.c @@ -66,8 +66,9 @@ public void xbuf_add_char(struct xbuffer *xbuf, char c) /* * Add arbitrary data to an xbuf. */ -public void xbuf_add_data(struct xbuffer *xbuf, constant unsigned char *data, size_t len) +public void xbuf_add_data(struct xbuffer *xbuf, constant void *vdata, size_t len) { + constant unsigned char *data = (constant unsigned char *) vdata; size_t i; for (i = 0; i < len; i++) xbuf_add_byte(xbuf, data[i]); diff --git a/contrib/less/xbuf.h b/contrib/less/xbuf.h index a5bdefb3c2d1..79e6453c3215 100644 --- a/contrib/less/xbuf.h +++ b/contrib/less/xbuf.h @@ -17,7 +17,7 @@ void xbuf_deinit(struct xbuffer *xbuf); void xbuf_reset(struct xbuffer *xbuf); void xbuf_add_byte(struct xbuffer *xbuf, unsigned char b); void xbuf_add_char(struct xbuffer *xbuf, char c); -void xbuf_add_data(struct xbuffer *xbuf, constant unsigned char *data, size_t len); +void xbuf_add_data(struct xbuffer *xbuf, constant void *data, size_t len); int xbuf_pop(struct xbuffer *xbuf); constant char *xbuf_char_data(constant struct xbuffer *xbuf); diff --git a/usr.bin/less/defines.h b/usr.bin/less/defines.h index d95ff956bd37..a051790d0f49 100644 --- a/usr.bin/less/defines.h +++ b/usr.bin/less/defines.h @@ -21,91 +21,91 @@ * be safe to run by unprivileged users. * SECURE_COMPILE is set by the --with-secure configure option. */ -#define SECURE SECURE_COMPILE +#define SECURE SECURE_COMPILE /* * 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 (!SECURE) +#define SHELL_ESCAPE (!SECURE) /* * EXAMINE is 1 if you wish to allow examining files by name from within less. */ -#define EXAMINE (!SECURE) +#define EXAMINE (!SECURE) /* * TAB_COMPLETE_FILENAME is 1 if you wish to allow the TAB key * to complete filenames at prompts. */ -#define TAB_COMPLETE_FILENAME (!SECURE) +#define TAB_COMPLETE_FILENAME (!SECURE) /* * CMD_HISTORY is 1 if you wish to allow keys to cycle through * previous commands at prompts. */ -#define CMD_HISTORY 1 +#define CMD_HISTORY 1 /* * HILITE_SEARCH is 1 if you wish to have search targets to be * displayed in standout mode. */ -#define HILITE_SEARCH 1 +#define HILITE_SEARCH 1 /* * EDITOR is 1 if you wish to allow editor invocation (the "v" command). * (This is possible only if your system supplies the system() function.) * EDIT_PGM is the name of the (default) editor to be invoked. */ -#define EDITOR (!SECURE) +#define EDITOR (!SECURE) /* * TAGS is 1 if you wish to support tag files. */ -#define TAGS (!SECURE) +#define TAGS (!SECURE) /* - * USERFILE is 1 if you wish to allow a .less file to specify + * USERFILE is 1 if you wish to allow a .lesskey or .less file to specify * user-defined key bindings. */ -#define USERFILE (!SECURE) +#define USERFILE (!SECURE) /* * GLOB is 1 if you wish to have shell metacharacters expanded in filenames. * This will generally work if your system provides the "popen" function * and the "echo" shell command. */ -#define GLOB (!SECURE) +#define GLOB (!SECURE) /* * PIPEC is 1 if you wish to have the "|" command * which allows the user to pipe data into a shell command. */ -#define PIPEC (!SECURE && HAVE_POPEN) +#define PIPEC (!SECURE && HAVE_POPEN) /* * LOGFILE is 1 if you wish to allow the -o option (to create log files). */ -#define LOGFILE (!SECURE) +#define LOGFILE (!SECURE) /* - * OSC8_SEARCH is 1 if you wish to allow the ^O^O and related commands + * OSC8_LINK is 1 if you wish to allow the ^O^O and related commands * (to open OSC8 hyperlinks). */ -#define OSC8_LINK 1 +#define OSC8_LINK 1 /* * GNU_OPTIONS is 1 if you wish to support the GNU-style command * line options --help and --version. */ -#define GNU_OPTIONS 1 +#define GNU_OPTIONS 1 /* * ONLY_RETURN is 1 if you want RETURN to be the only input which * will continue past an error message. * Otherwise, any key will continue past an error message. */ -#define ONLY_RETURN 0 +#define ONLY_RETURN 0 /* * LESSKEYFILE is the filename of the default lesskey output file @@ -116,33 +116,36 @@ * LESSHISTFILE is the filename of the history file * (in the HOME directory). */ -#define LESSKEYFILE ".less" -#define LESSKEYFILE_SYS "/etc/lesskey" -#define DEF_LESSKEYINFILE ".lesskey" -#define LESSKEYINFILE_SYS "/etc/syslesskey" -#define LESSHISTFILE ".lesshst" +/* FreeBSD */ +#define SYSDIR "/etc" + +#define LESSKEYFILE ".less" +#define LESSKEYFILE_SYS SYSDIR "/sysless" +#define DEF_LESSKEYINFILE ".lesskey" +#define LESSKEYINFILE_SYS SYSDIR "/syslesskey" +#define LESSHISTFILE ".lesshst" /* Autodetect mingw */ #if defined(__MINGW32__) /* * Define MSDOS_COMPILER if compiling under Microsoft C. */ -#define MSDOS_COMPILER WIN32C +#define MSDOS_COMPILER WIN32C /* * Pathname separator character. */ -#define PATHNAME_SEP "\\" +#define PATHNAME_SEP "\\" #else /* * Define MSDOS_COMPILER if compiling under Microsoft C. */ -#define MSDOS_COMPILER 0 +#define MSDOS_COMPILER 0 /* * Pathname separator character. */ -#define PATHNAME_SEP "/" +#define PATHNAME_SEP "/" #endif /* Settings always true on Unix. */ @@ -154,9 +157,9 @@ #define TGETENT_OK 1 /* - * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. + * HAVE_ANSI_PROTOS is 1 if your compiler supports ANSI function prototypes. */ -#define HAVE_ANSI_PROTOS 1 +#define HAVE_ANSI_PROTOS 1 /* * HAVE_SYS_TYPES_H is 1 if your system has <sys/types.h>. @@ -172,28 +175,28 @@ * HAVE_PERROR is 1 if your system has the perror() call. * (Actually, if it has sys_errlist, sys_nerr and errno.) */ -#define HAVE_PERROR 1 +#define HAVE_PERROR 1 /* * HAVE_TIME is 1 if your system has the time() call. */ -#define HAVE_TIME 1 +#define HAVE_TIME 1 /* * HAVE_SHELL is 1 if your system supports a SHELL command interpreter. */ -#define HAVE_SHELL 1 +#define HAVE_SHELL 1 /* * Default shell metacharacters and meta-escape character. */ -#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," -#define DEF_METAESCAPE "\\" +#define DEF_METACHARS "; *?\t\n'\"()<>[]|&^`#\\$%=~{}," +#define DEF_METAESCAPE "\\" /* * HAVE_DUP is 1 if your system has the dup() call. */ -#define HAVE_DUP 1 +#define HAVE_DUP 1 /* Define to 1 if you have the memcpy() function. */ #define HAVE_MEMCPY 1 @@ -211,26 +214,26 @@ * Sizes of various buffers. */ #if 0 /* old sizes for small memory machines */ -#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ -#define UNGOT_SIZE 100 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 200 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 512 /* Max size of line in tags file */ -#define TABSTOP_MAX 32 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 512 /* Buffer for multichar commands */ +#define UNGOT_SIZE 100 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 200 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 512 /* Max size of line in tags file */ +#define TABSTOP_MAX 32 /* Max number of custom tab stops */ #define LINENUM_POOL 200 /* Size of line number pool */ #else /* more reasonable sizes for modern machines */ -#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ -#define UNGOT_SIZE 200 /* Max chars to unget() */ -#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ -#define OUTBUF_SIZE 1024 /* Output buffer */ -#define PROMPT_SIZE 2048 /* Max size of prompt string */ -#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ -#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ -#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ -#define TABSTOP_MAX 128 /* Max number of custom tab stops */ +#define CMDBUF_SIZE 2048 /* Buffer for multichar commands */ +#define UNGOT_SIZE 200 /* Max chars to unget() */ +#define LINEBUF_SIZE 1024 /* Initial max size of line in input file */ +#define OUTBUF_SIZE 1024 /* Output buffer */ +#define PROMPT_SIZE 2048 /* Max size of prompt string */ +#define TERMBUF_SIZE 2048 /* Termcap buffer for tgetent */ +#define TERMSBUF_SIZE 1024 /* Buffer to hold termcap strings */ +#define TAGLINE_SIZE 1024 /* Max size of line in tags file */ +#define TABSTOP_MAX 128 /* Max number of custom tab stops */ #define LINENUM_POOL 1024 /* Size of line number pool */ #endif @@ -393,6 +396,9 @@ /* Define to 1 if you have the <termcap.h> header file. */ #define HAVE_TERMCAP_H 1 +/* Define HAVE_TERMINFO if you have the terminfo library. */ +#define HAVE_TERMINFO 1 + /* Define HAVE_TERMIOS_FUNCS if you have tcgetattr/tcsetattr. */ #define HAVE_TERMIOS_FUNCS 1 @@ -429,12 +435,6 @@ /* Define HAVE_VOID if your compiler supports the "void" type. */ #define HAVE_VOID 1 -/* Define HAVE_WCTYPE if you have iswupper, iswlower, towupper, towlower. */ -#define HAVE_WCTYPE 1 - -/* Define to 1 if you have the <wctype.h> header file. */ -#define HAVE_WCTYPE_H 1 - /* Define to 1 if you have the '_setjmp' function. */ #define HAVE__SETJMP 1 |
