diff options
Diffstat (limited to 'src/options.c')
-rw-r--r-- | src/options.c | 1068 |
1 files changed, 608 insertions, 460 deletions
diff --git a/src/options.c b/src/options.c index 2206f3e..d38ce45 100644 --- a/src/options.c +++ b/src/options.c @@ -1,6 +1,7 @@ /* options.c Copyright (C) 1999-2003 Tom Gilbert. +Copyright (C) 2010-2024 Birte Kristina Friesel. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -23,15 +24,15 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */ +#include <strings.h> #include "feh.h" #include "filelist.h" #include "options.h" static void check_options(void); -static void feh_create_default_config(char *rcfile); -static void feh_parse_option_array(int argc, char **argv); -static void feh_parse_environment_options(void); -static void feh_check_theme_options(int arg, char **argv); +static void feh_getopt_theme(int argc, char **argv); +static void feh_parse_option_array(int argc, char **argv, int finalrun); +static void feh_check_theme_options(char **argv); static void feh_parse_options_from_string(char *opts); static void feh_load_options_for_theme(char *theme); static void show_usage(void); @@ -53,52 +54,40 @@ void init_parse_options(int argc, char **argv) opt.display = 1; opt.aspect = 1; opt.slideshow_delay = 0.0; + opt.conversion_timeout = -1; opt.thumb_w = 60; opt.thumb_h = 60; opt.thumb_redraw = 10; + opt.scroll_step = 20; opt.menu_font = estrdup(DEFAULT_MENU_FONT); opt.font = NULL; - opt.image_bg = estrdup("default"); - opt.menu_bg = estrdup(PREFIX "/share/feh/images/menubg_default.png"); - opt.menu_style = estrdup(PREFIX "/share/feh/fonts/menu.style"); + opt.max_height = opt.max_width = UINT_MAX; - opt.reload_button = 0; - opt.pan_button = 1; - opt.zoom_button = 2; - opt.menu_button = 3; - opt.menu_ctrl_mask = 0; - opt.prev_button = 4; - opt.next_button = 5; - - opt.draw_actions = 0; - - opt.rotate_button = 2; - opt.no_rotate_ctrl_mask = 0; - opt.blur_button = 1; - opt.no_blur_ctrl_mask = 0; + opt.zoom_rate = 1.25; opt.start_list_at = NULL; opt.jump_on_resort = 1; - opt.builtin_http = 0; - - opt.xinerama = 0; opt.screen_clip = 1; + opt.cache_size = 4; #ifdef HAVE_LIBXINERAMA /* if we're using xinerama, then enable it by default */ opt.xinerama = 1; + opt.xinerama_index = -1; #endif /* HAVE_LIBXINERAMA */ +#ifdef HAVE_INOTIFY + opt.auto_reload = 1; +#endif /* HAVE_INOTIFY */ + opt.use_conversion_cache = 1; + + feh_getopt_theme(argc, argv); - D(("About to parse env options (if any)\n")); - /* Check for and parse any options in FEH_OPTIONS */ - feh_parse_environment_options(); + D(("About to check for theme configuration\n")); + feh_check_theme_options(argv); D(("About to parse commandline options\n")); /* Parse the cmdline args */ - feh_parse_option_array(argc, argv); - - D(("About to check for theme configuration\n")); - feh_check_theme_options(argc, argv); + feh_parse_option_array(argc, argv, 1); /* If we have a filelist to read, do it now */ if (opt.filelistfile) { @@ -111,9 +100,6 @@ void init_parse_options(int argc, char **argv) D(("Options parsed\n")); - if (opt.bgmode) - return; - filelist_len = gib_list_length(filelist); if (!filelist_len) show_mini_usage(); @@ -124,7 +110,7 @@ void init_parse_options(int argc, char **argv) return; } -static void feh_check_theme_options(int arg, char **argv) +static void feh_check_theme_options(char **argv) { if (!theme) { /* This prevents screw up when running src/feh or ./feh */ @@ -141,53 +127,65 @@ static void feh_check_theme_options(int arg, char **argv) free(theme); return; - arg = 0; } static void feh_load_options_for_theme(char *theme) { FILE *fp = NULL; - char *home; + char *home = getenv("HOME"); char *rcpath = NULL; + char *oldrcpath = NULL; + char *confbase = getenv("XDG_CONFIG_HOME"); + // s, s1 and s2 must always have identical size char s[1024], s1[1024], s2[1024]; int cont = 0; int bspos; - if (opt.rcfile) { - if ((fp = fopen(opt.rcfile, "r")) == NULL) { - weprintf("couldn't load the specified rcfile %s\n", opt.rcfile); - return; - } - } else { - home = getenv("HOME"); - if (!home) - eprintf("D'oh! Please define HOME in your environment! " - "It would really help me out...\n"); - rcpath = estrjoin("/", home, ".fehrc", NULL); - D(("Trying %s for config\n", rcpath)); - fp = fopen(rcpath, "r"); - - if (!fp && ((fp = fopen("/etc/fehrc", "r")) == NULL)) { - feh_create_default_config(rcpath); - - if ((fp = fopen(rcpath, "r")) == NULL) - return; - } - - free(rcpath); + if (confbase) + rcpath = estrjoin("/", confbase, "feh/themes", NULL); + else if (home) + rcpath = estrjoin("/", home, ".config/feh/themes", NULL); + else { + weprintf("You have no HOME, cannot read configuration"); + return; } + oldrcpath = estrjoin("/", home, ".fehrc", NULL); + + fp = fopen(rcpath, "r"); + + free(rcpath); + + if (!fp && ((fp = fopen(oldrcpath, "r")) != NULL)) + weprintf("The theme config file was moved from ~/.fehrc to " + "~/.config/feh/themes. Run\n" + " mkdir -p ~/.config/feh; mv ~/.fehrc ~/.config/feh/themes\n" + "to fix this."); + + free(oldrcpath); + + if (!fp && ((fp = fopen("/etc/feh/themes", "r")) == NULL)) + return; + /* Oooh. We have an options file :) */ for (; fgets(s, sizeof(s), fp);) { s1[0] = '\0'; s2[0] = '\0'; if (cont) { + /* + * fgets ensures that s contains no more than 1023 characters + * (+ 1 null byte) + */ sscanf(s, " %[^\n]\n", (char *) &s2); if (!*s2) break; D(("Got continued options %s\n", s2)); } else { + /* + * fgets ensures that s contains no more than 1023 characters + * (+ 1 null byte) + */ sscanf(s, "%s %[^\n]\n", (char *) &s1, (char *) &s2); if (!(*s1) || (!*s2) || (*s1 == '\n') || (*s1 == '#')) { cont = 0; @@ -221,67 +219,52 @@ static void feh_load_options_for_theme(char *theme) return; } -static void feh_parse_environment_options(void) -{ - char *opts; - - if ((opts = getenv("FEH_OPTIONS")) == NULL) - return; - - weprintf - ("The FEH_OPTIONS configuration method is depreciated and will soon die.\n" - "Use the .fehrc configuration file instead."); - - /* We definitely have some options to parse */ - feh_parse_options_from_string(opts); - return; -} - /* FIXME This function is a crufty bitch ;) */ static void feh_parse_options_from_string(char *opts) { - char **list = NULL; + char *list[sizeof(char *) * 64]; int num = 0; char *s; char *t; char last = 0; - int inquote = 0; + char inquote = 0; int i = 0; /* So we don't reinvent the wheel (not again, anyway), we use the getopt_long function to do this parsing as well. This means it has to look like the real argv ;) */ - list = malloc(sizeof(char *)); - list[num++] = estrdup(PACKAGE); for (s = opts, t = opts;; t++) { - if ((*t == ' ') && !(inquote)) { + + if (num > 64) + eprintf(PACKAGE " does not support more than 64 words per " + "theme definition.\n Please shorten your lines."); + + if ((*t == ' ') && !inquote) { *t = '\0'; num++; - list = erealloc(list, sizeof(char *) * num); list[num - 1] = feh_string_normalize(s); s = t + 1; } else if (*t == '\0') { num++; - list = erealloc(list, sizeof(char *) * num); list[num - 1] = feh_string_normalize(s); break; - } else if (*t == '\"' && last != '\\') - inquote = !(inquote); + } else if ((*t == inquote) && (last != '\\')) { + inquote = 0; + } else if (((*t == '\"') || (*t == '\'')) && (last != '\\') && !inquote) + inquote = *t; last = *t; } - feh_parse_option_array(num, list); + feh_parse_option_array(num, list, 0); for (i = 0; i < num; i++) if (list[i]) free(list[i]); - if (list) - free(list); return; } @@ -301,6 +284,9 @@ char *feh_string_normalize(char *str) else if ((*s == '\"') && (last == '\\')) ret[i++] = '\"'; else if ((*s == '\"') && (last == 0)); + else if ((*s == '\'') && (last == '\\')) + ret[i++] = '\''; + else if ((*s == '\'') && (last == 0)); else if ((*s == ' ') && (last == '\\')) ret[i++] = ' '; else @@ -308,7 +294,7 @@ char *feh_string_normalize(char *str) last = *s; } - if (i && ret[i - 1] == '\"') + if (i && ((ret[i - 1] == '\"') || (ret[i - 1] == '\''))) ret[i - 1] = '\0'; else ret[i] = '\0'; @@ -317,232 +303,249 @@ char *feh_string_normalize(char *str) return(estrdup(ret)); } -static void feh_parse_option_array(int argc, char **argv) +static void feh_getopt_theme(int argc, char **argv) +{ + static char stropts[] = "-T:"; + static struct option lopts[] = { + {"theme", 1, 0, 'T'}, + {0, 0, 0, 0} + }; + int optch = 0, cmdx = 0; + + opterr = 0; + + while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != EOF) { + if (optch == 'T') + theme = estrdup(optarg); + } + + opterr = 1; + optind = 0; +} + +static void feh_parse_option_array(int argc, char **argv, int finalrun) { + int discard; static char stropts[] = - "a:A:b:B:cC:dD:e:E:f:Fg:GhH:iIj:J:kK:lL:mM:nNo:O:pPqQrR:sS:tT:uUvVwW:xXy:YzZ" - "0:1:2:4:5:8:9:.@:^:~:):|:_:+:"; + "a:A:b:B:C:dD:e:E:f:Fg:GhH:iIj:J:kK:lL:mM:nNo:O:pPqrR:sS:tT:uUvVwW:xXy:YzZ" + ".@:^:~:|:+:<:>:"; /* (*name, has_arg, *flag, val) See: struct option in getopts.h */ static struct option lopts[] = { - {"help" , 0, 0, 'h'}, - {"version" , 0, 0, 'v'}, - {"montage" , 0, 0, 'm'}, - {"collage" , 0, 0, 'c'}, - {"index" , 0, 0, 'i'}, - {"fullindex" , 0, 0, 'I'}, - {"verbose" , 0, 0, 'V'}, - {"borderless" , 0, 0, 'x'}, - {"keep-http" , 0, 0, 'k'}, - {"stretch" , 0, 0, 's'}, - {"multiwindow" , 0, 0, 'w'}, - {"recursive" , 0, 0, 'r'}, - {"randomize" , 0, 0, 'z'}, - {"list" , 0, 0, 'l'}, - {"quiet" , 0, 0, 'q'}, - {"loadable" , 0, 0, 'U'}, - {"unloadable" , 0, 0, 'u'}, - {"no-menus" , 0, 0, 'N'}, - {"full-screen" , 0, 0, 'F'}, /* deprecated */ - {"fullscreen" , 0, 0, 'F'}, - {"auto-zoom" , 0, 0, 'Z'}, - {"ignore-aspect" , 0, 0, 'X'}, - {"draw-filename" , 0, 0, 'd'}, - {"preload" , 0, 0, 'p'}, - {"reverse" , 0, 0, 'n'}, - {"thumbnails" , 0, 0, 't'}, - {"builtin" , 0, 0, 'Q'}, - {"scale-down" , 0, 0, '.'}, - {"no-jump-on-resort", 0, 0, 220}, - {"hide-pointer" , 0, 0, 'Y'}, - {"draw-actions" , 0, 0, 'G'}, - {"cache-thumbnails", 0, 0, 'P'}, - {"cycle-once" , 0, 0, 224}, - {"no-xinerama" , 0, 0, 225}, - {"no-rotate-ctrl-mask", 0, 0, 226}, - {"no-blur-ctrl-mask", 0, 0, 227}, - {"menu-ctrl-mask", 0, 0, 228}, - - {"output" , 1, 0, 'o'}, - {"output-only" , 1, 0, 'O'}, - {"action" , 1, 0, 'A'}, - {"limit-width" , 1, 0, 'W'}, - {"limit-height" , 1, 0, 'H'}, - {"reload" , 1, 0, 'R'}, - {"alpha" , 1, 0, 'a'}, - {"sort" , 1, 0, 'S'}, - {"theme" , 1, 0, 'T'}, - {"filelist" , 1, 0, 'f'}, - {"customlist" , 1, 0, 'L'}, - {"geometry" , 1, 0, 'g'}, - {"menu-font" , 1, 0, 'M'}, - {"thumb-width" , 1, 0, 'y'}, - {"thumb-height" , 1, 0, 'E'}, - {"slideshow-delay",1, 0, 'D'}, - {"font" , 1, 0, 'e'}, - {"title-font" , 1, 0, '@'}, - {"title" , 1, 0, '^'}, - {"thumb-title" , 1, 0, '~'}, - {"bg" , 1, 0, 'b'}, - {"fontpath" , 1, 0, 'C'}, - {"menu-bg" , 1, 0, ')'}, - {"image-bg" , 1, 0, 'B'}, - {"reload-button" , 1, 0, '0'}, - {"pan-button" , 1, 0, '1'}, - {"zoom-button" , 1, 0, '2'}, - {"menu-button" , 1, 0, '3'}, - {"prev-button" , 1, 0, '4'}, - {"next-button" , 1, 0, '5'}, - {"rotate-button" , 1, 0, '8'}, - {"blur-button" , 1, 0, '9'}, - {"start-at" , 1, 0, '|'}, - {"rcfile" , 1, 0, '_'}, - {"debug" , 0, 0, '+'}, - {"output-dir" , 1, 0, 'j'}, - {"bg-tile" , 1, 0, 200}, - {"bg-center" , 1, 0, 201}, - {"bg-scale" , 1, 0, 202}, - {"menu-style" , 1, 0, 204}, - {"zoom" , 1, 0, 205}, - {"no-screen-clip", 0, 0, 206}, - {"caption-path" , 1, 0, 'K'}, - {"action1" , 1, 0, 209}, - {"action2" , 1, 0, 210}, - {"action3" , 1, 0, 211}, - {"action4" , 1, 0, 212}, - {"action5" , 1, 0, 213}, - {"action6" , 1, 0, 214}, - {"action7" , 1, 0, 215}, - {"action8" , 1, 0, 216}, - {"action9" , 1, 0, 217}, - {"bg-fill" , 1, 0, 218}, - {"bg-max" , 1, 0, 219}, - {"index-name" , 1, 0, 230}, - {"index-size" , 1, 0, 231}, - {"index-dim" , 1, 0, 232}, - {"thumb-redraw" , 1, 0, 'J'}, - {"info" , 1, 0, 234}, - + {"debug" , 0, 0, OPTION_debug}, + {"scale-down" , 0, 0, OPTION_scale_down}, + {"max-dimension" , 1, 0, OPTION_max_dimension}, + {"min-dimension" , 1, 0, OPTION_min_dimension}, + {"title-font" , 1, 0, OPTION_title_font}, + {"action" , 1, 0, OPTION_action}, + {"image-bg" , 1, 0, OPTION_image_bg}, + {"fontpath" , 1, 0, OPTION_fontpath}, + {"slideshow-delay",1, 0, OPTION_slideshow_delay}, + {"thumb-height" , 1, 0, OPTION_thumb_height}, + {"full-screen" , 0, 0, OPTION_fullscreen}, /* deprecated */ + {"fullscreen" , 0, 0, OPTION_fullscreen}, + {"draw-actions" , 0, 0, OPTION_draw_actions}, + {"limit-height" , 1, 0, OPTION_limit_height}, + {"fullindex" , 0, 0, OPTION_fullindex}, + {"thumb-redraw" , 1, 0, OPTION_thumb_redraw}, + {"caption-path" , 1, 0, OPTION_caption_path}, + {"customlist" , 1, 0, OPTION_customlist}, + {"menu-font" , 1, 0, OPTION_menu_font}, + {"no-menus" , 0, 0, OPTION_no_menus}, + {"output-only" , 1, 0, OPTION_output_only}, + {"cache-thumbnails", 0, 0, OPTION_cache_thumbnails}, + {"reload" , 1, 0, OPTION_reload}, + {"sort" , 1, 0, OPTION_sort}, + {"theme" , 1, 0, OPTION_theme}, + {"loadable" , 0, 0, OPTION_loadable}, + {"verbose" , 0, 0, OPTION_verbose}, + {"limit-width" , 1, 0, OPTION_limit_width}, + {"ignore-aspect" , 0, 0, OPTION_ignore_aspect}, + {"hide-pointer" , 0, 0, OPTION_hide_pointer}, + {"auto-zoom" , 0, 0, OPTION_auto_zoom}, + {"title" , 1, 0, OPTION_title}, + {"alpha" , 1, 0, OPTION_alpha}, + {"bg" , 1, 0, OPTION_bg}, + {"draw-filename" , 0, 0, OPTION_draw_filename}, + {"font" , 1, 0, OPTION_font}, + {"filelist" , 1, 0, OPTION_filelist}, + {"geometry" , 1, 0, OPTION_geometry}, + {"help" , 0, 0, OPTION_help}, + {"index" , 0, 0, OPTION_index}, + {"output-dir" , 1, 0, OPTION_output_dir}, + {"keep-http" , 0, 0, OPTION_keep_http}, + {"list" , 0, 0, OPTION_list}, + {"montage" , 0, 0, OPTION_montage}, + {"reverse" , 0, 0, OPTION_reverse}, + {"output" , 1, 0, OPTION_output}, + {"preload" , 0, 0, OPTION_preload}, + {"quiet" , 0, 0, OPTION_quiet}, + {"recursive" , 0, 0, OPTION_recursive}, + {"stretch" , 0, 0, OPTION_stretch}, + {"thumbnails" , 0, 0, OPTION_thumbnails}, + {"unloadable" , 0, 0, OPTION_unloadable}, + {"version" , 0, 0, OPTION_version}, + {"multiwindow" , 0, 0, OPTION_multiwindow}, + {"borderless" , 0, 0, OPTION_borderless}, + {"thumb-width" , 1, 0, OPTION_thumb_width}, + {"randomize" , 0, 0, OPTION_randomize}, + {"start-at" , 1, 0, OPTION_start_at}, + {"thumb-title" , 1, 0, OPTION_thumb_title}, + {"bg-tile" , 0, 0, OPTION_bg_title}, + {"bg-center" , 0, 0, OPTION_bg_center}, + {"bg-scale" , 0, 0, OPTION_bg_scale}, + {"zoom" , 1, 0, OPTION_zoom}, + {"zoom-step" , 1, 0, OPTION_zoom_step}, + {"no-screen-clip", 0, 0, OPTION_no_screen_clip}, + {"index-info" , 1, 0, OPTION_index_info}, + {"magick-timeout", 1, 0, OPTION_magick_timeout}, + {"action1" , 1, 0, OPTION_action1}, + {"action2" , 1, 0, OPTION_action2}, + {"action3" , 1, 0, OPTION_action3}, + {"action4" , 1, 0, OPTION_action4}, + {"action5" , 1, 0, OPTION_action5}, + {"action6" , 1, 0, OPTION_action6}, + {"action7" , 1, 0, OPTION_action7}, + {"action8" , 1, 0, OPTION_action8}, + {"action9" , 1, 0, OPTION_action9}, + {"bg-fill" , 0, 0, OPTION_bg_fill}, + {"bg-max" , 0, 0, OPTION_bg_max}, + {"no-jump-on-resort", 0, 0, OPTION_no_jump_on_resort}, + {"edit" , 0, 0, OPTION_edit}, +#ifdef HAVE_LIBEXIF + {"draw-exif" , 0, 0, OPTION_draw_exif}, + {"auto-rotate" , 0, 0, OPTION_auto_rotate}, +#endif + {"no-xinerama" , 0, 0, OPTION_no_xinerama}, + {"draw-tinted" , 0, 0, OPTION_draw_tinted}, + {"info" , 1, 0, OPTION_info}, + {"tap-zones" , 0, 0, OPTION_tap_zones}, + {"force-aliasing", 0, 0, OPTION_force_aliasing}, + {"no-fehbg" , 0, 0, OPTION_no_fehbg}, + {"keep-zoom-vp" , 0, 0, OPTION_keep_zoom_vp}, + {"scroll-step" , 1, 0, OPTION_scroll_step}, + {"xinerama-index", 1, 0, OPTION_xinerama_index}, + {"insecure" , 0, 0, OPTION_insecure}, + {"no-recursive" , 0, 0, OPTION_no_recursive}, + {"cache-size" , 1, 0, OPTION_cache_size}, + {"on-last-slide" , 1, 0, OPTION_on_last_slide}, + {"conversion-timeout" , 1, 0, OPTION_conversion_timeout}, + {"version-sort" , 0, 0, OPTION_version_sort}, + {"offset" , 1, 0, OPTION_offset}, +#ifdef HAVE_INOTIFY + {"auto-reload" , 0, 0, OPTION_auto_reload}, +#endif + {"class" , 1, 0, OPTION_class}, + {"no-conversion-cache", 0, 0, OPTION_no_conversion_cache}, + {"window-id", 1, 0, OPTION_window_id}, {0, 0, 0, 0} }; int optch = 0, cmdx = 0; - int i = 0; - /* Now to pass some optionarinos */ while ((optch = getopt_long(argc, argv, stropts, lopts, &cmdx)) != EOF) { D(("Got option, getopt calls it %d, or %c\n", optch, optch)); switch (optch) { case 0: break; - case 'h': - show_usage(); - break; - case 'v': - show_version(); - break; - case 'm': - opt.index = 1; - opt.index_show_name = 0; - opt.index_show_size = 0; - opt.index_show_dim = 0; + case OPTION_debug: + opt.debug = 1; break; - case 'c': - opt.collage = 1; + case OPTION_max_dimension: + opt.filter_by_dimensions = 1; + XParseGeometry(optarg, &discard, &discard, &opt.max_width, &opt.max_height); + if (opt.max_width == 0) + opt.max_width = UINT_MAX; + if (opt.max_height == 0) + opt.max_height = UINT_MAX; break; - case 'i': - opt.index = 1; - opt.index_show_name = 1; - opt.index_show_size = 0; - opt.index_show_dim = 0; + case OPTION_min_dimension: + opt.filter_by_dimensions = 1; + XParseGeometry(optarg, &discard, &discard, &opt.min_width, &opt.min_height); break; - case '.': + case OPTION_scale_down: opt.scale_down = 1; break; - case 'I': - opt.index = 1; - opt.index_show_name = 1; - opt.index_show_size = 1; - opt.index_show_dim = 1; - break; - case 'l': - opt.list = 1; - opt.display = 0; - break; - case 'Q': - opt.builtin_http = 1; - break; - case 'L': - opt.customlist = estrdup(optarg); - opt.display = 0; - break; - case 'M': - free(opt.menu_font); - opt.menu_font = estrdup(optarg); - break; - case '+': - opt.debug = 1; - break; - case 'n': - opt.reverse = 1; + case OPTION_title_font: + opt.title_font = estrdup(optarg); break; - case 'g': - opt.geom_flags = XParseGeometry(optarg, &opt.geom_x, &opt.geom_y, &opt.geom_w, &opt.geom_h); + case OPTION_action: + opt.actions[0] = estrdup(optarg); break; - case 'N': - opt.no_menus = 1; + case OPTION_image_bg: + opt.image_bg = estrdup(optarg); break; - case 'V': - opt.verbose = 1; + case OPTION_fontpath: + D(("adding fontpath %s\n", optarg)); + imlib_add_path_to_font_path(optarg); break; - case 'q': - opt.quiet = 1; + case OPTION_slideshow_delay: + opt.slideshow_delay = atof(optarg); + if (opt.slideshow_delay < 0.0) { + opt.slideshow_delay *= (-1); + opt.paused = 1; + } else { + opt.paused = 0; + } break; - case 'x': - opt.borderless = 1; + case OPTION_thumb_height: + opt.thumb_h = atoi(optarg); break; - case 'k': - opt.keep_http = 1; + case OPTION_fullscreen: + opt.full_screen = 1; break; - case 's': - opt.stretch = 1; + case OPTION_draw_actions: + opt.draw_actions = 1; break; - case 'w': - opt.multiwindow = 1; + case OPTION_limit_height: + opt.limit_h = atoi(optarg); break; - case 'r': - opt.recursive = 1; + case OPTION_fullindex: + opt.index = 1; + opt.index_info = estrdup("%n\n%S\n%wx%h"); break; - case 'z': - opt.randomize = 1; + case OPTION_thumb_redraw: + opt.thumb_redraw = atoi(optarg); break; - case 'd': - opt.draw_filename = 1; + case OPTION_caption_path: + opt.caption_path = estrdup(optarg); break; - case 'F': - opt.full_screen = 1; + case OPTION_customlist: + opt.customlist = estrdup(optarg); + opt.display = 0; break; - case 'Z': - opt.auto_zoom = 1; + case OPTION_menu_font: + free(opt.menu_font); + opt.menu_font = estrdup(optarg); break; - case 'U': - opt.loadables = 1; - opt.display = 0; + case OPTION_no_menus: + opt.no_menus = 1; break; - case 'u': - opt.unloadables = 1; + case OPTION_output_only: + opt.output = 1; + opt.output_file = estrdup(optarg); opt.display = 0; break; - case 'p': - opt.preload = 1; + case OPTION_cache_thumbnails: + opt.cache_thumbnails = 1; break; - case 'X': - opt.aspect = 0; + case OPTION_reload: + opt.reload = atof(optarg); + opt.use_conversion_cache = 0; +#ifdef HAVE_INOTIFY + opt.auto_reload = 0; +#endif break; - case 'S': + case OPTION_sort: if (!strcasecmp(optarg, "name")) opt.sort = SORT_NAME; + else if (!strcasecmp(optarg, "none")) + opt.sort = SORT_NONE; else if (!strcasecmp(optarg, "filename")) opt.sort = SORT_FILENAME; + else if (!strcasecmp(optarg, "dirname")) + opt.sort = SORT_DIRNAME; + else if (!strcasecmp(optarg, "mtime")) + opt.sort = SORT_MTIME; else if (!strcasecmp(optarg, "width")) opt.sort = SORT_WIDTH; else if (!strcasecmp(optarg, "height")) @@ -558,219 +561,304 @@ static void feh_parse_option_array(int argc, char **argv) "sort by filename", optarg); opt.sort = SORT_FILENAME; } + if (opt.randomize) { + weprintf("commandline contains --randomize and --sort. " + "--randomize has been unset"); + opt.randomize = 0; + } break; - case 'o': - opt.output = 1; - opt.output_file = estrdup(optarg); + case OPTION_theme: + theme = estrdup(optarg); break; - case 'O': - opt.output = 1; - opt.output_file = estrdup(optarg); + case OPTION_loadable: + opt.loadables = 1; opt.display = 0; break; - case 'T': - theme = estrdup(optarg); + case OPTION_verbose: + opt.verbose = 1; break; - case 'C': - D(("adding fontpath %s\n", optarg)); - imlib_add_path_to_font_path(optarg); + case OPTION_limit_width: + opt.limit_w = atoi(optarg); break; - case 'e': - opt.font = estrdup(optarg); + case OPTION_ignore_aspect: + opt.aspect = 0; break; - case '@': - opt.title_font = estrdup(optarg); + case OPTION_hide_pointer: + opt.hide_pointer = 1; + break; + case OPTION_auto_zoom: + opt.zoom_mode = ZOOM_MODE_MAX; break; - case '^': + case OPTION_title: opt.title = estrdup(optarg); break; - case '~': - opt.thumb_title = estrdup(optarg); + case OPTION_alpha: + opt.alpha = 1; + opt.alpha_level = 255 - atoi(optarg); break; - case 'b': + case OPTION_bg: opt.bg = 1; opt.bg_file = estrdup(optarg); break; - case '_': - opt.rcfile = estrdup(optarg); + case OPTION_draw_filename: + opt.draw_filename = 1; break; - case 'A': - opt.actions[0] = estrdup(optarg); + case OPTION_font: + opt.font = estrdup(optarg); break; - case 'W': - opt.limit_w = atoi(optarg); + case OPTION_filelist: + if (!strcmp(optarg, "-")) + opt.filelistfile = estrdup("/dev/stdin"); + else + opt.filelistfile = estrdup(optarg); break; - case 'H': - opt.limit_h = atoi(optarg); + case OPTION_geometry: + opt.geom_enabled = 1; + opt.geom_flags = XParseGeometry(optarg, &opt.geom_x, + &opt.geom_y, &opt.geom_w, &opt.geom_h); break; - case 'y': - opt.thumb_w = atoi(optarg); + case OPTION_help: + show_usage(); break; - case 'E': - opt.thumb_h = atoi(optarg); + case OPTION_index: + opt.index = 1; + opt.index_info = estrdup("%n"); break; - case ')': - free(opt.menu_bg); - opt.menu_bg = estrdup(optarg); + case OPTION_output_dir: + opt.output_dir = estrdup(optarg); break; - case 'B': - free(opt.image_bg); - opt.image_bg = estrdup(optarg); + case OPTION_keep_http: + opt.keep_http = 1; break; - case 'D': - opt.slideshow_delay = atof(optarg); - if (opt.slideshow_delay < 0.0) { - opt.slideshow_delay *= (-1); - opt.paused = 1; - } + case OPTION_list: + opt.list = 1; + opt.display = 0; break; - case 'R': - opt.reload = atoi(optarg); + case OPTION_montage: + opt.index = 1; break; - case 'a': - opt.alpha = 1; - opt.alpha_level = 255 - atoi(optarg); + case OPTION_reverse: + opt.reverse = 1; break; - case 'f': - opt.filelistfile = estrdup(optarg); + case OPTION_output: + opt.output = 1; + opt.output_file = estrdup(optarg); break; - case '0': - opt.reload_button = atoi(optarg); + case OPTION_preload: + opt.preload = 1; break; - case '1': - opt.pan_button = atoi(optarg); + case OPTION_quiet: + opt.quiet = 1; break; - case '2': - opt.zoom_button = atoi(optarg); + case OPTION_recursive: + opt.recursive = 1; break; - case '3': - opt.menu_button = atoi(optarg); + case OPTION_stretch: + opt.stretch = 1; break; - case '4': - opt.prev_button = atoi(optarg); + case OPTION_thumbnails: + opt.thumbs = 1; + opt.index_info = estrdup("%n"); break; - case '5': - opt.next_button = atoi(optarg); + case OPTION_unloadable: + opt.unloadables = 1; + opt.display = 0; break; - case '8': - opt.rotate_button = atoi(optarg); + case OPTION_version: + show_version(); break; - case '9': - opt.blur_button = atoi(optarg); + case OPTION_multiwindow: + opt.multiwindow = 1; break; - case '|': - opt.start_list_at = estrdup(optarg); + case OPTION_borderless: + opt.borderless = 1; break; - case 't': - opt.thumbs = 1; - opt.index_show_name = 1; - opt.index_show_size = 0; - opt.index_show_dim = 0; + case OPTION_thumb_width: + opt.thumb_w = atoi(optarg); break; - case 'j': - opt.output_dir = estrdup(optarg); + case OPTION_randomize: + opt.randomize = 1; + if (opt.sort != SORT_NONE) { + weprintf("commandline contains --sort and --randomize. " + "--sort has been unset"); + opt.sort = SORT_NONE; + } + break; + case OPTION_start_at: + opt.start_list_at = estrdup(optarg); + break; + case OPTION_thumb_title: + opt.thumb_title = estrdup(optarg); break; - case 200: + case OPTION_bg_title: opt.bgmode = BG_MODE_TILE; - opt.output_file = estrdup(optarg); break; - case 201: + case OPTION_bg_center: opt.bgmode = BG_MODE_CENTER; - opt.output_file = estrdup(optarg); break; - case 202: + case OPTION_bg_scale: opt.bgmode = BG_MODE_SCALE; - opt.output_file = estrdup(optarg); - break; - case 218: - opt.bgmode = BG_MODE_FILL; - opt.output_file = estrdup(optarg); - break; - case 219: - opt.bgmode = BG_MODE_MAX; - opt.output_file = estrdup(optarg); break; - case 204: - free(opt.menu_style); - opt.menu_style = estrdup(optarg); + case OPTION_zoom: + if (!strcmp("fill", optarg)) + opt.zoom_mode = ZOOM_MODE_FILL; + else if (!strcmp("max", optarg)) + opt.zoom_mode = ZOOM_MODE_MAX; + else + opt.default_zoom = atoi(optarg); break; - case 205: - opt.default_zoom = atoi(optarg); - break; - case 206: + case OPTION_no_screen_clip: opt.screen_clip = 0; break; - case 'K': - opt.caption_path = estrdup(optarg); + case OPTION_index_info: + opt.index_info = estrdup(optarg); break; - case 209: + case OPTION_magick_timeout: + weprintf("--magick-timeout is deprecated, please use --conversion-timeout instead"); + opt.conversion_timeout = atoi(optarg); + break; + case OPTION_action1: opt.actions[1] = estrdup(optarg); break; - case 210: + case OPTION_action2: opt.actions[2] = estrdup(optarg); break; - case 211: + case OPTION_action3: opt.actions[3] = estrdup(optarg); break; - case 212: + case OPTION_action4: opt.actions[4] = estrdup(optarg); break; - case 213: + case OPTION_action5: opt.actions[5] = estrdup(optarg); break; - case 214: + case OPTION_action6: opt.actions[6] = estrdup(optarg); break; - case 215: + case OPTION_action7: opt.actions[7] = estrdup(optarg); break; - case 216: + case OPTION_action8: opt.actions[8] = estrdup(optarg); break; - case 217: + case OPTION_action9: opt.actions[9] = estrdup(optarg); break; - case 220: - opt.jump_on_resort = 0; + case OPTION_bg_fill: + opt.bgmode = BG_MODE_FILL; break; - case 'Y': - opt.hide_pointer = 1; + case OPTION_bg_max: + opt.bgmode = BG_MODE_MAX; break; - case 'G': - opt.draw_actions = 1; + case OPTION_no_jump_on_resort: + opt.jump_on_resort = 0; break; - case 'P': - opt.cache_thumbnails = 1; + case OPTION_edit: + opt.edit = 1; + break; +#ifdef HAVE_LIBEXIF + case OPTION_draw_exif: + opt.draw_exif = 1; break; - case 224: - opt.cycle_once = 1; + case OPTION_auto_rotate: +#if defined(IMLIB2_VERSION_MAJOR) && defined(IMLIB2_VERSION_MINOR) && defined(IMLIB2_VERSION_MICRO) && (IMLIB2_VERSION_MAJOR > 1 || IMLIB2_VERSION_MINOR > 7 || IMLIB2_VERSION_MICRO >= 5) + weprintf("This feh release was built with Imlib2 version %d.%d.%d, which transparently adjusts for image orientation according to EXIF data.", IMLIB2_VERSION_MAJOR, IMLIB2_VERSION_MINOR, IMLIB2_VERSION_MICRO); + weprintf("--auto-rotate would rotate an already correctly oriented image, resulting in incorrect orientation. It has been disabled in this build. Rebuild feh with Imlib2 <1.7.5 to enable --auto-rotate."); +#else + opt.auto_rotate = 1; +#endif break; - case 225: +#endif + case OPTION_no_xinerama: opt.xinerama = 0; break; - case 226: - opt.no_rotate_ctrl_mask = 1; + case OPTION_draw_tinted: + opt.text_bg = TEXT_BG_TINTED; break; - case 227: - opt.no_blur_ctrl_mask = 1; + case OPTION_info: + opt.info_cmd = estrdup(optarg); + if (opt.info_cmd[0] == ';') { + opt.draw_info = 0; + opt.info_cmd++; + } else { + opt.draw_info = 1; + } break; - case 228: - opt.menu_ctrl_mask = 1; + case OPTION_tap_zones: + opt.tap_zones = 1; break; - case 230: - opt.index_show_name = atoi(optarg); + case OPTION_force_aliasing: + opt.force_aliasing = 1; break; - case 231: - opt.index_show_size = atoi(optarg); + case OPTION_no_fehbg: + opt.no_fehbg = 1; break; - case 232: - opt.index_show_dim = atoi(optarg); + case OPTION_keep_zoom_vp: + opt.keep_zoom_vp = 1; break; - case 'J': - opt.thumb_redraw = atoi(optarg); + case OPTION_scroll_step: + opt.scroll_step = atoi(optarg); break; - case 234: - opt.info_cmd = estrdup(optarg); + case OPTION_xinerama_index: + opt.xinerama_index = atoi(optarg); + break; + case OPTION_insecure: + opt.insecure_ssl = 1; + break; + case OPTION_no_recursive: + opt.recursive = 0; + break; + case OPTION_cache_size: + opt.cache_size = atoi(optarg); + if (opt.cache_size < 0) + opt.cache_size = 0; + if (opt.cache_size > 2048) + opt.cache_size = 2048; + break; + case OPTION_on_last_slide: + if (!strcmp(optarg, "quit")) { + opt.on_last_slide = ON_LAST_SLIDE_QUIT; + } else if (!strcmp(optarg, "hold")) { + opt.on_last_slide = ON_LAST_SLIDE_HOLD; + } else if (!strcmp(optarg, "resume")) { + opt.on_last_slide = ON_LAST_SLIDE_RESUME; + } else { + weprintf("Unrecognized on-last-slide action \"%s\"." + "Supported actions: hold, resume, quit\n", optarg); + } + break; + case OPTION_conversion_timeout: + opt.conversion_timeout = atoi(optarg); + break; + case OPTION_version_sort: + opt.version_sort = 1; + break; + case OPTION_offset: + opt.offset_flags = XParseGeometry(optarg, &opt.offset_x, + &opt.offset_y, (unsigned int *)&discard, (unsigned int *)&discard); + break; +#ifdef HAVE_INOTIFY + case OPTION_auto_reload: + opt.auto_reload = 1; + break; +#endif + case OPTION_class: + opt.x11_class = estrdup(optarg); + break; + case OPTION_no_conversion_cache: + opt.use_conversion_cache = 0; + break; + case OPTION_window_id: + opt.x11_windowid = strtol(optarg, NULL, 0); + break; + case OPTION_zoom_step: + opt.zoom_rate = atof(optarg); + if ((opt.zoom_rate <= 0)) { + weprintf("Zooming disabled due to --zoom-step=%f", opt.zoom_rate); + opt.zoom_rate = 1.0; + } else { + opt.zoom_rate = 1 + ((float)opt.zoom_rate / 100); + } break; default: break; @@ -780,62 +868,90 @@ static void feh_parse_option_array(int argc, char **argv) /* Now the leftovers, which must be files */ if (optind < argc) { while (optind < argc) { + if (opt.reload) + original_file_items = gib_list_add_front(original_file_items, estrdup(argv[optind])); /* If recursive is NOT set, but the only argument is a directory name, we grab all the files in there, but not subdirs */ add_file_to_filelist_recursively(argv[optind++], FILELIST_FIRST); } } - - for (i = 0; i < 10; i++) { - if (opt.actions[i] && !opt.hold_actions[i] && (opt.actions[i][0] == ';')) { - opt.hold_actions[i] = 1; - opt.actions[i] = &opt.actions[i][1]; + else if (finalrun && !opt.filelistfile && !opt.bgmode) { + /* + * if --start-at is a non-local URL (i.e., does not start with file:///), + * behave as if "feh URL" was called (there is no directory we can load) + */ + if (opt.start_list_at && path_is_url(opt.start_list_at) && (strlen(opt.start_list_at) <= 8 || strncmp(opt.start_list_at, "file:///", 8) != 0)) { + add_file_to_filelist_recursively(opt.start_list_at, FILELIST_FIRST); + /* + * Otherwise, make "feh --start-at dir/file.jpg" behave like + * "feh --start-at dir/file.jpg dir". + */ + } else if (opt.start_list_at && strrchr(opt.start_list_at, '/')) { + /* + * feh can't candle urlencoded path components ("some%20dir" etc). + * Use libcurl to unescape them if --start-at is file://... + */ + if (strlen(opt.start_list_at) > 8 && strncmp(opt.start_list_at, "file:///", 8) == 0) { + char *unescaped_path = feh_http_unescape(opt.start_list_at); + if (unescaped_path != NULL) { + free(opt.start_list_at); + opt.start_list_at = estrdup(unescaped_path + 7); + free(unescaped_path); + } else { + char *new_path = estrdup(opt.start_list_at + 7); + free(opt.start_list_at); + opt.start_list_at = new_path; + } + } + char *target_directory = estrdup(opt.start_list_at); + char *filename_start = strrchr(target_directory, '/'); + if (filename_start) { + *filename_start = '\0'; + } + add_file_to_filelist_recursively(target_directory, FILELIST_FIRST); + original_file_items = gib_list_add_front(original_file_items, estrdup(target_directory)); + free(target_directory); + } else { + add_file_to_filelist_recursively(".", FILELIST_FIRST); } } /* So that we can safely be called again */ - optind = 1; + optind = 0; return; } static void check_options(void) { - if ((opt.index + opt.collage) > 1) { - weprintf("you can't use collage mode and index mode together.\n" - " I'm going with index"); - opt.collage = 0; - } + int i; + char *endptr; - if (opt.full_screen && opt.multiwindow) { - weprintf("you shouldn't combine multiwindow mode with full-screen mode,\n" - " Multiwindow mode has been disabled."); - opt.multiwindow = 0; + for (i = 0; i < 10; i++) { + if (opt.actions[i] && !opt.hold_actions[i] && (opt.actions[i][0] == ';')) { + opt.hold_actions[i] = 1; + opt.actions[i] = opt.actions[i] + 1; + } + opt.action_titles[i] = opt.actions[i]; + if (opt.actions[i] && (opt.actions[i][0] == '[')) { + if (((endptr = strchr(opt.actions[i], ']')) != NULL) + && (opt.actions[i][1] != ' ')) { + opt.action_titles[i] = opt.actions[i] + 1; + opt.actions[i] = endptr + 1; + *endptr = 0; + } + } } - if (opt.list && (opt.multiwindow || opt.index || opt.collage)) { - weprintf("list mode can't be combined with other processing modes,\n" - " list mode disabled."); - opt.list = 0; + if (opt.full_screen && opt.multiwindow) { + eprintf("You cannot combine --fullscreen with --multiwindow"); } - if (opt.sort && opt.randomize) { - weprintf("You cant sort AND randomize the filelist...\n" - "randomize mode has been unset\n"); - opt.randomize = 0; + if (opt.list && (opt.multiwindow || opt.index)) { + eprintf("You cannot combine --list with other modes"); } if (opt.loadables && opt.unloadables) { - weprintf("You cant show loadables AND unloadables...\n" - "you might as well use ls ;)\n" - "loadables only will be shown\n"); - opt.unloadables = 0; - } - - if (opt.thumb_title && (!opt.thumbs)) { - weprintf("Doesn't make sense to set thumbnail title when not in\n" - "thumbnail mode.\n"); - free(opt.thumb_title); - opt.thumb_title = NULL; + eprintf("You cannot combine --loadable with --unloadable"); } return; @@ -843,38 +959,70 @@ static void check_options(void) static void show_version(void) { - printf(PACKAGE " version " VERSION "\n"); + puts(PACKAGE " version " VERSION); + puts("Compile-time switches: " + +#ifdef HAVE_LIBCURL + "curl " +#endif + +#ifdef DEBUG + "debug " +#endif + +#ifdef HAVE_LIBEXIF + "exif " +#endif + +#ifdef HAVE_INOTIFY + "inotify " +#endif + +#ifdef INCLUDE_HELP + "help " +#endif + +#ifdef HAVE_LIBMAGIC + "magic " +#endif + +#if _FILE_OFFSET_BITS == 64 + "stat64 " +#endif + +#ifdef HAVE_STRVERSCMP + "verscmp " +#endif + +#ifdef HAVE_LIBXINERAMA + "xinerama " +#endif + + ); + exit(0); } void show_mini_usage(void) { - fprintf(stderr, PACKAGE " - No loadable images specified.\n" - "Use " PACKAGE " --help for detailed usage information\n"); + fputs(PACKAGE ": No loadable images specified.\n" +#ifdef INCLUDE_HELP + "See '" PACKAGE " --help' or 'man " PACKAGE "' for detailed usage information\n", +#else + "See 'man " PACKAGE "' for detailed usage information\n", +#endif + stderr); exit(1); } static void show_usage(void) { fputs( +#ifdef INCLUDE_HELP #include "help.inc" +#else + "See 'man " PACKAGE "'\n" +#endif , stdout); exit(0); } - -static void feh_create_default_config(char *rcfile) -{ - FILE *fp; - - if ((fp = fopen(rcfile, "w")) == NULL) { - weprintf("Unable to create default config file %s\n", rcfile); - return; - } - - fputs( -#include "fehrc.inc" - , fp); - fclose(fp); - - return; -} |