[78] | 1 |
|
---|
| 2 | /***********************************************************************
|
---|
| 3 |
|
---|
| 4 | $Id: systemf.c 1270 2008-11-08 20:48:24Z gyoung $
|
---|
| 5 |
|
---|
| 6 | System Interfaces
|
---|
| 7 |
|
---|
| 8 | Copyright (c) 1993-98 M. Kimes
|
---|
[1082] | 9 | Copyright (c) 2003, 2008 Steven H.Levine
|
---|
[78] | 10 |
|
---|
[330] | 11 | 21 Nov 03 SHL Comments
|
---|
| 12 | 31 Jul 04 SHL Indent -i2
|
---|
| 13 | 01 Aug 04 SHL Rework lstrip/rstrip usage
|
---|
| 14 | 17 Jul 06 SHL Use Runtime_Error
|
---|
[373] | 15 | 26 Jul 06 SHL Use convert_nl_to_nul
|
---|
[441] | 16 | 15 Aug 06 SHL More error popups
|
---|
[519] | 17 | 01 Nov 06 SHL runemf2: temp fix for hung windows caused by termq errors
|
---|
[540] | 18 | 03 Nov 06 SHL runemf2: rework termination queue logic to work for multiple threads
|
---|
[552] | 19 | 07 Jan 07 GKY Move error strings etc. to string file
|
---|
[775] | 20 | 06 Aug 07 GKY Reduce DosSleep times (ticket 148)
|
---|
[793] | 21 | 20 Aug 07 GKY Move #pragma alloc_text to end for OpenWatcom compat
|
---|
[985] | 22 | 29 Feb 08 GKY Changes to enable user settable command line length
|
---|
| 23 | 29 Feb 08 GKY Refactor global command line variables to notebook.h
|
---|
[1021] | 24 | 26 May 08 SHL Use uiLineNumber correctly
|
---|
[1082] | 25 | 19 Jul 08 GKY Replace save_dir2(dir) with pFM2SaveDirectory or pTmpDir and use MakeTempName
|
---|
[1270] | 26 | 08 Nov 08 GKY Post an event semaphore to WaitChildThread to fix hang caused by viewer trying
|
---|
| 27 | to open a file before the archiver process closes. (Ticket 58)
|
---|
[78] | 28 |
|
---|
| 29 | ***********************************************************************/
|
---|
| 30 |
|
---|
[2] | 31 | #include <stdlib.h>
|
---|
| 32 | #include <stdarg.h>
|
---|
| 33 | #include <string.h>
|
---|
| 34 | #include <ctype.h>
|
---|
[330] | 35 |
|
---|
[907] | 36 | #define INCL_DOS
|
---|
| 37 | #define INCL_DOSERRORS
|
---|
| 38 | #define INCL_WIN
|
---|
[1162] | 39 | #define INCL_LONGLONG // dircnrs.h
|
---|
[907] | 40 |
|
---|
[1186] | 41 | #include "fm3dll.h"
|
---|
[1227] | 42 | #include "fm3dll2.h" // #define's for UM_*, control id's, etc.
|
---|
[1213] | 43 | #include "mkdir.h" // Data declaration(s)
|
---|
| 44 | #include "init.h" // Data declaration(s)
|
---|
| 45 | #include "mainwnd.h" // Data declaration(s)
|
---|
[2] | 46 | #include "fm3dlg.h"
|
---|
| 47 | #include "fm3str.h"
|
---|
[1162] | 48 | #include "errutil.h" // Dos_Error...
|
---|
| 49 | #include "strutil.h" // GetPString
|
---|
[985] | 50 | #include "notebook.h" //targetdirectory
|
---|
[907] | 51 | #include "pathutil.h"
|
---|
[1162] | 52 | #include "cmdline.h" // CmdLineDlgProc
|
---|
| 53 | #include "shadow.h" // RunSeamless
|
---|
| 54 | #include "systemf.h"
|
---|
| 55 | #include "strips.h" // convert_nl_to_nul, strip_lead_char
|
---|
| 56 | #include "dirs.h" // switch_to
|
---|
[1186] | 57 | #include "valid.h" // MakeFullName
|
---|
| 58 | #include "misc.h" // GetCmdSpec
|
---|
| 59 | #include "copyf.h" // MakeTempName
|
---|
| 60 | #include "wrappers.h" // xfopen
|
---|
[1039] | 61 | #include "fortify.h"
|
---|
[2] | 62 |
|
---|
[330] | 63 | static PSZ pszSrcFile = __FILE__;
|
---|
| 64 |
|
---|
[1268] | 65 | HEV hWaitChildSem;
|
---|
| 66 |
|
---|
[1162] | 67 | //static HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
| 68 | // PROGTYPE * progt, ULONG fl, char *formatstring, ...);
|
---|
| 69 |
|
---|
[917] | 70 | /**
|
---|
| 71 | * Bring session foreground
|
---|
| 72 | * @return TRUE if OK, else FALSE
|
---|
| 73 | */
|
---|
[2] | 74 |
|
---|
[105] | 75 | BOOL ShowSession(HWND hwnd, PID pid)
|
---|
[78] | 76 | {
|
---|
[105] | 77 | HSWITCH hswitch;
|
---|
| 78 | SWCNTRL swctl;
|
---|
| 79 | ULONG rc;
|
---|
[2] | 80 |
|
---|
[519] | 81 | hswitch = WinQuerySwitchHandle(pid ? (HWND)0 : hwnd, pid);
|
---|
[441] | 82 | if (hswitch) {
|
---|
[105] | 83 | rc = WinQuerySwitchEntry(hswitch, &swctl);
|
---|
[441] | 84 | if (!rc) {
|
---|
[105] | 85 | if (swctl.idProcess == pid && swctl.uchVisibility == SWL_VISIBLE)
|
---|
[1162] | 86 | rc = WinSwitchToProgram(hswitch);
|
---|
[105] | 87 | if (!rc)
|
---|
[1162] | 88 | return TRUE;
|
---|
[78] | 89 | // else saymsg(MB_ENTER,HWND_DESKTOP,DEBUG_STRING,"Failed: %lu/%lx",rc,rc);
|
---|
[2] | 90 |
|
---|
[105] | 91 | }
|
---|
| 92 | }
|
---|
| 93 | return FALSE;
|
---|
[2] | 94 | }
|
---|
| 95 |
|
---|
[917] | 96 | /**
|
---|
| 97 | * Invoke runemf2 for command and file/directory list
|
---|
| 98 | * @return command return code or
|
---|
| 99 | * -1 if runtime error or
|
---|
| 100 | * -2 if user cancels command line edit dialog
|
---|
| 101 | */
|
---|
[519] | 102 |
|
---|
[105] | 103 | int ExecOnList(HWND hwnd, char *command, int flags, char *tpath,
|
---|
[1162] | 104 | char **list, char *prompt, PCSZ pszCallingFile, UINT uiLineNumber)
|
---|
[78] | 105 | {
|
---|
[105] | 106 | /* executes the command once for all files in list */
|
---|
[2] | 107 |
|
---|
[985] | 108 | char path[CCHMAXPATH], *commandline, modpath[CCHMAXPATH], listfile[CCHMAXPATH],
|
---|
[105] | 109 | *p, *pp, drive, *file, *ext, *dot;
|
---|
[2] | 110 | register int x;
|
---|
[105] | 111 | BOOL spaces;
|
---|
[2] | 112 |
|
---|
[441] | 113 | if (!command || !*command) {
|
---|
| 114 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
---|
[105] | 115 | return -1;
|
---|
[441] | 116 | }
|
---|
[989] | 117 | commandline = xmalloc(MaxComLineStrg + 1, pszSrcFile, __LINE__);
|
---|
[985] | 118 | if (!commandline)
|
---|
| 119 | return -1; //already complained
|
---|
[2] | 120 | *listfile = 0;
|
---|
[123] | 121 | bstrip(command);
|
---|
[2] | 122 |
|
---|
| 123 | *path = 0;
|
---|
[105] | 124 | if (tpath && *tpath)
|
---|
| 125 | strcpy(path, tpath);
|
---|
[441] | 126 | else if (*command != '<' || !strchr(command, '>')) {
|
---|
[105] | 127 | strcpy(path, command + (*command == '"'));
|
---|
| 128 | if (*command == '\"')
|
---|
| 129 | p = strchr(path, '\"');
|
---|
[2] | 130 | else
|
---|
[105] | 131 | p = strchr(path, ' ');
|
---|
| 132 | if (p)
|
---|
[2] | 133 | *p = 0;
|
---|
[105] | 134 | p = strrchr(path, '\\');
|
---|
| 135 | if (!p)
|
---|
| 136 | p = strrchr(path, ':');
|
---|
[441] | 137 | if (p) {
|
---|
| 138 | if (*p == ':') {
|
---|
[1162] | 139 | p++;
|
---|
| 140 | *p = '\\';
|
---|
| 141 | p++;
|
---|
[2] | 142 | }
|
---|
| 143 | *p = 0;
|
---|
| 144 | }
|
---|
| 145 | else
|
---|
| 146 | *path = 0;
|
---|
| 147 | }
|
---|
[441] | 148 | if (!*path) {
|
---|
[105] | 149 | if (list && list[0])
|
---|
| 150 | strcpy(path, list[0]);
|
---|
| 151 | p = strrchr(path, '\\');
|
---|
| 152 | if (!p)
|
---|
| 153 | p = strrchr(path, ':');
|
---|
[441] | 154 | if (p) {
|
---|
| 155 | if (*p == ':') {
|
---|
[1162] | 156 | p++;
|
---|
| 157 | *p = '\\';
|
---|
| 158 | p++;
|
---|
[2] | 159 | }
|
---|
| 160 | *p = 0;
|
---|
| 161 | }
|
---|
| 162 | else
|
---|
| 163 | *path = 0;
|
---|
| 164 | }
|
---|
| 165 | *modpath = 0;
|
---|
[105] | 166 | if (list && list[0])
|
---|
| 167 | strcpy(modpath, list[0]);
|
---|
| 168 | p = strrchr(modpath, '\\');
|
---|
| 169 | if (!p)
|
---|
| 170 | p = strrchr(modpath, ':');
|
---|
[441] | 171 | if (p) {
|
---|
| 172 | if (*p == ':') {
|
---|
[2] | 173 | p++;
|
---|
| 174 | *p = '\\';
|
---|
| 175 | p++;
|
---|
| 176 | }
|
---|
| 177 | *p = 0;
|
---|
| 178 | }
|
---|
| 179 | else
|
---|
| 180 | *modpath = 0;
|
---|
[105] | 181 | if (!*modpath)
|
---|
| 182 | strcpy(modpath, path);
|
---|
| 183 | if (*path)
|
---|
[2] | 184 | MakeFullName(path);
|
---|
[105] | 185 | if (*modpath)
|
---|
[2] | 186 | MakeFullName(modpath);
|
---|
[105] | 187 | if (IsFullName(path))
|
---|
| 188 | drive = toupper(*path);
|
---|
| 189 | else
|
---|
| 190 | drive = 0;
|
---|
[2] | 191 |
|
---|
[1162] | 192 | p = command; // substitue for special % sequences
|
---|
[2] | 193 |
|
---|
[105] | 194 | pp = commandline;
|
---|
| 195 | *commandline = 0;
|
---|
[441] | 196 | while (*p) {
|
---|
| 197 | if (*p == '%') {
|
---|
| 198 | switch (*(p + 1)) {
|
---|
[1162] | 199 | case '!': /* write list to file, add filename */
|
---|
| 200 | if (list) {
|
---|
| 201 | if (!*listfile) {
|
---|
| 202 | FILE *fp;
|
---|
[2] | 203 |
|
---|
[1082] | 204 |
|
---|
| 205 | strcpy(listfile, pTmpDir ? pTmpDir : pFM2SaveDirectory);
|
---|
| 206 | MakeTempName(listfile, "$FM2LI$T", 2);
|
---|
| 207 | /*if (listfile[strlen(listfile) - 1] != '\\')
|
---|
| 208 | strcat(listfile, "\\");
|
---|
| 209 | sprintf(&listfile[strlen(listfile)], "%s.%03x",
|
---|
| 210 | LISTTEMPROOT, (clock() & 4095));*/
|
---|
| 211 | fp = xfopen(listfile, "w",pszSrcFile,__LINE__);
|
---|
| 212 | if (fp) {
|
---|
| 213 | for (x = 0; list[x]; x++)
|
---|
| 214 | {
|
---|
| 215 | fputs(list[x], fp);
|
---|
| 216 | if (list[x + 1])
|
---|
| 217 | fputc('\n', fp);
|
---|
| 218 | }
|
---|
| 219 | fclose(fp);
|
---|
| 220 | }
|
---|
| 221 | }
|
---|
| 222 | strcpy(pp, listfile);
|
---|
| 223 | pp += strlen(listfile);
|
---|
[1162] | 224 | }
|
---|
| 225 | p += 2;
|
---|
| 226 | break;
|
---|
[2] | 227 |
|
---|
[1162] | 228 | case 'c': /* add name of command processor */
|
---|
| 229 | {
|
---|
| 230 | char *env = GetCmdSpec(FALSE);
|
---|
[2] | 231 |
|
---|
[1162] | 232 | if (needs_quoting(env) && !strchr(env, '\"')) {
|
---|
| 233 | *pp = '\"';
|
---|
| 234 | pp++;
|
---|
| 235 | spaces = TRUE;
|
---|
| 236 | }
|
---|
| 237 | else
|
---|
| 238 | spaces = FALSE;
|
---|
| 239 | strcpy(pp, env);
|
---|
| 240 | p += 2;
|
---|
| 241 | pp += strlen(env);
|
---|
| 242 | if (spaces) {
|
---|
| 243 | *pp = '\"';
|
---|
| 244 | pp++;
|
---|
| 245 | }
|
---|
| 246 | }
|
---|
| 247 | break;
|
---|
[2] | 248 |
|
---|
[1162] | 249 | case 't': /* add Target directory */
|
---|
| 250 | if (needs_quoting(targetdir) && !strchr(targetdir, '\"')) {
|
---|
| 251 | *pp = '\"';
|
---|
| 252 | pp++;
|
---|
| 253 | spaces = TRUE;
|
---|
| 254 | }
|
---|
| 255 | else
|
---|
| 256 | spaces = FALSE;
|
---|
| 257 | strcpy(pp, targetdir);
|
---|
| 258 | p += 2;
|
---|
| 259 | pp += strlen(targetdir);
|
---|
| 260 | if (spaces) {
|
---|
| 261 | *pp = '\"';
|
---|
| 262 | pp++;
|
---|
| 263 | }
|
---|
| 264 | break;
|
---|
[2] | 265 |
|
---|
[1162] | 266 | case '$': /* add drive letter */
|
---|
| 267 | if (drive)
|
---|
| 268 | *pp = drive;
|
---|
| 269 | else {
|
---|
| 270 | ULONG ulDriveNum = 3, ulDriveMap;
|
---|
[2] | 271 |
|
---|
[1162] | 272 | DosQCurDisk(&ulDriveNum, &ulDriveMap);
|
---|
| 273 | *pp = (char) (ulDriveNum + '@');
|
---|
| 274 | }
|
---|
| 275 | pp++;
|
---|
| 276 | p += 2;
|
---|
| 277 | break;
|
---|
[2] | 278 |
|
---|
[1162] | 279 | case 'U': /* add path of first list component */
|
---|
[105] | 280 | case 'u':
|
---|
[1162] | 281 | if (*modpath) {
|
---|
| 282 | if (needs_quoting(modpath) && !strchr(modpath, '\"')) {
|
---|
| 283 | spaces = TRUE;
|
---|
| 284 | *pp = '\"';
|
---|
| 285 | pp++;
|
---|
| 286 | }
|
---|
| 287 | else
|
---|
| 288 | spaces = FALSE;
|
---|
| 289 | if (*(p + 1) == 'u') {
|
---|
| 290 | strcpy(pp, modpath);
|
---|
| 291 | pp += strlen(modpath);
|
---|
| 292 | }
|
---|
| 293 | else {
|
---|
| 294 | strcpy(pp, modpath + 2);
|
---|
| 295 | pp += strlen(modpath + 2);
|
---|
| 296 | }
|
---|
| 297 | if (spaces) {
|
---|
| 298 | if (modpath[strlen(modpath) - 1] == '\\') {
|
---|
| 299 | *pp = '\\';
|
---|
| 300 | pp++;
|
---|
| 301 | }
|
---|
| 302 | *pp = '\"';
|
---|
| 303 | pp++;
|
---|
| 304 | }
|
---|
| 305 | }
|
---|
| 306 | else {
|
---|
| 307 | char temp[CCHMAXPATH];
|
---|
[2] | 308 |
|
---|
[1162] | 309 | strcpy(temp, pFM2SaveDirectory);
|
---|
| 310 | if (needs_quoting(temp) && !strchr(temp, '\"')) {
|
---|
| 311 | spaces = TRUE;
|
---|
| 312 | *pp = '\"';
|
---|
| 313 | pp++;
|
---|
| 314 | }
|
---|
| 315 | else
|
---|
| 316 | spaces = FALSE;
|
---|
| 317 | strcpy(pp, temp);
|
---|
| 318 | pp += strlen(temp);
|
---|
| 319 | if (spaces) {
|
---|
| 320 | if (temp[strlen(temp) - 1] == '\\') {
|
---|
| 321 | *pp = '\\';
|
---|
| 322 | pp++;
|
---|
| 323 | }
|
---|
| 324 | *pp = '\"';
|
---|
| 325 | pp++;
|
---|
| 326 | }
|
---|
| 327 | }
|
---|
| 328 | p += 2;
|
---|
| 329 | break;
|
---|
[2] | 330 |
|
---|
[1162] | 331 | case 'P': /* add path of execution */
|
---|
[105] | 332 | case 'p':
|
---|
[1162] | 333 | if (*path) {
|
---|
| 334 | if (needs_quoting(path) && !strchr(path, '\"')) {
|
---|
| 335 | spaces = TRUE;
|
---|
| 336 | *pp = '\"';
|
---|
| 337 | pp++;
|
---|
| 338 | }
|
---|
| 339 | else
|
---|
| 340 | spaces = FALSE;
|
---|
| 341 | if (*(p + 1) == 'p') {
|
---|
| 342 | strcpy(pp, path);
|
---|
| 343 | pp += strlen(path);
|
---|
| 344 | }
|
---|
| 345 | else {
|
---|
| 346 | strcpy(pp, path + 2);
|
---|
| 347 | pp += strlen(path + 2);
|
---|
| 348 | }
|
---|
| 349 | if (spaces) {
|
---|
| 350 | if (path[strlen(path) - 1] == '\\') {
|
---|
| 351 | *pp = '\\';
|
---|
| 352 | pp++;
|
---|
| 353 | }
|
---|
| 354 | *pp = '\"';
|
---|
| 355 | pp++;
|
---|
| 356 | }
|
---|
| 357 | }
|
---|
| 358 | else {
|
---|
| 359 | char temp[CCHMAXPATH];
|
---|
[2] | 360 |
|
---|
[1162] | 361 | strcpy(temp, pFM2SaveDirectory);
|
---|
| 362 | if (needs_quoting(temp) && !strchr(temp, '\"')) {
|
---|
| 363 | spaces = TRUE;
|
---|
| 364 | *pp = '\"';
|
---|
| 365 | pp++;
|
---|
| 366 | }
|
---|
| 367 | else
|
---|
| 368 | spaces = FALSE;
|
---|
| 369 | strcpy(pp, temp);
|
---|
| 370 | pp += strlen(temp);
|
---|
| 371 | if (spaces) {
|
---|
| 372 | if (temp[strlen(temp) - 1] == '\\') {
|
---|
| 373 | *pp = '\\';
|
---|
| 374 | pp++;
|
---|
| 375 | }
|
---|
| 376 | *pp = '\"';
|
---|
| 377 | pp++;
|
---|
| 378 | }
|
---|
| 379 | }
|
---|
| 380 | p += 2;
|
---|
| 381 | break;
|
---|
[2] | 382 |
|
---|
[105] | 383 | case 'D':
|
---|
[1162] | 384 | if (hwndMain) {
|
---|
| 385 | PCNRITEM pci;
|
---|
[2] | 386 |
|
---|
[1162] | 387 | pci = (PCNRITEM) WinSendMsg(WinWindowFromID(WinWindowFromID(
|
---|
| 388 | hwndTree, FID_CLIENT), TREE_CNR),
|
---|
| 389 | CM_QUERYRECORDEMPHASIS,
|
---|
| 390 | MPFROMLONG(CMA_FIRST),
|
---|
| 391 | MPFROMSHORT(CRA_CURSORED));
|
---|
| 392 | if (pci && (int) pci != -1 && *pci->pszFileName) {
|
---|
| 393 | if (needs_quoting(pci->pszFileName) &&
|
---|
| 394 | !strchr(pci->pszFileName, '\"'))
|
---|
| 395 | {
|
---|
| 396 | *pp = '\"';
|
---|
| 397 | pp++;
|
---|
| 398 | spaces = TRUE;
|
---|
| 399 | }
|
---|
| 400 | else
|
---|
| 401 | spaces = FALSE;
|
---|
| 402 | strcpy(pp, pci->pszFileName);
|
---|
| 403 | pp += strlen(pci->pszFileName);
|
---|
| 404 | if (spaces) {
|
---|
| 405 | *pp = '\"';
|
---|
| 406 | pp++;
|
---|
| 407 | }
|
---|
| 408 | }
|
---|
| 409 | }
|
---|
| 410 | p += 2;
|
---|
| 411 | break;
|
---|
[2] | 412 |
|
---|
[105] | 413 | case 'd':
|
---|
[1162] | 414 | if (hwndMain) {
|
---|
| 415 | HENUM henum;
|
---|
| 416 | char retstr[CCHMAXPATH];
|
---|
| 417 | HWND hwndC, hwndDir;
|
---|
| 418 | USHORT id;
|
---|
| 419 | BOOL first = TRUE;
|
---|
[2] | 420 |
|
---|
[1162] | 421 | henum = WinBeginEnumWindows(hwndMain);
|
---|
| 422 | while ((hwndC = WinGetNextWindow(henum)) != NULLHANDLE) {
|
---|
| 423 | if (hwndC != hwndTree) {
|
---|
| 424 | id = WinQueryWindowUShort(hwndC, QWS_ID);
|
---|
| 425 | if (id) {
|
---|
| 426 | hwndDir = WinWindowFromID(hwndC, FID_CLIENT);
|
---|
| 427 | if (hwndDir) {
|
---|
| 428 | hwndDir = WinWindowFromID(hwndDir, DIR_CNR);
|
---|
| 429 | if (hwndDir) {
|
---|
| 430 | *retstr = 0;
|
---|
| 431 | WinSendMsg(hwndC, UM_CONTAINERDIR, MPFROMP(retstr), MPVOID);
|
---|
| 432 | if (*retstr) {
|
---|
| 433 | if (!first) {
|
---|
| 434 | *pp = ' ';
|
---|
| 435 | pp++;
|
---|
| 436 | }
|
---|
| 437 | first = FALSE;
|
---|
| 438 | if (needs_quoting(retstr) && !strchr(retstr, '\"')) {
|
---|
| 439 | *pp = '\"';
|
---|
| 440 | pp++;
|
---|
| 441 | spaces = TRUE;
|
---|
| 442 | }
|
---|
| 443 | else
|
---|
| 444 | spaces = FALSE;
|
---|
| 445 | strcpy(pp, retstr);
|
---|
| 446 | pp += strlen(retstr);
|
---|
| 447 | if (spaces) {
|
---|
| 448 | *pp = '\"';
|
---|
| 449 | pp++;
|
---|
| 450 | }
|
---|
| 451 | }
|
---|
| 452 | }
|
---|
| 453 | }
|
---|
| 454 | }
|
---|
| 455 | }
|
---|
| 456 | }
|
---|
| 457 | WinEndEnumWindows(henum);
|
---|
| 458 | }
|
---|
| 459 | p += 2;
|
---|
| 460 | break;
|
---|
[2] | 461 |
|
---|
[105] | 462 | case '%':
|
---|
[1162] | 463 | *pp = '%';
|
---|
| 464 | pp++;
|
---|
| 465 | p += 2;
|
---|
| 466 | break;
|
---|
[2] | 467 |
|
---|
[105] | 468 | case 'R':
|
---|
| 469 | case 'F':
|
---|
| 470 | case 'A':
|
---|
| 471 | case 'r':
|
---|
| 472 | case 'f':
|
---|
| 473 | case 'a':
|
---|
| 474 | case 'e':
|
---|
[1162] | 475 | if (list) {
|
---|
| 476 | for (x = 0; list[x]; x++)
|
---|
| 477 | {
|
---|
| 478 | file = strrchr(list[x], '\\');
|
---|
| 479 | if (!file)
|
---|
| 480 | file = strrchr(list[x], ':');
|
---|
| 481 | if (file)
|
---|
| 482 | file++;
|
---|
| 483 | else
|
---|
| 484 | file = list[x];
|
---|
| 485 | ext = strrchr(file, '.');
|
---|
| 486 | dot = ext;
|
---|
| 487 | if (ext)
|
---|
| 488 | ext++;
|
---|
| 489 | switch (*(p + 1)) {
|
---|
| 490 | case 'R':
|
---|
| 491 | case 'r':
|
---|
| 492 | if (pp + strlen(list[x]) > commandline + MaxComLineStrg)
|
---|
| 493 | goto BreakOut;
|
---|
| 494 | if (*(p + 1) == 'r') {
|
---|
| 495 | strcpy(pp, list[x]);
|
---|
| 496 | pp += strlen(list[x]);
|
---|
| 497 | }
|
---|
| 498 | else {
|
---|
| 499 | strcpy(pp, list[x] + 2);
|
---|
| 500 | pp += strlen(list[x] + 2);
|
---|
| 501 | }
|
---|
| 502 | break;
|
---|
[2] | 503 |
|
---|
[1162] | 504 | case 'F':
|
---|
| 505 | case 'f':
|
---|
| 506 | if (*(p + 1) == 'F' && dot)
|
---|
| 507 | *dot = 0;
|
---|
| 508 | if (pp + strlen(file) > commandline + MaxComLineStrg)
|
---|
| 509 | goto BreakOut;
|
---|
| 510 | if (needs_quoting(file)) {
|
---|
| 511 | spaces = TRUE;
|
---|
| 512 | *pp = '\"';
|
---|
| 513 | pp++;
|
---|
| 514 | }
|
---|
| 515 | else
|
---|
| 516 | spaces = FALSE;
|
---|
| 517 | strcpy(pp, file);
|
---|
| 518 | pp += strlen(file);
|
---|
| 519 | if (*(p + 1) == 'F' && dot)
|
---|
| 520 | *dot = '.';
|
---|
| 521 | if (spaces) {
|
---|
| 522 | if (*(pp - 1) != '\"') {
|
---|
| 523 | *pp = '\"';
|
---|
| 524 | pp++;
|
---|
| 525 | }
|
---|
| 526 | }
|
---|
| 527 | break;
|
---|
[2] | 528 |
|
---|
[1162] | 529 | case 'A':
|
---|
| 530 | case 'a':
|
---|
| 531 | if (pp + strlen(list[x]) > commandline + MaxComLineStrg)
|
---|
| 532 | goto BreakOut;
|
---|
| 533 | if (needs_quoting(list[x]) && !strchr(list[x], '\"')) {
|
---|
| 534 | spaces = TRUE;
|
---|
| 535 | *pp = '\"';
|
---|
| 536 | pp++;
|
---|
| 537 | }
|
---|
| 538 | else
|
---|
| 539 | spaces = FALSE;
|
---|
| 540 | if (*(p + 1) == 'a') {
|
---|
| 541 | strcpy(pp, list[x]);
|
---|
| 542 | pp += strlen(list[x]);
|
---|
| 543 | }
|
---|
| 544 | else {
|
---|
| 545 | strcpy(pp, list[x] + 2);
|
---|
| 546 | pp += strlen(list[x] + 2);
|
---|
| 547 | }
|
---|
| 548 | if (spaces) {
|
---|
| 549 | if (list[x][strlen(list[x]) - 1] == '\\') {
|
---|
| 550 | *pp = '\\';
|
---|
| 551 | pp++;
|
---|
| 552 | }
|
---|
| 553 | *pp = '\"';
|
---|
| 554 | pp++;
|
---|
| 555 | }
|
---|
| 556 | break;
|
---|
[2] | 557 |
|
---|
[1162] | 558 | case 'e':
|
---|
| 559 | if (ext) {
|
---|
| 560 | if (pp + strlen(ext) > commandline + MaxComLineStrg)
|
---|
| 561 | goto BreakOut;
|
---|
| 562 | if (needs_quoting(ext)) {
|
---|
| 563 | spaces = TRUE;
|
---|
| 564 | *pp = '\"';
|
---|
| 565 | pp++;
|
---|
| 566 | }
|
---|
| 567 | else
|
---|
| 568 | spaces = FALSE;
|
---|
| 569 | strcpy(pp, ext);
|
---|
| 570 | pp += strlen(ext);
|
---|
| 571 | if (spaces) {
|
---|
| 572 | if (*(pp - 1) != '\"') {
|
---|
| 573 | *pp = '\"';
|
---|
| 574 | pp++;
|
---|
| 575 | }
|
---|
| 576 | }
|
---|
| 577 | }
|
---|
| 578 | break;
|
---|
| 579 | }
|
---|
| 580 | if (list[x + 1]) {
|
---|
| 581 | *pp = ' ';
|
---|
| 582 | pp++;
|
---|
| 583 | }
|
---|
| 584 | }
|
---|
| 585 | }
|
---|
| 586 | p += 2;
|
---|
| 587 | break;
|
---|
[2] | 588 |
|
---|
[105] | 589 | default:
|
---|
[1162] | 590 | *pp = *p;
|
---|
| 591 | p++;
|
---|
| 592 | pp++;
|
---|
| 593 | break;
|
---|
[105] | 594 | }
|
---|
| 595 | }
|
---|
[441] | 596 | else {
|
---|
[105] | 597 | *pp = *p;
|
---|
| 598 | pp++;
|
---|
| 599 | p++;
|
---|
| 600 | }
|
---|
| 601 | *pp = 0;
|
---|
| 602 | }
|
---|
| 603 |
|
---|
[2] | 604 | BreakOut:
|
---|
| 605 |
|
---|
[105] | 606 | {
|
---|
| 607 | EXECARGS ex;
|
---|
| 608 | ULONG size;
|
---|
| 609 | int ret;
|
---|
[2] | 610 |
|
---|
[105] | 611 | memset(&ex, 0, sizeof(EXECARGS));
|
---|
| 612 | size = sizeof(ex.environment) - 1;
|
---|
| 613 | PrfQueryProfileData(fmprof, FM3Str, command, ex.environment, &size);
|
---|
[441] | 614 | if (flags & PROMPT) {
|
---|
| 615 | /* allow editing command line */
|
---|
[105] | 616 | ex.flags = (flags & (~PROMPT));
|
---|
| 617 | ex.commandline = commandline;
|
---|
| 618 | strcpy(ex.path, path);
|
---|
| 619 | if (prompt)
|
---|
[1162] | 620 | strcpy(ex.title, prompt);
|
---|
[105] | 621 | ret = WinDlgBox(HWND_DESKTOP, hwnd, CmdLineDlgProc, FM3ModHandle,
|
---|
[1162] | 622 | EXEC_FRAME, &ex);
|
---|
[985] | 623 | if (ret != 1) {
|
---|
[1039] | 624 | free(commandline);
|
---|
[985] | 625 | return (ret == 0) ? -1 : -2;
|
---|
| 626 | }
|
---|
[105] | 627 | }
|
---|
| 628 | else
|
---|
| 629 | ex.flags = flags;
|
---|
| 630 | ex.flags &= (~PROMPT);
|
---|
[1014] | 631 | ret = runemf2(ex.flags, hwnd, pszCallingFile, uiLineNumber, path,
|
---|
[1162] | 632 | (*ex.environment) ? ex.environment : NULL,
|
---|
[1014] | 633 | "%s", commandline);
|
---|
[1039] | 634 | free(commandline);
|
---|
[1014] | 635 | return ret;
|
---|
[105] | 636 | }
|
---|
[2] | 637 | }
|
---|
| 638 |
|
---|
[917] | 639 | /** Run requested app
|
---|
| 640 | * @return application return code or -1 if problem starting app
|
---|
| 641 | */
|
---|
[441] | 642 |
|
---|
[888] | 643 | int runemf2(int type, HWND hwnd, PCSZ pszCallingFile, UINT uiLineNumber,
|
---|
[1162] | 644 | char *pszDirectory, char *pszEnvironment,
|
---|
| 645 | char *formatstring,...)
|
---|
[78] | 646 | {
|
---|
[920] | 647 | /** example:
|
---|
[105] | 648 |
|
---|
[2] | 649 | * status = runemf2(SEPARATE | WINDOWED,
|
---|
[888] | 650 | * hwnd, pszCallingFile, __LINE__,
|
---|
[2] | 651 | * NullStr,
|
---|
| 652 | * NULL,
|
---|
| 653 | * "%s /C %s",
|
---|
| 654 | * getenv("COMSPEC"),
|
---|
| 655 | * batchfilename);
|
---|
[105] | 656 | *
|
---|
| 657 | * use (HWND)0 for hwnd if window handle not handy.
|
---|
[888] | 658 | * pszCallingFile and __LINE__ are used to determine caller for easier error tracking
|
---|
[105] | 659 | */
|
---|
[2] | 660 |
|
---|
[920] | 661 | /**
|
---|
[1252] | 662 | * type bitmapped flag -- see systemf.h
|
---|
[2] | 663 | */
|
---|
| 664 |
|
---|
[105] | 665 | va_list parguments;
|
---|
| 666 | int ret = -1;
|
---|
[540] | 667 | RESULTCODES results;
|
---|
[519] | 668 | STARTDATA sdata;
|
---|
[105] | 669 | REQUESTDATA rq;
|
---|
[562] | 670 | ULONG ulSessID;
|
---|
| 671 | ULONG ulLength;
|
---|
| 672 | UINT ctr;
|
---|
| 673 | ULONG ulAppType;
|
---|
[105] | 674 | PID sessPID;
|
---|
| 675 | BOOL wasquote;
|
---|
[540] | 676 | char *pszPgm, *pszArgs = NULL;
|
---|
| 677 | char szObject[32] = "", *p, szSavedir[CCHMAXPATH];
|
---|
| 678 | BOOL useTermQ = FALSE;
|
---|
| 679 | char szTempdir[CCHMAXPATH];
|
---|
| 680 |
|
---|
[519] | 681 | typedef struct {
|
---|
| 682 | USHORT usSessID;
|
---|
| 683 | USHORT usRC;
|
---|
| 684 | } TERMINFO;
|
---|
| 685 |
|
---|
[540] | 686 | TERMINFO *pTermInfo;
|
---|
[105] | 687 | BYTE bPriority;
|
---|
| 688 | APIRET rc;
|
---|
[519] | 689 | PIB *ppib;
|
---|
| 690 | TIB *ptib;
|
---|
[2] | 691 |
|
---|
[540] | 692 | // Shared by all threads
|
---|
| 693 | # define TERMQ_BASE_NAME "\\QUEUES\\FM3WAIT"
|
---|
| 694 | static char szTermQName[30];
|
---|
| 695 | static HQUEUE hTermQ;
|
---|
[1268] | 696 | //static HEV hTermQSem;
|
---|
[540] | 697 |
|
---|
| 698 | if (pszDirectory && *pszDirectory) {
|
---|
| 699 | if (!DosQueryPathInfo(pszDirectory,
|
---|
[1162] | 700 | FIL_QUERYFULLNAME,
|
---|
| 701 | szTempdir,
|
---|
| 702 | sizeof(szTempdir)))
|
---|
[540] | 703 | pszDirectory = szTempdir;
|
---|
[105] | 704 | }
|
---|
[2] | 705 |
|
---|
[105] | 706 | if (!hwnd)
|
---|
| 707 | hwnd = HWND_DESKTOP;
|
---|
[2] | 708 |
|
---|
[540] | 709 | rc = DosAllocMem((PVOID)&pszPgm,
|
---|
[1162] | 710 | MaxComLineStrg,
|
---|
| 711 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
[330] | 712 | if (rc) {
|
---|
| 713 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
[105] | 714 | return -1;
|
---|
[330] | 715 | }
|
---|
[2] | 716 |
|
---|
[540] | 717 | *szSavedir = 0;
|
---|
[2] | 718 |
|
---|
[540] | 719 | *pszPgm = 0;
|
---|
[105] | 720 | va_start(parguments,
|
---|
[1162] | 721 | formatstring);
|
---|
[540] | 722 | vsprintf(pszPgm,
|
---|
[1162] | 723 | formatstring,
|
---|
| 724 | parguments);
|
---|
[105] | 725 | va_end(parguments);
|
---|
[906] | 726 |
|
---|
[540] | 727 | if (pszEnvironment) {
|
---|
| 728 | p = &pszEnvironment[strlen(pszEnvironment)] + 1;
|
---|
[105] | 729 | *p = 0;
|
---|
[540] | 730 | p = pszEnvironment;
|
---|
[373] | 731 | while ((p = convert_nl_to_nul(p)) != NULL)
|
---|
| 732 | ; // loop
|
---|
[105] | 733 | }
|
---|
[2] | 734 |
|
---|
[540] | 735 | if (!*pszPgm) {
|
---|
[105] | 736 | p = GetCmdSpec(FALSE);
|
---|
[540] | 737 | strcpy(pszPgm, p);
|
---|
| 738 | if (!*pszPgm) {
|
---|
[441] | 739 | Runtime_Error2(pszSrcFile, __LINE__, IDS_NODATATEXT);
|
---|
[105] | 740 | return -1;
|
---|
[441] | 741 | }
|
---|
[105] | 742 | }
|
---|
[2] | 743 |
|
---|
[540] | 744 | if (*pszPgm) {
|
---|
| 745 | if (*pszPgm == '<' && strchr(pszPgm, '>')) {
|
---|
[441] | 746 | /* is a workplace object */
|
---|
[105] | 747 | HOBJECT hWPSObject;
|
---|
| 748 | char temp;
|
---|
[2] | 749 |
|
---|
[540] | 750 | p = strchr(pszPgm, '>');
|
---|
[105] | 751 | p++;
|
---|
| 752 | temp = *p;
|
---|
[330] | 753 | if (temp) {
|
---|
[1162] | 754 | rc = DosAllocMem((PVOID)&pszArgs,
|
---|
| 755 | MaxComLineStrg * 2,
|
---|
| 756 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
| 757 | if (rc)
|
---|
| 758 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
[330] | 759 | }
|
---|
[105] | 760 | else
|
---|
[1162] | 761 | pszArgs = NULL;
|
---|
[105] | 762 | *p = 0;
|
---|
| 763 | /* Find the handle of the WPS object */
|
---|
[540] | 764 | hWPSObject = WinQueryObject(pszPgm);
|
---|
[105] | 765 | *p = temp;
|
---|
[441] | 766 | if (hWPSObject != NULLHANDLE) {
|
---|
[1162] | 767 | if (pszArgs && *p) {
|
---|
| 768 | sprintf(pszArgs,"OPEN=DEFAULT;PARAMETERS=\"%s\"",p);
|
---|
| 769 | WinSetObjectData(hWPSObject,pszArgs);
|
---|
| 770 | }
|
---|
| 771 | else
|
---|
| 772 | WinSetObjectData(hWPSObject,"OPEN=DEFAULT");
|
---|
| 773 | ret = 0;
|
---|
[105] | 774 | }
|
---|
| 775 | goto ObjectInterrupt;
|
---|
| 776 | }
|
---|
[2] | 777 |
|
---|
[773] | 778 | if ((type & RUNTYPE_MASK) == SYNCHRONOUS ||
|
---|
[1162] | 779 | (type & RUNTYPE_MASK) == ASYNCHRONOUS ||
|
---|
| 780 | (type & RUNTYPE_MASK) == DETACHED)
|
---|
[105] | 781 | {
|
---|
[540] | 782 | strip_lead_char(" \t", pszPgm);
|
---|
| 783 | p = pszPgm;
|
---|
[105] | 784 | wasquote = FALSE;
|
---|
| 785 | while (*p &&
|
---|
[1162] | 786 | (wasquote ||
|
---|
| 787 | (*p != ' ' &&
|
---|
| 788 | *p != '\t')))
|
---|
[105] | 789 | {
|
---|
[1162] | 790 | if (*p == '\"') {
|
---|
| 791 | if (!wasquote) {
|
---|
| 792 | wasquote = TRUE;
|
---|
| 793 | memmove(p,
|
---|
| 794 | p + 1,
|
---|
| 795 | strlen(p));
|
---|
| 796 | while (*p == ' ' ||
|
---|
| 797 | *p == '\t')
|
---|
| 798 | p++;
|
---|
| 799 | }
|
---|
| 800 | else {
|
---|
| 801 | memmove(p,
|
---|
| 802 | p + 1,
|
---|
| 803 | strlen(p));
|
---|
| 804 | break;
|
---|
| 805 | }
|
---|
| 806 | }
|
---|
| 807 | else
|
---|
| 808 | p++;
|
---|
[105] | 809 | }
|
---|
[441] | 810 | if (*p) {
|
---|
[1162] | 811 | *p = 0;
|
---|
| 812 | p++;
|
---|
[105] | 813 | }
|
---|
| 814 | else
|
---|
[1162] | 815 | p = pszPgm;
|
---|
| 816 | p[strlen(p) + 1] = 0; /* double-terminate args */
|
---|
[540] | 817 | if (*pszPgm) {
|
---|
[1162] | 818 | if (!strchr(pszPgm, '\\') &&
|
---|
| 819 | !strchr(pszPgm, ':') &&
|
---|
| 820 | pszDirectory &&
|
---|
| 821 | *pszDirectory)
|
---|
| 822 | {
|
---|
| 823 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 824 | switch_to(pszDirectory);
|
---|
| 825 | }
|
---|
| 826 | rc = DosQueryAppType(pszPgm,&ulAppType);
|
---|
| 827 | if (!strchr(pszPgm, '\\') &&
|
---|
| 828 | !strchr(pszPgm, ':') &&
|
---|
| 829 | pszDirectory &&
|
---|
| 830 | *pszDirectory)
|
---|
| 831 | switch_to(szSavedir);
|
---|
| 832 | if (rc) {
|
---|
| 833 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
|
---|
| 834 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
|
---|
| 835 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 836 | DosFreeMem(pszPgm);
|
---|
| 837 | if (pszArgs)
|
---|
| 838 | DosFreeMem(pszArgs);
|
---|
| 839 | return -1;
|
---|
| 840 | }
|
---|
| 841 | if (ulAppType) {
|
---|
| 842 | if (ulAppType & FAPPTYP_DLL || ulAppType & FAPPTYP_VIRTDRV ||
|
---|
| 843 | ulAppType & FAPPTYP_PHYSDRV || ulAppType & FAPPTYP_PROTDLL)
|
---|
| 844 | {
|
---|
| 845 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
| 846 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
| 847 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 848 | if (pszPgm)
|
---|
| 849 | DosFreeMem(pszPgm);
|
---|
| 850 | if (pszArgs)
|
---|
| 851 | DosFreeMem(pszArgs);
|
---|
| 852 | return -1;
|
---|
| 853 | }
|
---|
| 854 | if (ulAppType & FAPPTYP_DOS || ulAppType & FAPPTYP_WINDOWSREAL ||
|
---|
| 855 | ulAppType & FAPPTYP_WINDOWSPROT || ulAppType & FAPPTYP_WINDOWSPROT31)
|
---|
| 856 | {
|
---|
| 857 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
| 858 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
| 859 | ulAppType, pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 860 | if (pszPgm)
|
---|
| 861 | DosFreeMem(pszPgm);
|
---|
| 862 | if (pszArgs)
|
---|
| 863 | DosFreeMem(pszArgs);
|
---|
| 864 | return -1;
|
---|
| 865 | }
|
---|
| 866 | }
|
---|
| 867 | memset(&results, 0, sizeof(results));
|
---|
| 868 | if (pszDirectory && *pszDirectory) {
|
---|
| 869 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 870 | switch_to(pszDirectory);
|
---|
| 871 | }
|
---|
| 872 | ret = DosExecPgm(szObject, sizeof(szObject),
|
---|
| 873 | ((type & RUNTYPE_MASK) == ASYNCHRONOUS ? EXEC_ASYNC : 0) +
|
---|
| 874 | ((type & RUNTYPE_MASK) == DETACHED ? EXEC_BACKGROUND : 0),
|
---|
| 875 | pszPgm, pszEnvironment, &results, pszPgm);
|
---|
| 876 | if (pszDirectory && *pszDirectory)
|
---|
| 877 | switch_to(szSavedir);
|
---|
| 878 | if (ret) {
|
---|
| 879 | Dos_Error(MB_ENTER,ret,hwnd,pszSrcFile,__LINE__,
|
---|
| 880 | GetPString(IDS_DOSEXECPGMFAILEDTEXT), pszPgm,
|
---|
| 881 | pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 882 | }
|
---|
[105] | 883 | }
|
---|
| 884 | }
|
---|
[441] | 885 | else {
|
---|
[519] | 886 | if (~type & FULLSCREEN)
|
---|
[1162] | 887 | type |= WINDOWED;
|
---|
[985] | 888 | rc = DosAllocMem((PVOID) & pszArgs, MaxComLineStrg * 2,
|
---|
[1162] | 889 | PAG_COMMIT | OBJ_TILE | PAG_READ | PAG_WRITE);
|
---|
[441] | 890 | if (rc) {
|
---|
[1162] | 891 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,GetPString(IDS_OUTOFMEMORY));
|
---|
| 892 | DosFreeMem(pszPgm);
|
---|
| 893 | return -1;
|
---|
[105] | 894 | }
|
---|
[540] | 895 | *pszArgs = 0;
|
---|
| 896 | memset(&sdata, 0, sizeof(sdata));
|
---|
| 897 | strip_lead_char(" \t", pszPgm);
|
---|
| 898 | p = pszPgm;
|
---|
[105] | 899 | wasquote = FALSE;
|
---|
[441] | 900 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
[1162] | 901 | if (*p == '\"') {
|
---|
| 902 | if (!wasquote) {
|
---|
| 903 | wasquote = TRUE;
|
---|
| 904 | memmove(p, p + 1, strlen(p));
|
---|
| 905 | while (*p == ' ' || *p == '\t')
|
---|
| 906 | p++;
|
---|
| 907 | }
|
---|
| 908 | else {
|
---|
| 909 | memmove(p, p + 1, strlen(p));
|
---|
| 910 | break;
|
---|
| 911 | }
|
---|
| 912 | }
|
---|
| 913 | else
|
---|
| 914 | p++;
|
---|
[540] | 915 | } // while
|
---|
[441] | 916 | if (*p) {
|
---|
[1162] | 917 | *p = 0;
|
---|
| 918 | p++;
|
---|
[105] | 919 | }
|
---|
| 920 | else
|
---|
[1162] | 921 | p = NullStr;
|
---|
[105] | 922 | if (*p)
|
---|
[1162] | 923 | strcpy(pszArgs, p);
|
---|
[2] | 924 |
|
---|
[540] | 925 | p = strrchr(pszPgm, '.');
|
---|
[441] | 926 | if (p) {
|
---|
[1162] | 927 | char temp[CCHMAXPATH + 1];
|
---|
[2] | 928 |
|
---|
[1162] | 929 | if (!stricmp(p, ".BAT")) {
|
---|
| 930 | strcpy(temp, pszPgm);
|
---|
| 931 | strcpy(pszPgm, pszArgs);
|
---|
| 932 | strcpy(pszArgs, "/C ");
|
---|
| 933 | strcat(pszArgs, temp);
|
---|
| 934 | strcat(pszArgs, " ");
|
---|
| 935 | strcat(pszArgs, pszPgm);
|
---|
| 936 | strcpy(pszPgm, GetCmdSpec(TRUE)); // DOS
|
---|
| 937 | }
|
---|
| 938 | else if (!stricmp(p, ".CMD") || !stricmp(p, ".BTM")) {
|
---|
| 939 | // Assume 4OS2 is BTM
|
---|
| 940 | strcpy(temp, pszPgm);
|
---|
| 941 | strcpy(pszPgm, pszArgs);
|
---|
| 942 | strcpy(pszArgs, "/C ");
|
---|
| 943 | strcat(pszArgs, temp);
|
---|
| 944 | strcat(pszArgs, " ");
|
---|
| 945 | strcat(pszArgs, pszPgm);
|
---|
| 946 | strcpy(pszPgm, GetCmdSpec(FALSE)); // OS/2
|
---|
| 947 | }
|
---|
[105] | 948 | }
|
---|
[2] | 949 |
|
---|
[888] | 950 | // goddamned OS/2 limit
|
---|
[2] | 951 |
|
---|
[540] | 952 | if (strlen(pszPgm) + strlen(pszArgs) > 1024)
|
---|
[1162] | 953 | pszArgs[1024 - strlen(pszPgm)] = 0;
|
---|
[2] | 954 |
|
---|
[540] | 955 | if (!strchr(pszPgm, '\\') &&
|
---|
[1162] | 956 | !strchr(pszPgm, ':') &&
|
---|
| 957 | pszDirectory &&
|
---|
| 958 | *pszDirectory)
|
---|
[105] | 959 | {
|
---|
[1162] | 960 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 961 | switch_to(pszDirectory);
|
---|
[105] | 962 | }
|
---|
[562] | 963 | rc = DosQueryAppType(pszPgm,&ulAppType);
|
---|
[540] | 964 | if (!strchr(pszPgm, '\\') &&
|
---|
[1162] | 965 | !strchr(pszPgm, ':') &&
|
---|
| 966 | pszDirectory &&
|
---|
| 967 | *pszDirectory)
|
---|
| 968 | switch_to(szSavedir);
|
---|
[917] | 969 | if (rc) {
|
---|
[1162] | 970 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,
|
---|
| 971 | GetPString(IDS_DOSQAPPTYPEFAILEDTEXT),
|
---|
| 972 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 973 | DosFreeMem(pszPgm);
|
---|
| 974 | if (pszArgs)
|
---|
| 975 | DosFreeMem(pszArgs);
|
---|
| 976 | return -1;
|
---|
[105] | 977 | }
|
---|
[2] | 978 |
|
---|
[562] | 979 | if (ulAppType) {
|
---|
[1162] | 980 | if (ulAppType & (FAPPTYP_DLL | FAPPTYP_VIRTDRV | FAPPTYP_PHYSDRV | FAPPTYP_PROTDLL))
|
---|
| 981 | {
|
---|
| 982 | Runtime_Error(pszSrcFile, __LINE__,
|
---|
| 983 | GetPString(IDS_APPTYPEUNEXPECTEDTEXT),
|
---|
| 984 | pszPgm, pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
| 985 | DosFreeMem(pszPgm);
|
---|
| 986 | if (pszArgs)
|
---|
| 987 | DosFreeMem(pszArgs);
|
---|
| 988 | return -1;
|
---|
| 989 | }
|
---|
| 990 | ulAppType &= ~FAPPTYP_BOUND;
|
---|
| 991 | if (ulAppType & (FAPPTYP_DOS | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
| 992 | {
|
---|
| 993 | if (ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
| 994 | {
|
---|
| 995 | if (~type & FULLSCREEN &&
|
---|
| 996 | ulAppType & (FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSPROT31))
|
---|
| 997 | {
|
---|
| 998 | ret = RunSeamless(pszPgm, pszArgs, hwnd);
|
---|
| 999 | if (pszPgm)
|
---|
| 1000 | DosFreeMem(pszPgm);
|
---|
| 1001 | if (pszArgs)
|
---|
| 1002 | DosFreeMem(pszArgs);
|
---|
| 1003 | return ret ? 0 : -1;
|
---|
| 1004 | }
|
---|
| 1005 | else {
|
---|
| 1006 | strcat(pszPgm, " ");
|
---|
| 1007 | strcat(pszPgm, pszArgs);
|
---|
| 1008 | *pszArgs = 0;
|
---|
| 1009 | if (ulAppType & (FAPPTYP_WINDOWSPROT | FAPPTYP_WINDOWSREAL | FAPPTYP_WINDOWSPROT31))
|
---|
| 1010 | strcat(pszArgs, "/3 ");
|
---|
| 1011 | strcat(pszArgs, pszPgm);
|
---|
| 1012 | strcpy(pszPgm, "WINOS2.COM");
|
---|
| 1013 | }
|
---|
| 1014 | }
|
---|
| 1015 | else {
|
---|
| 1016 | if (~type & FULLSCREEN) {
|
---|
| 1017 | type |= WINDOWED;
|
---|
| 1018 | ulAppType = SSF_TYPE_WINDOWEDVDM;
|
---|
| 1019 | }
|
---|
| 1020 | else {
|
---|
| 1021 | type &= ~WINDOWED;
|
---|
| 1022 | ulAppType = SSF_TYPE_VDM;
|
---|
| 1023 | }
|
---|
| 1024 | }
|
---|
| 1025 | }
|
---|
| 1026 | else if (ulAppType & FAPPTYP_32BIT) {
|
---|
| 1027 | ulAppType &= ~FAPPTYP_32BIT;
|
---|
| 1028 | if (ulAppType == FAPPTYP_WINDOWAPI)
|
---|
| 1029 | ulAppType = SSF_TYPE_PM;
|
---|
| 1030 | else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
|
---|
| 1031 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 1032 | else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
| 1033 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
| 1034 | type &= ~WINDOWED;
|
---|
| 1035 | type |= FULLSCREEN;
|
---|
| 1036 | }
|
---|
| 1037 | else /* ? */
|
---|
| 1038 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 1039 | }
|
---|
| 1040 | else if (ulAppType == FAPPTYP_WINDOWAPI)
|
---|
| 1041 | ulAppType = SSF_TYPE_PM;
|
---|
| 1042 | else if (ulAppType == FAPPTYP_WINDOWCOMPAT)
|
---|
| 1043 | ulAppType = SSF_TYPE_WINDOWABLEVIO;
|
---|
| 1044 | else if (ulAppType == FAPPTYP_NOTWINDOWCOMPAT) {
|
---|
| 1045 | type &= ~WINDOWED;
|
---|
| 1046 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
| 1047 | }
|
---|
| 1048 | else
|
---|
| 1049 | ulAppType = SSF_TYPE_DEFAULT;
|
---|
| 1050 | if ((type & FULLSCREEN || ~type & WINDOWED) &&
|
---|
| 1051 | ulAppType == SSF_TYPE_WINDOWABLEVIO)
|
---|
| 1052 | {
|
---|
| 1053 | ulAppType = SSF_TYPE_FULLSCREEN;
|
---|
| 1054 | }
|
---|
| 1055 | // fixme parens?
|
---|
| 1056 | else if (type & FULLSCREEN ||
|
---|
| 1057 | (type & WINDOWED && ulAppType == SSF_TYPE_WINDOWEDVDM))
|
---|
| 1058 | {
|
---|
| 1059 | ulAppType = SSF_TYPE_VDM;
|
---|
| 1060 | }
|
---|
[105] | 1061 | }
|
---|
[562] | 1062 | if (ulAppType == SSF_TYPE_WINDOWEDVDM && type & SEPARATEKEEP) {
|
---|
[1162] | 1063 | type &= ~SEPARATEKEEP;
|
---|
| 1064 | type |= SEPARATE;
|
---|
[105] | 1065 | }
|
---|
[2] | 1066 |
|
---|
[519] | 1067 | DosGetInfoBlocks(&ptib, &ppib);
|
---|
| 1068 |
|
---|
[540] | 1069 | if (~type & WAIT)
|
---|
[1162] | 1070 | useTermQ = FALSE;
|
---|
[519] | 1071 | else {
|
---|
[1162] | 1072 | rc = 0;
|
---|
| 1073 | DosEnterCritSec();
|
---|
| 1074 | if (!hTermQ) {
|
---|
| 1075 | // Create term queue and event semaphore just once
|
---|
| 1076 | sprintf(szTermQName, TERMQ_BASE_NAME "_%x", ppib->pib_ulpid);
|
---|
| 1077 | rc = DosCreateQueue(&hTermQ, QUE_FIFO | QUE_CONVERT_ADDRESS, szTermQName);
|
---|
| 1078 | if (rc) {
|
---|
| 1079 | hTermQ = (HQUEUE)0; // Try to survive
|
---|
| 1080 | DosExitCritSec();
|
---|
| 1081 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosCreateQueue");
|
---|
| 1082 | }
|
---|
| 1083 | else {
|
---|
[1268] | 1084 | rc = DosCreateEventSem(NULL,(PHEV)&hWaitChildSem,0,FALSE);
|
---|
[1162] | 1085 | if (rc) {
|
---|
[1268] | 1086 | hWaitChildSem = (HEV)0; // Try to survive
|
---|
[1162] | 1087 | DosCloseQueue(hTermQ);
|
---|
| 1088 | hTermQ = (HQUEUE)0; // Try to survive
|
---|
| 1089 | DosExitCritSec();
|
---|
[1268] | 1090 | Dos_Error(MB_ENTER,rc,HWND_DESKTOP,pszSrcFile,__LINE__,"DosCreateEventSem");
|
---|
[1162] | 1091 | }
|
---|
| 1092 | // if (!rc) fprintf(stderr,"%s %d qcreated ptib %x hTermQ %x\n",__FILE__, __LINE__,ptib,hTermQ);
|
---|
| 1093 | }
|
---|
| 1094 | } // if 1st time
|
---|
[1268] | 1095 | useTermQ = hTermQ && hWaitChildSem;
|
---|
[1162] | 1096 | if (!rc)
|
---|
| 1097 | DosExitCritSec();
|
---|
[540] | 1098 | } // if wait
|
---|
[562] | 1099 |
|
---|
| 1100 | memset(&sdata,0,sizeof(sdata));
|
---|
[519] | 1101 | sdata.Length = sizeof(sdata);
|
---|
[562] | 1102 | sdata.Related = type & (WAIT | CHILD) ? SSF_RELATED_CHILD :
|
---|
[1162] | 1103 | SSF_RELATED_INDEPENDENT;
|
---|
[519] | 1104 | sdata.FgBg = type & BACKGROUND ? SSF_FGBG_BACK : SSF_FGBG_FORE;
|
---|
| 1105 | sdata.TraceOpt = SSF_TRACEOPT_NONE;
|
---|
[540] | 1106 | sdata.PgmName = pszPgm;
|
---|
[562] | 1107 | if (*pszArgs)
|
---|
[1162] | 1108 | sdata.PgmInputs = pszArgs;
|
---|
[562] | 1109 | if (useTermQ)
|
---|
[1162] | 1110 | sdata.TermQ = szTermQName;
|
---|
[540] | 1111 | sdata.Environment = pszEnvironment;
|
---|
[519] | 1112 | sdata.InheritOpt = SSF_INHERTOPT_PARENT;
|
---|
[562] | 1113 | sdata.SessionType = ulAppType;
|
---|
[540] | 1114 | sdata.ObjectBuffer = szObject;
|
---|
| 1115 | sdata.ObjectBuffLen = sizeof(szObject);
|
---|
[773] | 1116 | if ((type & RUNTYPE_MASK) == SEPARATEKEEP)
|
---|
[1162] | 1117 | sdata.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
|
---|
[562] | 1118 | if (type & MAXIMIZED)
|
---|
[1162] | 1119 | sdata.PgmControl |= SSF_CONTROL_MAXIMIZE;
|
---|
[562] | 1120 | if (type & MINIMIZED)
|
---|
[1162] | 1121 | sdata.PgmControl |= SSF_CONTROL_MINIMIZE;
|
---|
[562] | 1122 | if (type & INVISIBLE)
|
---|
[1162] | 1123 | sdata.PgmControl |= SSF_CONTROL_INVISIBLE;
|
---|
[562] | 1124 |
|
---|
[540] | 1125 | if (pszDirectory && *pszDirectory) {
|
---|
[1162] | 1126 | strcpy(szSavedir, pFM2SaveDirectory);
|
---|
| 1127 | switch_to(pszDirectory);
|
---|
[105] | 1128 | }
|
---|
[562] | 1129 |
|
---|
[563] | 1130 | // printf("%s %d DosStartsession thread 0x%x data\n ",
|
---|
[1162] | 1131 | // __FILE__, __LINE__,ptib->tib_ordinal); fflush(stdout); // 10 Mar 07 SHL hang
|
---|
[563] | 1132 | // printf(" %d %d %d %s %s %s %d %d\n %s %x %x\n",
|
---|
[562] | 1133 | // sdata.Length , sdata.Related, sdata.FgBg, sdata.PgmName,
|
---|
[563] | 1134 | // sdata.PgmInputs, sdata.TermQ, sdata.InheritOpt,
|
---|
| 1135 | // sdata.SessionType, szTermQName,
|
---|
[1268] | 1136 | // hTermQ, hWaitChildSem); fflush(stdout);
|
---|
[519] | 1137 | ret = DosStartSession(&sdata, &ulSessID, &sessPID);
|
---|
[562] | 1138 |
|
---|
[563] | 1139 | // if (type & WAIT) {
|
---|
| 1140 | // printf("%s %d DosStartession thread 0x%x rc = %d sess = %u pid = 0x%x\n",
|
---|
[1162] | 1141 | // __FILE__, __LINE__, ptib->tib_ordinal,ret, ulSessID, sessPID); fflush(stdout); // 10 Mar 07 SHL hang
|
---|
[563] | 1142 | // }
|
---|
| 1143 | // else {
|
---|
| 1144 | // printf("%s %d DosStartession thread 0x%x nowait rc = %d\n",
|
---|
[1162] | 1145 | // __FILE__, __LINE__, ptib->tib_ordinal,ret); fflush(stdout); // 10 Mar 07 SHL hang
|
---|
[563] | 1146 | // }
|
---|
| 1147 |
|
---|
[540] | 1148 | if (pszDirectory && *pszDirectory)
|
---|
[1162] | 1149 | switch_to(szSavedir);
|
---|
[562] | 1150 |
|
---|
[330] | 1151 | if (ret && ret != ERROR_SMG_START_IN_BACKGROUND) {
|
---|
[1162] | 1152 | Dos_Error(MB_CANCEL,ret,hwnd,pszSrcFile,__LINE__,
|
---|
| 1153 | GetPString(IDS_DOSSTARTSESSIONFAILEDTEXT),pszPgm,pszArgs,
|
---|
| 1154 | pszCallingFile, uiLineNumber); // 26 May 08 SHL
|
---|
[330] | 1155 | }
|
---|
[441] | 1156 | else if (type & WAIT) {
|
---|
[1162] | 1157 | if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
| 1158 | ShowSession(hwnd, sessPID);
|
---|
[2] | 1159 |
|
---|
[1162] | 1160 | if (!useTermQ) {
|
---|
| 1161 | STATUSDATA sd;
|
---|
| 1162 | // Could not create queue - fallback - fixme to be gone?
|
---|
| 1163 | // printf("%s %d waiting wo/termq\n", __FILE__, __LINE__); fflush(stdout); // 12 Mar 07 SHL hang
|
---|
[2] | 1164 |
|
---|
[1162] | 1165 | memset(&sd, 0, sizeof(sd));
|
---|
| 1166 | sd.Length = (USHORT) sizeof(sd);
|
---|
| 1167 | sd.SelectInd = SET_SESSION_UNCHANGED;
|
---|
| 1168 | sd.BondInd = SET_SESSION_UNCHANGED;
|
---|
| 1169 | for (ctr = 0;; ctr++)
|
---|
| 1170 | {
|
---|
| 1171 | DosSleep(100);//05 Aug 07 GKY 200
|
---|
| 1172 | if (DosSetSession(ulSessID, &sd)) // Check if session gone (i.e. finished)
|
---|
| 1173 | break;
|
---|
[1268] | 1174 | if (ctr > 20) {
|
---|
[1162] | 1175 | // printf("%s %d thread 0x%x showing slow sess %u pid 0x%x\n",
|
---|
| 1176 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,sessPID); fflush(stdout); // 12 Mar 07 SHL
|
---|
| 1177 | ShowSession(hwnd, sessPID); // Show every 2 seconds
|
---|
| 1178 | ctr = 0;
|
---|
| 1179 | }
|
---|
| 1180 | }
|
---|
| 1181 | }
|
---|
| 1182 | else {
|
---|
[1270] | 1183 | ULONG clPosted;
|
---|
| 1184 |
|
---|
| 1185 | DosResetEventSem(hWaitChildSem, &clPosted);
|
---|
[1162] | 1186 | for (ctr = 0;; ctr++)
|
---|
| 1187 | {
|
---|
| 1188 | if (ctr < 20) {
|
---|
| 1189 | rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
[1268] | 1190 | DCWW_NOWAIT, &bPriority, hWaitChildSem);
|
---|
[1162] | 1191 | if (rc == ERROR_QUE_EMPTY) {
|
---|
| 1192 | DosSleep(50);//05 Aug 07 GKY 100
|
---|
| 1193 | continue;
|
---|
| 1194 | }
|
---|
| 1195 | }
|
---|
| 1196 | else {
|
---|
| 1197 | if (ctr == 20) {
|
---|
| 1198 | // printf("%s %d thread 0x%x showing slow sess %u pid 0x%x\n",
|
---|
| 1199 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,sessPID); fflush(stdout);
|
---|
| 1200 | ShowSession(hwnd, sessPID); // Show long running session
|
---|
| 1201 | }
|
---|
| 1202 | rc = DosReadQueue(hTermQ, &rq, &ulLength, (PPVOID)&pTermInfo, 0,
|
---|
| 1203 | DCWW_WAIT, &bPriority, 0);
|
---|
| 1204 | }
|
---|
[540] | 1205 |
|
---|
[1162] | 1206 | if (rc) {
|
---|
| 1207 | // Oh heck
|
---|
| 1208 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosReadQueue");
|
---|
| 1209 | DosSleep(100);//05 Aug 07 GKY 500
|
---|
| 1210 | continue;
|
---|
| 1211 | }
|
---|
[540] | 1212 |
|
---|
[1268] | 1213 | //printf("%s %d DosReadQueue thread 0x%x sess %u sessRC %u rq.pid 0x%x rq.data 0x%x\n",
|
---|
| 1214 | // __FILE__, __LINE__,ptib->tib_ordinal,pTermInfo->usSessID,pTermInfo->usRC,rq.pid, rq.ulData); fflush(stdout);
|
---|
[562] | 1215 |
|
---|
[1268] | 1216 | if (pTermInfo->usSessID == ulSessID) {
|
---|
[1270] | 1217 | DosPostEventSem(hWaitChildSem); //Posted to WaitChildThread (arccnrs.c)
|
---|
[1268] | 1218 | break; // Our session is done
|
---|
| 1219 | }
|
---|
[540] | 1220 |
|
---|
[1162] | 1221 | // Requeue session for other thread
|
---|
| 1222 | {
|
---|
| 1223 | static ULONG ulLastSessID;
|
---|
| 1224 | // printf("%s %d requeue thread 0x%x our sess %u term sess %u term rc %u\n",
|
---|
| 1225 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID,pTermInfo->usSessID,pTermInfo->usRC); fflush(stdout);
|
---|
| 1226 | // fixme to be gone when no longer needed for debug?
|
---|
| 1227 | if (ulLastSessID) {
|
---|
| 1228 | DosSleep(100);//05 Aug 07 GKY 500
|
---|
| 1229 | ulLastSessID = pTermInfo->usSessID;
|
---|
| 1230 | }
|
---|
| 1231 | // requeue term report for other thread and do not free yet
|
---|
| 1232 | rc = DosWriteQueue(hTermQ, rq.ulData, ulLength,(PVOID)pTermInfo, bPriority);
|
---|
| 1233 | if (rc)
|
---|
| 1234 | Dos_Error(MB_CANCEL,rc,hwnd,pszSrcFile,__LINE__,"DosWriteQueue");
|
---|
| 1235 | DosSleep(50); //05 Aug 07 GKY 100 // Let other thread see queue entry
|
---|
| 1236 | }
|
---|
| 1237 | } // for
|
---|
[540] | 1238 |
|
---|
[1162] | 1239 | ret = pTermInfo->usRC == 0; // Set 1 if rc 0 else 0
|
---|
| 1240 | // printf("%s %d thread 0x%x term for sess %u\n",
|
---|
| 1241 | // __FILE__, __LINE__,ptib->tib_ordinal,ulSessID);fflush(stdout);
|
---|
| 1242 | DosFreeMem(pTermInfo);
|
---|
| 1243 | }
|
---|
[540] | 1244 | } // if wait
|
---|
[105] | 1245 | else if (!(type & (BACKGROUND | MINIMIZED | INVISIBLE)))
|
---|
[1162] | 1246 | ShowSession(hwnd, sessPID);
|
---|
[105] | 1247 | }
|
---|
| 1248 | }
|
---|
[2] | 1249 |
|
---|
| 1250 | ObjectInterrupt:
|
---|
| 1251 |
|
---|
[540] | 1252 | if (pszPgm)
|
---|
| 1253 | DosFreeMem(pszPgm);
|
---|
| 1254 | if (pszArgs)
|
---|
| 1255 | DosFreeMem(pszArgs);
|
---|
[562] | 1256 |
|
---|
[105] | 1257 | return ret;
|
---|
[2] | 1258 | }
|
---|
| 1259 |
|
---|
[519] | 1260 | //== Exec() Start application with WinStartApp ==
|
---|
[1193] | 1261 | #if 0 // JBS 11 Sep 08
|
---|
[105] | 1262 | HAPP Exec(HWND hwndNotify, BOOL child, char *startdir, char *env,
|
---|
[1162] | 1263 | PROGTYPE *progt, ULONG fl, char *formatstring,...)
|
---|
[78] | 1264 | {
|
---|
[105] | 1265 | PROGDETAILS pgd;
|
---|
[2] | 1266 | register char *p;
|
---|
[105] | 1267 | char *parameters = NULL, *executable = NULL;
|
---|
[519] | 1268 | HAPP happ = (HAPP)0;
|
---|
[105] | 1269 | ULONG ulOptions = SAF_INSTALLEDCMDLINE;
|
---|
| 1270 | BOOL wasquote;
|
---|
| 1271 | va_list parguments;
|
---|
[2] | 1272 |
|
---|
[105] | 1273 | if (child)
|
---|
[2] | 1274 | ulOptions |= SAF_STARTCHILDAPP;
|
---|
| 1275 |
|
---|
[985] | 1276 | executable = xmallocz(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
[330] | 1277 | if (executable) {
|
---|
[105] | 1278 | va_start(parguments, formatstring);
|
---|
| 1279 | vsprintf(executable, formatstring, parguments);
|
---|
[2] | 1280 | va_end(parguments);
|
---|
[105] | 1281 | strip_lead_char(" \t", executable);
|
---|
[441] | 1282 | if (*executable) {
|
---|
[985] | 1283 | parameters = xmalloc(MaxComLineStrg, pszSrcFile, __LINE__);
|
---|
[441] | 1284 | if (parameters) {
|
---|
[1162] | 1285 | p = executable;
|
---|
| 1286 | wasquote = FALSE;
|
---|
| 1287 | while (*p && (wasquote || (*p != ' ' && *p != '\t'))) {
|
---|
| 1288 | if (*p == '\"') {
|
---|
| 1289 | if (!wasquote) {
|
---|
| 1290 | wasquote = TRUE;
|
---|
| 1291 | memmove(p, p + 1, strlen(p));
|
---|
| 1292 | while (*p == ' ' || *p == '\t')
|
---|
| 1293 | p++;
|
---|
| 1294 | }
|
---|
| 1295 | else {
|
---|
| 1296 | memmove(p, p + 1, strlen(p));
|
---|
| 1297 | break;
|
---|
| 1298 | }
|
---|
| 1299 | }
|
---|
| 1300 | else
|
---|
| 1301 | p++;
|
---|
| 1302 | }
|
---|
| 1303 | if (*p) {
|
---|
| 1304 | *p = 0;
|
---|
| 1305 | p++;
|
---|
| 1306 | }
|
---|
| 1307 | else
|
---|
| 1308 | p = NullStr;
|
---|
| 1309 | if (*p)
|
---|
| 1310 | strcpy(parameters, p);
|
---|
[2] | 1311 |
|
---|
[1162] | 1312 | if (p && (!stricmp(p, ".BAT") || !stricmp(p, ".CMD"))) {
|
---|
| 1313 | char *temp;
|
---|
[2] | 1314 |
|
---|
[1162] | 1315 | temp = xmalloc(CCHMAXPATH * 2,pszSrcFile,__LINE__);
|
---|
| 1316 | if (temp) {
|
---|
| 1317 | if (!stricmp(p, ".BAT")) {
|
---|
| 1318 | strcpy(temp, executable);
|
---|
| 1319 | strcpy(executable, parameters);
|
---|
| 1320 | strcpy(parameters, "/C ");
|
---|
| 1321 | strcat(parameters, temp);
|
---|
| 1322 | strcat(parameters, " ");
|
---|
| 1323 | strcat(parameters, executable);
|
---|
| 1324 | strcpy(executable, GetCmdSpec(TRUE));
|
---|
| 1325 | }
|
---|
| 1326 | else if (!stricmp(p, ".CMD")) {
|
---|
| 1327 | strcpy(temp, executable);
|
---|
| 1328 | strcpy(executable, parameters);
|
---|
| 1329 | strcpy(parameters, "/C ");
|
---|
| 1330 | strcat(parameters, temp);
|
---|
| 1331 | strcat(parameters, " ");
|
---|
| 1332 | strcat(parameters, executable);
|
---|
| 1333 | strcpy(executable, GetCmdSpec(FALSE));
|
---|
| 1334 | }
|
---|
| 1335 | free(temp);
|
---|
| 1336 | }
|
---|
| 1337 | }
|
---|
[2] | 1338 |
|
---|
[1162] | 1339 | memset(&pgd, 0, sizeof(pgd));
|
---|
| 1340 | pgd.Length = sizeof(pgd);
|
---|
| 1341 | pgd.progt = *progt;
|
---|
| 1342 | pgd.swpInitial.fl = fl;
|
---|
| 1343 | pgd.pszEnvironment = env;
|
---|
| 1344 | pgd.pszStartupDir = startdir;
|
---|
| 1345 | pgd.pszParameters = *parameters ? parameters : NULL;
|
---|
| 1346 | pgd.pszExecutable = executable;
|
---|
| 1347 | pgd.swpInitial.hwndInsertBehind = HWND_TOP;
|
---|
| 1348 | happ = WinStartApp(hwndNotify, &pgd, NULL, NULL, ulOptions);
|
---|
| 1349 | free(parameters);
|
---|
[2] | 1350 | }
|
---|
| 1351 | }
|
---|
[1039] | 1352 | free(executable);
|
---|
[2] | 1353 | }
|
---|
| 1354 | return happ;
|
---|
| 1355 | }
|
---|
[1162] | 1356 | #endif
|
---|
[920] | 1357 | #pragma alloc_text(SYSTEMF,ShowSession,ExecOnList,runemf2)
|
---|