1
linux/drivers/accessibility/speakup/i18n.c

631 lines
19 KiB
C
Raw Normal View History

License cleanup: add SPDX GPL-2.0 license identifier to files with no license Many source files in the tree are missing licensing information, which makes it harder for compliance tools to determine the correct license. By default all files without license information are under the default license of the kernel, which is GPL version 2. Update the files which contain no license information with the 'GPL-2.0' SPDX license identifier. The SPDX identifier is a legally binding shorthand, which can be used instead of the full boiler plate text. This patch is based on work done by Thomas Gleixner and Kate Stewart and Philippe Ombredanne. How this work was done: Patches were generated and checked against linux-4.14-rc6 for a subset of the use cases: - file had no licensing information it it. - file was a */uapi/* one with no licensing information in it, - file was a */uapi/* one with existing licensing information, Further patches will be generated in subsequent months to fix up cases where non-standard license headers were used, and references to license had to be inferred by heuristics based on keywords. The analysis to determine which SPDX License Identifier to be applied to a file was done in a spreadsheet of side by side results from of the output of two independent scanners (ScanCode & Windriver) producing SPDX tag:value files created by Philippe Ombredanne. Philippe prepared the base worksheet, and did an initial spot review of a few 1000 files. The 4.13 kernel was the starting point of the analysis with 60,537 files assessed. Kate Stewart did a file by file comparison of the scanner results in the spreadsheet to determine which SPDX license identifier(s) to be applied to the file. She confirmed any determination that was not immediately clear with lawyers working with the Linux Foundation. Criteria used to select files for SPDX license identifier tagging was: - Files considered eligible had to be source code files. - Make and config files were included as candidates if they contained >5 lines of source - File already had some variant of a license header in it (even if <5 lines). All documentation files were explicitly excluded. The following heuristics were used to determine which SPDX license identifiers to apply. - when both scanners couldn't find any license traces, file was considered to have no license information in it, and the top level COPYING file license applied. For non */uapi/* files that summary was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 11139 and resulted in the first patch in this series. If that file was a */uapi/* path one, it was "GPL-2.0 WITH Linux-syscall-note" otherwise it was "GPL-2.0". Results of that was: SPDX license identifier # files ---------------------------------------------------|------- GPL-2.0 WITH Linux-syscall-note 930 and resulted in the second patch in this series. - if a file had some form of licensing information in it, and was one of the */uapi/* ones, it was denoted with the Linux-syscall-note if any GPL family license was found in the file or had no licensing in it (per prior point). Results summary: SPDX license identifier # files ---------------------------------------------------|------ GPL-2.0 WITH Linux-syscall-note 270 GPL-2.0+ WITH Linux-syscall-note 169 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-2-Clause) 21 ((GPL-2.0 WITH Linux-syscall-note) OR BSD-3-Clause) 17 LGPL-2.1+ WITH Linux-syscall-note 15 GPL-1.0+ WITH Linux-syscall-note 14 ((GPL-2.0+ WITH Linux-syscall-note) OR BSD-3-Clause) 5 LGPL-2.0+ WITH Linux-syscall-note 4 LGPL-2.1 WITH Linux-syscall-note 3 ((GPL-2.0 WITH Linux-syscall-note) OR MIT) 3 ((GPL-2.0 WITH Linux-syscall-note) AND MIT) 1 and that resulted in the third patch in this series. - when the two scanners agreed on the detected license(s), that became the concluded license(s). - when there was disagreement between the two scanners (one detected a license but the other didn't, or they both detected different licenses) a manual inspection of the file occurred. - In most cases a manual inspection of the information in the file resulted in a clear resolution of the license that should apply (and which scanner probably needed to revisit its heuristics). - When it was not immediately clear, the license identifier was confirmed with lawyers working with the Linux Foundation. - If there was any question as to the appropriate license identifier, the file was flagged for further research and to be revisited later in time. In total, over 70 hours of logged manual review was done on the spreadsheet to determine the SPDX license identifiers to apply to the source files by Kate, Philippe, Thomas and, in some cases, confirmation by lawyers working with the Linux Foundation. Kate also obtained a third independent scan of the 4.13 code base from FOSSology, and compared selected files where the other two scanners disagreed against that SPDX file, to see if there was new insights. The Windriver scanner is based on an older version of FOSSology in part, so they are related. Thomas did random spot checks in about 500 files from the spreadsheets for the uapi headers and agreed with SPDX license identifier in the files he inspected. For the non-uapi files Thomas did random spot checks in about 15000 files. In initial set of patches against 4.14-rc6, 3 files were found to have copy/paste license identifier errors, and have been fixed to reflect the correct identifier. Additionally Philippe spent 10 hours this week doing a detailed manual inspection and review of the 12,461 patched files from the initial patch version early this week with: - a full scancode scan run, collecting the matched texts, detected license ids and scores - reviewing anything where there was a license detected (about 500+ files) to ensure that the applied SPDX license was correct - reviewing anything where there was no detection but the patch license was not GPL-2.0 WITH Linux-syscall-note to ensure that the applied SPDX license was correct This produced a worksheet with 20 files needing minor correction. This worksheet was then exported into 3 different .csv files for the different types of files to be modified. These .csv files were then reviewed by Greg. Thomas wrote a script to parse the csv files and add the proper SPDX tag to the file, in the format that the file expected. This script was further refined by Greg based on the output to detect more types of files automatically and to distinguish between header and source .c files (which need different comment types.) Finally Greg ran the script using the .csv files to generate the patches. Reviewed-by: Kate Stewart <kstewart@linuxfoundation.org> Reviewed-by: Philippe Ombredanne <pombredanne@nexb.com> Reviewed-by: Thomas Gleixner <tglx@linutronix.de> Signed-off-by: Greg Kroah-Hartman <gregkh@linuxfoundation.org>
2017-11-01 07:07:57 -07:00
// SPDX-License-Identifier: GPL-2.0
/* Internationalization implementation. Includes definitions of English
* string arrays, and the i18n pointer.
*/
#include <linux/slab.h> /* For kmalloc. */
#include <linux/ctype.h>
#include <linux/module.h>
#include <linux/string.h>
#include "speakup.h"
#include "spk_priv.h"
static char *speakup_msgs[MSG_LAST_INDEX];
static char *speakup_default_msgs[MSG_LAST_INDEX] = {
[MSG_BLANK] = "blank",
[MSG_IAM_ALIVE] = "I'm aLive!",
[MSG_YOU_KILLED_SPEAKUP] = "You killed speakup!",
[MSG_HEY_THATS_BETTER] = "hey. That's better!",
[MSG_YOU_TURNED_ME_OFF] = "You turned me off!",
[MSG_PARKED] = "parked!",
[MSG_UNPARKED] = "unparked!",
[MSG_MARK] = "mark",
[MSG_CUT] = "cut",
[MSG_MARK_CLEARED] = "mark, cleared",
[MSG_PASTE] = "paste",
[MSG_BRIGHT] = "bright",
[MSG_ON_BLINKING] = "on blinking",
[MSG_OFF] = "off",
[MSG_ON] = "on",
[MSG_NO_WINDOW] = "no window",
[MSG_CURSORING_OFF] = "cursoring off",
[MSG_CURSORING_ON] = "cursoring on",
[MSG_HIGHLIGHT_TRACKING] = "highlight tracking",
[MSG_READ_WINDOW] = "read windo",
[MSG_READ_ALL] = "read all",
[MSG_EDIT_DONE] = "edit done",
[MSG_WINDOW_ALREADY_SET] = "window already set, clear then reset",
[MSG_END_BEFORE_START] = "error end before start",
[MSG_WINDOW_CLEARED] = "window cleared",
[MSG_WINDOW_SILENCED] = "window silenced",
[MSG_WINDOW_SILENCE_DISABLED] = "window silence disabled",
[MSG_ERROR] = "error",
[MSG_GOTO_CANCELED] = "goto canceled",
[MSG_GOTO] = "go to?",
[MSG_LEAVING_HELP] = "leaving help",
[MSG_IS_UNASSIGNED] = "is unassigned",
[MSG_HELP_INFO] =
"press space to exit, up or down to scroll, or a letter to go to a command",
[MSG_EDGE_TOP] = "top,",
[MSG_EDGE_BOTTOM] = "bottom,",
[MSG_EDGE_LEFT] = "left,",
[MSG_EDGE_RIGHT] = "right,",
[MSG_NUMBER] = "number",
[MSG_SPACE] = "space",
[MSG_START] = "start",
[MSG_END] = "end",
[MSG_CTRL] = "control-",
[MSG_DISJUNCTION] = "or",
/* Messages with embedded format specifiers. */
[MSG_POS_INFO] = "line %ld, col %ld, t t y %d",
[MSG_CHAR_INFO] = "hex %02x, decimal %d",
[MSG_REPEAT_DESC] = "times %d .",
[MSG_REPEAT_DESC2] = "repeated %d .",
[MSG_WINDOW_LINE] = "window is line %d",
[MSG_WINDOW_BOUNDARY] = "%s at line %d, column %d",
[MSG_EDIT_PROMPT] = "edit %s, press space when done",
[MSG_NO_COMMAND] = "no commands for %c",
[MSG_KEYDESC] = "is %s",
/* Control keys. */
/* Most of these duplicate the entries in state names. */
[MSG_CTL_SHIFT] = "shift",
[MSG_CTL_ALTGR] = "altgr",
[MSG_CTL_CONTROL] = "control",
[MSG_CTL_ALT] = "alt",
[MSG_CTL_LSHIFT] = "l shift",
[MSG_CTL_SPEAKUP] = "speakup",
[MSG_CTL_LCONTROL] = "l control",
[MSG_CTL_RCONTROL] = "r control",
[MSG_CTL_CAPSSHIFT] = "caps shift",
/* Color names. */
[MSG_COLOR_BLACK] = "black",
[MSG_COLOR_BLUE] = "blue",
[MSG_COLOR_GREEN] = "green",
[MSG_COLOR_CYAN] = "cyan",
[MSG_COLOR_RED] = "red",
[MSG_COLOR_MAGENTA] = "magenta",
[MSG_COLOR_YELLOW] = "yellow",
[MSG_COLOR_WHITE] = "white",
[MSG_COLOR_GREY] = "grey",
[MSG_COLOR_BRIGHTBLUE] = "bright blue",
[MSG_COLOR_BRIGHTGREEN] = "bright green",
[MSG_COLOR_BRIGHTCYAN] = "bright cyan",
[MSG_COLOR_BRIGHTRED] = "bright red",
[MSG_COLOR_BRIGHTMAGENTA] = "bright magenta",
[MSG_COLOR_BRIGHTYELLOW] = "bright yellow",
[MSG_COLOR_BRIGHTWHITE] = "bright white",
/* Names of key states. */
[MSG_STATE_DOUBLE] = "double",
[MSG_STATE_SPEAKUP] = "speakup",
[MSG_STATE_ALT] = "alt",
[MSG_STATE_CONTROL] = "ctrl",
[MSG_STATE_ALTGR] = "altgr",
[MSG_STATE_SHIFT] = "shift",
/* Key names. */
[MSG_KEYNAME_ESC] = "escape",
[MSG_KEYNAME_1] = "1",
[MSG_KEYNAME_2] = "2",
[MSG_KEYNAME_3] = "3",
[MSG_KEYNAME_4] = "4",
[MSG_KEYNAME_5] = "5",
[MSG_KEYNAME_6] = "6",
[MSG_KEYNAME_7] = "7",
[MSG_KEYNAME_8] = "8",
[MSG_KEYNAME_9] = "9",
[MSG_KEYNAME_0] = "0",
[MSG_KEYNAME_DASH] = "minus",
[MSG_KEYNAME_EQUAL] = "equal",
[MSG_KEYNAME_BS] = "back space",
[MSG_KEYNAME_TAB] = "tab",
[MSG_KEYNAME_Q] = "q",
[MSG_KEYNAME_W] = "w",
[MSG_KEYNAME_E] = "e",
[MSG_KEYNAME_R] = "r",
[MSG_KEYNAME_T] = "t",
[MSG_KEYNAME_Y] = "y",
[MSG_KEYNAME_U] = "u",
[MSG_KEYNAME_I] = "i",
[MSG_KEYNAME_O] = "o",
[MSG_KEYNAME_P] = "p",
[MSG_KEYNAME_LEFTBRACE] = "left brace",
[MSG_KEYNAME_RIGHTBRACE] = "right brace",
[MSG_KEYNAME_ENTER] = "enter",
[MSG_KEYNAME_LEFTCTRL] = "left control",
[MSG_KEYNAME_A] = "a",
[MSG_KEYNAME_S] = "s",
[MSG_KEYNAME_D] = "d",
[MSG_KEYNAME_F] = "f",
[MSG_KEYNAME_G] = "g",
[MSG_KEYNAME_H] = "h",
[MSG_KEYNAME_J] = "j",
[MSG_KEYNAME_K] = "k",
[MSG_KEYNAME_L] = "l",
[MSG_KEYNAME_SEMICOLON] = "semicolon",
[MSG_KEYNAME_SINGLEQUOTE] = "apostrophe",
[MSG_KEYNAME_GRAVE] = "accent",
[MSG_KEYNAME_LEFTSHFT] = "left shift",
[MSG_KEYNAME_BACKSLASH] = "back slash",
[MSG_KEYNAME_Z] = "z",
[MSG_KEYNAME_X] = "x",
[MSG_KEYNAME_C] = "c",
[MSG_KEYNAME_V] = "v",
[MSG_KEYNAME_B] = "b",
[MSG_KEYNAME_N] = "n",
[MSG_KEYNAME_M] = "m",
[MSG_KEYNAME_COMMA] = "comma",
[MSG_KEYNAME_DOT] = "dot",
[MSG_KEYNAME_SLASH] = "slash",
[MSG_KEYNAME_RIGHTSHFT] = "right shift",
[MSG_KEYNAME_KPSTAR] = "keypad asterisk",
[MSG_KEYNAME_LEFTALT] = "left alt",
[MSG_KEYNAME_SPACE] = "space",
[MSG_KEYNAME_CAPSLOCK] = "caps lock",
[MSG_KEYNAME_F1] = "f1",
[MSG_KEYNAME_F2] = "f2",
[MSG_KEYNAME_F3] = "f3",
[MSG_KEYNAME_F4] = "f4",
[MSG_KEYNAME_F5] = "f5",
[MSG_KEYNAME_F6] = "f6",
[MSG_KEYNAME_F7] = "f7",
[MSG_KEYNAME_F8] = "f8",
[MSG_KEYNAME_F9] = "f9",
[MSG_KEYNAME_F10] = "f10",
[MSG_KEYNAME_NUMLOCK] = "num lock",
[MSG_KEYNAME_SCROLLLOCK] = "scroll lock",
[MSG_KEYNAME_KP7] = "keypad 7",
[MSG_KEYNAME_KP8] = "keypad 8",
[MSG_KEYNAME_KP9] = "keypad 9",
[MSG_KEYNAME_KPMINUS] = "keypad minus",
[MSG_KEYNAME_KP4] = "keypad 4",
[MSG_KEYNAME_KP5] = "keypad 5",
[MSG_KEYNAME_KP6] = "keypad 6",
[MSG_KEYNAME_KPPLUS] = "keypad plus",
[MSG_KEYNAME_KP1] = "keypad 1",
[MSG_KEYNAME_KP2] = "keypad 2",
[MSG_KEYNAME_KP3] = "keypad 3",
[MSG_KEYNAME_KP0] = "keypad 0",
[MSG_KEYNAME_KPDOT] = "keypad dot",
[MSG_KEYNAME_103RD] = "103rd",
[MSG_KEYNAME_F13] = "f13",
[MSG_KEYNAME_102ND] = "102nd",
[MSG_KEYNAME_F11] = "f11",
[MSG_KEYNAME_F12] = "f12",
[MSG_KEYNAME_F14] = "f14",
[MSG_KEYNAME_F15] = "f15",
[MSG_KEYNAME_F16] = "f16",
[MSG_KEYNAME_F17] = "f17",
[MSG_KEYNAME_F18] = "f18",
[MSG_KEYNAME_F19] = "f19",
[MSG_KEYNAME_F20] = "f20",
[MSG_KEYNAME_KPENTER] = "keypad enter",
[MSG_KEYNAME_RIGHTCTRL] = "right control",
[MSG_KEYNAME_KPSLASH] = "keypad slash",
[MSG_KEYNAME_SYSRQ] = "sysrq",
[MSG_KEYNAME_RIGHTALT] = "right alt",
[MSG_KEYNAME_LF] = "line feed",
[MSG_KEYNAME_HOME] = "home",
[MSG_KEYNAME_UP] = "up",
[MSG_KEYNAME_PGUP] = "page up",
[MSG_KEYNAME_LEFT] = "left",
[MSG_KEYNAME_RIGHT] = "right",
[MSG_KEYNAME_END] = "end",
[MSG_KEYNAME_DOWN] = "down",
[MSG_KEYNAME_PGDN] = "page down",
[MSG_KEYNAME_INS] = "insert",
[MSG_KEYNAME_DEL] = "delete",
[MSG_KEYNAME_MACRO] = "macro",
[MSG_KEYNAME_MUTE] = "mute",
[MSG_KEYNAME_VOLDOWN] = "volume down",
[MSG_KEYNAME_VOLUP] = "volume up",
[MSG_KEYNAME_POWER] = "power",
[MSG_KEYNAME_KPEQUAL] = "keypad equal",
[MSG_KEYNAME_KPPLUSDASH] = "keypad plusminus",
[MSG_KEYNAME_PAUSE] = "pause",
[MSG_KEYNAME_F21] = "f21",
[MSG_KEYNAME_F22] = "f22",
[MSG_KEYNAME_F23] = "f23",
[MSG_KEYNAME_F24] = "f24",
[MSG_KEYNAME_KPCOMMA] = "keypad comma",
[MSG_KEYNAME_LEFTMETA] = "left meta",
[MSG_KEYNAME_RIGHTMETA] = "right meta",
[MSG_KEYNAME_COMPOSE] = "compose",
[MSG_KEYNAME_STOP] = "stop",
[MSG_KEYNAME_AGAIN] = "again",
[MSG_KEYNAME_PROPS] = "props",
[MSG_KEYNAME_UNDO] = "undo",
[MSG_KEYNAME_FRONT] = "front",
[MSG_KEYNAME_COPY] = "copy",
[MSG_KEYNAME_OPEN] = "open",
[MSG_KEYNAME_PASTE] = "paste",
[MSG_KEYNAME_FIND] = "find",
[MSG_KEYNAME_CUT] = "cut",
[MSG_KEYNAME_HELP] = "help",
[MSG_KEYNAME_MENU] = "menu",
[MSG_KEYNAME_CALC] = "calc",
[MSG_KEYNAME_SETUP] = "setup",
[MSG_KEYNAME_SLEEP] = "sleep",
[MSG_KEYNAME_WAKEUP] = "wakeup",
[MSG_KEYNAME_FILE] = "file",
[MSG_KEYNAME_SENDFILE] = "send file",
[MSG_KEYNAME_DELFILE] = "delete file",
[MSG_KEYNAME_XFER] = "transfer",
[MSG_KEYNAME_PROG1] = "prog1",
[MSG_KEYNAME_PROG2] = "prog2",
[MSG_KEYNAME_WWW] = "www",
[MSG_KEYNAME_MSDOS] = "msdos",
[MSG_KEYNAME_COFFEE] = "coffee",
[MSG_KEYNAME_DIRECTION] = "direction",
[MSG_KEYNAME_CYCLEWINDOWS] = "cycle windows",
[MSG_KEYNAME_MAIL] = "mail",
[MSG_KEYNAME_BOOKMARKS] = "bookmarks",
[MSG_KEYNAME_COMPUTER] = "computer",
[MSG_KEYNAME_BACK] = "back",
[MSG_KEYNAME_FORWARD] = "forward",
[MSG_KEYNAME_CLOSECD] = "close cd",
[MSG_KEYNAME_EJECTCD] = "eject cd",
[MSG_KEYNAME_EJECTCLOSE] = "eject close cd",
[MSG_KEYNAME_NEXTSONG] = "next song",
[MSG_KEYNAME_PLAYPAUSE] = "play pause",
[MSG_KEYNAME_PREVSONG] = "previous song",
[MSG_KEYNAME_STOPCD] = "stop cd",
[MSG_KEYNAME_RECORD] = "record",
[MSG_KEYNAME_REWIND] = "rewind",
[MSG_KEYNAME_PHONE] = "phone",
[MSG_KEYNAME_ISO] = "iso",
[MSG_KEYNAME_CONFIG] = "config",
[MSG_KEYNAME_HOMEPG] = "home page",
[MSG_KEYNAME_REFRESH] = "refresh",
[MSG_KEYNAME_EXIT] = "exit",
[MSG_KEYNAME_MOVE] = "move",
[MSG_KEYNAME_EDIT] = "edit",
[MSG_KEYNAME_SCROLLUP] = "scroll up",
[MSG_KEYNAME_SCROLLDN] = "scroll down",
[MSG_KEYNAME_KPLEFTPAR] = "keypad left paren",
[MSG_KEYNAME_KPRIGHTPAR] = "keypad right paren",
/* Function names. */
[MSG_FUNCNAME_ATTRIB_BLEEP_DEC] = "attribute bleep decrement",
[MSG_FUNCNAME_ATTRIB_BLEEP_INC] = "attribute bleep increment",
[MSG_FUNCNAME_BLEEPS_DEC] = "bleeps decrement",
[MSG_FUNCNAME_BLEEPS_INC] = "bleeps increment",
[MSG_FUNCNAME_CHAR_FIRST] = "character, first",
[MSG_FUNCNAME_CHAR_LAST] = "character, last",
[MSG_FUNCNAME_CHAR_CURRENT] = "character, say current",
[MSG_FUNCNAME_CHAR_HEX_AND_DEC] = "character, say hex and decimal",
[MSG_FUNCNAME_CHAR_NEXT] = "character, say next",
[MSG_FUNCNAME_CHAR_PHONETIC] = "character, say phonetic",
[MSG_FUNCNAME_CHAR_PREVIOUS] = "character, say previous",
[MSG_FUNCNAME_CURSOR_PARK] = "cursor park",
[MSG_FUNCNAME_CUT] = "cut",
[MSG_FUNCNAME_EDIT_DELIM] = "edit delimiters",
[MSG_FUNCNAME_EDIT_EXNUM] = "edit exnum",
[MSG_FUNCNAME_EDIT_MOST] = "edit most",
[MSG_FUNCNAME_EDIT_REPEATS] = "edit repeats",
[MSG_FUNCNAME_EDIT_SOME] = "edit some",
[MSG_FUNCNAME_GOTO] = "go to",
[MSG_FUNCNAME_GOTO_BOTTOM] = "go to bottom edge",
[MSG_FUNCNAME_GOTO_LEFT] = "go to left edge",
[MSG_FUNCNAME_GOTO_RIGHT] = "go to right edge",
[MSG_FUNCNAME_GOTO_TOP] = "go to top edge",
[MSG_FUNCNAME_HELP] = "help",
[MSG_FUNCNAME_LINE_SAY_CURRENT] = "line, say current",
[MSG_FUNCNAME_LINE_SAY_NEXT] = "line, say next",
[MSG_FUNCNAME_LINE_SAY_PREVIOUS] = "line, say previous",
[MSG_FUNCNAME_LINE_SAY_WITH_INDENT] = "line, say with indent",
[MSG_FUNCNAME_PASTE] = "paste",
[MSG_FUNCNAME_PITCH_DEC] = "pitch decrement",
[MSG_FUNCNAME_PITCH_INC] = "pitch increment",
[MSG_FUNCNAME_PUNC_DEC] = "punctuation decrement",
[MSG_FUNCNAME_PUNC_INC] = "punctuation increment",
[MSG_FUNCNAME_PUNC_LEVEL_DEC] = "punc level decrement",
[MSG_FUNCNAME_PUNC_LEVEL_INC] = "punc level increment",
[MSG_FUNCNAME_QUIET] = "quiet",
[MSG_FUNCNAME_RATE_DEC] = "rate decrement",
[MSG_FUNCNAME_RATE_INC] = "rate increment",
[MSG_FUNCNAME_READING_PUNC_DEC] = "reading punctuation decrement",
[MSG_FUNCNAME_READING_PUNC_INC] = "reading punctuation increment",
[MSG_FUNCNAME_SAY_ATTRIBUTES] = "say attributes",
[MSG_FUNCNAME_SAY_FROM_LEFT] = "say from left",
[MSG_FUNCNAME_SAY_FROM_TOP] = "say from top",
[MSG_FUNCNAME_SAY_POSITION] = "say position",
[MSG_FUNCNAME_SAY_SCREEN] = "say screen",
[MSG_FUNCNAME_SAY_TO_BOTTOM] = "say to bottom",
[MSG_FUNCNAME_SAY_TO_RIGHT] = "say to right",
[MSG_FUNCNAME_SPEAKUP] = "speakup",
[MSG_FUNCNAME_SPEAKUP_LOCK] = "speakup lock",
[MSG_FUNCNAME_SPEAKUP_OFF] = "speakup off",
[MSG_FUNCNAME_SPEECH_KILL] = "speech kill",
[MSG_FUNCNAME_SPELL_DELAY_DEC] = "spell delay decrement",
[MSG_FUNCNAME_SPELL_DELAY_INC] = "spell delay increment",
[MSG_FUNCNAME_SPELL_WORD] = "spell word",
[MSG_FUNCNAME_SPELL_WORD_PHONETICALLY] = "spell word phonetically",
[MSG_FUNCNAME_TONE_DEC] = "tone decrement",
[MSG_FUNCNAME_TONE_INC] = "tone increment",
[MSG_FUNCNAME_VOICE_DEC] = "voice decrement",
[MSG_FUNCNAME_VOICE_INC] = "voice increment",
[MSG_FUNCNAME_VOLUME_DEC] = "volume decrement",
[MSG_FUNCNAME_VOLUME_INC] = "volume increment",
[MSG_FUNCNAME_WINDOW_CLEAR] = "window, clear",
[MSG_FUNCNAME_WINDOW_SAY] = "window, say",
[MSG_FUNCNAME_WINDOW_SET] = "window, set",
[MSG_FUNCNAME_WINDOW_SILENCE] = "window, silence",
[MSG_FUNCNAME_WORD_SAY_CURRENT] = "word, say current",
[MSG_FUNCNAME_WORD_SAY_NEXT] = "word, say next",
[MSG_FUNCNAME_WORD_SAY_PREVIOUS] = "word, say previous",
};
static struct msg_group_t all_groups[] = {
{
.name = "ctl_keys",
.start = MSG_CTL_START,
.end = MSG_CTL_END,
},
{
.name = "colors",
.start = MSG_COLORS_START,
.end = MSG_COLORS_END,
},
{
.name = "formatted",
.start = MSG_FORMATTED_START,
.end = MSG_FORMATTED_END,
},
{
.name = "function_names",
.start = MSG_FUNCNAMES_START,
.end = MSG_FUNCNAMES_END,
},
{
.name = "key_names",
.start = MSG_KEYNAMES_START,
.end = MSG_KEYNAMES_END,
},
{
.name = "announcements",
.start = MSG_ANNOUNCEMENTS_START,
.end = MSG_ANNOUNCEMENTS_END,
},
{
.name = "states",
.start = MSG_STATES_START,
.end = MSG_STATES_END,
},
};
static const int num_groups = ARRAY_SIZE(all_groups);
char *spk_msg_get(enum msg_index_t index)
{
return speakup_msgs[index];
}
/*
* Function: next_specifier
* Finds the start of the next format specifier in the argument string.
* Return value: pointer to start of format
* specifier, or NULL if no specifier exists.
*/
static char *next_specifier(char *input)
{
int found = 0;
char *next_percent = input;
while (next_percent && !found) {
next_percent = strchr(next_percent, '%');
if (next_percent) {
/* skip over doubled percent signs */
while (next_percent[0] == '%' &&
next_percent[1] == '%')
next_percent += 2;
if (*next_percent == '%')
found = 1;
else if (*next_percent == '\0')
next_percent = NULL;
}
}
return next_percent;
}
/* Skip over 0 or more flags. */
static char *skip_flags(char *input)
{
while ((*input != '\0') && strchr(" 0+-#", *input))
input++;
return input;
}
/* Skip over width.precision, if it exists. */
static char *skip_width(char *input)
{
while (isdigit(*input))
input++;
if (*input == '.') {
input++;
while (isdigit(*input))
input++;
}
return input;
}
/*
* Skip past the end of the conversion part.
* Note that this code only accepts a handful of conversion specifiers:
* c d s x and ld. Not accidental; these are exactly the ones used in
* the default group of formatted messages.
*/
static char *skip_conversion(char *input)
{
if ((input[0] == 'l') && (input[1] == 'd'))
input += 2;
else if ((*input != '\0') && strchr("cdsx", *input))
input++;
return input;
}
/*
* Function: find_specifier_end
* Return a pointer to the end of the format specifier.
*/
static char *find_specifier_end(char *input)
{
input++; /* Advance over %. */
input = skip_flags(input);
input = skip_width(input);
input = skip_conversion(input);
return input;
}
/*
* Function: compare_specifiers
* Compare the format specifiers pointed to by *input1 and *input2.
* Return true if they are the same, false otherwise.
* Advance *input1 and *input2 so that they point to the character following
* the end of the specifier.
*/
static bool compare_specifiers(char **input1, char **input2)
{
bool same = false;
char *end1 = find_specifier_end(*input1);
char *end2 = find_specifier_end(*input2);
size_t length1 = end1 - *input1;
size_t length2 = end2 - *input2;
if ((length1 == length2) && !memcmp(*input1, *input2, length1))
same = true;
*input1 = end1;
*input2 = end2;
return same;
}
/*
* Function: fmt_validate
* Check that two format strings contain the same number of format specifiers,
* and that the order of specifiers is the same in both strings.
* Return true if the condition holds, false if it doesn't.
*/
static bool fmt_validate(char *template, char *user)
{
bool valid = true;
bool still_comparing = true;
char *template_ptr = template;
char *user_ptr = user;
while (still_comparing && valid) {
template_ptr = next_specifier(template_ptr);
user_ptr = next_specifier(user_ptr);
if (template_ptr && user_ptr) {
/* Both have at least one more specifier. */
valid = compare_specifiers(&template_ptr, &user_ptr);
} else {
/* No more format specifiers in one or both strings. */
still_comparing = false;
/* See if one has more specifiers than the other. */
if (template_ptr || user_ptr)
valid = false;
}
}
return valid;
}
/*
* Function: msg_set
* Description: Add a user-supplied message to the user_messages array.
* The message text is copied to a memory area allocated with kmalloc.
* If the function fails, then user_messages is untouched.
* Arguments:
* - index: a message number, as found in i18n.h.
* - text: text of message. Not NUL-terminated.
* - length: number of bytes in text.
* Failure conditions:
* -EINVAL - Invalid format specifiers in formatted message or illegal index.
* -ENOMEM - Unable to allocate memory.
*/
ssize_t spk_msg_set(enum msg_index_t index, char *text, size_t length)
{
char *newstr = NULL;
unsigned long flags;
if ((index < MSG_FIRST_INDEX) || (index >= MSG_LAST_INDEX))
return -EINVAL;
newstr = kmemdup_nul(text, length, GFP_KERNEL);
if (!newstr)
return -ENOMEM;
if (index >= MSG_FORMATTED_START &&
index <= MSG_FORMATTED_END &&
!fmt_validate(speakup_default_msgs[index], newstr)) {
kfree(newstr);
return -EINVAL;
}
spin_lock_irqsave(&speakup_info.spinlock, flags);
if (speakup_msgs[index] != speakup_default_msgs[index])
kfree(speakup_msgs[index]);
speakup_msgs[index] = newstr;
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
return 0;
}
/*
* Find a message group, given its name. Return a pointer to the structure
* if found, or NULL otherwise.
*/
struct msg_group_t *spk_find_msg_group(const char *group_name)
{
struct msg_group_t *group = NULL;
int i;
for (i = 0; i < num_groups; i++) {
if (!strcmp(all_groups[i].name, group_name)) {
group = &all_groups[i];
break;
}
}
return group;
}
void spk_reset_msg_group(struct msg_group_t *group)
{
unsigned long flags;
enum msg_index_t i;
spin_lock_irqsave(&speakup_info.spinlock, flags);
for (i = group->start; i <= group->end; i++) {
if (speakup_msgs[i] != speakup_default_msgs[i])
kfree(speakup_msgs[i]);
speakup_msgs[i] = speakup_default_msgs[i];
}
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
}
/* Called at initialization time, to establish default messages. */
void spk_initialize_msgs(void)
{
memcpy(speakup_msgs, speakup_default_msgs,
sizeof(speakup_default_msgs));
}
/* Free user-supplied strings when module is unloaded: */
void spk_free_user_msgs(void)
{
enum msg_index_t index;
unsigned long flags;
spin_lock_irqsave(&speakup_info.spinlock, flags);
for (index = MSG_FIRST_INDEX; index < MSG_LAST_INDEX; index++) {
if (speakup_msgs[index] != speakup_default_msgs[index]) {
kfree(speakup_msgs[index]);
speakup_msgs[index] = speakup_default_msgs[index];
}
}
spin_unlock_irqrestore(&speakup_info.spinlock, flags);
}