summaryrefslogtreecommitdiff
path: root/libxklavier/xklavier_config.c
blob: 6b37911d5e24add7f4836e4e9eee13e0b3373418 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
#include <errno.h>
#include <string.h>
#include <locale.h>
#include <sys/stat.h>

#include <libxml/xpath.h>

#include "config.h"

#include "xklavier_private.h"

#include <X11/extensions/XKBfile.h>
#include <X11/extensions/XKM.h>

#define RULES_FILE "xfree86"

#define RULES_PATH ( XKB_BASE "/rules/" RULES_FILE )

#define XML_CFG_PATH ( XKB_BASE "/rules/xfree86.xml" )

// For "bad" X servers we hold our own copy
#define XML_CFG_FALLBACK_PATH ( DATA_DIR "/xfree86.xml" )

#define MULTIPLE_LAYOUTS_CHECK_PATH ( XKB_BASE "/symbols/pc/en_US" )

#define XK_XKB_KEYS
#include <X11/keysymdef.h>

typedef struct _XklConfigRegistry
{
  xmlDocPtr doc;
  xmlXPathContextPtr xpathContext;
}
XklConfigRegistry;

XkbRF_VarDefsRec _xklVarDefs;

static XklConfigRegistry theRegistry;

static xmlXPathCompExprPtr modelsXPath;
static xmlXPathCompExprPtr layoutsXPath;
static xmlXPathCompExprPtr optionGroupsXPath;

static XkbRF_RulesPtr rules;
static XkbComponentNamesRec componentNames;
static char *locale;

static Bool _XklConfigInitialized(  )
{
  return theRegistry.xpathContext != NULL;
}

static xmlChar *_XklNodeGetXmlLangAttr( xmlNodePtr nptr )
{
  if( nptr->properties != NULL &&
      !strcmp( "lang", nptr->properties[0].name ) &&
      nptr->properties[0].ns != NULL &&
      !strcmp( "xml", nptr->properties[0].ns->prefix ) &&
      nptr->properties[0].children != NULL )
    return nptr->properties[0].children->content;
  else
    return NULL;
}

static Bool _XklReadConfigItem( xmlNodePtr iptr, XklConfigItemPtr pci )
{
  xmlNodePtr nameElement, descElement = NULL, ntDescElement =
    NULL, nptr, ptr, shortDescElement = NULL, ntShortDescElement = NULL;
  int maxDescPriority = -1;
  int maxShortDescPriority = -1;

  *pci->name = 0;
  *pci->shortDescription = 0;
  *pci->description = 0;
  if( iptr->type != XML_ELEMENT_NODE )
    return False;
  ptr = iptr->children;
  while( ptr != NULL )
  {
    switch ( ptr->type )
    {
      case XML_ELEMENT_NODE:
        if( !strcmp( ptr->name, "configItem" ) )
          break;
        return False;
      case XML_TEXT_NODE:
        ptr = ptr->next;
        continue;
      default:
        return False;
    }
    break;
  }
  if( ptr == NULL )
    return False;

  nptr = ptr->children;

  if( nptr->type == XML_TEXT_NODE )
    nptr = nptr->next;
  nameElement = nptr;
  nptr = nptr->next;

  while( nptr != NULL )
  {
    if( nptr->type != XML_TEXT_NODE )
    {
      xmlChar *lang = _XklNodeGetXmlLangAttr( nptr );

      if( lang != NULL )
      {
        int priority = _XklGetLanguagePriority( lang );
        if( !strcmp( nptr->name, "description" ) && ( priority > maxDescPriority ) )    // higher priority
        {
          descElement = nptr;
          maxDescPriority = priority;
        } else if( !strcmp( nptr->name, "shortDescription" ) && ( priority > maxShortDescPriority ) )   // higher priority
        {
          shortDescElement = nptr;
          maxShortDescPriority = priority;
        }
      } else
      {
        if( !strcmp( nptr->name, "description" ) )
          ntDescElement = nptr;
        else if( !strcmp( nptr->name, "shortDescription" ) )
          ntShortDescElement = nptr;
      }
    }
    nptr = nptr->next;
  }

  // if no language-specific description found - use the ones without lang
  if( descElement == NULL )
    descElement = ntDescElement;

  if( shortDescElement == NULL )
    shortDescElement = ntShortDescElement;

  //
  // Actually, here we should have some code to find the correct localized description...
  // 

  if( nameElement != NULL && nameElement->children != NULL )
    strncat( pci->name, nameElement->children->content,
             XKL_MAX_CI_NAME_LENGTH - 1 );

  if( shortDescElement != NULL && shortDescElement->children != NULL )
    strncat( pci->shortDescription,
             _XklLocaleFromUtf8( shortDescElement->children->content ),
             XKL_MAX_CI_SHORT_DESC_LENGTH - 1 );

  if( descElement != NULL && descElement->children != NULL )
    strncat( pci->description,
             _XklLocaleFromUtf8( descElement->children->content ),
             XKL_MAX_CI_DESC_LENGTH - 1 );
  return True;
}

static void _XklConfigEnumFromNodeSet( xmlNodeSetPtr nodes,
                                       ConfigItemProcessFunc func,
                                       void *userData )
{
  int i;
  if( nodes != NULL )
  {
    xmlNodePtr *theNodePtr = nodes->nodeTab;
    for( i = nodes->nodeNr; --i >= 0; )
    {
      XklConfigItem ci;
      if( _XklReadConfigItem( *theNodePtr, &ci ) )
        func( &ci, userData );

      theNodePtr++;
    }
  }
}

static void _XklConfigEnumSimple( xmlXPathCompExprPtr xpathCompExpr,
                                  ConfigItemProcessFunc func, void *userData )
{
  xmlXPathObjectPtr xpathObj;

  if( !_XklConfigInitialized(  ) )
    return;
  xpathObj = xmlXPathCompiledEval( xpathCompExpr, theRegistry.xpathContext );
  if( xpathObj != NULL )
  {
    _XklConfigEnumFromNodeSet( xpathObj->nodesetval, func, userData );
    xmlXPathFreeObject( xpathObj );
  }
}

static void _XklConfigEnumDirect( const char *format,
                                  const char *value,
                                  ConfigItemProcessFunc func, void *userData )
{
  char xpathExpr[1024];
  xmlXPathObjectPtr xpathObj;

  if( !_XklConfigInitialized(  ) )
    return;
  snprintf( xpathExpr, sizeof xpathExpr, format, value );
  xpathObj = xmlXPathEval( xpathExpr, theRegistry.xpathContext );
  if( xpathObj != NULL )
  {
    _XklConfigEnumFromNodeSet( xpathObj->nodesetval, func, userData );
    xmlXPathFreeObject( xpathObj );
  }
}

static Bool _XklConfigFindObject( const char *format,
                                  const char *arg1,
                                  XklConfigItemPtr ptr /* in/out */ ,
                                  xmlNodePtr * nodePtr /* out */  )
{
  xmlXPathObjectPtr xpathObj;
  xmlNodeSetPtr nodes;
  Bool rv = False;
  char xpathExpr[1024];

  if( !_XklConfigInitialized(  ) )
    return False;

  snprintf( xpathExpr, sizeof xpathExpr, format, arg1, ptr->name );
  xpathObj = xmlXPathEval( xpathExpr, theRegistry.xpathContext );
  if( xpathObj == NULL )
    return False;

  nodes = xpathObj->nodesetval;
  if( nodes != NULL && nodes->nodeTab != NULL )
  {
    rv = _XklReadConfigItem( *nodes->nodeTab, ptr );
    if( nodePtr != NULL )
    {
      *nodePtr = *nodes->nodeTab;
    }
  }

  xmlXPathFreeObject( xpathObj );
  return rv;
}

char *_XklConfigRecMergeLayouts( const XklConfigRecPtr data )
{
  return _XklConfigRecMergeByComma( ( const char ** ) data->layouts,
                                    data->numLayouts );
}

char *_XklConfigRecMergeVariants( const XklConfigRecPtr data )
{
  return _XklConfigRecMergeByComma( ( const char ** ) data->variants,
                                    data->numVariants );
}

char *_XklConfigRecMergeOptions( const XklConfigRecPtr data )
{
  return _XklConfigRecMergeByComma( ( const char ** ) data->options,
                                    data->numOptions );
}

char *_XklConfigRecMergeByComma( const char **array, const int arrayLength )
{
  int len = 0;
  int i;
  char *merged;
  const char **theString;

  if( ( theString = array ) == NULL )
    return NULL;

  for( i = arrayLength; --i >= 0; theString++ )
  {
    if( *theString != NULL )
      len += strlen( *theString );
    len++;
  }

  if( len < 1 )
    return NULL;

  merged = ( char * ) malloc( len );
  merged[0] = '\0';

  theString = array;
  for( i = arrayLength; --i >= 0; theString++ )
  {
    if( *theString != NULL )
      strcat( merged, *theString );
    if( i != 0 )
      strcat( merged, "," );
  }
  return merged;
}

void _XklConfigRecSplitLayouts( XklConfigRecPtr data, const char *merged )
{
  _XklConfigRecSplitByComma( &data->layouts, &data->numLayouts, merged );
}

void _XklConfigRecSplitVariants( XklConfigRecPtr data, const char *merged )
{
  _XklConfigRecSplitByComma( &data->variants, &data->numVariants, merged );
}

void _XklConfigRecSplitOptions( XklConfigRecPtr data, const char *merged )
{
  _XklConfigRecSplitByComma( &data->options, &data->numOptions, merged );
}

void _XklConfigRecSplitByComma( char ***array,
                                int *arraySize, const char *merged )
{
  const char *pc = merged;
  char **ppc, *npc;
  *arraySize = 0;
  *array = NULL;

  if( merged == NULL || merged[0] == '\0' )
    return;

  // first count the elements 
  while( ( npc = strchr( pc, ',' ) ) != NULL )
  {
    ( *arraySize )++;
    pc = npc + 1;
  }
  ( *arraySize )++;

  if( ( *arraySize ) != 0 )
  {
    int len;
    *array = ( char ** ) malloc( ( sizeof( char * ) ) * ( *arraySize ) );

    ppc = *array;
    pc = merged;
    while( ( npc = strchr( pc, ',' ) ) != NULL )
    {
      int len = npc - pc;
      *ppc = ( char * ) strndup( pc, len );
      ppc++;
      pc = npc + 1;
    }

    len = npc - pc;
    *ppc = ( char * ) strndup( pc, len );
  }
}

static Bool _XklConfigPrepareBeforeKbd( const XklConfigRecPtr data )
{
  memset( &_xklVarDefs, 0, sizeof( _xklVarDefs ) );

  _xklVarDefs.model = ( char * ) data->model;

  if( data->layouts != NULL )
    _xklVarDefs.layout = _XklConfigRecMergeLayouts( data );

  if( data->variants != NULL )
    _xklVarDefs.variant = _XklConfigRecMergeVariants( data );

  if( data->options != NULL )
    _xklVarDefs.options = _XklConfigRecMergeOptions( data );

  locale = setlocale( LC_ALL, NULL );
  if( locale != NULL )
    locale = strdup( locale );

  rules = XkbRF_Load( RULES_PATH, locale, True, True );

  if( rules == NULL )
  {
    _xklLastErrorMsg = "Could not load rules";
    return False;
  }

  if( !XkbRF_GetComponents( rules, &_xklVarDefs, &componentNames ) )
  {
    _xklLastErrorMsg = "Could not translate rules into components";
    return False;
  }

  return True;
}

static void _XklConfigCleanAfterKbd(  )
{
  XkbRF_Free( rules, True );

  if( locale != NULL )
  {
    free( locale );
    locale = NULL;
  }
  if( _xklVarDefs.layout != NULL )
  {
    free( _xklVarDefs.layout );
    _xklVarDefs.layout = NULL;
  }
  if( _xklVarDefs.options != NULL )
  {
    free( _xklVarDefs.options );
    _xklVarDefs.options = NULL;
  }
}

static void _XklApplyFun2XkbDesc( XkbDescPtr xkb, XkbDescModifierFunc fun,
                                  void *userData, Bool activeInServer )
{
  int mask;
  // XklDumpXkbDesc( "comp.xkb", xkb );
  if( fun == NULL )
    return;

  if( activeInServer )
  {
    mask = ( *fun ) ( NULL, NULL );
    if( mask == 0 )
      return;
    XkbGetUpdatedMap( _xklDpy, mask, xkb );
    // XklDumpXkbDesc( "restored1.xkb", xkb );
  }

  mask = ( *fun ) ( xkb, userData );
  if( activeInServer )
  {
    // XklDumpXkbDesc( "comp+.xkb", xkb );
    XkbSetMap( _xklDpy, mask, xkb );
    XSync( _xklDpy, False );

    // XkbGetUpdatedMap( _xklDpy, XkbAllMapComponentsMask, xkb );
    // XklDumpXkbDesc( "restored2.xkb", xkb );
  }
}

void XklConfigInit( void )
{
  xmlXPathInit(  );
  modelsXPath = xmlXPathCompile( "/xkbConfigRegistry/modelList/model" );
  layoutsXPath = xmlXPathCompile( "/xkbConfigRegistry/layoutList/layout" );
  optionGroupsXPath =
    xmlXPathCompile( "/xkbConfigRegistry/optionList/group" );
  _XklI18NInit(  );
}

void XklConfigTerm( void )
{
  if( modelsXPath != NULL )
    xmlXPathFreeCompExpr( modelsXPath );
  if( layoutsXPath != NULL )
    xmlXPathFreeCompExpr( layoutsXPath );
  if( optionGroupsXPath != NULL )
    xmlXPathFreeCompExpr( optionGroupsXPath );
}

Bool XklConfigLoadRegistry( void )
{
  struct stat statBuf;

  const char* fileName = XML_CFG_PATH; 
  if ( stat( XML_CFG_PATH, &statBuf ) != 0 )
     fileName = XML_CFG_FALLBACK_PATH;

  theRegistry.doc = xmlParseFile( fileName );
  if( theRegistry.doc == NULL )
  {
    theRegistry.xpathContext = NULL;
    _xklLastErrorMsg = "Could not parse XKB configuration registry";
  } else
    theRegistry.xpathContext = xmlXPathNewContext( theRegistry.doc );
  return _XklConfigInitialized(  );
}

void XklConfigFreeRegistry( void )
{
  if( _XklConfigInitialized(  ) )
  {
    xmlXPathFreeContext( theRegistry.xpathContext );
    xmlFreeDoc( theRegistry.doc );
  }
}

void XklConfigEnumModels( ConfigItemProcessFunc func, void *userData )
{
  _XklConfigEnumSimple( modelsXPath, func, userData );
}

void XklConfigEnumLayouts( ConfigItemProcessFunc func, void *userData )
{
  _XklConfigEnumSimple( layoutsXPath, func, userData );
}

void XklConfigEnumLayoutVariants( const char *layoutName,
                                  ConfigItemProcessFunc func, void *userData )
{
  _XklConfigEnumDirect
    ( "/xkbConfigRegistry/layoutList/layout/variantList/variant[../../configItem/name = '%s']",
      layoutName, func, userData );
}

void XklConfigEnumOptionGroups( GroupProcessFunc func, void *userData )
{
  xmlXPathObjectPtr xpathObj;
  int i;

  if( !_XklConfigInitialized(  ) )
    return;
  xpathObj =
    xmlXPathCompiledEval( optionGroupsXPath, theRegistry.xpathContext );
  if( xpathObj != NULL )
  {
    xmlNodeSetPtr nodes = xpathObj->nodesetval;
    xmlNodePtr *theNodePtr = nodes->nodeTab;
    for( i = nodes->nodeNr; --i >= 0; )
    {
      XklConfigItem ci;

      if( _XklReadConfigItem( *theNodePtr, &ci ) )
      {
        Bool allowMC = True;
        xmlChar *allowMCS =
          xmlGetProp( *theNodePtr, "allowMultipleSelection" );
        if( allowMCS != NULL )
        {
          allowMC = strcmp( "false", allowMCS );
          xmlFree( allowMCS );
        }

        func( &ci, allowMC, userData );
      }

      theNodePtr++;
    }
    xmlXPathFreeObject( xpathObj );
  }
}

void XklConfigEnumOptions( const char *optionGroupName,
                           ConfigItemProcessFunc func, void *userData )
{
  _XklConfigEnumDirect
    ( "/xkbConfigRegistry/optionList/group/option[../configItem/name = '%s']",
      optionGroupName, func, userData );
}

Bool XklConfigFindModel( XklConfigItemPtr ptr /* in/out */  )
{
  return
    _XklConfigFindObject
    ( "/xkbConfigRegistry/modelList/model[configItem/name = '%s%s']", "",
      ptr, NULL );
}

Bool XklConfigFindLayout( XklConfigItemPtr ptr /* in/out */  )
{
  return
    _XklConfigFindObject
    ( "/xkbConfigRegistry/layoutList/layout[configItem/name = '%s%s']", "",
      ptr, NULL );
}

Bool XklConfigFindVariant( const char *layoutName,
                           XklConfigItemPtr ptr /* in/out */  )
{
  return
    _XklConfigFindObject
    ( "/xkbConfigRegistry/layoutList/layout/variantList/variant"
      "[../../configItem/name = '%s' and configItem/name = '%s']",
      layoutName, ptr, NULL );
}

Bool XklConfigFindOptionGroup( XklConfigItemPtr ptr /* in/out */ ,
                               Bool * allowMultipleSelection /* out */  )
{
  xmlNodePtr node;
  Bool rv =
    _XklConfigFindObject
    ( "/xkbConfigRegistry/optionList/group[configItem/name = '%s%s']", "",
      ptr, &node );

  if( rv && allowMultipleSelection != NULL )
  {
    xmlChar *val = xmlGetProp( node, "allowMultipleSelection" );
    *allowMultipleSelection = False;
    if( val != NULL )
    {
      *allowMultipleSelection = !strcmp( val, "true" );
      xmlFree( val );
    }
  }
  return rv;
}

Bool XklConfigFindOption( const char *optionGroupName,
                          XklConfigItemPtr ptr /* in/out */  )
{
  return
    _XklConfigFindObject
    ( "/xkbConfigRegistry/optionList/group/option"
      "[../configItem/name = '%s' and configItem/name = '%s']",
      optionGroupName, ptr, NULL );
}

Bool XklMultipleLayoutsSupported( void )
{
  struct stat buf;
  return 0 == stat( MULTIPLE_LAYOUTS_CHECK_PATH, &buf );
}

Bool XklConfigActivate( const XklConfigRecPtr data, XkbDescModifierFunc fun,
                        void *userData )
{
  Bool rv = False;
  if( _XklConfigPrepareBeforeKbd( data ) )
  {
    XkbDescPtr xkb;
    xkb =
      XkbGetKeyboardByName( _xklDpy, XkbUseCoreKbd, &componentNames,
                            XkbGBN_AllComponentsMask,
                            XkbGBN_AllComponentsMask &
                            ( ~XkbGBN_GeometryMask ), True );

    //!! Do I need to free it anywhere?
    if( xkb != NULL )
    {
      _XklApplyFun2XkbDesc( xkb, fun, userData, True );
#if 0
      XklDumpXkbDesc( "config.xkb", xkb );
      int i;
      XklDebug( 150, "New model: [%s]\n", data->model );
      XklDebug( 150, "New layout: [%s]\n", data->layout );
      XklDebug( 150, "New variant: [%s]\n", data->variant );
      for( i = data->numOptions; --i >= 0; )
        XklDebug( 150, "New option[%d]: [%s]\n", i, data->options[i] );
#endif

      if( XklSetNamesProp
          ( _xklAtoms[XKB_RF_NAMES_PROP_ATOM], RULES_FILE, data ) )
        rv = True;
      else
        _xklLastErrorMsg = "Could not set names property";
      XkbFreeKeyboard( xkb, XkbAllComponentsMask, True );
    } else
    {
      _xklLastErrorMsg = "Could not load keyboard description";
    }
  }
  _XklConfigCleanAfterKbd(  );
  return rv;
}

int XklSetKeyAsSwitcher( XkbDescPtr kbd, void *userData )
{
  if( kbd != NULL )
  {
    XkbClientMapPtr map = kbd->map;
    if( map != NULL )
    {
      KeySym keysym = ( KeySym ) userData;
      KeySym *psym = map->syms;
      int symno;

      for( symno = map->num_syms; --symno >= 0; psym++ )
      {
        if( *psym == keysym )
        {
          XklDebug( 160, "Changing %s to %s at %d\n",
                    XKeysymToString( *psym ),
                    XKeysymToString( XK_ISO_Next_Group ), psym - map->syms );
          *psym = XK_ISO_Next_Group;
          break;
        }
      }
    } else
      XklDebug( 160, "No client map in the keyboard description?\n" );
  }
  return XkbKeySymsMask | XkbKeyTypesMask | XkbKeyActionsMask;
}

Bool XklConfigWriteXKMFile( const char *fileName, const XklConfigRecPtr data,
                            XkbDescModifierFunc fun, void *userData )
{
  Bool rv = False;

  FILE *output = fopen( fileName, "w" );
  XkbFileInfo dumpInfo;

  if( output == NULL )
  {
    _xklLastErrorMsg = "Could not open the XKB file";
    return False;
  }

  if( _XklConfigPrepareBeforeKbd( data ) )
  {
    XkbDescPtr xkb;
    xkb =
      XkbGetKeyboardByName( _xklDpy, XkbUseCoreKbd, &componentNames,
                            XkbGBN_AllComponentsMask,
                            XkbGBN_AllComponentsMask &
                            ( ~XkbGBN_GeometryMask ), False );
    if( xkb != NULL )
    {
      _XklApplyFun2XkbDesc( xkb, fun, userData, False );

      dumpInfo.defined = 0;
      dumpInfo.xkb = xkb;
      dumpInfo.type = XkmKeymapFile;
      rv = XkbWriteXKMFile( output, &dumpInfo );
      XkbFreeKeyboard( xkb, XkbGBN_AllComponentsMask, True );
    } else
      _xklLastErrorMsg = "Could not load keyboard description";
  }
  _XklConfigCleanAfterKbd(  );
  fclose( output );
  return rv;
}