Exemplo n.º 1
0
static int
fire(Option opt)
{
    int status = 0;

    if (opt.type == OPT_IS_FUNC) {
	int (*cp)(char *) = opt.data, rcode;

	rcode = cp(NULL);
	if (rcode & (DITEM_RECREATE | DITEM_RESTORE))
	    status = 1;
    }
    else if (opt.type == OPT_IS_VAR) {
	if (opt.data) {
	    (void)variable_get_value(opt.aux, opt.data);
	    status = 1;
	}
	else if (variable_get(opt.aux))
	    variable_unset(opt.aux);
	else
	    variable_set2(opt.aux, "YES");
    }
    if (opt.check)
	opt.check(opt);
    refresh();
    return status;
}
Exemplo n.º 2
0
int
dmenuISetVariable(dialogMenuItem *tmp)
{
    char *ans, *var;

    if (!(var = (char *)tmp->data)) {
	msgConfirm("Incorrect data field for `%s'!", tmp->title);
	return DITEM_FAILURE;
    }
    ans = msgGetInput(variable_get(var), tmp->title, 1);
    if (!ans)
	return DITEM_FAILURE;
    else if (!*ans)
	variable_unset(var);
    else
	variable_set2(var, ans, *var != '_');
    return DITEM_SUCCESS;
}
Exemplo n.º 3
0
/* For a given string, call it or spit out an undefined command diagnostic */
int
dispatchCommand(char *str)
{
    int i;
    char *cp;

    if (!str || !*str) {
	msgConfirm("Null or zero-length string passed to dispatchCommand");
	return DITEM_FAILURE;
    }
    /* If it's got a newline, trim it */
    if ((cp = index(str, '\n')) != NULL)
	*cp = '\0';

    /* If it's got a `=' sign in there, assume it's a variable setting */
    if (index(str, '=')) {
	if (isDebug())
	    msgDebug("dispatch: setting variable `%s'\n", str);
	variable_set(str, 0);
	i = DITEM_SUCCESS;
    }
    else {
	/* A command might be a pathname if it's encoded in argv[0], which
	   we also support */
	if ((cp = rindex(str, '/')) != NULL)
	    str = cp + 1;
	if (isDebug())
	    msgDebug("dispatch: calling resword `%s'\n", str);
	if (!call_possible_resword(str, NULL, &i)) {
	    msgNotify("Warning: No such command ``%s''", str);
	    i = DITEM_FAILURE;
	}
	/*
	 * Allow a user to prefix a command with "noError" to cause
	 * us to ignore any errors for that one command.
	 */
	if (i != DITEM_SUCCESS && variable_get(VAR_NO_ERROR))
	    i = DITEM_SUCCESS;
	variable_unset(VAR_NO_ERROR);
    }
    return i;
}
Exemplo n.º 4
0
int
dmenuISetVariable(dialogMenuItem *tmp)
{
    char *ans, *p, *var;

    if (!(var = strdup((char *)tmp->data))) {
	msgConfirm("Incorrect data field for `%s'!", tmp->title);
	return DITEM_FAILURE;
    }
    if ((p = index(var, '=')) != NULL)
	*p = '\0';
    ans = msgGetInput(variable_get(var), tmp->title, 1);
    if (!ans) {
	free(var);
	return DITEM_FAILURE;
    } else if (!*ans)
	variable_unset(var);
    else
	variable_set2(var, ans, *var != '_');
    free(var);
    return DITEM_SUCCESS;
}