+ // Use GetModuleFileName() to get the path to lyxc.exe
+ GetModuleFileName(0, cmd + i0, sizeof(cmd) / 2);
+
+ // substitute executable name
+ for (i = i0; cmd[i] != 0; ++i);
+
+ for (--i; i >= i0 && cmd[i] != '\\' && cmd[i] != '/'; --i);
+
+ for (++i; *lyxc && i < sizeof(cmd); )
+ cmd[i++] = *lyxc++;
+
+ // check whether lyxc.exe is there
+ cmd[i] = '\0';
+ lyxc = cmd + i0;
+ if (GetFileAttributesA(lyxc) == 0xFFFFFFFF) {
+ exitcode = GetLastError();
+ MessageBox(0, lyxc, "Error: cannot find the real LyX executable below", 0);
+ ExitProcess(exitcode);
+ }
+
+ // it's there, so finish quoting filename
+ cmd[i++] = '\"';
+
+ // parse remainder of command line
+ while (*cmdLine != 0 && !err) {
+ if (i < sizeof(cmd))
+ cmd[i++] = ' ';
+ else
+ err = 1;
+
+ if ((*cmdLine >= 'A' && *cmdLine <= 'Z') ||
+ (*cmdLine >= 'a' && *cmdLine <= 'z'))
+ var = cmd + i;
+ else
+ var = NULL;
+
+ val = NULL;
+ inquote = 0;
+ while (!err && ((*cmdLine != 0 && *cmdLine != ' ' &&
+ *cmdLine != '\t') || inquote))