Annotation of sys/dev/usb/makemap.awk, Revision 1.1
1.1 ! nbrk 1: #! /usr/bin/awk -f
! 2: # $OpenBSD: makemap.awk,v 1.7 2007/06/17 07:53:11 mbalmer Exp $
! 3: #
! 4: # Copyright (c) 2005, Miodrag Vallat
! 5: #
! 6: # Redistribution and use in source and binary forms, with or without
! 7: # modification, are permitted provided that the following conditions
! 8: # are met:
! 9: # 1. Redistributions of source code must retain the above copyright
! 10: # notice, this list of conditions and the following disclaimer.
! 11: # 2. Redistributions in binary form must reproduce the above copyright
! 12: # notice, this list of conditions and the following disclaimer in the
! 13: # documentation and/or other materials provided with the distribution.
! 14: #
! 15: # THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR
! 16: # IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED
! 17: # WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
! 18: # DISCLAIMED. IN NO EVENT SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT,
! 19: # INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
! 20: # (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
! 21: # SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
! 22: # HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
! 23: # STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN
! 24: # ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
! 25: # POSSIBILITY OF SUCH DAMAGE.
! 26: #
! 27: #
! 28: # This script attempts to convert, with minimal hacks and losses, the
! 29: # regular PS/2 keyboard (pckbd) layout tables into USB keyboard (ukbd)
! 30: # layout tables.
! 31: #
! 32:
! 33: BEGIN {
! 34: rcsid = "$OpenBSD: makemap.awk,v 1.7 2007/06/17 07:53:11 mbalmer Exp $"
! 35: ifdepth = 0
! 36: ignore = 0
! 37: declk = 0
! 38: haskeys = 0
! 39: kbfr = 0
! 40:
! 41: # PS/2 id -> UKBD conversion table, or "sanity lossage 102"
! 42: # (101 is for GSC keyboards!)
! 43: for (i = 0; i < 256; i++)
! 44: conv[i] = -1
! 45:
! 46: conv[1] = 41
! 47: conv[2] = 30
! 48: conv[3] = 31
! 49: conv[4] = 32
! 50: conv[5] = 33
! 51: conv[6] = 34
! 52: conv[7] = 35
! 53: conv[8] = 36
! 54: conv[9] = 37
! 55: conv[10] = 38
! 56: conv[11] = 39
! 57: conv[12] = 45
! 58: conv[13] = 46
! 59: conv[14] = 42
! 60: conv[15] = 43
! 61: conv[16] = 20
! 62: conv[17] = 26
! 63: conv[18] = 8
! 64: conv[19] = 21
! 65: conv[20] = 23
! 66: conv[21] = 28
! 67: conv[22] = 24
! 68: conv[23] = 12
! 69: conv[24] = 18
! 70: conv[25] = 19
! 71: conv[26] = 47
! 72: conv[27] = 48
! 73: conv[28] = 40
! 74: conv[29] = 224
! 75: conv[30] = 4
! 76: conv[31] = 22
! 77: conv[32] = 7
! 78: conv[33] = 9
! 79: conv[34] = 10
! 80: conv[35] = 11
! 81: conv[36] = 13
! 82: conv[37] = 14
! 83: conv[38] = 15
! 84: conv[39] = 51
! 85: conv[40] = 52
! 86: conv[41] = 53
! 87: conv[42] = 225
! 88: conv[43] = 50
! 89: conv[44] = 29
! 90: conv[45] = 27
! 91: conv[46] = 6
! 92: conv[47] = 25
! 93: conv[48] = 5
! 94: conv[49] = 17
! 95: conv[50] = 16
! 96: conv[51] = 54
! 97: conv[52] = 55
! 98: conv[53] = 56
! 99: conv[54] = 229
! 100: conv[55] = 85
! 101: conv[56] = 226
! 102: conv[57] = 44
! 103: conv[58] = 57
! 104: conv[59] = 58
! 105: conv[60] = 59
! 106: conv[61] = 60
! 107: conv[62] = 61
! 108: conv[63] = 62
! 109: conv[64] = 63
! 110: conv[65] = 64
! 111: conv[66] = 65
! 112: conv[67] = 66
! 113: conv[68] = 67
! 114: conv[69] = 83
! 115: conv[70] = 71
! 116: conv[71] = 95
! 117: conv[72] = 96
! 118: conv[73] = 97
! 119: conv[74] = 86
! 120: conv[75] = 92
! 121: conv[76] = 93
! 122: conv[77] = 94
! 123: conv[78] = 87
! 124: conv[79] = 89
! 125: conv[80] = 90M
! 126: conv[81] = 91
! 127: conv[82] = 98
! 128: conv[83] = 99
! 129: conv[86] = 100
! 130: conv[87] = 68
! 131: conv[88] = 69
! 132: conv[112] = 135
! 133: conv[115] = 136
! 134: conv[121] = 137
! 135: conv[123] = 138
! 136: conv[125] = 139
! 137: conv[127] = 72
! 138: conv[156] = 88
! 139: conv[157] = 228
! 140: conv[170] = 70
! 141: conv[181] = 84
! 142: conv[184] = 230
! 143: # 198 is #if 0 in the PS/2 map...
! 144: conv[199] = 74
! 145: conv[200] = 82
! 146: conv[201] = 75
! 147: conv[203] = 80
! 148: conv[205] = 79
! 149: conv[207] = 77
! 150: conv[208] = 81
! 151: conv[209] = 78
! 152: conv[210] = 73
! 153: conv[211] = 99
! 154: conv[219] = 227
! 155: conv[220] = 231
! 156: conv[221] = 101
! 157: }
! 158: NR == 1 {
! 159: VERSION = $0
! 160: gsub("\\$", "", VERSION)
! 161: gsub("\\$", "", rcsid)
! 162:
! 163: printf("/*\t\$OpenBSD\$\t*/\n\n")
! 164: printf("/*\n")
! 165: printf(" * THIS FILE IS AUTOMAGICALLY GENERATED. DO NOT EDIT.\n")
! 166: printf(" *\n")
! 167: printf(" * generated by:\n")
! 168: printf(" *\t%s\n", rcsid)
! 169: printf(" * generated from:\n")
! 170: printf(" */\n")
! 171: print VERSION
! 172:
! 173: next
! 174: }
! 175:
! 176: #
! 177: # A very limited #if ... #endif parser. We only want to correctly detect
! 178: # ``#if 0'' constructs, so as not to process their contents. This is necessary
! 179: # since our output is out-of-order from our input.
! 180: #
! 181: # Note that this does NOT handle ``#ifdef notyet'' correctly - please only use
! 182: # ``#if 0'' constructs in the input.
! 183: #
! 184:
! 185: /^#if/ {
! 186: ignores[ifdepth] = ignore
! 187: if ($2 == "0")
! 188: ignore = 1
! 189: else
! 190: ignore = 0
! 191: ifdepth++
! 192: if (ignore)
! 193: next
! 194: }
! 195: /^#endif/ {
! 196: oldignore = ignore
! 197: ifdepth--
! 198: ignore = ignores[ifdepth]
! 199: ignores[ifdepth] = 0
! 200: if (oldignore)
! 201: next
! 202: }
! 203:
! 204: $1 == "#include" {
! 205: if (ignore)
! 206: next
! 207: if ($2 == "<dev/pckbc/wskbdmap_mfii.h>")
! 208: next
! 209: printf("#include %s\n", $2)
! 210: next
! 211: }
! 212: $1 == "#define" || $1 == "#undef" {
! 213: if (ignore)
! 214: next
! 215: print $0
! 216: next
! 217: }
! 218:
! 219: # Don't bother converting the DEC LK layout.
! 220: /declk\[/ {
! 221: declk = 1
! 222: next
! 223: }
! 224: /declk/ {
! 225: next
! 226: }
! 227:
! 228: /pckbd/ {
! 229: gsub("pckbd", "ukbd", $0)
! 230: mapname = $4
! 231: }
! 232:
! 233: /KC/ {
! 234: if (ignore)
! 235: next
! 236:
! 237: if (declk)
! 238: next
! 239:
! 240: haskeys = 1
! 241:
! 242: sidx = substr($1, 4, length($1) - 5)
! 243: orig = int(sidx)
! 244: id = conv[orig]
! 245:
! 246: # 183 is another Print Screen...
! 247: if (orig == 183)
! 248: next
! 249:
! 250: if (id == -1) {
! 251: printf("/* initially KC(%d),", orig)
! 252: for (f = 2; f <= NF; f++) {
! 253: if ($f != "/*" && $f != "*/")
! 254: printf("\t%s", $f)
! 255: }
! 256: printf("\t*/\n")
! 257: } else {
! 258: lines[id] = sprintf(" KC(%d),\t", id)
! 259: #
! 260: # This makes sure that the non-comment part of the output
! 261: # ends up with a trailing comma. This is necessary since
! 262: # the last line of an input block might not have a trailing
! 263: # comma, but might not be the last line of an output block
! 264: # due to sorting.
! 265: #
! 266: comma = 0
! 267: for (f = 2; f <= NF; f++) {
! 268: l = length($f)
! 269: if ($f == "/*")
! 270: comma++
! 271: if (comma == 0 && substr($f, l) != ",") {
! 272: lines[id] = sprintf("%s%s,", lines[id], $f)
! 273: l++
! 274: } else {
! 275: lines[id] = sprintf("%s%s", lines[id], $f)
! 276: }
! 277: if (comma == 0 && f != NF) {
! 278: if (l < 2 * 8)
! 279: lines[id] = lines[id] "\t"
! 280: if (l < 8)
! 281: lines[id] = lines[id] "\t"
! 282: }
! 283: if ($f == "*/")
! 284: comma--
! 285: }
! 286: }
! 287:
! 288: next
! 289: }
! 290: /};/ {
! 291: if (ignore)
! 292: next
! 293:
! 294: if (declk) {
! 295: declk = 0
! 296: next
! 297: }
! 298:
! 299: if (haskeys) {
! 300: # Duplicate 42 (backspace) as 76 and 50 (backslash bar) as 49
! 301: if (!lines[76]) {
! 302: lines[76] = lines[42]
! 303: sub("42", "76", lines[76])
! 304: }
! 305: if (!lines[49]) {
! 306: lines[49] = lines[50]
! 307: sub("50", "49", lines[49])
! 308: }
! 309:
! 310: for (i = 0; i < 256; i++)
! 311: if (lines[i]) {
! 312: print lines[i]
! 313: lines[i] = ""
! 314: }
! 315:
! 316: haskeys = 0
! 317:
! 318: #
! 319: # Apple black USB keyboards use a slightly different
! 320: # layout. We define them here.
! 321: #
! 322: if (mapname == "ukbd_keydesc_fr[]") {
! 323: print $0
! 324: print "\nstatic const keysym_t ukbd_keydesc_fr_apple[] = {"
! 325: print " KC(5),\tKS_b,\t\tKS_B,\t\tKS_ssharp,"
! 326: print " KC(8),\tKS_e,\t\tKS_E,\t\tKS_ecircumflex,\tKS_Ecircumflex,"
! 327: print " KC(11),\tKS_h,\t\tKS_H,\t\tKS_Igrave,\tKS_Icircumflex,"
! 328: print " KC(12),\tKS_i,\t\tKS_I,\t\tKS_icircumflex,\tKS_idiaeresis,"
! 329: print " KC(13),\tKS_j,\t\tKS_J,\t\tKS_Idiaeresis,\tKS_Iacute,"
! 330: print " KC(14),\tKS_k,\t\tKS_K,\t\tKS_Egrave,\tKS_Ediaeresis,"
! 331: print " KC(15),\tKS_l,\t\tKS_L,\t\tKS_voidSymbol,\tKS_bar,"
! 332: print " KC(16),\tKS_comma,\tKS_question,\tKS_voidSymbol,\tKS_questiondown,"
! 333: print " KC(17),\tKS_n,\t\tKS_N,\t\tKS_asciitilde,"
! 334: print " KC(20),\tKS_a,\t\tKS_A,\t\tKS_ae,\t\tKS_AE,"
! 335: print " KC(21),\tKS_r,\t\tKS_R,\t\tKS_registered,\tKS_comma,"
! 336: print " KC(22),\tKS_s,\t\tKS_S,\t\tKS_Ograve,"
! 337: print " KC(26),\tKS_z,\t\tKS_Z,\t\tKS_Acircumflex,\tKS_Aring,"
! 338: print " KC(28),\tKS_y,\t\tKS_Y,\t\tKS_Uacute,"
! 339: print " KC(31),\tKS_eacute,\tKS_2,\t\tKS_ediaeresis,"
! 340: print " KC(32),\tKS_quotedbl,\tKS_3,"
! 341: print " KC(33),\tKS_apostrophe,\tKS_4,"
! 342: print " KC(34),\tKS_parenleft,\tKS_5,\t\tKS_braceleft,\tKS_bracketleft,"
! 343: print " KC(35),\tKS_section,\tKS_6,"
! 344: print " KC(36),\tKS_egrave,\tKS_7,\t\tKS_guillemotleft,"
! 345: print "\t\t\t\t\t\tKS_guillemotright,"
! 346: print " KC(37),\tKS_exclam,\tKS_8,"
! 347: print " KC(38),\tKS_ccedilla,\tKS_9,\t\tKS_Ccedilla,\tKS_Aacute,"
! 348: print " KC(37),\tKS_exclam,\tKS_8,\t\tKS_exclamdown,\tKS_Ucircumflex,"
! 349: print " KC(39),\tKS_agrave,\tKS_0,\t\tKS_oslash,\tKS_Ooblique,"
! 350: print " KC(45),\tKS_parenright,\tKS_degree,\tKS_braceright,\tKS_bracketright,"
! 351: print " KC(46),\tKS_minus,\tKS_underscore,"
! 352: print " KC(47),\tKS_dead_circumflex, KS_dead_diaeresis,"
! 353: print "\t\t\t\t\t\tKS_ocircumflex,\tKS_Ocircumflex,"
! 354: print " KC(48),\tKS_dollar,\tKS_asterisk,\tKS_cent,\tKS_yen,"
! 355: print " KC(50),\tKS_grave,\tKS_sterling,\tKS_at,\t\tKS_numbersign,"
! 356: print " KC(51),\tKS_m,\t\tKS_M,\t\tKS_mu,\t\tKS_Oacute,"
! 357: print " KC(52),\tKS_ugrave,\tKS_percent,\tKS_Ugrave,"
! 358: print " KC(53),\tKS_at,\t\tKS_numbersign,"
! 359: print " KC(55),\tKS_colon,\tKS_slash,\tKS_voidSymbol,\tKS_backslash,"
! 360: print " KC(56),\tKS_equal,\tKS_plus,"
! 361: print " KC(103),\tKS_KP_Equal,"
! 362: print " KC(231),\tKS_Mode_switch,\tKS_Multi_key,"
! 363: } else
! 364: if (mapname == "ukbd_keydesc_pt[]") {
! 365: print $0
! 366: print "\nstatic const keysym_t ukbd_keydesc_pt_apple[] = {"
! 367: print "/* pos\t\tnormal\t\tshifted */"
! 368: print " KC(46),\tKS_plus,\tKS_asterisk,"
! 369: print " KC(47),\tKS_masculine,\tKS_ordfeminine,"
! 370: print " KC(50),\tKS_backslash,\tKS_bar,"
! 371: print " KC(52),\tKS_dead_tilde,\tKS_dead_circumflex"
! 372: }
! 373: }
! 374: }
! 375: /KB_FR/ {
! 376: print $0
! 377: if (kbfr++ == 0) {
! 378: print "\tKBD_MAP(KB_FR | KB_APPLE,\tKB_FR,\tukbd_keydesc_fr_apple),"
! 379: } else {
! 380: print "\tKBD_MAP(KB_FR | KB_APPLE | KB_SWAPCTRLCAPS,\tKB_FR | KB_APPLE,"
! 381: print "\t\tukbd_keydesc_swapctrlcaps),"
! 382: }
! 383: next
! 384: }
! 385: /KB_PT/ {
! 386: print $0
! 387: print "\tKBD_MAP(KB_PT | KB_APPLE,\tKB_PT,\tukbd_keydesc_pt_apple),"
! 388: next
! 389: }
! 390: {
! 391: if (ignore)
! 392: next
! 393: if (declk)
! 394: next
! 395: print $0
! 396: }
CVSweb