Пример #1
0
/* See interface.h for function descriptions. */
int if_init(void)
{
    if (init_curses())
        return 1;

    hl_groups_instance = hl_groups_initialize();
    if (!hl_groups_instance)
        return 3;

    if (hl_groups_setup(hl_groups_instance) == -1)
        return 3;

    /* Set up the signal handler to catch SIGWINCH */
    if (set_up_signal() == -1)
        return 2;

    if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) {
        screen_size.ws_row = LINES;
        screen_size.ws_col = COLS;
    }

    /* Create the file dialog object */
    if ((fd = filedlg_new(0, 0, HEIGHT, WIDTH)) == NULL)
        return 5;

    /* Set up window layout */
    window_height_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0));
    switch (if_layout()) {
        case 2:
            return 4;
    }

    return 0;
}
Пример #2
0
/* See interface.h for function descriptions. */
int if_init(void)
{
    if (init_curses())
    {
        clog_error(CLOG_CGDB, "Unable to initialize the ncurses library");
        return -1;
    }

    hl_groups_instance = hl_groups_initialize();
    if (!hl_groups_instance)
    {
        clog_error(CLOG_CGDB, "Unable to setup highlighting groups");
        return -1;
    }

    if (hl_groups_setup(hl_groups_instance) == -1)
    {
        clog_error(CLOG_CGDB, "Unable to setup highlighting groups");
        return -1;
    }

    /* Set up the signal handler to catch SIGWINCH */
    if (set_up_signal() == -1)
    {
        clog_error(CLOG_CGDB, "Unable to handle signal: SIGWINCH");
        return -1;
    }

    if (ioctl(fileno(stdout), TIOCGWINSZ, &screen_size) == -1) {
        screen_size.ws_row = swin_lines();
        screen_size.ws_col = swin_cols();
    }

    /* Create the file dialog object */
    fd = filedlg_new(0, 0, HEIGHT, WIDTH);

    /* Set up window layout */
    window_shift = (int) ((HEIGHT / 2) * (cur_win_split / 2.0));
    switch (if_layout()) {
        case 2:
            return 4;
    }

    G_line_number = ibuf_init();

    return 0;
}
Пример #3
0
int gtkspell_start(char *path, char * args[]) {
	int fd_error[2];
	char buf[BUFSIZE];

	if (gtkspell_running()) {
		error_print("gtkspell_start called while already running.\n");
		gtkspell_stop();
	}

	if (!signal_set_up) {
		set_up_signal();
		signal_set_up = 1;
	}

	pipe(fd_write);
	pipe(fd_read);
	pipe(fd_error);

	spell_pid = fork();
	if (spell_pid < 0) {
		error_print("fork: %s\n", strerror(errno));
		return -1;
	} else if (spell_pid == 0) {
		dup2(fd_write[0], 0);
		close(fd_write[0]);
		close(fd_write[1]);

		dup2(fd_read[1], 1);
		close(fd_read[0]);
		close(fd_read[1]);

		dup2(fd_error[1], 2);
		close(fd_error[0]);
		close(fd_error[1]);

		if (path == NULL) {
			if (execvp(args[0], args) < 0) 
				error_print("execvp('%s'): %s\n", args[0], strerror(errno));
		} else {
			if (execv(path, args) < 0) 
				error_print("execv('%s'): %s\n", path, strerror(errno));
		}
		/* if we get here, we failed.
		 * send some text on the pipe to indicate status.
		 */
		write(0, "!", 1); /* stdout _is_ the pipe. */

		_exit(0);
	} else {
		/* there are at least two ways to fail:
		 * - the exec() can fail
		 * - the exec() can succeed, but the program can dump the help screen
		 * we must check for both.
		 */
		fd_set rfds;
		struct timeval tv;
		
		close(fd_write[0]);
		close(fd_read[1]);

		FD_ZERO(&rfds);
		FD_SET(fd_error[0], &rfds);
		FD_SET(fd_read[0], &rfds);
		tv.tv_sec = 2;
		tv.tv_usec = 0;

		if (select(MAX(fd_error[0], fd_read[0])+1, 
					&rfds, NULL, NULL, &tv) < 0) {
			/* FIXME: is this needed? */
			error_print("Timed out waiting for spell command.\n");
			gtkspell_stop();
			return -1;
		}

		if (FD_ISSET(fd_error[0], &rfds)) { /* stderr readable? */
			error_print("Spell command printed on stderr -- probably failed.\n");
			gtkspell_stop();
			return -1;
		}

		/* we're done with stderr, now. */
		close(fd_error[0]);
		close(fd_error[1]);

		/* otherwise, fd_read[0] is set. */
		readline(buf);

		/* ispell should print something like this:
		 * @(#) International Ispell Version 3.1.20 10/10/95
		 * if it doesn't, it's an error. */
		if (buf[0] != '@') {
			gtkspell_stop();
			return -1;
		}
	}

	/* put ispell into terse mode.  
	 * this makes it not respond on correctly spelled words. */
	sprintf(buf, "!\n");
	writetext(buf);
	return 0;
}
Пример #4
0
int main(int argc, char **argv)
{

    int gdb_fd, child_fd, slavefd, masterfd;

#if 0
    int c;

    read(0, &c, 1);
#endif

    if (tty_cbreak(STDIN_FILENO, &term_attributes) == -1)
        logger_write_pos(logger, __FILE__, __LINE__, "tty_cbreak error");

    pty_pair = pty_pair_create();
    if (!pty_pair) {
        fprintf(stderr, "%s:%d Unable to create PTY pair", __FILE__, __LINE__);
        exit(-1);
    }

    slavefd = pty_pair_get_slavefd(pty_pair);
    if (slavefd == -1) {
        fprintf(stderr, "%s:%d Unable to get slavefd", __FILE__, __LINE__);
        exit(-1);
    }

    masterfd = pty_pair_get_masterfd(pty_pair);
    if (masterfd == -1) {
        fprintf(stderr, "%s:%d Unable to get masterfd", __FILE__, __LINE__);
        exit(-1);
    }

    if (tty_off_xon_xoff(masterfd) == -1)
        exit(-1);

    rline = rline_initialize(slavefd, rlctx_send_user_command, tab_completion,
                             getenv("TERM"));

    if ((tgdb = tgdb_initialize(NULL, argc - 1, argv + 1, &gdb_fd,
                                &child_fd)) == NULL) {
        logger_write_pos(logger, __FILE__, __LINE__, "tgdb_start error");
        goto driver_end;
    }

    if (tgdb_set_verbose_error_handling(tgdb, 1) != 1) {
        logger_write_pos(logger, __FILE__, __LINE__, "driver error");
        goto driver_end;
    }

    /* Ask TGDB to print error messages */
    if (tgdb_set_verbose_gui_command_output(tgdb, 1) != 1) {
        logger_write_pos(logger, __FILE__, __LINE__, "driver error");
        goto driver_end;
    }

    set_up_signal();

    main_loop(gdb_fd, child_fd);

    if (tgdb_shutdown(tgdb) == -1)
        logger_write_pos(logger, __FILE__, __LINE__, "could not shutdown");

driver_end:

    if (tty_set_attributes(STDIN_FILENO, &term_attributes) == -1)
        logger_write_pos(logger, __FILE__, __LINE__, "tty_reset error");

    return 0;
}