⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 win_keymap.c

📁 操作系统SunOS 4.1.3版本的源码
💻 C
📖 第 1 页 / 共 3 页
字号:
#ifndef lint#ifdef sccsstatic char sccsid[] = "@(#)win_keymap.c 20.19 90/02/05 Copyr 1985 Sun Micro";#endif#endif/* *	Copyright (c) 1987 Sun Microsystems, Inc. */ /****************************************************************************** *	win_keymap.c -- keymapping system for SunView event mapping ******************************************************************************/#define win_keymap_c#include <stdio.h>#include <ctype.h>#include <sys/param.h>	/* max files/process (NOFILE) from here *//* #include <sundev/kbd.h>	/* struct keyboard definition from here */#include <sys/types.h>#include <sys/time.h>#include <sunwindow/defaults.h>#include <sunwindow/bitmask.h>#include <sunwindow/hashfn.h>#include <sunwindow/win_keymap.h>typedef struct {    unsigned short	raw_code;    unsigned short	keyflags;}   _sunview_keys;KeymapFileEntry	keymap_from_fd[NOFILE];int		keymap_initialized;int		keymap_enable;#define LOCALHEAPSIZE (256-8)static char *local_heap;static char *local_heap_hwm;/* * mask_mathches returns 1 if m1 and m2 are the same or differ only in the  * SHIFTMASK bit; returns 0 otherwise. * m1 is the shiftmask for an incoming event, m2 is the mask for one of the * key-mappable semantic events(currently just erase-{word,char,line}. * Masks that differ in SHIFTMASK only are translated into complimentry * semantic events.  E.g. CTRL-TAB = next field and SHIFT-CTRL-TAB = previous * field. */#define mask_matches(m1, m2)   ((m1 == m2|SHIFTMASK) ? 1 : 0)static _sunview_keys	*win_keymap_translate_action_to_key();/* *  local_malloc(size) -- use the local heap to localize the keymap data *    to 1 page.  Note that allocating more than this will revert to using *    malloc(). */static caddr_tlocal_malloc(size)    int size;{    char *p;    if (!local_heap_hwm) {	local_heap_hwm = local_heap = (char *)valloc(LOCALHEAPSIZE);	if (local_heap == 0) {            perror("local_malloc():");            exit(1);        }    }    if (local_heap_hwm - local_heap + size > LOCALHEAPSIZE) {        return (caddr_t)malloc(size);    } else {        p = local_heap_hwm;        local_heap_hwm += size;        return (caddr_t)p;    }}#ifdef MALLOC_DEBUGstatic caddr_tMalloc(s)    unsigned s;{    caddr_t p;    char buf[64];    static int callno, hwm;    printf("%d: Malloc(%d), hwm %d\n",            ++callno, s, hwm+=s);        if ((p = (caddr_t)local_malloc(s)) == 0) {        (void)sprintf(buf, "win_keymap: Malloc(%d) hwm is %d", s,                local_heap_hwm - local_heap);        perror(buf);        exit(1);    } else {        return p;    }}#else#define Malloc(s)	(local_malloc((s)))#endifstatic intmetanormalize(c, mask)	register int c, mask;{	register int d = c % 128;	if  (d >= 64) {		if (mask & CTRLMASK)			return d%32 + 128;		else if (mask & SHIFTMASK)			return d%32 + 192;		else			return d+128;	} else {		return d+128;	}}/****************************************************************************** *	octal_char(s) -- return the char value represented by the string *		pointer pointed to by s.  The double indirection is used to  *		consume characters in the string.  Note that on return the *		string pointer points one beyond the end of the octal sequence. *		An octal sequence is defined by K&R p. 180-1; it is 1 to 3 *		octal digits. ******************************************************************************/static charoctal_char(str)	char	**str;{	register int	i;	char	v;	v = 0;	for (i = 0; i < 3 && isdigit(**str) && **str <= '7'; i++, (*str)++)		v = 8 * v + (**str - '0');	return (v);}/****************************************************************************** *	win_keymap_event_parse(p, e) -- parse the string pointed to by p (char **) *		to build the event pointed to by e (Event *).  The string pointer is *		modified and the event pointer is returned. ******************************************************************************/#define maskbit(b)	(1<<(b))#define	SUNOS_3_X	0#define SUNOS_4_X	1static unsigned short std_bind;  /* either SUNOS_3_X or SUNOS_4_X */voidwin_keymap_set_inputmask(mask, key, keyflags)    Inputmask *mask;    unsigned short key;    unsigned short keyflags /* ShortEvent sie_bits value */;{    if (isworkstationdevid(key)) {        win_setinputcodebit(mask, (short) key);            } if (ASCII_FIRST <= (short) key && (short) key <= ASCII_LAST) {        mask->im_flags |= IM_ASCII;        if (keyflags & SIE_NEGEVENT)            mask->im_flags |= IM_NEGASCII;    } else if (META_FIRST <= (short) key && (short) key <= META_LAST) {        mask->im_flags |= IM_META;        if (keyflags & SIE_NEGEVENT)            mask->im_flags |= IM_NEGMETA;    } else if (TOP_FIRST <= (short) key && (short) key <= TOP_LAST) {        mask->im_flags |= IM_TOP;        if (keyflags & SIE_NEGEVENT)            mask->im_flags |= IM_NEGTOP;    }}voidwin_keymap_unset_inputmask(mask, key, keyflags)    Inputmask *mask;    unsigned short key;    unsigned short keyflags /* ShortEvent sie_bits value */;{    if (isworkstationdevid(key)) {        win_unsetinputcodebit(mask, (short) key);#ifdef KNOWEVERYTHING           } if (ASCII_FIRST <= (short) key && (short) key <= ASCII_LAST) {        mask->im_flags |= IM_ASCII;        if (keyflags & SIE_NEGEVENT)            mask->im_flags |= IM_NEGASCII;    } else if (META_FIRST <= (short) key && (short) key <= META_LAST) {        mask->im_flags |= IM_META;        if (keyflags & SIE_NEGEVENT)            mask->im_flags |= IM_NEGMETA;    } else if (TOP_FIRST <= (short) key && (short) key <= TOP_LAST) {        mask->im_flags |= IM_TOP;        if (keyflags & SIE_NEGEVENT)            mask->im_flags |= IM_NEGTOP;#endif    }}voidwin_keymap_lazy_init(){    void win_keymap_enable(), win_keymap_init();        /* lazy evaluate the keymap initializiation */    if (!keymap_initialized) {        win_keymap_init();        win_keymap_enable();    }}voidwin_keymap_lazy_bind(){    register int i;    int first;    int index;    unsigned short action;    /* lazy evaluate which bindings we need by checking defaults */        if (!std_bind) {        if (defaults_exists("/Compatibility/New_keyboard_accelerators",                (int *)0)) {            if (!strcmp("Enabled", (char *)defaults_get_string(                    "/Compatibility/New_keyboard_accelerators", "Enabled", 0)))                std_bind = SUNOS_4_X;            else                std_bind = SUNOS_3_X;        } else {            std_bind = SUNOS_4_X;         }    }}voidwin_keymap_set_imask_from_std_bind(mask, action)    Inputmask *mask;    unsigned short action;{    register _sunview_keys *key;    win_keymap_lazy_bind();    /* take care of all the stuff that may not be semantic events */    win_keymap_set_inputmask(mask, action, 0);        key = win_keymap_translate_action_to_key(action);    win_keymap_set_inputmask(mask, key->raw_code, key->keyflags);}voidwin_keymap_unset_imask_from_std_bind(mask, action)    Inputmask *mask;    unsigned short action;{    _sunview_keys	*key;    win_keymap_lazy_bind();    /* keys is static storage that changes w/ every call to      * win_keymap_translate_action_to_keys, so its contents     * have to be looked at right away.     */    key = win_keymap_translate_action_to_key(action);    win_keymap_unset_inputmask(mask, key->raw_code, key->keyflags);}static _sunview_keys *win_keymap_translate_action_to_key(action){    static _sunview_keys	key;        switch(action) {	    case ACTION_STOP:	        key.raw_code = WIN_STOP;		key.keyflags = 0;	        break;	    case ACTION_CAPS_LOCK:	        key.raw_code = KEY_TOP(1);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_AGAIN:	        key.raw_code = KEY_LEFT(2);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_PROPS:	        key.raw_code = KEY_LEFT(3);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_UNDO:	        key.raw_code = KEY_LEFT(4);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_FRONT:	        key.raw_code = KEY_LEFT(5);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_BACK:	        key.raw_code = KEY_LEFT(5);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_COPY:	        key.raw_code = KEY_LEFT(6);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_OPEN:	        key.raw_code = KEY_LEFT(7);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_CLOSE:	        key.raw_code = KEY_LEFT(7);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_PASTE:	        key.raw_code = KEY_LEFT(8);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_FIND_BACKWARD:	        key.raw_code = KEY_LEFT(9);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_FIND_FORWARD:	        key.raw_code = KEY_LEFT(9);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_REPLACE:	        key.raw_code = KEY_LEFT(9);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_CUT:	        key.raw_code = KEY_LEFT(10);		key.keyflags = SIE_NEGEVENT;		break;	    case ACTION_HELP:	        key.raw_code = 32569;		key.keyflags = SIE_NEGEVENT;		break;    }    return &key;}/****************************************************************************** *	Inputmask Manipulation  --  The goal is to do reasonable job of handling *	the input mask.  The new semantic events do not appear in the current *	input mask since they are not real keys.  The strategy here is that *	given some semantic event Y, look through the mappings for occurrences *	of Y in the range (remember domain and range of a mapping X -> Y) and then *	take the domain value X as the thing whose input mask bits we are *	talking about. ******************************************************************************//* *    Semantic bit mask manipulation */voidwin_keymap_set_smask(windowfd, code)	int windowfd;	unsigned short code;{    Bitmask	*m = keymap_from_fd[windowfd].smask;    win_keymap_lazy_init();    win_keymap_lazy_bind();    if (!m)	m = keymap_from_fd[windowfd].smask =	            sv_bits_new_mask(SUNVIEW_LAST - SUNVIEW_FIRST + 1);    if (SUNVIEW_FIRST <= code && code <= SUNVIEW_LAST)	(void)sv_bits_set_mask(m, code - SUNVIEW_FIRST);}voidwin_keymap_unset_smask(windowfd, code)	int windowfd;	unsigned short code;{	Bitmask	*m = keymap_from_fd[windowfd].smask;	if (!m) return;	if (SUNVIEW_FIRST <= code && code <= SUNVIEW_LAST)		(void)sv_bits_unset_mask(m, code - SUNVIEW_FIRST);}intwin_keymap_get_smask(windowfd, code)	int windowfd;	unsigned short code;{	Bitmask	*m = keymap_from_fd[windowfd].smask;	if (!m) return 0;	return sv_bits_get_mask(m, code - SUNVIEW_FIRST);

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -