Example #1
0
static void lkxeys_attr_free(LXHotkeyAttr *data)
{
    g_free(data->name);
    g_list_free_full(data->values, g_free);
    free_actions(data->subopts);
    g_slice_free(LXHotkeyAttr, data);
}
Example #2
0
gboolean
rra_diff_info_free(rra_diff_info *in_info)
{
    if (in_info == NULL)
    {
        return FALSE;
    }

    gboolean ret_val = TRUE;

    ret_val = free_actions(in_info->action_list);

    g_ptr_array_free(in_info->action_list, TRUE);
    in_info->action_list = NULL;

    rra_free_type(rra_diff_info, in_info);
    return ret_val;
}
Example #3
0
int main (int parArgc, char* parArgv[]) {
	size_t z;
	size_t actions_count;
	char** actions;
	char* action_path;
	char* specified_action;
	size_t action_path_length;
	size_t selected_action;
	char** argv;
	int retval;
	int should_quit;

	find_actions(&actions, &actions_count);
	retval = manage_commandline(parArgc, parArgv, actions, actions_count, &should_quit);
	if (should_quit) {
		free_actions(actions, actions_count);
		return retval;
	}
	if (0 == actions_count) {
		fprintf(stderr, "No actions found in \"%s\"\n", ACTIONS_SEARCH_PATH);
		return 1;
	}

	if (1 < parArgc)
		specified_action = parArgv[1];
	else
		specified_action = "";
	assert((actions and actions_count) or (not actions and not actions_count));
	selected_action = foreach_avail_action(&same_action, actions, actions_count, specified_action);

	if (actions_count == selected_action) {
		//Find a possible mispelling and show a hint to the user if any
		selected_action = foreach_avail_action(&find_similar, actions, actions_count, specified_action);
		if (selected_action < actions_count) {
			fprintf(stderr, "Unrecognized action \"%s\" - maybe you meant \"%s\"?\n",
				specified_action,
				get_actionname(actions[selected_action])
			);
		}
		else {
			fprintf(stderr, "Unrecognized action \"%s\"\n", specified_action);
		}
		free_actions(actions, actions_count);
		return 2;
	}

	action_path_length = lengthof(ACTIONS_SEARCH_PATH) - 1;
	if (ACTIONS_SEARCH_PATH[lengthof(ACTIONS_SEARCH_PATH) - 2] != '/') {
		++action_path_length;
	}
	action_path_length += strlen(actions[selected_action]);
	++action_path_length;

	action_path = malloc(action_path_length);
	memcpy(action_path, ACTIONS_SEARCH_PATH, lengthof(ACTIONS_SEARCH_PATH) - 1);
	z = lengthof(ACTIONS_SEARCH_PATH) - 1;
	if (ACTIONS_SEARCH_PATH[lengthof(ACTIONS_SEARCH_PATH) - 2] != '/') {
		action_path[lengthof(ACTIONS_SEARCH_PATH) - 1] = '/';
		++z;
	}
	strcpy(action_path + z, actions[selected_action]);

	free_actions(actions, actions_count);

	argv = malloc(sizeof(char*) * (parArgc - 1 + 1));
	argv[0] = action_path;
	for (z = 2; z < (size_t)parArgc; ++z) {
		argv[z - 1] = parArgv[z];
	}
	argv[parArgc - 1] = NULL;

	/*printf("would call %s\n", action_path);*/
	retval = execv(action_path, argv);
	if (retval < 0) {
		fprintf(stderr, "Error executing \"%s\": %d:\n%s\n", action_path, errno, strerror(errno));
		free(action_path);
		return 1;
	}

	/* the program won't get here, but just to be clean... */
	free(action_path);
	return 0;
}