From 3b4f9f16446895de513b6655a48d2e8074aec9b9 Mon Sep 17 00:00:00 2001 From: Karel Zak Date: Fri, 17 May 2013 14:11:51 +0200 Subject: fdisk: detect menu entries collisions in debug mode Signed-off-by: Karel Zak --- fdisks/fdisk-menu.c | 50 ++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 50 insertions(+) (limited to 'fdisks/fdisk-menu.c') diff --git a/fdisks/fdisk-menu.c b/fdisks/fdisk-menu.c index 7cbf83b74..09d5ff0c4 100644 --- a/fdisks/fdisk-menu.c +++ b/fdisks/fdisk-menu.c @@ -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 -- cgit v1.2.3-55-g7522