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 a_lang;
|
||||||
string question;
|
string question;
|
||||||
string urltoview;
|
string urltoview;
|
||||||
|
|
||||||
thisprog = argv[0];
|
|
||||||
argc--; argv++;
|
|
||||||
|
|
||||||
while (argc > 0 && **argv == '-') {
|
// Avoid disturbing argc and argv. Especially, setting argc to 0
|
||||||
(*argv)++;
|
// prevents WM_CLASS to be set from argv[0] (it appears that qt
|
||||||
if (!(**argv))
|
// 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();
|
Usage();
|
||||||
while (**argv)
|
while (**myargv)
|
||||||
switch (*(*argv)++) {
|
switch (*(*myargv)++) {
|
||||||
case 'a': op_flags |= OPT_a; break;
|
case 'a': op_flags |= OPT_a; break;
|
||||||
case 'c': op_flags |= OPT_c; if (argc < 2) Usage();
|
case 'c': op_flags |= OPT_c; if (myargc < 2) Usage();
|
||||||
a_config = *(++argv);
|
a_config = *(++myargv);
|
||||||
argc--; goto b1;
|
myargc--; goto b1;
|
||||||
case 'f': op_flags |= OPT_f; break;
|
case 'f': op_flags |= OPT_f; break;
|
||||||
case 'h': op_flags |= OPT_h; Usage();break;
|
case 'h': op_flags |= OPT_h; Usage();break;
|
||||||
case 'L': op_flags |= OPT_L; if (argc < 2) Usage();
|
case 'L': op_flags |= OPT_L; if (myargc < 2) Usage();
|
||||||
a_lang = *(++argv);
|
a_lang = *(++myargv);
|
||||||
argc--; goto b1;
|
myargc--; goto b1;
|
||||||
case 'l': op_flags |= OPT_l; break;
|
case 'l': op_flags |= OPT_l; break;
|
||||||
case 'o': op_flags |= OPT_o; break;
|
case 'o': op_flags |= OPT_o; break;
|
||||||
case 'q': op_flags |= OPT_q; if (argc < 2) Usage();
|
case 'q': op_flags |= OPT_q; if (myargc < 2) Usage();
|
||||||
question = *(++argv);
|
question = *(++myargv);
|
||||||
argc--; goto b1;
|
myargc--; goto b1;
|
||||||
case 't': op_flags |= OPT_t; break;
|
case 't': op_flags |= OPT_t; break;
|
||||||
case 'v': op_flags |= OPT_v;
|
case 'v': op_flags |= OPT_v;
|
||||||
fprintf(stdout, "%s\n", Rcl::version_string().c_str());
|
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;
|
case 'w': op_flags |= OPT_w; break;
|
||||||
default: Usage();
|
default: Usage();
|
||||||
}
|
}
|
||||||
b1: argc--; argv++;
|
b1: myargc--; myargv++;
|
||||||
}
|
}
|
||||||
|
|
||||||
// If -q was given, all remaining non-option args are concatenated
|
// 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
|
// to the query. This is for the common case recoll -q x y z to
|
||||||
// avoid needing quoting "x y z"
|
// avoid needing quoting "x y z"
|
||||||
if (op_flags & OPT_q)
|
if (op_flags & OPT_q)
|
||||||
while (argc > 0) {
|
while (myargc > 0) {
|
||||||
question += " ";
|
question += " ";
|
||||||
question += *argv++;
|
question += *myargv++;
|
||||||
argc--;
|
myargc--;
|
||||||
}
|
}
|
||||||
|
|
||||||
// Else the remaining argument should be an URL to be opened
|
// Else the remaining argument should be an URL to be opened
|
||||||
if (argc == 1) {
|
if (myargc == 1) {
|
||||||
urltoview = *argv++;argc--;
|
urltoview = *myargv++;myargc--;
|
||||||
if (urltoview.compare(0, 7, cstr_fileu)) {
|
if (urltoview.compare(0, 7, cstr_fileu)) {
|
||||||
Usage();
|
Usage();
|
||||||
}
|
}
|
||||||
} else if (argc > 0)
|
} else if (myargc > 0)
|
||||||
Usage();
|
Usage();
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
Loading…
x
Reference in New Issue
Block a user