signal(SIGKILL, cleanup);
main(int argc, char **argv){	int opt;	int i;	while ((opt = (getopt(argc,argv,"3DPRb:cdfhi:m:st:I:F:r:M:S:C:p:w:z:"))) != -1) {		switch (opt) {			case '3':				mouse.flags |= Emulate3Button;				break;			case 'D':				mouse.flags |= ClearDTR;				break;			case 'P':				mouse.flags |= NoPnP;				break;			case 'R':				mouse.flags |= ClearRTS;				break;			case 'b':				mouse.hw.buttons = atoi(optarg);				break;			case 'c':				mouse.flags |= ChordMiddle;							break;			case 'd':				++debug;				break;			case 'f':				nodaemon = TRUE;				break;			case 'M':				if (!mouse_installmap(optarg)) {					warnx("invalid mapping `%s'\n", optarg);					usage();				}				break;			case 's':				mouse.baudrate = 9600;				break;				case 't':				if (strcmp(optarg, "auto") == 0) {					mouse.proto = P_UNKNOWN;					mouse.flags &= ~NoPnP;					break;				}				for (i = 0; mouse_names[i]; i++)					if (strcmp(optarg,mouse_names[i]) == 0){						mouse.proto = i;						mouse.flags |= NoPnP;						break;					}				if (mouse_names[i])					break;				printf("no such mouse protocol `%s'\n", optarg);				usage();				break;			case 'm':				for (i = 0 ; mouse_models[i].name; i++)					if (strcmp(optarg,mouse_models[i].name) == 0){						mouse.hw.model =							mouse_models[i].val;						break;					}				if (mouse_models[i].name)					break;				printf("no such mouse type `%s'\n", optarg);				usage();				break;			case 'i':				if (strcmp(optarg, "all") == 0)					identify = ID_ALL;				else if (strcmp(optarg, "port") == 0)					identify = ID_PORT;				else if (strcmp(optarg, "if") == 0)					identify = ID_IF;				else if (strcmp(optarg, "type") == 0)					identify = ID_TYPE;				else if (strcmp(optarg, "model") == 0)					identify = ID_MODEL;				else {					printf("invalid argument `%s'", optarg);					usage();				}				break;			case 'I':				pidfile = optarg;				break;			case 'F':				mouse.rate = atoi(optarg);				if (mouse.rate <= 0) {					printf("invalid rate `%s'\n", optarg);					usage();				}				break;			case 'r':				if (strcmp(optarg, "high") == 0)					mouse.resolution = MOUSE_RES_HIGH;				else if (strcmp(optarg, "medium-high") == 0)					mouse.resolution = MOUSE_RES_MEDIUMHIGH;				else if (strcmp(optarg, "medium-low") == 0)					mouse.resolution = MOUSE_RES_MEDIUMLOW;				else if (strcmp(optarg, "low") == 0)					mouse.resolution = MOUSE_RES_LOW;				else if (strcmp(optarg, "default") == 0)					mouse.resolution = MOUSE_RES_DEFAULT;				else {					mouse.resolution = atoi(optarg);					if (mouse.resolution <= 0) {						printf("invalid resolution `%s'\n", optarg);						usage();					}				}				break;			case 'S':				mouse.baudrate = atoi(optarg);				if (mouse.baudrate <= 0) {					printf("invalid baudrate `%s'\n", optarg);					usage();				}				break;			case 'C':#define MAX_CLICKTHRESHOLD 2000 /* max delay for double click */								mouse.clickthreshold = atoi(optarg);				if ((mouse.clickthreshold < 0) || 				(mouse.clickthreshold > MAX_CLICKTHRESHOLD)) {					printf("invalid threshold `%s': max value is %d\n"						, optarg,MAX_CLICKTHRESHOLD);					usage();				}				break;			case 'p':				mouse.portname = strdup(optarg);				break;			case 'h':				usage();				break;			case 'w':				i = atoi(optarg);				if ((i <= 0) || (i > MOUSE_MAXBUTTON)) {					warnx("invalid argument `%s'", optarg);					usage();				}				mouse.wmode = 1 << (i - 1);				break;			case 'z':				if (strcmp(optarg, "x") == 0)					mouse.zmap = MOUSE_XAXIS;				else if (strcmp(optarg, "y") == 0)					mouse.zmap = MOUSE_YAXIS;				else {					i = atoi(optarg);				/* 				 * Use button i for negative Z axis movement 				 * and button (i + 1) for positive Z axis 				 * movement.			         */					if ((i <= 0) || 					(i > MOUSE_MAXBUTTON - 1)) {						warnx("invalid argument `%s'", 								optarg);						usage();					}					mouse.zmap = 1 << (i - 1);				}				break;			default:				usage();		}	}	/* 	 * mouse device name : 	 * Logitech bus mouse : /dev/lms0	 * Microsoft bus mouse (also refered as inport) : /dev/mms0 	 * PS/2 mouse : /dev/pms0 	 *	 * Note that Logitech and Microsoft bus mouse speak the same	 * protocol (BusMouse).	 */	switch(mouse.proto) {		case P_INPORT:			/* Inport and Bus use the same protocol (BusMouse) */			mouse.proto = P_BM;			mouse.portname = MMS_DEV;			break;		case P_BM:			if (!mouse.portname)				mouse.portname = LMS_DEV;			break;		case P_PS2:			if (!mouse.portname)				mouse.portname = PMS_DEV;			break;		default:			if (mouse.portname) /* serial mouse */				break;			printf("no port name specified\n");			usage();	}		for (;;) {		if (sigsetjmp(env, 1) == 0) {			signal(SIGUSR1, freedev);			signal(SIGUSR2, opendev);			signal(SIGINT , cleanup);			signal(SIGQUIT, cleanup);			signal(SIGTERM, cleanup);			signal(SIGKILL, cleanup);			if ((mouse.mfd = open(mouse.portname, 			    O_RDWR | O_NONBLOCK, 0)) == -1) 				logerr(1, "unable to open %s", mouse.portname);			if (mouse_identify() == P_UNKNOWN) {				logwarn("cannot determine mouse type on %s",				    mouse.portname);				close(mouse.mfd);				mouse.mfd = -1;			}			/* print some information */			if (identify != ID_NONE) {				if (identify == ID_ALL)					printf("%s %s %s %s\n", 					    mouse.portname,					    mouse_if(mouse.hw.iftype),					    mouse_name(mouse.proto), 					    mouse_model(mouse.hw.model));				else if (identify & ID_PORT)					printf("%s\n", mouse.portname);				else if (identify & ID_IF)					printf("%s\n", mouse_if(mouse.hw.iftype));				else if (identify & ID_TYPE)					printf("%s\n", mouse_name(mouse.proto));				else if (identify & ID_MODEL)					printf("%s\n", mouse_model(mouse.hw.model));				exit(0);			} else {				debug("port: %s  interface: %s  type: %s  model: %s", 				mouse.portname, mouse_if(mouse.hw.iftype),				mouse_name(mouse.proto), mouse_model(mouse.hw.model));			}			if (mouse.mfd == -1) {			/*		         * We cannot continue because of error.  Exit if the 		         * program has not become a daemon.  Otherwise, block 		         * until the the user corrects the problem and issues 			 * SIGHUP. 			 */				if (!background)					exit(1);				sigpause(0);			}			mouse_init(); /* init mouse */			moused();	}		if (mouse.mfd != -1)			close(mouse.mfd);	}	/* NOT REACHED */	exit(0);	return (0);}