i18n.c 19 KB

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