[hackers] [dmenu] fast but inexact || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Sun, 15 May 2011 14:03:37 +0200 (CEST)

changeset: 402:bcce5d224459
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sun May 15 13:02:33 2011 +0100
files: dmenu.c
description:
fast but inexact

diff -r 2e6ce9f498e0 -r bcce5d224459 dmenu.c
--- a/dmenu.c Sun May 15 02:37:49 2011 +0100
+++ b/dmenu.c Sun May 15 13:02:33 2011 +0100
@@ -444,19 +444,22 @@
 
 void
 readstdin(void) {
- char buf[sizeof text], *p;
- size_t i, size = 0;
+ char buf[sizeof text], *p, *maxstr = NULL;
+ size_t i, max = 0, size = 0;
 
         for(i = 0; fgets(buf, sizeof buf, stdin); items[++i].text = NULL) {
- if(i+1 == size / sizeof *items || !items)
+ if(i+1 >= size / sizeof *items)
                         if(!(items = realloc(items, (size += BUFSIZ))))
                                 eprintf("cannot realloc %u bytes:", size);
                 if((p = strchr(buf, '\n')))
                         *p = '\0';
                 if(!(items[i].text = strdup(buf)))
                         eprintf("cannot strdup %u bytes:", strlen(buf)+1);
- inputw = MAX(inputw, textw(dc, items[i].text));
+ if(strlen(items[i].text) > max)
+ max = strlen(maxstr = items[i].text);
         }
+ if(maxstr)
+ inputw = textw(dc, maxstr);
 }
 
 void
Received on Sun May 15 2011 - 14:03:37 CEST

This archive was generated by hypermail 2.2.0 : Sun May 15 2011 - 14:12:04 CEST