<commit_before>/**
 * @file
 *
 * @date Feb 6, 2013
 * @author: <NAME>
 */

#include <stdint.h>
#include <string.h>

#include <drivers/keyboard.h>
#include <drivers/input/input_dev.h>
#include <drivers/input/keymap.h>


/*
 * Key map
 */
static const uint8_t key_map[] = {
	0,      0x1b,   '1',    '2',    '3',    '4',    '5',    '6',
	'7',    '8',    '9',    '0',    '-',    '=',    '\b',   '\t',
	'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
	'o',    'p',    '[',    ']',    '\n',   KEY_CTRL, 'a',    's',
	'd',    'f',    'g',    'h',    'j',    'k',    'l',    ';',
	'\'',   '`',    KEY_SHFT, '\\',   'z',    'x',    'c',    'v',
	'b',    'n',    'm',    ',',    '.',    '/',    KEY_SHFT, '*',
	KEY_ALT,  ' ',    KEY_CAPS, KEY_F1,   KEY_F2,   KEY_F3,   KEY_F4,   KEY_F5,
	KEY_F6,   KEY_F7,   KEY_F8,   KEY_F9,   KEY_F10,  0,      0,      KEY_HOME,
	KEY_UP,   KEY_PGUP, 0,      KEY_LEFT, 0,      KEY_RGHT, 0,      KEY_END,
	KEY_DOWN, KEY_PGDN, KEY_INS,  0x7f,   KEY_F11,  KEY_F12
};

#define KEY_MAX (sizeof(key_map) / sizeof(char))

static const uint8_t shift_map[] = {
	0,      0x1b,   '!',    '@',    '#',    '$',    '%',    '^',
	'&',    '*',    '(',    ')',    '_',    '+',    '\b',   '\t',
	'Q',    'W',    'E',    'R',    'T',    'Y',    'U',    'I',
	'O',    'P',    '{',    '}',    '\n',   KEY_CTRL, 'A',    'S',
	'D',    'F',    'G',    'H',    'J',    'K',    'L',    ':',
	'"',    '~',    0,      '|',    'Z',    'X',    'C',    'V',
	'B',    'N',    'M',    '<',    '>',    '?',    0,      '*',
	KEY_ALT,  ' ',    0,      0,      0,      0,      0,      0,
	0,      0,      0,      0,      0,      0,      0,      KEY_HOME,
	KEY_UP,   KEY_PGUP, 0,      KEY_LEFT, 0,      KEY_RGHT, 0,      KEY_END,
	KEY_DOWN, KEY_PGDN, KEY_INS,  0x7f,   0,      0
};

int keymap_kbd(struct input_event *event) {
	if((event->value & 0xFFFF) > KEY_MAX) {
		return -1;
	}

	if(event->value & SHIFT_PRESSED) {
		return (int)shift_map[event->value & 0xFFFF];
	} else {
		return (int)key_map[event->value & 0xFFFF];
	}
}

static const unsigned char esc_start[] = {0x1B, 0x5B}; /* esc, '[' */

int keymap_to_ascii(struct input_event *event, unsigned char ascii_buff[4]) {
	int keycode = keymap_kbd(event);
	int seq_len = 0;

	if(keycode < 0) {
		return 0;
	}

	switch (keycode) {
	case 0:
	case KEY_CAPS:<commit_msg>keymap: ctrl handling<commit_after>/**
 * @file
 *
 * @date Feb 6, 2013
 * @author: <NAME>
 */

#include <stdint.h>
#include <string.h>

#include <drivers/keyboard.h>
#include <drivers/input/input_dev.h>
#include <drivers/input/keymap.h>


/*
 * Key map
 */
static const uint8_t key_map[] = {
	0,      0x1b,   '1',    '2',    '3',    '4',    '5',    '6',
	'7',    '8',    '9',    '0',    '-',    '=',    '\b',   '\t',
	'q',    'w',    'e',    'r',    't',    'y',    'u',    'i',
	'o',    'p',    '[',    ']',    '\n',   KEY_CTRL, 'a',    's',
	'd',    'f',    'g',    'h',    'j',    'k',    'l',    ';',
	'\'',   '`',    KEY_SHFT, '\\',   'z',    'x',    'c',    'v',
	'b',    'n',    'm',    ',',    '.',    '/',    KEY_SHFT, '*',
	KEY_ALT,  ' ',    KEY_CAPS, KEY_F1,   KEY_F2,   KEY_F3,   KEY_F4,   KEY_F5,
	KEY_F6,   KEY_F7,   KEY_F8,   KEY_F9,   KEY_F10,  0,      0,      KEY_HOME,
	KEY_UP,   KEY_PGUP, 0,      KEY_LEFT, 0,      KEY_RGHT, 0,      KEY_END,
	KEY_DOWN, KEY_PGDN, KEY_INS,  0x7f,   KEY_F11,  KEY_F12
};

#define KEY_MAX (sizeof(key_map) / sizeof(char))

static const uint8_t shift_map[] = {
	0,      0x1b,   '!',    '@',    '#',    '$',    '%',    '^',
	'&',    '*',    '(',    ')',    '_',    '+',    '\b',   '\t',
	'Q',    'W',    'E',    'R',    'T',    'Y',    'U',    'I',
	'O',    'P',    '{',    '}',    '\n',   KEY_CTRL, 'A',    'S',
	'D',    'F',    'G',    'H',    'J',    'K',    'L',    ':',
	'"',    '~',    0,      '|',    'Z',    'X',    'C',    'V',
	'B',    'N',    'M',    '<',    '>',    '?',    0,      '*',
	KEY_ALT,  ' ',    0,      0,      0,      0,      0,      0,
	0,      0,      0,      0,      0,      0,      0,      KEY_HOME,
	KEY_UP,   KEY_PGUP, 0,      KEY_LEFT, 0,      KEY_RGHT, 0,      KEY_END,
	KEY_DOWN, KEY_PGDN, KEY_INS,  0x7f,   0,      0
};

int keymap_kbd(struct input_event *event) {
	if((event->value & 0xFFFF) > KEY_MAX) {
		return -1;
	}

	if(event->value & SHIFT_PRESSED) {
		return (int)shift_map[event->value & 0xFFFF];
	} else if (event->value & CTRL_PRESSED){
		uint8_t val = shift_map[event->value & 0xFFFF];
		if (val > 0x3f) {
			return (int)shift_map[event->value & 0xFFFF]  & 0x1f;
		} else {
			return 0;
		}
	} else {
		return (int)key_map[event->value & 0xFFFF];
	}
}

static const unsigned char esc_start[] = {0x1B, 0x5B}; /* esc, '[' */

int keymap_to_ascii(struct input_event *event, unsigned char ascii_buff[4]) {
	int keycode = keymap_kbd(event);
	int seq_len = 0;

	if(keycode < 0) {
		return 0;
	}

	switch (keycode) {
	case 0:
	case KEY_CAPS:
{'fraction_non_alphanumeric': 0.24108798681228105, 'fraction_numerical': 0.03461776220894292, 'mean_word_length': 1.9013747758517634, 'pattern_counts': {'":': 0, '<': 19, '<?xml version=': 0, '>': 31, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 4, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6595273', 'n_tokens_mistral': 2367, 'n_tokens_neox': 2261, 'n_words': 453}