diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-22 01:34:45 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-22 01:34:45 -0700 |
commit | 292cf3ee0494b14e6f82df755ae02b2f078afc35 (patch) | |
tree | 624dd892b6d44e85131a5a192eb3093ebc1e0428 /src/main.c | |
parent | 12fe3f62f2931f296beb130840c091542647319b (diff) | |
download | mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.tar.gz mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.tar.bz2 mirror-meh-292cf3ee0494b14e6f82df755ae02b2f078afc35.zip |
cleanup
Diffstat (limited to 'src/main.c')
-rw-r--r-- | src/main.c | 31 |
1 files changed, 22 insertions, 9 deletions
@@ -22,7 +22,7 @@ struct imageformat *formats[] = { &libjpeg, &gif, &libpng, - &giflib, + &giflib, /* HACK! make gif last (uses read()) */ NULL }; @@ -34,21 +34,15 @@ void usage(){ exit(1); } -struct image *imgopen(const char *filename){ +struct image *imgopen(FILE *f){ struct image *img = NULL; struct imageformat **fmt = formats; - FILE *f; - if((f = fopen(filename, "rb")) == NULL){ - fprintf(stderr, "Cannot open '%s'\n", filename); - return NULL; - } for(fmt = formats; *fmt; fmt++){ if((img = (*fmt)->open(f))){ img->fmt = *fmt; return img; } } - fprintf(stderr, "Unknown file type: '%s'\n", filename); return NULL; } @@ -96,6 +90,7 @@ void run(){ int width = 0, height = 0; struct image *img = NULL; int redraw = 0; + FILE *f = NULL; for(;;){ XEvent event; @@ -157,7 +152,21 @@ void run(){ if(redraw){ if(!img){ const char *firstimg = filename; - while(!(img = imgopen(filename))){ + while(!img){ + if(f){ + fclose(f); + f = NULL; + } + if(!(f = fopen(filename, "rb"))) + fprintf(stderr, "Cannot open '%s'\n", filename); + + if(f){ + if((img = imgopen(f))) + break; + else + fprintf(stderr, "Invalid format '%s'\n", filename); + } + filename = direction(); if(filename == firstimg){ fprintf(stderr, "No valid images to view\n"); @@ -173,6 +182,10 @@ void run(){ if(img->fmt->read(img)){ fprintf(stderr, "read error!\n"); } + if(f){ + fclose(f); + f = NULL; + } continue; /* Allow for some events to be read, read is slow */ } drawimage(img, width, height); |