keymap.c revision f46a6179
1/* $Xorg: keymap.c,v 1.3 2000/08/17 19:54:32 cpqbld Exp $ */ 2/************************************************************ 3 Copyright (c) 1994 by Silicon Graphics Computer Systems, Inc. 4 5 Permission to use, copy, modify, and distribute this 6 software and its documentation for any purpose and without 7 fee is hereby granted, provided that the above copyright 8 notice appear in all copies and that both that copyright 9 notice and this permission notice appear in supporting 10 documentation, and that the name of Silicon Graphics not be 11 used in advertising or publicity pertaining to distribution 12 of the software without specific prior written permission. 13 Silicon Graphics makes no representation about the suitability 14 of this software for any purpose. It is provided "as is" 15 without any express or implied warranty. 16 17 SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS 18 SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY 19 AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON 20 GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL 21 DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, 22 DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE 23 OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH 24 THE USE OR PERFORMANCE OF THIS SOFTWARE. 25 26 ********************************************************/ 27/* $XFree86$ */ 28 29#include "xkbcomp.h" 30#include "tokens.h" 31#include "expr.h" 32#include "vmod.h" 33#include "action.h" 34#include "misc.h" 35#include "indicators.h" 36 37#define KEYCODES 0 38#define GEOMETRY 1 39#define TYPES 2 40#define COMPAT 3 41#define SYMBOLS 4 42#define MAX_SECTIONS 5 43 44XkbFile * sections[MAX_SECTIONS]; 45 46Bool 47CompileKeymap(XkbFile *file,XkbFileInfo *result,unsigned merge) 48{ 49unsigned have; 50Bool ok; 51unsigned required,legal; 52unsigned mainType; 53char * mainName; 54LEDInfo * unbound= NULL; 55 56 bzero(sections,MAX_SECTIONS*sizeof(XkbFile *)); 57 mainType= file->type; 58 mainName= file->name; 59 switch (mainType) { 60 case XkmSemanticsFile: 61 required= XkmSemanticsRequired; 62 legal= XkmSemanticsLegal; 63 break; 64 case XkmLayoutFile: 65 required= XkmLayoutRequired; 66 legal= XkmKeymapLegal; 67 break; 68 case XkmKeymapFile: 69 required= XkmKeymapRequired; 70 legal= XkmKeymapLegal; 71 break; 72 default: 73 ERROR1("Cannot compile %s alone into an XKM file\n", 74 XkbConfigText(mainType,XkbMessage)); 75 return False; 76 } 77 have= 0; 78 ok= 1; 79 file= (XkbFile *)file->defs; 80 while ((file)&&(ok)) { 81 file->topName= mainName; 82 if ((have&(1<<file->type))!=0) { 83 ERROR2("More than one %s section in a %s file\n", 84 XkbConfigText(file->type,XkbMessage), 85 XkbConfigText(mainType,XkbMessage)); 86 ACTION("All sections after the first ignored\n"); 87 ok= False; 88 } 89 else if ((1<<file->type)&(~legal)) { 90 ERROR2("Cannot define %s in a %s file\n", 91 XkbConfigText(file->type,XkbMessage), 92 XkbConfigText(mainType,XkbMessage)); 93 ok= False; 94 } 95 else switch (file->type) { 96 case XkmSemanticsFile: 97 case XkmLayoutFile: 98 case XkmKeymapFile: 99 WSGO2("Illegal %s configuration in a %s file\n", 100 XkbConfigText(file->type,XkbMessage), 101 XkbConfigText(mainType,XkbMessage)); 102 ACTION("Ignored\n"); 103 ok= False; 104 break; 105 case XkmKeyNamesIndex: 106 sections[KEYCODES]= file; 107 break; 108 case XkmTypesIndex: 109 sections[TYPES]= file; 110 break; 111 case XkmSymbolsIndex: 112 sections[SYMBOLS]= file; 113 break; 114 case XkmCompatMapIndex: 115 sections[COMPAT]= file; 116 break; 117 case XkmGeometryIndex: 118 case XkmGeometryFile: 119 sections[GEOMETRY]= file; 120 break; 121 case XkmVirtualModsIndex: 122 case XkmIndicatorsIndex: 123 WSGO1("Found an isolated %s section\n", 124 XkbConfigText(file->type,XkbMessage)); 125 break; 126 default: 127 WSGO1("Unknown file type %d\n",file->type); 128 break; 129 } 130 if (ok) 131 have|= (1<<file->type); 132 file= (XkbFile*)file->common.next; 133 } 134 if (ok) { 135 if (ok && (sections[KEYCODES]!=NULL)) 136 ok= CompileKeycodes(sections[KEYCODES],result,MergeOverride); 137 if (ok && (sections[GEOMETRY]!=NULL)) 138 ok= CompileGeometry(sections[GEOMETRY],result,MergeOverride); 139 if (ok && (sections[TYPES]!=NULL)) 140 ok= CompileKeyTypes(sections[TYPES],result,MergeOverride); 141 if (ok && (sections[COMPAT]!=NULL)) 142 ok=CompileCompatMap(sections[COMPAT],result,MergeOverride,&unbound); 143 if (ok && (sections[SYMBOLS]!=NULL)) 144 ok= CompileSymbols(sections[SYMBOLS],result,MergeOverride); 145 } 146 if (!ok) 147 return False; 148 result->defined= have; 149 if (required&(~have)) { 150 register int i,bit; 151 unsigned missing; 152 missing= required&(~have); 153 for (i=0,bit=1;missing!=0;i++,bit<<=1) { 154 if (missing&bit) { 155 ERROR2("Missing %s section in a %s file\n", 156 XkbConfigText(i,XkbMessage), 157 XkbConfigText(mainType,XkbMessage)); 158 missing&=~bit; 159 } 160 } 161 ACTION1("Description of %s not compiled\n", 162 XkbConfigText(mainType,XkbMessage)); 163 ok= False; 164 } 165 ok= BindIndicators(result,True,unbound,NULL); 166 return ok; 167} 168 169