Util: Add patht function to transform path: '~/' is now allowed

This commit is contained in:
Martin Duquesnoy 2010-08-02 19:20:06 +02:00
parent 00638264d3
commit 36ca03f8f3
4 changed files with 24 additions and 4 deletions

View File

@ -159,7 +159,7 @@ draw_image(Drawable dr, int x, int y, int w, int h, char *name)
imlib_context_set_colormap(DefaultColormap(dpy, DefaultScreen(dpy)));
imlib_context_set_drawable(dr);
image = imlib_load_image(name);
image = imlib_load_image(patht(name));
imlib_context_set_image(image);
if(w <= 0)

View File

@ -201,16 +201,16 @@ init_status(void)
sprintf(conf.status_path, "%s/"DEF_STATUS, home);
}
if (stat(conf.status_path, &st) == -1)
if (stat(patht(conf.status_path), &st) == -1)
{
warn("%s", conf.status_path);
warn("%s", patht(conf.status_path));
return;
}
if(st.st_size && st.st_mode & S_IXUSR)
estatus = True;
else
warnx("status file specified in configuratin (status_path) or present in wmfs directory can't be executed, try 'chmod +x %s'.", conf.status_path);
warnx("status file specified in configuratin (status_path) or present in wmfs directory can't be executed, try 'chmod +x %s'.", patht(conf.status_path));
return;
}

View File

@ -340,3 +340,21 @@ clean_value(char *str)
return p;
}
/* To use ~/ shortcut.. */
char*
patht(char *path)
{
static char ret[512];
if(!path)
return NULL;
strcpy(ret, path);
if(strstr(path, "~/"))
sprintf(ret, "%s/%s", getenv("HOME"), path + 2);
printf("--> (%s) - %s\n", path, ret);
return ret;
}

View File

@ -296,6 +296,8 @@ int spawn(const char *str, ...);
void swap_ptr(void **x, void **y);
void uicb_spawn(uicb_t);
char *clean_value(char *str);
char* patht(char *path);
#ifdef HAVE_IMLIB
int parse_image_block(ImageAttr *im, char *str);