Skip to content

Commit 49c6358

Browse files
authored
Move create_dom_pk_codes to tools/maint. NFC (#24016)
1 parent 674bf95 commit 49c6358

File tree

4 files changed

+60
-50
lines changed

4 files changed

+60
-50
lines changed

pyproject.toml

+1-1
Original file line numberDiff line numberDiff line change
@@ -80,13 +80,13 @@ conf\.py |
8080
emrun\.py |
8181
site/source/_themes/ |
8282
tools/scons/site_scons/site_tools/emscripten/__init__\.py |
83+
tools/maint/create_dom_pk_codes.py |
8384
site/source/get_wiki\.py |
8485
test/parse_benchmark_output\.py
8586
)'''
8687

8788
[[tool.mypy.overrides]]
8889
module = [
89-
"tools.create_dom_pk_codes",
9090
"tools.webidl_binder",
9191
"tools.toolchain_profiler",
9292
"tools.filelock",

system/include/emscripten/dom_pk_codes.h

+3-3
Original file line numberDiff line numberDiff line change
@@ -5,10 +5,10 @@
55
* found in the LICENSE file.
66
*
77
* This file was automatically generated from script
8-
* tools/create_dom_pk_codes.py. Edit that file to make changes here.
9-
* Run
8+
* tools/maint/create_dom_pk_codes.py. Edit that file to make changes here.
9+
* Then run:
1010
*
11-
* tools/create_dom_pk_codes.py
11+
* tools/maint/create_dom_pk_codes.py
1212
*
1313
* in Emscripten root directory to regenerate this file.
1414
*/

system/lib/html5/dom_pk_codes.c

+20-20
Original file line numberDiff line numberDiff line change
@@ -1,27 +1,29 @@
1-
/* This file was automatically generated from script
2-
tools/create_dom_pk_codes.py. Edit that file to make changes here.
3-
Run
4-
5-
python tools/create_dom_pk_codes.py
6-
7-
in Emscripten root directory to regenerate this file. */
1+
/*
2+
* This file was automatically generated from script
3+
* tools/maint/create_dom_pk_codes.py. Edit that file to make changes here.
4+
* Then run:
5+
*
6+
* tools/maint/create_dom_pk_codes.py
7+
*
8+
* in Emscripten root directory to regenerate this file.
9+
*/
810

911
#include <emscripten/dom_pk_codes.h>
1012

11-
DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString)
12-
{
13+
DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString) {
1314
if (!keyCodeString) return 0;
1415

1516
/* Compute the collision free hash. */
1617
unsigned int hash = 0;
17-
while(*keyCodeString) hash = ((hash ^ 0x7E057D79U) << 3) ^ (unsigned int)*keyCodeString++;
18-
19-
/* Don't expose the hash values out to the application, but map to fixed IDs. This is useful for
20-
mapping back codes to MDN documentation page at
18+
while (*keyCodeString) hash = ((hash ^ 0x7E057D79U) << 3) ^ (unsigned int)*keyCodeString++;
2119

22-
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code */
23-
switch(hash)
24-
{
20+
/*
21+
* Don't expose the hash values out to the application, but map to fixed IDs.
22+
* This is useful for mapping back codes to MDN documentation page at
23+
*
24+
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code
25+
*/
26+
switch (hash) {
2527
case 0x98051284U /* Unidentified */: return DOM_PK_UNKNOWN; /* 0x0000 */
2628
case 0x67243A2DU /* Escape */: return DOM_PK_ESCAPE; /* 0x0001 */
2729
case 0x67251058U /* Digit0 */: return DOM_PK_0; /* 0x0002 */
@@ -183,10 +185,8 @@ DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString)
183185
}
184186
}
185187

186-
const char *emscripten_dom_pk_code_to_string(DOM_PK_CODE_TYPE code)
187-
{
188-
switch(code)
189-
{
188+
const char *emscripten_dom_pk_code_to_string(DOM_PK_CODE_TYPE code) {
189+
switch (code) {
190190
case DOM_PK_UNKNOWN: return "DOM_PK_UNKNOWN";
191191
case DOM_PK_ESCAPE: return "DOM_PK_ESCAPE";
192192
case DOM_PK_0: return "DOM_PK_0";

tools/create_dom_pk_codes.py renamed to tools/maint/create_dom_pk_codes.py

+36-26
Original file line numberDiff line numberDiff line change
@@ -30,6 +30,7 @@
3030

3131
# Use #include <emscripten/dom_pk_codes.h> in your code to access these IDs.
3232

33+
import os
3334
import sys
3435
import random
3536

@@ -276,8 +277,16 @@ def longest_key_code_length():
276277
return max(map(len, [x[1] for x in input_strings]))
277278

278279

279-
h_file = open('system/include/emscripten/dom_pk_codes.h', 'w')
280-
c_file = open('system/lib/html5/dom_pk_codes.c', 'w')
280+
script_dir = os.path.dirname(os.path.abspath(__file__))
281+
root = os.path.dirname(os.path.dirname(script_dir))
282+
283+
h_filename = os.path.join(root, 'system/include/emscripten/dom_pk_codes.h')
284+
c_filename = os.path.join(root, 'system/lib/html5/dom_pk_codes.c')
285+
print(f'Writing: {h_filename}')
286+
print(f'Writing: {c_filename}')
287+
h_file = open(h_filename, 'w')
288+
c_file = open(c_filename, 'w')
289+
281290

282291
# Generate the output file:
283292

@@ -289,10 +298,10 @@ def longest_key_code_length():
289298
* found in the LICENSE file.
290299
*
291300
* This file was automatically generated from script
292-
* tools/create_dom_pk_codes.py. Edit that file to make changes here.
293-
* Run
301+
* tools/maint/create_dom_pk_codes.py. Edit that file to make changes here.
302+
* Then run:
294303
*
295-
* tools/create_dom_pk_codes.py
304+
* tools/maint/create_dom_pk_codes.py
296305
*
297306
* in Emscripten root directory to regenerate this file.
298307
*/
@@ -303,13 +312,16 @@ def longest_key_code_length():
303312
304313
''')
305314

306-
c_file.write('''/* This file was automatically generated from script
307-
tools/create_dom_pk_codes.py. Edit that file to make changes here.
308-
Run
309-
310-
python tools/create_dom_pk_codes.py
311-
312-
in Emscripten root directory to regenerate this file. */
315+
c_file.write('''\
316+
/*
317+
* This file was automatically generated from script
318+
* tools/maint/create_dom_pk_codes.py. Edit that file to make changes here.
319+
* Then run:
320+
*
321+
* tools/maint/create_dom_pk_codes.py
322+
*
323+
* in Emscripten root directory to regenerate this file.
324+
*/
313325
314326
#include <emscripten/dom_pk_codes.h>
315327
''')
@@ -332,20 +344,20 @@ def longest_key_code_length():
332344
''')
333345

334346
c_file.write('''
335-
DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString)
336-
{
347+
DOM_PK_CODE_TYPE emscripten_compute_dom_pk_code(const char *keyCodeString) {
337348
if (!keyCodeString) return 0;
338349
339350
/* Compute the collision free hash. */
340351
unsigned int hash = 0;
341-
while(*keyCodeString) hash = ((hash ^ 0x%04XU) << %d) ^ (unsigned int)*keyCodeString++;
342-
343-
/* Don't expose the hash values out to the application, but map to fixed IDs. This is useful for
344-
mapping back codes to MDN documentation page at
345-
346-
https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code */
347-
switch(hash)
348-
{
352+
while (*keyCodeString) hash = ((hash ^ 0x%04XU) << %d) ^ (unsigned int)*keyCodeString++;
353+
354+
/*
355+
* Don't expose the hash values out to the application, but map to fixed IDs.
356+
* This is useful for mapping back codes to MDN documentation page at
357+
*
358+
* https://developer.mozilla.org/en-US/docs/Web/API/KeyboardEvent/code
359+
*/
360+
switch (hash) {
349361
''' % (k1, k2))
350362

351363
for s in input_strings:
@@ -355,10 +367,8 @@ def longest_key_code_length():
355367
}
356368
}
357369
358-
const char *emscripten_dom_pk_code_to_string(DOM_PK_CODE_TYPE code)
359-
{
360-
switch(code)
361-
{
370+
const char *emscripten_dom_pk_code_to_string(DOM_PK_CODE_TYPE code) {
371+
switch (code) {
362372
''')
363373

364374
for s in input_strings:

0 commit comments

Comments
 (0)