qt GUI: avoid decrementing argc to 0 in main because this seems to prevent setting WM_CLASS during qapp::exec()
This commit is contained in:
parent
bf5f74bc13
commit
a619922ba1
@ -256,30 +256,38 @@ int main(int argc, char **argv)
|
||||
string a_lang;
|
||||
string question;
|
||||
string urltoview;
|
||||
|
||||
thisprog = argv[0];
|
||||
argc--; argv++;
|
||||
|
||||
while (argc > 0 && **argv == '-') {
|
||||
(*argv)++;
|
||||
if (!(**argv))
|
||||
// Avoid disturbing argc and argv. Especially, setting argc to 0
|
||||
// prevents WM_CLASS to be set from argv[0] (it appears that qt
|
||||
// keeps a ref to argc, and that it is used at exec() time to set
|
||||
// WM_CLASS from argv[0]). Curiously, it seems that the argv
|
||||
// pointer can be modified without consequences, but we use a copy
|
||||
// to play it safe
|
||||
int myargc = argc;
|
||||
char **myargv = argv;
|
||||
thisprog = myargv[0];
|
||||
myargc--; myargv++;
|
||||
|
||||
while (myargc > 0 && **myargv == '-') {
|
||||
(*myargv)++;
|
||||
if (!(**myargv))
|
||||
Usage();
|
||||
while (**argv)
|
||||
switch (*(*argv)++) {
|
||||
while (**myargv)
|
||||
switch (*(*myargv)++) {
|
||||
case 'a': op_flags |= OPT_a; break;
|
||||
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
||||
a_config = *(++argv);
|
||||
argc--; goto b1;
|
||||
case 'c': op_flags |= OPT_c; if (myargc < 2) Usage();
|
||||
a_config = *(++myargv);
|
||||
myargc--; goto b1;
|
||||
case 'f': op_flags |= OPT_f; break;
|
||||
case 'h': op_flags |= OPT_h; Usage();break;
|
||||
case 'L': op_flags |= OPT_L; if (argc < 2) Usage();
|
||||
a_lang = *(++argv);
|
||||
argc--; goto b1;
|
||||
case 'L': op_flags |= OPT_L; if (myargc < 2) Usage();
|
||||
a_lang = *(++myargv);
|
||||
myargc--; goto b1;
|
||||
case 'l': op_flags |= OPT_l; break;
|
||||
case 'o': op_flags |= OPT_o; break;
|
||||
case 'q': op_flags |= OPT_q; if (argc < 2) Usage();
|
||||
question = *(++argv);
|
||||
argc--; goto b1;
|
||||
case 'q': op_flags |= OPT_q; if (myargc < 2) Usage();
|
||||
question = *(++myargv);
|
||||
myargc--; goto b1;
|
||||
case 't': op_flags |= OPT_t; break;
|
||||
case 'v': op_flags |= OPT_v;
|
||||
fprintf(stdout, "%s\n", Rcl::version_string().c_str());
|
||||
@ -287,26 +295,26 @@ int main(int argc, char **argv)
|
||||
case 'w': op_flags |= OPT_w; break;
|
||||
default: Usage();
|
||||
}
|
||||
b1: argc--; argv++;
|
||||
b1: myargc--; myargv++;
|
||||
}
|
||||
|
||||
// If -q was given, all remaining non-option args are concatenated
|
||||
// to the query. This is for the common case recoll -q x y z to
|
||||
// avoid needing quoting "x y z"
|
||||
if (op_flags & OPT_q)
|
||||
while (argc > 0) {
|
||||
while (myargc > 0) {
|
||||
question += " ";
|
||||
question += *argv++;
|
||||
argc--;
|
||||
question += *myargv++;
|
||||
myargc--;
|
||||
}
|
||||
|
||||
// Else the remaining argument should be an URL to be opened
|
||||
if (argc == 1) {
|
||||
urltoview = *argv++;argc--;
|
||||
if (myargc == 1) {
|
||||
urltoview = *myargv++;myargc--;
|
||||
if (urltoview.compare(0, 7, cstr_fileu)) {
|
||||
Usage();
|
||||
}
|
||||
} else if (argc > 0)
|
||||
} else if (myargc > 0)
|
||||
Usage();
|
||||
|
||||
|
||||
|
||||
Loading…
x
Reference in New Issue
Block a user