Переглянути джерело

Readded file-type check at startup

master
Bert 14 роки тому
джерело
коміт
426edfb349
3 змінених файлів з 27 додано та 5 видалено
  1. +1
    -1
      Makefile
  2. +18
    -1
      image.c
  3. +8
    -3
      main.c

+ 1
- 1
Makefile Переглянути файл

@@ -1,6 +1,6 @@
all: sxiv

VERSION=git-20110404
VERSION=git-20110405

CC?=gcc
PREFIX?=/usr/local


+ 18
- 1
image.c Переглянути файл

@@ -56,6 +56,23 @@ void img_free(img_t* img) {
imlib_free_image();
}

int img_check(const char *filename) {
Imlib_Image *im;

if (!filename)
return 0;

if ((im = imlib_load_image(filename))) {
imlib_context_set_image(im);
imlib_image_set_changes_on_disk();
imlib_free_image();
return 1;
} else {
warn("invalid file: %s", filename);
return 0;
}
}

int img_load(img_t *img, const char *filename) {
if (!img || !filename)
return 0;
@@ -66,7 +83,7 @@ int img_load(img_t *img, const char *filename) {
imlib_context_set_anti_alias(img->aa);
img->scalemode = options->scalemode;
} else {
warn("not an image: %s", filename);
warn("invalid file: %s", filename);
imlib_context_set_image(im_invalid);
imlib_context_set_anti_alias(0);
}


+ 8
- 3
main.c Переглянути файл

@@ -178,7 +178,7 @@ void update_title() {
fileidx + 1, filecnt, (int) (img.zoom * 100.0), size, unit,
filenames[fileidx]);
} else {
n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] not an image: %s",
n = snprintf(win_title, TITLE_LEN, "sxiv: [%d/%d] invalid: %s",
fileidx + 1, filecnt, filenames[fileidx]);
}
}
@@ -193,7 +193,13 @@ void update_title() {
}

int check_append(const char *filename) {
if (filename && !access(filename, R_OK)) {
if (!filename)
return 0;

if (access(filename, R_OK)) {
warn("could not open file: %s", filename);
return 0;
} else if (img_check(filename)) {
if (fileidx == filecnt) {
filecnt *= 2;
filenames = (const char**) s_realloc(filenames,
@@ -202,7 +208,6 @@ int check_append(const char *filename) {
filenames[fileidx++] = filename;
return 1;
} else {
warn("could not open file: %s", filename);
return 0;
}
}


Завантаження…
Відмінити
Зберегти