/* See LICENSE file for copyright and license details. */
+#define _BSD_SOURCE
#include <ctype.h>
#include <locale.h>
#include <stdarg.h>
static void cleanup(void);
static void drawmenu(void);
static void drawtext(const char *text, ulong col[ColLast]);
-static void *emalloc(uint size);
static void eprint(const char *errstr, ...);
static ulong getcolor(const char *colstr);
static Bool grabkeyboard(void);
XDrawString(dpy, dc.drawable, dc.gc, x, y, buf, len);
}
-void *
-emalloc(uint size) {
- void *res = malloc(size);
-
- if(!res)
- eprint("fatal: could not malloc() %u bytes\n", size);
- return res;
-}
-
void
eprint(const char *errstr, ...) {
va_list ap;
calcoffsets();
break;
case XK_Return:
- if((e->state & ShiftMask) && text)
+ if((e->state & ShiftMask) && *text)
fprintf(stdout, "%s", text);
else if(sel)
fprintf(stdout, "%s", sel->text);
- else if(text)
+ else if(*text)
fprintf(stdout, "%s", text);
fflush(stdout);
running = False;
maxname = p;
max = len;
}
- new = emalloc(sizeof(Item));
+ if((new = (Item *)malloc(sizeof(Item))) == NULL)
+ eprint("fatal: could not malloc() %u bytes\n", sizeof(Item));
new->next = new->left = new->right = NULL;
new->text = p;
if(!i)
else
eprint("usage: dmenu [-i] [-b] [-fn <font>] [-nb <color>] [-nf <color>]\n"
" [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
- setlocale(LC_CTYPE, "");
+ if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ fprintf(stderr, "warning: no locale support\n");
if(!(dpy = XOpenDisplay(0)))
eprint("dmenu: cannot open display\n");
screen = DefaultScreen(dpy);