New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

separated short options in theme file #49

Closed
ze- opened this Issue Jun 5, 2011 · 3 comments

Comments

Projects
None yet
3 participants
@ze-

ze- commented Jun 5, 2011

if a theme (but not normal commandline) contains multiple separate short options (e.g. -x -d instead of -xd), feh gives errors and ignores the first argument specified on commandline, or segfaults if no arguments are specified.
for example:
theme: feh --scale-down -x -d
commandline: feh ~/img.jpg
result: the following errors, and loading all images in . while ignoring ~/img.jpg
feh: invalid option -- '�'
feh: invalid option -- ''

experienced with 1.14.1

@ghost ghost assigned derf Jun 5, 2011

@derf

This comment has been minimized.

Owner

derf commented Jun 5, 2011

I can't reproduce the segfault, but I do get the error messages. Looks like another case of weird memory management in feh/getopt... I'll see what I can do about it.

@livibetter

This comment has been minimized.

Contributor

livibetter commented Aug 1, 2011

I think I found the problem... and the fix is so simple:

diff --git a/src/options.c b/src/options.c
index b5a95dd..052f8a8 100644
--- a/src/options.c
+++ b/src/options.c
@@ -794,7 +794,7 @@ static void feh_parse_option_array(int argc, char **argv, int finalrun)
                add_file_to_filelist_recursively(".", FILELIST_FIRST);

        /* So that we can safely be called again */
-       optind = 1;
+       optind = 0;
        return;
 }

from manpage:

A program that scans multiple argument vectors, or [snip], or changes the value of POSIXLY_CORRECT between scans, must reinitialize getopt() by resetting optind to 0, rather than the traditional value of 1. (Resetting to 0 forces the invocation of an internal initialization routine that rechecks POSIXLY_CORRECT and checks for GNU extensions in optstring.)

A small suggestion, "--debug" should be a special case, when loading theme options, there are some D() used, but they will never print anything out since "--debug" at least have to wait until theme options are processed. There should be a quick check on debug option at very early stage.

@derf

This comment has been minimized.

Owner

derf commented Aug 1, 2011

Ooh. Yeah, that's looking good. Looks like I missed that while reading the documentation...
Thanks!

As for --debug: Right now it's useless for debugging getopt stuff, yeah. But I don't want yet another special case, I think I'll create a compile time switch for that (make debug=2 or similar). That way, you can really debug everything.

@derf derf closed this Aug 1, 2011

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment