4 #include <linux/slab.h>
5 #include <linux/ctype.h>
6 #include <linux/module.h>
7 #include <linux/string.h>
46 "press space to exit, up or down to scroll, or a letter to go to a command",
370 .name =
"function_names",
380 .name =
"announcements",
391 static const int num_groups =
sizeof(all_groups) /
sizeof(
struct msg_group_t);
397 ch = speakup_msgs[
index];
407 static char *next_specifier(
char *
input)
410 char *next_percent =
input;
412 while ((next_percent !=
NULL) && !found) {
413 next_percent =
strchr(next_percent,
'%');
414 if (next_percent !=
NULL) {
416 while ((next_percent[0] ==
'%')
417 && (next_percent[1] ==
'%'))
419 if (*next_percent ==
'%')
421 else if (*next_percent ==
'\0')
430 static char *skip_flags(
char *input)
432 while ((*input !=
'\0') &&
strchr(
" 0+-#", *input))
438 static char *skip_width(
char *input)
456 static char *skip_conversion(
char *input)
458 if ((input[0] ==
'l') && (input[1] ==
'd'))
460 else if ((*input !=
'\0') &&
strchr(
"cdsx", *input))
469 static char *find_specifier_end(
char *input)
472 input = skip_flags(input);
473 input = skip_width(input);
474 input = skip_conversion(input);
484 static int compare_specifiers(
char **input1,
char **input2)
487 char *end1 = find_specifier_end(*input1);
488 char *end2 = find_specifier_end(*input2);
489 size_t length1 = end1 - *input1;
490 size_t length2 = end2 - *input2;
492 if ((length1 == length2) && !
memcmp(*input1, *input2, length1))
506 static int fmt_validate(
char *
template,
char *
user)
509 int still_comparing = 1;
510 char *template_ptr =
template;
511 char *user_ptr =
user;
513 while (still_comparing && valid) {
514 template_ptr = next_specifier(template_ptr);
515 user_ptr = next_specifier(user_ptr);
516 if (template_ptr && user_ptr) {
518 valid = compare_specifiers(&template_ptr, &user_ptr);
523 if (template_ptr || user_ptr)
552 memcpy(newstr, text, length);
556 && !fmt_validate(speakup_default_msgs[index],
562 if (speakup_msgs[index] != speakup_default_msgs[index])
563 kfree(speakup_msgs[index]);
564 speakup_msgs[
index] = newstr;
584 for (i = 0; i < num_groups; i++) {
585 if (!
strcmp(all_groups[i].
name, group_name)) {
586 group = &all_groups[
i];
600 for (i = group->
start; i <= group->
end; i++) {
601 if (speakup_msgs[i] != speakup_default_msgs[i])
602 kfree(speakup_msgs[i]);
603 speakup_msgs[
i] = speakup_default_msgs[
i];
611 memcpy(speakup_msgs, speakup_default_msgs,
612 sizeof(speakup_default_msgs));
623 if (speakup_msgs[index] != speakup_default_msgs[index]) {
624 kfree(speakup_msgs[index]);
625 speakup_msgs[
index] = speakup_default_msgs[
index];