]>
git.proxmox.com Git - mirror_novnc.git/blob - utils/genkeysymdef.js
3 * genkeysymdef: X11 keysymdef.h to JavaScript converter
4 * Copyright 2013 jalf <git@jalf.dk>
5 * Copyright 2017 Pierre Ossman for Cendio AB
6 * Licensed under MPL 2.0 (see LICENSE.txt)
11 var fs
= require('fs');
13 var show_help
= process
.argv
.length
=== 2;
17 for (i
= 2; i
< process
.argv
.length
; ++i
) {
18 switch (process
.argv
[i
]) {
26 filename
= process
.argv
[i
];
32 console
.log("Error: No filename specified\n");
36 console
.log("Parses a *nix keysymdef.h to generate Unicode code point mappings");
37 console
.log("Usage: node parse.js [options] filename:");
38 console
.log(" -h [ --help ] Produce this help message");
39 console
.log(" filename The keysymdef.h file to parse");
43 var buf
= fs
.readFileSync(filename
);
44 var str
= buf
.toString('utf8');
46 var re
= /^#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/m;
48 var arr
= str
.split('\n');
52 for (i
= 0; i
< arr
.length
; ++i
) {
53 var result
= re
.exec(arr
[i
]);
55 var keyname
= result
[1];
56 var keysym
= parseInt(result
[2], 16);
57 var remainder
= result
[3];
59 var unicodeRes
= /U\+([0-9a-fA-F]+)/.exec(remainder
);
61 var unicode
= parseInt(unicodeRes
[1], 16);
62 // The first entry is the preferred one
63 if (!codepoints
[unicode
]){
64 codepoints
[unicode
] = { keysym
: keysym
, name
: keyname
};
72 " * Mapping from Unicode codepoints to X11/RFB keysyms\n" +
74 " * This file was automatically generated from keysymdef.h\n" +
78 "/* Functions at the bottom */\n" +
80 "var codepoints = {\n";
83 var s
= num
.toString(16);
85 s
= ("0000" + s
).slice(-4);
90 for (var codepoint
in codepoints
) {
91 codepoint
= parseInt(codepoint
);
94 if ((codepoint
>= 0x20) && (codepoint
<= 0xff)) {
98 // Handled by the general Unicode mapping?
99 if ((codepoint
| 0x01000000) === codepoints
[codepoint
].keysym
) {
103 out
+= " " + toHex(codepoint
) + ": " +
104 toHex(codepoints
[codepoint
].keysym
) +
105 ", // XK_" + codepoints
[codepoint
].name
+ "\n";
111 "export default {\n" +
112 " lookup : function(u) {\n" +
113 " // Latin-1 is one-to-one mapping\n" +
114 " if ((u >= 0x20) && (u <= 0xff)) {\n" +
118 " // Lookup table (fairly random)\n" +
119 " var keysym = codepoints[u];\n" +
120 " if (keysym !== undefined) {\n" +
121 " return keysym;\n" +
124 " // General mapping as final fallback\n" +
125 " return 0x01000000 | u;\n" +