xsel

Program for manipulating the X clipboard
git clone https://git.sinitax.com/kfish/xsel
Log | Files | Refs | README | LICENSE | sfeed.txt

commit 87f992933e27c95b140ea8504ea6ccaa6d47e2ad
parent 02ea656cd47cad4c66bbfe411e0198eb86e943bc
Author: Sergey Mironov <ierton@gmail.com>
Date:   Tue,  2 Nov 2010 18:17:29 +0300

xsel.c: add --zeroflush option

Zeroflush mode is enhanced --follow mode. With --zeroflush option, xsel
will clear selection every time it reads '\0' from stdin.

Diffstat:
Mxsel.c | 23+++++++++++++++++++++++
1 file changed, 23 insertions(+), 0 deletions(-)

diff --git a/xsel.c b/xsel.c @@ -70,6 +70,10 @@ static Atom compound_text_atom; /* The COMPOUND_TEXT atom */ static int NUM_TARGETS; static Atom supported_targets[MAX_NUM_TARGETS]; +/* do_zeroflush: Use only last zero-separated part of input. + * All previous parts are discarded */ +static Bool do_zeroflush = False; + /* do_follow: Follow mode for output */ static Bool do_follow = False; @@ -112,6 +116,7 @@ usage (void) printf ("Input options\n"); printf (" -a, --append Append standard input to the selection\n"); printf (" -f, --follow Append to selection as standard input grows\n"); + printf (" -z, --zeroflush Overwrites selection when zero ('\\0') is received\n"); printf (" -i, --input Read standard input into the selection\n\n"); printf ("Output options\n"); printf (" -o, --output Write the selection to standard output\n\n"); @@ -868,6 +873,19 @@ try_read: read_buffer[total_input] = '\0'; + if(do_zeroflush && total_input > 0) { + int i; + for(i=total_input-1; i>=0; i--) { + if(read_buffer[i] == '\0') { + print_debug (D_TRACE, "Flushing input at %d", i); + memmove(&read_buffer[0], &read_buffer[i+1], total_input - i); + total_input = total_input - i - 1; + read_buffer[total_input] = '\0'; + break; + } + } + } + print_debug (D_TRACE, "Accumulated %d bytes input", total_input); return read_buffer; @@ -1994,6 +2012,11 @@ main(int argc, char *argv[]) do_follow = True; do_input = True; dont_output = True; + } else if (OPT("--zeroflush") || OPT("-z")) { + do_follow = True; + do_input = True; + dont_output = True; + do_zeroflush = True; } else if (OPT("--primary") || OPT("-p")) { selection = XA_PRIMARY; } else if (OPT("--secondary") || OPT("-s")) {