diff options
Diffstat (limited to 'src/options.c')
-rw-r--r-- | src/options.c | 189 |
1 files changed, 98 insertions, 91 deletions
diff --git a/src/options.c b/src/options.c index 2206f3e..de72429 100644 --- a/src/options.c +++ b/src/options.c @@ -1,6 +1,7 @@ /* options.c Copyright (C) 1999-2003 Tom Gilbert. +Copyright (C) 2010-2011 Daniel Friesel. Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to @@ -28,9 +29,8 @@ CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. #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_getopt_theme(int argc, char **argv); +static void feh_parse_option_array(int argc, char **argv, int finalrun); static void feh_check_theme_options(int arg, char **argv); static void feh_parse_options_from_string(char *opts); static void feh_load_options_for_theme(char *theme); @@ -80,8 +80,6 @@ void init_parse_options(int argc, char **argv) opt.start_list_at = NULL; opt.jump_on_resort = 1; - opt.builtin_http = 0; - opt.xinerama = 0; opt.screen_clip = 1; #ifdef HAVE_LIBXINERAMA @@ -89,17 +87,15 @@ void init_parse_options(int argc, char **argv) opt.xinerama = 1; #endif /* HAVE_LIBXINERAMA */ - 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 parse commandline options\n")); - /* Parse the cmdline args */ - feh_parse_option_array(argc, argv); + feh_getopt_theme(argc, argv); D(("About to check for theme configuration\n")); feh_check_theme_options(argc, argv); + D(("About to parse commandline options\n")); + /* Parse the cmdline args */ + feh_parse_option_array(argc, argv, 1); + /* If we have a filelist to read, do it now */ if (opt.filelistfile) { /* joining two reverse-sorted lists in this manner works nicely for us @@ -147,35 +143,38 @@ static void feh_check_theme_options(int arg, char **argv) 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"); 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; - } + if (!home) + eprintf("You have no HOME, cannot read themes"); - free(rcpath); - } + oldrcpath = estrjoin("/", home, ".fehrc", NULL); + + if (confbase) + rcpath = estrjoin("/", confbase, "feh/themes", NULL); + else + rcpath = estrjoin("/", home, ".config/feh/themes", 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);) { @@ -221,22 +220,6 @@ 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) { @@ -275,7 +258,7 @@ static void feh_parse_options_from_string(char *opts) last = *t; } - feh_parse_option_array(num, list); + feh_parse_option_array(num, list, 0); for (i = 0; i < num; i++) if (list[i]) @@ -317,11 +300,31 @@ 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) { 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:cC:dD:e:E:f:Fg:GhH:iIj:J:kK:lL:mM:nNo:O:pPqrR:sS:tT:uUvVwW:xXy:YzZ" + "0:1:2:4:5:8:9:.@:^:~:):|:+:"; /* (*name, has_arg, *flag, val) See: struct option in getopts.h */ static struct option lopts[] = { @@ -351,7 +354,6 @@ static void feh_parse_option_array(int argc, char **argv) {"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'}, @@ -396,7 +398,6 @@ static void feh_parse_option_array(int argc, char **argv) {"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}, @@ -422,11 +423,11 @@ static void feh_parse_option_array(int argc, char **argv) {"index-dim" , 1, 0, 232}, {"thumb-redraw" , 1, 0, 'J'}, {"info" , 1, 0, 234}, + {"force-aliasing", 0, 0, 235}, {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) { @@ -468,9 +469,6 @@ static void feh_parse_option_array(int argc, char **argv) opt.list = 1; opt.display = 0; break; - case 'Q': - opt.builtin_http = 1; - break; case 'L': opt.customlist = estrdup(optarg); opt.display = 0; @@ -522,7 +520,7 @@ static void feh_parse_option_array(int argc, char **argv) opt.full_screen = 1; break; case 'Z': - opt.auto_zoom = 1; + opt.zoom_mode = ZOOM_MODE_MAX; break; case 'U': opt.loadables = 1; @@ -591,9 +589,6 @@ static void feh_parse_option_array(int argc, char **argv) opt.bg = 1; opt.bg_file = estrdup(optarg); break; - case '_': - opt.rcfile = estrdup(optarg); - break; case 'A': opt.actions[0] = estrdup(optarg); break; @@ -612,6 +607,7 @@ static void feh_parse_option_array(int argc, char **argv) case ')': free(opt.menu_bg); opt.menu_bg = estrdup(optarg); + weprintf("The --menu-bg option is deprecated and will be removed by 2012"); break; case 'B': free(opt.image_bg); @@ -693,9 +689,15 @@ static void feh_parse_option_array(int argc, char **argv) case 204: free(opt.menu_style); opt.menu_style = estrdup(optarg); + weprintf("The --menu-style option is deprecated and will be removed by 2012"); break; case 205: - opt.default_zoom = atoi(optarg); + 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 206: opt.screen_clip = 0; @@ -772,6 +774,9 @@ static void feh_parse_option_array(int argc, char **argv) case 234: opt.info_cmd = estrdup(optarg); break; + case 235: + opt.force_aliasing = 1; + break; default: break; } @@ -785,13 +790,8 @@ static void feh_parse_option_array(int argc, char **argv) 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) + add_file_to_filelist_recursively(".", FILELIST_FIRST); /* So that we can safely be called again */ optind = 1; @@ -800,6 +800,14 @@ static void feh_parse_option_array(int argc, char **argv) static void check_options(void) { + int i; + 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]; + } + } + if ((opt.index + opt.collage) > 1) { weprintf("you can't use collage mode and index mode together.\n" " I'm going with index"); @@ -843,7 +851,23 @@ 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_LIBXINERAMA + "xinerama " +#endif + + ); + exit(0); } @@ -861,20 +885,3 @@ static void show_usage(void) , 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; -} |