removed useless newlines
Anselm R. Garbe arg@10kloc.org
Fri, 06 Oct 2006 11:52:57 +0200
M
draw.c
→
draw.c
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMIV-MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dmenu.h"@@ -32,21 +31,17 @@ XRectangle r = { dc.x, dc.y, dc.w, dc.h };
XSetForeground(dpy, dc.gc, col[ColBG]); XFillRectangles(dpy, dc.drawable, dc.gc, &r, 1); - if(!text) return; - w = 0; olen = len = strlen(text); if(len >= sizeof(buf)) len = sizeof(buf) - 1; memcpy(buf, text, len); buf[len] = 0; - h = dc.font.ascent + dc.font.descent; y = dc.y + (dc.h / 2) - (h / 2) + dc.font.ascent; x = dc.x + (h / 2); - /* shorten text if necessary */ while(len && (w = textnw(buf, len)) > dc.w - h) buf[--len] = 0;@@ -58,10 +53,8 @@ buf[len - 2] = '.';
if(len > 3) buf[len - 3] = '.'; } - if(w > dc.w) return; /* too long */ - gcv.foreground = col[ColFG]; if(dc.font.set) { XChangeGC(dpy, dc.gc, GCForeground, &gcv);@@ -106,7 +99,6 @@ if(dc.font.set) {
XFontSetExtents *font_extents; XFontStruct **xfonts; char **font_names; - dc.font.ascent = dc.font.descent = 0; font_extents = XExtentsOfFontSet(dc.font.set); n = XFontsOfFontSet(dc.font.set, &xfonts, &font_names);
M
main.c
→
main.c
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * (C)opyright MMVI Sander van Dijk <a dot h dot vandijk at gmail dot com> * See LICENSE file for license details. */@@ -47,7 +46,6 @@ unsigned int tw, w;
if(!curr) return; - w = cmdw + 2 * SPACE; for(next = curr; next; next=next->right) { tw = textw(next->text);@@ -57,7 +55,6 @@ w += tw;
if(w > mw) break; } - w = cmdw + 2 * SPACE; for(prev = curr; prev && prev->left; prev=prev->left) { tw = textw(prev->left->text);@@ -78,18 +75,15 @@ dc.y = 0;
dc.w = mw; dc.h = mh; drawtext(NULL, dc.norm); - /* print command */ if(cmdw && item) dc.w = cmdw; drawtext(text[0] ? text : NULL, dc.norm); dc.x += cmdw; - if(curr) { dc.w = SPACE; drawtext((curr && curr->left) ? "<" : NULL, dc.norm); dc.x += dc.w; - /* determine maximum items */ for(i = curr; i != next; i=i->right) { dc.w = textw(i->text);@@ -98,7 +92,6 @@ dc.w = mw / 3;
drawtext(i->text, (sel == i) ? dc.sel : dc.norm); dc.x += dc.w; } - dc.x = mw - SPACE; dc.w = SPACE; drawtext(next ? ">" : NULL, dc.norm);@@ -114,11 +107,9 @@ Item *i, *j;
if(!pattern) return; - plen = strlen(pattern); item = j = NULL; nitem = 0; - for(i = allitems; i; i=i->next) if(!plen || !strncmp(pattern, i->text, plen)) { if(!j)@@ -142,7 +133,6 @@ i->right = NULL;
j = i; nitem++; } - curr = prev = next = sel = item; calcoffsets(); }@@ -157,12 +147,10 @@
len = strlen(text); buf[0] = 0; num = XLookupString(e, buf, sizeof(buf), &ksym, 0); - if(IsFunctionKey(ksym) || IsKeypadKey(ksym) || IsMiscFunctionKey(ksym) || IsPFKey(ksym) || IsPrivateKeypadKey(ksym)) return; - /* first check if a control mask is omitted */ if(e->state & ControlMask) { switch (ksym) {@@ -261,7 +249,6 @@ if(max < len) {
maxname = p; max = len; } - new = emalloc(sizeof(Item)); new->next = new->left = new->right = NULL; new->text = p;@@ -318,7 +305,6 @@ exit(EXIT_SUCCESS);
} else eprint("usage: dmenu [-font <name>] [-{norm,sel}{bg,fg} <color>] [-t <seconds>] [-v]\n", stdout); - dpy = XOpenDisplay(0); if(!dpy) eprint("dmenu: cannot open display\n");@@ -333,44 +319,37 @@ */
while(XGrabKeyboard(dpy, root, True, GrabModeAsync, GrabModeAsync, CurrentTime) != GrabSuccess) usleep(1000); - FD_ZERO(&rd); FD_SET(STDIN_FILENO, &rd); if(select(ConnectionNumber(dpy) + 1, &rd, NULL, NULL, &timeout) < 1) goto UninitializedEnd; maxname = readstdin(); - /* style */ dc.norm[ColBG] = getcolor(normbg); dc.norm[ColFG] = getcolor(normfg); dc.sel[ColBG] = getcolor(selbg); dc.sel[ColFG] = getcolor(selfg); setfont(font); - + /* menu window */ wa.override_redirect = 1; wa.background_pixmap = ParentRelative; wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask; - mx = my = 0; mw = DisplayWidth(dpy, screen); mh = dc.font.height + 2; - win = XCreateWindow(dpy, root, mx, my, mw, mh, 0, DefaultDepth(dpy, screen), CopyFromParent, DefaultVisual(dpy, screen), CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa); XDefineCursor(dpy, win, XCreateFontCursor(dpy, XC_xterm)); - /* pixmap */ dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen)); dc.gc = XCreateGC(dpy, root, 0, 0); XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter); - if(maxname) cmdw = textw(maxname); if(cmdw > mw / 3) cmdw = mw / 3; - text[0] = 0; match(text); XMapRaised(dpy, win);@@ -392,6 +371,7 @@ break;
} } + /* cleanup */ while(allitems) { itm = allitems->next; free(allitems->text);@@ -408,6 +388,5 @@ XDestroyWindow(dpy, win);
UninitializedEnd: XUngrabKeyboard(dpy, CurrentTime); XCloseDisplay(dpy); - return ret; }
M
util.c
→
util.c
@@ -1,5 +1,4 @@
-/* - * (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> +/* (C)opyright MMVI Anselm R. Garbe <garbeam at gmail dot com> * See LICENSE file for license details. */ #include "dmenu.h"@@ -22,6 +21,7 @@
void * emalloc(unsigned int size) { void *res = malloc(size); + if(!res) badmalloc(size); return res;@@ -40,6 +40,7 @@
char * estrdup(const char *str) { void *res = strdup(str); + if(!res) badmalloc(strlen(str)); return res;