]> git.armaanb.net Git - dmenu.git/blobdiff - dmenu.c
minor update regarding locale support
[dmenu.git] / dmenu.c
diff --git a/dmenu.c b/dmenu.c
index 2afcc4873aab202743b0694b691235d73ac72000..afb5303cf420fb01623b8ac3123e4b80584326b4 100644 (file)
--- a/dmenu.c
+++ b/dmenu.c
@@ -1,4 +1,5 @@
 /* See LICENSE file for copyright and license details. */
+#define _BSD_SOURCE
 #include <ctype.h>
 #include <locale.h>
 #include <stdarg.h>
@@ -52,7 +53,6 @@ static char *cistrstr(const char *s, const char *sub);
 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);
@@ -252,15 +252,6 @@ drawtext(const char *text, ulong col[ColLast]) {
                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;
@@ -477,11 +468,11 @@ kpress(XKeyEvent * e) {
                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;
@@ -563,7 +554,8 @@ readstdin(void) {
                        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)
@@ -718,7 +710,8 @@ main(int argc, char *argv[]) {
                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);