Chromium Code Reviews
chromiumcodereview-hr@appspot.gserviceaccount.com (chromiumcodereview-hr) | Please choose your nickname with Settings | Help | Chromium Project | Gerrit Changes | Sign out
(65)

Side by Side Diff: chromeos/ime/gen_input_methods.py

Issue 150723006: Make input_methods.txt to be able to specify indicator string. (Closed) Base URL: svn://svn.chromium.org/chrome/trunk/src
Patch Set: more consistent Created 6 years, 10 months ago
Use n/p to move between diff chunks; N/P to move between comments. Draft comments are only viewable by you.
Jump to:
View unified diff | Download patch | Annotate | Revision Log
« no previous file with comments | « chromeos/ime/component_extension_ime_manager.cc ('k') | chromeos/ime/input_method_descriptor.h » ('j') | no next file with comments »
Toggle Intra-line Diffs ('i') | Expand Comments ('e') | Collapse Comments ('c') | Show Comments Hide Comments ('s')
OLDNEW
1 #!/usr/bin/env python 1 #!/usr/bin/env python
2 # Copyright (c) 2012 The Chromium Authors. All rights reserved. 2 # Copyright (c) 2012 The Chromium Authors. All rights reserved.
3 # Use of this source code is governed by a BSD-style license that can be 3 # Use of this source code is governed by a BSD-style license that can be
4 # found in the LICENSE file. 4 # found in the LICENSE file.
5 5
6 """Generate a C++ header from input_methods.txt. 6 """Generate a C++ header from input_methods.txt.
7 7
8 This program generates a C++ header file containing the information on 8 This program generates a C++ header file containing the information on
9 available input methods. It parses input_methods.txt, and then generates a 9 available input methods. It parses input_methods.txt, and then generates a
10 static array definition from the information extracted. The input and output 10 static array definition from the information extracted. The input and output
11 file names are specified on the command line. 11 file names are specified on the command line.
12 12
13 Run it like: 13 Run it like:
14 gen_input_methods.py input_methods.txt input_methods.h 14 gen_input_methods.py input_methods.txt input_methods.h
15 15
16 It will produce output that looks like: 16 It will produce output that looks like:
17 17
18 // This file is automatically generated by gen_input_methods.py 18 // This file is automatically generated by gen_input_methods.py
19 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ 19 #ifndef CHROMEOS_IME_INPUT_METHODS_H_
20 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ 20 #define CHROMEOS_IME_INPUT_METHODS_H_
21 21
22 namespace chromeos { 22 namespace chromeos {
23 namespace input_method { 23 namespace input_method {
24 24
25 struct InputMethodsInfo { 25 struct InputMethodsInfo {
26 const char* input_method_id; 26 const char* input_method_id;
27 const char* language_code; 27 const char* language_code;
28 const char* xkb_keyboard_id; 28 const char* xkb_keyboard_id;
29 const char* indicator;
29 bool is_login_keyboard; 30 bool is_login_keyboard;
30 }; 31 };
31 const InputMethodsInfo kInputMethods[] = { 32 const InputMethodsInfo kInputMethods[] = {
32 {"xkb:us::eng", "en-US", "us", true}, 33 {"xkb:us::eng", "en-US", "us", "US", true},
33 {"xkb:us:dvorak:eng", "en-US", "us(dvorak)", true}, 34 {"xkb:us:dvorak:eng", "en-US", "us(dvorak)", "DV", true},
34 {"xkb:be::fra", "fr", "be", true}, 35 {"xkb:be::fra", "fr", "be", "BE", true},
35 {"xkb:br::por", "pt-BR", "br", true}, 36 {"xkb:br::por", "pt-BR", "br", "BR", true},
36 {"xkb:ru::rus", "ru", "ru", false}, 37 {"xkb:ru::rus", "ru", "ru", "RU", false},
37 }; 38 };
38 39
39 } // namespace input_method 40 } // namespace input_method
40 } // namespace chromeos 41 } // namespace chromeos
41 42
42 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ 43 #endif // CHROMEOS_IME_INPUT_METHODS_H_
43 44
44 """ 45 """
45 46
46 import fileinput 47 import fileinput
47 import re 48 import re
48 import sys 49 import sys
49 50
50 OUTPUT_HEADER = """// Automatically generated by gen_input_methods.py 51 OUTPUT_HEADER = """// Automatically generated by gen_input_methods.py
51 #ifndef CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ 52 #ifndef CHROMEOS_IME_INPUT_METHODS_H_
52 #define CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ 53 #define CHROMEOS_IME_INPUT_METHODS_H_
53 54
54 namespace chromeos { 55 namespace chromeos {
55 namespace input_method { 56 namespace input_method {
56 57
57 struct InputMethodsInfo { 58 struct InputMethodsInfo {
58 const char* input_method_id; 59 const char* input_method_id;
59 const char* language_code; 60 const char* language_code;
60 const char* xkb_layout_id; 61 const char* xkb_layout_id;
62 const char* indicator;
61 bool is_login_keyboard; 63 bool is_login_keyboard;
62 }; 64 };
63 const InputMethodsInfo kInputMethods[] = { 65 const InputMethodsInfo kInputMethods[] = {
64 """ 66 """
65 67
66 CPP_FORMAT = '#if %s\n' 68 CPP_FORMAT = '#if %s\n'
67 ENGINE_FORMAT = (' {"%(input_method_id)s", "%(language_code)s", ' + 69 ENGINE_FORMAT = (' {"%(input_method_id)s", "%(language_code)s", ' +
68 '"%(xkb_layout_id)s", %(is_login_keyboard)s},\n') 70 '"%(xkb_layout_id)s", "%(indicator)s", ' +
71 '%(is_login_keyboard)s},\n')
69 72
70 OUTPUT_FOOTER = """ 73 OUTPUT_FOOTER = """
71 }; 74 };
72 75
73 } // namespace input_method 76 } // namespace input_method
74 } // namespace chromeos 77 } // namespace chromeos
75 78
76 #endif // CHROME_BROWSER_CHROMEOS_INPUT_METHOD_INPUT_METHODS_H_ 79 #endif // CHROMEOS_IME_INPUT_METHODS_H_
77 """ 80 """
78 81
79 def CreateEngineHeader(engines): 82 def CreateEngineHeader(engines):
80 """Create the header file from a list of engines. 83 """Create the header file from a list of engines.
81 84
82 Arguments: 85 Arguments:
83 engines: list of engine objects 86 engines: list of engine objects
84 Returns: 87 Returns:
85 The text of a C++ header file containing the engine data. 88 The text of a C++ header file containing the engine data.
86 """ 89 """
(...skipping 13 matching lines...) Expand all
100 def main(argv): 103 def main(argv):
101 if len(argv) != 3: 104 if len(argv) != 3:
102 print 'Usage: gen_input_methods.py [whitelist] [output]' 105 print 'Usage: gen_input_methods.py [whitelist] [output]'
103 sys.exit(1) 106 sys.exit(1)
104 engines = [] 107 engines = []
105 for line in fileinput.input(sys.argv[1]): 108 for line in fileinput.input(sys.argv[1]):
106 line = line.strip() 109 line = line.strip()
107 if not line or re.match(r'#', line): 110 if not line or re.match(r'#', line):
108 continue 111 continue
109 columns = line.split() 112 columns = line.split()
110 assert len(columns) == 3 or len(columns) == 4, "Invalid format: " + line 113 assert len(columns) == 4 or len(columns) == 5, "Invalid format: " + line
111 engine = {} 114 engine = {}
112 engine['input_method_id'] = columns[0] 115 engine['input_method_id'] = columns[0]
113 engine['xkb_layout_id'] = columns[1] 116 engine['xkb_layout_id'] = columns[1]
114 engine['language_code'] = columns[2] 117 engine['language_code'] = columns[2]
118 engine['indicator'] = columns[3]
115 is_login_keyboard = "false" 119 is_login_keyboard = "false"
116 if len(columns) == 4: 120 if len(columns) == 5:
117 assert columns[3] == "login", "Invalid attribute: " + columns[3] 121 assert columns[4] == "login", "Invalid attribute: " + columns[4]
118 is_login_keyboard = "true" 122 is_login_keyboard = "true"
119 engine['is_login_keyboard'] = is_login_keyboard 123 engine['is_login_keyboard'] = is_login_keyboard
120 engines.append(engine) 124 engines.append(engine)
121 125
122 output = CreateEngineHeader(engines) 126 output = CreateEngineHeader(engines)
123 output_file = open(sys.argv[2], 'w') 127 output_file = open(sys.argv[2], 'w')
124 output_file.write(output) 128 output_file.write(output)
125 129
126 130
127 if __name__ == '__main__': 131 if __name__ == '__main__':
128 main(sys.argv) 132 main(sys.argv)
OLDNEW
« no previous file with comments | « chromeos/ime/component_extension_ime_manager.cc ('k') | chromeos/ime/input_method_descriptor.h » ('j') | no next file with comments »

Powered by Google App Engine
This is Rietveld 408576698