]> git.dujemihanovic.xyz Git - u-boot.git/commitdiff
efi_selftest: refactor text input test
authorHeinrich Schuchardt <xypron.glpk@gmx.de>
Tue, 11 Sep 2018 20:38:04 +0000 (22:38 +0200)
committerAlexander Graf <agraf@suse.de>
Sun, 23 Sep 2018 19:55:30 +0000 (21:55 +0200)
Move reusable utility functions to efi_selftest_util.c.

Signed-off-by: Heinrich Schuchardt <xypron.glpk@gmx.de>
Signed-off-by: Alexander Graf <agraf@suse.de>
include/efi_selftest.h
lib/efi_selftest/efi_selftest_textinput.c
lib/efi_selftest/efi_selftest_util.c

index 59b3c080bde60f9930f7675e07ceeec9b495fdc7..56beac305ec6906e81390fe2a6eca0873b90cec3 100644 (file)
@@ -76,6 +76,22 @@ void efi_st_exit_boot_services(void);
 void efi_st_printc(int color, const char *fmt, ...)
                 __attribute__ ((format (__printf__, 2, 3)));
 
+/**
+ * efi_st_translate_char() - translate a unicode character to a string
+ *
+ * @code:      unicode character
+ * Return:     string
+ */
+u16 *efi_st_translate_char(u16 code);
+
+/**
+ * efi_st_translate_code() - translate a scan code to a human readable string
+ *
+ * @code:      unicode character
+ * Return:     string
+ */
+u16 *efi_st_translate_code(u16 code);
+
 /*
  * Compare memory.
  * We cannot use lib/string.c due to different CFLAGS values.
index 7aa84de89ddaf52befc2b1710f3df0689e48ace5..40b0a8b25cf06ae8a8fa351c607b47f6584b7243 100644 (file)
 
 #include <efi_selftest.h>
 
-struct translate {
-       u16 code;
-       u16 *text;
-};
-
 static struct efi_boot_services *boottime;
 
-static struct translate control_characters[] = {
-       {0, L"Null"},
-       {8, L"BS"},
-       {9, L"TAB"},
-       {10, L"LF"},
-       {13, L"CR"},
-       {0, NULL},
-};
-
-static u16 ch[] = L"' '";
-static u16 unknown[] = L"unknown";
-
-static struct translate scan_codes[] = {
-       {0x00, L"Null"},
-       {0x01, L"Up"},
-       {0x02, L"Down"},
-       {0x03, L"Right"},
-       {0x04, L"Left"},
-       {0x05, L"Home"},
-       {0x06, L"End"},
-       {0x07, L"Insert"},
-       {0x08, L"Delete"},
-       {0x09, L"Page Up"},
-       {0x0a, L"Page Down"},
-       {0x0b, L"FN 1"},
-       {0x0c, L"FN 2"},
-       {0x0d, L"FN 3"},
-       {0x0e, L"FN 4"},
-       {0x0f, L"FN 5"},
-       {0x10, L"FN 6"},
-       {0x11, L"FN 7"},
-       {0x12, L"FN 8"},
-       {0x13, L"FN 9"},
-       {0x14, L"FN 10"},
-       {0x15, L"FN 11"},
-       {0x16, L"FN 12"},
-       {0x17, L"Escape"},
-       {0x68, L"FN 13"},
-       {0x69, L"FN 14"},
-       {0x6a, L"FN 15"},
-       {0x6b, L"FN 16"},
-       {0x6c, L"FN 17"},
-       {0x6d, L"FN 18"},
-       {0x6e, L"FN 19"},
-       {0x6f, L"FN 20"},
-       {0x70, L"FN 21"},
-       {0x71, L"FN 22"},
-       {0x72, L"FN 23"},
-       {0x73, L"FN 24"},
-       {0x7f, L"Mute"},
-       {0x80, L"Volume Up"},
-       {0x81, L"Volume Down"},
-       {0x100, L"Brightness Up"},
-       {0x101, L"Brightness Down"},
-       {0x102, L"Suspend"},
-       {0x103, L"Hibernate"},
-       {0x104, L"Toggle Display"},
-       {0x105, L"Recovery"},
-       {0x106, L"Reject"},
-       {0x0, NULL},
-};
-
-/*
- * Translate a unicode character to a string.
- *
- * @code       unicode character
- * @return     string
- */
-static u16 *translate_char(u16 code)
-{
-       struct translate *tr;
-
-       if (code >= ' ') {
-               ch[1] = code;
-               return ch;
-       }
-       for (tr = control_characters; tr->text; ++tr) {
-               if (tr->code == code)
-                       return tr->text;
-       }
-       return unknown;
-}
-
-/*
- * Translate a scan code to a human readable string.
- *
- * @code       unicode character
- * @return     string
- */
-static u16 *translate_code(u16 code)
-{
-       struct translate *tr;
-
-       for (tr = scan_codes; tr->text; ++tr) {
-               if (tr->code == code)
-                       return tr->text;
-       }
-       return unknown;
-}
-
 /*
  * Setup unit test.
  *
@@ -160,9 +55,9 @@ static int execute(void)
 
                efi_st_printf("Unicode char %u (%ps), scan code %u (%ps)\n",
                              (unsigned int)input_key.unicode_char,
-                             translate_char(input_key.unicode_char),
+                             efi_st_translate_char(input_key.unicode_char),
                              (unsigned int)input_key.scan_code,
-                             translate_code(input_key.scan_code));
+                             efi_st_translate_code(input_key.scan_code));
 
                switch (input_key.unicode_char) {
                case 'x':
index 87a04f898a47ad18c334d7242b3d5a739c041aeb..96a964c863ef7c5e641305d3316a0ece65d86202 100644 (file)
@@ -9,6 +9,99 @@
 
 #include <efi_selftest.h>
 
+struct efi_st_translate {
+       u16 code;
+       u16 *text;
+};
+
+static struct efi_st_translate efi_st_control_characters[] = {
+       {0, L"Null"},
+       {8, L"BS"},
+       {9, L"TAB"},
+       {10, L"LF"},
+       {13, L"CR"},
+       {0, NULL},
+};
+
+static u16 efi_st_ch[] = L"' '";
+static u16 efi_st_unknown[] = L"unknown";
+
+static struct efi_st_translate efi_st_scan_codes[] = {
+       {0x00, L"Null"},
+       {0x01, L"Up"},
+       {0x02, L"Down"},
+       {0x03, L"Right"},
+       {0x04, L"Left"},
+       {0x05, L"Home"},
+       {0x06, L"End"},
+       {0x07, L"Insert"},
+       {0x08, L"Delete"},
+       {0x09, L"Page Up"},
+       {0x0a, L"Page Down"},
+       {0x0b, L"FN 1"},
+       {0x0c, L"FN 2"},
+       {0x0d, L"FN 3"},
+       {0x0e, L"FN 4"},
+       {0x0f, L"FN 5"},
+       {0x10, L"FN 6"},
+       {0x11, L"FN 7"},
+       {0x12, L"FN 8"},
+       {0x13, L"FN 9"},
+       {0x14, L"FN 10"},
+       {0x15, L"FN 11"},
+       {0x16, L"FN 12"},
+       {0x17, L"Escape"},
+       {0x68, L"FN 13"},
+       {0x69, L"FN 14"},
+       {0x6a, L"FN 15"},
+       {0x6b, L"FN 16"},
+       {0x6c, L"FN 17"},
+       {0x6d, L"FN 18"},
+       {0x6e, L"FN 19"},
+       {0x6f, L"FN 20"},
+       {0x70, L"FN 21"},
+       {0x71, L"FN 22"},
+       {0x72, L"FN 23"},
+       {0x73, L"FN 24"},
+       {0x7f, L"Mute"},
+       {0x80, L"Volume Up"},
+       {0x81, L"Volume Down"},
+       {0x100, L"Brightness Up"},
+       {0x101, L"Brightness Down"},
+       {0x102, L"Suspend"},
+       {0x103, L"Hibernate"},
+       {0x104, L"Toggle Display"},
+       {0x105, L"Recovery"},
+       {0x106, L"Reject"},
+       {0x0, NULL},
+};
+
+u16 *efi_st_translate_char(u16 code)
+{
+       struct efi_st_translate *tr;
+
+       if (code >= ' ') {
+               efi_st_ch[1] = code;
+               return efi_st_ch;
+       }
+       for (tr = efi_st_control_characters; tr->text; ++tr) {
+               if (tr->code == code)
+                       return tr->text;
+       }
+       return efi_st_unknown;
+}
+
+u16 *efi_st_translate_code(u16 code)
+{
+       struct efi_st_translate *tr;
+
+       for (tr = efi_st_scan_codes; tr->text; ++tr) {
+               if (tr->code == code)
+                       return tr->text;
+       }
+       return efi_st_unknown;
+}
+
 int efi_st_memcmp(const void *buf1, const void *buf2, size_t length)
 {
        const u8 *pos1 = buf1;