[hackers] [dmenu] portability || Connor Lane Smith

From: <hg_AT_suckless.org>
Date: Sun, 15 May 2011 22:54:30 +0200 (CEST)

changeset: 407:a740b7c3fe2f
tag: tip
user: Connor Lane Smith <cls_AT_lubutu.com>
date: Sun May 15 21:54:26 2011 +0100
files: config.mk dmenu.c draw.c
description:
portability

diff -r 1ce845e311df -r a740b7c3fe2f config.mk
--- a/config.mk Sun May 15 16:05:32 2011 +0100
+++ b/config.mk Sun May 15 21:54:26 2011 +0100
@@ -18,7 +18,7 @@
 
 # flags
 CPPFLAGS = -D_BSD_SOURCE -DVERSION=\"${VERSION}\" ${XINERAMAFLAGS}
-CFLAGS = -std=c99 -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
+CFLAGS = -ansi -pedantic -Wall -Os ${INCS} ${CPPFLAGS}
 LDFLAGS = -s ${LIBS}
 
 # compiler and linker
diff -r 1ce845e311df -r a740b7c3fe2f dmenu.c
--- a/dmenu.c Sun May 15 16:05:32 2011 +0100
+++ b/dmenu.c Sun May 15 21:54:26 2011 +0100
@@ -3,6 +3,7 @@
 #include <stdio.h>
 #include <stdlib.h>
 #include <string.h>
+#include <strings.h>
 #include <unistd.h>
 #include <X11/Xlib.h>
 #include <X11/Xatom.h>
@@ -231,13 +232,14 @@
 void
 keypress(XKeyEvent *ev) {
         char buf[32];
- size_t len;
         KeySym ksym;
 
- len = strlen(text);
         XLookupString(ev, buf, sizeof buf, &ksym, NULL);
- if(ev->state & ControlMask)
- switch(tolower(ksym)) {
+ if(ev->state & ControlMask) {
+ KeySym lower, upper;
+
+ XConvertCase(ksym, &lower, &upper);
+ switch(lower) {
                 default:
                         return;
                 case XK_a:
@@ -290,13 +292,14 @@
                         XConvertSelection(dc->dpy, XA_PRIMARY, utf8, utf8, win, CurrentTime);
                         return;
                 }
+ }
         switch(ksym) {
         default:
                 if(!iscntrl(*buf))
                         insert(buf, strlen(buf));
                 break;
         case XK_Delete:
- if(cursor == len)
+ if(text[cursor] == '\0')
                         return;
                 cursor = nextrune(+1);
         case XK_BackSpace:
@@ -304,8 +307,8 @@
                         insert(NULL, nextrune(-1) - cursor);
                 break;
         case XK_End:
- if(cursor < len) {
- cursor = len;
+ if(text[cursor] != '\0') {
+ cursor = strlen(text);
                         break;
                 }
                 if(next) {
@@ -358,7 +361,7 @@
                 fputs((sel && !(ev->state & ShiftMask)) ? sel->text : text, stdout);
                 exit(EXIT_SUCCESS);
         case XK_Right:
- if(cursor < len) {
+ if(text[cursor] != '\0') {
                         cursor = nextrune(+1);
                         break;
                 }
@@ -385,7 +388,7 @@
 match(Bool sub) {
         size_t len = strlen(text);
         Item *lexact, *lprefix, *lsubstr, *exactend, *prefixend, *substrend;
- Item *item, *next = NULL;
+ Item *item, *next;
 
         lexact = lprefix = lsubstr = exactend = prefixend = substrend = NULL;
         for(item = sub ? matches : items; item && item->text; item = next) {
diff -r 1ce845e311df -r a740b7c3fe2f draw.c
--- a/draw.c Sun May 15 16:05:32 2011 +0100
+++ b/draw.c Sun May 15 21:54:26 2011 +0100
@@ -15,12 +15,13 @@
 
 void
 drawrect(DC *dc, int x, int y, unsigned int w, unsigned int h, Bool fill, unsigned long color) {
- XRectangle r = { dc->x + x, dc->y + y, w, h };
+ XRectangle r;
 
- if(!fill) {
- r.width -= 1;
- r.height -= 1;
- }
+ r.x = dc->x + x;
+ r.y = dc->y + y;
+ r.width = fill ? w : w-1;
+ r.height = fill ? h : h-1;
+
         XSetForeground(dc->dpy, dc->gc, color);
         (fill ? XFillRectangles : XDrawRectangles)(dc->dpy, dc->canvas, dc->gc, &r, 1);
 }
Received on Sun May 15 2011 - 22:54:30 CEST

This archive was generated by hypermail 2.2.0 : Sun May 15 2011 - 23:00:10 CEST