+char *
+GenerateGlobalTranslationTable (void)
+{
+ /* go through all menu items and extract the keyboard shortcuts, so that X11 can load them */
+ char *output;
+
+ int i,j;
+ MenuItem *mi;
+
+ output = strdup("");
+
+ /* loop over all menu entries */
+ for( i=0; menuBar[i].mi ; i++)
+ {
+ mi = menuBar[i].mi;
+ for(j=0; mi[j].proc; j++)
+ {
+ if (mi[j].accel)
+ {
+ int ctrl = 0;
+ int shift = 0;
+ int alt = 0;
+
+ char *key,*test, *mods;
+
+ /* check for Ctrl/Alt */
+ if( strstr(mi[j].accel, "<Ctrl>") ) ctrl = 1;
+ if( strstr(mi[j].accel, "<Shift>") ) shift = 1;
+ if( strstr(mi[j].accel, "<Alt>") ) alt = 1;
+
+ /* remove all <...> */
+ test = strrchr(mi[j].accel, '>');
+ if ( test==NULL )
+ key = strdup(mi[j].accel);
+ else
+ key = strdup(++test); // remove ">"
+
+ /* instead of shift X11 uses the uppercase letter directly*/
+ if (shift && strlen(key)==1 )
+ {
+ *key = toupper(*key);
+ shift = 0;
+ }
+
+ /* handle some special cases which have different names in X11 */
+ if ( strncmp(key, "Page_Down", 9) == 0 )
+ {
+ free(key);
+ key=strdup("Next");
+ }
+ else if ( strncmp(key, "Page_Up", 7) == 0 )
+ {
+ free(key);
+ key=strdup("Prior");
+ };
+
+ /* create string of mods */
+ if (ctrl)
+ mods = strdup("Ctrl ");
+ else
+ mods = strdup("");
+
+ if(alt)
+ {
+ mods = realloc(mods, strlen(mods) + strlen("Meta ")+1);
+ strncat(mods, "Meta ", 5);
+ };
+
+ if(shift)
+ {
+ mods = realloc(mods, strlen(mods) + strlen("Shift ")+1);
+ strncat(mods, "Shift ", 6);
+ };
+
+ // remove trailing space
+ if( isspace(mods[strlen(mods)-1]) )
+ mods[strlen(mods)-1]='\0';
+
+ /* get the name for the callback, we can use MenuItem() here that will call KeyBindingProc */
+ size_t namesize = snprintf(NULL, 0, "%s.%s", menuBar[i].ref, mi[j].ref);
+ char *name = malloc(namesize+1);
+ snprintf(name, namesize+1, "%s.%s", menuBar[i].ref, mi[j].ref);
+
+ size_t buffersize = snprintf(NULL, 0, ":%s<Key>%s: MenuItem(%s) \n ", mods, key, name);
+ char *buffer = malloc(buffersize+1);
+ snprintf(buffer, buffersize+1, ":%s<Key>%s: MenuItem(%s) \n ", mods, key, name);
+
+ /* add string to the output */
+ output = realloc(output, strlen(output) + strlen(buffer)+1);
+ strncat(output, buffer, strlen(buffer));
+
+ /* clean up */
+ free(key);
+ free(buffer);
+ free(name);
+ free(mods);
+ }
+ }
+ }
+ return output;
+}
+
+