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