Annotation of sys/arch/hppa/gsc/makemap.awk, Revision 1.1.1.1
1.1 nbrk 1: #! /usr/bin/awk -f
2: # $OpenBSD: makemap.awk,v 1.6 2005/05/12 16:21:23 miod Exp $
3: #
4: # Copyright (c) 2003, 2005, Miodrag Vallat.
5: # All rights reserved.
6: #
7: # Redistribution and use in source and binary forms, with or without
8: # modification, are permitted provided that the following conditions
9: # are met:
10: # 1. Redistributions of source code must retain the above copyright
11: # notice, this list of conditions and the following disclaimer.
12: # 2. Redistributions in binary form must reproduce the above copyright
13: # notice, this list of conditions and the following disclaimer in the
14: # documentation and/or other materials provided with the distribution.
15: #
16: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
17: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES
18: # OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED.
19: # IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT,
20: # INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT
21: # NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
22: # DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY
23: # THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT
24: # (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF
25: # THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
26: #
27:
28: #
29: # This script attempts to convert, with minimal hacks and losses, the
30: # regular PS/2 keyboard (pckbd) layout tables into GSC keyboard (gsckbd)
31: # layout tables, as almost all scancodes are completely different in the
32: # GSC world.
33: #
34:
35: BEGIN {
36: rcsid = "$OpenBSD: makemap.awk,v 1.6 2005/05/12 16:21:23 miod Exp $"
37: ifdepth = 0
38: ignore = 0
39: mapnum = 0
40: declk = 0
41:
42: # PS/2 id -> GSCKBD conversion table, or "sanity lossage 101"
43: for (i = 0; i < 256; i++)
44: conv[i] = -1
45:
46: conv[1] = 118
47: conv[2] = 22
48: conv[3] = 30
49: conv[4] = 38
50: conv[5] = 37
51: conv[6] = 46
52: conv[7] = 54
53: conv[8] = 61
54: conv[9] = 62
55: conv[10] = 70
56: conv[11] = 69
57: conv[12] = 78
58: conv[13] = 85
59: conv[14] = 102
60: conv[15] = 13
61: conv[16] = 21
62: conv[17] = 29
63: conv[18] = 36
64: conv[19] = 45
65: conv[20] = 44
66: conv[21] = 53
67: conv[22] = 60
68: conv[23] = 67
69: conv[24] = 68
70: conv[25] = 77
71: conv[26] = 84
72: conv[27] = 91
73: conv[28] = 90
74: conv[29] = 20
75: conv[30] = 28
76: conv[31] = 27
77: conv[32] = 35
78: conv[33] = 43
79: conv[34] = 52
80: conv[35] = 51
81: conv[36] = 59
82: conv[37] = 66
83: conv[38] = 75
84: conv[39] = 76
85: conv[40] = 82
86: conv[41] = 14
87: conv[42] = 18
88: conv[43] = 93
89: conv[44] = 26
90: conv[45] = 34
91: conv[46] = 33
92: conv[47] = 42
93: conv[48] = 50
94: conv[49] = 49
95: conv[50] = 58
96: conv[51] = 65
97: conv[52] = 73
98: conv[53] = 74
99: conv[54] = 89
100: conv[55] = 124
101: conv[56] = 17
102: conv[57] = 41
103: conv[58] = 88
104: conv[59] = 5
105: conv[60] = 6
106: conv[61] = 4
107: conv[62] = 12
108: conv[63] = 3
109: conv[64] = 11
110: conv[65] = 131
111: conv[66] = 10
112: conv[67] = 1
113: conv[68] = 9
114: conv[69] = 119
115: conv[70] = 126
116: conv[71] = 108
117: conv[72] = 117
118: conv[73] = 125
119: conv[74] = 123
120: conv[75] = 107
121: conv[76] = 115
122: conv[77] = 116
123: conv[78] = 121
124: conv[79] = 105
125: conv[80] = 114
126: conv[81] = 122
127: conv[82] = 112
128: conv[83] = 113
129: conv[86] = 97
130: conv[87] = 120
131: conv[88] = 7
132: # 112 used by jp
133: # 115 used by jp and br
134: # 121 used by jp
135: # 123 used by jp
136: # 125 used by jp
137: conv[127] = 127
138: conv[156] = 218
139: conv[157] = 148
140: # Print Screen produces E0 12 E0 7C when pressed, then E0 7C E0 12
141: # when released. Ignore the E0 12 code and match only on E0 7C
142: conv[170] = 252
143: conv[181] = 202
144: conv[184] = 145
145: conv[198] = 254
146: conv[199] = 236
147: conv[200] = 245
148: conv[201] = 253
149: conv[203] = 235
150: conv[205] = 244
151: conv[207] = 233
152: conv[208] = 242
153: conv[209] = 250
154: conv[210] = 240
155: conv[211] = 113
156: }
157: NR == 1 {
158: VERSION = $0
159: gsub("\\$", "", VERSION)
160: gsub("\\$", "", rcsid)
161:
162: printf("/*\t\$OpenBSD\$\t*/\n\n")
163: printf("/*\n")
164: printf(" * THIS FILE IS AUTOMAGICALLY GENERATED. DO NOT EDIT.\n")
165: printf(" *\n")
166: printf(" * generated by:\n")
167: printf(" *\t%s\n", rcsid)
168: printf(" * generated from:\n")
169: printf(" */\n")
170: print VERSION
171:
172: next
173: }
174:
175: #
176: # A very limited #if ... #endif parser. We only want to correctly detect
177: # ``#if 0'' constructs, so as not to process their contents. This is necessary
178: # since our output is out-of-order from our input.
179: #
180: # Note that this does NOT handle ``#ifdef notyet'' correctly - please only use
181: # ``#if 0'' constructs in the input.
182: #
183:
184: /^#if/ {
185: ignores[ifdepth] = ignore
186: if ($2 == "0")
187: ignore = 1
188: else
189: ignore = 0
190: ifdepth++
191: if (ignore)
192: next
193: }
194: /^#endif/ {
195: oldignore = ignore
196: ifdepth--
197: ignore = ignores[ifdepth]
198: ignores[ifdepth] = 0
199: if (oldignore)
200: next
201: }
202:
203: $1 == "#include" {
204: if (ignore)
205: next
206: if ($2 == "<dev/pckbc/wskbdmap_mfii.h>")
207: print "#include <hppa/gsc/gsckbdmap.h>"
208: else
209: printf("#include %s\n", $2)
210:
211: next
212: }
213: $1 == "#define" || $1 == "#undef" {
214: if (ignore)
215: next
216: print $0
217: next
218: }
219:
220: # Don't bother converting the DEC LK layout.
221: /declk\[/ {
222: declk = 1
223: next
224: }
225: /declk/ {
226: next
227: }
228:
229: /pckbd/ {
230: if (ignore)
231: next
232: gsub("pckbd", "gsckbd", $0)
233: print $0
234: next
235: }
236:
237: /KC/ {
238: if (ignore)
239: next
240:
241: if (declk)
242: next
243:
244: sidx = substr($1, 4, length($1) - 5)
245: orig = int(sidx)
246: id = conv[orig]
247:
248: # 183 is another Print Screen...
249: if (orig == 183)
250: next
251:
252: if (id == -1) {
253: printf("/* initially KC(%d),", orig)
254: for (f = 2; f <= NF; f++) {
255: if ($f != "/*" && $f != "*/")
256: printf("\t%s", $f)
257: }
258: printf("\t*/\n")
259: } else {
260: lines[id] = sprintf(" KC(%d),\t", id)
261: #
262: # This makes sure that the non-comment part of the output
263: # ends up with a trailing comma. This is necessary since
264: # the last line of an input block might not have a trailing
265: # comma, but might not be the last line of an output block
266: # due to sorting.
267: #
268: comma = 0
269: for (f = 2; f <= NF; f++) {
270: l = length($f)
271: if ($f == "/*")
272: comma++
273: if (comma == 0 && substr($f, l) != ",") {
274: lines[id] = sprintf("%s%s,", lines[id], $f)
275: l++
276: } else {
277: lines[id] = sprintf("%s%s", lines[id], $f)
278: }
279: if (comma == 0 && f != NF) {
280: if (l < 2 * 8)
281: lines[id] = lines[id] "\t"
282: if (l < 8)
283: lines[id] = lines[id] "\t"
284: }
285: if ($f == "*/")
286: comma--
287: }
288: }
289:
290: next
291: }
292: /};/ {
293: if (ignore)
294: next
295:
296: if (declk) {
297: declk = 0
298: next
299: }
300:
301: for (i = 0; i < 256; i++)
302: if (lines[i]) {
303: print lines[i]
304: lines[i] = ""
305: }
306:
307: if (mapnum == 0) {
308: # Add 241 to the US map...
309: print " KC(241),\tKS_Delete"
310: print $0
311: print "\nstatic const keysym_t gsckbd_keydesc_precisionbook[] = {"
312: print "/* pos command\t\tnormal shifted */"
313: print " KC(7), KS_Cmd_Screen0,\tKS_f1,"
314: print " KC(15), KS_Cmd_Screen1,\tKS_f2,"
315: print " KC(23), KS_Cmd_Screen2,\tKS_f3,"
316: print " KC(31), KS_Cmd_Screen3,\tKS_f4,"
317: print " KC(39), KS_Cmd_Screen4,\tKS_f5,"
318: print " KC(47), KS_Cmd_Screen5,\tKS_f6,"
319: print " KC(55), KS_Cmd_Screen6,\tKS_f7,"
320: print " KC(63), KS_Cmd_Screen7,\tKS_f8,"
321: print " KC(71), KS_Cmd_Screen8,\tKS_f9,"
322: print " KC(79), KS_Cmd_Screen9,\tKS_f10,"
323: print " KC(86), KS_Cmd_Screen10,\tKS_f11,"
324: print " KC(94), KS_Cmd_Screen11,\tKS_f12,"
325: print " KC(8), KS_Cmd_Debugger,\tKS_Escape,"
326: print " KC(87),\t\t\tKS_Print_Screen,"
327: print " KC(92),\t\t\tKS_backslash,\tKS_bar,"
328: print " KC(96),\t\t\tKS_KP_Down,\tKS_KP_2,"
329: print " KC(95),\t\t\tKS_Hold_Screen,"
330: print " KC(97),\t\t\tKS_KP_Left,\tKS_KP_4,"
331: print " KC(98),\t\t\tKS_Pause, /* Break */"
332: print " KC(99),\t\t\tKS_KP_Up,\tKS_KP_8,"
333: print " KC(100),\t\t\tKS_KP_Delete,\tKS_KP_Decimal,"
334: print " KC(101),\t\t\tKS_KP_End,\tKS_KP_1,"
335: print " KC(103),\t\t\tKS_KP_Insert,\tKS_KP_0,"
336: print " KC(106),\t\t\tKS_KP_Right,\tKS_KP_6,"
337: print " KC(109),\t\t\tKS_KP_Next,\tKS_KP_3,"
338: print " KC(110),\t\t\tKS_KP_Home,\tKS_KP_7,"
339: print " KC(111),\t\t\tKS_KP_Prior,\tKS_KP_9,"
340: print " KC(20),\t\t\tKS_Caps_Lock,"
341: print " KC(17), KS_Cmd1,\t\tKS_Control_L,"
342: print " KC(88), KS_Cmd1,\t\tKS_Control_R,"
343: print " KC(25), KS_Cmd2,\t\tKS_Alt_L,"
344: print " KC(57), KS_Cmd2,\t\tKS_Alt_R,\tKS_Multi_key,"
345: print " KC(139),\t\t\tKS_Meta_L,"
346: print " KC(140),\t\t\tKS_Meta_R,"
347: }
348: mapnum++
349: }
350: /{0, 0, 0, 0}/ {
351: printf("\tKBD_MAP(KB_US | KB_MACHDEP,\tKB_US,\tgsckbd_keydesc_precisionbook),\n");
352: }
353: {
354: if (ignore)
355: next
356: if (declk)
357: next
358: print $0
359: }
CVSweb