summaryrefslogtreecommitdiff
path: root/src/filelist.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/filelist.c')
-rw-r--r--src/filelist.c58
1 files changed, 49 insertions, 9 deletions
diff --git a/src/filelist.c b/src/filelist.c
index eaef54b..b569b8a 100644
--- a/src/filelist.c
+++ b/src/filelist.c
@@ -383,6 +383,20 @@ int feh_file_info_load(feh_file * file, Imlib_Image im)
return(0);
}
+void feh_file_dirname(char *dst, feh_file * f, int maxlen)
+{
+ int n = strlen(f->filename) - strlen(f->name);
+
+ /* Give up on long dirnames */
+ if (n <= 0 || n >= maxlen) {
+ dst[0] = '\0';
+ return;
+ }
+
+ strncpy(dst, f->filename, n);
+ dst[n] = '\0';
+}
+
int feh_cmp_filename(void *file1, void *file2)
{
return(strcmp(FEH_FILE(file1)->filename, FEH_FILE(file2)->filename));
@@ -393,6 +407,17 @@ int feh_cmp_name(void *file1, void *file2)
return(strcmp(FEH_FILE(file1)->name, FEH_FILE(file2)->name));
}
+int feh_cmp_dirname(void *file1, void *file2)
+{
+ char dir1[PATH_MAX], dir2[PATH_MAX];
+ int cmp;
+ feh_file_dirname(dir1, FEH_FILE(file1), PATH_MAX);
+ feh_file_dirname(dir2, FEH_FILE(file2), PATH_MAX);
+ if ((cmp = strcmp(dir1, dir2)) != 0)
+ return(cmp);
+ return(feh_cmp_name(file1, file2));
+}
+
/* Return -1 if file1 is _newer_ than file2 */
int feh_cmp_mtime(void *file1, void *file2)
{
@@ -465,6 +490,9 @@ void feh_prepare_filelist(void)
case SORT_FILENAME:
filelist = gib_list_sort(filelist, feh_cmp_filename);
break;
+ case SORT_DIRNAME:
+ filelist = gib_list_sort(filelist, feh_cmp_dirname);
+ break;
case SORT_MTIME:
filelist = gib_list_sort(filelist, feh_cmp_mtime);
break;
@@ -523,6 +551,7 @@ gib_list *feh_read_filelist(char *filename)
FILE *fp;
gib_list *list = NULL;
char s[1024], s1[1024];
+ Imlib_Load_Error err = IMLIB_LOAD_ERROR_NONE;
Imlib_Image tmp_im;
struct stat st;
signed short tmp_magick_timeout;
@@ -535,17 +564,26 @@ gib_list *feh_read_filelist(char *filename)
*/
tmp_magick_timeout = opt.magick_timeout;
opt.magick_timeout = -1;
- if (!stat(filename, &st) && S_ISREG(st.st_mode) &&
- feh_load_image_char(&tmp_im, filename)) {
- weprintf("Filelist file %s is an image, refusing to use it.\n"
- "Did you mix up -f and -F?", filename);
- opt.filelistfile = NULL;
- return NULL;
+ if (!stat(filename, &st) && S_ISREG(st.st_mode)) {
+ tmp_im = imlib_load_image_with_error_return(filename, &err);
+ if (err == IMLIB_LOAD_ERROR_NONE) {
+ gib_imlib_free_image_and_decache(tmp_im);
+ weprintf("Filelist file %s is an image, refusing to use it.\n"
+ "Did you mix up -f and -F?", filename);
+ opt.filelistfile = NULL;
+ return NULL;
+ }
}
opt.magick_timeout = tmp_magick_timeout;
errno = 0;
- if ((fp = fopen(filename, "r")) == NULL) {
+
+ if (!strcmp(filename, "/dev/stdin"))
+ fp = stdin;
+ else
+ fp = fopen(filename, "r");
+
+ if (fp == NULL) {
/* return quietly, as it's okay to specify a filelist file that doesn't
exist. In that case we create it on exit. */
return(NULL);
@@ -561,7 +599,8 @@ gib_list *feh_read_filelist(char *filename)
/* Add it to the new list */
list = gib_list_add_front(list, feh_file_new(s1));
}
- fclose(fp);
+ if (strcmp(filename, "/dev/stdin"))
+ fclose(fp);
return(list);
}
@@ -584,7 +623,8 @@ char *feh_absolute_path(char *path)
/* I SHOULD be able to just use a simple realpath() here, but dumb *
old Solaris's realpath doesn't return an absolute path if the
path you give it is relative. Linux and BSD get this right... */
- getcwd(cwd, sizeof(cwd));
+ if (getcwd(cwd, sizeof(cwd)) == NULL)
+ eprintf("Cannot determine working directory:");
snprintf(temp, sizeof(temp), "%s/%s", cwd, path);
if (realpath(temp, fullpath) != NULL) {
ret = estrdup(fullpath);