コード例 #1
0
ファイル: filetype.c プロジェクト: sklnd/vifm
char *
get_default_program_for_file(const char *file)
{
	int x;
	char *strptr;

	x = get_filetype_number(file, nfiletypes, all_filetypes);
	if(x < 0)
		return NULL;

	strptr = strdup(all_filetypes[x].com);

	replace_double_comma(strptr, 1);
	return strptr;
}
コード例 #2
0
ファイル: filetype.c プロジェクト: ackeack/workenv
/* 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);
}