[SeaBIOS] [PATCH v2 4/6] boot: reorganize interactive_bootmenu

Paolo Bonzini pbonzini at redhat.com
Wed Oct 17 18:23:46 CEST 2012


This reindents the code and introduces a switch statement, to prepare for
adding F11 as a shortcut for network boot.

Signed-off-by: Paolo Bonzini <pbonzini at redhat.com>
---
 src/boot.c | 76 +++++++++++++++++++++++++++++++++-----------------------------
 1 file modificato, 40 inserzioni(+), 36 rimozioni(-)

diff --git a/src/boot.c b/src/boot.c
index 5101167..e3bdd7b 100644
--- a/src/boot.c
+++ b/src/boot.c
@@ -412,48 +412,52 @@ interactive_bootmenu(void)
     enable_bootsplash();
     int scan_code = get_keystroke(menutime);
     disable_bootsplash();
-    if (scan_code != 0x86)
-        /* not F12 */
-        return;
-
-    while (get_keystroke(0) >= 0)
-        ;
+    switch (scan_code) {
+    case 0x86: { // F12
+        printf("Select boot device:\n\n");
+        wait_threads();
 
-    printf("Select boot device:\n\n");
-    wait_threads();
+        // Show menu items
+        struct bootentry_s *pos = BootList;
+        int maxmenu = 0;
+        while (pos) {
+            char desc[60];
+            maxmenu++;
+            printf("%d. %s\n", maxmenu
+                   , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
+            pos = pos->next;
+        }
 
-    // Show menu items
-    struct bootentry_s *pos = BootList;
-    int maxmenu = 0;
-    while (pos) {
-        char desc[60];
-        maxmenu++;
-        printf("%d. %s\n", maxmenu
-               , strtcpy(desc, pos->description, ARRAY_SIZE(desc)));
-        pos = pos->next;
-    }
+        // Get key press
+        while (get_keystroke(0) >= 0)
+            ;
 
-    // Get key press
-    for (;;) {
-        scan_code = get_keystroke(1000);
-        if (scan_code >= 1 && scan_code <= maxmenu+1)
+        for (;;) {
+            scan_code = get_keystroke(1000);
+            if (scan_code >= 1 && scan_code <= maxmenu+1)
+                break;
+        }
+        printf("\n");
+        if (scan_code == 0x01)
+            // ESC
             break;
+
+        // Find entry and make top priority.
+        int choice = scan_code - 1;
+        struct bootentry_s **pprev = &BootList;
+        while (--choice)
+            pprev = &(*pprev)->next;
+        pos = *pprev;
+        *pprev = pos->next;
+        pos->next = BootList;
+        BootList = pos;
+        pos->priority = 0;
+        break;
     }
-    printf("\n");
-    if (scan_code == 0x01)
-        // ESC
-        return;
 
-    // Find entry and make top priority.
-    int choice = scan_code - 1;
-    struct bootentry_s **pprev = &BootList;
-    while (--choice)
-        pprev = &(*pprev)->next;
-    pos = *pprev;
-    *pprev = pos->next;
-    pos->next = BootList;
-    BootList = pos;
-    pos->priority = 0;
+    default:
+        break;
+    }
 }
 
 // BEV (Boot Execution Vector) list
-- 
1.7.12.1





More information about the SeaBIOS mailing list