+static void keymap_lookup_key(MappedKey *mk, KeySym sym, const char *what) {
+ const MappedModifier *shift, *xshift;
+ int col, kc;
+ char cols[MAXMAPCOL+1];
+
+ memset(cols,'.',MAXMAPCOL);
+ cols[MAXMAPCOL]= 0;
+
+ for (col=0; col<mapwidth && col<MAXMAPCOL; col++) {
+ keydebugf("KEYMAP lookup %-10s %#lx col=%d ",
+ what, (unsigned long)sym, col);
+
+#define CHECK_SHIFT(sh) do{ \
+ if ((sh) && (sh)->isdef!='y') { \
+ cols[col]= (sh)->isdef; \
+ keydebugf("no-modifier " #sh "'%c'\n", (sh)->isdef); \
+ continue; \
+ } \
+ }while(0)
+
+ shift= col & 1 ? &mm_shift : 0;
+ CHECK_SHIFT(shift);
+
+ xshift= col >= 4 ? &mm_isol3shift :
+ col >= 2 ? &mm_modeswitch :
+ 0;
+ CHECK_SHIFT(xshift);
+
+ for (kc=kc_min; kc <= kc_max; kc++) {
+ if (mapping[(kc-kc_min)*mapwidth + col] == sym)
+ goto found;
+ }
+ cols[col]= '_';
+ keydebugf("not-found\n");
+ }
+ fprintf(stderr,"\n"
+ "Unable to find a key to press to generate %s.\n"
+ "(Technical details: cols:%s sh:%c:%d modesw:%c:%d isol3:%c:%d)\n",
+ what, cols,
+#define SH_DETAILS(sh) mm_##sh.isdef, mm_##sh.kc
+ SH_DETAILS(shift), SH_DETAILS(modeswitch), SH_DETAILS(isol3shift));
+ fatal("Keymap is unsuitable!");
+
+ found:;
+ int *fill= mk->kc;
+
+ if (xshift) *fill++ = xshift->kc;
+ if (shift) *fill++ = shift->kc;
+ *fill++ += kc;
+ mk->len= fill - mk->kc;
+ keydebugf("found kc=%d len=%d\n",kc,mk->len);