Преглед изворни кода

Strict conformance to IEEE Std 1003.1-2001

master
Bert пре 13 година
родитељ
комит
6e575b0f72
8 измењених фајлова са 64 додато и 38 уклоњено
  1. +2
    -2
      commands.c
  2. +2
    -0
      image.c
  3. +7
    -2
      main.c
  4. +2
    -2
      options.c
  5. +9
    -19
      thumbs.c
  6. +38
    -6
      util.c
  7. +2
    -7
      util.h
  8. +2
    -0
      window.c

+ 2
- 2
commands.c Прегледај датотеку

@@ -16,9 +16,9 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 200112L /* for setenv(3) */ #define _POSIX_C_SOURCE 200112L
#include <stdlib.h>


#include <stdlib.h>
#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>
#include <sys/wait.h> #include <sys/wait.h>


+ 2
- 0
image.c Прегледај датотеку

@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 200112L

#include <string.h> #include <string.h>
#include <unistd.h> #include <unistd.h>




+ 7
- 2
main.c Прегледај датотеку

@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 200112L

#include <stdlib.h> #include <stdlib.h>
#include <stdio.h> #include <stdio.h>
#include <string.h> #include <string.h>
@@ -430,8 +432,9 @@ int fncmp(const void *a, const void *b) {
} }


int main(int argc, char **argv) { int main(int argc, char **argv) {
int i, len, start; int i, start;
size_t n; size_t n;
ssize_t len;
char *filename; char *filename;
struct stat fstats; struct stat fstats;
r_dir_t dir; r_dir_t dir;
@@ -460,11 +463,13 @@ int main(int argc, char **argv) {
/* build file list: */ /* build file list: */
if (options->from_stdin) { if (options->from_stdin) {
filename = NULL; filename = NULL;
while ((len = getline(&filename, &n, stdin)) > 0) { while ((len = get_line(&filename, &n, stdin)) > 0) {
if (filename[len-1] == '\n') if (filename[len-1] == '\n')
filename[len-1] = '\0'; filename[len-1] = '\0';
check_add_file(filename); check_add_file(filename);
} }
if (filename)
free(filename);
} else { } else {
for (i = 0; i < options->filecnt; i++) { for (i = 0; i < options->filecnt; i++) {
filename = options->filenames[i]; filename = options->filenames[i];


+ 2
- 2
options.c Прегледај датотеку

@@ -16,12 +16,12 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 2 /* for getopt(3) */ #define _POSIX_C_SOURCE 200112L
#include <unistd.h>


#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <stdio.h> #include <stdio.h>
#include <unistd.h>


#include "options.h" #include "options.h"
#include "util.h" #include "util.h"


+ 9
- 19
thumbs.c Прегледај датотеку

@@ -16,12 +16,14 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 200112L

#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/time.h>
#include <sys/types.h> #include <sys/types.h>
#include <sys/stat.h> #include <sys/stat.h>
#include <unistd.h> #include <unistd.h>
#include <utime.h>


#include "thumbs.h" #include "thumbs.h"
#include "util.h" #include "util.h"
@@ -29,11 +31,6 @@
#define _THUMBS_CONFIG #define _THUMBS_CONFIG
#include "config.h" #include "config.h"


#ifdef __NetBSD__
#define st_mtim st_mtimespec
#define st_atim st_atimespec
#endif

#ifdef EXIF_SUPPORT #ifdef EXIF_SUPPORT
void exif_auto_orientate(const fileinfo_t*); void exif_auto_orientate(const fileinfo_t*);
#endif #endif
@@ -76,12 +73,8 @@ Imlib_Image* tns_cache_load(const char *filepath) {
return NULL; return NULL;


if ((cfile = tns_cache_filepath(filepath))) { if ((cfile = tns_cache_filepath(filepath))) {
if (!stat(cfile, &cstats) && if (!stat(cfile, &cstats) && cstats.st_mtime == fstats.st_mtime)
cstats.st_mtim.tv_sec == fstats.st_mtim.tv_sec &&
cstats.st_mtim.tv_nsec / 1000 == fstats.st_mtim.tv_nsec / 1000)
{
im = imlib_load_image(cfile); im = imlib_load_image(cfile);
}
free(cfile); free(cfile);
} }


@@ -91,7 +84,7 @@ Imlib_Image* tns_cache_load(const char *filepath) {
void tns_cache_write(thumb_t *t, Bool force) { void tns_cache_write(thumb_t *t, Bool force) {
char *cfile, *dirend; char *cfile, *dirend;
struct stat cstats, fstats; struct stat cstats, fstats;
struct timeval times[2]; struct utimbuf times;
Imlib_Load_Error err = 0; Imlib_Load_Error err = 0;


if (!t || !t->im || !t->file || !t->file->name || !t->file->path) if (!t || !t->im || !t->file || !t->file->name || !t->file->path)
@@ -101,10 +94,7 @@ void tns_cache_write(thumb_t *t, Bool force) {
return; return;


if ((cfile = tns_cache_filepath(t->file->path))) { if ((cfile = tns_cache_filepath(t->file->path))) {
if (force || stat(cfile, &cstats) || if (force || stat(cfile, &cstats) || cstats.st_mtime != fstats.st_mtime) {
cstats.st_mtim.tv_sec != fstats.st_mtim.tv_sec ||
cstats.st_mtim.tv_nsec / 1000 != fstats.st_mtim.tv_nsec / 1000)
{
if ((dirend = strrchr(cfile, '/'))) { if ((dirend = strrchr(cfile, '/'))) {
*dirend = '\0'; *dirend = '\0';
err = r_mkdir(cfile); err = r_mkdir(cfile);
@@ -120,9 +110,9 @@ void tns_cache_write(thumb_t *t, Bool force) {
if (err) { if (err) {
warn("could not cache thumbnail: %s", t->file->name); warn("could not cache thumbnail: %s", t->file->name);
} else { } else {
TIMESPEC_TO_TIMEVAL(&times[0], &fstats.st_atim); times.actime = fstats.st_atime;
TIMESPEC_TO_TIMEVAL(&times[1], &fstats.st_mtim); times.modtime = fstats.st_mtime;
utimes(cfile, times); utime(cfile, &times);
} }
} }
free(cfile); free(cfile);


+ 38
- 6
util.c Прегледај датотеку

@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 200112L

#include <stdlib.h> #include <stdlib.h>
#include <string.h> #include <string.h>
#include <sys/types.h> #include <sys/types.h>
@@ -27,6 +29,7 @@
#include "util.h" #include "util.h"


enum { enum {
BUF_SIZE = 1024,
DNAME_CNT = 512, DNAME_CNT = 512,
FNAME_LEN = 1024 FNAME_LEN = 1024
}; };
@@ -87,6 +90,39 @@ void die(const char* fmt, ...) {
exit(1); exit(1);
} }


ssize_t get_line(char **buf, size_t *n, FILE *stream) {
size_t len;
char *s;

if (!stream || feof(stream) || ferror(stream))
return -1;

if (!*buf || !*n) {
*n = BUF_SIZE;
*buf = (char*) s_malloc(*n);
}
s = *buf;

while (1) {
if (!fgets(s, *n - (s - *buf), stream))
return -1;
len = strlen(s);
if (feof(stream))
break;
if (len > 0 && s[len-1] == '\n')
break;
if (len + 1 == *n - (s - *buf)) {
*buf = (char*) s_realloc(*buf, 2 * *n);
s = *buf + *n - 1;
*n *= 2;
} else {
s += len;
}
}

return s - *buf + len;
}

void size_readable(float *size, const char **unit) { void size_readable(float *size, const char **unit) {
const char *units[] = { "", "K", "M", "G" }; const char *units[] = { "", "K", "M", "G" };
int i; int i;
@@ -98,13 +134,9 @@ void size_readable(float *size, const char **unit) {


char* absolute_path(const char *filename) { char* absolute_path(const char *filename) {
size_t len; size_t len;
char *path = NULL;
const char *basename; const char *basename;
char *dirname = NULL; char *dir, *dirname = NULL, *path = NULL, *s;
char *cwd = NULL; char *cwd = NULL, *twd = NULL;
char *twd = NULL;
char *dir;
char *s;


if (!filename || *filename == '\0' || *filename == '/') if (!filename || *filename == '\0' || *filename == '/')
return NULL; return NULL;


+ 2
- 7
util.h Прегледај датотеку

@@ -45,13 +45,6 @@
(tv)->tv_usec += (t) % 1000 * 1000; \ (tv)->tv_usec += (t) % 1000 * 1000; \
} }


#ifndef TIMESPEC_TO_TIMEVAL
#define TIMESPEC_TO_TIMEVAL(tv,ts) { \
(tv)->tv_sec = (ts)->tv_sec; \
(tv)->tv_usec = (ts)->tv_nsec / 1000; \
}
#endif

typedef struct { typedef struct {
DIR *dir; DIR *dir;
char *name; char *name;
@@ -69,6 +62,8 @@ char* s_strdup(char*);
void warn(const char*, ...); void warn(const char*, ...);
void die(const char*, ...); void die(const char*, ...);


ssize_t get_line(char**, size_t*, FILE*);

void size_readable(float*, const char**); void size_readable(float*, const char**);


char* absolute_path(const char*); char* absolute_path(const char*);


+ 2
- 0
window.c Прегледај датотеку

@@ -16,6 +16,8 @@
* 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA. * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
*/ */


#define _POSIX_C_SOURCE 200112L

#include <string.h> #include <string.h>
#include <X11/Xutil.h> #include <X11/Xutil.h>
#include <X11/cursorfont.h> #include <X11/cursorfont.h>


||||||
x
 
000:0
Loading…
Откажи
Сачувај