/************************************************************ 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. ********************************************************/ #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/share/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 "pc105" #endif /* Values used in svSrc to state how a value was obtained. The order of these * is important, the bigger the higher the priority. * e.g. FROM_CONFIG overrides FROM_SERVER */ #define UNDEFINED 0 #define FROM_SERVER 1 /* retrieved from server at runtime */ #define FROM_RULES 2 /* xkb rules file */ #define FROM_CONFIG 3 /* command-line specified config file */ #define FROM_CMD_LINE 4 /* specified at the cmdline */ #define NUM_SOURCES 5 /* Indices used into svSrc, svNValue */ #define RULES_NDX 0 /* rules file */ #define CONFIG_NDX 1 /* config file (if used) */ #define DISPLAY_NDX 2 /* X display name */ #define LOCALE_NDX 3 /* machine's locale */ #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 /***====================================================================***/ static Bool print = False; static Bool query = False; static Bool synch = False; static int verbose = 5; static Display *dpy; /** * human-readable versions of FROM_CONFIG, FROM_SERVER, etc. Used for error * reporting. */ static char *srcName[NUM_SOURCES] = { "undefined", "X server", "rules file", "config file", "command line" }; /** * human-readable versions for RULES_NDX, CONFIG_NDX, etc. Used for error * reporting. */ static 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" }; /** * Holds the source for each of RULES, CONFIG, DISPLAY, etc. * i.e. if svSrc[LAYOUT_NDX] == FROM_SERVER, then the layout has been fetched * from the server. */ static int svSrc[NUM_STRING_VALS]; /** * Holds the value for each of RULES, CONFIG, DISPLAY, etc. */ static char *svValue[NUM_STRING_VALS]; static XkbConfigRtrnRec cfgResult; static XkbRF_RulesPtr rules = NULL; static XkbRF_VarDefsRec rdefs; static Bool clearOptions = False; static int szOptions = 0; static int numOptions = 0; static char **options = NULL; static int szInclPath = 0; static int numInclPath = 0; static char **inclPath = NULL; static XkbDescPtr xkb = NULL; static int deviceSpec = XkbUseCoreKbd; /***====================================================================***/ #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] [ [ [