Skip to content
Snippets Groups Projects
Commit 31d40696 authored by deuce's avatar deuce
Browse files

Add a getdirname() function which returns a pointer to the last component

of a path that is surrounded by path delimiters.
Use this with GLOB_MARK to for the directory list.
parent 09b77723
No related branches found
No related tags found
No related merge requests found
......@@ -150,6 +150,26 @@ char *insensitive_mask(char *mask)
#endif
}
char *getdirname(char *path)
{
char *p1;
char *p2;
p1=strrchr(path,'/');
#ifdef _WIN32
p2=strrchr(path,'\\');
if(p2 > p1)
p1=p2;
#endif
p2 = path;
if(p1 > path) {
for(p2=p1-1; p2>=path && !IS_PATH_DELIM(*p2); p2--);
if(IS_PATH_DELIM(*p2) && *(p2+1))
p2++;
}
return(p2);
}
char **get_file_opt_list(char **fns, int files, int dirsonly, int root)
{
char **opts;
......@@ -167,7 +187,7 @@ char **get_file_opt_list(char **fns, int files, int dirsonly, int root)
for(i=0;i<files;i++) {
if(isdir(fns[i])) {
if(dirsonly)
opts[j++]=strdup(getfname(fns[i]));
opts[j++]=strdup(getdirname(fns[i]));
}
else {
if(!dirsonly)
......@@ -366,7 +386,7 @@ int filepick(uifcapi_t *api, char *title, struct file_pick *fp, char *dir, char
#else
//#error Need to do something about root paths (in get_file_opt_list() too!)
#endif
if(glob(dglob, 0, NULL, &dgl)!=0) {
if(glob(dglob, GLOB_MARK, NULL, &dgl)!=0) {
if(lastpath==NULL) {
fp->files=0;
retval=-1;
......
0% Loading or .
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment