Ejemplo n.º 1
0
/* Associates pattern with the list of programs either for X or non-X
 * associations and depending on current execution environment. */
static void
assoc_programs(matcher_t *matcher, const assoc_records_t *programs, int for_x,
		int in_x)
{
	const assoc_t assoc = {
		.matcher = matcher,
		.records = clone_assoc_records(programs, matcher_get_expr(matcher),
				for_x ? &xfiletypes : &filetypes),
	};

	register_assoc(assoc, for_x, in_x);
}

/* Parses comma separated list of commands into array of associations.  Returns
 * the list. */
static assoc_records_t
parse_command_list(const char cmds[], int with_descr)
{
	assoc_records_t records = {};

	char *free_this = strdup(cmds);

	char *part = free_this, *state = NULL;
	while((part = split_and_get_dc(part, &state)) != NULL)
	{
		const char *description = "";

		if(with_descr && *part == '{')
		{
			char *p = strchr(part + 1, '}');
			if(p != NULL)
			{
				*p = '\0';
				description = part + 1;
				part = skip_whitespace(p + 1);
			}
		}

		if(part[0] != '\0')
		{
			ft_assoc_record_add(&records, part, description);
		}
	}

	free(free_this);

	return records;
}
Ejemplo n.º 2
0
/* Associates patter with list of comma separated programs either for X or non-X
 * associations and depending on current execution environment. */
static void
assoc_programs(const char pattern[], const char programs[], int for_x, int in_x)
{
    assoc_t assoc;
    char *prog;
    char *free_this;

    if(pattern[0] == '\0')
    {
        return;
    }

    assoc.pattern = strdup(pattern);
    assoc.records.list = NULL;
    assoc.records.count = 0;

    prog = strdup(programs);
    free_this = prog;

    while(prog != NULL)
    {
        char *ptr;
        const char *description = "";

        if((ptr = strchr(prog, ',')) != NULL)
        {
            while(ptr != NULL && ptr[1] == ',')
            {
                ptr = strchr(ptr + 2, ',');
            }
            if(ptr != NULL)
            {
                *ptr = '\0';
                ptr++;
            }
        }

        while(isspace(*prog) || *prog == ',')
        {
            prog++;
        }

        if(*prog == '{')
        {
            char *p = strchr(prog + 1, '}');
            if(p != NULL)
            {
                *p = '\0';
                description = prog + 1;
                prog = skip_whitespace(p + 1);
            }
        }

        if(prog[0] != '\0')
        {
            replace_double_comma(prog, 0);
            add_assoc_record(&assoc.records, prog, description);
        }
        prog = ptr;
    }

    free(free_this);

    register_assoc(assoc, for_x, in_x);
}