dinput with dmenu flags, fixed usage & -v, cosmetics 340b176d
Connor Lane Smith · 2010-06-29 16:07 2 file(s) · +32 −14
dinput.c +16 −8
76 76
	/* print prompt? */
77 77
	if(prompt) {
78 78
		dc.w = promptw;
79 -
		drawtext(&dc, prompt, selcol, False);
79 +
		drawtext(&dc, prompt, normcol, False);
80 80
		dc.x += dc.w;
81 81
	}
82 82
	dc.w = mw - dc.x;
83 -
	drawtext(&dc, *text ? text : NULL, normcol, False);
83 +
	drawtext(&dc, *text ? text : NULL, selcol, False);
84 84
	drawcursor();
85 85
	XCopyArea(dpy, dc.drawable, win, dc.gc, 0, 0, mw, mh, 0, 0);
86 86
	XFlush(dpy);
329 329
	/* command line args */
330 330
	progname = argv[0];
331 331
	for(i = 1; i < argc; i++)
332 -
		if(!strcmp(argv[i], "-b"))
332 +
		if(!strcmp(argv[i], "-i"))
333 +
			;  /* ignore flag */
334 +
		else if(!strcmp(argv[i], "-b"))
333 335
			topbar = False;
334 336
		else if(!strcmp(argv[i], "-e")) {
335 337
			if(++i < argc) parent = atoi(argv[i]);
336 338
		}
339 +
		else if(!strcmp(argv[i], "-l"))
340 +
			i++;  /* ignore flag */
337 341
		else if(!strcmp(argv[i], "-fn")) {
338 342
			if(++i < argc) font = argv[i];
339 343
		}
352 356
		else if(!strcmp(argv[i], "-sf")) {
353 357
			if(++i < argc) selfgcolor = argv[i];
354 358
		}
355 -
		else if(!strcmp(argv[i], "-v"))
356 -
			eprint("dinput-"VERSION", © 2006-2010 dinput engineers, see LICENSE for details\n");
359 +
		else if(!strcmp(argv[i], "-v")) {
360 +
			printf("dinput-"VERSION", © 2006-2010 dinput engineers, see LICENSE for details\n");
361 +
			exit(EXIT_SUCCESS);
362 +
		}
357 363
		else if(!*text)
358 364
			strncpy(text, argv[i], sizeof text);
359 -
		else
360 -
			eprint("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
361 -
			       "              [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n");
365 +
		else {
366 +
			fputs("usage: dinput [-b] [-e <xid>] [-fn <font>] [-nb <color>] [-nf <color>]\n"
367 +
			      "              [-p <prompt>] [-sb <color>] [-sf <color>] [-v] [<text>]\n", stderr);
368 +
			exit(EXIT_FAILURE);
369 +
		}
362 370
	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
363 371
		fprintf(stderr, "dinput: warning: no locale support\n");
364 372
	if(!(dpy = XOpenDisplay(NULL)))
dmenu.c +16 −6
49 49
#include "draw.h"
50 50
51 51
/* variables */
52 +
static char **argp = NULL;
52 53
static char *maxname = NULL;
53 54
static char *prompt = NULL;
54 55
static char text[4096];
151 152
void
152 153
dinput(void) {
153 154
	cleanup();
154 -
	execlp("dinput", "dinput", text, NULL); /* todo: argv */
155 +
	argp[0] = "dinput";
156 +
	argp[1] = text;
157 +
	execvp("dinput", argp);
155 158
	eprint("cannot exec dinput\n");
156 159
}
157 160
587 590
		else if(!strcmp(argv[i], "-sf")) {
588 591
			if(++i < argc) selfgcolor = argv[i];
589 592
		}
590 -
		else if(!strcmp(argv[i], "-v"))
591 -
			eprint("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
592 -
		else
593 -
			eprint("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
594 -
			       "             [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n");
593 +
		else if(!strcmp(argv[i], "-v")) {
594 +
			printf("dmenu-"VERSION", © 2006-2010 dmenu engineers, see LICENSE for details\n");
595 +
			exit(EXIT_SUCCESS);
596 +
		}
597 +
		else {
598 +
			fputs("usage: dmenu [-i] [-b] [-e <xid>] [-l <lines>] [-fn <font>] [-nb <color>]\n"
599 +
			       "             [-nf <color>] [-p <prompt>] [-sb <color>] [-sf <color>] [-v]\n", stderr);
600 +
			exit(EXIT_FAILURE);
601 +
		}
595 602
	if(!setlocale(LC_CTYPE, "") || !XSupportsLocale())
596 603
		fprintf(stderr, "dmenu: warning: no locale support\n");
597 604
	if(!(dpy = XOpenDisplay(NULL)))
599 606
	screen = DefaultScreen(dpy);
600 607
	if(!parent)
601 608
		parent = RootWindow(dpy, screen);
609 +
	if(!(argp = malloc(sizeof *argp * (argc+2))))
610 +
		eprint("cannot malloc %u bytes\n", sizeof *argp * (argc+2));
611 +
	memcpy(argp + 2, argv + 1, sizeof *argp * argc);
602 612
603 613
	readstdin();
604 614
	running = grabkeyboard();