File: x_win32.c

package info (click to toggle)
mlterm 3.1.2-1.3
  • links: PTS, VCS
  • area: main
  • in suites: wheezy
  • size: 23,168 kB
  • sloc: ansic: 102,795; sh: 9,676; java: 2,018; perl: 1,601; makefile: 1,595; cpp: 771; sed: 16
file content (198 lines) | stat: -rw-r--r-- 3,407 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
/*
 *	$Id$
 */

#include  "x_win32.h"


#if  0
#include  <stdio.h>
#define  SELF_TEST
#endif


#define  TABLE_SIZE  (sizeof(keysym_table) / sizeof(keysym_table[0]))


static struct
{
	char *  str ;
	/* KeySym */ WORD  ksym ;	/* 16bit */

} keysym_table[] =
{
	{ "A" , 0x41 } ,
	{ "B" , 0x42 } ,
	{ "BackSpace" , XK_BackSpace } ,
	{ "C" , 0x43 } ,
	{ "D" , 0x44 } ,
	{ "Delete" , XK_Delete } ,
	{ "Down" , XK_Down } ,
	{ "E" , 0x45 } ,
	{ "End" , XK_End } ,
	{ "Escape" , XK_Escape } ,
	{ "F" , 0x46 } ,
	{ "F1" , XK_F1 } ,
	{ "F10" , XK_F10 } ,
	{ "F11" , XK_F11 } ,
	{ "F12" , XK_F12 } ,
	{ "F13" , XK_F13 } ,
	{ "F14" , XK_F14 } ,
	{ "F15" , XK_F15 } ,
	{ "F16" , XK_F16 } ,
	{ "F17" , XK_F17 } ,
	{ "F18" , XK_F18 } ,
	{ "F19" , XK_F19 } ,
	{ "F2" , XK_F2 } ,
	{ "F20" , XK_F20 } ,
	{ "F21" , XK_F21 } ,
	{ "F22" , XK_F22 } ,
	{ "F23" , XK_F23 } ,
	{ "F24" , XK_F24 } ,
	{ "F3" , XK_F3 } ,
	{ "F4" , XK_F4 } ,
	{ "F5" , XK_F5 } ,
	{ "F6" , XK_F6 } ,
	{ "F7" , XK_F7 } ,
	{ "F8" , XK_F8 } ,
	{ "F9" , XK_F9 } ,
	{ "G" , 0x47 } ,
	{ "H" , 0x48 } ,
	{ "Home" , XK_Home } ,
	{ "I" , 0x49 } ,
	{ "Insert" , XK_Insert } ,
	{ "J" , 0x4a } ,
	{ "K" , 0x4b } ,
	{ "L" , 0x4c } ,
	{ "Left" , XK_Left } ,
	{ "M" , 0x4d } ,
	{ "N" , 0x4e } ,
	{ "Next" , XK_Next } ,
	{ "O" , 0x4f } ,
	{ "P" , 0x50 } ,
	{ "Prior" , XK_Prior } ,
	{ "Q" , 0x51 } ,
	{ "R" , 0x52 } ,
	{ "Return" , XK_Return } ,
	{ "Right" , XK_Right } ,
	{ "S" , 0x53 } ,
	{ "T" , 0x54 } ,
	{ "Tab" , XK_Tab } ,
	{ "U" , 0x55 } ,
	{ "Up" , XK_Up } ,
	{ "V" , 0x56 } ,
	{ "W" , 0x57 } ,
	{ "X" , 0x58 } ,
	{ "Y" , 0x59 } ,
	{ "Z" , 0x5a } ,
	{ "space" , VK_SPACE } ,
} ;

/* --- global functions --- */

KeySym
XStringToKeysym(
	char *  str
	)
{
#ifdef  SELF_TEST
	int  debug_count = 0 ;
#endif
	size_t  prev_idx ;
	size_t  idx ;
	size_t  distance ;

	prev_idx = -1 ;

	/* +1 => roundup */
	idx = (TABLE_SIZE + 1) / 2 ;

	/* idx + distance == TABLE_SIZE - 1 */
	distance = TABLE_SIZE - idx - 1 ;

	while( 1)
	{
		int  cmp ;

		if( ( cmp = strcmp( keysym_table[idx].str , str)) == 0)
		{
		#ifdef  SELF_TEST
			fprintf( stderr , "%.2d/%.2d:" , debug_count , TABLE_SIZE) ;
		#endif

			return  keysym_table[idx].ksym ;
		}
		else
		{
			size_t  next_idx ;

		#ifdef  SELF_TEST
			debug_count ++ ;
		#endif

			/* +1 => roundup */
			if( ( distance = (distance + 1) / 2) == 0)
			{
				break ;
			}

			if( cmp > 0)
			{
				if( idx < distance)
				{
					/* idx - distance == 0 */
					distance = idx ;
				}

				next_idx = idx - distance ;
			}
			else /* if( cmp < 0) */
			{
				if( idx + distance >= TABLE_SIZE)
				{
					/* idx + distance == TABLE_SIZE - 1 */
					distance = TABLE_SIZE - idx - 1 ;
				}

				next_idx = idx + distance ;
			}

			if( next_idx == prev_idx)
			{
				break ;
			}

			prev_idx = idx ;
			idx = next_idx ;
		}
	}

	return  NoSymbol ;
}

#ifdef  SELF_TEST

int
main()
{
	size_t  count ;

	for( count = 0 ; count < TABLE_SIZE ; count++)
	{
		fprintf( stderr , "%x %x\n" ,
			XStringToKeysym( keysym_table[count].str) ,
			keysym_table[count].ksym) ;
		/*
		 * stderr isn't flushed without fflush() if
		 * XStringToKeysym() falls to infinite-loop.
		 */
		fflush( stderr) ;
	}

	fprintf( stderr , "%x\n" , XStringToKeysym( "a")) ; fflush( stderr) ;
	fprintf( stderr , "%x\n" , XStringToKeysym( "hoge")) ; fflush( stderr) ;
	fprintf( stderr , "%x\n" , XStringToKeysym( "zzzz")) ; fflush( stderr) ;

	return  1 ;
}
#endif