changeset: 2061:b6a2dc0472c1
tag: tip
user: Kris Maglione <jg_AT_suckless.org>
date: Fri Apr 06 02:25:58 2007 -0400
summary: Use util.c (emalloc, estrdup) in wmii9menu.
diff -r dad3a8b2db01 -r b6a2dc0472c1 cmd/Makefile
--- a/cmd/Makefile Fri Apr 06 02:09:51 2007 -0400
+++ b/cmd/Makefile Fri Apr 06 02:25:58 2007 -0400
@@ -25,5 +25,5 @@ wmiir.O: ${OWMIIR}
${LINK} $@ ${STATIC} ${OWMIIR}
EXCFLAGS=${INCX11}
-wmii9menu.O: wmii9menu.o
- ${LINK} $@ $*.o ${LIBX11}
+wmii9menu.O: wmii9menu.o ${OFILES}
+ ${LINK} $@ $*.o ${OFILES} ${LIBX11}
diff -r dad3a8b2db01 -r b6a2dc0472c1 cmd/wmii9menu.c
--- a/cmd/wmii9menu.c Fri Apr 06 02:09:51 2007 -0400
+++ b/cmd/wmii9menu.c Fri Apr 06 02:25:58 2007 -0400
@@ -39,6 +39,7 @@
#include <stdlib.h>
#include <string.h>
#include <X11/Xutil.h>
+#include <util.h>
#define nil ((void*)0)
@@ -54,16 +55,12 @@ XFontStruct *font;
XFontStruct *font;
GC gc;
-unsigned long selbg;
-unsigned long selfg;
-unsigned long normbg;
-unsigned long normfg;
+unsigned long selfg, selbg;
+unsigned long normfg, normbg;
unsigned long border;
-char *sfgname = nil;
-char *sbgname = nil;
-char *nfgname = nil;
-char *nbgname = nil;
-char *brcname = nil;
+char *sfgname, *sbgname;
+char *nfgname, *nbgname;
+char *brcname;
/* for XSetWMProperties to use */
int g_argc;
@@ -96,21 +93,13 @@ char **commands;
char **commands;
int numitems;
-void usage(), run_menu();
+void usage();
+void run_menu();
void create_window();
-void redraw(), warpmouse();
+void redraw();
+void warpmouse();
void memory();
int args();
-
-/* memory --- print the out of memory message and die */
-
-void
-memory(s)
-char *s;
-{
- fprintf(stderr, "%s: couldn't allocate memory for %s\n", progname, s);
- exit(1);
-}
/* args --- go through the argument list, set options */
@@ -209,19 +198,16 @@ main(int argc, char **argv)
char *s = fbuf;
strtok(s, "\n");
if (s[0] == '-') {
- char *temp[3];
+ char *temp[2];
+
temp[0] = s;
- temp[1] = strchr(s, ' ');
- if (temp[1]) {
- *(temp[1]++) = '\0';
- s = malloc(strlen(temp[1]) + 1);
- if (s == nil)
- memory("temporary argument");
- strcpy(s, temp[1]);
+ s = strchr(s, ' ');
+ if (s) {
+ *s++ = '\0';
+ s = estrdup(s);
temp[1] = s;
}
- temp[2] = 0;
- args(temp[1] ? 2 : 1, temp);
+ args(s ? 2 : 1, temp);
continue;
}
if (s[0] == '#')
@@ -232,10 +218,9 @@ main(int argc, char **argv)
/* allocate space */
if (f_argc < nlabels + 1) {
int k;
- char **temp = malloc(sizeof(char *) * (f_argc + 5));
- if (temp == 0)
- memory("temporary item");
-
+ char **temp;
+
+ temp = emalloc(sizeof(char *) * (f_argc + 5));
for (k = 0; k < nlabels; k++)
temp[k] = f_argv[k];
@@ -243,18 +228,13 @@ main(int argc, char **argv)
f_argv = temp;
f_argc += 5;
}
- f_argv[nlabels] = malloc(strlen(s) + 1);
- if (f_argv[nlabels] == nil)
- memory("temporary text");
- strcpy(f_argv[nlabels], s);
+ f_argv[nlabels] = estrdup(s);
++nlabels;
}
}
- labels = (char **) malloc((numitems + nlabels) * sizeof(char *));
- commands = (char **) malloc((numitems + nlabels) * sizeof(char *));
- if (commands == nil || labels == nil)
- memory("command and label arrays");
+ labels = emalloc((numitems + nlabels) * sizeof(char *));
+ commands = emalloc((numitems + nlabels) * sizeof(char *));
for (j = 0; j < numitems; j++) {
labels[j] = argv[i + j];
@@ -422,12 +402,11 @@ run_menu()
break;
case MapNotify:
redraw(high, wide);
- if(XGrabPointer(dpy, menuwin, False, MouseMask,
- GrabModeAsync, GrabModeAsync,
- 0, None, CurrentTime
- ) != GrabSuccess) {
+ if(XGrabPointer(dpy, menuwin,
+ False, MouseMask,
+ GrabModeAsync, GrabModeAsync,
+ 0, None, CurrentTime) != GrabSuccess)
fprintf(stderr, "Failed to grab the mouse\n");
- }
break;
case Expose:
redraw(high, wide);
Received on Fri Apr 06 2007 - 08:28:53 UTC
This archive was generated by hypermail 2.2.0 : Sun Jul 13 2008 - 15:56:34 UTC