Example #1
0
File: fb.c Project: gettler/mvpmc
static void
add_files(mvp_widget_t *fbw)
{
	char *wc[] = { "*.mpg", "*.mpeg", "*.mp3", "*.nuv", "*.vob", "*.gif",
			"*.bmp", "*.m3u", "*.pls", "*.jpg", "*.jpeg", "*.png", "*.wav",
			"*.ac3", "*.ogg", "*.ts", "*.flac", ".fla", NULL };
	char *WC[] = { "*.MPG", "*.MPEG", "*.MP3", "*.NUV", "*.VOB", "*.GIF",
			"*.BMP", "*.M3U", "*.JPG", "*.JPEG", "*.PNG", "*.WAV",
			"*.AC3", "*.OGG", "*.TS", "*.FLAC", "*.FLA", NULL };


	item_attr.select = select_callback;
	item_attr.hilite = hilite_callback;
	item_attr.fg = fb_attr.fg;
	item_attr.bg = fb_attr.bg;

	file_count = 0;
	do_glob(fbw, wc);
	do_glob(fbw, WC);
	if (vlc_server!=NULL) {
		char *vlc[] = { "*.divx", "*.DIVX", "*.flv", "*.FLV", "*.avi", "*.AVI", "*.wmv",
			"*.WMV", "*.wma", "*.WMA", "*.mp4", "*.MP4",
 			"*.mov", "*.MOV",
			"*.rm", "*.RM", "*.ogm", "*.OGM", "*.iso", "*.ISO", NULL };
		do_glob(fbw, vlc);
	}
}
		/* NOTREACHED */
	    }

	    if ( p == '\0' )
		return FAIL;

	    if ( p == '[' ) {
		char s = *string++;
		char reverse = '\0';
		char first, last;
		char gotcha = '\0';

		NEXTP;
		if ( p == '^' ) {
		    reverse = '\1';
		    NEXTP;
		}
		if ( p == ']' ) { /* special case */
		    gotcha = (s==p);
		    NEXTP;
		}

		while (  p != ']' && !gotcha ) {
		    first = p;
		    NEXTP;
		    if ( p == '-' && pattern[1] != ']' ) {
			NEXTP;
			last = p;
			NEXTP;
		    } else
			last = first;
		    if ( first > last )
			return ERROR;
		    gotcha = (first <= s && s <= last );
		}
		while ( p != ']' )
		    NEXTP;

		if ( reverse ? gotcha : !gotcha )
		    return FAIL;
	    } else if ( p != *string )
		return FAIL;
	    else
		string++;
	}
    }
    if ( seenstar )
	return SUCCES;

    if ( *string )
	return FAIL;
    return SUCCES;
}

static char *main_path;		/* ptr to scratchpad */
static int offset;		/* no of leading char in main_path to ignore */
static char **namelist;		/* name list buildup */
static int nnames;		/* no of names found */
static int left;		/* no of slots allocated but not used yet */

#define GLOBMAXSEG	50	/* max segments in pattern */
#define GLOBCHUNK	20	/* no of slots to allocate at a time */

#ifndef MAXNAMLEN
#define MAXNAMLEN 256
#endif

int
#ifndef ANSI_PROTOTYPES
glob_path( pattern, names )
    char *pattern;
    char ***names;
#else /* ANSI_PROTOTYPES */
glob_path(char *pattern, char ***names)
#endif /* ANSI_PROTOTYPES */
{
    char mpath[ MAXPATHLEN + MAXNAMLEN + 1 ];
    char *gpat[GLOBMAXSEG];
    char *pat;

    if (pattern == 0)
	return -1;

    if ((pat = strdup(pattern)) == NULL)
	return -1;

    if (split_pat(pat, gpat) < 0)
    {
	(void)free(pat);
	return -1;
    }
    
    main_path = mpath;		/* initalisation of static storage */
    namelist = 0;
    nnames = left = 0;

    if ( *gpat && **gpat == '/' )
    {
	main_path[0] = '/';
	main_path[1] = '\0';
	offset = 0;
	do_glob(main_path, gpat + 1);
    }
    else
    {
	main_path[0] = '.';
	main_path[1] = '\0';
	offset = 2;
	do_glob(main_path + 1, gpat);
    }

    (void)free(pat);

    if (namelist == 0)
	*names = (char **)malloc(sizeof(char *));
    else
	*names = (char **)realloc(namelist, (nnames+1) * sizeof(char *));

    if (*names == 0)
	return -1;
    (*names)[nnames] = 0;
    return nnames;
}
                		/* the rest of the pattern segments */
#endif /* ANSI_PROTOTYPES */
{
    char *saved_end = path_end;	/* saved to be resored */
    char *pat;			/* current pattern segment */
    struct stat st;		/* to check if file exists */

#ifdef GLOBDEBUG
    ffprintf(STDDBG,"do_glob: path = '%s', pat = '%s'\n", main_path, *gpat );
#endif

    for ( ; (pat = *gpat) != 0 && no_glob(pat); gpat++ )
    {
#ifdef GLOBDEBUG
	ffprintf(STDDBG,"no_glob: path = '%s', pat = '%s'\n", main_path, pat );
#endif
	*path_end = '/';
	(void)strcpy(path_end+1, pat);
	path_end += strlen(pat) + 1;

	if (GLOBSTAT(main_path, &st) != 0 )
	{
	    *saved_end = '\0';
	    return;
	}
    }
    if (pat)
	matchdir(path_end, gpat);
    else
	add_name();

    *saved_end = '\0';
    return;
}

static void
#ifndef ANSI_PROTOTYPES
matchdir(path_end, gpat)
    char *path_end;		/* ptr to end of main_path */
    char **gpat;		/* the rest of the pattern segments */
#else /* ANSI_PROTOTYPES */
matchdir(char *path_end, char **gpat)
                   		/* ptr to end of main_path */
                		/* the rest of the pattern segments */
#endif /* ANSI_PROTOTYPES */
{
    char *x;			/* scratch */
    VOIDDIR *dirp;		/* for directory reading */
    VOIDDIRENT *dp;		/* directory entry */
    struct stat st;		/* to determine files type */

#ifdef GLOBDEBUG
    ffprintf(STDDBG,"matchdir: path = '%s', pat = '%s'\n", main_path, *gpat );
#endif
    if ((dirp = OPENDIR(main_path)) == NULL)
	return;

    *path_end = '/';

    while ((dp = READDIR(dirp)) != NULL)
    {
	char *dirname;
	x = dirname = GETNAME(dp);	/* was dp->d_name */
	if (*x == '.' && (*++x == '\0' || (*x == '.' && *++x == '\0')))
	    continue;
	if (*dirname == '.' && **gpat != '.')
	    continue;

	(void)strcpy(path_end + 1, dirname);

	if (glob_match(*gpat, dirname))
	{   /* this is a match */
	    if ( *(gpat+1) == 0 )
	    {	/* and it is the last */
		add_name();	/* so eat it */
		continue;
	    }
	    if (GLOBSTAT(main_path, &st) == 0 /* else not the last */
		&& (st.st_mode & S_IFMT) == S_IFDIR)
		do_glob(path_end + strlen(dirname) + 1, gpat + 1);
	} 
    }

    (void)CLOSEDIR(dirp);

    *path_end = '\0';
}
main(int argc, char **argv) {
        do_glob();
        do_glob();
}