+ return XTextWidth(dc.font.xfont, text, len);
+}
+
+int
+textw(const char *text) {
+ return textnw(text, strlen(text)) + dc.font.height;
+}
+
+int
+main(int argc, char *argv[]) {
+ unsigned int i;
+ Bool topbar = True;
+
+ /* command line args */
+ for(i = 1; i < argc; i++)
+ if(!strcmp(argv[i], "-i")) {
+ fstrncmp = strncasecmp;
+ fstrstr = cistrstr;
+ }
+ else if(!strcmp(argv[i], "-b"))
+ topbar = False;
+ else if(!strcmp(argv[i], "-e")) {
+ if(++i < argc) parent = atoi(argv[i]);
+ }
+ else if(!strcmp(argv[i], "-l")) {
+ calcoffsets = calcoffsetsv;
+ if(++i < argc) lines = atoi(argv[i]);
+ }
+ else if(!strcmp(argv[i], "-fn")) {
+ if(++i < argc) font = argv[i];
+ }
+ else if(!strcmp(argv[i], "-nb")) {
+ if(++i < argc) normbgcolor = argv[i];
+ }
+ else if(!strcmp(argv[i], "-nf")) {
+ if(++i < argc) normfgcolor = argv[i];
+ }
+ else if(!strcmp(argv[i], "-p")) {
+ if(++i < argc) prompt = argv[i];
+ }
+ else if(!strcmp(argv[i], "-sb")) {
+ if(++i < argc) selbgcolor = argv[i];
+ }
+ else if(!strcmp(argv[i], "-sf")) {
+ if(++i < argc) selfgcolor = argv[i];
+ }
+ else if(!strcmp(argv[i], "-v"))
+ eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
+ else
+ eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
+ " [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
+ if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
+ fprintf(stderr, "warning: no locale support\n");
+ if(!(dpy = XOpenDisplay(NULL)))
+ eprint("dmenu: cannot open display\n");
+ screen = DefaultScreen(dpy);
+ if(!parent)
+ parent = RootWindow(dpy, screen);
+
+ readstdin();
+ running = grabkeyboard();
+
+ setup(topbar);
+ drawmenu();
+ XSync(dpy, False);
+ run();
+ cleanup();