summaryrefslogblamecommitdiff
path: root/main.c
blob: 1a9d483c68d35e9bf166813e683103f783d9d311 (plain) (tree)
























































































                                                                         
#include <unistd.h>

#include "menu.h"
#include "ui.h"
#include "config.h"
#include "util.h"

int main(int argc, char *argv[])
{
	int errflg, fd, rc;
	char c;

	State state = {
		.headerr         = headerr,
		.headverf        = headverf,
		.statstr         = statstr,
		.statverf        = statverf,
		.statfail        = statfail,
		.cmds[PASS].name = headpromt
	};

	errflg = 0;
	while ((c = getopt(argc, argv, "ip:e:v:s:r:l:c:u:d:w:")) != -1) {
		switch(c) {
		case 'i':
			state.flag |= IGNORE_ISIG;
			break;
		case 'p':
			state.cmds[PASS].name = optarg;
			break;
		case 'e':
			state.headerr = optarg;
			break;
		case 'v':
			state.headverf = optarg;
			break;
		case 's':
			state.statstr = optarg;
			break;
		case 'r':
			state.statverf = *optarg;
			break;
		case 'l':
			state.statfail = *optarg;
			break;
		case 'c':
			state.cmds[PASS].cmd = optarg;
			break;
		case 'u':
			state.cmds[UP].name = optarg;

			while (*optarg && *optarg != '=')
				optarg++;
			if (*optarg == '=')
				state.cmds[UP].cmd = optarg + 1;
			else
				errflg++;

			*optarg = '\0';
			break;
		case 'd':
			state.cmds[DOWN].name = optarg;

			while (*optarg && *optarg != '=')
				optarg++;
			if (*optarg == '=')
				state.cmds[DOWN].cmd = optarg + 1;
			else
				errflg++;

			*optarg = '\0';
			break;
		case 'w':
			state.floc = optarg;
			break;
		case '?':
			errflg++;
		}
	}

	if (errflg || !state.cmds[PASS].cmd)
		die("usage: tuil [-ipevsrl]");

	fd = uiinit(&state);
	rc = menuinit(&state, fd) - 1;
	uicleanup();
	
	return rc;
}