void init_parse_options(int argc, char **argv) { /* TODO: sort these to match declaration of __fehoptions */ /* For setting the command hint on X windows */ cmdargc = argc; cmdargv = argv; /* Set default options */ memset(&opt, 0, sizeof(fehoptions)); opt.display = 1; opt.aspect = 1; opt.slideshow_delay = 0.0; opt.magick_timeout = -1; opt.thumb_w = 60; opt.thumb_h = 60; opt.thumb_redraw = 10; opt.menu_font = estrdup(DEFAULT_MENU_FONT); opt.font = NULL; opt.menu_bg = estrdup(PREFIX "/share/feh/images/menubg_default.png"); opt.max_height = opt.max_width = UINT_MAX; opt.start_list_at = NULL; opt.jump_on_resort = 1; opt.screen_clip = 1; #ifdef HAVE_LIBXINERAMA /* if we're using xinerama, then enable it by default */ opt.xinerama = 1; #endif /* HAVE_LIBXINERAMA */ feh_getopt_theme(argc, argv); 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, 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 here, as files specified on the commandline end up at the *end* of the combined filelist, in the specified order. */ D(("About to load filelist from file\n")); filelist = gib_list_cat(filelist, feh_read_filelist(opt.filelistfile)); } D(("Options parsed\n")); filelist_len = gib_list_length(filelist); if (!filelist_len) show_mini_usage(); check_options(); feh_prepare_filelist(); return; }
/* FIXME This function is a crufty bitch ;) */ static void feh_parse_options_from_string(char *opts) { char *list[sizeof(char *) * 64]; int num = 0; char *s; char *t; char last = 0; int 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[num++] = estrdup(PACKAGE); for (s = opts, t = opts;; t++) { 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[num - 1] = feh_string_normalize(s); s = t + 1; } else if (*t == '\0') { num++; list[num - 1] = feh_string_normalize(s); break; } else if (((*t == '\"') || (*t == '\'')) && last != '\\') inquote = !(inquote); last = *t; } feh_parse_option_array(num, list, 0); for (i = 0; i < num; i++) if (list[i]) free(list[i]); return; }