Exemplo n.º 1
0
/**
 * 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;
}
Exemplo n.º 2
0
/**
 * Retrieve xkb values from the XKB_RULES_NAMES property and store their
 * contents in svValues.
 * If the property cannot be read, the built-in defaults are used.
 *
 * @return True.
 */
Bool
getServerValues(void)
{
    XkbRF_VarDefsRec vd;
    char *tmp = NULL;

    if (!XkbRF_GetNamesProp(dpy, &tmp, &vd) || !tmp)
    {
        VMSG1(3, "Couldn't interpret %s property\n", _XKB_RF_NAMES_PROP_ATOM);
        tmp = DFLT_XKB_RULES_FILE;
        vd.model = DFLT_XKB_MODEL;
        vd.layout = DFLT_XKB_LAYOUT;
        vd.variant = NULL;
        vd.options = NULL;
        VMSG3(3, "Use defaults: rules - '%s' model - '%s' layout - '%s'\n",
              tmp, vd.model, vd.layout);
    }
    if (tmp)
        trySetString(&settings.rules, tmp, FROM_SERVER);
    if (vd.model)
        trySetString(&settings.model, vd.model, FROM_SERVER);
    if (vd.layout)
        trySetString(&settings.layout, vd.layout, FROM_SERVER);
    if (vd.variant)
        trySetString(&settings.variant, vd.variant, FROM_SERVER);
    if ((vd.options) && (!clearOptions))
    {
        addStringToOptions(vd.options, &options);
        XFree(vd.options);
    }
    return True;
}
Exemplo n.º 3
0
/**
 * 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;
}
Exemplo n.º 4
0
XkbRF_RulesPtr
tryLoadRules(char *name, char *locale, Bool wantDesc, Bool wantRules)
{
    XkbRF_RulesPtr rules = NULL;
    VMSG1(7, "Trying to load rules file %s...\n", name);
    rules = XkbRF_Load(name, locale, wantDesc, wantRules);
    if (rules)
    {
        VMSG(7, "Success.\n");
    }
    return rules;
}
Exemplo n.º 5
0
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;
}
Exemplo n.º 6
0
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;
}
Exemplo n.º 7
0
int
main(int argc, char **argv)
{
    if ((!parseArgs(argc, argv)) || (!getDisplay(argc, argv)))
        exit(-1);
    settings.locale.value = setlocale(LC_ALL, settings.locale.value);
    settings.locale.src = FROM_SERVER;
    VMSG1(7, "locale is %s\n", settings.locale.value);
    if (dpy)
        getServerValues();
    if (settings.config.value && (!applyConfig(settings.config.value)))
        exit(-3);
    if (!applyRules())
        exit(-4);
    if (!applyComponentNames())
        exit(-5);
    if (dpy)
        XCloseDisplay(dpy);
    exit(0);
}
Exemplo n.º 8
0
int
main(int argc, char **argv)
{
    if ((!parseArgs(argc, argv)) || (!getDisplay(argc, argv)))
        exit(-1);
    svValue[LOCALE_NDX] = setlocale(LC_ALL, svValue[LOCALE_NDX]);
    svSrc[LOCALE_NDX] = FROM_SERVER;
    VMSG1(7, "locale is %s\n", svValue[LOCALE_NDX]);
    if (dpy)
        getServerValues();
    if (svValue[CONFIG_NDX] && (!applyConfig(svValue[CONFIG_NDX])))
        exit(-3);
    if (!applyRules())
        exit(-4);
    if (!applyComponentNames())
        exit(-5);
    if (dpy)
        XCloseDisplay(dpy);
    exit(0);
}
Exemplo n.º 9
0
/**
 * Parse commandline arguments.
 * Return True on success or False if an unrecognized option has been
 * specified.
 */
int
parseArgs(int argc, char **argv)
{
    int i;
    Bool ok;
    unsigned present;

    ok = True;
    addToList(&inclPath, ".");
    addToList(&inclPath, DFLT_XKB_CONFIG_ROOT);
    for (i = 1; (i < argc) && ok; i++)
    {
        if (argv[i][0] != '-')
        {
            /* Allow a call like "setxkbmap us" to work. Layout is default,
               if -layout is given, then try parsing variant, then options */
            if (!settings.layout.src)
                trySetString(&settings.layout, argv[i], FROM_CMD_LINE);
            else if (!settings.variant.src)
                trySetString(&settings.variant, argv[i], FROM_CMD_LINE);
            else
                ok = addToList(&options, argv[i]);
        }
        else if (streq(argv[i], "-compat"))
            ok = setOptString(&i, argc, argv, &settings.compat, FROM_CMD_LINE);
        else if (streq(argv[i], "-config"))
            ok = setOptString(&i, argc, argv, &settings.config, FROM_CMD_LINE);
        else if (streq(argv[i], "-device"))
        {
            if ( ++i < argc ) {
                deviceSpec = atoi(argv[i]); /* only allow device IDs, not names */
            } else {
                usage(argc, argv);
                exit(-1);
            }
        }
        else if (streq(argv[i], "-display"))
            ok = setOptString(&i, argc, argv, &settings.display, FROM_CMD_LINE);
        else if (streq(argv[i], "-geometry"))
            ok = setOptString(&i, argc, argv, &settings.geometry, FROM_CMD_LINE);
        else if (streq(argv[i], "-help") || streq(argv[i], "-?"))
        {
            usage(argc, argv);
            exit(0);
        }
        else if (streq(argv[i], "-I")) /* space between -I and path */
        {
            if ( ++i < argc )
                ok = addToList(&inclPath, argv[i]);
            else
                VMSG(0, "No directory specified on the command line\n"
                     "Trailing -I option ignored\n");
        }
        else if (strpfx(argv[i], "-I")) /* no space between -I and path */
            ok = addToList(&inclPath, &argv[i][2]);
        else if (streq(argv[i], "-keycodes"))
            ok = setOptString(&i, argc, argv, &settings.keycodes, FROM_CMD_LINE);
        else if (streq(argv[i], "-keymap"))
            ok = setOptString(&i, argc, argv, &settings.keymap, FROM_CMD_LINE);
        else if (streq(argv[i], "-layout"))
            ok = setOptString(&i, argc, argv, &settings.layout, FROM_CMD_LINE);
        else if (streq(argv[i], "-model"))
            ok = setOptString(&i, argc, argv, &settings.model, FROM_CMD_LINE);
        else if (streq(argv[i], "-option"))
        {
            if ((i == argc - 1) || (argv[i + 1][0] == '\0')
                || (argv[i + 1][0] == '-'))
            {
                clearOptions = True;
                ok = addToList(&options, "");
                if (i < argc - 1 && argv[i + 1][0] == '\0')
                    i++;
            }
            else
            {
                ok = addToList(&options, argv[++i]);
            }
        }
        else if (streq(argv[i], "-print"))
            print = True;
        else if (streq(argv[i], "-query"))
            query = True;
        else if (streq(argv[i], "-rules"))
            ok = setOptString(&i, argc, argv, &settings.rules, FROM_CMD_LINE);
        else if (streq(argv[i], "-symbols"))
            ok = setOptString(&i, argc, argv, &settings.symbols, FROM_CMD_LINE);
        else if (streq(argv[i], "-synch"))
            synch = True;
        else if (streq(argv[i], "-types"))
            ok = setOptString(&i, argc, argv, &settings.types, FROM_CMD_LINE);
        else if (streq(argv[i], "-verbose") || (streq(argv[i], "-v")))
        {
            if ((i < argc - 1) && (isdigit(argv[i + 1][0])))
                verbose = atoi(argv[++i]);
            else
                verbose++;
            if (verbose < 0)
            {
                ERR1("Illegal verbose level %d.  Reset to 0\n", verbose);
                verbose = 0;
            }
            else if (verbose > 10)
            {
                ERR1("Illegal verbose level %d.  Reset to 10\n", verbose);
                verbose = 10;
            }
            VMSG1(7, "Setting verbose level to %d\n", verbose);
        }
        else if (streq(argv[i], "-variant"))
            ok = setOptString(&i, argc, argv, &settings.variant, FROM_CMD_LINE);
        else
        {
            ERR1("Error!   Option \"%s\" not recognized\n", argv[i]);
            ok = False;
        }
    }

    present = 0;
    if (settings.types.value)
        present++;
    if (settings.compat.value)
        present++;
    if (settings.symbols.value)
        present++;
    if (settings.keycodes.value)
        present++;
    if (settings.geometry.value)
        present++;
    if (settings.config.value)
        present++;
    if (settings.model.value)
        present++;
    if (settings.layout.value)
        present++;
    if (settings.variant.value)
        present++;
    if (settings.keymap.value && present)
    {
        ERR("No other components can be specified when a keymap is present\n");
        return False;
    }
    return ok;
}
Exemplo n.º 10
0
/**
 * Parse commandline arguments.
 * Return True on success or False if an unrecognized option has been
 * specified.
 */
int
parseArgs(int argc, char **argv)
{
    int i;
    Bool ok;
    unsigned present;

    ok = True;
    addToList(&szInclPath, &numInclPath, &inclPath, ".");
    addToList(&szInclPath, &numInclPath, &inclPath, DFLT_XKB_CONFIG_ROOT);
    for (i = 1; (i < argc) && ok; i++)
    {
        if (argv[i][0] != '-')
        {
            /* Allow a call like "setxkbmap us" to work. Layout is default,
               if -layout is given, then try parsing variant, then options */
            if (!svSrc[LAYOUT_NDX])
                trySetString(LAYOUT_NDX, argv[i], FROM_CMD_LINE);
            else if (!svSrc[VARIANT_NDX])
                trySetString(VARIANT_NDX, argv[i], FROM_CMD_LINE);
            else
                ok = addToList(&szOptions, &numOptions, &options, argv[i]);
        }
        else if (streq(argv[i], "-compat"))
            ok = setOptString(&i, argc, argv, COMPAT_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-config"))
            ok = setOptString(&i, argc, argv, CONFIG_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-device"))
            deviceSpec = atoi(argv[++i]); /* only allow device IDs, not names */
        else if (streq(argv[i], "-display"))
            ok = setOptString(&i, argc, argv, DISPLAY_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-geometry"))
            ok = setOptString(&i, argc, argv, GEOMETRY_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-help") || streq(argv[i], "-?"))
        {
            usage(argc, argv);
            exit(0);
        }
        else if (strpfx(argv[i], "-I"))
            ok = addToList(&szInclPath, &numInclPath, &inclPath, &argv[i][2]);
        else if (streq(argv[i], "-keycodes"))
            ok = setOptString(&i, argc, argv, KEYCODES_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-keymap"))
            ok = setOptString(&i, argc, argv, KEYMAP_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-layout"))
            ok = setOptString(&i, argc, argv, LAYOUT_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-model"))
            ok = setOptString(&i, argc, argv, MODEL_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-option"))
        {
            if ((i == argc - 1) || (argv[i + 1][0] == '\0')
                || (argv[i + 1][0] == '-'))
            {
                clearOptions = True;
                ok = addToList(&szOptions, &numOptions, &options, "");
                if (i < argc - 1 && argv[i + 1][0] == '\0')
                    i++;
            }
            else
            {
                ok = addToList(&szOptions, &numOptions, &options, argv[++i]);
            }
        }
        else if (streq(argv[i], "-print"))
            print = True;
        else if (streq(argv[i], "-query"))
            query = True;
        else if (streq(argv[i], "-rules"))
            ok = setOptString(&i, argc, argv, RULES_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-symbols"))
            ok = setOptString(&i, argc, argv, SYMBOLS_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-synch"))
            synch = True;
        else if (streq(argv[i], "-types"))
            ok = setOptString(&i, argc, argv, TYPES_NDX, FROM_CMD_LINE);
        else if (streq(argv[i], "-verbose") || (streq(argv[i], "-v")))
        {
            if ((i < argc - 1) && (isdigit(argv[i + 1][0])))
                verbose = atoi(argv[++i]);
            else
                verbose++;
            if (verbose < 0)
            {
                ERR1("Illegal verbose level %d.  Reset to 0\n", verbose);
                verbose = 0;
            }
            else if (verbose > 10)
            {
                ERR1("Illegal verbose level %d.  Reset to 10\n", verbose);
                verbose = 10;
            }
            VMSG1(7, "Setting verbose level to %d\n", verbose);
        }
        else if (streq(argv[i], "-variant"))
            ok = setOptString(&i, argc, argv, VARIANT_NDX, FROM_CMD_LINE);
        else
        {
            ERR1("Error!   Option \"%s\" not recognized\n", argv[i]);
            ok = False;
        }
    }

    present = 0;
    if (svValue[TYPES_NDX])
        present++;
    if (svValue[COMPAT_NDX])
        present++;
    if (svValue[SYMBOLS_NDX])
        present++;
    if (svValue[KEYCODES_NDX])
        present++;
    if (svValue[GEOMETRY_NDX])
        present++;
    if (svValue[CONFIG_NDX])
        present++;
    if (svValue[MODEL_NDX])
        present++;
    if (svValue[LAYOUT_NDX])
        present++;
    if (svValue[VARIANT_NDX])
        present++;
    if (svValue[KEYMAP_NDX] && present)
    {
        ERR("No other components can be specified when a keymap is present\n");
        return False;
    }
    return ok;
}