int keymapMenuSelect(dialogMenuItem *self) { static const struct { const char *country, *lang; } map[] = { {"dk", "danish"}, {"ee", "estonian"}, {"fi", "finnish"}, {"de", "german"}, {"is", "icelandic"}, {"no", "norwegian"}, {"pl", "pl_PL"}, {"es", "spanish"}, {"se", "swedish"}, {"ch", "swiss"}, {"gb", "uk"}, {"gg", "uk"}, {"ie", "uk"}, {"im", "uk"}, {"je", "uk"}, {NULL, NULL} }; const char *country, *lang; int i; int choice, scroll, curr, max; char prefix[16 + 1]; if ((country = variable_get(VAR_COUNTRY)) != NULL) { lang = country; for (i = 0; map[i].country; ++i) if (!strcmp(country, map[i].country)) { lang = map[i].lang; break; } snprintf(prefix, sizeof(prefix), "keymap=%s.iso", lang); if ((choice = keymapSetDefault(prefix)) == -1) { snprintf(prefix, sizeof(prefix), "keymap=%s", lang); if ((choice = keymapSetDefault(prefix)) == -1) { #ifdef PC98 snprintf(prefix, sizeof(prefix), "keymap=jp.pc98"); #else snprintf(prefix, sizeof(prefix), "keymap=us.iso"); #endif if ((choice = keymapSetDefault(prefix)) == -1) choice = 0; } } dmenuSetDefaultIndex(&MenuSysconsKeymap, &choice, &scroll, &curr, &max); return dmenuOpen(&MenuSysconsKeymap, &choice, &scroll, &curr, &max, FALSE); } else return dmenuOpenSimple(&MenuSysconsKeymap, FALSE) ? DITEM_SUCCESS : DITEM_FAILURE; }
/* Set the default menu item that matches any field and scroll to it. */ Boolean dmenuSetDefaultItem(DMenu *menu, const char *prompt, const char *title, void *data, int *choice, int *scroll, int *curr, int *max) { if ((*choice = dmenuFindItem(menu, prompt, title, data)) != -1) { dmenuSetDefaultIndex(menu, choice, scroll, curr, max); return TRUE; } else { *choice = *scroll = *curr = *max = 0; return FALSE; } }