// 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] = …; static struct msg_group_t all_groups[] = …; static const int num_groups = …; char *spk_msg_get(enum msg_index_t 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) { … } /* Skip over 0 or more flags. */ static char *skip_flags(char *input) { … } /* Skip over width.precision, if it exists. */ static char *skip_width(char *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) { … } /* * Function: find_specifier_end * Return a pointer to the end of the format specifier. */ static char *find_specifier_end(char *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) { … } /* * 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) { … } /* * 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) { … } /* * 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) { … } void spk_reset_msg_group(struct msg_group_t *group) { … } /* Called at initialization time, to establish default messages. */ void spk_initialize_msgs(void) { … } /* Free user-supplied strings when module is unloaded: */ void spk_free_user_msgs(void) { … }