Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Add %T temp output filename format specifier #638

Open
wants to merge 1 commit into
base: master
Choose a base branch
from
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Jump to
Jump to file
Failed to load files.
Diff view
Diff view
4 changes: 4 additions & 0 deletions man/feh.pre
Expand Up @@ -1327,6 +1327,10 @@ Human-readable image size
.
Image format
.
.It \&%T
.
Temporary output filename
.
.It %u
.
Number of current file
Expand Down
5 changes: 5 additions & 0 deletions src/filelist.c
Expand Up @@ -49,6 +49,7 @@ feh_file *feh_file_new(char *filename)
newfile = (feh_file *) emalloc(sizeof(feh_file));
newfile->caption = NULL;
newfile->filename = estrdup(filename);
newfile->tempname = NULL;
s = strrchr(filename, '/');
if (s)
newfile->name = estrdup(s + 1);
Expand All @@ -67,6 +68,10 @@ void feh_file_free(feh_file * file)
return;
if (file->filename)
free(file->filename);
if (file->tempname) {
unlink(file->tempname);
free(file->tempname);
}
if (file->name)
free(file->name);
if (file->caption)
Expand Down
1 change: 1 addition & 0 deletions src/filelist.h
Expand Up @@ -32,6 +32,7 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.

struct __feh_file {
char *filename;
char *tempname;
char *caption;
char *name;

Expand Down
1 change: 1 addition & 0 deletions src/help.raw
Expand Up @@ -144,6 +144,7 @@ FORMAT SPECIFIERS
%s image size in bytes
%S image size with appropriate unit (kB/MB)
%t image format
%T temporary output filename
%u current file number
%w image width
%v " PACKAGE " version
Expand Down
26 changes: 14 additions & 12 deletions src/imlib.c
Expand Up @@ -249,7 +249,9 @@ void feh_print_load_error(char *file, winwidget w, Imlib_Load_Error err, enum fe
int feh_is_image(feh_file * file)
{
unsigned char buf[16];
FILE *fh = fopen(file->filename, "r");
char *filename = file->tempname ? file->tempname : file->filename;

FILE *fh = fopen(filename, "r");
if (!fh) {
return 0;
}
Expand Down Expand Up @@ -297,7 +299,7 @@ int feh_is_image(feh_file * file)
// PNM et al.
return 1;
}
if (strstr(file->filename, ".tga")) {
if (strstr(filename, ".tga")) {
// TGA
return 1;
}
Expand All @@ -324,7 +326,7 @@ int feh_is_image(feh_file * file)
// XPM
return 1;
}
if (strstr(file->filename, ".bz2") || strstr(file->filename, ".gz")) {
if (strstr(filename, ".bz2") || strstr(filename, ".gz")) {
// Imlib2 supports compressed images. It relies on the filename to
// determine the appropriate loader and does not use magic bytes here.
return 1;
Expand All @@ -343,42 +345,42 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
enum { SRC_IMLIB, SRC_HTTP, SRC_MAGICK, SRC_DCRAW } image_source = SRC_IMLIB;
char *tmpname = NULL;
char *real_filename = NULL;
char *filename;

D(("filename is %s, image is %p\n", file->filename, im));

if (!file || !file->filename)
return 0;

if (path_is_url(file->filename)) {
filename = file->tempname ? file->tempname : file->filename;
if (path_is_url(filename)) {
image_source = SRC_HTTP;

if ((tmpname = feh_http_load_image(file->filename)) == NULL) {
if ((tmpname = feh_http_load_image(filename)) == NULL) {
feh_err = LOAD_ERROR_CURL;
err = IMLIB_LOAD_ERROR_FILE_DOES_NOT_EXIST;
}
}
else {
if (feh_is_image(file)) {
*im = imlib_load_image_with_error_return(file->filename, &err);
*im = imlib_load_image_with_error_return(filename, &err);
} else {
feh_err = LOAD_ERROR_MAGICBYTES;
err = IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT;
}
}

if (opt.conversion_timeout >= 0 && (
(err == IMLIB_LOAD_ERROR_UNKNOWN) ||
(err == IMLIB_LOAD_ERROR_NO_LOADER_FOR_FILE_FORMAT))) {
if (feh_file_is_raw(file->filename)) {
if (feh_file_is_raw(filename)) {
image_source = SRC_DCRAW;
tmpname = feh_dcraw_load_image(file->filename);
tmpname = feh_dcraw_load_image(filename);
if (!tmpname) {
feh_err = LOAD_ERROR_DCRAW;
}
} else {
image_source = SRC_MAGICK;
feh_err = LOAD_ERROR_IMLIB;
tmpname = feh_magick_load_image(file->filename);
tmpname = feh_magick_load_image(filename);
if (!tmpname) {
feh_err = LOAD_ERROR_IMAGEMAGICK;
}
Expand All @@ -388,7 +390,7 @@ int feh_load_image(Imlib_Image * im, feh_file * file)
if (tmpname) {
*im = imlib_load_image_with_error_return(tmpname, &err);
if (!err && im) {
real_filename = file->filename;
real_filename = filename;
file->filename = tmpname;

/*
Expand Down
8 changes: 8 additions & 0 deletions src/slideshow.c
Expand Up @@ -511,6 +511,14 @@ char *feh_printf(char *str, feh_file * file, winwidget winwid)
strncat(ret, file->info->format, sizeof(ret) - strlen(ret) - 1);
}
break;
case 'T':
if (file) {
if (file->tempname == NULL) {
file->tempname = feh_unique_filename("/tmp/","feh_tempname");
}
strncat(ret, file->tempname, sizeof(ret) - strlen(ret) - 1);
}
break;
case 'u':
f = current_file ? current_file : gib_list_find_by_data(filelist, file);
snprintf(buf, sizeof(buf), "%d", f ? gib_list_num(filelist, f) + 1 : 0);
Expand Down