]> git.ipfire.org Git - thirdparty/util-linux.git/commitdiff
fdisk: detect menu entries collisions in debug mode
authorKarel Zak <kzak@redhat.com>
Fri, 17 May 2013 12:11:51 +0000 (14:11 +0200)
committerKarel Zak <kzak@redhat.com>
Mon, 16 Sep 2013 14:46:55 +0000 (16:46 +0200)
Signed-off-by: Karel Zak <kzak@redhat.com>
fdisks/fdisk-menu.c

index 7cbf83b74125b4b89545333210202acf13916f8c..09d5ff0c4dd7ae11a29fb7f577776adc791c0d8d 100644 (file)
@@ -178,11 +178,61 @@ static const struct menu_entry *next_menu_entry(
        return NULL;
 }
 
+/* returns @menu and menu entry for then @key */
+static const struct menu_entry *get_fdisk_menu_entry(
+               struct fdisk_context *cxt,
+               int key,
+               const struct menu **menu)
+{
+       struct menu_context mc = MENU_CXT_EMPTY;
+       const struct menu_entry *e;
+
+       while ((e = next_menu_entry(cxt, &mc))) {
+               if (IS_MENU_SEP(e) || e->key != key)
+                       continue;
+
+               if (menu)
+                       *menu = menus[mc.menu_idx];
+               return e;
+       }
+
+       return NULL;
+}
+
+static int menu_detect_collisions(struct fdisk_context *cxt)
+{
+       struct menu_context mc = MENU_CXT_EMPTY;
+       const struct menu_entry *e, *r;
+
+       while ((e = next_menu_entry(cxt, &mc))) {
+               if (IS_MENU_SEP(e))
+                       continue;
+
+               r = get_fdisk_menu_entry(cxt, e->key, NULL);
+               if (!r) {
+                       DBG(CONTEXT, dbgprint("warning: not found "
+                                       "entry for %c", e->key));
+                       return -1;
+               }
+               if (r != e) {
+                       DBG(CONTEXT, dbgprint("warning: duplicate key '%c'",
+                                               e->key));
+                       DBG(CONTEXT, dbgprint("         %s", e->title));
+                       DBG(CONTEXT, dbgprint("         %s", r->title));
+                       abort();
+               }
+       }
+
+       return 0;
+}
+
 static int print_fdisk_menu(struct fdisk_context *cxt)
 {
        struct menu_context mc = MENU_CXT_EMPTY;
        const struct menu_entry *e;
 
+       ON_DBG(CONTEXT, menu_detect_collisions(cxt));
+
        if (fdisk_context_display_details(cxt))
                printf(_("\nExpert commands:\n"));
        else