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