]>
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;
16 for (var i
= 2; i
< process
.argv
.length
; ++i
) {
17 switch (process
.argv
[i
]) {
25 filename
= process
.argv
[i
];
31 console
.log("Error: No filename specified\n");
35 console
.log("Parses a *nix keysymdef.h to generate Unicode code point mappings");
36 console
.log("Usage: node parse.js [options] filename:");
37 console
.log(" -h [ --help ] Produce this help message");
38 console
.log(" filename The keysymdef.h file to parse");
42 var buf
= fs
.readFileSync(filename
);
43 var str
= buf
.toString('utf8');
45 var re
= /^\#define XK_([a-zA-Z_0-9]+)\s+0x([0-9a-fA-F]+)\s*(\/\*\s*(.*)\s*\*\/)?\s*$/m;
47 var arr
= str
.split('\n');
51 for (var i
= 0; i
< arr
.length
; ++i
) {
52 var result
= re
.exec(arr
[i
]);
54 var keyname
= result
[1];
55 var keysym
= parseInt(result
[2], 16);
56 var remainder
= result
[3];
58 var unicodeRes
= /U\+([0-9a-fA-F]+)/.exec(remainder
);
60 var unicode
= parseInt(unicodeRes
[1], 16);
61 // The first entry is the preferred one
62 if (!codepoints
[unicode
]){
63 codepoints
[unicode
] = { keysym
: keysym
, name
: keyname
};
71 " * Mapping from Unicode codepoints to X11/RFB keysyms\n" +
73 " * This file was automatically generated from keysymdef.h\n" +
77 "/* Functions at the bottom */\n" +
79 "var codepoints = {\n";
82 var s
= num
.toString(16);
84 s
= ("0000" + s
).slice(-4);
89 for (var codepoint
in codepoints
) {
90 codepoint
= parseInt(codepoint
);
93 if ((codepoint
>= 0x20) && (codepoint
<= 0xff)) {
97 // Handled by the general Unicode mapping?
98 if ((codepoint
| 0x01000000) === codepoints
[codepoint
].keysym
) {
102 out
+= " " + toHex(codepoint
) + ": " +
103 toHex(codepoints
[codepoint
].keysym
) +
104 ", // XK_" + codepoints
[codepoint
].name
+ "\n";
110 "export default {\n" +
111 " lookup : function(u) {\n" +
112 " // Latin-1 is one-to-one mapping\n" +
113 " if ((u >= 0x20) && (u <= 0xff)) {\n" +
117 " // Lookup table (fairly random)\n" +
118 " var keysym = codepoints[u];\n" +
119 " if (keysym !== undefined) {\n" +
120 " return keysym;\n" +
123 " // General mapping as final fallback\n" +
124 " return 0x01000000 | u;\n" +