if (keycode >> (dev->keycodesize * 8)) 
if (dev->keycodesize < sizeof(keycode) && (keycode >> (dev->keycodesize * 8))) 
static k_handler_fn K_HANDLERS;static k_handler_fn *k_handler[16] = { K_HANDLERS };#define FN_HANDLERS\	fn_null, 	fn_enter,	fn_show_ptregs,	fn_show_mem,\	fn_show_state,	fn_send_intr, 	fn_lastcons, 	fn_caps_toggle,\	fn_num,		fn_hold, 	fn_scroll_forw,	fn_scroll_back,\	fn_boot_it, 	fn_caps_on, 	fn_compose,	fn_SAK,\	fn_dec_console, fn_inc_console, fn_spawn_con, 	fn_bare_numtypedef void (fn_handler_fn)(struct vc_data *vc, struct pt_regs *regs);static fn_handler_fn FN_HANDLERS;static fn_handler_fn *fn_handler[] = { FN_HANDLERS };/* * Variables exported for vt_ioctl.c *//* maximum values each key_handler can handle */const int max_vals[] = {	255, ARRAY_SIZE(func_table) - 1, ARRAY_SIZE(fn_handler) - 1, NR_PAD - 1,	NR_DEAD - 1, 255, 3, NR_SHIFT - 1, 255, NR_ASCII - 1, NR_LOCK - 1,	255, NR_LOCK - 1, 255};const int NR_TYPES = ARRAY_SIZE(max_vals);struct kbd_struct kbd_table[MAX_NR_CONSOLES];static struct kbd_struct *kbd = kbd_table;static struct kbd_struct kbd0;int spawnpid, spawnsig;/* * Variables exported for vt.c */int shift_state = 0;/* * Internal Data. */static struct input_handler kbd_handler;static unsigned long key_down[NBITS(KEY_MAX)];		/* keyboard key bitmap */static unsigned char shift_down[NR_SHIFT];		/* shift state counters.. */static int dead_key_next;static int npadch = -1;					/* -1 or number assembled on pad */static unsigned char diacr;static char rep;					/* flag telling character repeat */static unsigned char ledstate = 0xff;			/* undefined */static unsigned char ledioctl;static struct ledptr {	unsigned int *addr;	unsigned int mask;	unsigned char valid:1;} ledptrs[3];/* Simple translation table for the SysRq keys */#ifdef CONFIG_MAGIC_SYSRQunsigned char kbd_sysrq_xlate[KEY_MAX + 1] =        "\000\0331234567890-=\177\t"                    /* 0x00 - 0x0f */        "qwertyuiop[]\r\000as"                          /* 0x10 - 0x1f */        "dfghjkl;'`\000\\zxcv"                          /* 0x20 - 0x2f */        "bnm,./\000*\000 \000\201\202\203\204\205"      /* 0x30 - 0x3f */        "\206\207\210\211\212\000\000789-456+1"         /* 0x40 - 0x4f */        "230\177\000\000\213\214\000\000\000\000\000\000\000\000\000\000" /* 0x50 - 0x5f */        "\r\000/";                                      /* 0x60 - 0x6f */static int sysrq_down;#endifstatic int sysrq_alt;/* * Translation of scancodes to keycodes. We set them on only the first attached * keyboard - for per-keyboard setting, /dev/input/event is more useful. */int getkeycode(unsigned int scancode){	struct list_head * node;	struct input_dev *dev = NULL;	list_for_each(node,&kbd_handler.h_list) {		struct input_handle * handle = to_handle_h(node);		if (handle->dev->keycodesize) { 			dev = handle->dev; 			break;		}	}	if (!dev)		return -ENODEV;	if (scancode >= dev->keycodemax)		return -EINVAL;	return INPUT_KEYCODE(dev, scancode);}int setkeycode(unsigned int scancode, unsigned int keycode){	struct list_head * node;	struct input_dev *dev = NULL;	unsigned int i, oldkey;	list_for_each(node,&kbd_handler.h_list) {		struct input_handle *handle = to_handle_h(node);		if (handle->dev->keycodesize) { 			dev = handle->dev; 			break; 		}	}	if (!dev)		return -ENODEV;	if (scancode >= dev->keycodemax)		return -EINVAL;	if (keycode < 0 || keycode > KEY_MAX)		return -EINVAL;	if (keycode >> (dev->keycodesize * 8))		return -EINVAL;	oldkey = SET_INPUT_KEYCODE(dev, scancode, keycode);	clear_bit(oldkey, dev->keybit);	set_bit(keycode, dev->keybit);	for (i = 0; i < dev->keycodemax; i++)		if (INPUT_KEYCODE(dev,i) == oldkey)			set_bit(oldkey, dev->keybit);	return 0;}/* * Making beeps and bells.  */static void kd_nosound(unsigned long ignored){	struct list_head * node;	list_for_each(node,&kbd_handler.h_list) {		struct input_handle *handle = to_handle_h(node);		if (test_bit(EV_SND, handle->dev->evbit)) {			if (test_bit(SND_TONE, handle->dev->sndbit))				input_event(handle->dev, EV_SND, SND_TONE, 0);			if (test_bit(SND_BELL, handle->dev->sndbit))				input_event(handle->dev, EV_SND, SND_BELL, 0);		}	}}static struct timer_list kd_mksound_timer =		TIMER_INITIALIZER(kd_nosound, 0, 0);void kd_mksound(unsigned int hz, unsigned int ticks){	struct list_head * node;	del_timer(&kd_mksound_timer);	if (hz) {		list_for_each_prev(node,&kbd_handler.h_list) {			struct input_handle *handle = to_handle_h(node);			if (test_bit(EV_SND, handle->dev->evbit)) {				if (test_bit(SND_TONE, handle->dev->sndbit)) {					input_event(handle->dev, EV_SND, SND_TONE, hz);					break;				}				if (test_bit(SND_BELL, handle->dev->sndbit)) {					input_event(handle->dev, EV_SND, SND_BELL, 1);					break;				}			}		}		if (ticks)			mod_timer(&kd_mksound_timer, jiffies + ticks);	} else		kd_nosound(0);}/* * Setting the keyboard rate. */int kbd_rate(struct kbd_repeat *rep){	struct list_head *node;	unsigned int d = 0;	unsigned int p = 0;	list_for_each(node,&kbd_handler.h_list) {		struct input_handle *handle = to_handle_h(node);		struct input_dev *dev = handle->dev;		if (test_bit(EV_REP, dev->evbit)) {			if (rep->delay > 0)				input_event(dev, EV_REP, REP_DELAY, rep->delay);			if (rep->period > 0)				input_event(dev, EV_REP, REP_PERIOD, rep->period);			d = dev->rep[REP_DELAY];			p = dev->rep[REP_PERIOD];		}	}	rep->delay  = d;	rep->period = p;	return 0;}/* * Helper Functions. */static void put_queue(struct vc_data *vc, int ch){	struct tty_struct *tty = vc->vc_tty;	if (tty) {		tty_insert_flip_char(tty, ch, 0);		con_schedule_flip(tty);	}}static void puts_queue(struct vc_data *vc, char *cp){	struct tty_struct *tty = vc->vc_tty;	if (!tty)		return;	while (*cp) {		tty_insert_flip_char(tty, *cp, 0);		cp++;	}	con_schedule_flip(tty);}static void applkey(struct vc_data *vc, int key, char mode){	static char buf[] = { 0x1b, 'O', 0x00, 0x00 };	buf[1] = (mode ? 'O' : '[');	buf[2] = key;	puts_queue(vc, buf);}/* * Many other routines do put_queue, but I think either * they produce ASCII, or they produce some user-assigned * string, and in both cases we might assume that it is * in utf-8 already. UTF-8 is defined for words of up to 31 bits, * but we need only 16 bits here */static void to_utf8(struct vc_data *vc, ushort c){	if (c < 0x80)		/*  0******* */		put_queue(vc, c);    	else if (c < 0x800) {		/* 110***** 10****** */		put_queue(vc, 0xc0 | (c >> 6)); 		put_queue(vc, 0x80 | (c & 0x3f));    	} else {		/* 1110**** 10****** 10****** */		put_queue(vc, 0xe0 | (c >> 12));		put_queue(vc, 0x80 | ((c >> 6) & 0x3f));		put_queue(vc, 0x80 | (c & 0x3f));    	}}/*  * Called after returning from RAW mode or when changing consoles - recompute * shift_down[] and shift_state from key_down[] maybe called when keymap is * undefined, so that shiftkey release is seen */void compute_shiftstate(void){	unsigned int i, j, k, sym, val;	shift_state = 0;	memset(shift_down, 0, sizeof(shift_down));		for (i = 0; i < ARRAY_SIZE(key_down); i++) {		if (!key_down[i])			continue;		k = i * BITS_PER_LONG;		for (j = 0; j < BITS_PER_LONG; j++, k++) {			if (!test_bit(k, key_down))				continue;			sym = U(key_maps[0][k]);			if (KTYP(sym) != KT_SHIFT && KTYP(sym) != KT_SLOCK)				continue;			val = KVAL(sym);			if (val == KVAL(K_CAPSSHIFT))				val = KVAL(K_SHIFT);			shift_down[val]++;			shift_state |= (1 << val);		}	}}/* * We have a combining character DIACR here, followed by the character CH. * If the combination occurs in the table, return the corresponding value. * Otherwise, if CH is a space or equals DIACR, return DIACR. * Otherwise, conclude that DIACR was not combining after all, * queue it and return CH. */static unsigned char handle_diacr(struct vc_data *vc, unsigned char ch){	int d = diacr;	unsigned int i;	diacr = 0;	for (i = 0; i < accent_table_size; i++) {		if (accent_table[i].diacr == d && accent_table[i].base == ch)			return accent_table[i].result;	}	if (ch == ' ' || ch == d)		return d;	put_queue(vc, d);	return ch;}/* * Special function handlers */static void fn_enter(struct vc_data *vc, struct pt_regs *regs){	if (diacr) {		put_queue(vc, diacr);		diacr = 0;	}	put_queue(vc, 13);	if (vc_kbd_mode(kbd, VC_CRLF))		put_queue(vc, 10);}static void fn_caps_toggle(struct vc_data *vc, struct pt_regs *regs){	if (rep)		return;	chg_vc_kbd_led(kbd, VC_CAPSLOCK);}static void fn_caps_on(struct vc_data *vc, struct pt_regs *regs){	if (rep)		return;	set_vc_kbd_led(kbd, VC_CAPSLOCK);}static void fn_show_ptregs(struct vc_data *vc, struct pt_regs *regs){	if (regs)		show_regs(regs);}static void fn_hold(struct vc_data *vc, struct pt_regs *regs){	struct tty_struct *tty = vc->vc_tty;	if (rep || !tty)		return;	/*	 * Note: SCROLLOCK will be set (cleared) by stop_tty (start_tty);	 * these routines are also activated by ^S/^Q.	 * (And SCROLLOCK can also be set by the ioctl KDSKBLED.)	 */	if (tty->stopped)		start_tty(tty);	else		stop_tty(tty);}static void fn_num(struct vc_data *vc, struct pt_regs *regs){	if (vc_kbd_mode(kbd,VC_APPLIC))		applkey(vc, 'P', 1);	else		fn_bare_num(vc, regs);}/* * Bind this to Shift-NumLock if you work in application keypad mode * but want to be able to change the NumLock flag. * Bind this to NumLock if you prefer that the NumLock key always * changes the NumLock flag. */static void fn_bare_num(struct vc_data *vc, struct pt_regs *regs){	if (!rep)		chg_vc_kbd_led(kbd, VC_NUMLOCK);}static void fn_lastcons(struct vc_data *vc, struct pt_regs *regs){	/* switch to the last used console, ChN */	set_console(last_console);}static void fn_dec_console(struct vc_data *vc, struct pt_regs *regs){	int i, cur = fg_console;	/* Currently switching?  Queue this next switch relative to that. */	if (want_console != -1)		cur = want_console;	for (i = cur-1; i != cur; i--) {		if (i == -1)			i = MAX_NR_CONSOLES-1;		if (vc_cons_allocated(i))			break;	}	set_console(i);}static void fn_inc_console(struct vc_data *vc, struct pt_regs *regs){	int i, cur = fg_console;	/* Currently switching?  Queue this next switch relative to that. */	if (want_console != -1)		cur = want_console;	for (i = cur+1; i != cur; i++) {		if (i == MAX_NR_CONSOLES)			i = 0;		if (vc_cons_allocated(i))			break;	}	set_console(i);}static void fn_send_intr(struct vc_data *vc, struct pt_regs *regs){	struct tty_struct *tty = vc->vc_tty;	if (!tty)		return;	tty_insert_flip_char(tty, 0, TTY_BREAK);	con_schedule_flip(tty);}static void fn_scroll_forw(struct vc_data *vc, struct pt_regs *regs){	scrollfront(vc, 0);}static void fn_scroll_back(struct vc_data *vc, struct pt_regs *regs){	scrollback(vc, 0);}static void fn_show_mem(struct vc_data *vc, struct pt_regs *regs){	show_mem();}static void fn_show_state(struct vc_data *vc, struct pt_regs *regs){	show_state();}static void fn_boot_it(struct vc_data *vc, struct pt_regs *regs){	ctrl_alt_del();}static void fn_compose(struct vc_data *vc, struct pt_regs *regs){	dead_key_next = 1;}static void fn_spawn_con(struct vc_data *vc, struct pt_regs *regs){        if (spawnpid)	   if(kill_proc(spawnpid, spawnsig, 1))	     spawnpid = 0;}static void fn_SAK(struct vc_data *vc, struct pt_regs *regs){	struct tty_struct *tty = vc->vc_tty;	/*	 * SAK should also work in all raw modes and reset	 * them properly.	 */	if (tty)		do_SAK(tty);	reset_vc(vc);}static void fn_null(struct vc_data *vc, struct pt_regs *regs){	compute_shiftstate();}/* * Special key handlers */static void k_ignore(struct vc_data *vc, unsigned char value, char up_flag, struct pt_regs *regs){}
10457	/local/tlutelli/issta_data/temp/c/2005_temp/2005/10457/4cee99564db7f65a6f88e4b752da52768cde3802/keyboard.c/clean/drivers/char/keyboard.c