diff options
-rw-r--r-- | src/backend.h | 12 | ||||
-rw-r--r-- | src/backend_freeimage.c | 21 | ||||
-rw-r--r-- | src/backend_freeimage.h | 2 | ||||
-rw-r--r-- | src/backend_libpng.c | 21 | ||||
-rw-r--r-- | src/backend_libpng.h | 2 | ||||
-rw-r--r-- | src/backend_librsvg.c | 23 | ||||
-rw-r--r-- | src/backend_librsvg.h | 2 | ||||
-rw-r--r-- | src/imv.c | 63 | ||||
-rw-r--r-- | src/imv.h | 2 |
9 files changed, 78 insertions, 70 deletions
diff --git a/src/backend.h b/src/backend.h index 0da2244..714efde 100644 --- a/src/backend.h +++ b/src/backend.h @@ -18,13 +18,19 @@ struct imv_backend { /* Name of the backend, for debug and user informational purposes */ const char *name; + /* Information about the backend, displayed by help dialog */ + const char *description; + + /* Official website address */ + const char *website; + + /* License the backend is used under */ + const char *license; + /* Input: path to open * Output: initialises the imv_source instance passed in */ enum backend_result (*open_path)(const char *path, struct imv_source **src); - - /* Clean up this backend */ - void (*free)(struct imv_backend *backend); }; #endif diff --git a/src/backend_freeimage.c b/src/backend_freeimage.c index 9443075..0032e31 100644 --- a/src/backend_freeimage.c +++ b/src/backend_freeimage.c @@ -258,23 +258,22 @@ static enum backend_result open_path(const char *path, struct imv_source **src) return BACKEND_SUCCESS; } -static void backend_free(struct imv_backend *backend) -{ - free(backend); -} +const struct imv_backend freeimage_backend = { + .name = "FreeImage", + .description = "Open source image library supporting a large number of formats", + .website = "http://freeimage.sourceforge.net/", + .license = "FreeImage Public License v1.0", + .open_path = &open_path, +}; -struct imv_backend *imv_backend_freeimage(void) +const struct imv_backend *imv_backend_freeimage(void) { - struct imv_backend *backend = malloc(sizeof(struct imv_backend)); - backend->name = "FreeImage (FIPL v1.0 license)"; - backend->open_path = &open_path; - backend->free = &backend_free; - return backend; + return &freeimage_backend; } #else -struct imv_backend *imv_backend_freeimage(void) +const struct imv_backend *imv_backend_freeimage(void) { return NULL; } diff --git a/src/backend_freeimage.h b/src/backend_freeimage.h index de7d078..4eb0879 100644 --- a/src/backend_freeimage.h +++ b/src/backend_freeimage.h @@ -4,6 +4,6 @@ struct imv_backend; /* Create an instance of the freeimage backend */ -struct imv_backend *imv_backend_freeimage(void); +const struct imv_backend *imv_backend_freeimage(void); #endif diff --git a/src/backend_libpng.c b/src/backend_libpng.c index d5a2676..0e58b6f 100644 --- a/src/backend_libpng.c +++ b/src/backend_libpng.c @@ -179,23 +179,22 @@ static enum backend_result open_path(const char *path, struct imv_source **src) return BACKEND_SUCCESS; } -static void backend_free(struct imv_backend *backend) -{ - free(backend); -} +const struct imv_backend libpng_backend = { + .name = "libpng", + .description = "The official PNG reference implementation", + .website = "http://www.libpng.org/pub/png/libpng.html", + .license = "The libpng license", + .open_path = &open_path, +}; -struct imv_backend *imv_backend_libpng(void) +const struct imv_backend *imv_backend_libpng(void) { - struct imv_backend *backend = malloc(sizeof(struct imv_backend)); - backend->name = "libpng (libpng/zlib license)"; - backend->open_path = &open_path; - backend->free = &backend_free; - return backend; + return &libpng_backend; } #else -struct imv_backend *imv_backend_libpng(void) +const struct imv_backend *imv_backend_libpng(void) { return NULL; } diff --git a/src/backend_libpng.h b/src/backend_libpng.h index be0d0b5..7370576 100644 --- a/src/backend_libpng.h +++ b/src/backend_libpng.h @@ -4,6 +4,6 @@ struct imv_backend; /* Create an instance of the libpng backend */ -struct imv_backend *imv_backend_libpng(void); +const struct imv_backend *imv_backend_libpng(void); #endif diff --git a/src/backend_librsvg.c b/src/backend_librsvg.c index 416743a..acadb25 100644 --- a/src/backend_librsvg.c +++ b/src/backend_librsvg.c @@ -130,23 +130,22 @@ static enum backend_result open_path(const char *path, struct imv_source **src) return BACKEND_SUCCESS; } -static void backend_free(struct imv_backend *backend) +const struct imv_backend librsvg_backend = { + .name = "libRSVG", + .description = "SVG library developed by GNOME", + .website = "https://wiki.gnome.org/Projects/LibRsvg", + .license = "Lesser GNU Public License", + .open_path = &open_path, +}; + +const struct imv_backend *imv_backend_librsvg(void) { - free(backend); -} - -struct imv_backend *imv_backend_librsvg(void) -{ - struct imv_backend *backend = malloc(sizeof(struct imv_backend)); - backend->name = "librsvg (LGPL license)"; - backend->open_path = &open_path; - backend->free = &backend_free; - return backend; + return &librsvg_backend; } #else -struct imv_backend *imv_backend_librsvg(void) +const struct imv_backend *imv_backend_librsvg(void) { return NULL; } diff --git a/src/backend_librsvg.h b/src/backend_librsvg.h index 16dd6c8..b62aa85 100644 --- a/src/backend_librsvg.h +++ b/src/backend_librsvg.h @@ -4,6 +4,6 @@ struct imv_backend; /* Create an instance of the rsvg backend */ -struct imv_backend *imv_backend_librsvg(void); +const struct imv_backend *imv_backend_librsvg(void); #endif @@ -54,7 +54,7 @@ enum background_type { }; struct backend_chain { - struct imv_backend *backend; + const struct imv_backend *backend; struct backend_chain *next; }; @@ -288,7 +288,6 @@ struct imv *imv_create(void) imv->font_name = strdup("Monospace:24"); imv->binds = imv_binds_create(); imv->navigator = imv_navigator_create(); - imv->backends = NULL; imv->source = NULL; imv->last_source = NULL; @@ -372,20 +371,14 @@ void imv_free(struct imv *imv) free(imv->overlay_text); imv_binds_free(imv->binds); imv_navigator_free(imv->navigator); - - struct backend_chain *chain = imv->backends; - while (chain) { - struct backend_chain *next_backend = chain->next; - chain->backend->free(chain->backend); - chain = next_backend; - } - if (imv->source) { imv->source->free(imv->source); } imv_commands_free(imv->commands); imv_viewport_free(imv->view); - imv_image_free(imv->image); + if (imv->image) { + imv_image_free(imv->image); + } if (imv->next_frame) { imv_bitmap_free(imv->next_frame); } @@ -416,7 +409,7 @@ void imv_free(struct imv *imv) free(imv); } -void imv_install_backend(struct imv *imv, struct imv_backend *backend) +void imv_install_backend(struct imv *imv, const struct imv_backend *backend) { struct backend_chain *chain = malloc(sizeof(struct backend_chain)); chain->backend = backend; @@ -528,6 +521,33 @@ static int load_paths_from_stdin(void *data) return 0; } +static void print_help(struct imv *imv) +{ + printf("imv %s\nSee manual for usage information.\n", IMV_VERSION); + puts("This version of imv has been compiled with the following backends:\n"); + + for (struct backend_chain *chain = imv->backends; + chain; + chain = chain->next) { + printf("Name: %s\n" + "Description: %s\n" + "Website: %s\n" + "License: %s\n\n", + chain->backend->name, + chain->backend->description, + chain->backend->website, + chain->backend->license); + } + + puts("Legal:\n" + "imv's full source code is published under the terms of the MIT\n" + "license, and can be found at https://github.com/eXeC64/imv\n" + "\n" + "imv uses the inih library to parse ini files.\n" + "See https://github.com/benhoyt/inih for details.\n" + "inih is used under the New (3-clause) BSD license."); +} + bool imv_parse_args(struct imv *imv, int argc, char **argv) { /* Do not print getopt errors */ @@ -544,22 +564,7 @@ bool imv_parse_args(struct imv *imv, int argc, char **argv) case 'l': imv->list_files_at_exit = true; break; case 'n': imv->starting_path = optarg; break; case 'h': - fprintf(stdout, - "imv %s\n" - "See manual for usage information.\n" - "\n" - "Legal:\n" - "imv's full source code is published under the terms of the MIT\n" - "license, and can be found at https://github.com/eXeC64/imv\n" - "\n" - "imv uses the FreeImage open source image library.\n" - "See http://freeimage.sourceforge.net for details.\n" - "FreeImage is used under the FIPL License v1.0.\n" - "\n" - "imv uses the inih library to parse ini files.\n" - "See https://github.com/benhoyt/inih for details.\n" - "inih is used under the New (3-clause) BSD license.\n" - , IMV_VERSION); + print_help(imv); imv->quit = true; return true; case 's': @@ -707,7 +712,7 @@ int imv_run(struct imv *imv) fprintf(stderr, "No backends installed. Unable to load image.\n"); } for (struct backend_chain *chain = imv->backends; chain; chain = chain->next) { - struct imv_backend *backend = chain->backend; + const struct imv_backend *backend = chain->backend; result = backend->open_path(current_path, &new_source); if (result == BACKEND_UNSUPPORTED) { /* Try the next backend */ @@ -10,7 +10,7 @@ struct imv *imv_create(void); void imv_free(struct imv *imv); /* Used in reverse addition order. Most recently added is the first used. */ -void imv_install_backend(struct imv *imv, struct imv_backend *backend); +void imv_install_backend(struct imv *imv, const struct imv_backend *backend); bool imv_load_config(struct imv *imv); bool imv_parse_args(struct imv *imv, int argc, char **argv); |