1*4882a593Smuzhiyun // SPDX-License-Identifier: GPL-2.0
2*4882a593Smuzhiyun /* Internationalization implementation. Includes definitions of English
3*4882a593Smuzhiyun * string arrays, and the i18n pointer.
4*4882a593Smuzhiyun */
5*4882a593Smuzhiyun
6*4882a593Smuzhiyun #include <linux/slab.h> /* For kmalloc. */
7*4882a593Smuzhiyun #include <linux/ctype.h>
8*4882a593Smuzhiyun #include <linux/module.h>
9*4882a593Smuzhiyun #include <linux/string.h>
10*4882a593Smuzhiyun #include "speakup.h"
11*4882a593Smuzhiyun #include "spk_priv.h"
12*4882a593Smuzhiyun
13*4882a593Smuzhiyun static char *speakup_msgs[MSG_LAST_INDEX];
14*4882a593Smuzhiyun static char *speakup_default_msgs[MSG_LAST_INDEX] = {
15*4882a593Smuzhiyun [MSG_BLANK] = "blank",
16*4882a593Smuzhiyun [MSG_IAM_ALIVE] = "I'm aLive!",
17*4882a593Smuzhiyun [MSG_YOU_KILLED_SPEAKUP] = "You killed speakup!",
18*4882a593Smuzhiyun [MSG_HEY_THATS_BETTER] = "hey. That's better!",
19*4882a593Smuzhiyun [MSG_YOU_TURNED_ME_OFF] = "You turned me off!",
20*4882a593Smuzhiyun [MSG_PARKED] = "parked!",
21*4882a593Smuzhiyun [MSG_UNPARKED] = "unparked!",
22*4882a593Smuzhiyun [MSG_MARK] = "mark",
23*4882a593Smuzhiyun [MSG_CUT] = "cut",
24*4882a593Smuzhiyun [MSG_MARK_CLEARED] = "mark, cleared",
25*4882a593Smuzhiyun [MSG_PASTE] = "paste",
26*4882a593Smuzhiyun [MSG_BRIGHT] = "bright",
27*4882a593Smuzhiyun [MSG_ON_BLINKING] = "on blinking",
28*4882a593Smuzhiyun [MSG_OFF] = "off",
29*4882a593Smuzhiyun [MSG_ON] = "on",
30*4882a593Smuzhiyun [MSG_NO_WINDOW] = "no window",
31*4882a593Smuzhiyun [MSG_CURSORING_OFF] = "cursoring off",
32*4882a593Smuzhiyun [MSG_CURSORING_ON] = "cursoring on",
33*4882a593Smuzhiyun [MSG_HIGHLIGHT_TRACKING] = "highlight tracking",
34*4882a593Smuzhiyun [MSG_READ_WINDOW] = "read windo",
35*4882a593Smuzhiyun [MSG_READ_ALL] = "read all",
36*4882a593Smuzhiyun [MSG_EDIT_DONE] = "edit done",
37*4882a593Smuzhiyun [MSG_WINDOW_ALREADY_SET] = "window already set, clear then reset",
38*4882a593Smuzhiyun [MSG_END_BEFORE_START] = "error end before start",
39*4882a593Smuzhiyun [MSG_WINDOW_CLEARED] = "window cleared",
40*4882a593Smuzhiyun [MSG_WINDOW_SILENCED] = "window silenced",
41*4882a593Smuzhiyun [MSG_WINDOW_SILENCE_DISABLED] = "window silence disabled",
42*4882a593Smuzhiyun [MSG_ERROR] = "error",
43*4882a593Smuzhiyun [MSG_GOTO_CANCELED] = "goto canceled",
44*4882a593Smuzhiyun [MSG_GOTO] = "go to?",
45*4882a593Smuzhiyun [MSG_LEAVING_HELP] = "leaving help",
46*4882a593Smuzhiyun [MSG_IS_UNASSIGNED] = "is unassigned",
47*4882a593Smuzhiyun [MSG_HELP_INFO] =
48*4882a593Smuzhiyun "press space to exit, up or down to scroll, or a letter to go to a command",
49*4882a593Smuzhiyun [MSG_EDGE_TOP] = "top,",
50*4882a593Smuzhiyun [MSG_EDGE_BOTTOM] = "bottom,",
51*4882a593Smuzhiyun [MSG_EDGE_LEFT] = "left,",
52*4882a593Smuzhiyun [MSG_EDGE_RIGHT] = "right,",
53*4882a593Smuzhiyun [MSG_NUMBER] = "number",
54*4882a593Smuzhiyun [MSG_SPACE] = "space",
55*4882a593Smuzhiyun [MSG_START] = "start",
56*4882a593Smuzhiyun [MSG_END] = "end",
57*4882a593Smuzhiyun [MSG_CTRL] = "control-",
58*4882a593Smuzhiyun [MSG_DISJUNCTION] = "or",
59*4882a593Smuzhiyun
60*4882a593Smuzhiyun /* Messages with embedded format specifiers. */
61*4882a593Smuzhiyun [MSG_POS_INFO] = "line %ld, col %ld, t t y %d",
62*4882a593Smuzhiyun [MSG_CHAR_INFO] = "hex %02x, decimal %d",
63*4882a593Smuzhiyun [MSG_REPEAT_DESC] = "times %d .",
64*4882a593Smuzhiyun [MSG_REPEAT_DESC2] = "repeated %d .",
65*4882a593Smuzhiyun [MSG_WINDOW_LINE] = "window is line %d",
66*4882a593Smuzhiyun [MSG_WINDOW_BOUNDARY] = "%s at line %d, column %d",
67*4882a593Smuzhiyun [MSG_EDIT_PROMPT] = "edit %s, press space when done",
68*4882a593Smuzhiyun [MSG_NO_COMMAND] = "no commands for %c",
69*4882a593Smuzhiyun [MSG_KEYDESC] = "is %s",
70*4882a593Smuzhiyun
71*4882a593Smuzhiyun /* Control keys. */
72*4882a593Smuzhiyun /* Most of these duplicate the entries in state names. */
73*4882a593Smuzhiyun [MSG_CTL_SHIFT] = "shift",
74*4882a593Smuzhiyun [MSG_CTL_ALTGR] = "altgr",
75*4882a593Smuzhiyun [MSG_CTL_CONTROL] = "control",
76*4882a593Smuzhiyun [MSG_CTL_ALT] = "alt",
77*4882a593Smuzhiyun [MSG_CTL_LSHIFT] = "l shift",
78*4882a593Smuzhiyun [MSG_CTL_SPEAKUP] = "speakup",
79*4882a593Smuzhiyun [MSG_CTL_LCONTROL] = "l control",
80*4882a593Smuzhiyun [MSG_CTL_RCONTROL] = "r control",
81*4882a593Smuzhiyun [MSG_CTL_CAPSSHIFT] = "caps shift",
82*4882a593Smuzhiyun
83*4882a593Smuzhiyun /* Color names. */
84*4882a593Smuzhiyun [MSG_COLOR_BLACK] = "black",
85*4882a593Smuzhiyun [MSG_COLOR_BLUE] = "blue",
86*4882a593Smuzhiyun [MSG_COLOR_GREEN] = "green",
87*4882a593Smuzhiyun [MSG_COLOR_CYAN] = "cyan",
88*4882a593Smuzhiyun [MSG_COLOR_RED] = "red",
89*4882a593Smuzhiyun [MSG_COLOR_MAGENTA] = "magenta",
90*4882a593Smuzhiyun [MSG_COLOR_YELLOW] = "yellow",
91*4882a593Smuzhiyun [MSG_COLOR_WHITE] = "white",
92*4882a593Smuzhiyun [MSG_COLOR_GREY] = "grey",
93*4882a593Smuzhiyun
94*4882a593Smuzhiyun /* Names of key states. */
95*4882a593Smuzhiyun [MSG_STATE_DOUBLE] = "double",
96*4882a593Smuzhiyun [MSG_STATE_SPEAKUP] = "speakup",
97*4882a593Smuzhiyun [MSG_STATE_ALT] = "alt",
98*4882a593Smuzhiyun [MSG_STATE_CONTROL] = "ctrl",
99*4882a593Smuzhiyun [MSG_STATE_ALTGR] = "altgr",
100*4882a593Smuzhiyun [MSG_STATE_SHIFT] = "shift",
101*4882a593Smuzhiyun
102*4882a593Smuzhiyun /* Key names. */
103*4882a593Smuzhiyun [MSG_KEYNAME_ESC] = "escape",
104*4882a593Smuzhiyun [MSG_KEYNAME_1] = "1",
105*4882a593Smuzhiyun [MSG_KEYNAME_2] = "2",
106*4882a593Smuzhiyun [MSG_KEYNAME_3] = "3",
107*4882a593Smuzhiyun [MSG_KEYNAME_4] = "4",
108*4882a593Smuzhiyun [MSG_KEYNAME_5] = "5",
109*4882a593Smuzhiyun [MSG_KEYNAME_6] = "6",
110*4882a593Smuzhiyun [MSG_KEYNAME_7] = "7",
111*4882a593Smuzhiyun [MSG_KEYNAME_8] = "8",
112*4882a593Smuzhiyun [MSG_KEYNAME_9] = "9",
113*4882a593Smuzhiyun [MSG_KEYNAME_0] = "0",
114*4882a593Smuzhiyun [MSG_KEYNAME_DASH] = "minus",
115*4882a593Smuzhiyun [MSG_KEYNAME_EQUAL] = "equal",
116*4882a593Smuzhiyun [MSG_KEYNAME_BS] = "back space",
117*4882a593Smuzhiyun [MSG_KEYNAME_TAB] = "tab",
118*4882a593Smuzhiyun [MSG_KEYNAME_Q] = "q",
119*4882a593Smuzhiyun [MSG_KEYNAME_W] = "w",
120*4882a593Smuzhiyun [MSG_KEYNAME_E] = "e",
121*4882a593Smuzhiyun [MSG_KEYNAME_R] = "r",
122*4882a593Smuzhiyun [MSG_KEYNAME_T] = "t",
123*4882a593Smuzhiyun [MSG_KEYNAME_Y] = "y",
124*4882a593Smuzhiyun [MSG_KEYNAME_U] = "u",
125*4882a593Smuzhiyun [MSG_KEYNAME_I] = "i",
126*4882a593Smuzhiyun [MSG_KEYNAME_O] = "o",
127*4882a593Smuzhiyun [MSG_KEYNAME_P] = "p",
128*4882a593Smuzhiyun [MSG_KEYNAME_LEFTBRACE] = "left brace",
129*4882a593Smuzhiyun [MSG_KEYNAME_RIGHTBRACE] = "right brace",
130*4882a593Smuzhiyun [MSG_KEYNAME_ENTER] = "enter",
131*4882a593Smuzhiyun [MSG_KEYNAME_LEFTCTRL] = "left control",
132*4882a593Smuzhiyun [MSG_KEYNAME_A] = "a",
133*4882a593Smuzhiyun [MSG_KEYNAME_S] = "s",
134*4882a593Smuzhiyun [MSG_KEYNAME_D] = "d",
135*4882a593Smuzhiyun [MSG_KEYNAME_F] = "f",
136*4882a593Smuzhiyun [MSG_KEYNAME_G] = "g",
137*4882a593Smuzhiyun [MSG_KEYNAME_H] = "h",
138*4882a593Smuzhiyun [MSG_KEYNAME_J] = "j",
139*4882a593Smuzhiyun [MSG_KEYNAME_K] = "k",
140*4882a593Smuzhiyun [MSG_KEYNAME_L] = "l",
141*4882a593Smuzhiyun [MSG_KEYNAME_SEMICOLON] = "semicolon",
142*4882a593Smuzhiyun [MSG_KEYNAME_SINGLEQUOTE] = "apostrophe",
143*4882a593Smuzhiyun [MSG_KEYNAME_GRAVE] = "accent",
144*4882a593Smuzhiyun [MSG_KEYNAME_LEFTSHFT] = "left shift",
145*4882a593Smuzhiyun [MSG_KEYNAME_BACKSLASH] = "back slash",
146*4882a593Smuzhiyun [MSG_KEYNAME_Z] = "z",
147*4882a593Smuzhiyun [MSG_KEYNAME_X] = "x",
148*4882a593Smuzhiyun [MSG_KEYNAME_C] = "c",
149*4882a593Smuzhiyun [MSG_KEYNAME_V] = "v",
150*4882a593Smuzhiyun [MSG_KEYNAME_B] = "b",
151*4882a593Smuzhiyun [MSG_KEYNAME_N] = "n",
152*4882a593Smuzhiyun [MSG_KEYNAME_M] = "m",
153*4882a593Smuzhiyun [MSG_KEYNAME_COMMA] = "comma",
154*4882a593Smuzhiyun [MSG_KEYNAME_DOT] = "dot",
155*4882a593Smuzhiyun [MSG_KEYNAME_SLASH] = "slash",
156*4882a593Smuzhiyun [MSG_KEYNAME_RIGHTSHFT] = "right shift",
157*4882a593Smuzhiyun [MSG_KEYNAME_KPSTAR] = "keypad asterisk",
158*4882a593Smuzhiyun [MSG_KEYNAME_LEFTALT] = "left alt",
159*4882a593Smuzhiyun [MSG_KEYNAME_SPACE] = "space",
160*4882a593Smuzhiyun [MSG_KEYNAME_CAPSLOCK] = "caps lock",
161*4882a593Smuzhiyun [MSG_KEYNAME_F1] = "f1",
162*4882a593Smuzhiyun [MSG_KEYNAME_F2] = "f2",
163*4882a593Smuzhiyun [MSG_KEYNAME_F3] = "f3",
164*4882a593Smuzhiyun [MSG_KEYNAME_F4] = "f4",
165*4882a593Smuzhiyun [MSG_KEYNAME_F5] = "f5",
166*4882a593Smuzhiyun [MSG_KEYNAME_F6] = "f6",
167*4882a593Smuzhiyun [MSG_KEYNAME_F7] = "f7",
168*4882a593Smuzhiyun [MSG_KEYNAME_F8] = "f8",
169*4882a593Smuzhiyun [MSG_KEYNAME_F9] = "f9",
170*4882a593Smuzhiyun [MSG_KEYNAME_F10] = "f10",
171*4882a593Smuzhiyun [MSG_KEYNAME_NUMLOCK] = "num lock",
172*4882a593Smuzhiyun [MSG_KEYNAME_SCROLLLOCK] = "scroll lock",
173*4882a593Smuzhiyun [MSG_KEYNAME_KP7] = "keypad 7",
174*4882a593Smuzhiyun [MSG_KEYNAME_KP8] = "keypad 8",
175*4882a593Smuzhiyun [MSG_KEYNAME_KP9] = "keypad 9",
176*4882a593Smuzhiyun [MSG_KEYNAME_KPMINUS] = "keypad minus",
177*4882a593Smuzhiyun [MSG_KEYNAME_KP4] = "keypad 4",
178*4882a593Smuzhiyun [MSG_KEYNAME_KP5] = "keypad 5",
179*4882a593Smuzhiyun [MSG_KEYNAME_KP6] = "keypad 6",
180*4882a593Smuzhiyun [MSG_KEYNAME_KPPLUS] = "keypad plus",
181*4882a593Smuzhiyun [MSG_KEYNAME_KP1] = "keypad 1",
182*4882a593Smuzhiyun [MSG_KEYNAME_KP2] = "keypad 2",
183*4882a593Smuzhiyun [MSG_KEYNAME_KP3] = "keypad 3",
184*4882a593Smuzhiyun [MSG_KEYNAME_KP0] = "keypad 0",
185*4882a593Smuzhiyun [MSG_KEYNAME_KPDOT] = "keypad dot",
186*4882a593Smuzhiyun [MSG_KEYNAME_103RD] = "103rd",
187*4882a593Smuzhiyun [MSG_KEYNAME_F13] = "f13",
188*4882a593Smuzhiyun [MSG_KEYNAME_102ND] = "102nd",
189*4882a593Smuzhiyun [MSG_KEYNAME_F11] = "f11",
190*4882a593Smuzhiyun [MSG_KEYNAME_F12] = "f12",
191*4882a593Smuzhiyun [MSG_KEYNAME_F14] = "f14",
192*4882a593Smuzhiyun [MSG_KEYNAME_F15] = "f15",
193*4882a593Smuzhiyun [MSG_KEYNAME_F16] = "f16",
194*4882a593Smuzhiyun [MSG_KEYNAME_F17] = "f17",
195*4882a593Smuzhiyun [MSG_KEYNAME_F18] = "f18",
196*4882a593Smuzhiyun [MSG_KEYNAME_F19] = "f19",
197*4882a593Smuzhiyun [MSG_KEYNAME_F20] = "f20",
198*4882a593Smuzhiyun [MSG_KEYNAME_KPENTER] = "keypad enter",
199*4882a593Smuzhiyun [MSG_KEYNAME_RIGHTCTRL] = "right control",
200*4882a593Smuzhiyun [MSG_KEYNAME_KPSLASH] = "keypad slash",
201*4882a593Smuzhiyun [MSG_KEYNAME_SYSRQ] = "sysrq",
202*4882a593Smuzhiyun [MSG_KEYNAME_RIGHTALT] = "right alt",
203*4882a593Smuzhiyun [MSG_KEYNAME_LF] = "line feed",
204*4882a593Smuzhiyun [MSG_KEYNAME_HOME] = "home",
205*4882a593Smuzhiyun [MSG_KEYNAME_UP] = "up",
206*4882a593Smuzhiyun [MSG_KEYNAME_PGUP] = "page up",
207*4882a593Smuzhiyun [MSG_KEYNAME_LEFT] = "left",
208*4882a593Smuzhiyun [MSG_KEYNAME_RIGHT] = "right",
209*4882a593Smuzhiyun [MSG_KEYNAME_END] = "end",
210*4882a593Smuzhiyun [MSG_KEYNAME_DOWN] = "down",
211*4882a593Smuzhiyun [MSG_KEYNAME_PGDN] = "page down",
212*4882a593Smuzhiyun [MSG_KEYNAME_INS] = "insert",
213*4882a593Smuzhiyun [MSG_KEYNAME_DEL] = "delete",
214*4882a593Smuzhiyun [MSG_KEYNAME_MACRO] = "macro",
215*4882a593Smuzhiyun [MSG_KEYNAME_MUTE] = "mute",
216*4882a593Smuzhiyun [MSG_KEYNAME_VOLDOWN] = "volume down",
217*4882a593Smuzhiyun [MSG_KEYNAME_VOLUP] = "volume up",
218*4882a593Smuzhiyun [MSG_KEYNAME_POWER] = "power",
219*4882a593Smuzhiyun [MSG_KEYNAME_KPEQUAL] = "keypad equal",
220*4882a593Smuzhiyun [MSG_KEYNAME_KPPLUSDASH] = "keypad plusminus",
221*4882a593Smuzhiyun [MSG_KEYNAME_PAUSE] = "pause",
222*4882a593Smuzhiyun [MSG_KEYNAME_F21] = "f21",
223*4882a593Smuzhiyun [MSG_KEYNAME_F22] = "f22",
224*4882a593Smuzhiyun [MSG_KEYNAME_F23] = "f23",
225*4882a593Smuzhiyun [MSG_KEYNAME_F24] = "f24",
226*4882a593Smuzhiyun [MSG_KEYNAME_KPCOMMA] = "keypad comma",
227*4882a593Smuzhiyun [MSG_KEYNAME_LEFTMETA] = "left meta",
228*4882a593Smuzhiyun [MSG_KEYNAME_RIGHTMETA] = "right meta",
229*4882a593Smuzhiyun [MSG_KEYNAME_COMPOSE] = "compose",
230*4882a593Smuzhiyun [MSG_KEYNAME_STOP] = "stop",
231*4882a593Smuzhiyun [MSG_KEYNAME_AGAIN] = "again",
232*4882a593Smuzhiyun [MSG_KEYNAME_PROPS] = "props",
233*4882a593Smuzhiyun [MSG_KEYNAME_UNDO] = "undo",
234*4882a593Smuzhiyun [MSG_KEYNAME_FRONT] = "front",
235*4882a593Smuzhiyun [MSG_KEYNAME_COPY] = "copy",
236*4882a593Smuzhiyun [MSG_KEYNAME_OPEN] = "open",
237*4882a593Smuzhiyun [MSG_KEYNAME_PASTE] = "paste",
238*4882a593Smuzhiyun [MSG_KEYNAME_FIND] = "find",
239*4882a593Smuzhiyun [MSG_KEYNAME_CUT] = "cut",
240*4882a593Smuzhiyun [MSG_KEYNAME_HELP] = "help",
241*4882a593Smuzhiyun [MSG_KEYNAME_MENU] = "menu",
242*4882a593Smuzhiyun [MSG_KEYNAME_CALC] = "calc",
243*4882a593Smuzhiyun [MSG_KEYNAME_SETUP] = "setup",
244*4882a593Smuzhiyun [MSG_KEYNAME_SLEEP] = "sleep",
245*4882a593Smuzhiyun [MSG_KEYNAME_WAKEUP] = "wakeup",
246*4882a593Smuzhiyun [MSG_KEYNAME_FILE] = "file",
247*4882a593Smuzhiyun [MSG_KEYNAME_SENDFILE] = "send file",
248*4882a593Smuzhiyun [MSG_KEYNAME_DELFILE] = "delete file",
249*4882a593Smuzhiyun [MSG_KEYNAME_XFER] = "transfer",
250*4882a593Smuzhiyun [MSG_KEYNAME_PROG1] = "prog1",
251*4882a593Smuzhiyun [MSG_KEYNAME_PROG2] = "prog2",
252*4882a593Smuzhiyun [MSG_KEYNAME_WWW] = "www",
253*4882a593Smuzhiyun [MSG_KEYNAME_MSDOS] = "msdos",
254*4882a593Smuzhiyun [MSG_KEYNAME_COFFEE] = "coffee",
255*4882a593Smuzhiyun [MSG_KEYNAME_DIRECTION] = "direction",
256*4882a593Smuzhiyun [MSG_KEYNAME_CYCLEWINDOWS] = "cycle windows",
257*4882a593Smuzhiyun [MSG_KEYNAME_MAIL] = "mail",
258*4882a593Smuzhiyun [MSG_KEYNAME_BOOKMARKS] = "bookmarks",
259*4882a593Smuzhiyun [MSG_KEYNAME_COMPUTER] = "computer",
260*4882a593Smuzhiyun [MSG_KEYNAME_BACK] = "back",
261*4882a593Smuzhiyun [MSG_KEYNAME_FORWARD] = "forward",
262*4882a593Smuzhiyun [MSG_KEYNAME_CLOSECD] = "close cd",
263*4882a593Smuzhiyun [MSG_KEYNAME_EJECTCD] = "eject cd",
264*4882a593Smuzhiyun [MSG_KEYNAME_EJECTCLOSE] = "eject close cd",
265*4882a593Smuzhiyun [MSG_KEYNAME_NEXTSONG] = "next song",
266*4882a593Smuzhiyun [MSG_KEYNAME_PLAYPAUSE] = "play pause",
267*4882a593Smuzhiyun [MSG_KEYNAME_PREVSONG] = "previous song",
268*4882a593Smuzhiyun [MSG_KEYNAME_STOPCD] = "stop cd",
269*4882a593Smuzhiyun [MSG_KEYNAME_RECORD] = "record",
270*4882a593Smuzhiyun [MSG_KEYNAME_REWIND] = "rewind",
271*4882a593Smuzhiyun [MSG_KEYNAME_PHONE] = "phone",
272*4882a593Smuzhiyun [MSG_KEYNAME_ISO] = "iso",
273*4882a593Smuzhiyun [MSG_KEYNAME_CONFIG] = "config",
274*4882a593Smuzhiyun [MSG_KEYNAME_HOMEPG] = "home page",
275*4882a593Smuzhiyun [MSG_KEYNAME_REFRESH] = "refresh",
276*4882a593Smuzhiyun [MSG_KEYNAME_EXIT] = "exit",
277*4882a593Smuzhiyun [MSG_KEYNAME_MOVE] = "move",
278*4882a593Smuzhiyun [MSG_KEYNAME_EDIT] = "edit",
279*4882a593Smuzhiyun [MSG_KEYNAME_SCROLLUP] = "scroll up",
280*4882a593Smuzhiyun [MSG_KEYNAME_SCROLLDN] = "scroll down",
281*4882a593Smuzhiyun [MSG_KEYNAME_KPLEFTPAR] = "keypad left paren",
282*4882a593Smuzhiyun [MSG_KEYNAME_KPRIGHTPAR] = "keypad right paren",
283*4882a593Smuzhiyun
284*4882a593Smuzhiyun /* Function names. */
285*4882a593Smuzhiyun [MSG_FUNCNAME_ATTRIB_BLEEP_DEC] = "attribute bleep decrement",
286*4882a593Smuzhiyun [MSG_FUNCNAME_ATTRIB_BLEEP_INC] = "attribute bleep increment",
287*4882a593Smuzhiyun [MSG_FUNCNAME_BLEEPS_DEC] = "bleeps decrement",
288*4882a593Smuzhiyun [MSG_FUNCNAME_BLEEPS_INC] = "bleeps increment",
289*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_FIRST] = "character, first",
290*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_LAST] = "character, last",
291*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_CURRENT] = "character, say current",
292*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_HEX_AND_DEC] = "character, say hex and decimal",
293*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_NEXT] = "character, say next",
294*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_PHONETIC] = "character, say phonetic",
295*4882a593Smuzhiyun [MSG_FUNCNAME_CHAR_PREVIOUS] = "character, say previous",
296*4882a593Smuzhiyun [MSG_FUNCNAME_CURSOR_PARK] = "cursor park",
297*4882a593Smuzhiyun [MSG_FUNCNAME_CUT] = "cut",
298*4882a593Smuzhiyun [MSG_FUNCNAME_EDIT_DELIM] = "edit delimiters",
299*4882a593Smuzhiyun [MSG_FUNCNAME_EDIT_EXNUM] = "edit exnum",
300*4882a593Smuzhiyun [MSG_FUNCNAME_EDIT_MOST] = "edit most",
301*4882a593Smuzhiyun [MSG_FUNCNAME_EDIT_REPEATS] = "edit repeats",
302*4882a593Smuzhiyun [MSG_FUNCNAME_EDIT_SOME] = "edit some",
303*4882a593Smuzhiyun [MSG_FUNCNAME_GOTO] = "go to",
304*4882a593Smuzhiyun [MSG_FUNCNAME_GOTO_BOTTOM] = "go to bottom edge",
305*4882a593Smuzhiyun [MSG_FUNCNAME_GOTO_LEFT] = "go to left edge",
306*4882a593Smuzhiyun [MSG_FUNCNAME_GOTO_RIGHT] = "go to right edge",
307*4882a593Smuzhiyun [MSG_FUNCNAME_GOTO_TOP] = "go to top edge",
308*4882a593Smuzhiyun [MSG_FUNCNAME_HELP] = "help",
309*4882a593Smuzhiyun [MSG_FUNCNAME_LINE_SAY_CURRENT] = "line, say current",
310*4882a593Smuzhiyun [MSG_FUNCNAME_LINE_SAY_NEXT] = "line, say next",
311*4882a593Smuzhiyun [MSG_FUNCNAME_LINE_SAY_PREVIOUS] = "line, say previous",
312*4882a593Smuzhiyun [MSG_FUNCNAME_LINE_SAY_WITH_INDENT] = "line, say with indent",
313*4882a593Smuzhiyun [MSG_FUNCNAME_PASTE] = "paste",
314*4882a593Smuzhiyun [MSG_FUNCNAME_PITCH_DEC] = "pitch decrement",
315*4882a593Smuzhiyun [MSG_FUNCNAME_PITCH_INC] = "pitch increment",
316*4882a593Smuzhiyun [MSG_FUNCNAME_PUNC_DEC] = "punctuation decrement",
317*4882a593Smuzhiyun [MSG_FUNCNAME_PUNC_INC] = "punctuation increment",
318*4882a593Smuzhiyun [MSG_FUNCNAME_PUNC_LEVEL_DEC] = "punc level decrement",
319*4882a593Smuzhiyun [MSG_FUNCNAME_PUNC_LEVEL_INC] = "punc level increment",
320*4882a593Smuzhiyun [MSG_FUNCNAME_QUIET] = "quiet",
321*4882a593Smuzhiyun [MSG_FUNCNAME_RATE_DEC] = "rate decrement",
322*4882a593Smuzhiyun [MSG_FUNCNAME_RATE_INC] = "rate increment",
323*4882a593Smuzhiyun [MSG_FUNCNAME_READING_PUNC_DEC] = "reading punctuation decrement",
324*4882a593Smuzhiyun [MSG_FUNCNAME_READING_PUNC_INC] = "reading punctuation increment",
325*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_ATTRIBUTES] = "say attributes",
326*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_FROM_LEFT] = "say from left",
327*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_FROM_TOP] = "say from top",
328*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_POSITION] = "say position",
329*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_SCREEN] = "say screen",
330*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_TO_BOTTOM] = "say to bottom",
331*4882a593Smuzhiyun [MSG_FUNCNAME_SAY_TO_RIGHT] = "say to right",
332*4882a593Smuzhiyun [MSG_FUNCNAME_SPEAKUP] = "speakup",
333*4882a593Smuzhiyun [MSG_FUNCNAME_SPEAKUP_LOCK] = "speakup lock",
334*4882a593Smuzhiyun [MSG_FUNCNAME_SPEAKUP_OFF] = "speakup off",
335*4882a593Smuzhiyun [MSG_FUNCNAME_SPEECH_KILL] = "speech kill",
336*4882a593Smuzhiyun [MSG_FUNCNAME_SPELL_DELAY_DEC] = "spell delay decrement",
337*4882a593Smuzhiyun [MSG_FUNCNAME_SPELL_DELAY_INC] = "spell delay increment",
338*4882a593Smuzhiyun [MSG_FUNCNAME_SPELL_WORD] = "spell word",
339*4882a593Smuzhiyun [MSG_FUNCNAME_SPELL_WORD_PHONETICALLY] = "spell word phonetically",
340*4882a593Smuzhiyun [MSG_FUNCNAME_TONE_DEC] = "tone decrement",
341*4882a593Smuzhiyun [MSG_FUNCNAME_TONE_INC] = "tone increment",
342*4882a593Smuzhiyun [MSG_FUNCNAME_VOICE_DEC] = "voice decrement",
343*4882a593Smuzhiyun [MSG_FUNCNAME_VOICE_INC] = "voice increment",
344*4882a593Smuzhiyun [MSG_FUNCNAME_VOLUME_DEC] = "volume decrement",
345*4882a593Smuzhiyun [MSG_FUNCNAME_VOLUME_INC] = "volume increment",
346*4882a593Smuzhiyun [MSG_FUNCNAME_WINDOW_CLEAR] = "window, clear",
347*4882a593Smuzhiyun [MSG_FUNCNAME_WINDOW_SAY] = "window, say",
348*4882a593Smuzhiyun [MSG_FUNCNAME_WINDOW_SET] = "window, set",
349*4882a593Smuzhiyun [MSG_FUNCNAME_WINDOW_SILENCE] = "window, silence",
350*4882a593Smuzhiyun [MSG_FUNCNAME_WORD_SAY_CURRENT] = "word, say current",
351*4882a593Smuzhiyun [MSG_FUNCNAME_WORD_SAY_NEXT] = "word, say next",
352*4882a593Smuzhiyun [MSG_FUNCNAME_WORD_SAY_PREVIOUS] = "word, say previous",
353*4882a593Smuzhiyun };
354*4882a593Smuzhiyun
355*4882a593Smuzhiyun static struct msg_group_t all_groups[] = {
356*4882a593Smuzhiyun {
357*4882a593Smuzhiyun .name = "ctl_keys",
358*4882a593Smuzhiyun .start = MSG_CTL_START,
359*4882a593Smuzhiyun .end = MSG_CTL_END,
360*4882a593Smuzhiyun },
361*4882a593Smuzhiyun {
362*4882a593Smuzhiyun .name = "colors",
363*4882a593Smuzhiyun .start = MSG_COLORS_START,
364*4882a593Smuzhiyun .end = MSG_COLORS_END,
365*4882a593Smuzhiyun },
366*4882a593Smuzhiyun {
367*4882a593Smuzhiyun .name = "formatted",
368*4882a593Smuzhiyun .start = MSG_FORMATTED_START,
369*4882a593Smuzhiyun .end = MSG_FORMATTED_END,
370*4882a593Smuzhiyun },
371*4882a593Smuzhiyun {
372*4882a593Smuzhiyun .name = "function_names",
373*4882a593Smuzhiyun .start = MSG_FUNCNAMES_START,
374*4882a593Smuzhiyun .end = MSG_FUNCNAMES_END,
375*4882a593Smuzhiyun },
376*4882a593Smuzhiyun {
377*4882a593Smuzhiyun .name = "key_names",
378*4882a593Smuzhiyun .start = MSG_KEYNAMES_START,
379*4882a593Smuzhiyun .end = MSG_KEYNAMES_END,
380*4882a593Smuzhiyun },
381*4882a593Smuzhiyun {
382*4882a593Smuzhiyun .name = "announcements",
383*4882a593Smuzhiyun .start = MSG_ANNOUNCEMENTS_START,
384*4882a593Smuzhiyun .end = MSG_ANNOUNCEMENTS_END,
385*4882a593Smuzhiyun },
386*4882a593Smuzhiyun {
387*4882a593Smuzhiyun .name = "states",
388*4882a593Smuzhiyun .start = MSG_STATES_START,
389*4882a593Smuzhiyun .end = MSG_STATES_END,
390*4882a593Smuzhiyun },
391*4882a593Smuzhiyun };
392*4882a593Smuzhiyun
393*4882a593Smuzhiyun static const int num_groups = ARRAY_SIZE(all_groups);
394*4882a593Smuzhiyun
spk_msg_get(enum msg_index_t index)395*4882a593Smuzhiyun char *spk_msg_get(enum msg_index_t index)
396*4882a593Smuzhiyun {
397*4882a593Smuzhiyun return speakup_msgs[index];
398*4882a593Smuzhiyun }
399*4882a593Smuzhiyun
400*4882a593Smuzhiyun /*
401*4882a593Smuzhiyun * Function: next_specifier
402*4882a593Smuzhiyun * Finds the start of the next format specifier in the argument string.
403*4882a593Smuzhiyun * Return value: pointer to start of format
404*4882a593Smuzhiyun * specifier, or NULL if no specifier exists.
405*4882a593Smuzhiyun */
next_specifier(char * input)406*4882a593Smuzhiyun static char *next_specifier(char *input)
407*4882a593Smuzhiyun {
408*4882a593Smuzhiyun int found = 0;
409*4882a593Smuzhiyun char *next_percent = input;
410*4882a593Smuzhiyun
411*4882a593Smuzhiyun while (next_percent && !found) {
412*4882a593Smuzhiyun next_percent = strchr(next_percent, '%');
413*4882a593Smuzhiyun if (next_percent) {
414*4882a593Smuzhiyun /* skip over doubled percent signs */
415*4882a593Smuzhiyun while (next_percent[0] == '%' &&
416*4882a593Smuzhiyun next_percent[1] == '%')
417*4882a593Smuzhiyun next_percent += 2;
418*4882a593Smuzhiyun if (*next_percent == '%')
419*4882a593Smuzhiyun found = 1;
420*4882a593Smuzhiyun else if (*next_percent == '\0')
421*4882a593Smuzhiyun next_percent = NULL;
422*4882a593Smuzhiyun }
423*4882a593Smuzhiyun }
424*4882a593Smuzhiyun
425*4882a593Smuzhiyun return next_percent;
426*4882a593Smuzhiyun }
427*4882a593Smuzhiyun
428*4882a593Smuzhiyun /* Skip over 0 or more flags. */
skip_flags(char * input)429*4882a593Smuzhiyun static char *skip_flags(char *input)
430*4882a593Smuzhiyun {
431*4882a593Smuzhiyun while ((*input != '\0') && strchr(" 0+-#", *input))
432*4882a593Smuzhiyun input++;
433*4882a593Smuzhiyun return input;
434*4882a593Smuzhiyun }
435*4882a593Smuzhiyun
436*4882a593Smuzhiyun /* Skip over width.precision, if it exists. */
skip_width(char * input)437*4882a593Smuzhiyun static char *skip_width(char *input)
438*4882a593Smuzhiyun {
439*4882a593Smuzhiyun while (isdigit(*input))
440*4882a593Smuzhiyun input++;
441*4882a593Smuzhiyun if (*input == '.') {
442*4882a593Smuzhiyun input++;
443*4882a593Smuzhiyun while (isdigit(*input))
444*4882a593Smuzhiyun input++;
445*4882a593Smuzhiyun }
446*4882a593Smuzhiyun return input;
447*4882a593Smuzhiyun }
448*4882a593Smuzhiyun
449*4882a593Smuzhiyun /*
450*4882a593Smuzhiyun * Skip past the end of the conversion part.
451*4882a593Smuzhiyun * Note that this code only accepts a handful of conversion specifiers:
452*4882a593Smuzhiyun * c d s x and ld. Not accidental; these are exactly the ones used in
453*4882a593Smuzhiyun * the default group of formatted messages.
454*4882a593Smuzhiyun */
skip_conversion(char * input)455*4882a593Smuzhiyun static char *skip_conversion(char *input)
456*4882a593Smuzhiyun {
457*4882a593Smuzhiyun if ((input[0] == 'l') && (input[1] == 'd'))
458*4882a593Smuzhiyun input += 2;
459*4882a593Smuzhiyun else if ((*input != '\0') && strchr("cdsx", *input))
460*4882a593Smuzhiyun input++;
461*4882a593Smuzhiyun return input;
462*4882a593Smuzhiyun }
463*4882a593Smuzhiyun
464*4882a593Smuzhiyun /*
465*4882a593Smuzhiyun * Function: find_specifier_end
466*4882a593Smuzhiyun * Return a pointer to the end of the format specifier.
467*4882a593Smuzhiyun */
find_specifier_end(char * input)468*4882a593Smuzhiyun static char *find_specifier_end(char *input)
469*4882a593Smuzhiyun {
470*4882a593Smuzhiyun input++; /* Advance over %. */
471*4882a593Smuzhiyun input = skip_flags(input);
472*4882a593Smuzhiyun input = skip_width(input);
473*4882a593Smuzhiyun input = skip_conversion(input);
474*4882a593Smuzhiyun return input;
475*4882a593Smuzhiyun }
476*4882a593Smuzhiyun
477*4882a593Smuzhiyun /*
478*4882a593Smuzhiyun * Function: compare_specifiers
479*4882a593Smuzhiyun * Compare the format specifiers pointed to by *input1 and *input2.
480*4882a593Smuzhiyun * Return true if they are the same, false otherwise.
481*4882a593Smuzhiyun * Advance *input1 and *input2 so that they point to the character following
482*4882a593Smuzhiyun * the end of the specifier.
483*4882a593Smuzhiyun */
compare_specifiers(char ** input1,char ** input2)484*4882a593Smuzhiyun static bool compare_specifiers(char **input1, char **input2)
485*4882a593Smuzhiyun {
486*4882a593Smuzhiyun bool same = false;
487*4882a593Smuzhiyun char *end1 = find_specifier_end(*input1);
488*4882a593Smuzhiyun char *end2 = find_specifier_end(*input2);
489*4882a593Smuzhiyun size_t length1 = end1 - *input1;
490*4882a593Smuzhiyun size_t length2 = end2 - *input2;
491*4882a593Smuzhiyun
492*4882a593Smuzhiyun if ((length1 == length2) && !memcmp(*input1, *input2, length1))
493*4882a593Smuzhiyun same = true;
494*4882a593Smuzhiyun
495*4882a593Smuzhiyun *input1 = end1;
496*4882a593Smuzhiyun *input2 = end2;
497*4882a593Smuzhiyun return same;
498*4882a593Smuzhiyun }
499*4882a593Smuzhiyun
500*4882a593Smuzhiyun /*
501*4882a593Smuzhiyun * Function: fmt_validate
502*4882a593Smuzhiyun * Check that two format strings contain the same number of format specifiers,
503*4882a593Smuzhiyun * and that the order of specifiers is the same in both strings.
504*4882a593Smuzhiyun * Return true if the condition holds, false if it doesn't.
505*4882a593Smuzhiyun */
fmt_validate(char * template,char * user)506*4882a593Smuzhiyun static bool fmt_validate(char *template, char *user)
507*4882a593Smuzhiyun {
508*4882a593Smuzhiyun bool valid = true;
509*4882a593Smuzhiyun bool still_comparing = true;
510*4882a593Smuzhiyun char *template_ptr = template;
511*4882a593Smuzhiyun char *user_ptr = user;
512*4882a593Smuzhiyun
513*4882a593Smuzhiyun while (still_comparing && valid) {
514*4882a593Smuzhiyun template_ptr = next_specifier(template_ptr);
515*4882a593Smuzhiyun user_ptr = next_specifier(user_ptr);
516*4882a593Smuzhiyun if (template_ptr && user_ptr) {
517*4882a593Smuzhiyun /* Both have at least one more specifier. */
518*4882a593Smuzhiyun valid = compare_specifiers(&template_ptr, &user_ptr);
519*4882a593Smuzhiyun } else {
520*4882a593Smuzhiyun /* No more format specifiers in one or both strings. */
521*4882a593Smuzhiyun still_comparing = false;
522*4882a593Smuzhiyun /* See if one has more specifiers than the other. */
523*4882a593Smuzhiyun if (template_ptr || user_ptr)
524*4882a593Smuzhiyun valid = false;
525*4882a593Smuzhiyun }
526*4882a593Smuzhiyun }
527*4882a593Smuzhiyun return valid;
528*4882a593Smuzhiyun }
529*4882a593Smuzhiyun
530*4882a593Smuzhiyun /*
531*4882a593Smuzhiyun * Function: msg_set
532*4882a593Smuzhiyun * Description: Add a user-supplied message to the user_messages array.
533*4882a593Smuzhiyun * The message text is copied to a memory area allocated with kmalloc.
534*4882a593Smuzhiyun * If the function fails, then user_messages is untouched.
535*4882a593Smuzhiyun * Arguments:
536*4882a593Smuzhiyun * - index: a message number, as found in i18n.h.
537*4882a593Smuzhiyun * - text: text of message. Not NUL-terminated.
538*4882a593Smuzhiyun * - length: number of bytes in text.
539*4882a593Smuzhiyun * Failure conditions:
540*4882a593Smuzhiyun * -EINVAL - Invalid format specifiers in formatted message or illegal index.
541*4882a593Smuzhiyun * -ENOMEM - Unable to allocate memory.
542*4882a593Smuzhiyun */
spk_msg_set(enum msg_index_t index,char * text,size_t length)543*4882a593Smuzhiyun ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
544*4882a593Smuzhiyun {
545*4882a593Smuzhiyun char *newstr = NULL;
546*4882a593Smuzhiyun unsigned long flags;
547*4882a593Smuzhiyun
548*4882a593Smuzhiyun if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX))
549*4882a593Smuzhiyun return -EINVAL;
550*4882a593Smuzhiyun
551*4882a593Smuzhiyun newstr = kmalloc(length + 1, GFP_KERNEL);
552*4882a593Smuzhiyun if (!newstr)
553*4882a593Smuzhiyun return -ENOMEM;
554*4882a593Smuzhiyun
555*4882a593Smuzhiyun memcpy(newstr, text, length);
556*4882a593Smuzhiyun newstr[length] = '\0';
557*4882a593Smuzhiyun if (index >= MSG_FORMATTED_START &&
558*4882a593Smuzhiyun index <= MSG_FORMATTED_END &&
559*4882a593Smuzhiyun !fmt_validate(speakup_default_msgs[index], newstr)) {
560*4882a593Smuzhiyun kfree(newstr);
561*4882a593Smuzhiyun return -EINVAL;
562*4882a593Smuzhiyun }
563*4882a593Smuzhiyun spin_lock_irqsave(&speakup_info.spinlock, flags);
564*4882a593Smuzhiyun if (speakup_msgs[index] != speakup_default_msgs[index])
565*4882a593Smuzhiyun kfree(speakup_msgs[index]);
566*4882a593Smuzhiyun speakup_msgs[index] = newstr;
567*4882a593Smuzhiyun spin_unlock_irqrestore(&speakup_info.spinlock, flags);
568*4882a593Smuzhiyun return 0;
569*4882a593Smuzhiyun }
570*4882a593Smuzhiyun
571*4882a593Smuzhiyun /*
572*4882a593Smuzhiyun * Find a message group, given its name. Return a pointer to the structure
573*4882a593Smuzhiyun * if found, or NULL otherwise.
574*4882a593Smuzhiyun */
spk_find_msg_group(const char * group_name)575*4882a593Smuzhiyun struct msg_group_t *spk_find_msg_group(const char *group_name)
576*4882a593Smuzhiyun {
577*4882a593Smuzhiyun struct msg_group_t *group = NULL;
578*4882a593Smuzhiyun int i;
579*4882a593Smuzhiyun
580*4882a593Smuzhiyun for (i = 0; i < num_groups; i++) {
581*4882a593Smuzhiyun if (!strcmp(all_groups[i].name, group_name)) {
582*4882a593Smuzhiyun group = &all_groups[i];
583*4882a593Smuzhiyun break;
584*4882a593Smuzhiyun }
585*4882a593Smuzhiyun }
586*4882a593Smuzhiyun return group;
587*4882a593Smuzhiyun }
588*4882a593Smuzhiyun
spk_reset_msg_group(struct msg_group_t * group)589*4882a593Smuzhiyun void spk_reset_msg_group(struct msg_group_t *group)
590*4882a593Smuzhiyun {
591*4882a593Smuzhiyun unsigned long flags;
592*4882a593Smuzhiyun enum msg_index_t i;
593*4882a593Smuzhiyun
594*4882a593Smuzhiyun spin_lock_irqsave(&speakup_info.spinlock, flags);
595*4882a593Smuzhiyun
596*4882a593Smuzhiyun for (i = group->start; i <= group->end; i++) {
597*4882a593Smuzhiyun if (speakup_msgs[i] != speakup_default_msgs[i])
598*4882a593Smuzhiyun kfree(speakup_msgs[i]);
599*4882a593Smuzhiyun speakup_msgs[i] = speakup_default_msgs[i];
600*4882a593Smuzhiyun }
601*4882a593Smuzhiyun spin_unlock_irqrestore(&speakup_info.spinlock, flags);
602*4882a593Smuzhiyun }
603*4882a593Smuzhiyun
604*4882a593Smuzhiyun /* Called at initialization time, to establish default messages. */
spk_initialize_msgs(void)605*4882a593Smuzhiyun void spk_initialize_msgs(void)
606*4882a593Smuzhiyun {
607*4882a593Smuzhiyun memcpy(speakup_msgs, speakup_default_msgs,
608*4882a593Smuzhiyun sizeof(speakup_default_msgs));
609*4882a593Smuzhiyun }
610*4882a593Smuzhiyun
611*4882a593Smuzhiyun /* Free user-supplied strings when module is unloaded: */
spk_free_user_msgs(void)612*4882a593Smuzhiyun void spk_free_user_msgs(void)
613*4882a593Smuzhiyun {
614*4882a593Smuzhiyun enum msg_index_t index;
615*4882a593Smuzhiyun unsigned long flags;
616*4882a593Smuzhiyun
617*4882a593Smuzhiyun spin_lock_irqsave(&speakup_info.spinlock, flags);
618*4882a593Smuzhiyun for (index = MSG_FIRST_INDEX; index < MSG_LAST_INDEX; index++) {
619*4882a593Smuzhiyun if (speakup_msgs[index] != speakup_default_msgs[index]) {
620*4882a593Smuzhiyun kfree(speakup_msgs[index]);
621*4882a593Smuzhiyun speakup_msgs[index] = speakup_default_msgs[index];
622*4882a593Smuzhiyun }
623*4882a593Smuzhiyun }
624*4882a593Smuzhiyun spin_unlock_irqrestore(&speakup_info.spinlock, flags);
625*4882a593Smuzhiyun }
626