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