less/less-429-mouse.patch

2366 lines
73 KiB
Diff
Raw Blame History

This file contains invisible Unicode characters

This file contains invisible Unicode characters that are indistinguishable to humans but may be processed differently by a computer. If you think that this is intentional, you can safely ignore this warning. Use the Escape button to reveal them.

Index: Makefile.in
===================================================================
--- Makefile.in.orig 2009-02-24 03:39:21.000000000 +0100
+++ Makefile.in 2009-06-03 15:17:47.000000000 +0200
@@ -48,7 +48,8 @@ OBJ = main.${O} screen.${O} brac.${O} ch
help.${O} ifile.${O} input.${O} jump.${O} line.${O} linenum.${O} \
lsystem.${O} mark.${O} optfunc.${O} option.${O} opttbl.${O} os.${O} \
output.${O} position.${O} prompt.${O} search.${O} signal.${O} \
- tags.${O} ttyin.${O} version.${O} @REGEX_O@
+ tags.${O} ttyin.${O} version.${O} @REGEX_O@ \
+ selection.${O}
all: less$(EXEEXT) lesskey$(EXEEXT) lessecho$(EXEEXT)
Index: cmd.h
===================================================================
--- cmd.h.orig 2008-05-29 18:46:47.000000000 +0200
+++ cmd.h 2009-06-03 15:17:47.000000000 +0200
@@ -67,6 +67,10 @@
#define A_PREV_TAG 54
#define A_FILTER 55
+#define A_MOUSE 60
+#define A_MOUSE_END_SEL_IN 61
+#define A_MOUSE_END_SEL_OUT 62
+
#define A_INVALID 100
#define A_NOACTION 101
#define A_UINVALID 102
@@ -130,3 +134,7 @@
#define SK_BACKTAB 15
#define SK_CTL_BACKSPACE 16
#define SK_CONTROL_K 40
+
+/* less input command mode */
+#define M_NORMAL 1
+#define M_MULTICHAR_COMMAND 2
Index: command.c
===================================================================
--- command.c.orig 2009-03-30 21:45:51.000000000 +0200
+++ command.c 2009-06-03 15:19:41.000000000 +0200
@@ -4,7 +4,7 @@
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
*
- * For more information about less, or for information on how to
+ * For more information about less, or for information on how to
* contact the author, see the README file.
*/
@@ -56,7 +56,7 @@ extern int oldbot;
extern int forw_prompt;
static char ungot[UNGOT_SIZE];
-static char *ungotp = NULL;
+public char *ungotp = NULL;
#if SHELL_ESCAPE
static char *shellcmd = NULL; /* For holding last shell command for "!!" */
#endif
@@ -72,6 +72,10 @@ static int save_hshift;
#if PIPEC
static char pipec;
#endif
+int mouse_x1, mouse_y1; /* mouse coordinates on left mouse button press */
+extern char *selection; /* buffer with selection */
+extern int selection_size; /* current selection size */
+extern int xselection; /* is xselection available */
static void multi_search();
@@ -122,7 +126,7 @@ mca_search()
#if HILITE_SEARCH
if (search_type & SRCH_FILTER)
mca = A_FILTER;
- else
+ else
#endif
if (search_type & SRCH_FORW)
mca = A_F_SEARCH;
@@ -146,7 +150,7 @@ mca_search()
#if HILITE_SEARCH
if (search_type & SRCH_FILTER)
cmd_putstr("&/");
- else
+ else
#endif
if (search_type & SRCH_FORW)
cmd_putstr("/");
@@ -164,7 +168,7 @@ mca_opt_toggle()
int no_prompt;
int flag;
char *dash;
-
+
no_prompt = (optflag & OPT_NO_PROMPT);
flag = (optflag & ~OPT_NO_PROMPT);
dash = (flag == OPT_NO_TOGGLE) ? "_" : "-";
@@ -313,7 +317,7 @@ mca_char(c)
* Entering digits of a number.
* Terminated by a non-digit.
*/
- if (!((c >= '0' && c <= '9') || c == '.') &&
+ if (!((c >= '0' && c <= '9') || c == '.') &&
editchar(c, EC_PEEK|EC_NOHISTORY|EC_NOCOMPLETE|EC_NORIGHTLEFT) == A_INVALID)
{
/*
@@ -383,7 +387,7 @@ mca_char(c)
/*
* We're getting a long option name.
* See if we've matched an option name yet.
- * If so, display the complete name and stop
+ * If so, display the complete name and stop
* accepting chars until user hits RETURN.
*/
struct loption *o;
@@ -487,7 +491,7 @@ mca_char(c)
case A_FILTER:
/*
* Special case for search commands.
- * Certain characters as the first char of
+ * Certain characters as the first char of
* the pattern have special meaning:
* ! Toggle the NO_MATCH flag
* * Toggle the PAST_EOF flag
@@ -602,7 +606,7 @@ make_display()
/*
* {{ Maybe this should be:
* jump_loc(ch_zero(), jump_sline);
- * but this behavior seems rather unexpected
+ * but this behavior seems rather unexpected
* on the first screen. }}
*/
jump_loc(ch_zero(), 1);
@@ -638,7 +642,7 @@ prompt()
if (ungotp != NULL && ungotp > ungot)
{
/*
- * No prompt necessary if commands are from
+ * No prompt necessary if commands are from
* ungotten chars rather than from the user.
*/
return;
@@ -654,7 +658,7 @@ prompt()
* If we've hit EOF on the last file and the -E flag is set, quit.
*/
if (get_quit_at_eof() == OPT_ONPLUS &&
- eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
+ eof_displayed() && !(ch_getflags() & CH_HELPFILE) &&
next_ifile(curr_ifile) == NULL_IFILE)
quit(QUIT_OK);
@@ -662,12 +666,12 @@ prompt()
* If the entire file is displayed and the -F flag is set, quit.
*/
if (quit_if_one_screen &&
- entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
+ entire_file_displayed() && !(ch_getflags() & CH_HELPFILE) &&
next_ifile(curr_ifile) == NULL_IFILE)
quit(QUIT_OK);
#if MSDOS_COMPILER==WIN32C
- /*
+ /*
* In Win32, display the file name in the window title.
*/
if (!(ch_getflags() & CH_HELPFILE))
@@ -677,9 +681,9 @@ prompt()
* Select the proper prompt and display it.
*/
/*
- * If the previous action was a forward movement,
+ * If the previous action was a forward movement,
* don't clear the bottom line of the display;
- * just print the prompt since the forward movement guarantees
+ * just print the prompt since the forward movement guarantees
* that we're in the right position to display the prompt.
* Clearing the line could cause a problem: for example, if the last
* line displayed ended at the right screen edge without a newline,
@@ -759,7 +763,7 @@ getcc()
/*
* We have "/string" but no newline. Add the \n.
*/
- return ('\n');
+ return ('\n');
default:
/*
@@ -821,7 +825,7 @@ multi_search(pattern, n)
if (search_type & SRCH_FIRST_FILE)
{
/*
- * Start at the first (or last) file
+ * Start at the first (or last) file
* in the command line list.
*/
if (search_type & SRCH_FORW)
@@ -900,13 +904,218 @@ multi_search(pattern, n)
}
/*
+ * process escape sequence with mouse button action
+ * Note: action on mouse wheel depends on current less input command mode
+ */
+ static void
+process_mouse_button(mode)
+ int mode; /* normal mode or multicharacter command mode */
+{
+ int button, mouse_x, mouse_y;
+ int counter;
+
+ button = getcc() - 32;
+ mouse_x = getcc() - 32;
+ mouse_y = getcc() - 32;
+
+ if (button & 64)
+ {
+ /* mouse wheel used */
+ if (button & 1)
+ {
+ /* mouse wheel down */
+ switch (mode)
+ {
+ case M_NORMAL:
+ /* forward N (default 3) line. */
+ if (number <= 0)
+ number = 3;
+ cmd_exec();
+ if (show_attn == OPT_ONPLUS && number > 1)
+ set_attnpos(bottompos);
+ forward(number, 0, 0);
+ break;
+ case M_MULTICHAR_COMMAND:
+ /* the same behaviour as for down arrow */
+ ungetcc('k');
+ ungetcc('\033');
+ break;
+ default:
+ error("Warnning: Internal error, bad mode for process_mouse_button()", NULL_PARG);
+ break;
+ }
+ } else
+ {
+ /* mouse wheel up */
+ switch (mode)
+ {
+ case M_NORMAL:
+ /* backward N (default 3) line. */
+ if (number <= 0)
+ number = 3;
+ cmd_exec();
+ backward(number, 0, 0);
+ break;
+ case M_MULTICHAR_COMMAND:
+ /* the same behaviour as for up arrow */
+ ungetcc('j');
+ ungetcc('\033');
+ break;
+ default:
+ error("Warnning: Internal error, bad mode for process_mouse_button()", NULL_PARG);
+ break;
+ }
+ }
+ } else
+ {
+ /* 1-3 mouse button used */
+ switch (button & 3)
+ {
+ case 0:
+ /*
+ * left button pressed
+ * xterm is waiting for mouse tracking information
+ */
+ printf("\033[1;%d;%d;1;%dT",
+ mouse_x, mouse_y, get_swindow() + 1);
+ fflush(stdout);
+ /* save coordinates of selection */
+ mouse_x1 = mouse_x;
+ mouse_y1 = mouse_y;
+ break;
+ case 1:
+ /*
+ * middle button pressed
+ * paste selection
+ */
+ if (xselection)
+ read_xselection();
+ for (counter = selection_size; --counter >= 0;)
+ ungetcc(selection[counter]);
+ break;
+ case 3:
+ /* any button released */
+ break;
+ }
+ }
+ return;
+}
+
+/*
+ * process escape sequence with mouse action (end of selection)
+ * left mouse button was released inside of given area
+ */
+ static void
+process_mouse_end_selection_in()
+{
+ int button, mouse_x, mouse_y;
+
+ mouse_x = getcc() - 32;
+ mouse_y = getcc() - 32;
+ create_selection(mouse_x1 - 1, mouse_y1 - 1,
+ mouse_x - 1, mouse_y - 1);
+ if (xselection)
+ write_xselection();
+ return;
+}
+
+/*
+ * process escape sequence with mouse action (end of selection)
+ * left mouse button was released outside of given area
+ */
+ static void
+process_mouse_end_selection_out()
+{
+ int mouse_x, mouse_y;
+ int mouse_x2, mouse_y2;
+
+ mouse_x1 = getcc() - 32; /* startx */
+ mouse_y1 = getcc() - 32; /* starty */
+ mouse_x2 = getcc() - 32; /* endx - inside of given area */
+ mouse_y2 = getcc() - 32; /* endy - inside of given area */
+ mouse_x = getcc() - 32; /* current mouse x coordinate */
+ mouse_y = getcc() - 32; /* current mouse y coordinate */
+ create_selection(mouse_x1 - 1, mouse_y1 - 1,
+ mouse_x2 - 1, mouse_y2 - 1);
+ if (xselection)
+ write_xselection();
+ return;
+}
+
+/*
+ * process possible escape sequention with mouse action
+ * in multicharacter command mode
+ */
+ static int
+save_mouse_action(int *c)
+{
+ unsigned char mouse_cbuf[CMDBUF_SIZE + 1]; /* buffer for current input */
+ char *mouse_extra = NULL;
+ int mouse_cbuf_pos; /* current position in mouse_cbuf */
+ int mouse_action; /* what action is in current input ? */
+
+ mouse_cbuf[0] = *c;
+ mouse_cbuf[1] = '\0';
+ mouse_cbuf_pos = 1;
+
+ while (((mouse_action = mcmd_decode(mouse_cbuf, &mouse_extra)) == A_PREFIX) &&
+ (mouse_cbuf_pos < CMDBUF_SIZE))
+ {
+ /*
+ * current input contains prefix for an action
+ * read next char
+ */
+ mouse_cbuf[mouse_cbuf_pos++] = getcc();
+ mouse_cbuf[mouse_cbuf_pos] = '\0';
+ mouse_extra = NULL;
+ }
+
+ switch (mouse_action)
+ {
+ case A_MOUSE:
+ /*
+ * a mouse button pressed or released
+ */
+ process_mouse_button(M_MULTICHAR_COMMAND);
+ *c = getcc();
+ return 1;
+ case A_MOUSE_END_SEL_IN:
+ /*
+ * end of mouse selection
+ * left mouse button was released inside of given area
+ */
+ process_mouse_end_selection_in();
+ *c = getcc();
+ return 1;
+ case A_MOUSE_END_SEL_OUT:
+ /*
+ * end of mouse selection
+ * left mouse button was released outside of given area
+ */
+ process_mouse_end_selection_out();
+ *c = getcc();
+ return 1;
+ default:
+ /*
+ * no mouse action
+ * unget all characters
+ */
+ while (--mouse_cbuf_pos > 0)
+ ungetcc(mouse_cbuf[mouse_cbuf_pos]);
+ *c = mouse_cbuf[0];
+ return 0;
+ }
+ return 0;
+}
+
+/*
* Main command processor.
* Accept and execute commands until a quit command.
*/
public void
commands()
{
- register int c;
+ int c;
register int action;
register char *cbuf;
int newaction;
@@ -971,6 +1180,7 @@ commands()
* action to be performed.
*/
if (mca)
+ while (save_mouse_action(&c)); /* process all escape sequences with mouse actions */
switch (mca_char(c))
{
case MCA_MORE:
@@ -1002,7 +1212,7 @@ commands()
* We're in a multichar command.
* Add the character to the command buffer
* and display it on the screen.
- * If the user backspaces past the start
+ * If the user backspaces past the start
* of the line, abort the command.
*/
if (cmd_char(c) == CC_QUIT || len_cmdbuf() == 0)
@@ -1041,6 +1251,29 @@ commands()
switch (action)
{
+ case A_MOUSE:
+ /*
+ * a mouse button pressed or released
+ */
+ process_mouse_button(M_NORMAL);
+ break;
+
+ case A_MOUSE_END_SEL_IN:
+ /*
+ * end of mouse selection
+ * left mouse button was released inside of given area
+ */
+ process_mouse_end_selection_in();
+ break;
+
+ case A_MOUSE_END_SEL_OUT:
+ /*
+ * end of mouse selection
+ * left mouse button was released outside of given area
+ */
+ process_mouse_end_selection_out();
+ break;
+
case A_DIGIT:
/*
* First digit of a number.
@@ -1127,7 +1360,7 @@ commands()
cmd_exec();
backward((int) number, 1, 0);
break;
-
+
case A_FF_SCREEN:
/*
* Force forward one screen.
@@ -1156,8 +1389,8 @@ commands()
}
ignore_eoi = 0;
/*
- * This gets us back in "F mode" after processing
- * a non-abort signal (e.g. window-change).
+ * This gets us back in "F mode" after processing
+ * a non-abort signal (e.g. window-change).
*/
if (sigs && !ABORT_SIGS())
newaction = A_F_FOREVER;
@@ -1165,7 +1398,7 @@ commands()
case A_F_SCROLL:
/*
- * Forward N lines
+ * Forward N lines
* (default same as last 'd' or 'u' command).
*/
if (number > 0)
@@ -1178,7 +1411,7 @@ commands()
case A_B_SCROLL:
/*
- * Forward N lines
+ * Forward N lines
* (default same as last 'd' or 'u' command).
*/
if (number > 0)
@@ -1274,7 +1507,7 @@ commands()
/*
* Exit.
*/
- if (curr_ifile != NULL_IFILE &&
+ if (curr_ifile != NULL_IFILE &&
ch_getflags() & CH_HELPFILE)
{
/*
@@ -1342,7 +1575,7 @@ commands()
*/
DO_SEARCH();
break;
-
+
case A_T_AGAIN_SEARCH:
/*
* Repeat previous search, multiple files.
@@ -1362,8 +1595,8 @@ commands()
break;
case A_T_REVERSE_SEARCH:
- /*
- * Repeat previous search,
+ /*
+ * Repeat previous search,
* multiple files in reverse direction.
*/
save_search_type = search_type;
@@ -1406,7 +1639,7 @@ commands()
error("Command not available", NULL_PARG);
break;
#endif
-
+
case A_VISUAL:
/*
* Invoke an editor on the input file.
@@ -1460,7 +1693,7 @@ commands()
number = 1;
if (edit_next((int) number))
{
- if (get_quit_at_eof() && eof_displayed() &&
+ if (get_quit_at_eof() && eof_displayed() &&
!(ch_getflags() & CH_HELPFILE))
quit(QUIT_OK);
parg.p_string = (number > 1) ? "(N-th) " : "";
Index: decode.c
===================================================================
--- decode.c.orig 2009-03-30 21:45:51.000000000 +0200
+++ decode.c 2009-06-03 15:17:47.000000000 +0200
@@ -166,6 +166,13 @@ static unsigned char cmdtable[] =
'Z','Z',0, A_QUIT
};
+static unsigned char mousetable[] =
+{
+ ESC,'[','M',0, A_MOUSE,
+ ESC,'[','t',0, A_MOUSE_END_SEL_IN,
+ ESC,'[','T',0, A_MOUSE_END_SEL_OUT
+};
+
static unsigned char edittable[] =
{
'\t',0, EC_F_COMPLETE, /* TAB */
@@ -218,6 +225,7 @@ struct tablelist
* List of command tables and list of line-edit tables.
*/
static struct tablelist *list_fcmd_tables = NULL;
+static struct tablelist *list_mcmd_tables = NULL;
static struct tablelist *list_ecmd_tables = NULL;
static struct tablelist *list_var_tables = NULL;
static struct tablelist *list_sysvar_tables = NULL;
@@ -293,8 +301,10 @@ init_cmds()
/*
* Add the default command tables.
*/
+ add_fcmd_table((char*)mousetable, sizeof(mousetable));
add_fcmd_table((char*)cmdtable, sizeof(cmdtable));
add_ecmd_table((char*)edittable, sizeof(edittable));
+ add_mcmd_table((char*)mousetable, sizeof(mousetable));
#if USERFILE
/*
* For backwards compatibility,
@@ -369,6 +379,18 @@ add_ecmd_table(buf, len)
}
/*
+ * Add an mouse command table.
+ */
+ public void
+add_mcmd_table(buf, len)
+ char *buf;
+ int len;
+{
+ if (add_cmd_table(&list_mcmd_tables, buf, len) < 0)
+ error("Warning: some mouse commands disabled", NULL_PARG);
+}
+
+/*
* Add an environment variable table.
*/
static void
@@ -523,6 +545,17 @@ ecmd_decode(cmd, sp)
}
/*
+ * Decode a command from the mousetables list.
+ */
+ public int
+mcmd_decode(cmd, sp)
+ char *cmd;
+ char **sp;
+{
+ return (cmd_decode(list_mcmd_tables, cmd, sp));
+}
+
+/*
* Get the value of an environment variable.
* Looks first in the lesskey file, then in the real environment.
*/
Index: defines.h.in
===================================================================
--- defines.h.in.orig 2009-06-03 15:16:21.000000000 +0200
+++ defines.h.in 2009-06-03 15:17:47.000000000 +0200
@@ -183,7 +183,7 @@
* Sizes of various buffers.
*/
#define CMDBUF_SIZE 512 /* Buffer for multichar commands */
-#define UNGOT_SIZE 100 /* Max chars to unget() */
+#define UNGOT_SIZE 10000 /* 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 */
Index: funcs.h
===================================================================
--- funcs.h.orig 2008-06-09 19:11:24.000000000 +0200
+++ funcs.h 2009-06-03 15:17:47.000000000 +0200
@@ -86,8 +86,10 @@
public void init_cmds ();
public void add_fcmd_table ();
public void add_ecmd_table ();
+ public void add_mcmd_table ();
public int fcmd_decode ();
public int ecmd_decode ();
+ public int mcmd_decode ();
public char * lgetenv ();
public int lesskey ();
public void add_hometable ();
@@ -188,6 +190,7 @@
public void gomark ();
public POSITION markpos ();
public void unmark ();
+ public void opt_A ();
public void opt_o ();
public void opt__O ();
public void opt_l ();
@@ -278,3 +281,10 @@
public void open_getchr ();
public void close_getchr ();
public int getchr ();
+ public void clear_selection();
+ public int create_selection(int, int, int, int);
+ public int write_xselection();
+ public int read_xselection();
+ public int is_xselection_available();
+ public void init_mouse_support();
+ public void deinit_mouse_support();
Index: less.hlp
===================================================================
--- less.hlp.orig 2009-04-11 02:01:43.000000000 +0200
+++ less.hlp 2009-06-03 15:17:47.000000000 +0200
@@ -112,6 +112,8 @@
Display help (from command line).
-a ........ --search-skip-screen
Forward search skips current screen.
+ -A ........ --mouse-support
+ Use less mouse support (works only in xterm)
-b [_N] .... --buffers=[_N]
Number of buffers.
-B ........ --auto-buffers
Index: less.nro
===================================================================
--- less.nro.orig 2009-04-11 19:52:18.000000000 +0200
+++ less.nro 2009-06-03 15:19:41.000000000 +0200
@@ -10,7 +10,7 @@ less \- opposite of more
.br
.B "less \-\-version"
.br
-.B "less [\-[+]aBcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]"
+.B "less [\-[+]aABcCdeEfFgGiIJKLmMnNqQrRsSuUVwWX~]"
.br
.B " [\-b \fIspace\fP] [\-h \fIlines\fP] [\-j \fIline\fP] [\-k \fIkeyfile\fP]"
.br
@@ -24,7 +24,7 @@ less \- opposite of more
.SH DESCRIPTION
.I Less
-is a program similar to
+is a program similar to
.I more
(1), but which allows backward movement
in the file as well as forward movement.
@@ -45,7 +45,7 @@ Commands are based on both
.I more
and
.I vi.
-Commands may be preceded by a decimal number,
+Commands may be preceded by a decimal number,
called N in the descriptions below.
The number is used by some commands, as indicated.
@@ -70,7 +70,7 @@ Scroll forward N lines, default 1.
The entire N lines are displayed, even if N is more than the screen size.
.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
+If N is specified, it becomes the new default for
subsequent d and u commands.
.IP "b or ^B or ESC-v"
Scroll backward N lines, default one window (see option \-z below).
@@ -83,7 +83,7 @@ The entire N lines are displayed, even i
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
+If N is specified, it becomes the new default for
subsequent d and u commands.
.IP "ESC-) or RIGHTARROW"
Scroll horizontally right N characters, default half the screen width
@@ -150,16 +150,16 @@ Like }, but applies to square brackets r
Followed by two characters,
acts like {, but uses the two characters as open and close brackets,
respectively.
-For example, "ESC ^F < >" 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-^B"
Followed by two characters,
acts like }, but uses the two characters as open and close brackets,
respectively.
-For example, "ESC ^B < >" 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 letter,
+Followed by any lowercase letter,
marks the current position with that letter.
.IP "'"
(Single quote.)
@@ -189,7 +189,7 @@ they modify the type of search rather th
Search for lines which do NOT match the pattern.
.IP "^E or *"
Search multiple files.
-That is, if the search reaches the END of the current file
+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 "^F or @"
@@ -198,7 +198,7 @@ in the command line list,
regardless of what is currently displayed on the screen
or the settings of the \-a or \-j options.
.IP "^K"
-Highlight any text which matches the pattern on the current screen,
+Highlight any text which matches the pattern on the current screen,
but don't move to the first match (KEEP current position).
.IP "^R"
Don't interpret regular expression metacharacters;
@@ -214,7 +214,7 @@ Certain characters are special as in the
Search for lines which do NOT match the pattern.
.IP "^E or *"
Search multiple files.
-That is, if the search reaches the beginning of the current file
+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 "^F or @"
@@ -250,7 +250,7 @@ Repeat previous search, but in the rever
and crossing file boundaries.
.IP "ESC-u"
Undo search highlighting.
-Turn off highlighting of strings matching the current search pattern.
+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.
@@ -278,10 +278,10 @@ Examine a new file.
If the filename is missing, the "current" file (see the :n and :p commands
below) from the list of files in the command line is re-examined.
A percent sign (%) in the filename is replaced by the name of the
-current file.
+current file.
A pound sign (#) is replaced by the name of the previously examined file.
-However, two consecutive percent signs are simply
-replaced with a single percent sign.
+However, two consecutive percent signs are simply
+replaced with a single percent sign.
This allows you to enter a filename that contains a percent sign
in the name.
Similarly, two consecutive pound signs are replaced with a single pound sign.
@@ -334,7 +334,7 @@ the current setting is printed and nothi
Like the \- command, but takes a long option name (see OPTIONS below)
rather than a single option letter.
You must press RETURN after typing the option name.
-A ^P 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
@@ -366,19 +366,19 @@ rather than a single option letter.
You must press RETURN after typing the option name.
.IP +cmd
Causes the specified cmd to be executed each time a new file is examined.
-For example, +G causes
+For example, +G causes
.I less
-to initially display each file starting at the end
+to initially display each file starting at the end
rather than the beginning.
.IP V
-Prints the version number of
-.I less
+Prints the version number of
+.I less
being run.
.IP "q or Q or :q or :Q or ZZ"
Exits
.I less.
.PP
-The following
+The following
four
commands may or may not be valid, depending on your particular installation.
.PP
@@ -391,7 +391,7 @@ See also the discussion of LESSEDIT unde
.IP "! shell-command"
Invokes a shell to run the shell-command given.
A percent sign (%) in the command is replaced by the name of the
-current file.
+current file.
A pound sign (#) is replaced by the name of the previously examined file.
"!!" repeats the last shell command.
"!" with no shell command simply invokes a shell.
@@ -412,10 +412,10 @@ This only works if the input is a pipe,
.SH OPTIONS
Command line options are described below.
Most options may be changed while
-.I less
+.I less
is running, via the "\-" command.
.PP
-Most options may be given in one of two forms:
+Most options may be given in one of two forms:
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
@@ -429,20 +429,20 @@ the remainder of the name may be in eith
For example, \-\-Quit-at-eof is equivalent to \-\-QUIT-AT-EOF.
.PP
Options are also taken from the environment variable "LESS".
-For example,
-to avoid typing "less \-options ..." each time
-.I less
-is invoked, you might tell
+For example,
+to avoid typing "less \-options ..." each time
+.I less
+is invoked, you might tell
.I csh:
.sp
setenv LESS "-options"
.sp
-or if you use
+or if you use
.I sh:
.sp
LESS="-options"; export LESS
.sp
-On MS-DOS, you don't need the quotes, but you should replace any
+On MS-DOS, you don't need the quotes, but you should replace any
percent signs in the options string by double percent signs.
.sp
The environment variable is parsed before the command line,
@@ -466,17 +466,33 @@ This option displays a summary of the co
it may be necessary to quote the question mark, thus: "\-\e?".)
.IP "\-a or \-\-search-skip-screen"
Causes searches to start after the last line
-displayed on the screen,
+displayed on the screen,
thus skipping all lines displayed on the screen.
By default, searches start at the second line on the screen
(or after the last found line; see the \-j option).
+.IP "-A or --mouse-support"
+Causes less to process mouse actions itself. Currently
+it works only in xterm. The inspiration comes from vim-6.0.
+.sp
+Cut&Paste function works only internally by default. To access
+X selection you must hold SHIFT key to process the mouse actions
+by xterm. Or you can install
+.I xselection
+utility by which less
+is able to access X selection itself.
+.sp
+Also scrolling by mouse wheel button is supported. You must map
+wheel mouse action on the 4th and 5th mouse button. This is done
+in XF86Config in Section "InputDevice" by option:
+.sp
+ Option "ZAxisMapping" "4 5"
.IP "\-b\fIn\fP or \-\-buffers=\fIn\fP"
Specifies the amount of buffer space
.I less
will use for each file, in units of kilobytes (1024 bytes).
By default 64K 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
+The \-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.
@@ -486,18 +502,18 @@ buffers are allocated automatically as n
If a large amount of data is read from the pipe, this can cause
a large amount of memory to be allocated.
The \-B option disables this automatic allocation of buffers for pipes,
-so that only 64K
+so that only 64K
(or the amount of space specified by the \-b option)
is used for the pipe.
Warning: use of \-B can result in erroneous display, since only the
-most recently viewed part of the piped data is kept in memory;
+most recently viewed part of the piped data is kept in memory;
any earlier data is lost.
.IP "\-c or \-\-clear-screen"
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
+Same as \-c, for compatibility with older versions of
.I less.
.IP "\-d or \-\-dumb"
The \-d option suppresses the error message
@@ -510,24 +526,24 @@ on a dumb terminal.
.IP "\-D\fBx\fP\fIcolor\fP or \-\-color=\fBx\fP\fIcolor\fP"
[MS-DOS only]
Sets the color of the text displayed.
-\fBx\fP is a single character which selects the type of text whose color is
+\fBx\fP is a single character which selects the type of text whose color is
being set: n=normal, s=standout, d=bold, u=underlined, k=blink.
-\fIcolor\fP is a pair of numbers separated by a period.
-The first number selects the foreground color and the second selects
+\fIcolor\fP is a pair of numbers separated by a period.
+The first number selects the foreground color and the second selects
the background color of the text.
A single number \fIN\fP is the same as \fIN.M\fP,
where \fIM\fP is the normal background color.
.IP "\-e or \-\-quit-at-eof"
-Causes
-.I less
+Causes
+.I less
to automatically exit
the second time it reaches end-of-file.
-By default, the only way to exit
+By default, the only way to exit
.I less
is via the "q" command.
.IP "\-E or \-\-QUIT-AT-EOF"
-Causes
+Causes
.I less
to automatically exit the first time it reaches end-of-file.
.IP "\-f or \-\-force"
@@ -545,13 +561,13 @@ Causes
to automatically exit
if the entire file can be displayed on the first screen.
.IP "\-g or \-\-hilite-search"
-Normally,
-.I less
+Normally,
+.I less
will highlight ALL strings which match the last search command.
-The \-g option changes this behavior to highlight only the particular string
+The \-g option changes this behavior to highlight only the particular string
which was found by the last search command.
-This can cause
-.I less
+This can cause
+.I less
to run somewhat faster than the default.
.IP "\-G or \-\-HILITE-SEARCH"
The \-G option suppresses all highlighting of strings found by search commands.
@@ -565,11 +581,11 @@ backward, \-h0 is implied.)
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;
+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
+Like \-i, but searches ignore case even if
the pattern contains uppercase letters.
.IP "\-j\fIn\fP or \-\-jump-target=\fIn\fP"
Specifies a line on the screen where the "target" line
@@ -588,7 +604,7 @@ screen, .3 is three tenths down from the
If the line is specified as a fraction, the actual line number
is recalculated if the terminal window is resized, so that the
target line remains at the specified fraction of the screen height.
-If any form of the \-j option is used,
+If any form of the \-j option is used,
forward searches begin at the line immediately after the target line,
and backward searches begin at the target line.
For example, if "\-j4" is used, the target line is the
@@ -607,7 +623,7 @@ to open and interpret the named file as
Multiple \-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
+it is also used as a
.I lesskey
file.
.IP "\-K or \-\-quit-on-intr"
@@ -617,16 +633,16 @@ to exit immediately when an interrupt ch
Normally, an interrupt character causes
.I 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
+Note that use of this option makes it impossible to return to the
command prompt from the "F" command.
.IP "\-L or \-\-no-lessopen"
Ignore the LESSOPEN environment variable
(see the INPUT PREPROCESSOR section below).
-This option can be set from within \fIless\fP,
-but it will apply only to files opened subsequently, not to the
+This option can be set from within \fIless\fP,
+but it will apply only to files opened subsequently, not to the
file which is currently open.
.IP "\-m or \-\-long-prompt"
-Causes
+Causes
.I less
to prompt verbosely (like \fImore\fP),
with the percent into the file.
@@ -634,9 +650,9 @@ By default,
.I less
prompts with a colon.
.IP "\-M or \-\-LONG-PROMPT"
-Causes
+Causes
.I less
-to prompt even more verbosely than
+to prompt even more verbosely than
.I more.
.IP "\-n or \-\-line-numbers"
Suppresses line numbers.
@@ -657,7 +673,7 @@ Causes
to copy its input to the named file as it is being viewed.
This applies only when the input file is a pipe,
not an ordinary file.
-If the file already exists,
+If the file already exists,
.I less
will ask for confirmation before overwriting it.
.IP "\-O\fIfilename\fP or \-\-LOG-FILE=\fIfilename\fP"
@@ -665,14 +681,14 @@ The \-O option is like \-o, but it will
file without asking for confirmation.
.sp
If no log file has been specified,
-the \-o and \-O options can be used from within
+the \-o and \-O options can be used from within
.I 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
.I less.
.IP "\-p\fIpattern\fP or \-\-pattern=\fIpattern\fP"
-The \-p option on the command line is equivalent to
+The \-p option on the command line is equivalent to
specifying +/\fIpattern\fP;
that is, it tells
.I less
@@ -681,24 +697,24 @@ to start at the first occurrence of \fIp
Provides a way to tailor the three prompt
styles to your own preference.
This option would normally be put in the LESS environment
-variable, rather than being typed in with each
+variable, rather than being typed in with each
.I less
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
+-Ps 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).
-All prompt strings consist of a sequence of
+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"
Causes moderately "quiet" operation:
-the terminal bell is not rung
+the terminal bell is not rung
if an attempt is made to scroll past the end of the file
or before the beginning of the file.
If the terminal has a "visual bell", it is used instead.
@@ -726,7 +742,7 @@ ANSI "color" escape sequences are sequen
.sp
ESC [ ... m
.sp
-where the "..." is zero or more color specification characters
+where the "..." is zero or more color specification characters
For the purpose of keeping track of screen appearance,
ANSI color escape sequences are assumed to not move the cursor.
You can make
@@ -734,9 +750,9 @@ You can make
think that characters other than "m" can end ANSI color escape sequences
by setting the environment variable LESSANSIENDCHARS to the list of
characters which can end a color escape sequence.
-And you can make
-.I less
-think that characters other than the standard ones may appear between
+And you can make
+.I less
+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.
.IP "\-s or \-\-squeeze-blank-lines"
@@ -756,16 +772,16 @@ The \-t option, followed immediately by
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",
-which was previously built by
+which was previously built by
.I ctags
(1) or an equivalent command.
If the environment variable LESSGLOBALTAGS is set, it is taken to be
-the name of a command compatible with
+the name of a command compatible with
.I global
(1), and that command is executed to find the tag.
(See http://www.gnu.org/software/global/global.html).
-The \-t option may also be specified from within
-.I less
+The \-t option may also be specified from within
+.I less
(using the \- command) as a way of examining a new file.
The command ":t" is equivalent to specifying \-t from within
.I less.
@@ -775,18 +791,18 @@ Specifies a tags file to be used instead
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"
-Causes backspaces, tabs and carriage returns to be
+Causes backspaces, tabs and carriage returns 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,
backspaces which appear adjacent to an underscore character
are treated specially:
-the underlined text is displayed
+the underlined text is displayed
using the terminal's hardware underlining capability.
Also, backspaces which appear between two identical characters
-are treated specially:
-the overstruck text is printed
+are treated specially:
+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.
@@ -794,7 +810,7 @@ other carriage returns are handled as sp
Text which is overstruck or underlined can be searched for
if neither \-u nor \-U is in effect.
.IP "\-V or \-\-version"
-Displays the version number of
+Displays the version number of
.I less.
.IP "\-w or \-\-hilite-unread"
Temporarily highlights the first "new" line after a forward movement
@@ -806,7 +822,7 @@ The highlight is removed at the next com
The entire line is highlighted, unless the \-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
+Like \-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,..."
Sets tab stops.
@@ -832,14 +848,14 @@ By default, any forward movement causes
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.
-The "z" may be omitted for compatibility with some versions of
+The "z" may be omitted for compatibility with some versions of
.I more.
If the number
.I n
-is negative, it indicates
+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, \fI\-z-4\fP sets the
scrolling window to 20 lines. If the screen is resized to 40 lines,
the scrolling window automatically changes to 36 lines.
.IP "\-\fI\(dqcc\fP\ or\ \-\-quotes=\fIcc\fP"
@@ -870,7 +886,7 @@ to the terminal.
This is sometimes useful if the keypad strings make the numeric
keypad behave in an undesirable manner.
.IP "\-\-follow-name"
-Normally, if the input file is renamed while an F command is executing,
+Normally, if the input file is renamed while an F command is executing,
.I less
will continue to display the contents of the original file despite
its name change.
@@ -878,7 +894,7 @@ If \-\-follow-name is specified, during
.I less
will periodically attempt to reopen the file by name.
If the reopen succeeds and the file is a different file from the original
-(which means that a new file has been created
+(which means that a new file has been created
with the same name as the original (now renamed) file),
.I less
will display the contents of that new file.
@@ -894,7 +910,7 @@ For example, +G tells
.I less
to start at the end of the file rather than the beginning,
and +/xyz tells it to start at the first occurrence of "xyz" in the file.
-As a special case, +<number> acts like +<number>g;
+As a special case, +<number> acts like +<number>g;
that is, it starts the display at the specified line number
(however, see the caveat under the "g" command above).
If the option starts with ++, the initial command applies to
@@ -908,8 +924,8 @@ When entering command line at the bottom
or the pattern for a search command),
certain keys can be used to manipulate the command line.
Most commands have an alternate form in [ brackets ] which can be used if
-a key does not exist on a particular keyboard.
-(Note that the forms beginning with ESC do not work
+a key does not exist on a particular keyboard.
+(Note that the forms beginning with ESC do not work
in 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 ^V or ^A.
@@ -950,7 +966,7 @@ is entered into the command line.
Repeated TABs will cycle thru the other matching filenames.
If the completed filename is a directory, a "/" is appended to the filename.
(On MS-DOS systems, a "\e" is appended.)
-The environment variable LESSSEPARATOR can be used to specify a
+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.
@@ -965,9 +981,9 @@ If you have changed your line-kill chara
other than ^U, that character is used instead of ^U.
.SH "KEY BINDINGS"
-You may define your own
+You may define your own
.I less
-commands by using the program
+commands by using the program
.I lesskey
(1)
to create a lesskey file.
@@ -980,7 +996,7 @@ and to set environment variables.
If the environment variable LESSKEY is set,
.I less
uses that as the name of the lesskey file.
-Otherwise,
+Otherwise,
.I less
looks in a standard place for the lesskey file:
On Unix systems,
@@ -1004,24 +1020,24 @@ manual page for more details.
.P
A system-wide lesskey file may also be set up to provide key bindings.
If a key is defined in both a local lesskey file and in the
-system-wide file, key bindings in the local file take precedence over
+system-wide file, key bindings in the local file take precedence over
those in the system-wide file.
If the environment variable LESSKEY_SYSTEM is set,
.I less
uses that as the name of the system-wide lesskey file.
Otherwise,
-.I less
+.I less
looks in a standard place for the system-wide lesskey file:
On Unix systems, the system-wide lesskey file is /usr/local/etc/sysless.
-(However, if
-.I less
+(However, if
+.I less
was built with a different sysconf directory than /usr/local/etc,
that directory is where the sysless file is found.)
On MS-DOS and Windows systems, the system-wide lesskey file is c:\e_sysless.
On OS/2 systems, the system-wide lesskey file is c:\esysless.ini.
.SH "INPUT PREPROCESSOR"
-You may define an "input preprocessor" for
+You may define an "input preprocessor" for
.I less.
Before
.I less
@@ -1030,10 +1046,10 @@ way the contents of the file are display
An input preprocessor is simply an executable program (or shell script),
which writes the contents of the file to a different file,
called the replacement file.
-The contents of the replacement file are then displayed
+The contents of the replacement file are then displayed
in place of the contents of the original file.
However, it will appear to the user as if the original file is opened;
-that is,
+that is,
.I less
will display the original filename as the name of the current file.
.PP
@@ -1041,17 +1057,17 @@ An input preprocessor receives one comma
as entered by the user.
It should create the replacement file, and when finished,
print the name of the replacement file to its standard output.
-If the input preprocessor does not output a replacement filename,
+If the input preprocessor does not output a replacement filename,
.I less
uses the original file, as normal.
The input preprocessor is not called when viewing standard input.
To set up an input preprocessor, set the LESSOPEN environment variable
to a command line which will invoke your input preprocessor.
-This command line should include one occurrence of the string "%s",
+This command line should include one occurrence of the string "%s",
which will be replaced by the filename
when the input preprocessor command is invoked.
.PP
-When
+When
.I less
closes a file opened in such a way, it will call another program,
called the input postprocessor,
@@ -1059,11 +1075,11 @@ which may perform any desired clean-up a
replacement file created by LESSOPEN).
This program receives two command line arguments, the original filename
as entered by the user, and the name of the replacement file.
-To set up an input postprocessor, set the LESSCLOSE environment variable
+To set up an input postprocessor, set the LESSCLOSE environment variable
to a command line which will invoke your input postprocessor.
-It may include two occurrences of the string "%s";
-the first is replaced with the original name of the file and
-the second with the name of the replacement file,
+It may include two occurrences of the string "%s";
+the first is replaced with the original name of the file and
+the second with the name of the replacement file,
which was output by LESSOPEN.
.PP
For example, on many Unix systems, these two scripts will allow you
@@ -1079,7 +1095,7 @@ lessopen.sh:
.br
*.Z) uncompress -\c $1 >/tmp/less.$$ 2>/dev/null
.br
- if [ \-s /tmp/less.$$ ]; then
+ if [ \-s /tmp/less.$$ ]; then
.br
echo /tmp/less.$$
.br
@@ -1106,21 +1122,21 @@ More complex LESSOPEN and LESSCLOSE scri
to accept other types of compressed files, and so on.
.PP
It is also possible to set up an input preprocessor to
-pipe the file data directly to
+pipe the file data directly to
.I less,
rather than putting the data into a replacement file.
-This avoids the need to decompress the entire file before
+This avoids the need to decompress the entire file before
starting to view it.
An input preprocessor that works this way is called an input pipe.
An input pipe, instead of writing the name of a replacement file on
its standard output,
writes the entire contents of the replacement file on its standard output.
If the input pipe does not write any characters on its standard output,
-then there is no replacement file and
+then there is no replacement file and
.I less
uses the original file, as normal.
To use an input pipe,
-make the first character in the LESSOPEN environment variable a
+make the first character in the LESSOPEN environment variable a
vertical bar (|) to signify that the input preprocessor is an input pipe.
.PP
For example, on many Unix systems, this script will work like the
@@ -1151,7 +1167,7 @@ For compatibility with previous versions
.I less,
the input pipe is not used if
.I less
-is viewing standard input.
+is viewing standard input.
However, if the character after the vertical bar is a dash (\-),
the input pipe is used on standard input as well as other files.
@@ -1216,7 +1232,7 @@ For example, "bccc4b." would mean charac
1, 2 and 3 are control, 4, 5, 6 and 7 are binary, and 8 is normal.
All characters after the last are taken to be the same as the last,
so characters 9 through 255 would be normal.
-(This is an example, and does not necessarily
+(This is an example, and does not necessarily
represent any real character set.)
.PP
This table shows the value of LESSCHARDEF which is equivalent
@@ -1243,7 +1259,7 @@ to each of the possible values for LESSC
next\ \ 8bcccbcc18b95.bb125.bb
.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_TYPE or LANG
environment variables, then the default character set is utf-8.
.PP
@@ -1261,12 +1277,12 @@ interface is also not available, the def
.PP
Control and binary characters are displayed in standout (reverse video).
Each such character is displayed in caret notation if possible
-(e.g. ^A for control-A). Caret 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
+This format can be changed by
setting the LESSBINFMT environment variable.
-LESSBINFMT may begin with a "*" and one character to select
+LESSBINFMT may begin with a "*" and one character to select
the display attribute:
"*k" is blinking, "*d" is bold, "*u" is underlined, "*s" is standout,
and "*n" is normal.
@@ -1285,12 +1301,12 @@ acts similarly to LESSBINFMT but it appl
that were successfully decoded but are unsuitable for display (e.g.,
unassigned code points).
Its default value is "<U+%04lX>".
-Note that LESSUTFBINFMT and LESSBINFMT share their display attribute
-setting ("*x") so specifying one will affect both;
+Note that LESSUTFBINFMT and LESSBINFMT share their display attribute
+setting ("*x") so specifying one will affect both;
LESSUTFBINFMT is read after LESSBINFMT so its setting, if any,
-will have priority.
+will have priority.
Problematic octets in a UTF-8 file (octets of a truncated sequence,
-octets of a complete but non-shortest form sequence, illegal octets,
+octets of a complete but non-shortest form sequence, illegal octets,
and stray trailing octets)
are displayed individually using LESSBINFMT so as to facilitate diagnostic
of how the UTF-8 file is ill-formed.
@@ -1470,7 +1486,7 @@ The default value for LESSEDIT is:
Note that this expands to the editor name, followed by a + and the
line number, followed by the file name.
If your editor does not accept the "+linenumber" syntax, or has other
-differences in invocation syntax, the LESSEDIT variable can be
+differences in invocation syntax, the LESSEDIT variable can be
changed to modify this default.
.SH SECURITY
@@ -1509,10 +1525,10 @@ behaves (mostly) in conformance with the
In this mode, less behaves differently in these ways:
.PP
The \-e option works differently.
-If the \-e option is not set,
+If the \-e option is not set,
.I less
behaves as if the \-E option were set.
-If the \-e option is set,
+If the \-e option is set,
.I less
behaves as if the \-e and \-F options were set.
.PP
@@ -1524,7 +1540,7 @@ If the \-m option is set, the short prom
The \-n option acts like the \-z option.
The normal behavior of the \-n option is unavailable in this mode.
.PP
-The parameter to the \-p option is taken to be a
+The parameter to the \-p option is taken to be a
.I less
command rather than a search pattern.
.PP
@@ -1533,10 +1549,10 @@ and the MORE environment variable is use
.SH "ENVIRONMENT VARIABLES"
Environment variables may be specified either in the system environment
-as usual, or in a
+as usual, or in a
.I lesskey
(1) file.
-If environment variables are defined in more than one place,
+If environment variables are defined in more than one place,
variables defined in a local lesskey file take precedence over
variables defined in the system environment, which take precedence
over variables defined in the system-wide lesskey file.
@@ -1562,7 +1578,7 @@ Language for determining the character s
.IP LC_CTYPE
Language for determining the character set.
.IP LESS
-Options which are passed to
+Options which are passed to
.I less
automatically.
.IP LESSANSIENDCHARS
@@ -1594,11 +1610,11 @@ Normally should be set to "global" if yo
(1) command. If not set, global tags are not used.
.IP LESSHISTFILE
Name of the history file used to remember search commands and
-shell commands between invocations of
+shell commands between invocations of
.I less.
If set to "\-" or "/dev/null", a history file is not used.
The default is "$HOME/.lesshst" on Unix systems, "$HOME/_lesshst" on
-DOS and Windows systems, or "$HOME/lesshst.ini" or "$INIT/lesshst.ini"
+DOS and Windows systems, or "$HOME/lesshst.ini" or "$INIT/lesshst.ini"
on OS/2 systems.
.IP LESSHISTSIZE
The maximum number of commands to save in the history file.
@@ -1624,7 +1640,7 @@ String to be appended to a directory nam
.IP LESSUTFBINFMT
Format for displaying non-printable Unicode code points.
.IP LESS_IS_MORE
-Emulate the
+Emulate the
.I more
(1) command.
.IP LINES
@@ -1634,7 +1650,7 @@ Takes precedence over the number of line
the window system's idea of the screen size takes precedence over the
LINES and COLUMNS environment variables.)
.IP PATH
-User's search path (used to find a lesskey file
+User's search path (used to find a lesskey file
on MS-DOS and OS/2 systems).
.IP SHELL
The shell used to execute the ! command, as well as to expand filenames.
@@ -1658,7 +1674,7 @@ under the terms of either
the Free Software Foundation; or (2) the Less License.
See the file README in the less distribution for more details
regarding redistribution.
-You should have received a copy of the GNU General Public License
+You should have received a copy of the GNU General Public License
along with the source for less; see the file COPYING.
If not, write to the Free Software Foundation, 59 Temple Place,
Suite 330, Boston, MA 02111-1307, USA.
@@ -1676,10 +1692,10 @@ Mark Nudelman <markn@greenwoodsoftware.c
.br
See http://www.greenwoodsoftware.com/less/bugs.html for the latest list of known bugs in less.
.br
-Send bug reports or comments to the above address or to
+Send bug reports or comments to the above address or to
.br
bug-less@gnu.org.
.br
-For more information, see the less homepage at
+For more information, see the less homepage at
.br
http://www.greenwoodsoftware.com/less.
Index: main.c
===================================================================
--- main.c.orig 2009-03-30 21:45:52.000000000 +0200
+++ main.c 2009-06-03 15:17:47.000000000 +0200
@@ -32,6 +32,7 @@ public char * progname;
public int quitting;
public int secure;
public int dohelp;
+public int xselection = 0; /* is xselection utility available ? */
public int less_is_more;
#if LOGFILE
Index: optfunc.c
===================================================================
--- optfunc.c.orig 2009-03-30 21:45:52.000000000 +0200
+++ optfunc.c 2009-06-03 15:19:41.000000000 +0200
@@ -4,7 +4,7 @@
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
*
- * For more information about less, or for information on how to
+ * For more information about less, or for information on how to
* contact the author, see the README file.
*/
@@ -64,7 +64,31 @@ extern int ul_fg_color, ul_bg_color;
extern int so_fg_color, so_bg_color;
extern int bl_fg_color, bl_bg_color;
#endif
+extern int opt_mouse_support;
+/*
+ * Handler for the -A option.
+ */
+ /*ARGSUSED*/
+ public void
+opt_A(type, s)
+ int type;
+ char *s;
+{
+ switch (type)
+ {
+ case TOGGLE:
+ if (opt_mouse_support)
+ init_mouse_support();
+ else
+ deinit_mouse_support();
+ break;
+ case QUERY:
+ case INIT:
+ break;
+ }
+ return;
+}
#if LOGFILE
/*
@@ -139,7 +163,7 @@ opt_l(type, s)
int err;
int n;
char *t;
-
+
switch (type)
{
case INIT:
@@ -464,7 +488,7 @@ colordesc(s, fg_color, bg_color)
{
int fg, bg;
int err;
-
+
fg = getnum(&s, "D", &err);
if (err)
{
Index: opttbl.c
===================================================================
--- opttbl.c.orig 2009-03-30 21:45:52.000000000 +0200
+++ opttbl.c 2009-06-03 15:17:47.000000000 +0200
@@ -55,6 +55,7 @@ public int oldbot; /* Old bottom of scr
#if HILITE_SEARCH
public int hilite_search; /* Highlight matched search patterns? */
#endif
+public int opt_mouse_support; /* Less mouse support (works only with xterm) */
public int less_is_more = 0; /* Make compatible with POSIX more */
@@ -62,6 +63,7 @@ public int less_is_more = 0; /* Make com
* Long option names.
*/
static struct optname a_optname = { "search-skip-screen", NULL };
+static struct optname A_optname = { "mouse-support", NULL };
static struct optname b_optname = { "buffers", NULL };
static struct optname B__optname = { "auto-buffers", NULL };
static struct optname c_optname = { "clear-screen", NULL };
@@ -139,7 +141,14 @@ static struct loption option[] =
NULL
}
},
-
+ { 'A', &A_optname,
+ BOOL, OPT_OFF, &opt_mouse_support, opt_A,
+ {
+ "Do not use less mouse support",
+ "Use less mouse support (works only in xterm)",
+ NULL
+ }
+ },
{ 'b', &b_optname,
NUMBER|INIT_HANDLER, 64, &bufspace, opt_b,
{
Index: output.c
===================================================================
--- output.c.orig 2009-03-30 21:45:52.000000000 +0200
+++ output.c 2009-06-03 15:19:41.000000000 +0200
@@ -4,7 +4,7 @@
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
*
- * For more information about less, or for information on how to
+ * For more information about less, or for information on how to
* contact the author, see the README file.
*/
@@ -40,6 +40,8 @@ extern int so_fg_color, so_bg_color;
extern int bl_fg_color, bl_bg_color;
#endif
+extern char *ungotp;
+
/*
* Display the line which is in the line buffer.
*/
@@ -136,7 +138,7 @@ flush()
FOREGROUND_RED,
FOREGROUND_GREEN,
FOREGROUND_RED|FOREGROUND_GREEN,
- FOREGROUND_BLUE,
+ FOREGROUND_BLUE,
FOREGROUND_BLUE|FOREGROUND_RED,
FOREGROUND_BLUE|FOREGROUND_GREEN,
FOREGROUND_BLUE|FOREGROUND_GREEN|FOREGROUND_RED
@@ -181,7 +183,7 @@ flush()
/*
* Select foreground/background colors
- * based on the escape sequence.
+ * based on the escape sequence.
*/
fg = nm_fg_color;
bg = nm_bg_color;
@@ -490,7 +492,27 @@ get_return()
#else
c = getchr();
if (c != '\n' && c != '\r' && c != ' ' && c != READ_INTR)
+ {
+ /*
+ * on the standard input can be a sequence (not only one char)
+ * we have read first char of the potential sequence and
+ * we want to unget it to internal less buffer but there
+ * can be older ungotten chracters
+ *
+ * we must not to put old ungotten chars inside this sequence
+ *
+ * 1. solution is to put this char at the begin of internal
+ * less buffer (LIFO) to use this character after all older
+ * ungotten chars. But the user can be mixed that the current
+ * command is done later
+ *
+ * 2. soluton is to discard all old ungotten chars
+ *
+ * I prefer the 2. solution
+ */
+ ungotp = NULL;
ungetcc(c);
+ }
#endif
}
Index: screen.c
===================================================================
--- screen.c.orig 2009-06-03 15:16:21.000000000 +0200
+++ screen.c 2009-06-03 15:19:41.000000000 +0200
@@ -4,7 +4,7 @@
* You may distribute under the terms of either the GNU General Public
* License or the Less License, as specified in the README file.
*
- * For more information about less, or for information on how to
+ * For more information about less, or for information on how to
* contact the author, see the README file.
*/
@@ -241,12 +241,15 @@ extern int hilite_search;
extern char *tgetstr();
extern char *tgoto();
+extern int xselection; /* is xselection available */
+extern int opt_mouse_support; /* is less mouse support enabled (option -A ) */
+int mouse_support = 0; /* is less mouse support initialized ? */
/*
* Change terminal to "raw mode", or restore to "normal" mode.
- * "Raw mode" means
+ * "Raw mode" means
* 1. An outstanding read will complete on receipt of a single keystroke.
- * 2. Input is not echoed.
+ * 2. Input is not echoed.
* 3. On output, \n is mapped to \r\n.
* 4. \t is NOT expanded into spaces.
* 5. Signal-causing characters such as ctrl-C (interrupt),
@@ -268,7 +271,7 @@ raw_mode(on)
static struct termios save_term;
static int saved_term = 0;
- if (on)
+ if (on)
{
/*
* Get terminal modes.
@@ -419,7 +422,7 @@ raw_mode(on)
#endif
#if MUST_SET_LINE_DISCIPLINE
/*
- * System's termios is broken; need to explicitly
+ * System's termios is broken; need to explicitly
* request TERMIODISC line discipline.
*/
s.c_line = TERMIODISC;
@@ -594,7 +597,7 @@ raw_mode(on)
kill_char = CONTROL('U');
/*
* So that when we shell out or run another program, its
- * stdin is in cooked mode. We do not switch stdin to binary
+ * stdin is in cooked mode. We do not switch stdin to binary
* mode if fd0 is zero, since that means we were called before
* tty was reopened in open_getchr, in which case we would be
* changing the original stdin device outside less.
@@ -825,7 +828,7 @@ scrsize()
get_clock()
{
clock_t start;
-
+
/*
* Get synchronized at the start of a tick.
*/
@@ -861,7 +864,7 @@ delay(msec)
int msec;
{
long i;
-
+
while (msec-- > 0)
{
for (i = 0; i < msec_loops; i++)
@@ -911,7 +914,7 @@ special_key_str(key)
{
#if OS2
/*
- * If windowid is not NULL, assume less is executed in
+ * If windowid is not NULL, assume less is executed in
* the XFree86 environment.
*/
case SK_RIGHT_ARROW:
@@ -1089,7 +1092,7 @@ get_term()
*/
SET_BINARY(0);
GetConsoleScreenBufferInfo(con_out, &scr);
- ReadConsoleOutputAttribute(con_out, &curr_attr,
+ ReadConsoleOutputAttribute(con_out, &curr_attr,
1, scr.dwCursorPosition, &nread);
sy_bg_color = (curr_attr & BG_COLORS) >> 4; /* normalize */
sy_fg_color = curr_attr & FG_COLORS;
@@ -1184,7 +1187,7 @@ get_term()
* Disable highlighting by default on magic cookie terminals.
* Turning on highlighting might change the displayed width
* of a line, causing the display to get messed up.
- * The user can turn it back on with -g,
+ * The user can turn it back on with -g,
* but she won't like the results.
*/
hilite_search = 0;
@@ -1207,7 +1210,7 @@ get_term()
sc_e_keypad = ltgetstr("ke", &sp);
if (sc_e_keypad == NULL)
sc_e_keypad = "";
-
+
sc_init = ltgetstr("ti", &sp);
if (sc_init == NULL)
sc_init = "";
@@ -1241,7 +1244,7 @@ get_term()
if (sc_move == NULL || *sc_move == '\0')
{
/*
- * This is not an error here, because we don't
+ * This is not an error here, because we don't
* always need sc_move.
* We need it only if we don't have home or lower-left.
*/
@@ -1368,7 +1371,7 @@ cost(t)
/*
* Return the "best" of the two given termcap strings.
- * The best, if both exist, is the one with the lower
+ * The best, if both exist, is the one with the lower
* cost (see cost() function).
*/
static char *
@@ -1422,7 +1425,7 @@ tmodes(incap, outcap, instr, outstr, def
/*
- * Below are the functions which perform all the
+ * Below are the functions which perform all the
* terminal-specific screen manipulation.
*/
@@ -1458,7 +1461,7 @@ initcolor()
char *blanks;
int row;
int col;
-
+
/*
* Create a complete, blank screen using "normal" colors.
*/
@@ -1527,6 +1530,42 @@ win32_deinit_term()
#endif
+public void
+init_mouse_support()
+{
+ if (mouse_support)
+ /* nothing to do (less mouse support is already inicialized */
+ return;
+
+ /* save old highlight mouse tracking */
+ printf("\033[?1001s");
+ /* enable mouse tracking */
+ printf("\033[?1001h");
+ fflush(stdout);
+ mouse_support = 1;
+
+ /* check if the xselection utility is available and is usable */
+ xselection = is_xselection_available();
+
+ return;
+}
+
+public void
+deinit_mouse_support()
+{
+ if (!mouse_support)
+ /* nothing to do (mouse support was not inicialized) */
+ return;
+
+ /* disable mouse tracking */
+ printf("\033[?1001l");
+ /* restore old highlight mouse tracking */
+ printf("\033[?1001r");
+ fflush(stdout);
+ mouse_support = 0;
+ return;
+}
+
/*
* Initialize terminal
*/
@@ -1538,7 +1577,9 @@ init()
tputs(sc_init, sc_height, putchr);
if (!no_keypad)
tputs(sc_s_keypad, sc_height, putchr);
- if (top_scroll)
+ if (opt_mouse_support)
+ init_mouse_support();
+ if (top_scroll)
{
int i;
@@ -1576,6 +1617,7 @@ deinit()
tputs(sc_e_keypad, sc_height, putchr);
if (!no_init)
tputs(sc_deinit, sc_height, putchr);
+ deinit_mouse_support();
#else
/* Restore system colors. */
SETCOLORS(sy_fg_color, sy_bg_color);
@@ -1662,8 +1704,8 @@ add_line()
#if 0
/*
- * Remove the n topmost lines and scroll everything below it in the
- * window upward. This is needed to stop leaking the topmost line
+ * Remove the n topmost lines and scroll everything below it in the
+ * window upward. This is needed to stop leaking the topmost line
* into the scrollback buffer when we go down-one-line (in WIN32).
*/
public void
@@ -1748,7 +1790,7 @@ win32_clear()
}
/*
- * Remove the n topmost lines and scroll everything below it in the
+ * Remove the n topmost lines and scroll everything below it in the
* window upward.
*/
public void
@@ -1860,7 +1902,7 @@ line_left()
}
/*
- * Check if the console size has changed and reset internals
+ * Check if the console size has changed and reset internals
* (in lieu of SIGWINCH for WIN32).
*/
public void
@@ -1872,7 +1914,7 @@ check_winch()
if (con_out == INVALID_HANDLE_VALUE)
return;
-
+
flush();
GetConsoleScreenBufferInfo(con_out, &scr);
size.Y = scr.srWindow.Bottom - scr.srWindow.Top + 1;
@@ -1919,7 +1961,7 @@ create_flash()
struct videoconfig w;
char *blanks;
int row, col;
-
+
_getvideoconfig(&w);
videopages = w.numvideopages;
if (videopages < 2)
@@ -1944,7 +1986,7 @@ create_flash()
#if MSDOS_COMPILER==BORLANDC
register int n;
- whitescreen = (unsigned short *)
+ whitescreen = (unsigned short *)
malloc(sc_width * sc_height * sizeof(short));
if (whitescreen == NULL)
return;
@@ -2007,7 +2049,7 @@ vbell()
create_flash();
if (whitescreen == NULL)
return;
- currscreen = (unsigned short *)
+ currscreen = (unsigned short *)
malloc(sc_width * sc_height * sizeof(short));
if (currscreen == NULL) return;
gettext(1, 1, sc_width, sc_height, currscreen);
@@ -2093,7 +2135,7 @@ clear_eol()
short top, left;
short bot, right;
struct rccoord tpos;
-
+
flush();
/*
* Save current state.
@@ -2284,14 +2326,14 @@ apply_at_specials(attr)
#if 0 /* No longer used */
/*
- * Erase the character to the left of the cursor
+ * Erase the character to the left of the cursor
* and move the cursor left.
*/
public void
backspace()
{
#if !MSDOS_COMPILER
- /*
+ /*
* Erase the previous character by overstriking with a space.
*/
tputs(sc_backspace, 1, putchr);
@@ -2300,7 +2342,7 @@ backspace()
#else
#if MSDOS_COMPILER==MSOFTC
struct rccoord tpos;
-
+
flush();
tpos = _gettextposition();
if (tpos.col <= 1)
@@ -2404,12 +2446,12 @@ win32_kbhit(tty)
ip.Event.KeyEvent.wVirtualKeyCode == VK_SHIFT ||
ip.Event.KeyEvent.wVirtualKeyCode == VK_CONTROL ||
ip.Event.KeyEvent.wVirtualKeyCode == VK_MENU);
-
+
currentKey.ascii = ip.Event.KeyEvent.uChar.AsciiChar;
currentKey.scan = ip.Event.KeyEvent.wVirtualScanCode;
keyCount = ip.Event.KeyEvent.wRepeatCount;
- if (ip.Event.KeyEvent.dwControlKeyState &
+ if (ip.Event.KeyEvent.dwControlKeyState &
(LEFT_ALT_PRESSED | RIGHT_ALT_PRESSED))
{
switch (currentKey.scan)
@@ -2418,7 +2460,7 @@ win32_kbhit(tty)
currentKey.ascii = 0;
break;
}
- } else if (ip.Event.KeyEvent.dwControlKeyState &
+ } else if (ip.Event.KeyEvent.dwControlKeyState &
(LEFT_CTRL_PRESSED | RIGHT_CTRL_PRESSED))
{
switch (currentKey.scan)
@@ -2462,8 +2504,8 @@ WIN32getch(tty)
keyCount --;
ascii = currentKey.ascii;
/*
- * On PC's, the extended keys return a 2 byte sequence beginning
- * with '00', so if the ascii code is 00, the next byte will be
+ * On PC's, the extended keys return a 2 byte sequence beginning
+ * with '00', so if the ascii code is 00, the next byte will be
* the lsb of the scan code.
*/
pending_scancode = (ascii == 0x00);
Index: selection.c
===================================================================
--- /dev/null 1970-01-01 00:00:00.000000000 +0000
+++ selection.c 2009-06-03 15:18:53.000000000 +0200
@@ -0,0 +1,271 @@
+/*
+ * Copyright (C) 1984-2000 Mark Nudelman
+ *
+ * You may distribute under the terms of either the GNU General Public
+ * License or the Less License, as specified in the README file.
+ *
+ * For more information about less, or for information on how to
+ * contact the author, see the README file.
+ */
+/*
+ * Copyright (c) 1997-2000 Kazushi (Jam) Marukawa
+ * All rights of japanized routines are reserved.
+ *
+ * You may distribute under the terms of the Less License.
+ */
+
+
+/*
+ * User-level command processor.
+ */
+
+#include <stdio.h>
+#include "less.h"
+#include "position.h"
+#include "option.h"
+#include "cmd.h"
+
+#define IS_CONT(c) (((c) & 0xC0) == 0x80)
+#define SELECTION_SIZE_STEP 1000
+
+char *selection=NULL; /* buffer for less internal selection */
+int max_selection_size=0; /* current size of the buffer for less */
+ /* internal selection */
+int selection_size=0; /* current size of less internal selection */
+
+extern int utf_mode;
+
+/*
+ * clear less internal selection
+ */
+ public void
+clear_selection()
+{
+ if (selection)
+ {
+ free(selection);
+ selection=NULL;
+ max_selection_size=0;
+ selection_size=0;
+ }
+ return;
+}
+
+/*
+ * expand the size of less internal selection buffer
+ */
+ static int
+expand_selection_buffer(size)
+ int size; /* new size will be: max_selection_size + size */
+{
+ char *new_selection;
+
+ if (!selection)
+ {
+ /* buffer for selection isn't allocated */
+ selection = (char*)malloc((size + 1) * sizeof(char));
+ if (!selection)
+ {
+ error("WARNING: Not enough memory for selection", NULL_PARG);
+ clear_selection();
+ return 0;
+ }
+ max_selection_size = size;
+ selection_size = 0;
+ *selection = '\0';
+ return 1;
+ }
+
+ if (size > 0)
+ {
+ new_selection = (char*)malloc((max_selection_size + size + 1) * sizeof(char));
+ if (!new_selection)
+ {
+ error("WARNING: Not enough memory for selection", NULL_PARG);
+ clear_selection();
+ return 0;
+ }
+ memcpy(new_selection, selection, max_selection_size + 1);
+ free(selection);
+ selection = new_selection;
+ max_selection_size += size;
+ return 1;
+ }
+ return 0;
+}
+
+
+/*
+ * add a char into less internal selection
+ */
+ static int
+add_char_to_selection(c)
+ int c;
+{
+ if (selection_size >= max_selection_size)
+ if (!(expand_selection_buffer(SELECTION_SIZE_STEP)))
+ return 0;
+
+ /* finally add new char */
+ selection[selection_size++] = c;
+ selection[selection_size] = '\0';
+ return 1;
+}
+
+/*
+ * add more chars into less internal selection
+ */
+ static int
+add_buf_to_selection(buf, size)
+ char *buf;
+ int size;
+{
+ if ((selection_size + size) > max_selection_size)
+ if (!(expand_selection_buffer(size)))
+ return 0;
+
+ /* finally add buf to selection */
+ memcpy(selection + selection_size, buf, size);
+ selection_size += size;
+ selection[selection_size] = '\0';
+ return 1;
+}
+
+
+/*
+ * create less internal selection
+ * x1, y1, x2, y2 - are coordinates of begin and end of selection
+ */
+ public int
+create_selection(x1, y1, x2, y2)
+ int x1;
+ int y1;
+ int x2;
+ int y2;
+{
+ int x, y;
+ int c, csp, ap;
+ POSITION pos;
+
+ if ((x1 == x2) && (y1 == y2))
+ /* no new selection */
+ return 1;
+
+ if (((y1 == y2) && (x1 > x2)) || (y1 > y2))
+ {
+ /* we want to have x1,y1 as begin of selection */
+ x = x1; y = y1;
+ x1 = x2; y1 = y2;
+ x2 = x; y2 = y;
+ }
+
+ clear_selection();
+ for (y = y1; y <= y2; y++)
+ {
+ pos = position(y);
+ forw_line(pos);
+ for (x = (y == y1) ? x1 : 0;
+ (((c = gline(x, &csp, &ap)) != '\0') && !((y == y2) && (x >= x2)));
+ x++)
+ {
+ if (!add_char_to_selection(c))
+ /* something wrong */
+ return 0;
+ if ((utf_mode) && (IS_CONT(c)) && (y == y2))
+ /* it is multichar */
+ ++x2;
+ }
+ }
+ return 2;
+}
+
+/*
+ * write less internal selection to xselection
+ * it use the xselection utility because less isn't linked against Xlib
+ */
+ public int
+write_xselection()
+{
+ FILE *xsel;
+
+ if ((xsel = popen("xselection PRIMARY -", "w")) == NULL)
+ /* can't open xselection */
+ return 0;
+
+ if (selection)
+ if (fwrite(selection, 1, selection_size, xsel) != selection_size)
+ {
+ error("WARNING: Can not write the whole selection to the xselection", NULL_PARG);
+ pclose(xsel);
+ return 0;
+ }
+
+ if (pclose(xsel) != 0)
+ /* xselection didn't work correctly */
+ return 0;
+
+ /* everything OK */
+ return 1;
+}
+
+
+/*
+ * read xselection to less internal selection
+ * it use the xselection utility because less isn't linked against Xlib
+ */
+ public int
+read_xselection()
+{
+ FILE *xsel;
+ char buf[SELECTION_SIZE_STEP];
+ int read;
+
+ if ((xsel = popen("xselection PRIMARY", "r")) == NULL)
+ /* can't open xselection */
+ return 0;
+
+ clear_selection();
+ while ((read = fread(buf, 1, SELECTION_SIZE_STEP, xsel)) != 0)
+ {
+ if (!add_buf_to_selection(buf, read))
+ {
+ /* something wrong */
+ pclose(xsel);
+ return 0;
+ }
+ }
+
+ if (pclose(xsel) != 0)
+ {
+ /* xselection didn't work correctly */
+ clear_selection();
+ return 0;
+ }
+
+ /* everything OK */
+ return 1;
+}
+
+/*
+ * test if xselection utility is available
+ */
+ public int
+is_xselection_available()
+{
+ FILE *xsel;
+ char buf[SELECTION_SIZE_STEP];
+ int read;
+
+ if ((xsel = popen("xselection -help 2>/dev/null", "r")) == NULL)
+ /* can't open xselection */
+ return 0;
+
+ while ((read = fread(buf, 1, SELECTION_SIZE_STEP, xsel)) != 0);
+
+ if (pclose(xsel) != 0)
+ /* xselection doesn't work correctly */
+ return 0;
+
+ /* everything OK */
+ return 1;
+}