/** * Set the given string (obtained from src) in the svValue/svSrc globals. * If the given item is already set, it is overridden if the original source * is less significant than the given one. * * @param which What value is it (one of RULES_NDX, CONFIG_NDX, ...) */ void trySetString(setting_t *setting, char *newVal, enum source src) { if (setting->value != NULL) { if (setting->src == src) { VMSG2(0, "Warning! More than one %s from %s\n", setting->name, srcName[src]); VMSG2(0, " Using \"%s\", ignoring \"%s\"\n", setting->value, newVal); return; } else if (setting->src > src) { VMSG1(5, "Warning! Multiple definitions of %s\n", setting->name); VMSG2(5, " Using %s, ignoring %s\n", srcName[setting->src], srcName[src]); return; } } setting->src = src; setting->value = newVal; return; }
/** * Set the given string (obtained from src) in the svValue/svSrc globals. * If the given item is already set, it is overridden if the original source * is less significant than the given one. * * @param which What value is it (one of RULES_NDX, CONFIG_NDX, ...) */ void trySetString(int which, char *newVal, int src) { if (svValue[which] != NULL) { if (svSrc[which] == src) { VMSG2(0, "Warning! More than one %s from %s\n", svName[which], srcName[src]); VMSG2(0, " Using \"%s\", ignoring \"%s\"\n", svValue[which], newVal); return; } else if (svSrc[which] > src) { VMSG1(5, "Warning! Multiple definitions of %s\n", svName[which]); VMSG2(5, " Using %s, ignoring %s\n", srcName[svSrc[which]], srcName[src]); return; } } svSrc[which] = src; svValue[which] = newVal; return; }
FILE * findFileInPath(char *name) { register int i; char buf[PATH_MAX]; FILE *fp; if (name[0] == '/') { fp = fopen(name, "r"); if ((verbose > 7) || ((!fp) && (verbose > 0))) MSG2("%s file %s\n", (fp ? "Found" : "Didn't find"), name); return fp; } for (i = 0; (i < inclPath.num); i++) { if (snprintf(buf, PATH_MAX, "%s/%s", inclPath.item[i], name) >= PATH_MAX) { VMSG2(0, "Path too long (%s/%s). Ignored.\n", inclPath.item[i], name); continue; } fp = fopen(buf, "r"); if ((verbose > 7) || ((!fp) && (verbose > 5))) MSG2("%s file %s\n", (fp ? "Found" : "Didn't find"), buf); if (fp != NULL) return fp; } return NULL; }
Bool setOptString(int *arg, int argc, char **argv, setting_t *setting, enum source src) { int ndx; char *opt; ndx = *arg; opt = argv[ndx]; if (ndx >= argc - 1) { VMSG1(0, "No %s specified on the command line\n", setting->name); VMSG1(0, "Trailing %s option ignored\n", opt); return True; } ndx++; *arg = ndx; if (setting->value != NULL) { if (setting->src == src) { VMSG2(0, "More than one %s on %s\n", setting->name, srcName[src]); VMSG2(0, "Using \"%s\", ignoring \"%s\"\n", setting->value, argv[ndx]); return True; } else if (setting->src > src) { VMSG1(5, "Multiple definitions of %s\n", setting->name); VMSG2(5, "Using %s, ignoring %s\n", srcName[setting->src], srcName[src]); return True; } } setting->src = src; setting->value = argv[ndx]; return True; }
Bool setOptString(int *arg, int argc, char **argv, int which, int src) { int ndx; char *opt; ndx = *arg; opt = argv[ndx]; if (ndx >= argc - 1) { VMSG1(0, "No %s specified on the command line\n", svName[which]); VMSG1(0, "Trailing %s option ignored\n", opt); return True; } ndx++; *arg = ndx; if (svValue[which] != NULL) { if (svSrc[which] == src) { VMSG2(0, "More than one %s on %s\n", svName[which], srcName[src]); VMSG2(0, "Using \"%s\", ignoring \"%s\"\n", svValue[which], argv[ndx]); return True; } else if (svSrc[which] > src) { VMSG1(5, "Multiple definitions of %s\n", svName[which]); VMSG2(5, "Using %s, ignoring %s\n", srcName[svSrc[which]], srcName[src]); return True; } } svSrc[which] = src; svValue[which] = argv[ndx]; return True; }
/** * If any of model, layout, variant or options is specified, then compile the * options into the * * @return True on success or false otherwise. */ Bool applyRules(void) { int i; char *rfName; if (settings.model.src || settings.layout.src || settings.variant.src || options.item) { char buf[PATH_MAX]; XkbComponentNamesRec rnames; if (settings.variant.src < settings.layout.src) settings.variant.value = NULL; rdefs.model = settings.model.value; rdefs.layout = settings.layout.value; rdefs.variant = settings.variant.value; if (options.item) rdefs.options = stringFromOptions(rdefs.options, &options); if (settings.rules.src) rfName = settings.rules.value; else rfName = DFLT_XKB_RULES_FILE; if (rfName[0] == '/') { rules = tryLoadRules(rfName, settings.locale.value, True, True); } else { /* try to load rules files from all include paths until the first * we succeed with */ for (i = 0; (i < inclPath.num) && (!rules); i++) { if (snprintf(buf, PATH_MAX, "%s/rules/%s", inclPath.item[i], rfName) >= PATH_MAX) { VMSG2(0, "Path too long (%s/rules/%s). Ignored.\n", inclPath.item[i], rfName); continue; } rules = tryLoadRules(buf, settings.locale.value, True, True); } } if (!rules) { ERR1("Couldn't find rules file (%s) \n", rfName); return False; } /* Let the rules file to the magic, then update the svValues with * those returned after processing the rules */ XkbRF_GetComponents(rules, &rdefs, &rnames); if (rnames.keycodes) { trySetString(&settings.keycodes, rnames.keycodes, FROM_RULES); rnames.keycodes = NULL; } if (rnames.symbols) { trySetString(&settings.symbols, rnames.symbols, FROM_RULES); rnames.symbols = NULL; } if (rnames.types) { trySetString(&settings.types, rnames.types, FROM_RULES); rnames.types = NULL; } if (rnames.compat) { trySetString(&settings.compat, rnames.compat, FROM_RULES); rnames.compat = NULL; } if (rnames.geometry) { trySetString(&settings.geometry, rnames.geometry, FROM_RULES); rnames.geometry = NULL; } if (rnames.keymap) { trySetString(&settings.keymap, rnames.keymap, FROM_RULES); rnames.keymap = NULL; } if (verbose > 6) { MSG1("Applied rules from %s:\n", rfName); dumpNames(True, False); } } else if (verbose > 6) { MSG("No rules variables specified. Rules file ignored\n"); } return True; }
/** * If any of model, layout, variant or options is specified, then compile the * options into the * * @return True on success or false otherwise. */ Bool applyRules(void) { int i; char *rfName; if (svSrc[MODEL_NDX] || svSrc[LAYOUT_NDX] || svSrc[VARIANT_NDX] || options) { char buf[PATH_MAX]; XkbComponentNamesRec rnames; if (svSrc[VARIANT_NDX] < svSrc[LAYOUT_NDX]) svValue[VARIANT_NDX] = NULL; rdefs.model = svValue[MODEL_NDX]; rdefs.layout = svValue[LAYOUT_NDX]; rdefs.variant = svValue[VARIANT_NDX]; if (options) rdefs.options = stringFromOptions(rdefs.options, numOptions, options); if (svSrc[RULES_NDX]) rfName = svValue[RULES_NDX]; else rfName = DFLT_XKB_RULES_FILE; if (rfName[0] == '/') { rules = XkbRF_Load(rfName, svValue[LOCALE_NDX], True, True); } else { /* try to load rules files from all include paths until the first * we succeed with */ for (i = 0; (i < numInclPath) && (!rules); i++) { if ((strlen(inclPath[i]) + strlen(rfName) + 8) > PATH_MAX) { VMSG2(0, "Path too long (%s/rules/%s). Ignored.\n", inclPath[i], rfName); continue; } sprintf(buf, "%s/rules/%s", inclPath[i], svValue[RULES_NDX]); rules = XkbRF_Load(buf, svValue[LOCALE_NDX], True, True); } } if (!rules) { ERR1("Couldn't find rules file (%s) \n", svValue[RULES_NDX]); return False; } /* Let the rules file to the magic, then update the svValues with * those returned after processing the rules */ XkbRF_GetComponents(rules, &rdefs, &rnames); if (rnames.keycodes) { trySetString(KEYCODES_NDX, rnames.keycodes, FROM_RULES); rnames.keycodes = NULL; } if (rnames.symbols) { trySetString(SYMBOLS_NDX, rnames.symbols, FROM_RULES); rnames.symbols = NULL; } if (rnames.types) { trySetString(TYPES_NDX, rnames.types, FROM_RULES); rnames.types = NULL; } if (rnames.compat) { trySetString(COMPAT_NDX, rnames.compat, FROM_RULES); rnames.compat = NULL; } if (rnames.geometry) { trySetString(GEOMETRY_NDX, rnames.geometry, FROM_RULES); rnames.geometry = NULL; } if (rnames.keymap) { trySetString(KEYMAP_NDX, rnames.keymap, FROM_RULES); rnames.keymap = NULL; } if (verbose > 6) { MSG1("Applied rules from %s:\n", svValue[RULES_NDX]); dumpNames(True, False); } } else if (verbose > 6) { MSG("No rules variables specified. Rules file ignored\n"); } return True; }