/* $XdotOrg: app/setxkbmap/setxkbmap.c,v 1.2 2004/04/23 19:54:37 eich Exp $ */ /************************************************************ Copyright (c) 1996 by Silicon Graphics Computer Systems, Inc. Permission to use, copy, modify, and distribute this software and its documentation for any purpose and without fee is hereby granted, provided that the above copyright notice appear in all copies and that both that copyright notice and this permission notice appear in supporting documentation, and that the name of Silicon Graphics not be used in advertising or publicity pertaining to distribution of the software without specific prior written permission. Silicon Graphics makes no representation about the suitability of this software for any purpose. It is provided "as is" without any express or implied warranty. SILICON GRAPHICS DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE. IN NO EVENT SHALL SILICON GRAPHICS BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS SOFTWARE. ********************************************************/ /* $XFree86: xc/programs/setxkbmap/setxkbmap.c,v 3.7 2003/01/20 04:15:08 dawes Exp $ */ #include #include #include #include #include #include #include #include #include #include #include #ifndef PATH_MAX #ifdef MAXPATHLEN #define PATH_MAX MAXPATHLEN #else #define PATH_MAX 1024 #endif #endif #ifndef DFLT_XKB_CONFIG_ROOT #define DFLT_XKB_CONFIG_ROOT "/usr/X11R6/lib/X11/xkb" #endif #ifndef DFLT_XKB_RULES_FILE #define DFLT_XKB_RULES_FILE __XKBDEFRULES__ #endif #ifndef DFLT_XKB_LAYOUT #define DFLT_XKB_LAYOUT "us" #endif #ifndef DFLT_XKB_MODEL #define DFLT_XKB_MODEL "pc101" #endif #define UNDEFINED 0 #define FROM_SERVER 1 #define FROM_RULES 2 #define FROM_CONFIG 3 #define FROM_CMD_LINE 4 #define NUM_SOURCES 5 #define RULES_NDX 0 #define CONFIG_NDX 1 #define DISPLAY_NDX 2 #define LOCALE_NDX 3 #define MODEL_NDX 4 #define LAYOUT_NDX 5 #define VARIANT_NDX 6 #define KEYCODES_NDX 7 #define TYPES_NDX 8 #define COMPAT_NDX 9 #define SYMBOLS_NDX 10 #define GEOMETRY_NDX 11 #define KEYMAP_NDX 12 #define NUM_STRING_VALS 13 /***====================================================================***/ Bool print= False; Bool synch= False; int verbose= 5; Display * dpy; char * srcName[NUM_SOURCES] = { "undefined", "X server", "rules file", "config file", "command line" }; char * svName[NUM_STRING_VALS]= { "rules file", "config file", "X display", "locale", "keyboard model", "keyboard layout", "layout variant", "keycodes", "types", "compatibility map", "symbols", "geometry", "keymap" }; int svSrc[NUM_STRING_VALS]; char * svValue[NUM_STRING_VALS]; XkbConfigFieldsRec cfgDflts; XkbConfigRtrnRec cfgResult; XkbRF_RulesPtr rules= NULL; XkbRF_VarDefsRec rdefs; Bool clearOptions= False; int szOptions= 0; int numOptions= 0; char ** options= NULL; int szInclPath= 0; int numInclPath= 0; char ** inclPath= NULL; XkbDescPtr xkb= NULL; /***====================================================================***/ #define streq(s1,s2) (strcmp(s1,s2)==0) #define strpfx(s1,s2) (strncmp(s1,s2,strlen(s2))==0) #define MSG(s) printf(s) #define MSG1(s,a) printf(s,a) #define MSG2(s,a,b) printf(s,a,b) #define MSG3(s,a,b,c) printf(s,a,b,c) #define VMSG(l,s) if (verbose>(l)) printf(s) #define VMSG1(l,s,a) if (verbose>(l)) printf(s,a) #define VMSG2(l,s,a,b) if (verbose>(l)) printf(s,a,b) #define VMSG3(l,s,a,b,c) if (verbose>(l)) printf(s,a,b,c) #define ERR(s) fprintf(stderr,s) #define ERR1(s,a) fprintf(stderr,s,a) #define ERR2(s,a,b) fprintf(stderr,s,a,b) #define ERR3(s,a,b,c) fprintf(stderr,s,a,b,c) /***====================================================================***/ Bool addToList ( int *sz, int *num, char ***listIn, char *newVal ); void usage ( int argc, char ** argv ); void dumpNames ( Bool wantRules, Bool wantCNames ); void trySetString ( int which, char * newVal, int src ); Bool setOptString ( int *arg, int argc, char **argv, int which, int src ); int parseArgs ( int argc, char ** argv ); Bool getDisplay ( int argc, char ** argv ); Bool getServerValues ( void ); FILE * findFileInPath ( char * name, char * subdir ); Bool addStringToOptions ( char * opt_str, int * sz_opts, int * num_opts, char *** opts ); char * stringFromOptions ( char * orig, int numNew, char ** newOpts ); Bool applyConfig ( char * name ); Bool applyRules ( void ); Bool applyComponentNames ( void ); void printKeymap( void ); /***====================================================================***/ Bool addToList(int *sz,int *num,char ***listIn,char *newVal) { register int i; char **list; if ((!newVal)||(!newVal[0])) { *num= 0; return True; } list= *listIn; for (i=0;i<*num;i++) { if (streq(list[i],newVal)) return True; } if ((list==NULL)||(*sz<1)) { *num= 0; *sz= 4; list= (char **)calloc(*sz,sizeof(char *)); *listIn= list; } else if (*num>=*sz) { *sz*= 2; list= (char **)realloc(list,(*sz)*sizeof(char *)); *listIn= list; } if (!list) { ERR("Internal Error! Allocation failure in add to list!\n"); ERR(" Exiting.\n"); exit(-1); } list[*num]= strdup(newVal); (*num)= (*num)+1; return True; } /***====================================================================***/ void usage(int argc,char **argv) { MSG1("Usage: %s [args] [ [ [