Пример #1
0
static void show_console_input(void)
{
    if (!sys_hidden) {
        return;
    }

    sys_hidden--;
    if (!sys_hidden) {
        write_console_data("]", 1);
        write_console_data(sys_con.inputLine.text, sys_con.inputLine.cursorPos);
    }
}
Пример #2
0
static void hide_console_input(void)
{
    int i;

    if (!sys_hidden) {
        for (i = 0; i <= sys_con.inputLine.cursorPos; i++) {
            write_console_data("\b \b", 3);
        }
    }
    sys_hidden++;
}
Пример #3
0
static int process_mdb(SCLPEvent *event, MDBO *mdbo)
{
    int rc;
    int len;
    uint8_t buffer[SIZE_BUFFER];

    len = be16_to_cpu(mdbo->length);
    len -= sizeof(mdbo->length) + sizeof(mdbo->type)
            + sizeof(mdbo->mto.line_type_flags)
            + sizeof(mdbo->mto.alarm_control)
            + sizeof(mdbo->mto._reserved);

    assert(len <= SIZE_BUFFER);

    /* convert EBCDIC SCLP contents to ASCII console message */
    ascii_put(buffer, mdbo->mto.message, len);
    rc = write_console_data(event, (uint8_t *)NEWLINE, 1);
    if (rc < 0) {
        return rc;
    }
    return write_console_data(event, buffer, len);
}
Пример #4
0
static void write_console_output(const char *text)
{
    char    buf[MAXPRINTMSG];
    size_t  len;

    for (len = 0; len < MAXPRINTMSG; len++) {
        int c = *text++;
        if (!c) {
            break;
        }
        buf[len] = Q_charascii(c);
    }

    write_console_data(buf, len);
}
Пример #5
0
static int write_event_data(SCLPEvent *event, EventBufferHeader *evt_buf_hdr)
{
    int rc;
    int length;
    ssize_t written;
    ASCIIConsoleData *acd = (ASCIIConsoleData *) evt_buf_hdr;

    length = be16_to_cpu(evt_buf_hdr->length) - sizeof(EventBufferHeader);
    written = write_console_data(event, (uint8_t *)acd->data, length);

    rc = SCLP_RC_NORMAL_COMPLETION;
    /* set event buffer accepted flag */
    evt_buf_hdr->flags |= SCLP_EVENT_BUFFER_ACCEPTED;

    /* written will be zero if a pty is not connected - don't treat as error */
    if (written < 0) {
        /* event buffer not accepted due to error in character layer */
        evt_buf_hdr->flags &= ~(SCLP_EVENT_BUFFER_ACCEPTED);
        rc = SCLP_RC_CONTAINED_EQUIPMENT_CHECK;
    }

    return rc;
}
Пример #6
0
/*
================
Sys_ConsoleInput
================
*/
void Sys_RunConsole(void)
{
    INPUT_RECORD    recs[MAX_CONSOLE_INPUT_EVENTS];
    int     ch;
    DWORD   numread, numevents;
    int     i;
    inputField_t    *f;
    char    *s;

    if (hinput == INVALID_HANDLE_VALUE) {
        return;
    }

    if (!gotConsole) {
        return;
    }

    f = &sys_con.inputLine;
    while (1) {
        if (!GetNumberOfConsoleInputEvents(hinput, &numevents)) {
            Com_EPrintf("Error %lu getting number of console events.\n", GetLastError());
            gotConsole = qfalse;
            return;
        }

        if (numevents <= 0)
            break;
        if (numevents > MAX_CONSOLE_INPUT_EVENTS) {
            numevents = MAX_CONSOLE_INPUT_EVENTS;
        }

        if (!ReadConsoleInput(hinput, recs, numevents, &numread)) {
            Com_EPrintf("Error %lu reading console input.\n", GetLastError());
            gotConsole = qfalse;
            return;
        }

        for (i = 0; i < numread; i++) {
            if (recs[i].EventType == WINDOW_BUFFER_SIZE_EVENT) {
                // determine terminal width
                size_t width = recs[i].Event.WindowBufferSizeEvent.dwSize.X;

                if (!width) {
                    Com_EPrintf("Invalid console buffer width.\n");
                    gotConsole = qfalse;
                    return;
                }

                sys_con.widthInChars = width;

                // figure out input line width
                width--;
                if (width > MAX_FIELD_TEXT - 1) {
                    width = MAX_FIELD_TEXT - 1;
                }

                hide_console_input();
                IF_Init(&sys_con.inputLine, width, width);
                show_console_input();
                continue;
            }
            if (recs[i].EventType != KEY_EVENT) {
                continue;
            }

            if (!recs[i].Event.KeyEvent.bKeyDown) {
                continue;
            }

            switch (recs[i].Event.KeyEvent.wVirtualKeyCode) {
            case VK_UP:
                hide_console_input();
                Prompt_HistoryUp(&sys_con);
                show_console_input();
                break;
            case VK_DOWN:
                hide_console_input();
                Prompt_HistoryDown(&sys_con);
                show_console_input();
                break;
            case VK_RETURN:
                hide_console_input();
                s = Prompt_Action(&sys_con);
                if (s) {
                    if (*s == '\\' || *s == '/') {
                        s++;
                    }
                    Sys_Printf("]%s\n", s);
                    Cbuf_AddText(&cmd_buffer, s);
                    Cbuf_AddText(&cmd_buffer, "\n");
                } else {
                    write_console_data("\n", 1);
                }
                show_console_input();
                break;
            case VK_BACK:
                if (f->cursorPos) {
                    f->text[--f->cursorPos] = 0;
                    write_console_data("\b \b", 3);
                }
                break;
            case VK_TAB:
                hide_console_input();
                Prompt_CompleteCommand(&sys_con, qfalse);
                f->cursorPos = strlen(f->text);
                show_console_input();
                break;
            default:
                ch = recs[i].Event.KeyEvent.uChar.AsciiChar;
                if (ch < 32) {
                    break;
                }
                if (f->cursorPos < f->maxChars - 1) {
                    write_console_data(&ch, 1);
                    f->text[f->cursorPos] = ch;
                    f->text[++f->cursorPos] = 0;
                }
                break;
            }
        }
    }
}