Hi,

Last weekend Delta and I were playing with dclip, fixing some bugs and
finally, we think there are no more corner cases handling selections.
For those of you, who don't know what dclip is:

http://tecnoprawn.wordpress.com/2009/12/17/dclip/

dclip is a lightweight clipboard manager (19 LOC in sh) that uses dmenu
as frontend to show the stored selections and depends on xclip. It
tries to unify the mess with different X selections.

For example in dwm, in order to copy with M+C+c and paste with M+C+v
you can add the following in your config.h:

/* commands */
static const char *dclipcmd[] = { "dclip", "paste", "-fn", font, "-nb",
normbgcolor, "-nf", normfgcolor, "-s    b", selbgcolor , "-sf",
selfgcolor, NULL };

and in the keys[] section:

{ MODKEY|ControlMask,  XK_c,   spawn,   SHCMD("exec dclip copy") },
{ MODKEY|ControlMask,  XK_v,   spawn,   {.v = dclipcmd } },

Furthermore, using dclip I noticed that dmenu cannot create items larger
than 1024 bytes, so I've modified the function readstdin in order
to solve this issued. It was very bouring to copy a selection larger
than 1024 chars with dclip and then have to paste several items from
dmenu instead of just one.

I attached the patch for dmenu-4.0 (last stable release) and dmenu-tip
and the last release of dclip.

Kind regards,
-- Nibble

Attachment: dclip
Description: Binary data

diff -r 78f9f72cc9c6 dmenu.c
--- a/dmenu.c	Sat Feb 21 19:21:54 2009 +0000
+++ b/dmenu.c	Mon Dec 21 12:23:19 2009 +0100
@@ -519,24 +519,31 @@
 void
 readstdin(void) {
 	char *p, buf[1024];
-	unsigned int len = 0, max = 0;
+	unsigned int len = 0, blen = 0, max = 0;
 	Item *i, *new;
 
-	i = 0;
+	i = 0, p = NULL;
 	while(fgets(buf, sizeof buf, stdin)) {
-		len = strlen(buf);
-		if (buf[len - 1] == '\n')
-			buf[len - 1] = 0;
-		if(!(p = strdup(buf)))
-			eprint("fatal: could not strdup() %u bytes\n", strlen(buf));
+		len += (blen = strlen(buf));
+		if(!(p = realloc(p, len))) {
+			eprint("fatal: could not realloc() %u bytes\n", len);
+			return;
+		}
+		memcpy (p + len - blen, buf, blen);
+		if (p[len - 1] == '\n')
+			p[len - 1] = 0;
+		else if (!feof(stdin))
+			continue;
 		if(max < len) {
 			maxname = p;
 			max = len;
 		}
+		len = 0;
 		if(!(new = (Item *)malloc(sizeof(Item))))
 			eprint("fatal: could not malloc() %u bytes\n", sizeof(Item));
 		new->next = new->left = new->right = NULL;
 		new->text = p;
+		p = NULL;
 		if(!i)
 			allitems = new;
 		else 
diff -r 4684b2cf4eab dmenu.c
--- a/dmenu.c	Sat Dec 05 16:52:53 2009 +0000
+++ b/dmenu.c	Mon Dec 21 12:23:37 2009 +0100
@@ -625,24 +625,31 @@
 void
 readstdin(void) {
 	char *p, buf[1024];
-	unsigned int len = 0, max = 0;
+	unsigned int len = 0, blen = 0, max = 0;
 	Item *i, *new;
 
-	i = 0;
+	i = 0, p = NULL;
 	while(fgets(buf, sizeof buf, stdin)) {
-		len = strlen(buf);
-		if (buf[len - 1] == '\n')
-			buf[len - 1] = 0;
-		if(!(p = strdup(buf)))
-			eprint("fatal: could not strdup() %u bytes\n", strlen(buf));
+		len += (blen = strlen(buf));
+		if(!(p = realloc(p, len))) {
+			eprint("fatal: could not realloc() %u bytes\n", len);
+			return;
+		}
+		memcpy (p + len - blen, buf, blen);
+		if (p[len - 1] == '\n')
+			p[len - 1] = 0;
+		else if (!feof(stdin))
+			continue;
 		if(max < len) {
 			maxname = p;
 			max = len;
 		}
+		len = 0;
 		if(!(new = (Item *)malloc(sizeof(Item))))
 			eprint("fatal: could not malloc() %u bytes\n", sizeof(Item));
 		new->next = new->left = new->right = NULL;
 		new->text = p;
+		p = NULL;
 		if(!i)
 			allitems = new;
 		else 

Reply via email to