diff options
author | John Hawthorn <jhawthor@uvic.ca> | 2008-06-17 22:59:30 -0700 |
---|---|---|
committer | John Hawthorn <jhawthor@uvic.ca> | 2008-06-17 22:59:30 -0700 |
commit | c9b3a0d39da0edf4f3a109bed97183f93b16c70d (patch) | |
tree | a0d695dabee2bcbde2f5087e5beee122275174f2 | |
parent | 04733aa35d1a24e3f8b2674cf65b9b849a885966 (diff) | |
download | mirror-meh-c9b3a0d39da0edf4f3a109bed97183f93b16c70d.tar.gz mirror-meh-c9b3a0d39da0edf4f3a109bed97183f93b16c70d.tar.bz2 mirror-meh-c9b3a0d39da0edf4f3a109bed97183f93b16c70d.zip |
preparing for larger changes
-rw-r--r-- | src/main.c | 53 |
1 files changed, 31 insertions, 22 deletions
@@ -17,10 +17,12 @@ extern Display *display; extern struct imageformat libjpeg; extern struct imageformat giflib; extern struct imageformat libpng; +extern struct imageformat gif; struct imageformat *formats[] = { &libjpeg, - &giflib, + &gif, &libpng, + &giflib, NULL }; @@ -76,8 +78,21 @@ struct imagenode *buildlist(int argc, char *argv[]){ } } -void run(struct imagenode *image){ - int direction = 1; +struct imagenode *images; + +const char *nextimage(){ + images = images->next; + return images->filename; +} + +const char *previmage(){ + images = images->prev; + return images->filename; +} + +void run(){ + const char *(*direction)() = nextimage; + const char *filename = direction(); int width = 0, height = 0; struct image *img = NULL; int redraw = 0; @@ -116,12 +131,13 @@ void run(struct imagenode *image){ case XK_t: case XK_n: if(XLookupKeysym(&event.xkey, 0) == XK_t){ - image = image->next; - direction = 1; + direction = nextimage; }else{ - image = image->prev; - direction = -1; + direction = previmage; } + filename = direction(); + /* Pass through */ + case XK_r: if(img){ if(img->buf) free(img->buf); @@ -131,6 +147,8 @@ void run(struct imagenode *image){ redraw = 1; break; case XK_Return: + puts(filename); + fflush(stdout); break; } break; @@ -138,20 +156,13 @@ void run(struct imagenode *image){ } if(redraw){ if(!img){ - while(!(img = imgopen(image->filename))){ - struct imagenode *tmp = image; - if(image->next == image){ + const char *firstimg = filename; + while(!(img = imgopen(filename))){ + filename = direction(); + if(filename == firstimg){ fprintf(stderr, "No valid images to view\n"); exit(1); } - if(direction < 0){ - image = image->prev; - }else{ - image = image->next; - } - tmp->prev->next = tmp->next; - tmp->next->prev = tmp->prev; - free(tmp); } img->buf = NULL; setaspect(img->width, img->height); @@ -171,14 +182,12 @@ void run(struct imagenode *image){ } int main(int argc, char *argv[]){ - struct imagenode *list; - if(argc < 2) usage(); xinit(); - list = buildlist(argc - 1, &argv[1]); - run(list); + images = buildlist(argc - 1, &argv[1]); + run(); return 0; } |