Beispiel #1
0
fa_signal_t fa_signal_copy(fa_signal_t signal)
{
    switch (signal->tag) {
    case time_signal:
        return fa_signal_time();

    case random_signal:
        return fa_signal_random();

    case constant_signal:
        return copy_constant(signal);

    case lift_signal:
        return copy_lift(signal);

    case lift2_signal:
        return copy_lift2(signal);

    case loop_signal:
        return copy_loop(signal);

    case delay_signal:
        return copy_delay(signal);

    case insert_signal:
        return copy_insert(signal);

    case custom_signal:
        return copy_custom(signal);

    case input_signal:
        return copy_input(signal);

    case output_signal:
        return copy_output(signal);

    default:
        assert(false);
    }
}
Beispiel #2
0
int main(int argc, char* argv[])
{
	int fdm, c, ignoreeof, interactive, noecho, verbose;
	pid_t pid;
	char* config;
	char slave_name[20];
	struct termios orig_termios;
	struct winsize size;
	int flags;

	interactive = isatty(STDIN_FILENO);
	ignoreeof = 0;
	noecho = 0;
	verbose = 0;
	config = NULL;

	while ((c = getopt_long(argc, argv, "hVs:einv", long_options, NULL))
	       != EOF) {
		switch (c) {
		case 'h':
			printf("Usage: %s [options] config_file -- program [args ...]\n", argv[0]);
			printf("\t -h --help \t\tdisplay usage summary\n");
			printf("\t -V --version \t\tdisplay version\n");
			printf("\t -e --no-echo \t\tdisable echo\n");
			printf("\t -i --ignore-eof \tignore EOF\n");
			printf("\t -n --non-interactive \tforce non-interactive mode\n");
			printf("\t -v --verbose \t\tverbose mode\n");
			return EXIT_SUCCESS;
		case 'V':
			printf("irpty %s\n", VERSION);
			return EXIT_SUCCESS;

		case 'e':
			noecho = 1;
			break;

		case 'i':
			ignoreeof = 1;
			break;

		case 'n':
			interactive = 0;
			break;

		case 'v':
			verbose = 1;
			break;

		case '?':
			die("unrecognized option: -%c\n", optopt);
		}
	}
	if (optind + 1 >= argc)
		die("usage: irpty [ -s server -einv ] cfg program [ arg ... ]\n");

	config = argv[optind++];

	if ((lsock = lirc_init("irpty", 1)) == -1)
		exit(EXIT_FAILURE);
	flags = fcntl(lsock, F_GETFL, 0);
	if (flags != -1)
		fcntl(lsock, F_SETFL, flags | FASYNC | O_NONBLOCK);

	if (lirc_readconfig(config, &lconfig, NULL) != 0)
		exit(EXIT_FAILURE);

	if (interactive) {
		if (tcgetattr(STDIN_FILENO, &orig_termios) < 0)
			die("tcgetattr error on stdin\n");
		if (ioctl(STDIN_FILENO, TIOCGWINSZ, (char*)&size) < 0)
			die("TIOCGWINSZ error\n");
		pid = pty_fork(&fdm, slave_name, &orig_termios, &size);
	} else {
		pid = pty_fork(&fdm, slave_name, NULL, NULL);
	}

	if (pid < 0) {
		die("fork error\n");
	} else if (!pid) {                              /* child */
		if (noecho)
			set_noecho(STDIN_FILENO);       /* stdin is slave pty */
		if (execvp(argv[optind], &argv[optind]) < 0)
			die("can't execute: %s\n", argv[optind]);
	}
	if (verbose) {
		fprintf(stderr, "slave name = %s\n", slave_name);
		if (config)
			fprintf(stderr, "config file = %s\n", config);
	}
	if (interactive) {
		if (tty_raw(STDIN_FILENO) < 0)  /* user's tty to raw mode */
			die("tty_raw error");
		if (atexit(tty_atexit) < 0)     /* reset user's tty on exit */
			die("atexit error");
	}
	copy_loop(fdm, ignoreeof);

	exit(0);
}