예제 #1
0
void rl_history(FILE* input,char* cmd)
{
#ifdef READLINE
    if (tty_input(input)) {
        add_history(cmd);
    }
#endif            
    return;
}
예제 #2
0
파일: keybd.c 프로젝트: astrotycoon/fleurix
/*
 * Each keyboard interrupt came along with a 8bit scan code (via inb(KB_DATA)), if bit 8 is 
 * set, it's releasing a key, else pressing. 
 * */
int do_keybd_intr(struct trap *tf){
    uchar sc, ch, m;
    uchar *map = keybd_map;

    // got no data
    if ((inb(KB_STAT) & KB_STAT_DIB)==0){
        return -1;
    }
    sc = inb(KB_DATA);

    // ignore capslock yet.
    if ((sc & 0x7f) == 0x3A) 
        return 0;

    // check E0ESC
    if (sc == 0xE0) 
        mode |= E0ESC;

    // check shift, ctrl and alt
    if ((m = shift(sc))) {
        if (sc & 0x80) 
            mode &= ~m;
        else 
            mode |= m;
        return 0;
    }
    map = (mode & SHIFT)? shift_map: keybd_map;
    ch = map[sc & 0x7f];

    if (mode & CTRL) {
        switch(ch){
        case 'c': ch = CINTR; 
        case 'd': ch = CEOF;
        case 'x': ch = CKILL;
        case 'q': ch = CSTART;
        case 's': ch = CSTOP;
        case 'z': ch = CSUSP;
        case '\\': ch = CQUIT;
        }
    }

    // on pressed 
    if ((sc & 0x80)==0 && ch!='\0') {
        tty_input(&tty[0], ch);
    }
    // on released
    else {
        mode &= ~E0ESC;
    }

    return 0;
}
예제 #3
0
int
fgetc (int desc)
{

  if (desc == (int) stdin)
    return tty_input ();

  if (desc != sourcedesc)
    {
      errno = EBADF;
      return -1;
    }

  if (sourceleft-- <= 0)
    return EOF;
  return *sourceptr++;
}
예제 #4
0
파일: serial.c 프로젝트: AndrewD/prex
/*
 * Interrupt service routine
 */
static int
serial_isr(int irq)
{

	switch (inb(COM_IIR) & IIR_MASK) {
	case IIR_MSR:		/* Modem status change */
		break;
	case IIR_LSR:		/* Line status change */
		inb(COM_LSR);
		break;
	case IIR_TXB:		/* Transmitter holding register empty */
		tty_done(&serial_tty);
		break;
	case IIR_RXB:		/* Received data available */
		inb(COM_LSR);
		tty_input(inb(COM_RBR), &serial_tty);
		break;
	}
	return 0;
}
예제 #5
0
int internal_if_input(int key)
{
    int regex_icase = cgdbrc_get(CGDBRC_IGNORECASE)->variant.int_val;

    /* Normally, CGDB_KEY_ESC, but can be configured by the user */
    int cgdb_mode_key = cgdbrc_get(CGDBRC_CGDB_MODE_KEY)->variant.int_val;

    /* The cgdb mode key, puts the debugger into command mode */
    if (focus != CGDB && key == cgdb_mode_key) {
        /* Depending on which cgdb was in, it can free some memory here that
         * it was previously using. */
        if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_NORMAL) {
            ibuf_free(cur_sbc);
            cur_sbc = NULL;
        } else if (focus == CGDB_STATUS_BAR && sbc_kind == SBC_REGEX) {
            ibuf_free(regex_cur);
            regex_cur = NULL;
            free(src_win->cur->buf.cur_line);
            src_win->cur->buf.cur_line = NULL;
            src_win->cur->sel_rline = orig_line_regex;
            src_win->cur->sel_line = orig_line_regex;
        }
        if_set_focus(CGDB);
        return 0;
    }
    /* If you are already in cgdb mode, the cgdb mode key does nothing */
    else if (key == cgdb_mode_key)
        return 0;

    /* Check for global keystrokes */
    switch (focus) {
        case CGDB:
            switch (key) {
                case 'i':
                    if_set_focus(GDB);
                    return 0;
                case 'I':
                    if_set_focus(TTY);
                    return 0;
                case ':':
                    /* Set the type of the command the user is typing in the status bar */
                    sbc_kind = SBC_NORMAL;
                    if_set_focus(CGDB_STATUS_BAR);
                    /* Since the user is about to type in a command, allocate a buffer 
                     * in which this command can be stored. */
                    cur_sbc = ibuf_init();
                    return 0;
                case '/':
                case '?':
                    if (src_win->cur != NULL) {
                        regex_cur = ibuf_init();
                        regex_direction_cur = ('/' == key);
                        orig_line_regex = src_win->cur->sel_line;

                        sbc_kind = SBC_REGEX;
                        if_set_focus(CGDB_STATUS_BAR);

                        /* Capturing regular expressions */
                        source_search_regex_init(src_win);

                        /* Initialize the function for finding a regex and tell user */
                        if_draw();
                    }
                    return 0;
                case 'n':
                    source_search_regex(src_win, ibuf_get(regex_last), 2,
                            regex_direction_last, regex_icase);
                    if_draw();
                    break;
                case 'N':
                    source_search_regex(src_win, ibuf_get(regex_last), 2,
                            !regex_direction_last, regex_icase);
                    if_draw();
                    break;
                case 'T':
                    if (tty_win_on) {
                        tty_win_on = 0;
                        focus = CGDB;
                    } else {
                        tty_win_on = 1;
                        focus = TTY;
                    }

                    if_layout();

                    break;
                case CGDB_KEY_CTRL_T:
                    if (tgdb_tty_new(tgdb) == -1) {
                        /* Error */
                    } else {
                        scr_free(tty_win);
                        tty_win = NULL;
                        if_layout();
                    }

                    break;
                case CGDB_KEY_F1:
                    if_display_help();
                    return 0;
                case CGDB_KEY_F5:
                    /* Issue GDB run command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb, TGDB_RUN);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F6:
                    /* Issue GDB continue command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb,
                            TGDB_CONTINUE);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F7:
                    /* Issue GDB finish command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb,
                            TGDB_FINISH);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F8:
                    /* Issue GDB next command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb, TGDB_NEXT);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_F10:
                    /* Issue GDB step command */
                {
                    tgdb_request_ptr request_ptr;

                    request_ptr =
                            tgdb_request_run_debugger_command(tgdb, TGDB_STEP);
                    handle_request(tgdb, request_ptr);
                }
                    return 0;
                case CGDB_KEY_CTRL_L:
                    if_layout();
                    return 0;
            }
            source_input(src_win, key);
            return 0;
            break;
        case TTY:
            return tty_input(key);
        case GDB:
            return gdb_input(key);
        case FILE_DLG:
        {
            static char filedlg_file[MAX_LINE];
            int ret = filedlg_recv_char(fd, key, filedlg_file);

            /* The user cancelled */
            if (ret == -1) {
                if_set_focus(CGDB);
                return 0;
                /* Needs more data */
            } else if (ret == 0) {
                return 0;
                /* The user picked a file */
            } else if (ret == 1) {
                tgdb_request_ptr request_ptr;

                request_ptr = tgdb_request_filename_pair(tgdb, filedlg_file);
                handle_request(tgdb, request_ptr);
                if_set_focus(CGDB);
                return 0;
            }
        }
            return 0;
        case CGDB_STATUS_BAR:
            return status_bar_input(src_win, key);
    }

    /* Never gets here */
    return 0;
}
예제 #6
0
void btcmd(char* prompt_string,CMDENTRY app_cmds[],
              void(error_handler)(int))
{
    char* rlbuf = NULL;
    char* cp = NULL;
    static char cmdbuf[MAXBUFSZ+1];
    int status = 0;
    
    if (input == NULL) input = stdin;
    current_app_cmds = app_cmds;
    cblk.function = NULL;
    
    while (status >= 0) {
        if (rlbuf != NULL) {
            free(rlbuf);
            rlbuf = NULL;
        }
        if (tty_input(input)) {
#ifdef READLINE
            if (issue_prompt) 
                rlbuf = readline(prompt_string);
            else    
                rlbuf = readline(NULL);
            if (rlbuf != NULL) {
                if (strcmp(rlbuf,"") == 0) continue;
                strncpy(cmdbuf,rlbuf,MAXBUFSZ);
            }
#else
            if (issue_prompt) printf("%s",prompt_string);
            cp = fgets(cmdbuf,MAXBUFSZ,input);
#endif            
        }
        else {
            cp = fgets(cmdbuf,MAXBUFSZ,input);
        }
        if (cp == NULL && rlbuf == NULL) {
            if (input == stdin) {
                return; /* end of file in tty command stream */
            }
            else {
                btcmd_close_execute(&cblk);
                continue;
            }
        }
        find_cmd(cmdbuf,app_cmds);
        if (cblk.function != NULL) {
            if (cblk.nargs < 0) {
                bad_args(cblk.cmd);
                status = 1;
            }
            else {
                rl_history(input,rlbuf);
                if (echo && !tty_input(input)) {
                    fprintf(stdout,"%s%s",
                            prompt_string,
                            cmdbuf);
                }
                status = (cblk.function)(&cblk);
                if (status > 0  && !cblk.unknown_cmd) {
                    (error_handler)(status);
                }
            }
            if (status > 0 && stop_on_error && !tty_input(input)) {
                fprintf(stdout,
                        "command file processing terminated "
                        "(error on).\n");
                if (input == stdin) {
                    return; /* must be error in here document */
                }
                else {
                    while (input != stdin) btcmd_close_execute(&cblk);
                }
            }   
        }
    }
    return;
}
예제 #7
0
파일: driver.c 프로젝트: keenhenry/cgdb
int main_loop(int gdbfd, int childfd)
{
    int max;
    fd_set rfds;
    int result;

    int masterfd, slavefd;

    masterfd = pty_pair_get_masterfd(pty_pair);
    if (masterfd == -1) {
        logger_write_pos(logger, __FILE__, __LINE__,
                         "pty_pair_get_masterfd error");
        return -1;
    }

    slavefd = pty_pair_get_slavefd(pty_pair);
    if (slavefd == -1) {
        logger_write_pos(logger, __FILE__, __LINE__,
                         "pty_pair_get_slavefd error");
        return -1;
    }

    /* When TGDB is ready, we read from STDIN, otherwise, leave the data buffered. */
    /* get max fd  for select loop */
    max = (gdbfd > STDIN_FILENO) ? gdbfd : STDIN_FILENO;
    max = (max > childfd) ? max : childfd;
    max = (max > slavefd) ? max : slavefd;
    max = (max > masterfd) ? max : masterfd;

    while (1) {
        /* Clear the set and
         *
         * READ FROM:
         * stdin          (user or gui)
         * master         (gdb's stdout)
         * gui_stdout     (gui's stdout sending new info)
         *
         */
        FD_ZERO(&rfds);

        /* Let the terminal emulate the char's when TGDB is busy */
        FD_SET(STDIN_FILENO, &rfds);
        FD_SET(gdbfd, &rfds);
        FD_SET(slavefd, &rfds);
        FD_SET(masterfd, &rfds);

        if (childfd != -1)
            FD_SET(childfd, &rfds);

        result = select(max + 1, &rfds, NULL, NULL, NULL);

        /* if the signal interuppted system call keep going */
        if (result == -1 && errno == EINTR)
            continue;
        else if (result == -1)  /* on error ... must die -> stupid OS */
            logger_write_pos(logger, __FILE__, __LINE__, "select failed");

        /* Input received through the pty:  Handle it
         * Readline read from slavefd, and it wrote to the masterfd.
         */
        if (FD_ISSET(masterfd, &rfds))
            if (readline_input() == -1)
                return -1;

        if (FD_ISSET(slavefd, &rfds))
            rline_rl_callback_read_char(rline);

        /* stdin -> readline input */
        if (FD_ISSET(STDIN_FILENO, &rfds)) {
            stdin_input();
        }

        /* child's output -> stdout */
        if (childfd != -1 && FD_ISSET(childfd, &rfds)) {
            tty_input();
            continue;
        }

        /* gdb's output -> stdout  */
        if (FD_ISSET(gdbfd, &rfds))
            if (gdb_input() == -1)
                return -1;
    }

    return 0;
}
예제 #8
0
파일: serial.c 프로젝트: AdamRLukaitis/prex
/*
 * Character input.
 */
void
serial_rcv_char(struct serial_port *port, char c)
{

	tty_input(c, port->tty);
}