| 1 |
|
|---|
| 2 | /*
|
|---|
| 3 | *@@sourcefile apps.c:
|
|---|
| 4 | * contains program helpers (environments, application start).
|
|---|
| 5 | *
|
|---|
| 6 | * This file is new with V0.9.12 and contains functions
|
|---|
| 7 | * previously in winh.c and dosh2.c.
|
|---|
| 8 | *
|
|---|
| 9 | * Note: Version numbering in this file relates to XWorkplace version
|
|---|
| 10 | * numbering.
|
|---|
| 11 | *
|
|---|
| 12 | *@@header "helpers\apps.h"
|
|---|
| 13 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
|---|
| 14 | */
|
|---|
| 15 |
|
|---|
| 16 | /*
|
|---|
| 17 | * Copyright (C) 1997-2002 Ulrich Mller.
|
|---|
| 18 | * This file is part of the "XWorkplace helpers" source package.
|
|---|
| 19 | * This is free software; you can redistribute it and/or modify
|
|---|
| 20 | * it under the terms of the GNU General Public License as published
|
|---|
| 21 | * by the Free Software Foundation, in version 2 as it comes in the
|
|---|
| 22 | * "COPYING" file of the XWorkplace main distribution.
|
|---|
| 23 | * This program is distributed in the hope that it will be useful,
|
|---|
| 24 | * but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|---|
| 25 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|---|
| 26 | * GNU General Public License for more details.
|
|---|
| 27 | */
|
|---|
| 28 |
|
|---|
| 29 | #define OS2EMX_PLAIN_CHAR
|
|---|
| 30 | // this is needed for "os2emx.h"; if this is defined,
|
|---|
| 31 | // emx will define PSZ as _signed_ char, otherwise
|
|---|
| 32 | // as unsigned char
|
|---|
| 33 |
|
|---|
| 34 | #define INCL_DOSPROCESS
|
|---|
| 35 | #define INCL_DOSEXCEPTIONS
|
|---|
| 36 | #define INCL_DOSMODULEMGR
|
|---|
| 37 | #define INCL_DOSSESMGR
|
|---|
| 38 | #define INCL_DOSERRORS
|
|---|
| 39 |
|
|---|
| 40 | #define INCL_WINPROGRAMLIST // needed for PROGDETAILS, wppgm.h
|
|---|
| 41 | #define INCL_WINSHELLDATA
|
|---|
| 42 | #define INCL_WINERRORS
|
|---|
| 43 | #define INCL_SHLERRORS
|
|---|
| 44 | #include <os2.h>
|
|---|
| 45 |
|
|---|
| 46 | #include <stdio.h>
|
|---|
| 47 | #include <setjmp.h> // needed for except.h
|
|---|
| 48 | #include <assert.h> // needed for except.h
|
|---|
| 49 |
|
|---|
| 50 | #include "setup.h" // code generation and debugging options
|
|---|
| 51 |
|
|---|
| 52 | #include "helpers\dosh.h"
|
|---|
| 53 | #include "helpers\except.h" // exception handling
|
|---|
| 54 | #include "helpers\exeh.h"
|
|---|
| 55 | #include "helpers\prfh.h"
|
|---|
| 56 | #include "helpers\standards.h" // some standard macros
|
|---|
| 57 | #include "helpers\stringh.h"
|
|---|
| 58 | #include "helpers\winh.h"
|
|---|
| 59 | #include "helpers\xstring.h"
|
|---|
| 60 |
|
|---|
| 61 | #include "helpers\apps.h"
|
|---|
| 62 |
|
|---|
| 63 | /*
|
|---|
| 64 | *@@category: Helpers\PM helpers\Application helpers
|
|---|
| 65 | */
|
|---|
| 66 |
|
|---|
| 67 | /* ******************************************************************
|
|---|
| 68 | *
|
|---|
| 69 | * Environment helpers
|
|---|
| 70 | *
|
|---|
| 71 | ********************************************************************/
|
|---|
| 72 |
|
|---|
| 73 | /*
|
|---|
| 74 | *@@ appQueryEnvironmentLen:
|
|---|
| 75 | * returns the total length of the passed in environment
|
|---|
| 76 | * string buffer, including the terminating two null bytes.
|
|---|
| 77 | *
|
|---|
| 78 | *@@added V0.9.16 (2002-01-09) [umoeller]
|
|---|
| 79 | */
|
|---|
| 80 |
|
|---|
| 81 | ULONG appQueryEnvironmentLen(PCSZ pcszEnvironment)
|
|---|
| 82 | {
|
|---|
| 83 | ULONG cbEnvironment = 0;
|
|---|
| 84 | if (pcszEnvironment)
|
|---|
| 85 | {
|
|---|
| 86 | PCSZ pVarThis = pcszEnvironment;
|
|---|
| 87 | // go thru the environment strings; last one has two null bytes
|
|---|
| 88 | while (*pVarThis)
|
|---|
| 89 | {
|
|---|
| 90 | ULONG ulLenThis = strlen(pVarThis) + 1;
|
|---|
| 91 | cbEnvironment += ulLenThis;
|
|---|
| 92 | pVarThis += ulLenThis;
|
|---|
| 93 | }
|
|---|
| 94 |
|
|---|
| 95 | cbEnvironment++; // last null byte
|
|---|
| 96 | }
|
|---|
| 97 |
|
|---|
| 98 | return cbEnvironment;
|
|---|
| 99 | }
|
|---|
| 100 |
|
|---|
| 101 | /*
|
|---|
| 102 | *@@ appParseEnvironment:
|
|---|
| 103 | * this takes one of those ugly environment strings
|
|---|
| 104 | * as used by DosStartSession and WinStartApp (with
|
|---|
| 105 | * lots of zero-terminated strings one after another
|
|---|
| 106 | * and a duplicate zero byte as a terminator) as
|
|---|
| 107 | * input and splits it into an array of separate
|
|---|
| 108 | * strings in pEnv.
|
|---|
| 109 | *
|
|---|
| 110 | * The newly allocated strings are stored in in
|
|---|
| 111 | * pEnv->papszVars. The array count is stored in
|
|---|
| 112 | * pEnv->cVars.
|
|---|
| 113 | *
|
|---|
| 114 | * Each environment variable will be copied into
|
|---|
| 115 | * one newly allocated string in the array. Use
|
|---|
| 116 | * appFreeEnvironment to free the memory allocated
|
|---|
| 117 | * by this function.
|
|---|
| 118 | *
|
|---|
| 119 | * Use the following code to browse thru the array:
|
|---|
| 120 | +
|
|---|
| 121 | + DOSENVIRONMENT Env = {0};
|
|---|
| 122 | + if (appParseEnvironment(pszEnv,
|
|---|
| 123 | + &Env)
|
|---|
| 124 | + == NO_ERROR)
|
|---|
| 125 | + {
|
|---|
| 126 | + if (Env.papszVars)
|
|---|
| 127 | + {
|
|---|
| 128 | + PSZ *ppszThis = Env.papszVars;
|
|---|
| 129 | + for (ul = 0;
|
|---|
| 130 | + ul < Env.cVars;
|
|---|
| 131 | + ul++)
|
|---|
| 132 | + {
|
|---|
| 133 | + PSZ pszThis = *ppszThis;
|
|---|
| 134 | + // pszThis now has something like PATH=C:\TEMP
|
|---|
| 135 | + // ...
|
|---|
| 136 | + // next environment string
|
|---|
| 137 | + ppszThis++;
|
|---|
| 138 | + }
|
|---|
| 139 | + }
|
|---|
| 140 | + appFreeEnvironment(&Env);
|
|---|
| 141 | + }
|
|---|
| 142 | *
|
|---|
| 143 | *@@added V0.9.4 (2000-08-02) [umoeller]
|
|---|
| 144 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
|---|
| 145 | */
|
|---|
| 146 |
|
|---|
| 147 | APIRET appParseEnvironment(const char *pcszEnv,
|
|---|
| 148 | PDOSENVIRONMENT pEnv) // out: new environment
|
|---|
| 149 | {
|
|---|
| 150 | APIRET arc = NO_ERROR;
|
|---|
| 151 | if (!pcszEnv)
|
|---|
| 152 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 153 | else
|
|---|
| 154 | {
|
|---|
| 155 | PSZ pszVarThis = (PSZ)pcszEnv;
|
|---|
| 156 | ULONG cVars = 0;
|
|---|
| 157 | // count strings
|
|---|
| 158 | while (*pszVarThis)
|
|---|
| 159 | {
|
|---|
| 160 | cVars++;
|
|---|
| 161 | pszVarThis += strlen(pszVarThis) + 1;
|
|---|
| 162 | }
|
|---|
| 163 |
|
|---|
| 164 | pEnv->cVars = 0;
|
|---|
| 165 | pEnv->papszVars = 0;
|
|---|
| 166 |
|
|---|
| 167 | if (cVars)
|
|---|
| 168 | {
|
|---|
| 169 | ULONG cbArray = sizeof(PSZ) * cVars;
|
|---|
| 170 | PSZ *papsz;
|
|---|
| 171 | if (!(papsz = (PSZ*)malloc(cbArray)))
|
|---|
| 172 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 173 | else
|
|---|
| 174 | {
|
|---|
| 175 | PSZ *ppszTarget = papsz;
|
|---|
| 176 | memset(papsz, 0, cbArray);
|
|---|
| 177 | pszVarThis = (PSZ)pcszEnv;
|
|---|
| 178 | while (*pszVarThis)
|
|---|
| 179 | {
|
|---|
| 180 | ULONG ulThisLen;
|
|---|
| 181 | if (!(*ppszTarget = strhdup(pszVarThis, &ulThisLen)))
|
|---|
| 182 | {
|
|---|
| 183 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 184 | break;
|
|---|
| 185 | }
|
|---|
| 186 | (pEnv->cVars)++;
|
|---|
| 187 | ppszTarget++;
|
|---|
| 188 | pszVarThis += ulThisLen + 1;
|
|---|
| 189 | }
|
|---|
| 190 |
|
|---|
| 191 | pEnv->papszVars = papsz;
|
|---|
| 192 | }
|
|---|
| 193 | }
|
|---|
| 194 | }
|
|---|
| 195 |
|
|---|
| 196 | return arc;
|
|---|
| 197 | }
|
|---|
| 198 |
|
|---|
| 199 | /*
|
|---|
| 200 | *@@ appGetEnvironment:
|
|---|
| 201 | * calls appParseEnvironment for the current
|
|---|
| 202 | * process environment, which is retrieved from
|
|---|
| 203 | * the info blocks.
|
|---|
| 204 | *
|
|---|
| 205 | * Returns:
|
|---|
| 206 | *
|
|---|
| 207 | * -- NO_ERROR:
|
|---|
| 208 | *
|
|---|
| 209 | * -- ERROR_INVALID_PARAMETER
|
|---|
| 210 | *
|
|---|
| 211 | * -- ERROR_BAD_ENVIRONMENT: no environment found in
|
|---|
| 212 | * info blocks.
|
|---|
| 213 | *
|
|---|
| 214 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
|---|
| 215 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
|---|
| 216 | */
|
|---|
| 217 |
|
|---|
| 218 | APIRET appGetEnvironment(PDOSENVIRONMENT pEnv)
|
|---|
| 219 | {
|
|---|
| 220 | APIRET arc = NO_ERROR;
|
|---|
| 221 | if (!pEnv)
|
|---|
| 222 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 223 | else
|
|---|
| 224 | {
|
|---|
| 225 | PTIB ptib = 0;
|
|---|
| 226 | PPIB ppib = 0;
|
|---|
| 227 | arc = DosGetInfoBlocks(&ptib, &ppib);
|
|---|
| 228 | if (arc == NO_ERROR)
|
|---|
| 229 | {
|
|---|
| 230 | PSZ pszEnv;
|
|---|
| 231 | if (pszEnv = ppib->pib_pchenv)
|
|---|
| 232 | arc = appParseEnvironment(pszEnv, pEnv);
|
|---|
| 233 | else
|
|---|
| 234 | arc = ERROR_BAD_ENVIRONMENT;
|
|---|
| 235 | }
|
|---|
| 236 | }
|
|---|
| 237 |
|
|---|
| 238 | return arc;
|
|---|
| 239 | }
|
|---|
| 240 |
|
|---|
| 241 | /*
|
|---|
| 242 | *@@ appFindEnvironmentVar:
|
|---|
| 243 | * returns the PSZ* in the pEnv->papszVars array
|
|---|
| 244 | * which specifies the environment variable in pszVarName.
|
|---|
| 245 | *
|
|---|
| 246 | * With pszVarName, you can either specify the variable
|
|---|
| 247 | * name only ("VARNAME") or a full environment string
|
|---|
| 248 | * ("VARNAME=BLAH"). In any case, only the variable name
|
|---|
| 249 | * is compared.
|
|---|
| 250 | *
|
|---|
| 251 | * Returns NULL if no such variable name was found in
|
|---|
| 252 | * the array.
|
|---|
| 253 | *
|
|---|
| 254 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
|---|
| 255 | *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
|
|---|
| 256 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
|---|
| 257 | *@@changed V0.9.16 (2002-01-01) [umoeller]: removed extra heap allocation
|
|---|
| 258 | */
|
|---|
| 259 |
|
|---|
| 260 | PSZ* appFindEnvironmentVar(PDOSENVIRONMENT pEnv,
|
|---|
| 261 | PCSZ pszVarName)
|
|---|
| 262 | {
|
|---|
| 263 | PSZ *ppszRet = 0;
|
|---|
| 264 |
|
|---|
| 265 | if ( (pEnv)
|
|---|
| 266 | && (pEnv->papszVars)
|
|---|
| 267 | && (pszVarName)
|
|---|
| 268 | )
|
|---|
| 269 | {
|
|---|
| 270 | ULONG ul = 0;
|
|---|
| 271 | ULONG ulVarNameLen = 0;
|
|---|
| 272 |
|
|---|
| 273 | PSZ pFirstEqual;
|
|---|
| 274 | // rewrote all the following for speed V0.9.16 (2002-01-01) [umoeller]
|
|---|
| 275 | if (pFirstEqual = strchr(pszVarName, '='))
|
|---|
| 276 | // VAR=VALUE
|
|---|
| 277 | // ^ pFirstEqual
|
|---|
| 278 | ulVarNameLen = pFirstEqual - pszVarName;
|
|---|
| 279 | else
|
|---|
| 280 | ulVarNameLen = strlen(pszVarName);
|
|---|
| 281 |
|
|---|
| 282 | for (ul = 0;
|
|---|
| 283 | ul < pEnv->cVars;
|
|---|
| 284 | ul++)
|
|---|
| 285 | {
|
|---|
| 286 | PSZ pszThis = pEnv->papszVars[ul];
|
|---|
| 287 | if (pFirstEqual = strchr(pszThis, '='))
|
|---|
| 288 | {
|
|---|
| 289 | ULONG ulLenThis = pFirstEqual - pszThis;
|
|---|
| 290 | if ( (ulLenThis == ulVarNameLen)
|
|---|
| 291 | && (!memicmp(pszThis,
|
|---|
| 292 | (PVOID)pszVarName,
|
|---|
| 293 | ulVarNameLen))
|
|---|
| 294 | )
|
|---|
| 295 | {
|
|---|
| 296 | ppszRet = &pEnv->papszVars[ul];
|
|---|
| 297 | break;
|
|---|
| 298 | }
|
|---|
| 299 | }
|
|---|
| 300 | }
|
|---|
| 301 | }
|
|---|
| 302 |
|
|---|
| 303 | return ppszRet;
|
|---|
| 304 | }
|
|---|
| 305 |
|
|---|
| 306 | /*
|
|---|
| 307 | *@@ appSetEnvironmentVar:
|
|---|
| 308 | * sets an environment variable in the specified
|
|---|
| 309 | * environment, which must have been initialized
|
|---|
| 310 | * using appGetEnvironment first.
|
|---|
| 311 | *
|
|---|
| 312 | * pszNewEnv must be a full environment string
|
|---|
| 313 | * in the form "VARNAME=VALUE".
|
|---|
| 314 | *
|
|---|
| 315 | * If "VARNAME" has already been set to something
|
|---|
| 316 | * in the string array in pEnv, that array item
|
|---|
| 317 | * is replaced.
|
|---|
| 318 | *
|
|---|
| 319 | * OTOH, if "VARNAME" has not been set yet, a new
|
|---|
| 320 | * item is added to the array, and pEnv->cVars is
|
|---|
| 321 | * raised by one. In that case, fAddFirst determines
|
|---|
| 322 | * whether the new array item is added to the front
|
|---|
| 323 | * or the tail of the environment list.
|
|---|
| 324 | *
|
|---|
| 325 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
|---|
| 326 | *@@changed V0.9.7 (2000-12-17) [umoeller]: added fAddFirst
|
|---|
| 327 | *@@changed V0.9.12 (2001-05-21) [umoeller]: fixed memory leak
|
|---|
| 328 | *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed crash if !fAddFirst
|
|---|
| 329 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
|---|
| 330 | */
|
|---|
| 331 |
|
|---|
| 332 | APIRET appSetEnvironmentVar(PDOSENVIRONMENT pEnv,
|
|---|
| 333 | PCSZ pszNewEnv,
|
|---|
| 334 | BOOL fAddFirst)
|
|---|
| 335 | {
|
|---|
| 336 | APIRET arc = NO_ERROR;
|
|---|
| 337 | if ((!pEnv) || (!pszNewEnv))
|
|---|
| 338 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 339 | else
|
|---|
| 340 | {
|
|---|
| 341 | if (!pEnv->papszVars)
|
|---|
| 342 | {
|
|---|
| 343 | // no variables set yet:
|
|---|
| 344 | pEnv->papszVars = (PSZ*)malloc(sizeof(PSZ));
|
|---|
| 345 | pEnv->cVars = 1;
|
|---|
| 346 |
|
|---|
| 347 | *(pEnv->papszVars) = strdup(pszNewEnv);
|
|---|
| 348 | }
|
|---|
| 349 | else
|
|---|
| 350 | {
|
|---|
| 351 | PSZ *ppszEnvLine;
|
|---|
| 352 | if (ppszEnvLine = appFindEnvironmentVar(pEnv, pszNewEnv))
|
|---|
| 353 | // was set already: replace
|
|---|
| 354 | arc = strhStore(ppszEnvLine,
|
|---|
| 355 | pszNewEnv,
|
|---|
| 356 | NULL);
|
|---|
| 357 | else
|
|---|
| 358 | {
|
|---|
| 359 | // not set already:
|
|---|
| 360 | PSZ *ppszNew = NULL;
|
|---|
| 361 |
|
|---|
| 362 | // allocate new array, with one new entry
|
|---|
| 363 | // fixed V0.9.12 (2001-05-26) [umoeller], this crashed
|
|---|
| 364 | PSZ *papszNew;
|
|---|
| 365 |
|
|---|
| 366 | if (!(papszNew = (PSZ*)malloc(sizeof(PSZ) * (pEnv->cVars + 1))))
|
|---|
| 367 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 368 | else
|
|---|
| 369 | {
|
|---|
| 370 | if (fAddFirst)
|
|---|
| 371 | {
|
|---|
| 372 | // add as first entry:
|
|---|
| 373 | // overwrite first entry
|
|---|
| 374 | ppszNew = papszNew;
|
|---|
| 375 | // copy old entries
|
|---|
| 376 | memcpy(papszNew + 1, // second new entry
|
|---|
| 377 | pEnv->papszVars, // first old entry
|
|---|
| 378 | sizeof(PSZ) * pEnv->cVars);
|
|---|
| 379 | }
|
|---|
| 380 | else
|
|---|
| 381 | {
|
|---|
| 382 | // append at the tail:
|
|---|
| 383 | // overwrite last entry
|
|---|
| 384 | ppszNew = papszNew + pEnv->cVars;
|
|---|
| 385 | // copy old entries
|
|---|
| 386 | memcpy(papszNew, // first new entry
|
|---|
| 387 | pEnv->papszVars, // first old entry
|
|---|
| 388 | sizeof(PSZ) * pEnv->cVars);
|
|---|
| 389 | }
|
|---|
| 390 |
|
|---|
| 391 | free(pEnv->papszVars); // was missing V0.9.12 (2001-05-21) [umoeller]
|
|---|
| 392 | pEnv->papszVars = papszNew;
|
|---|
| 393 | pEnv->cVars++;
|
|---|
| 394 | *ppszNew = strdup(pszNewEnv);
|
|---|
| 395 | }
|
|---|
| 396 | }
|
|---|
| 397 | }
|
|---|
| 398 | }
|
|---|
| 399 |
|
|---|
| 400 | return arc;
|
|---|
| 401 | }
|
|---|
| 402 |
|
|---|
| 403 |
|
|---|
| 404 | /*
|
|---|
| 405 | *@@ appSetEnvironmentVars:
|
|---|
| 406 | * Apply a number of changes or additions to an environment
|
|---|
| 407 | * initialized by appGetEnvironment. The changes or additions
|
|---|
| 408 | * is to the environment is passed in as a pointer (pcszEnv) to
|
|---|
| 409 | * a set of zero terminated VARNAME=VALUE string which ends with
|
|---|
| 410 | * an empty string. (Hence just like the environment block
|
|---|
| 411 | * representation in OS/2.)
|
|---|
| 412 | *
|
|---|
| 413 | *@@added V1.0.0 (2002-09-04) [bird]
|
|---|
| 414 | */
|
|---|
| 415 |
|
|---|
| 416 | APIRET appSetEnvironmentVars(PDOSENVIRONMENT pEnv,
|
|---|
| 417 | PCSZ pcszEnv)
|
|---|
| 418 | {
|
|---|
| 419 | APIRET arc = NO_ERROR;
|
|---|
| 420 | if ( (!pEnv)
|
|---|
| 421 | || (!pcszEnv)
|
|---|
| 422 | )
|
|---|
| 423 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 424 | else
|
|---|
| 425 | {
|
|---|
| 426 | while (arc == NO_ERROR && *pcszEnv != '\0')
|
|---|
| 427 | {
|
|---|
| 428 | arc = appSetEnvironmentVar(pEnv, pcszEnv, FALSE);
|
|---|
| 429 | pcszEnv += strlen(pcszEnv) + 1;
|
|---|
| 430 | }
|
|---|
| 431 | }
|
|---|
| 432 | return arc;
|
|---|
| 433 | }
|
|---|
| 434 |
|
|---|
| 435 |
|
|---|
| 436 | /*
|
|---|
| 437 | *@@ appConvertEnvironment:
|
|---|
| 438 | * converts an environment initialized by appGetEnvironment
|
|---|
| 439 | * to the string format required by WinStartApp and DosExecPgm,
|
|---|
| 440 | * that is, one memory block is allocated in *ppszEnv and all
|
|---|
| 441 | * strings in pEnv->papszVars are copied to that block. Each
|
|---|
| 442 | * string is terminated with a null character; the last string
|
|---|
| 443 | * is terminated with two null characters.
|
|---|
| 444 | *
|
|---|
| 445 | * Use free() to free the memory block allocated by this
|
|---|
| 446 | * function in *ppszEnv.
|
|---|
| 447 | *
|
|---|
| 448 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
|---|
| 449 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
|---|
| 450 | */
|
|---|
| 451 |
|
|---|
| 452 | APIRET appConvertEnvironment(PDOSENVIRONMENT pEnv,
|
|---|
| 453 | PSZ *ppszEnv, // out: environment string
|
|---|
| 454 | PULONG pulSize) // out: size of block allocated in *ppszEnv; ptr can be NULL
|
|---|
| 455 | {
|
|---|
| 456 | APIRET arc = NO_ERROR;
|
|---|
| 457 | if ( (!pEnv)
|
|---|
| 458 | || (!pEnv->papszVars)
|
|---|
| 459 | )
|
|---|
| 460 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 461 | else
|
|---|
| 462 | {
|
|---|
| 463 | // count memory needed for all strings
|
|---|
| 464 | ULONG cbNeeded = 0,
|
|---|
| 465 | ul = 0;
|
|---|
| 466 | PSZ *ppszThis = pEnv->papszVars;
|
|---|
| 467 |
|
|---|
| 468 | for (ul = 0;
|
|---|
| 469 | ul < pEnv->cVars;
|
|---|
| 470 | ul++)
|
|---|
| 471 | {
|
|---|
| 472 | cbNeeded += strlen(*ppszThis) + 1; // length of string plus null terminator
|
|---|
| 473 |
|
|---|
| 474 | // next environment string
|
|---|
| 475 | ppszThis++;
|
|---|
| 476 | }
|
|---|
| 477 |
|
|---|
| 478 | cbNeeded++; // for another null terminator
|
|---|
| 479 |
|
|---|
| 480 | if (!(*ppszEnv = (PSZ)malloc(cbNeeded)))
|
|---|
| 481 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 482 | else
|
|---|
| 483 | {
|
|---|
| 484 | PSZ pTarget = *ppszEnv;
|
|---|
| 485 | if (pulSize)
|
|---|
| 486 | *pulSize = cbNeeded;
|
|---|
| 487 | ppszThis = pEnv->papszVars;
|
|---|
| 488 |
|
|---|
| 489 | // now copy each string
|
|---|
| 490 | for (ul = 0;
|
|---|
| 491 | ul < pEnv->cVars;
|
|---|
| 492 | ul++)
|
|---|
| 493 | {
|
|---|
| 494 | PSZ pSource = *ppszThis;
|
|---|
| 495 |
|
|---|
| 496 | while ((*pTarget++ = *pSource++))
|
|---|
| 497 | ;
|
|---|
| 498 |
|
|---|
| 499 | // *pTarget++ = 0; // append null terminator per string
|
|---|
| 500 |
|
|---|
| 501 | // next environment string
|
|---|
| 502 | ppszThis++;
|
|---|
| 503 | }
|
|---|
| 504 |
|
|---|
| 505 | *pTarget++ = 0; // append second null terminator
|
|---|
| 506 | }
|
|---|
| 507 | }
|
|---|
| 508 |
|
|---|
| 509 | return arc;
|
|---|
| 510 | }
|
|---|
| 511 |
|
|---|
| 512 | /*
|
|---|
| 513 | *@@ appFreeEnvironment:
|
|---|
| 514 | * frees memory allocated by appGetEnvironment.
|
|---|
| 515 | *
|
|---|
| 516 | *@@added V0.9.4 (2000-07-19) [umoeller]
|
|---|
| 517 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from dosh2.c to apps.c
|
|---|
| 518 | */
|
|---|
| 519 |
|
|---|
| 520 | APIRET appFreeEnvironment(PDOSENVIRONMENT pEnv)
|
|---|
| 521 | {
|
|---|
| 522 | APIRET arc = NO_ERROR;
|
|---|
| 523 | if ( (!pEnv)
|
|---|
| 524 | || (!pEnv->papszVars)
|
|---|
| 525 | )
|
|---|
| 526 | arc = ERROR_INVALID_PARAMETER;
|
|---|
| 527 | else
|
|---|
| 528 | {
|
|---|
| 529 | PSZ *ppszThis = pEnv->papszVars;
|
|---|
| 530 | PSZ pszThis;
|
|---|
| 531 | ULONG ul = 0;
|
|---|
| 532 |
|
|---|
| 533 | for (ul = 0;
|
|---|
| 534 | ul < pEnv->cVars;
|
|---|
| 535 | ul++)
|
|---|
| 536 | {
|
|---|
| 537 | pszThis = *ppszThis;
|
|---|
| 538 | free(pszThis);
|
|---|
| 539 | // *ppszThis = NULL;
|
|---|
| 540 | // next environment string
|
|---|
| 541 | ppszThis++;
|
|---|
| 542 | }
|
|---|
| 543 |
|
|---|
| 544 | free(pEnv->papszVars);
|
|---|
| 545 | pEnv->cVars = 0;
|
|---|
| 546 | }
|
|---|
| 547 |
|
|---|
| 548 | return arc;
|
|---|
| 549 | }
|
|---|
| 550 |
|
|---|
| 551 | /* ******************************************************************
|
|---|
| 552 | *
|
|---|
| 553 | * Application information
|
|---|
| 554 | *
|
|---|
| 555 | ********************************************************************/
|
|---|
| 556 |
|
|---|
| 557 | /*
|
|---|
| 558 | *@@ appQueryAppType:
|
|---|
| 559 | * returns the Control Program (Dos) and
|
|---|
| 560 | * Win* PROG_* application types for the
|
|---|
| 561 | * specified executable. Essentially, this
|
|---|
| 562 | * is a wrapper around DosQueryAppType.
|
|---|
| 563 | *
|
|---|
| 564 | * pcszExecutable must be fully qualified.
|
|---|
| 565 | * You can use doshFindExecutable to qualify
|
|---|
| 566 | * it.
|
|---|
| 567 | *
|
|---|
| 568 | * This returns the APIRET of DosQueryAppType.
|
|---|
| 569 | * If this is NO_ERROR; *pulDosAppType receives
|
|---|
| 570 | * the app type of DosQueryAppType. In addition,
|
|---|
| 571 | * *pulWinAppType is set to one of the following:
|
|---|
| 572 | *
|
|---|
| 573 | * -- PROG_FULLSCREEN
|
|---|
| 574 | *
|
|---|
| 575 | * -- PROG_PDD
|
|---|
| 576 | *
|
|---|
| 577 | * -- PROG_VDD
|
|---|
| 578 | *
|
|---|
| 579 | * -- PROG_DLL
|
|---|
| 580 | *
|
|---|
| 581 | * -- PROG_WINDOWEDVDM
|
|---|
| 582 | *
|
|---|
| 583 | * -- PROG_PM
|
|---|
| 584 | *
|
|---|
| 585 | * -- PROG_31_ENHSEAMLESSCOMMON
|
|---|
| 586 | *
|
|---|
| 587 | * -- PROG_WINDOWABLEVIO
|
|---|
| 588 | *
|
|---|
| 589 | * -- PROG_DEFAULT
|
|---|
| 590 | *
|
|---|
| 591 | *@@added V0.9.9 (2001-03-07) [umoeller]
|
|---|
| 592 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
|---|
| 593 | *@@changed V0.9.14 (2001-08-07) [pr]: use FAPPTYP_* constants
|
|---|
| 594 | *@@changed V0.9.16 (2001-12-08) [umoeller]: added checks for batch files, other optimizations
|
|---|
| 595 | */
|
|---|
| 596 |
|
|---|
| 597 | APIRET appQueryAppType(const char *pcszExecutable,
|
|---|
| 598 | PULONG pulDosAppType, // out: DOS app type
|
|---|
| 599 | PULONG pulWinAppType) // out: PROG_* app type
|
|---|
| 600 | {
|
|---|
| 601 | APIRET arc;
|
|---|
| 602 |
|
|---|
| 603 | /*
|
|---|
| 604 | #define FAPPTYP_NOTSPEC 0x0000
|
|---|
| 605 | #define FAPPTYP_NOTWINDOWCOMPAT 0x0001
|
|---|
| 606 | #define FAPPTYP_WINDOWCOMPAT 0x0002
|
|---|
| 607 | #define FAPPTYP_WINDOWAPI 0x0003
|
|---|
| 608 | #define FAPPTYP_BOUND 0x0008
|
|---|
| 609 | #define FAPPTYP_DLL 0x0010
|
|---|
| 610 | #define FAPPTYP_DOS 0x0020
|
|---|
| 611 | #define FAPPTYP_PHYSDRV 0x0040 // physical device driver
|
|---|
| 612 | #define FAPPTYP_VIRTDRV 0x0080 // virtual device driver
|
|---|
| 613 | #define FAPPTYP_PROTDLL 0x0100 // 'protected memory' dll
|
|---|
| 614 | #define FAPPTYP_WINDOWSREAL 0x0200 // Windows real mode app
|
|---|
| 615 | #define FAPPTYP_WINDOWSPROT 0x0400 // Windows protect mode app
|
|---|
| 616 | #define FAPPTYP_WINDOWSPROT31 0x1000 // Windows 3.1 protect mode app
|
|---|
| 617 | #define FAPPTYP_32BIT 0x4000
|
|---|
| 618 | */
|
|---|
| 619 |
|
|---|
| 620 | ULONG ulWinAppType = PROG_DEFAULT;
|
|---|
| 621 |
|
|---|
| 622 | if (!(arc = DosQueryAppType((PSZ)pcszExecutable, pulDosAppType)))
|
|---|
| 623 | {
|
|---|
| 624 | // clear the 32-bit flag
|
|---|
| 625 | // V0.9.16 (2001-12-08) [umoeller]
|
|---|
| 626 | ULONG ulDosAppType = (*pulDosAppType) & ~FAPPTYP_32BIT,
|
|---|
| 627 | ulLoAppType = ulDosAppType & 0xFFFF;
|
|---|
| 628 |
|
|---|
| 629 | if (ulDosAppType & FAPPTYP_PHYSDRV) // 0x40
|
|---|
| 630 | ulWinAppType = PROG_PDD;
|
|---|
| 631 | else if (ulDosAppType & FAPPTYP_VIRTDRV) // 0x80
|
|---|
| 632 | ulWinAppType = PROG_VDD;
|
|---|
| 633 | else if ((ulDosAppType & 0xF0) == FAPPTYP_DLL) // 0x10
|
|---|
| 634 | // DLL bit set
|
|---|
| 635 | ulWinAppType = PROG_DLL;
|
|---|
| 636 | else if (ulDosAppType & FAPPTYP_DOS) // 0x20
|
|---|
| 637 | // DOS bit set?
|
|---|
| 638 | ulWinAppType = PROG_WINDOWEDVDM;
|
|---|
| 639 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI) == FAPPTYP_WINDOWAPI) // 0x0003)
|
|---|
| 640 | // "Window-API" == PM
|
|---|
| 641 | ulWinAppType = PROG_PM;
|
|---|
| 642 | else if (ulLoAppType == FAPPTYP_WINDOWSREAL)
|
|---|
| 643 | ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // @@todo really?
|
|---|
| 644 | else if ( (ulLoAppType == FAPPTYP_WINDOWSPROT31) // 0x1000) // windows program (?!?)
|
|---|
| 645 | || (ulLoAppType == FAPPTYP_WINDOWSPROT) // ) // windows program (?!?)
|
|---|
| 646 | )
|
|---|
| 647 | ulWinAppType = PROG_31_ENHSEAMLESSCOMMON; // PROG_31_ENH;
|
|---|
| 648 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_WINDOWCOMPAT) // 0x02)
|
|---|
| 649 | ulWinAppType = PROG_WINDOWABLEVIO;
|
|---|
| 650 | else if ((ulDosAppType & FAPPTYP_WINDOWAPI /* 0x03 */ ) == FAPPTYP_NOTWINDOWCOMPAT) // 0x01)
|
|---|
| 651 | ulWinAppType = PROG_FULLSCREEN;
|
|---|
| 652 | }
|
|---|
| 653 |
|
|---|
| 654 | if (ulWinAppType == PROG_DEFAULT)
|
|---|
| 655 | {
|
|---|
| 656 | // added checks for batch files V0.9.16 (2001-12-08) [umoeller]
|
|---|
| 657 | PCSZ pcszExt;
|
|---|
| 658 | if (pcszExt = doshGetExtension(pcszExecutable))
|
|---|
| 659 | {
|
|---|
| 660 | if (!stricmp(pcszExt, "BAT"))
|
|---|
| 661 | {
|
|---|
| 662 | ulWinAppType = PROG_WINDOWEDVDM;
|
|---|
| 663 | arc = NO_ERROR;
|
|---|
| 664 | }
|
|---|
| 665 | else if (!stricmp(pcszExt, "CMD"))
|
|---|
| 666 | {
|
|---|
| 667 | ulWinAppType = PROG_WINDOWABLEVIO;
|
|---|
| 668 | arc = NO_ERROR;
|
|---|
| 669 | }
|
|---|
| 670 | }
|
|---|
| 671 | }
|
|---|
| 672 |
|
|---|
| 673 | *pulWinAppType = ulWinAppType;
|
|---|
| 674 |
|
|---|
| 675 | return arc;
|
|---|
| 676 | }
|
|---|
| 677 |
|
|---|
| 678 | /*
|
|---|
| 679 | *@@ appIsWindowsApp:
|
|---|
| 680 | * checks the specified program category
|
|---|
| 681 | * (PROGDETAILS.progt.progc) for whether
|
|---|
| 682 | * it represents a Win-OS/2 application.
|
|---|
| 683 | *
|
|---|
| 684 | * Returns:
|
|---|
| 685 | *
|
|---|
| 686 | * -- 0: no windows app (it's VIO, OS/2
|
|---|
| 687 | * or DOS fullscreen, or PM).
|
|---|
| 688 | *
|
|---|
| 689 | * -- 1: Win-OS/2 standard app.
|
|---|
| 690 | *
|
|---|
| 691 | * -- 2: Win-OS/2 enhanced-mode app.
|
|---|
| 692 | *
|
|---|
| 693 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
|---|
| 694 | */
|
|---|
| 695 |
|
|---|
| 696 | ULONG appIsWindowsApp(ULONG ulProgCategory)
|
|---|
| 697 | {
|
|---|
| 698 | switch (ulProgCategory)
|
|---|
| 699 | {
|
|---|
| 700 | case PROG_31_ENHSEAMLESSVDM: // 17
|
|---|
| 701 | case PROG_31_ENHSEAMLESSCOMMON: // 18
|
|---|
| 702 | case PROG_31_ENH: // 19
|
|---|
| 703 | return 2;
|
|---|
| 704 |
|
|---|
| 705 | #ifndef PROG_30_STD
|
|---|
| 706 | #define PROG_30_STD (PROGCATEGORY)11
|
|---|
| 707 | #endif
|
|---|
| 708 |
|
|---|
| 709 | #ifndef PROG_30_STDSEAMLESSVDM
|
|---|
| 710 | #define PROG_30_STDSEAMLESSVDM (PROGCATEGORY)13
|
|---|
| 711 | #endif
|
|---|
| 712 |
|
|---|
| 713 | case PROG_WINDOW_REAL: // 10
|
|---|
| 714 | case PROG_30_STD: // 11
|
|---|
| 715 | case PROG_WINDOW_AUTO: // 12
|
|---|
| 716 | case PROG_30_STDSEAMLESSVDM: // 13
|
|---|
| 717 | case PROG_30_STDSEAMLESSCOMMON: // 14
|
|---|
| 718 | case PROG_31_STDSEAMLESSVDM: // 15
|
|---|
| 719 | case PROG_31_STDSEAMLESSCOMMON: // 16
|
|---|
| 720 | case PROG_31_STD: // 20
|
|---|
| 721 | return 1;
|
|---|
| 722 | }
|
|---|
| 723 |
|
|---|
| 724 | return 0;
|
|---|
| 725 | }
|
|---|
| 726 |
|
|---|
| 727 | /* ******************************************************************
|
|---|
| 728 | *
|
|---|
| 729 | * Application start
|
|---|
| 730 | *
|
|---|
| 731 | ********************************************************************/
|
|---|
| 732 |
|
|---|
| 733 | /*
|
|---|
| 734 | *@@ CheckAndQualifyExecutable:
|
|---|
| 735 | * checks the executable in the given PROGDETAILS
|
|---|
| 736 | * for whether it is fully qualified.
|
|---|
| 737 | *
|
|---|
| 738 | * If so, the existence is verified.
|
|---|
| 739 | *
|
|---|
| 740 | * If not, we search for it on the PATH. If we
|
|---|
| 741 | * find it, we use pstrExecutablePath to store
|
|---|
| 742 | * the fully qualified executable and set
|
|---|
| 743 | * pDetails->pszExecutable to it. The caller
|
|---|
| 744 | * must initialize the buffer and clear it
|
|---|
| 745 | * after the call.
|
|---|
| 746 | *
|
|---|
| 747 | * Returns:
|
|---|
| 748 | *
|
|---|
| 749 | * -- NO_ERROR: executable exists and might
|
|---|
| 750 | * have been fully qualified.
|
|---|
| 751 | *
|
|---|
| 752 | * -- ERROR_FILE_NOT_FOUND
|
|---|
| 753 | *
|
|---|
| 754 | *@@added V0.9.20 (2002-07-03) [umoeller]
|
|---|
| 755 | *@@changed V1.0.0 (2002-08-21) [umoeller]: now allowing for UNC
|
|---|
| 756 | */
|
|---|
| 757 |
|
|---|
| 758 | STATIC APIRET CheckAndQualifyExecutable(PPROGDETAILS pDetails, // in/out: program details
|
|---|
| 759 | PXSTRING pstrExecutablePatched) // in/out: buffer for q'fied exec (must be init'ed)
|
|---|
| 760 | {
|
|---|
| 761 | APIRET arc = NO_ERROR;
|
|---|
| 762 |
|
|---|
| 763 | ULONG ulAttr;
|
|---|
| 764 | // check if the executable is fully qualified; if so,
|
|---|
| 765 | // check if the executable file exists
|
|---|
| 766 | if ( // allow UNC V1.0.0 (2002-08-21) [umoeller]
|
|---|
| 767 | ( (pDetails->pszExecutable[0] == '\\')
|
|---|
| 768 | && (pDetails->pszExecutable[1] == '\\')
|
|---|
| 769 | )
|
|---|
| 770 | || ( (pDetails->pszExecutable[1] == ':')
|
|---|
| 771 | && (strchr(pDetails->pszExecutable, '\\'))
|
|---|
| 772 | )
|
|---|
| 773 | )
|
|---|
| 774 | {
|
|---|
| 775 | arc = doshQueryPathAttr(pDetails->pszExecutable,
|
|---|
| 776 | &ulAttr);
|
|---|
| 777 | }
|
|---|
| 778 | else
|
|---|
| 779 | {
|
|---|
| 780 | // _not_ fully qualified: look it up on the PATH then
|
|---|
| 781 | // V0.9.16 (2001-12-06) [umoeller]
|
|---|
| 782 | CHAR szFQExecutable[CCHMAXPATH];
|
|---|
| 783 | if (!(arc = doshSearchPath("PATH",
|
|---|
| 784 | pDetails->pszExecutable,
|
|---|
| 785 | szFQExecutable,
|
|---|
| 786 | sizeof(szFQExecutable))))
|
|---|
| 787 | {
|
|---|
| 788 | // alright, found it:
|
|---|
| 789 | xstrcpy(pstrExecutablePatched, szFQExecutable, 0);
|
|---|
| 790 | pDetails->pszExecutable = pstrExecutablePatched->psz;
|
|---|
| 791 | }
|
|---|
| 792 | }
|
|---|
| 793 |
|
|---|
| 794 | return arc;
|
|---|
| 795 | }
|
|---|
| 796 |
|
|---|
| 797 | /*
|
|---|
| 798 | *@@ CallBatchCorrectly:
|
|---|
| 799 | * fixes the specified PROGDETAILS for
|
|---|
| 800 | * command files in the executable part
|
|---|
| 801 | * by inserting /C XXX into the parameters
|
|---|
| 802 | * and setting the executable to the fully
|
|---|
| 803 | * qualified command interpreter specified
|
|---|
| 804 | * by the given environment variable.
|
|---|
| 805 | *
|
|---|
| 806 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
|---|
| 807 | *@@changed V0.9.7 (2001-01-15) [umoeller]: now using XSTRING
|
|---|
| 808 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
|---|
| 809 | *@@changed V0.9.20 (2002-07-03) [umoeller]: now always qualifying executable to fix broken BAT files
|
|---|
| 810 | *@@changed V1.0.0 (2002-08-12) [umoeller]: this didn't work for batch and cmd files that had "+" characters in their full path, fixed
|
|---|
| 811 | */
|
|---|
| 812 |
|
|---|
| 813 | STATIC APIRET CallBatchCorrectly(PPROGDETAILS pProgDetails,
|
|---|
| 814 | PXSTRING pstrExecutablePatched, // in/out: buffer for q'fied exec (must be init'ed)
|
|---|
| 815 | PXSTRING pstrParams, // in/out: modified parameters (reallocated)
|
|---|
| 816 | const char *pcszEnvVar, // in: env var spec'g command proc
|
|---|
| 817 | // (e.g. "OS2_SHELL"); can be NULL
|
|---|
| 818 | const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE")
|
|---|
| 819 | {
|
|---|
| 820 | APIRET arc = NO_ERROR;
|
|---|
| 821 |
|
|---|
| 822 | // XXX.CMD file as executable:
|
|---|
| 823 | // fix args to /C XXX.CMD
|
|---|
| 824 |
|
|---|
| 825 | PSZ pszOldParams = NULL;
|
|---|
| 826 | ULONG ulOldParamsLength = pstrParams->ulLength;
|
|---|
| 827 | BOOL fQuotes = FALSE;
|
|---|
| 828 |
|
|---|
| 829 | if (ulOldParamsLength)
|
|---|
| 830 | // we have parameters already:
|
|---|
| 831 | // make a backup... we'll append that later
|
|---|
| 832 | pszOldParams = strdup(pstrParams->psz);
|
|---|
| 833 |
|
|---|
| 834 | // set new params to "/C filename.cmd"
|
|---|
| 835 | xstrcpy(pstrParams, "/C ", 0);
|
|---|
| 836 |
|
|---|
| 837 | // if the path has spaces, or other invalid characters,
|
|---|
| 838 | // include it in quotes V1.0.0 (2002-08-12) [umoeller]
|
|---|
| 839 | if (fQuotes = !!strpbrk(pProgDetails->pszExecutable, " +&|="))
|
|---|
| 840 | xstrcatc(pstrParams, '"');
|
|---|
| 841 | // @@bugbug "=" still doesn't work
|
|---|
| 842 |
|
|---|
| 843 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 844 | _PmpfF(("fQuotes (parameters need quotes) is %d", fQuotes));
|
|---|
| 845 | #endif
|
|---|
| 846 |
|
|---|
| 847 | xstrcat(pstrParams,
|
|---|
| 848 | pProgDetails->pszExecutable,
|
|---|
| 849 | 0);
|
|---|
| 850 |
|
|---|
| 851 | if (fQuotes)
|
|---|
| 852 | xstrcatc(pstrParams, '"'); // V1.0.0 (2002-08-12) [umoeller]
|
|---|
| 853 |
|
|---|
| 854 | if (pszOldParams)
|
|---|
| 855 | {
|
|---|
| 856 | // .cmd had params:
|
|---|
| 857 | // append space and old params
|
|---|
| 858 | xstrcatc(pstrParams, ' ');
|
|---|
| 859 | xstrcat(pstrParams,
|
|---|
| 860 | pszOldParams,
|
|---|
| 861 | ulOldParamsLength);
|
|---|
| 862 | free(pszOldParams);
|
|---|
| 863 | }
|
|---|
| 864 |
|
|---|
| 865 | // set executable to $(OS2_SHELL)
|
|---|
| 866 | pProgDetails->pszExecutable = NULL;
|
|---|
| 867 | if (pcszEnvVar)
|
|---|
| 868 | pProgDetails->pszExecutable = getenv(pcszEnvVar);
|
|---|
| 869 | if (!pProgDetails->pszExecutable)
|
|---|
| 870 | pProgDetails->pszExecutable = (PSZ)pcszDefProc;
|
|---|
| 871 | // should be on PATH
|
|---|
| 872 |
|
|---|
| 873 | // and make sure this is always qualified
|
|---|
| 874 | // V0.9.20 (2002-07-03) [umoeller]
|
|---|
| 875 | return CheckAndQualifyExecutable(pProgDetails,
|
|---|
| 876 | pstrExecutablePatched);
|
|---|
| 877 | }
|
|---|
| 878 |
|
|---|
| 879 | /*
|
|---|
| 880 | *@@ appQueryDefaultWin31Environment:
|
|---|
| 881 | * returns the default Win-OS/2 3.1 environment
|
|---|
| 882 | * from OS2.INI, which you can then merge with
|
|---|
| 883 | * your process environment to be able to
|
|---|
| 884 | * start Win-OS/2 sessions properly with
|
|---|
| 885 | * appStartApp.
|
|---|
| 886 | *
|
|---|
| 887 | * Caller must free() the return value.
|
|---|
| 888 | *
|
|---|
| 889 | *@@added V0.9.12 (2001-05-26) [umoeller]
|
|---|
| 890 | *@@changed V0.9.19 (2002-03-28) [umoeller]: now returning APIRET
|
|---|
| 891 | */
|
|---|
| 892 |
|
|---|
| 893 | APIRET appQueryDefaultWin31Environment(PSZ *ppsz)
|
|---|
| 894 | {
|
|---|
| 895 | APIRET arc = NO_ERROR;
|
|---|
| 896 | PSZ pszReturn = NULL;
|
|---|
| 897 | ULONG ulSize = 0;
|
|---|
| 898 |
|
|---|
| 899 | // get default environment (from Win-OS/2 settings object) from OS2.INI
|
|---|
| 900 | PSZ pszDefEnv;
|
|---|
| 901 | if (pszDefEnv = prfhQueryProfileData(HINI_USER,
|
|---|
| 902 | "WINOS2",
|
|---|
| 903 | "PM_GlobalWindows31Settings",
|
|---|
| 904 | &ulSize))
|
|---|
| 905 | {
|
|---|
| 906 | if (pszReturn = (PSZ)malloc(ulSize + 2))
|
|---|
| 907 | {
|
|---|
| 908 | PSZ p;
|
|---|
| 909 | memset(pszReturn, 0, ulSize + 2);
|
|---|
| 910 | memcpy(pszReturn, pszDefEnv, ulSize);
|
|---|
| 911 |
|
|---|
| 912 | for (p = pszReturn;
|
|---|
| 913 | p < pszReturn + ulSize;
|
|---|
| 914 | p++)
|
|---|
| 915 | if (*p == ';')
|
|---|
| 916 | *p = 0;
|
|---|
| 917 |
|
|---|
| 918 | // okay.... now we got an OS/2-style environment
|
|---|
| 919 | // with 0, 0, 00 strings
|
|---|
| 920 |
|
|---|
| 921 | *ppsz = pszReturn;
|
|---|
| 922 | }
|
|---|
| 923 | else
|
|---|
| 924 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 925 |
|
|---|
| 926 | free(pszDefEnv);
|
|---|
| 927 | }
|
|---|
| 928 | else
|
|---|
| 929 | arc = ERROR_BAD_ENVIRONMENT;
|
|---|
| 930 |
|
|---|
| 931 | return arc;
|
|---|
| 932 | }
|
|---|
| 933 |
|
|---|
| 934 | /*
|
|---|
| 935 | *@@ appBuildProgDetails:
|
|---|
| 936 | * extracted code from appStartApp to fix the
|
|---|
| 937 | * given PROGDETAILS data to support the typical
|
|---|
| 938 | * WPS stuff and allocate a single block of
|
|---|
| 939 | * shared memory containing all the data.
|
|---|
| 940 | *
|
|---|
| 941 | * This is now used by XWP's progOpenProgram
|
|---|
| 942 | * directly as a temporary fix for all the
|
|---|
| 943 | * session hangs.
|
|---|
| 944 | *
|
|---|
| 945 | * As input, this takes a PROGDETAILS structure,
|
|---|
| 946 | * which is converted in various ways. In detail,
|
|---|
| 947 | * this supports:
|
|---|
| 948 | *
|
|---|
| 949 | * -- starting "*" executables (command prompts
|
|---|
| 950 | * for OS/2, DOS, Win-OS/2);
|
|---|
| 951 | *
|
|---|
| 952 | * -- starting ".CMD" and ".BAT" files as
|
|---|
| 953 | * PROGDETAILS.pszExecutable; for those, we
|
|---|
| 954 | * convert the executable and parameters to
|
|---|
| 955 | * start CMD.EXE or COMMAND.COM with the "/C"
|
|---|
| 956 | * parameter instead;
|
|---|
| 957 | *
|
|---|
| 958 | * -- starting apps which are not fully qualified
|
|---|
| 959 | * and therefore assumed to be on the PATH
|
|---|
| 960 | * (for which doshSearchPath("PATH") is called).
|
|---|
| 961 | *
|
|---|
| 962 | * Unless it is "*", PROGDETAILS.pszExecutable must
|
|---|
| 963 | * be a proper file name. The full path may be omitted
|
|---|
| 964 | * if it is on the PATH, but the extension (.EXE etc.)
|
|---|
| 965 | * must be given. You can use doshFindExecutable to
|
|---|
| 966 | * find executables if you don't know the extension.
|
|---|
| 967 | *
|
|---|
| 968 | * This also handles and merges special and default
|
|---|
| 969 | * environments for the app to be started. The
|
|---|
| 970 | * following should be respected:
|
|---|
| 971 | *
|
|---|
| 972 | * -- As with WinStartApp, if PROGDETAILS.pszEnvironment
|
|---|
| 973 | * is NULL, the new app inherits the default environment
|
|---|
| 974 | * from the shell.
|
|---|
| 975 | *
|
|---|
| 976 | * -- However, if you specify an environment, you _must_
|
|---|
| 977 | * specify a complete environment. This function
|
|---|
| 978 | * will not merge environments. Use
|
|---|
| 979 | * appSetEnvironmentVar to change environment
|
|---|
| 980 | * variables in a complete environment set.
|
|---|
| 981 | *
|
|---|
| 982 | * -- If PROGDETAILS specifies a Win-OS/2 session
|
|---|
| 983 | * and PROGDETAILS.pszEnvironment is empty,
|
|---|
| 984 | * this uses the default Win-OS/2 environment
|
|---|
| 985 | * from OS2.INI. See appQueryDefaultWin31Environment.
|
|---|
| 986 | *
|
|---|
| 987 | * Even though this isn't clearly said in PMREF,
|
|---|
| 988 | * PROGDETAILS.swpInitial is important:
|
|---|
| 989 | *
|
|---|
| 990 | * -- To start a session minimized, set fl to SWP_MINIMIZE.
|
|---|
| 991 | *
|
|---|
| 992 | * -- To start a VIO session with auto-close disabled,
|
|---|
| 993 | * set the half-documented SWP_NOAUTOCLOSE flag (0x8000)
|
|---|
| 994 | * This flag is now in the newer toolkit headers.
|
|---|
| 995 | *
|
|---|
| 996 | * In addition, this supports the following session
|
|---|
| 997 | * flags with ulFlags if PROG_DEFAULT is specified:
|
|---|
| 998 | *
|
|---|
| 999 | * -- APP_RUN_FULLSCREEN: start a fullscreen session
|
|---|
| 1000 | * for VIO, DOS, and Win-OS/2 programs. Otherwise
|
|---|
| 1001 | * we start a windowed or (share) a seamless session.
|
|---|
| 1002 | * Ignored if the program is PM.
|
|---|
| 1003 | *
|
|---|
| 1004 | * -- APP_RUN_ENHANCED: for Win-OS/2 sessions, use
|
|---|
| 1005 | * enhanced mode.
|
|---|
| 1006 | * Ignored if the program is not Win-OS/2.
|
|---|
| 1007 | *
|
|---|
| 1008 | * -- APP_RUN_STANDARD: for Win-OS/2 sessions, use
|
|---|
| 1009 | * standard mode.
|
|---|
| 1010 | * Ignored if the program is not Win-OS/2.
|
|---|
| 1011 | *
|
|---|
| 1012 | * -- APP_RUN_SEPARATE: for Win-OS/2 sessions, use
|
|---|
| 1013 | * a separate session.
|
|---|
| 1014 | * Ignored if the program is not Win-OS/2.
|
|---|
| 1015 | *
|
|---|
| 1016 | * If NO_ERROR is returned, *ppDetails receives a
|
|---|
| 1017 | * new buffer of shared memory containing all the
|
|---|
| 1018 | * data packed together.
|
|---|
| 1019 | *
|
|---|
| 1020 | * The shared memory is allocated unnamed and
|
|---|
| 1021 | * with OBJ_GETTABLE. It is the responsibility
|
|---|
| 1022 | * of the caller to call DosFreeMem on that buffer.
|
|---|
| 1023 | *
|
|---|
| 1024 | * Returns:
|
|---|
| 1025 | *
|
|---|
| 1026 | * -- NO_ERROR
|
|---|
| 1027 | *
|
|---|
| 1028 | * -- ERROR_INVALID_PARAMETER: pcProgDetails or
|
|---|
| 1029 | * ppDetails is NULL; or PROGDETAILS.pszExecutable is NULL.
|
|---|
| 1030 | *
|
|---|
| 1031 | * -- ERROR_FILE_NOT_FOUND, ERROR_PATH_NOT_FOUND:
|
|---|
| 1032 | * PROGDETAILS.pszExecutable and/or PROGDETAILS.pszStartupDir
|
|---|
| 1033 | * are invalid.
|
|---|
| 1034 | * A NULL PROGDETAILS.pszStartupDir is supported though.
|
|---|
| 1035 | *
|
|---|
| 1036 | * -- ERROR_BAD_FORMAT
|
|---|
| 1037 | *
|
|---|
| 1038 | * -- ERROR_BAD_ENVIRONMENT: environment is larger than 60.000 bytes.
|
|---|
| 1039 | *
|
|---|
| 1040 | * -- ERROR_NOT_ENOUGH_MEMORY
|
|---|
| 1041 | *
|
|---|
| 1042 | * plus the error codes from doshQueryPathAttr, doshSearchPath,
|
|---|
| 1043 | * appParseEnvironment, appSetEnvironmentVar, and appConvertEnvironment.
|
|---|
| 1044 | *
|
|---|
| 1045 | *@@added V0.9.18 (2002-03-27) [umoeller]
|
|---|
| 1046 | *@@changed V0.9.19 (2002-03-28) [umoeller]: now allocating contiguous buffer
|
|---|
| 1047 | *@@changed V0.9.20 (2002-07-03) [umoeller]: fixed Win-OS/2 full screen breakage
|
|---|
| 1048 | *@@changed V0.9.20 (2002-07-03) [umoeller]: fixed broken bat and cmd files when PROG_DEFAULT was set
|
|---|
| 1049 | *@@changed V1.0.0 (2002-08-18) [umoeller]: fixed cmd and bat files that had "=" in their paths
|
|---|
| 1050 | */
|
|---|
| 1051 |
|
|---|
| 1052 | APIRET appBuildProgDetails(PPROGDETAILS *ppDetails, // out: shared mem with fixed program spec (req.)
|
|---|
| 1053 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
|---|
| 1054 | ULONG ulFlags) // in: APP_RUN_* flags or 0
|
|---|
| 1055 | {
|
|---|
| 1056 | APIRET arc = NO_ERROR;
|
|---|
| 1057 |
|
|---|
| 1058 | XSTRING strExecutablePatched,
|
|---|
| 1059 | strParamsPatched;
|
|---|
| 1060 | PSZ pszWinOS2Env = 0;
|
|---|
| 1061 |
|
|---|
| 1062 | PROGDETAILS Details;
|
|---|
| 1063 | ULONG ulIsWinApp;
|
|---|
| 1064 |
|
|---|
| 1065 | // parameter checking extended V1.0.0 (2002-08-21) [umoeller]
|
|---|
| 1066 | if ( (!pcProgDetails)
|
|---|
| 1067 | || (!pcProgDetails->pszExecutable)
|
|---|
| 1068 | || (!pcProgDetails->pszExecutable[0])
|
|---|
| 1069 | || (!ppDetails)
|
|---|
| 1070 | )
|
|---|
| 1071 | return ERROR_INVALID_PARAMETER;
|
|---|
| 1072 |
|
|---|
| 1073 | *ppDetails = NULL;
|
|---|
| 1074 |
|
|---|
| 1075 | /*
|
|---|
| 1076 | * part 1:
|
|---|
| 1077 | * fix up the PROGDETAILS fields
|
|---|
| 1078 | */
|
|---|
| 1079 |
|
|---|
| 1080 | xstrInit(&strExecutablePatched, 0);
|
|---|
| 1081 | xstrInit(&strParamsPatched, 0);
|
|---|
| 1082 |
|
|---|
| 1083 | memcpy(&Details, pcProgDetails, sizeof(PROGDETAILS));
|
|---|
| 1084 | // pointers still point into old prog details buffer
|
|---|
| 1085 | Details.Length = sizeof(PROGDETAILS);
|
|---|
| 1086 | Details.progt.fbVisible = SHE_VISIBLE;
|
|---|
| 1087 |
|
|---|
| 1088 | // memset(&Details.swpInitial, 0, sizeof(SWP));
|
|---|
| 1089 | // this wasn't a good idea... WPProgram stores stuff
|
|---|
| 1090 | // in here, such as the "minimize on startup" -> SWP_MINIMIZE
|
|---|
| 1091 |
|
|---|
| 1092 | // duplicate parameters...
|
|---|
| 1093 | // we need this for string manipulations below...
|
|---|
| 1094 | if ( (Details.pszParameters)
|
|---|
| 1095 | && (Details.pszParameters[0]) // V0.9.18
|
|---|
| 1096 | )
|
|---|
| 1097 | xstrcpy(&strParamsPatched,
|
|---|
| 1098 | Details.pszParameters,
|
|---|
| 1099 | 0);
|
|---|
| 1100 |
|
|---|
| 1101 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 1102 | _PmpfF((" old progc: 0x%lX", pcProgDetails->progt.progc));
|
|---|
| 1103 | _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle)));
|
|---|
| 1104 | _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable)));
|
|---|
| 1105 | _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters)));
|
|---|
| 1106 | _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon)));
|
|---|
| 1107 | #endif
|
|---|
| 1108 |
|
|---|
| 1109 | // program type fixups
|
|---|
| 1110 | switch (Details.progt.progc) // that's a ULONG
|
|---|
| 1111 | {
|
|---|
| 1112 | case ((ULONG)-1): // we get that sometimes...
|
|---|
| 1113 | case PROG_DEFAULT:
|
|---|
| 1114 | {
|
|---|
| 1115 | // V0.9.12 (2001-05-26) [umoeller]
|
|---|
| 1116 | ULONG ulDosAppType;
|
|---|
| 1117 | appQueryAppType(Details.pszExecutable,
|
|---|
| 1118 | &ulDosAppType,
|
|---|
| 1119 | &Details.progt.progc);
|
|---|
| 1120 | }
|
|---|
| 1121 | break;
|
|---|
| 1122 | }
|
|---|
| 1123 |
|
|---|
| 1124 | // set session type from option flags
|
|---|
| 1125 | if (ulFlags & APP_RUN_FULLSCREEN)
|
|---|
| 1126 | {
|
|---|
| 1127 | if (Details.progt.progc == PROG_WINDOWABLEVIO)
|
|---|
| 1128 | Details.progt.progc = PROG_FULLSCREEN;
|
|---|
| 1129 | else if (Details.progt.progc == PROG_WINDOWEDVDM)
|
|---|
| 1130 | Details.progt.progc = PROG_VDM;
|
|---|
| 1131 | }
|
|---|
| 1132 |
|
|---|
| 1133 | if (ulIsWinApp = appIsWindowsApp(Details.progt.progc))
|
|---|
| 1134 | {
|
|---|
| 1135 | if (ulFlags & APP_RUN_FULLSCREEN)
|
|---|
| 1136 | Details.progt.progc = (ulFlags & APP_RUN_ENHANCED)
|
|---|
| 1137 | ? PROG_31_ENH
|
|---|
| 1138 | : PROG_31_STD;
|
|---|
| 1139 | else
|
|---|
| 1140 | {
|
|---|
| 1141 | if (ulFlags & APP_RUN_STANDARD)
|
|---|
| 1142 | Details.progt.progc = (ulFlags & APP_RUN_SEPARATE)
|
|---|
| 1143 | ? PROG_31_STDSEAMLESSVDM
|
|---|
| 1144 | : PROG_31_STDSEAMLESSCOMMON;
|
|---|
| 1145 | else if (ulFlags & APP_RUN_ENHANCED)
|
|---|
| 1146 | Details.progt.progc = (ulFlags & APP_RUN_SEPARATE)
|
|---|
| 1147 | ? PROG_31_ENHSEAMLESSVDM
|
|---|
| 1148 | : PROG_31_ENHSEAMLESSCOMMON;
|
|---|
| 1149 | }
|
|---|
| 1150 |
|
|---|
| 1151 | // re-run V0.9.16 (2001-10-19) [umoeller]
|
|---|
| 1152 | ulIsWinApp = appIsWindowsApp(Details.progt.progc);
|
|---|
| 1153 | }
|
|---|
| 1154 |
|
|---|
| 1155 | /*
|
|---|
| 1156 | * command lines fixups:
|
|---|
| 1157 | *
|
|---|
| 1158 | */
|
|---|
| 1159 |
|
|---|
| 1160 | if (!strcmp(Details.pszExecutable, "*"))
|
|---|
| 1161 | {
|
|---|
| 1162 | /*
|
|---|
| 1163 | * "*" for command sessions:
|
|---|
| 1164 | *
|
|---|
| 1165 | */
|
|---|
| 1166 |
|
|---|
| 1167 | if (ulIsWinApp)
|
|---|
| 1168 | {
|
|---|
| 1169 | // cheat: WinStartApp doesn't support NULL
|
|---|
| 1170 | // for Win-OS2 sessions, so manually start winos2.com
|
|---|
| 1171 | Details.pszExecutable = "WINOS2.COM";
|
|---|
| 1172 | // this is a DOS app, so fix this to DOS fullscreen
|
|---|
| 1173 | Details.progt.progc = PROG_VDM;
|
|---|
| 1174 |
|
|---|
| 1175 | if (ulIsWinApp == 2)
|
|---|
| 1176 | {
|
|---|
| 1177 | // enhanced Win-OS/2 session:
|
|---|
| 1178 | PSZ psz = NULL;
|
|---|
| 1179 | if (strParamsPatched.ulLength)
|
|---|
| 1180 | // "/3 " + existing params
|
|---|
| 1181 | psz = strdup(strParamsPatched.psz);
|
|---|
| 1182 |
|
|---|
| 1183 | xstrcpy(&strParamsPatched, "/3 ", 0);
|
|---|
| 1184 |
|
|---|
| 1185 | if (psz)
|
|---|
| 1186 | {
|
|---|
| 1187 | xstrcat(&strParamsPatched, psz, 0);
|
|---|
| 1188 | free(psz);
|
|---|
| 1189 | }
|
|---|
| 1190 | }
|
|---|
| 1191 | }
|
|---|
| 1192 | else
|
|---|
| 1193 | // for all other executable types
|
|---|
| 1194 | // (including OS/2 and DOS sessions),
|
|---|
| 1195 | // set pszExecutable to NULL; this will
|
|---|
| 1196 | // have WinStartApp start a cmd shell
|
|---|
| 1197 | Details.pszExecutable = NULL;
|
|---|
| 1198 |
|
|---|
| 1199 | } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0)
|
|---|
| 1200 |
|
|---|
| 1201 | // else
|
|---|
| 1202 |
|
|---|
| 1203 | // no, this else breaks the WINOS2.COM hack above... we
|
|---|
| 1204 | // need to look for that on the PATH as well
|
|---|
| 1205 | // V0.9.20 (2002-07-03) [umoeller]
|
|---|
| 1206 | if (Details.pszExecutable)
|
|---|
| 1207 | {
|
|---|
| 1208 | // check the executable and look for it on the
|
|---|
| 1209 | // PATH if necessary
|
|---|
| 1210 | if (!(arc = CheckAndQualifyExecutable(&Details,
|
|---|
| 1211 | &strExecutablePatched)))
|
|---|
| 1212 | {
|
|---|
| 1213 | PSZ pszExtension;
|
|---|
| 1214 |
|
|---|
| 1215 | // make sure startup dir is really a directory
|
|---|
| 1216 | // V0.9.20 (2002-07-03) [umoeller]: moved this down
|
|---|
| 1217 | if (Details.pszStartupDir)
|
|---|
| 1218 | {
|
|---|
| 1219 | ULONG ulAttr;
|
|---|
| 1220 | // it is valid to specify a startup dir of "C:"
|
|---|
| 1221 | if ( (strlen(Details.pszStartupDir) > 2)
|
|---|
| 1222 | && (!(arc = doshQueryPathAttr(Details.pszStartupDir,
|
|---|
| 1223 | &ulAttr)))
|
|---|
| 1224 | && (!(ulAttr & FILE_DIRECTORY))
|
|---|
| 1225 | )
|
|---|
| 1226 | arc = ERROR_PATH_NOT_FOUND;
|
|---|
| 1227 | }
|
|---|
| 1228 |
|
|---|
| 1229 | // V1.0.0: this define is never set. I have thus completely
|
|---|
| 1230 | // disabled the batch hacks that we used to provide, that is
|
|---|
| 1231 | // we no longer change the "c:\path\batch.cmd" to "cmd.exe /c c:\path\batch.cmd"
|
|---|
| 1232 | // because it is perfectly valid to call WinStartApp with a
|
|---|
| 1233 | // batch file. The problem with my code was that cmd.exe has
|
|---|
| 1234 | // a weird bug in that if you give it something via /c that
|
|---|
| 1235 | // has an equals character (=) in its path, e.g. "c:\path=path\batch.cmd",
|
|---|
| 1236 | // the command parser apparently stops at the first "=" and
|
|---|
| 1237 | // reports "c:\path" not found or something. What a bitch.
|
|---|
| 1238 | #ifdef ENABLEBATCHHACKS
|
|---|
| 1239 |
|
|---|
| 1240 | // we frequently get here for BAT and CMD files
|
|---|
| 1241 | // with progtype == PROG_DEFAULT, so include
|
|---|
| 1242 | // that in the check, or all BAT files will fail
|
|---|
| 1243 | // V0.9.20 (2002-07-03) [umoeller]
|
|---|
| 1244 |
|
|---|
| 1245 | switch (Details.progt.progc)
|
|---|
| 1246 | {
|
|---|
| 1247 | /*
|
|---|
| 1248 | * .CMD files fixups
|
|---|
| 1249 | *
|
|---|
| 1250 | */
|
|---|
| 1251 |
|
|---|
| 1252 | case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller]
|
|---|
| 1253 | case PROG_FULLSCREEN: // OS/2 fullscreen
|
|---|
| 1254 | case PROG_WINDOWABLEVIO: // OS/2 window
|
|---|
| 1255 | {
|
|---|
| 1256 | if ( (pszExtension = doshGetExtension(Details.pszExecutable))
|
|---|
| 1257 | && (!stricmp(pszExtension, "CMD"))
|
|---|
| 1258 | )
|
|---|
| 1259 | {
|
|---|
| 1260 | arc = CallBatchCorrectly(&Details,
|
|---|
| 1261 | &strExecutablePatched,
|
|---|
| 1262 | &strParamsPatched,
|
|---|
| 1263 | "OS2_SHELL",
|
|---|
| 1264 | "CMD.EXE");
|
|---|
| 1265 | }
|
|---|
| 1266 | }
|
|---|
| 1267 | break;
|
|---|
| 1268 | }
|
|---|
| 1269 |
|
|---|
| 1270 | switch (Details.progt.progc)
|
|---|
| 1271 | {
|
|---|
| 1272 | case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller]
|
|---|
| 1273 | case PROG_VDM: // DOS fullscreen
|
|---|
| 1274 | case PROG_WINDOWEDVDM: // DOS window
|
|---|
| 1275 | {
|
|---|
| 1276 | if ( (pszExtension = doshGetExtension(Details.pszExecutable))
|
|---|
| 1277 | && (!stricmp(pszExtension, "BAT"))
|
|---|
| 1278 | )
|
|---|
| 1279 | {
|
|---|
| 1280 | arc = CallBatchCorrectly(&Details,
|
|---|
| 1281 | &strExecutablePatched,
|
|---|
| 1282 | &strParamsPatched,
|
|---|
| 1283 | // there is no environment variable
|
|---|
| 1284 | // for the DOS shell
|
|---|
| 1285 | NULL,
|
|---|
| 1286 | "COMMAND.COM");
|
|---|
| 1287 | }
|
|---|
| 1288 | }
|
|---|
| 1289 | break;
|
|---|
| 1290 | } // end switch (Details.progt.progc)
|
|---|
| 1291 | #endif // ENABLEBATCHHACKS
|
|---|
| 1292 | }
|
|---|
| 1293 | }
|
|---|
| 1294 |
|
|---|
| 1295 | if (!arc)
|
|---|
| 1296 | {
|
|---|
| 1297 | if ( (ulIsWinApp)
|
|---|
| 1298 | && ( (!(Details.pszEnvironment))
|
|---|
| 1299 | || (!(*Details.pszEnvironment))
|
|---|
| 1300 | )
|
|---|
| 1301 | )
|
|---|
| 1302 | {
|
|---|
| 1303 | // this is a windoze app, and caller didn't bother
|
|---|
| 1304 | // to give us an environment:
|
|---|
| 1305 | // we MUST set one then, or we'll get the strangest
|
|---|
| 1306 | // errors, up to system hangs. V0.9.12 (2001-05-26) [umoeller]
|
|---|
| 1307 |
|
|---|
| 1308 | DOSENVIRONMENT Env = {0};
|
|---|
| 1309 |
|
|---|
| 1310 | // get standard WIN-OS/2 environment
|
|---|
| 1311 | PSZ pszTemp;
|
|---|
| 1312 | if (!(arc = appQueryDefaultWin31Environment(&pszTemp)))
|
|---|
| 1313 | {
|
|---|
| 1314 | if (!(arc = appParseEnvironment(pszTemp,
|
|---|
| 1315 | &Env)))
|
|---|
| 1316 | {
|
|---|
| 1317 | // now override KBD_CTRL_BYPASS=CTRL_ESC
|
|---|
| 1318 | if ( (!(arc = appSetEnvironmentVar(&Env,
|
|---|
| 1319 | "KBD_CTRL_BYPASS=CTRL_ESC",
|
|---|
| 1320 | FALSE))) // add last
|
|---|
| 1321 | && (!(arc = appConvertEnvironment(&Env,
|
|---|
| 1322 | &pszWinOS2Env, // freed at bottom
|
|---|
| 1323 | NULL)))
|
|---|
| 1324 | )
|
|---|
| 1325 | Details.pszEnvironment = pszWinOS2Env;
|
|---|
| 1326 |
|
|---|
| 1327 | appFreeEnvironment(&Env);
|
|---|
| 1328 | }
|
|---|
| 1329 |
|
|---|
| 1330 | free(pszTemp);
|
|---|
| 1331 | }
|
|---|
| 1332 | }
|
|---|
| 1333 |
|
|---|
| 1334 | if (!arc)
|
|---|
| 1335 | {
|
|---|
| 1336 | // if no title is given, use the executable
|
|---|
| 1337 | if (!Details.pszTitle)
|
|---|
| 1338 | Details.pszTitle = Details.pszExecutable;
|
|---|
| 1339 |
|
|---|
| 1340 | // make sure params have a leading space
|
|---|
| 1341 | // V0.9.18 (2002-03-27) [umoeller]
|
|---|
| 1342 | if (strParamsPatched.ulLength)
|
|---|
| 1343 | {
|
|---|
| 1344 | if (strParamsPatched.psz[0] != ' ')
|
|---|
| 1345 | {
|
|---|
| 1346 | XSTRING str2;
|
|---|
| 1347 | xstrInit(&str2, 0);
|
|---|
| 1348 | xstrcpy(&str2, " ", 1);
|
|---|
| 1349 | xstrcats(&str2, &strParamsPatched);
|
|---|
| 1350 | xstrcpys(&strParamsPatched, &str2);
|
|---|
| 1351 | xstrClear(&str2);
|
|---|
| 1352 | // we really need xstrInsert or something
|
|---|
| 1353 | }
|
|---|
| 1354 | Details.pszParameters = strParamsPatched.psz;
|
|---|
| 1355 | }
|
|---|
| 1356 | else
|
|---|
| 1357 | // never pass null pointers
|
|---|
| 1358 | Details.pszParameters = "";
|
|---|
| 1359 |
|
|---|
| 1360 | // never pass null pointers
|
|---|
| 1361 | if (!Details.pszIcon)
|
|---|
| 1362 | Details.pszIcon = "";
|
|---|
| 1363 |
|
|---|
| 1364 | // never pass null pointers
|
|---|
| 1365 | if (!Details.pszStartupDir)
|
|---|
| 1366 | Details.pszStartupDir = "";
|
|---|
| 1367 |
|
|---|
| 1368 | }
|
|---|
| 1369 | }
|
|---|
| 1370 |
|
|---|
| 1371 | /*
|
|---|
| 1372 | * part 2:
|
|---|
| 1373 | * pack the fixed PROGDETAILS fields
|
|---|
| 1374 | */
|
|---|
| 1375 |
|
|---|
| 1376 | if (!arc)
|
|---|
| 1377 | {
|
|---|
| 1378 | ULONG cb,
|
|---|
| 1379 | cbTitle,
|
|---|
| 1380 | cbExecutable,
|
|---|
| 1381 | cbParameters,
|
|---|
| 1382 | cbStartupDir,
|
|---|
| 1383 | cbIcon,
|
|---|
| 1384 | cbEnvironment;
|
|---|
| 1385 |
|
|---|
| 1386 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 1387 | _PmpfF((" new progc: 0x%lX", pcProgDetails->progt.progc));
|
|---|
| 1388 | _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle)));
|
|---|
| 1389 | _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable)));
|
|---|
| 1390 | _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters)));
|
|---|
| 1391 | _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon)));
|
|---|
| 1392 | #endif
|
|---|
| 1393 |
|
|---|
| 1394 | // allocate a chunk of tiled memory from OS/2 to make sure
|
|---|
| 1395 | // this is aligned on a 64K memory (backed up by a 16-bit
|
|---|
| 1396 | // LDT selector); if it is not, and the environment
|
|---|
| 1397 | // crosses segments, it gets truncated!!
|
|---|
| 1398 | cb = sizeof(PROGDETAILS);
|
|---|
| 1399 | if (cbTitle = strhSize(Details.pszTitle))
|
|---|
| 1400 | cb += cbTitle;
|
|---|
| 1401 |
|
|---|
| 1402 | if (cbExecutable = strhSize(Details.pszExecutable))
|
|---|
| 1403 | cb += cbExecutable;
|
|---|
| 1404 |
|
|---|
| 1405 | if (cbParameters = strhSize(Details.pszParameters))
|
|---|
| 1406 | cb += cbParameters;
|
|---|
| 1407 |
|
|---|
| 1408 | if (cbStartupDir = strhSize(Details.pszStartupDir))
|
|---|
| 1409 | cb += cbStartupDir;
|
|---|
| 1410 |
|
|---|
| 1411 | if (cbIcon = strhSize(Details.pszIcon))
|
|---|
| 1412 | cb += cbIcon;
|
|---|
| 1413 |
|
|---|
| 1414 | if (cbEnvironment = appQueryEnvironmentLen(Details.pszEnvironment))
|
|---|
| 1415 | cb += cbEnvironment;
|
|---|
| 1416 |
|
|---|
| 1417 | if (cb > 60000) // to be on the safe side
|
|---|
| 1418 | arc = ERROR_BAD_ENVIRONMENT; // 10;
|
|---|
| 1419 | else
|
|---|
| 1420 | {
|
|---|
| 1421 | PPROGDETAILS pNewProgDetails;
|
|---|
| 1422 | // alright, allocate the shared memory now
|
|---|
| 1423 | if (!(arc = DosAllocSharedMem((PVOID*)&pNewProgDetails,
|
|---|
| 1424 | NULL,
|
|---|
| 1425 | cb,
|
|---|
| 1426 | PAG_COMMIT | OBJ_GETTABLE | OBJ_TILE | PAG_EXECUTE | PAG_READ | PAG_WRITE)))
|
|---|
| 1427 | {
|
|---|
| 1428 | // and copy stuff
|
|---|
| 1429 | PBYTE pThis;
|
|---|
| 1430 |
|
|---|
| 1431 | memset(pNewProgDetails, 0, cb);
|
|---|
| 1432 |
|
|---|
| 1433 | pNewProgDetails->Length = sizeof(PROGDETAILS);
|
|---|
| 1434 |
|
|---|
| 1435 | pNewProgDetails->progt.progc = Details.progt.progc;
|
|---|
| 1436 |
|
|---|
| 1437 | pNewProgDetails->progt.fbVisible = Details.progt.fbVisible;
|
|---|
| 1438 | memcpy(&pNewProgDetails->swpInitial, &Details.swpInitial, sizeof(SWP));
|
|---|
| 1439 |
|
|---|
| 1440 | // start copying into buffer right after PROGDETAILS
|
|---|
| 1441 | pThis = (PBYTE)(pNewProgDetails + 1);
|
|---|
| 1442 |
|
|---|
| 1443 | // handy macro to avoid typos
|
|---|
| 1444 | #define COPY(id) if (cb ## id) { \
|
|---|
| 1445 | memcpy(pThis, Details.psz ## id, cb ## id); \
|
|---|
| 1446 | pNewProgDetails->psz ## id = pThis; \
|
|---|
| 1447 | pThis += cb ## id; }
|
|---|
| 1448 |
|
|---|
| 1449 | COPY(Title);
|
|---|
| 1450 | COPY(Executable);
|
|---|
| 1451 | COPY(Parameters);
|
|---|
| 1452 | COPY(StartupDir);
|
|---|
| 1453 | COPY(Icon);
|
|---|
| 1454 | COPY(Environment);
|
|---|
| 1455 |
|
|---|
| 1456 | *ppDetails = pNewProgDetails;
|
|---|
| 1457 | }
|
|---|
| 1458 | }
|
|---|
| 1459 | }
|
|---|
| 1460 |
|
|---|
| 1461 | xstrClear(&strParamsPatched);
|
|---|
| 1462 | xstrClear(&strExecutablePatched);
|
|---|
| 1463 |
|
|---|
| 1464 | if (pszWinOS2Env)
|
|---|
| 1465 | free(pszWinOS2Env);
|
|---|
| 1466 |
|
|---|
| 1467 | return arc;
|
|---|
| 1468 | }
|
|---|
| 1469 |
|
|---|
| 1470 | /*
|
|---|
| 1471 | *@@ CallDosStartSession:
|
|---|
| 1472 | *
|
|---|
| 1473 | *@@added V0.9.18 (2002-03-27) [umoeller]
|
|---|
| 1474 | */
|
|---|
| 1475 |
|
|---|
| 1476 | STATIC APIRET CallDosStartSession(HAPP *phapp,
|
|---|
| 1477 | const PROGDETAILS *pNewProgDetails, // in: program spec (req.)
|
|---|
| 1478 | ULONG cbFailingName,
|
|---|
| 1479 | PSZ pszFailingName)
|
|---|
| 1480 | {
|
|---|
| 1481 | APIRET arc = NO_ERROR;
|
|---|
| 1482 |
|
|---|
| 1483 | BOOL fCrit = FALSE,
|
|---|
| 1484 | fResetDir = FALSE;
|
|---|
| 1485 | CHAR szCurrentDir[CCHMAXPATH];
|
|---|
| 1486 |
|
|---|
| 1487 | ULONG sid,
|
|---|
| 1488 | pid;
|
|---|
| 1489 | STARTDATA SData;
|
|---|
| 1490 | SData.Length = sizeof(STARTDATA);
|
|---|
| 1491 | SData.Related = SSF_RELATED_INDEPENDENT; // SSF_RELATED_CHILD;
|
|---|
| 1492 | // per default, try to start this in the foreground
|
|---|
| 1493 | SData.FgBg = SSF_FGBG_FORE;
|
|---|
| 1494 | SData.TraceOpt = SSF_TRACEOPT_NONE;
|
|---|
| 1495 |
|
|---|
| 1496 | SData.PgmTitle = pNewProgDetails->pszTitle;
|
|---|
| 1497 | SData.PgmName = pNewProgDetails->pszExecutable;
|
|---|
| 1498 | SData.PgmInputs = pNewProgDetails->pszParameters;
|
|---|
| 1499 |
|
|---|
| 1500 | SData.TermQ = NULL;
|
|---|
| 1501 | SData.Environment = pNewProgDetails->pszEnvironment;
|
|---|
| 1502 | SData.InheritOpt = SSF_INHERTOPT_PARENT; // ignored
|
|---|
| 1503 |
|
|---|
| 1504 | switch (pNewProgDetails->progt.progc)
|
|---|
| 1505 | {
|
|---|
| 1506 | case PROG_FULLSCREEN:
|
|---|
| 1507 | SData.SessionType = SSF_TYPE_FULLSCREEN;
|
|---|
| 1508 | break;
|
|---|
| 1509 |
|
|---|
| 1510 | case PROG_WINDOWABLEVIO:
|
|---|
| 1511 | SData.SessionType = SSF_TYPE_WINDOWABLEVIO;
|
|---|
| 1512 | break;
|
|---|
| 1513 |
|
|---|
| 1514 | case PROG_PM:
|
|---|
| 1515 | SData.SessionType = SSF_TYPE_PM;
|
|---|
| 1516 | SData.FgBg = SSF_FGBG_BACK; // otherwise we get ERROR_SMG_START_IN_BACKGROUND
|
|---|
| 1517 | break;
|
|---|
| 1518 |
|
|---|
| 1519 | case PROG_VDM:
|
|---|
| 1520 | SData.SessionType = SSF_TYPE_VDM;
|
|---|
| 1521 | break;
|
|---|
| 1522 |
|
|---|
| 1523 | case PROG_WINDOWEDVDM:
|
|---|
| 1524 | SData.SessionType = SSF_TYPE_WINDOWEDVDM;
|
|---|
| 1525 | break;
|
|---|
| 1526 |
|
|---|
| 1527 | default:
|
|---|
| 1528 | SData.SessionType = SSF_TYPE_DEFAULT;
|
|---|
| 1529 | }
|
|---|
| 1530 |
|
|---|
| 1531 | SData.IconFile = 0;
|
|---|
| 1532 | SData.PgmHandle = 0;
|
|---|
| 1533 |
|
|---|
| 1534 | SData.PgmControl = 0;
|
|---|
| 1535 |
|
|---|
| 1536 | if (pNewProgDetails->progt.fbVisible == SHE_VISIBLE)
|
|---|
| 1537 | SData.PgmControl |= SSF_CONTROL_VISIBLE;
|
|---|
| 1538 |
|
|---|
| 1539 | if (pNewProgDetails->swpInitial.fl & SWP_HIDE)
|
|---|
| 1540 | SData.PgmControl |= SSF_CONTROL_INVISIBLE;
|
|---|
| 1541 |
|
|---|
| 1542 | if (pNewProgDetails->swpInitial.fl & SWP_MAXIMIZE)
|
|---|
| 1543 | SData.PgmControl |= SSF_CONTROL_MAXIMIZE;
|
|---|
| 1544 | if (pNewProgDetails->swpInitial.fl & SWP_MINIMIZE)
|
|---|
| 1545 | {
|
|---|
| 1546 | SData.PgmControl |= SSF_CONTROL_MINIMIZE;
|
|---|
| 1547 | // use background then
|
|---|
| 1548 | SData.FgBg = SSF_FGBG_BACK;
|
|---|
| 1549 | }
|
|---|
| 1550 | if (pNewProgDetails->swpInitial.fl & SWP_MOVE)
|
|---|
| 1551 | SData.PgmControl |= SSF_CONTROL_SETPOS;
|
|---|
| 1552 | if (pNewProgDetails->swpInitial.fl & SWP_NOAUTOCLOSE)
|
|---|
| 1553 | SData.PgmControl |= SSF_CONTROL_NOAUTOCLOSE;
|
|---|
| 1554 |
|
|---|
| 1555 | SData.InitXPos = pNewProgDetails->swpInitial.x;
|
|---|
| 1556 | SData.InitYPos = pNewProgDetails->swpInitial.y;
|
|---|
| 1557 | SData.InitXSize = pNewProgDetails->swpInitial.cx;
|
|---|
| 1558 | SData.InitYSize = pNewProgDetails->swpInitial.cy;
|
|---|
| 1559 |
|
|---|
| 1560 | SData.Reserved = 0;
|
|---|
| 1561 | SData.ObjectBuffer = pszFailingName;
|
|---|
| 1562 | SData.ObjectBuffLen = cbFailingName;
|
|---|
| 1563 |
|
|---|
| 1564 | // now, if a required module cannot be found,
|
|---|
| 1565 | // DosStartSession still returns ERROR_FILE_NOT_FOUND
|
|---|
| 1566 | // (2), but pszFailingName will be set to something
|
|---|
| 1567 | // meaningful... so set it to a null string first
|
|---|
| 1568 | // and we can then check if it has changed
|
|---|
| 1569 | if (pszFailingName)
|
|---|
| 1570 | *pszFailingName = '\0';
|
|---|
| 1571 |
|
|---|
| 1572 | TRY_QUIET(excpt1)
|
|---|
| 1573 | {
|
|---|
| 1574 | if ( (pNewProgDetails->pszStartupDir)
|
|---|
| 1575 | && (pNewProgDetails->pszStartupDir[0])
|
|---|
| 1576 | )
|
|---|
| 1577 | {
|
|---|
| 1578 | fCrit = !DosEnterCritSec();
|
|---|
| 1579 | if ( (!(arc = doshQueryCurrentDir(szCurrentDir)))
|
|---|
| 1580 | && (!(arc = doshSetCurrentDir(pNewProgDetails->pszStartupDir)))
|
|---|
| 1581 | )
|
|---|
| 1582 | fResetDir = TRUE;
|
|---|
| 1583 | }
|
|---|
| 1584 |
|
|---|
| 1585 | if ( (!arc)
|
|---|
| 1586 | && (!(arc = DosStartSession(&SData, &sid, &pid)))
|
|---|
| 1587 | )
|
|---|
| 1588 | {
|
|---|
| 1589 | // app started:
|
|---|
| 1590 | // compose HAPP from that
|
|---|
| 1591 | *phapp = sid;
|
|---|
| 1592 | }
|
|---|
| 1593 | else if (pszFailingName && *pszFailingName)
|
|---|
| 1594 | // DosStartSession has set this to something
|
|---|
| 1595 | // other than NULL: then use error code 1804,
|
|---|
| 1596 | // as cmd.exe does
|
|---|
| 1597 | arc = 1804;
|
|---|
| 1598 | }
|
|---|
| 1599 | CATCH(excpt1)
|
|---|
| 1600 | {
|
|---|
| 1601 | arc = ERROR_PROTECTION_VIOLATION;
|
|---|
| 1602 | } END_CATCH();
|
|---|
| 1603 |
|
|---|
| 1604 | if (fResetDir)
|
|---|
| 1605 | doshSetCurrentDir(szCurrentDir);
|
|---|
| 1606 |
|
|---|
| 1607 | if (fCrit)
|
|---|
| 1608 | DosExitCritSec();
|
|---|
| 1609 |
|
|---|
| 1610 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 1611 | _Pmpf((" DosStartSession returned %d, pszFailingName: \"%s\"",
|
|---|
| 1612 | arc, pszFailingName));
|
|---|
| 1613 | #endif
|
|---|
| 1614 |
|
|---|
| 1615 | return arc;
|
|---|
| 1616 | }
|
|---|
| 1617 |
|
|---|
| 1618 | /*
|
|---|
| 1619 | *@@ CallWinStartApp:
|
|---|
| 1620 | * wrapper around WinStartApp which copies all the
|
|---|
| 1621 | * parameters into a contiguous block of tiled memory.
|
|---|
| 1622 | *
|
|---|
| 1623 | * This might fix some of the problems with truncated
|
|---|
| 1624 | * environments we were having because apparently the
|
|---|
| 1625 | * WinStartApp thunking to 16-bit doesn't always work.
|
|---|
| 1626 | *
|
|---|
| 1627 | *@@added V0.9.18 (2002-02-13) [umoeller]
|
|---|
| 1628 | *@@changed V0.9.18 (2002-03-27) [umoeller]: made failing modules work
|
|---|
| 1629 | */
|
|---|
| 1630 |
|
|---|
| 1631 | STATIC APIRET CallWinStartApp(HAPP *phapp, // out: application handle if NO_ERROR is returned
|
|---|
| 1632 | HWND hwndNotify, // in: notify window or NULLHANDLE
|
|---|
| 1633 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
|---|
| 1634 | ULONG cbFailingName,
|
|---|
| 1635 | PSZ pszFailingName)
|
|---|
| 1636 | {
|
|---|
| 1637 | APIRET arc = NO_ERROR;
|
|---|
| 1638 |
|
|---|
| 1639 | if (!pcProgDetails)
|
|---|
| 1640 | return ERROR_INVALID_PARAMETER;
|
|---|
| 1641 |
|
|---|
| 1642 | if (pszFailingName)
|
|---|
| 1643 | *pszFailingName = '\0';
|
|---|
| 1644 |
|
|---|
| 1645 | if (!(*phapp = WinStartApp(hwndNotify,
|
|---|
| 1646 | // receives WM_APPTERMINATENOTIFY
|
|---|
| 1647 | (PPROGDETAILS)pcProgDetails,
|
|---|
| 1648 | pcProgDetails->pszParameters,
|
|---|
| 1649 | NULL, // "reserved", PMREF says...
|
|---|
| 1650 | SAF_INSTALLEDCMDLINE)))
|
|---|
| 1651 | // we MUST use SAF_INSTALLEDCMDLINE
|
|---|
| 1652 | // or no Win-OS/2 session will start...
|
|---|
| 1653 | // whatever is going on here... Warp 4 FP11
|
|---|
| 1654 |
|
|---|
| 1655 | // do not use SAF_STARTCHILDAPP, or the
|
|---|
| 1656 | // app will be terminated automatically
|
|---|
| 1657 | // when the calling process terminates!
|
|---|
| 1658 | {
|
|---|
| 1659 | // cannot start app:
|
|---|
| 1660 | PERRINFO pei;
|
|---|
| 1661 |
|
|---|
| 1662 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 1663 | _Pmpf((__FUNCTION__ ": WinStartApp failed"));
|
|---|
| 1664 | #endif
|
|---|
| 1665 |
|
|---|
| 1666 | // unfortunately WinStartApp doesn't
|
|---|
| 1667 | // return meaningful codes like DosStartSession, so
|
|---|
| 1668 | // try to see what happened
|
|---|
| 1669 |
|
|---|
| 1670 | if (pei = WinGetErrorInfo(0))
|
|---|
| 1671 | {
|
|---|
| 1672 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 1673 | _Pmpf((" WinGetErrorInfo returned 0x%lX, errorid 0x%lX, %d",
|
|---|
| 1674 | pei,
|
|---|
| 1675 | pei->idError,
|
|---|
| 1676 | ERRORIDERROR(pei->idError)));
|
|---|
| 1677 | #endif
|
|---|
| 1678 |
|
|---|
| 1679 | switch (ERRORIDERROR(pei->idError))
|
|---|
| 1680 | {
|
|---|
| 1681 | case PMERR_DOS_ERROR: // (0x1200)
|
|---|
| 1682 | {
|
|---|
| 1683 | /*
|
|---|
| 1684 | PUSHORT pausMsgOfs = (PUSHORT)(((PBYTE)pei) + pei->offaoffszMsg);
|
|---|
| 1685 | PULONG pulData = (PULONG)(((PBYTE)pei) + pei->offBinaryData);
|
|---|
| 1686 | PSZ pszMsg = (PSZ)(((PBYTE)pei) + *pausMsgOfs);
|
|---|
| 1687 |
|
|---|
| 1688 | CHAR szMsg[1000];
|
|---|
| 1689 | sprintf(szMsg, "cDetail: %d\nmsg: %s\n*pul: %d",
|
|---|
| 1690 | pei->cDetailLevel,
|
|---|
| 1691 | pszMsg,
|
|---|
| 1692 | *(pulData - 1));
|
|---|
| 1693 |
|
|---|
| 1694 | WinMessageBox(HWND_DESKTOP,
|
|---|
| 1695 | NULLHANDLE,
|
|---|
| 1696 | szMsg,
|
|---|
| 1697 | "Error",
|
|---|
| 1698 | 0,
|
|---|
| 1699 | MB_OK | MB_MOVEABLE);
|
|---|
| 1700 |
|
|---|
| 1701 | // Very helpful. The message is "UNK 1200 E",
|
|---|
| 1702 | // where I assume "UNK" means "unknown", which is
|
|---|
| 1703 | // exactly what I was trying to find out. Oh my.
|
|---|
| 1704 | // And cDetailLevel is always 1, which isn't terribly
|
|---|
| 1705 | // helpful either. V0.9.18 (2002-03-27) [umoeller]
|
|---|
| 1706 | // WHO THE &%õ$ CREATED THESE APIS?
|
|---|
| 1707 |
|
|---|
| 1708 | */
|
|---|
| 1709 |
|
|---|
| 1710 | // this is probably the case where the module
|
|---|
| 1711 | // couldn't be loaded, so try DosStartSession
|
|---|
| 1712 | // to get a meaningful return code... note that
|
|---|
| 1713 | // this cannot handle hwndNotify then
|
|---|
| 1714 | /* arc = CallDosStartSession(phapp,
|
|---|
| 1715 | pcProgDetails,
|
|---|
| 1716 | cbFailingName,
|
|---|
| 1717 | pszFailingName); */
|
|---|
| 1718 | arc = ERROR_FILE_NOT_FOUND;
|
|---|
| 1719 | }
|
|---|
| 1720 | break;
|
|---|
| 1721 |
|
|---|
| 1722 | case PMERR_INVALID_APPL: // (0x1530)
|
|---|
| 1723 | // Attempted to start an application whose type is not
|
|---|
| 1724 | // recognized by OS/2.
|
|---|
| 1725 | // This we get also if the executable doesn't exist...
|
|---|
| 1726 | // V0.9.18 (2002-03-27) [umoeller]
|
|---|
| 1727 | // arc = ERROR_INVALID_EXE_SIGNATURE;
|
|---|
| 1728 | arc = ERROR_FILE_NOT_FOUND;
|
|---|
| 1729 | break;
|
|---|
| 1730 |
|
|---|
| 1731 | case PMERR_INVALID_PARAMETERS: // (0x1208)
|
|---|
| 1732 | // An application parameter value is invalid for
|
|---|
| 1733 | // its converted PM type. For example: a 4-byte
|
|---|
| 1734 | // value outside the range -32 768 to +32 767 cannot be
|
|---|
| 1735 | // converted to a SHORT, and a negative number cannot
|
|---|
| 1736 | // be converted to a ULONG or USHORT.
|
|---|
| 1737 | arc = ERROR_INVALID_DATA;
|
|---|
| 1738 | break;
|
|---|
| 1739 |
|
|---|
| 1740 | case PMERR_STARTED_IN_BACKGROUND: // (0x1532)
|
|---|
| 1741 | // The application started a new session in the
|
|---|
| 1742 | // background.
|
|---|
| 1743 | arc = ERROR_SMG_START_IN_BACKGROUND;
|
|---|
| 1744 | break;
|
|---|
| 1745 |
|
|---|
| 1746 | case PMERR_INVALID_WINDOW: // (0x1206)
|
|---|
| 1747 | // The window specified with a Window List call
|
|---|
| 1748 | // is not a valid frame window.
|
|---|
| 1749 |
|
|---|
| 1750 | default:
|
|---|
| 1751 | arc = ERROR_BAD_FORMAT;
|
|---|
| 1752 | break;
|
|---|
| 1753 | }
|
|---|
| 1754 |
|
|---|
| 1755 | WinFreeErrorInfo(pei);
|
|---|
| 1756 | }
|
|---|
| 1757 | }
|
|---|
| 1758 |
|
|---|
| 1759 | return arc;
|
|---|
| 1760 | }
|
|---|
| 1761 |
|
|---|
| 1762 | /*
|
|---|
| 1763 | *@@ appStartApp:
|
|---|
| 1764 | * wrapper around WinStartApp which fixes the
|
|---|
| 1765 | * specified PROGDETAILS to (hopefully) work
|
|---|
| 1766 | * work with all executable types.
|
|---|
| 1767 | *
|
|---|
| 1768 | * This first calls appBuildProgDetails (see
|
|---|
| 1769 | * remarks there) and then calls WinStartApp.
|
|---|
| 1770 | *
|
|---|
| 1771 | * Since this calls WinStartApp in turn, this
|
|---|
| 1772 | * requires a message queue on the calling thread.
|
|---|
| 1773 | *
|
|---|
| 1774 | * Note that this also does minimal checking on
|
|---|
| 1775 | * the specified parameters so it can return something
|
|---|
| 1776 | * more meaningful than FALSE like WinStartApp.
|
|---|
| 1777 | * As a result, you get a DOS error code now (V0.9.16).
|
|---|
| 1778 | *
|
|---|
| 1779 | * Most importantly:
|
|---|
| 1780 | *
|
|---|
| 1781 | * -- ERROR_INVALID_THREADID: not running on thread 1.
|
|---|
| 1782 | * See remarks below.
|
|---|
| 1783 | *
|
|---|
| 1784 | * -- ERROR_NOT_ENOUGH_MEMORY
|
|---|
| 1785 | *
|
|---|
| 1786 | * plus the many error codes from appBuildProgDetails,
|
|---|
| 1787 | * which gets called in turn.
|
|---|
| 1788 | *
|
|---|
| 1789 | * <B>About enforcing thread 1</B>
|
|---|
| 1790 | *
|
|---|
| 1791 | * OK, after long, long debugging hours, I have found
|
|---|
| 1792 | * that WinStartApp hangs the system in the following
|
|---|
| 1793 | * cases hard:
|
|---|
| 1794 | *
|
|---|
| 1795 | * -- If a Win-OS/2 session is started and WinStartApp
|
|---|
| 1796 | * is _not_ on thread 1. For this reason, we check
|
|---|
| 1797 | * if the caller is trying to start a Win-OS/2
|
|---|
| 1798 | * session and return ERROR_INVALID_THREADID if
|
|---|
| 1799 | * this is not running on thread 1.
|
|---|
| 1800 | *
|
|---|
| 1801 | * -- By contrast, there are many situations where
|
|---|
| 1802 | * calling WinStartApp from within the Workplace
|
|---|
| 1803 | * process will hang the system, most notably
|
|---|
| 1804 | * with VIO sessions. I have been unable to figure
|
|---|
| 1805 | * out why this happens, so XWorkplace now uses
|
|---|
| 1806 | * its daemon to call WinStartApp instead.
|
|---|
| 1807 | *
|
|---|
| 1808 | * As a word of wisdom, do not call this from
|
|---|
| 1809 | * within the Workplace process. For some strange
|
|---|
| 1810 | * reason though, the XWorkplace "Run" dialog
|
|---|
| 1811 | * (which uses this) _does_ work. Whatever.
|
|---|
| 1812 | *
|
|---|
| 1813 | *@@added V0.9.6 (2000-10-16) [umoeller]
|
|---|
| 1814 | *@@changed V0.9.7 (2000-12-10) [umoeller]: PROGDETAILS.swpInitial no longer zeroed... this broke VIOs
|
|---|
| 1815 | *@@changed V0.9.7 (2000-12-17) [umoeller]: PROGDETAILS.pszEnvironment no longer zeroed
|
|---|
| 1816 | *@@changed V0.9.9 (2001-01-27) [umoeller]: crashed if PROGDETAILS.pszExecutable was NULL
|
|---|
| 1817 | *@@changed V0.9.12 (2001-05-26) [umoeller]: fixed PROG_DEFAULT
|
|---|
| 1818 | *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c
|
|---|
| 1819 | *@@changed V0.9.14 (2001-08-07) [pr]: removed some env. strings for Win. apps.
|
|---|
| 1820 | *@@changed V0.9.14 (2001-08-23) [pr]: added session type options
|
|---|
| 1821 | *@@changed V0.9.16 (2001-10-19) [umoeller]: added prototype to return APIRET
|
|---|
| 1822 | *@@changed V0.9.16 (2001-10-19) [umoeller]: added thread-1 check
|
|---|
| 1823 | *@@changed V0.9.16 (2001-12-06) [umoeller]: now using doshSearchPath for finding pszExecutable if not qualified
|
|---|
| 1824 | *@@changed V0.9.16 (2002-01-04) [umoeller]: removed error report if startup directory was drive letter only
|
|---|
| 1825 | *@@changed V0.9.16 (2002-01-04) [umoeller]: added more detailed error reports and *FailingName params
|
|---|
| 1826 | *@@changed V0.9.18 (2002-02-13) [umoeller]: added CallWinStartApp to fix possible memory problems
|
|---|
| 1827 | *@@changed V0.9.18 (2002-03-27) [umoeller]: no longer returning ERROR_INVALID_THREADID, except for Win-OS/2 sessions
|
|---|
| 1828 | *@@changed V0.9.18 (2002-03-27) [umoeller]: extracted appBuildProgDetails
|
|---|
| 1829 | *@@changed V0.9.19 (2002-03-28) [umoeller]: adjusted for new appBuildProgDetails
|
|---|
| 1830 | */
|
|---|
| 1831 |
|
|---|
| 1832 | APIRET appStartApp(HWND hwndNotify, // in: notify window or NULLHANDLE
|
|---|
| 1833 | const PROGDETAILS *pcProgDetails, // in: program spec (req.)
|
|---|
| 1834 | ULONG ulFlags, // in: APP_RUN_* flags or 0
|
|---|
| 1835 | HAPP *phapp, // out: application handle if NO_ERROR is returned
|
|---|
| 1836 | ULONG cbFailingName,
|
|---|
| 1837 | PSZ pszFailingName)
|
|---|
| 1838 | {
|
|---|
| 1839 | APIRET arc;
|
|---|
| 1840 |
|
|---|
| 1841 | PPROGDETAILS pDetails;
|
|---|
| 1842 |
|
|---|
| 1843 | if (!phapp)
|
|---|
| 1844 | return ERROR_INVALID_PARAMETER;
|
|---|
| 1845 |
|
|---|
| 1846 | if (!(arc = appBuildProgDetails(&pDetails,
|
|---|
| 1847 | pcProgDetails,
|
|---|
| 1848 | ulFlags)))
|
|---|
| 1849 | {
|
|---|
| 1850 | if (pszFailingName)
|
|---|
| 1851 | strhncpy0(pszFailingName, pDetails->pszExecutable, cbFailingName);
|
|---|
| 1852 |
|
|---|
| 1853 | if ( (appIsWindowsApp(pDetails->progt.progc))
|
|---|
| 1854 | && (doshMyTID() != 1) // V0.9.16 (2001-10-19) [umoeller]
|
|---|
| 1855 | )
|
|---|
| 1856 | arc = ERROR_INVALID_THREADID;
|
|---|
| 1857 | else
|
|---|
| 1858 | arc = CallWinStartApp(phapp,
|
|---|
| 1859 | hwndNotify,
|
|---|
| 1860 | pDetails,
|
|---|
| 1861 | cbFailingName,
|
|---|
| 1862 | pszFailingName);
|
|---|
| 1863 |
|
|---|
| 1864 | DosFreeMem(pDetails);
|
|---|
| 1865 |
|
|---|
| 1866 | } // end if (ProgDetails.pszExecutable)
|
|---|
| 1867 |
|
|---|
| 1868 | #ifdef DEBUG_PROGRAMSTART
|
|---|
| 1869 | _Pmpf((__FUNCTION__ ": returning %d", arc));
|
|---|
| 1870 | #endif
|
|---|
| 1871 |
|
|---|
| 1872 | return arc;
|
|---|
| 1873 | }
|
|---|
| 1874 |
|
|---|
| 1875 | /*
|
|---|
| 1876 | *@@ appWaitForApp:
|
|---|
| 1877 | * waits for the specified application to terminate
|
|---|
| 1878 | * and returns its exit code.
|
|---|
| 1879 | *
|
|---|
| 1880 | *@@added V0.9.9 (2001-03-07) [umoeller]
|
|---|
| 1881 | */
|
|---|
| 1882 |
|
|---|
| 1883 | BOOL appWaitForApp(HWND hwndNotify, // in: notify window
|
|---|
| 1884 | HAPP happ, // in: app to wait for
|
|---|
| 1885 | PULONG pulExitCode) // out: exit code (ptr can be NULL)
|
|---|
| 1886 | {
|
|---|
| 1887 | BOOL brc = FALSE;
|
|---|
| 1888 |
|
|---|
| 1889 | if (happ)
|
|---|
| 1890 | {
|
|---|
| 1891 | // app started:
|
|---|
| 1892 | // enter a modal message loop until we get the
|
|---|
| 1893 | // WM_APPTERMINATENOTIFY for happ. Then we
|
|---|
| 1894 | // know the app is done.
|
|---|
| 1895 | HAB hab = WinQueryAnchorBlock(hwndNotify);
|
|---|
| 1896 | QMSG qmsg;
|
|---|
| 1897 | // ULONG ulXFixReturnCode = 0;
|
|---|
| 1898 | while (WinGetMsg(hab, &qmsg, NULLHANDLE, 0, 0))
|
|---|
| 1899 | {
|
|---|
| 1900 | if ( (qmsg.msg == WM_APPTERMINATENOTIFY)
|
|---|
| 1901 | && (qmsg.hwnd == hwndNotify)
|
|---|
| 1902 | && (qmsg.mp1 == (MPARAM)happ)
|
|---|
| 1903 | )
|
|---|
| 1904 | {
|
|---|
| 1905 | // xfix has terminated:
|
|---|
| 1906 | // get xfix return code from mp2... this is:
|
|---|
| 1907 | // -- 0: everything's OK, continue.
|
|---|
| 1908 | // -- 1: handle section was rewritten, restart Desktop
|
|---|
| 1909 | // now.
|
|---|
| 1910 | if (pulExitCode)
|
|---|
| 1911 | *pulExitCode = (ULONG)qmsg.mp2;
|
|---|
| 1912 | brc = TRUE;
|
|---|
| 1913 | // do not dispatch this
|
|---|
| 1914 | break;
|
|---|
| 1915 | }
|
|---|
| 1916 |
|
|---|
| 1917 | WinDispatchMsg(hab, &qmsg);
|
|---|
| 1918 | }
|
|---|
| 1919 | }
|
|---|
| 1920 |
|
|---|
| 1921 | return brc;
|
|---|
| 1922 | }
|
|---|
| 1923 |
|
|---|
| 1924 | /*
|
|---|
| 1925 | *@@ appQuickStartApp:
|
|---|
| 1926 | * shortcut for simply starting an app.
|
|---|
| 1927 | *
|
|---|
| 1928 | * On errors, NULLHANDLE is returned.
|
|---|
| 1929 | *
|
|---|
| 1930 | * Only if pulExitCode != NULL, we wait for
|
|---|
| 1931 | * the app to complete and return the
|
|---|
| 1932 | * exit code.
|
|---|
| 1933 | *
|
|---|
| 1934 | *@@added V0.9.16 (2001-10-19) [umoeller]
|
|---|
| 1935 | *@@changed V0.9.20 (2002-08-10) [umoeller]: fixed missing destroy window, made wait optional
|
|---|
| 1936 | *@@changed V0.9.20 (2002-08-10) [umoeller]: added pcszWorkingDir
|
|---|
| 1937 | *@@changed V1.0.0 (2002-08-18) [umoeller]: changed prototype to return APIRET
|
|---|
| 1938 | */
|
|---|
| 1939 |
|
|---|
| 1940 | APIRET appQuickStartApp(const char *pcszFile,
|
|---|
| 1941 | ULONG ulProgType, // e.g. PROG_PM
|
|---|
| 1942 | const char *pcszArgs, // in: arguments (can be NULL)
|
|---|
| 1943 | const char *pcszWorkingDir, // in: working dir (can be NULL)
|
|---|
| 1944 | HAPP *phapp,
|
|---|
| 1945 | PULONG pulExitCode) // out: exit code; if ptr is NULL, we don't wait
|
|---|
| 1946 | {
|
|---|
| 1947 | APIRET arc = NO_ERROR;
|
|---|
| 1948 | PROGDETAILS pd = {0};
|
|---|
| 1949 | HAPP happReturn = NULLHANDLE;
|
|---|
| 1950 | CHAR szDir[CCHMAXPATH] = "";
|
|---|
| 1951 | PCSZ p;
|
|---|
| 1952 | HWND hwndObject = NULLHANDLE;
|
|---|
| 1953 |
|
|---|
| 1954 | pd.Length = sizeof(pd);
|
|---|
| 1955 | pd.progt.progc = ulProgType;
|
|---|
| 1956 | pd.progt.fbVisible = SHE_VISIBLE;
|
|---|
| 1957 | pd.pszExecutable = (PSZ)pcszFile;
|
|---|
| 1958 | pd.pszParameters = (PSZ)pcszArgs;
|
|---|
| 1959 |
|
|---|
| 1960 | if ( (!(pd.pszStartupDir = (PSZ)pcszWorkingDir))
|
|---|
| 1961 | && (p = strrchr(pcszFile, '\\'))
|
|---|
| 1962 | )
|
|---|
| 1963 | {
|
|---|
| 1964 | strhncpy0(szDir,
|
|---|
| 1965 | pcszFile,
|
|---|
| 1966 | p - pcszFile);
|
|---|
| 1967 | pd.pszStartupDir = szDir;
|
|---|
| 1968 | }
|
|---|
| 1969 |
|
|---|
| 1970 | if (pulExitCode)
|
|---|
| 1971 | if (!(hwndObject = winhCreateObjectWindow(WC_STATIC, NULL)))
|
|---|
| 1972 | arc = ERROR_NOT_ENOUGH_MEMORY;
|
|---|
| 1973 |
|
|---|
| 1974 | if ( (!arc)
|
|---|
| 1975 | && (!(arc = appStartApp(hwndObject,
|
|---|
| 1976 | &pd,
|
|---|
| 1977 | 0,
|
|---|
| 1978 | phapp,
|
|---|
| 1979 | 0,
|
|---|
| 1980 | NULL)))
|
|---|
| 1981 | )
|
|---|
| 1982 | {
|
|---|
| 1983 | if (pulExitCode)
|
|---|
| 1984 | appWaitForApp(hwndObject,
|
|---|
| 1985 | *phapp,
|
|---|
| 1986 | pulExitCode);
|
|---|
| 1987 | }
|
|---|
| 1988 |
|
|---|
| 1989 | if (hwndObject)
|
|---|
| 1990 | WinDestroyWindow(hwndObject); // was missing V0.9.20 (2002-08-10) [umoeller]
|
|---|
| 1991 |
|
|---|
| 1992 | return arc;
|
|---|
| 1993 | }
|
|---|
| 1994 |
|
|---|
| 1995 | /*
|
|---|
| 1996 | *@@ appOpenURL:
|
|---|
| 1997 | * opens the system default browser with the given
|
|---|
| 1998 | * URL.
|
|---|
| 1999 | *
|
|---|
| 2000 | * We return TRUE if appQuickStartApp succeeded with
|
|---|
| 2001 | * that URL.
|
|---|
| 2002 | *
|
|---|
| 2003 | *@@added V0.9.20 (2002-08-10) [umoeller]
|
|---|
| 2004 | *@@changed V1.0.0 (2002-08-21) [umoeller]: changed prototype to return browser
|
|---|
| 2005 | */
|
|---|
| 2006 |
|
|---|
| 2007 | APIRET appOpenURL(PCSZ pcszURL, // in: URL to open
|
|---|
| 2008 | PSZ pszAppStarted, // out: application that was started (req.)
|
|---|
| 2009 | ULONG cbAppStarted) // in: size of that buffer
|
|---|
| 2010 | {
|
|---|
| 2011 | APIRET arc = ERROR_NO_DATA;
|
|---|
| 2012 |
|
|---|
| 2013 | CHAR szStartupDir[CCHMAXPATH];
|
|---|
| 2014 | XSTRING strParameters;
|
|---|
| 2015 |
|
|---|
| 2016 | if ( (!pcszURL)
|
|---|
| 2017 | || (!pszAppStarted)
|
|---|
| 2018 | || (!cbAppStarted)
|
|---|
| 2019 | )
|
|---|
| 2020 | return ERROR_INVALID_PARAMETER;
|
|---|
| 2021 |
|
|---|
| 2022 | xstrInit(&strParameters, 0);
|
|---|
| 2023 |
|
|---|
| 2024 | if (PrfQueryProfileString(HINI_USER,
|
|---|
| 2025 | "WPURLDEFAULTSETTINGS",
|
|---|
| 2026 | "DefaultBrowserExe",
|
|---|
| 2027 | "NETSCAPE.EXE",
|
|---|
| 2028 | pszAppStarted,
|
|---|
| 2029 | cbAppStarted))
|
|---|
| 2030 | {
|
|---|
| 2031 | PSZ pszDefParams;
|
|---|
| 2032 | HAPP happ;
|
|---|
| 2033 |
|
|---|
| 2034 | if (pszDefParams = prfhQueryProfileData(HINI_USER,
|
|---|
| 2035 | "WPURLDEFAULTSETTINGS",
|
|---|
| 2036 | "DefaultParameters",
|
|---|
| 2037 | NULL))
|
|---|
| 2038 | {
|
|---|
| 2039 | xstrcpy(&strParameters, pszDefParams, 0);
|
|---|
| 2040 | xstrcatc(&strParameters, ' ');
|
|---|
| 2041 | free(pszDefParams);
|
|---|
| 2042 | }
|
|---|
| 2043 |
|
|---|
| 2044 | xstrcat(&strParameters, pcszURL, 0);
|
|---|
| 2045 |
|
|---|
| 2046 | PrfQueryProfileString(HINI_USER,
|
|---|
| 2047 | "WPURLDEFAULTSETTINGS",
|
|---|
| 2048 | "DefaultWorkingDir",
|
|---|
| 2049 | "",
|
|---|
| 2050 | szStartupDir,
|
|---|
| 2051 | sizeof(szStartupDir));
|
|---|
| 2052 |
|
|---|
| 2053 | arc = appQuickStartApp(pszAppStarted,
|
|---|
| 2054 | PROG_DEFAULT,
|
|---|
| 2055 | strParameters.psz,
|
|---|
| 2056 | szStartupDir,
|
|---|
| 2057 | &happ,
|
|---|
| 2058 | NULL); // don't wait
|
|---|
| 2059 | }
|
|---|
| 2060 |
|
|---|
| 2061 | xstrClear(&strParameters);
|
|---|
| 2062 |
|
|---|
| 2063 | return arc;
|
|---|
| 2064 | }
|
|---|