-static void *
-emalloc(unsigned int size) {
- void *res = malloc(size);
-
- if(!res)
- eprint("fatal: could not malloc() %u bytes\n", size);
- return res;
-}
-
-static void
-eprint(const char *errstr, ...) {
- va_list ap;
-
- va_start(ap, errstr);
- vfprintf(stderr, errstr, ap);
- va_end(ap);
- exit(EXIT_FAILURE);
-}
-
-static char *
-estrdup(const char *str) {
- void *res = strdup(str);
-
- if(!res)
- eprint("fatal: could not malloc() %u bytes\n", strlen(str));
- return res;
-}
-
-
-static void
-drawtext(const char *text, unsigned long col[ColLast]) {
- int x, y, w, h;
- static char buf[256];
- unsigned int len, olen;
- 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;
- if(len < olen) {
- if(len > 1)
- buf[len - 1] = '.';
- if(len > 2)
- buf[len - 2] = '.';
- if(len > 3)
- buf[len - 3] = '.';
- }
- if(w > dc.w)
- return; /* too long */
- XSetForeground(dpy, dc.gc, col[ColFG]);
- if(dc.font.set)
- XmbDrawString(dpy, dc.drawable, dc.font.set, dc.gc, x, y, buf, len);
+/* variables */
+char *font = FONT;
+char *maxname = NULL;
+char *normbg = NORMBGCOLOR;
+char *normfg = NORMFGCOLOR;
+char *prompt = NULL;
+char *selbg = SELBGCOLOR;
+char *selfg = SELFGCOLOR;
+char text[4096];
+int screen;
+int ret = 0;
+unsigned int cmdw = 0;
+unsigned int mw, mh;
+unsigned int promptw = 0;
+unsigned int numlockmask = 0;
+Bool running = True;
+Display *dpy;
+DC dc = {0};
+Item *allitems = NULL; /* first of all items */
+Item *item = NULL; /* first of pattern matching items */
+Item *sel = NULL;
+Item *next = NULL;
+Item *prev = NULL;
+Item *curr = NULL;
+Window root, win;
+int (*fstrncmp)(const char *, const char *, size_t n) = strncmp;
+char *(*fstrstr)(const char *, const char *) = strstr;
+
+void
+appenditem(Item *i, Item **list, Item **last) {
+ if(!(*last))
+ *list = i;