-void
-run(void) {
-       XEvent ev;
-
-       /* main event loop */
-       while(running && !XNextEvent(dpy, &ev))
-               switch (ev.type) {
-               default:        /* ignore all crap */
-                       break;
-               case KeyPress:
-                       kpress(&ev.xkey);
-                       break;
-               case Expose:
-                       if(ev.xexpose.count == 0)
-                               drawmenu();
-                       break;
-               }
-}
-
-void
-setup(int x, int y, int w) {
-       unsigned int i, j;
-       XModifierKeymap *modmap;
-       XSetWindowAttributes wa;
-
-       /* init modifier map */
-       modmap = XGetModifierMapping(dpy);
-       for(i = 0; i < 8; i++)
-               for(j = 0; j < modmap->max_keypermod; j++) {
-                       if(modmap->modifiermap[i * modmap->max_keypermod + j]
-                       == XKeysymToKeycode(dpy, XK_Num_Lock))
-                               numlockmask = (1 << i);
-               }
-       XFreeModifiermap(modmap);
-
-       /* style */
-       dc.norm[ColBG] = getcolor(normbg);
-       dc.norm[ColFG] = getcolor(normfg);
-       dc.sel[ColBG] = getcolor(selbg);
-       dc.sel[ColFG] = getcolor(selfg);
-       initfont(font);
-
-       /* menu window */
-       wa.override_redirect = 1;
-       wa.background_pixmap = ParentRelative;
-       wa.event_mask = ExposureMask | ButtonPressMask | KeyPressMask;
-       mw = w ? w : DisplayWidth(dpy, screen);
-       mh = dc.font.height + 2;
-       win = XCreateWindow(dpy, root, x, y, mw, mh, 0,
-                       DefaultDepth(dpy, screen), CopyFromParent,
-                       DefaultVisual(dpy, screen),
-                       CWOverrideRedirect | CWBackPixmap | CWEventMask, &wa);
-
-       /* pixmap */
-       dc.drawable = XCreatePixmap(dpy, root, mw, mh, DefaultDepth(dpy, screen));
-       dc.gc = XCreateGC(dpy, root, 0, 0);
-       XSetLineAttributes(dpy, dc.gc, 1, LineSolid, CapButt, JoinMiter);
-       if(!dc.font.set)
-               XSetFont(dpy, dc.gc, dc.font.xfont->fid);
-       if(maxname)
-               cmdw = textw(maxname);
-       if(cmdw > mw / 3)
-               cmdw = mw / 3;
-       if(prompt)
-               promptw = textw(prompt);
-       if(promptw > mw / 5)
-               promptw = mw / 5;
-       text[0] = 0;
-       match(text);
-       XMapRaised(dpy, win);
-}
-
-char *
-cistrstr(const char *s, const char *sub) {
-       int c, csub;
-       unsigned int len;
-
-       if(!sub)
-               return (char *)s;
-       if((c = *sub++) != 0) {
-               c = tolower(c);
-               len = strlen(sub);
-               do {
-                       do {
-                               if((csub = *s++) == 0)
-                                       return (NULL);
-                       }
-                       while(tolower(csub) != c);
-               }
-               while(strncasecmp(s, sub, len) != 0);
-               s--;
-       }
-       return (char *)s;
-}
-
-unsigned int
-textnw(const char *text, unsigned int len) {
-       XRectangle r;
-
-       if(dc.font.set) {
-               XmbTextExtents(dc.font.set, text, len, NULL, &r);
-               return r.width;
-       }
-       return XTextWidth(dc.font.xfont, text, len);
-}
-
-unsigned int
-textw(const char *text) {
-       return textnw(text, strlen(text)) + dc.font.height;
-}
-