Esempio n. 1
0
static char* less_gets(int sz)
{
	int c;
	unsigned i = 0;
	char *result = xzalloc(1);

	while (1) {
		c = '\0';
		less_gets_pos = sz + i;
		c = getch_nowait();
		if (c == 0x0d) {
			result[i] = '\0';
			less_gets_pos = -1;
			return result;
		}
		if (c == 0x7f)
			c = 8;
		if (c == 8 && i) {
			printf("\x8 \x8");
			i--;
		}
		if (c < ' ') /* filters out KEYCODE_xxx too (<0) */
			continue;
		if (i >= width - sz - 1)
			continue; /* len limit */
		bb_putchar(c);
		result[i++] = c;
		result = xrealloc(result, i+1);
	}
}
Esempio n. 2
0
File: less.c Progetto: OPSF/uClinux
static char* less_gets(int sz)
{
    char c;
    int i = 0;
    char *result = xzalloc(1);

    while (1) {
        c = '\0';
        less_gets_pos = sz + i;
        getch_nowait(&c, 1);
        if (c == 0x0d) {
            result[i] = '\0';
            less_gets_pos = -1;
            return result;
        }
        if (c == 0x7f)
            c = 8;
        if (c == 8 && i) {
            printf("\x8 \x8");
            i--;
        }
        if (c < ' ')
            continue;
        if (i >= width - sz - 1)
            continue; /* len limit */
        bb_putchar(c);
        result[i++] = c;
        result = xrealloc(result, i+1);
    }
}
Esempio n. 3
0
/* Grab a character from input without requiring the return key.
 * May return KEYCODE_xxx values.
 * Note that this function works best with raw input. */
static int less_getch(int pos)
{
	int i;

 again:
	less_gets_pos = pos;
	i = getch_nowait();
	less_gets_pos = -1;

	/* Discard Ctrl-something chars */
	if (i >= 0 && i < ' ' && i != 0x0d && i != 8)
		goto again;
	return i;
}
Esempio n. 4
0
File: less.c Progetto: OPSF/uClinux
/* Grab a character from input without requiring the return key. If the
 * character is ASCII \033, get more characters and assign certain sequences
 * special return codes. Note that this function works best with raw input. */
static int less_getch(int pos)
{
    unsigned char input[16];
    unsigned i;

again:
    less_gets_pos = pos;
    memset(input, 0, sizeof(input));
    getch_nowait(input, sizeof(input));
    less_gets_pos = -1;

    /* Detect escape sequences (i.e. arrow keys) and handle
     * them accordingly */
    if (input[0] == '\033' && input[1] == '[') {
        i = input[2] - REAL_KEY_UP;
        if (i < 4)
            return 20 + i;
        i = input[2] - REAL_PAGE_UP;
        if (i < 4)
            return 24 + i;
        if (input[2] == REAL_KEY_HOME_XTERM)
            return KEY_HOME;
        if (input[2] == REAL_KEY_HOME_ALT)
            return KEY_HOME;
        if (input[2] == REAL_KEY_END_XTERM)
            return KEY_END;
        if (input[2] == REAL_KEY_END_ALT)
            return KEY_END;
        return 0;
    }
    /* Reject almost all control chars */
    i = input[0];
    if (i < ' ' && i != 0x0d && i != 8)
        goto again;
    return i;
}