Changeset 185 for trunk/src/helpers/apps.c
- Timestamp:
- Jul 5, 2002, 11:22:37 AM (23 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/helpers/apps.c
r184 r185 779 779 780 780 /* 781 *@@ CheckAndQualifyExecutable: 782 * checks the executable in the given PROGDETAILS 783 * for whether it is fully qualified. 784 * 785 * If so, the existence is verified. 786 * 787 * If not, we search for it on the PATH. If we 788 * find it, we use pstrExecutablePath to store 789 * the fully qualified executable and set 790 * pDetails->pszExecutable to it. The caller 791 * must initialize the buffer and clear it 792 * after the call. 793 * 794 * Returns: 795 * 796 * -- NO_ERROR: executable exists and might 797 * have been fully qualified. 798 * 799 * -- ERROR_FILE_NOT_FOUND 800 * 801 *@@added V0.9.20 (2002-07-03) [umoeller] 802 */ 803 804 static APIRET CheckAndQualifyExecutable(PPROGDETAILS pDetails, // in/out: program details 805 PXSTRING pstrExecutablePatched) // in/out: buffer for q'fied exec (must be init'ed) 806 { 807 APIRET arc = NO_ERROR; 808 809 ULONG ulAttr; 810 // check if the executable is fully qualified; if so, 811 // check if the executable file exists 812 if ( (pDetails->pszExecutable[1] == ':') 813 && (strchr(pDetails->pszExecutable, '\\')) 814 ) 815 { 816 arc = doshQueryPathAttr(pDetails->pszExecutable, 817 &ulAttr); 818 } 819 else 820 { 821 // _not_ fully qualified: look it up on the PATH then 822 // V0.9.16 (2001-12-06) [umoeller] 823 CHAR szFQExecutable[CCHMAXPATH]; 824 if (!(arc = doshSearchPath("PATH", 825 pDetails->pszExecutable, 826 szFQExecutable, 827 sizeof(szFQExecutable)))) 828 { 829 // alright, found it: 830 xstrcpy(pstrExecutablePatched, szFQExecutable, 0); 831 pDetails->pszExecutable = pstrExecutablePatched->psz; 832 } 833 } 834 835 return arc; 836 } 837 838 /* 781 839 *@@ CallBatchCorrectly: 782 840 * fixes the specified PROGDETAILS for 783 841 * command files in the executable part 784 842 * by inserting /C XXX into the parameters 785 * and setting the executable according 786 * to an environment variable. 843 * and setting the executable to the fully 844 * qualified command interpreter specified 845 * by the given environment variable. 787 846 * 788 847 *@@added V0.9.6 (2000-10-16) [umoeller] 789 848 *@@changed V0.9.7 (2001-01-15) [umoeller]: now using XSTRING 790 849 *@@changed V0.9.12 (2001-05-27) [umoeller]: moved from winh.c to apps.c 791 */ 792 793 static VOID CallBatchCorrectly(PPROGDETAILS pProgDetails, 794 PXSTRING pstrParams, // in/out: modified parameters (reallocated) 795 const char *pcszEnvVar, // in: env var spec'g command proc 796 // (e.g. "OS2_SHELL"); can be NULL 797 const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE") 850 *@@changed V0.9.20 (2002-07-03) [umoeller]: now always qualifying executable to fix broken BAT files 851 */ 852 853 static APIRET CallBatchCorrectly(PPROGDETAILS pProgDetails, 854 PXSTRING pstrExecutablePatched, // in/out: buffer for q'fied exec (must be init'ed) 855 PXSTRING pstrParams, // in/out: modified parameters (reallocated) 856 const char *pcszEnvVar, // in: env var spec'g command proc 857 // (e.g. "OS2_SHELL"); can be NULL 858 const char *pcszDefProc) // in: def't command proc (e.g. "CMD.EXE") 798 859 { 860 APIRET arc = NO_ERROR; 861 799 862 // XXX.CMD file as executable: 800 863 // fix args to /C XXX.CMD … … 831 894 pProgDetails->pszExecutable = (PSZ)pcszDefProc; 832 895 // should be on PATH 896 897 // and make sure this is always qualified 898 // V0.9.20 (2002-07-03) [umoeller] 899 return CheckAndQualifyExecutable(pProgDetails, 900 pstrExecutablePatched); 833 901 } 834 902 … … 1134 1202 1135 1203 #ifdef DEBUG_PROGRAMSTART 1136 _Pmpf((__FUNCTION__ ": old progc: 0x%lX", pcProgDetails->progt.progc)); 1137 _Pmpf((" pszTitle: %s", (Details.pszTitle) ? Details.pszTitle : NULL)); 1138 _Pmpf((" pszIcon: %s", (Details.pszIcon) ? Details.pszIcon : NULL)); 1204 _PmpfF((" old progc: 0x%lX", pcProgDetails->progt.progc)); 1205 _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle))); 1206 _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable))); 1207 _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters))); 1208 _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon))); 1139 1209 #endif 1140 1210 … … 1185 1255 } 1186 1256 1187 if (!arc) 1257 /* 1258 * command lines fixups: 1259 * 1260 */ 1261 1262 if (!strcmp(Details.pszExecutable, "*")) 1188 1263 { 1189 1264 /* 1190 * command lines fixups:1265 * "*" for command sessions: 1191 1266 * 1192 1267 */ 1193 1268 1194 if ( !strcmp(Details.pszExecutable, "*"))1269 if (ulIsWinApp) 1195 1270 { 1196 /* 1197 * "*" for command sessions: 1198 * 1199 */ 1271 // cheat: WinStartApp doesn't support NULL 1272 // for Win-OS2 sessions, so manually start winos2.com 1273 Details.pszExecutable = "WINOS2.COM"; 1274 // this is a DOS app, so fix this to DOS fullscreen 1275 Details.progt.progc = PROG_VDM; 1200 1276 1201 1277 if (ulIsWinApp == 2) … … 1215 1291 } 1216 1292 } 1217 1218 if (ulIsWinApp) 1219 { 1220 // cheat: WinStartApp doesn't support NULL 1221 // for Win-OS2 sessions, so manually start winos2.com 1222 Details.pszExecutable = "WINOS2.COM"; 1223 // this is a DOS app, so fix this to DOS fullscreen 1224 Details.progt.progc = PROG_VDM; 1225 } 1226 else 1227 // for all other executable types 1228 // (including OS/2 and DOS sessions), 1229 // set pszExecutable to NULL; this will 1230 // have WinStartApp start a cmd shell 1231 Details.pszExecutable = NULL; 1232 1233 } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0) 1293 } 1234 1294 else 1295 // for all other executable types 1296 // (including OS/2 and DOS sessions), 1297 // set pszExecutable to NULL; this will 1298 // have WinStartApp start a cmd shell 1299 Details.pszExecutable = NULL; 1300 1301 } // end if (strcmp(pProgDetails->pszExecutable, "*") == 0) 1302 1303 // else 1304 1305 // no, this else breaks the WINOS2.COM hack above... we 1306 // need to look for that on the PATH as well 1307 // V0.9.20 (2002-07-03) [umoeller] 1308 if (Details.pszExecutable) 1309 { 1310 // check the executable and look for it on the 1311 // PATH if necessary 1312 if (!(arc = CheckAndQualifyExecutable(&Details, 1313 &strExecutablePatched))) 1235 1314 { 1236 // check if the executable is fully qualified; if so,1237 // check if the executable file exists 1238 if ( (Details.pszExecutable[1] == ':')1239 && (strchr(Details.pszExecutable, '\\'))1240 1315 PSZ pszExtension; 1316 1317 // make sure startup dir is really a directory 1318 // V0.9.20 (2002-07-03) [umoeller]: moved this down 1319 if (Details.pszStartupDir) 1241 1320 { 1242 1321 ULONG ulAttr; 1243 if (!(arc = doshQueryPathAttr(Details.pszExecutable, 1244 &ulAttr))) 1322 // it is valid to specify a startup dir of "C:" 1323 if ( (strlen(Details.pszStartupDir) > 2) 1324 && (!(arc = doshQueryPathAttr(Details.pszStartupDir, 1325 &ulAttr))) 1326 && (!(ulAttr & FILE_DIRECTORY)) 1327 ) 1328 arc = ERROR_PATH_NOT_FOUND; 1329 } 1330 1331 // we frequently get here for BAT and CMD files 1332 // with progtype == PROG_DEFAULT, so include 1333 // that in the check, or all BAT files will fail 1334 // V0.9.20 (2002-07-03) [umoeller] 1335 1336 switch (Details.progt.progc) 1337 { 1338 /* 1339 * .CMD files fixups 1340 * 1341 */ 1342 1343 case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller] 1344 case PROG_FULLSCREEN: // OS/2 fullscreen 1345 case PROG_WINDOWABLEVIO: // OS/2 window 1245 1346 { 1246 // make sure startup dir is really a directory 1247 if (Details.pszStartupDir) 1347 if ( (pszExtension = doshGetExtension(Details.pszExecutable)) 1348 && (!stricmp(pszExtension, "CMD")) 1349 ) 1248 1350 { 1249 // it is valid to specify a startup dir of "C:" 1250 if ( (strlen(Details.pszStartupDir) > 2) 1251 && (!(arc = doshQueryPathAttr(Details.pszStartupDir, 1252 &ulAttr))) 1253 && (!(ulAttr & FILE_DIRECTORY)) 1254 ) 1255 arc = ERROR_PATH_NOT_FOUND; 1351 arc = CallBatchCorrectly(&Details, 1352 &strExecutablePatched, 1353 &strParamsPatched, 1354 "OS2_SHELL", 1355 "CMD.EXE"); 1256 1356 } 1257 1357 } 1358 break; 1258 1359 } 1259 else 1360 1361 switch (Details.progt.progc) 1260 1362 { 1261 // _not_ fully qualified: look it up on the PATH then 1262 // V0.9.16 (2001-12-06) [umoeller] 1263 CHAR szFQExecutable[CCHMAXPATH]; 1264 if (!(arc = doshSearchPath("PATH", 1265 Details.pszExecutable, 1266 szFQExecutable, 1267 sizeof(szFQExecutable)))) 1363 case PROG_DEFAULT: // V0.9.20 (2002-07-03) [umoeller] 1364 case PROG_VDM: // DOS fullscreen 1365 case PROG_WINDOWEDVDM: // DOS window 1268 1366 { 1269 // alright, found it: 1270 xstrcpy(&strExecutablePatched, szFQExecutable, 0); 1271 Details.pszExecutable = strExecutablePatched.psz; 1367 if ( (pszExtension = doshGetExtension(Details.pszExecutable)) 1368 && (!stricmp(pszExtension, "BAT")) 1369 ) 1370 { 1371 arc = CallBatchCorrectly(&Details, 1372 &strExecutablePatched, 1373 &strParamsPatched, 1374 // there is no environment variable 1375 // for the DOS shell 1376 NULL, 1377 "COMMAND.COM"); 1378 } 1272 1379 } 1273 } 1274 1275 if (!arc) 1276 { 1277 PSZ pszExtension; 1278 switch (Details.progt.progc) 1279 { 1280 /* 1281 * .CMD files fixups 1282 * 1283 */ 1284 1285 case PROG_FULLSCREEN: // OS/2 fullscreen 1286 case PROG_WINDOWABLEVIO: // OS/2 window 1287 { 1288 if ( (pszExtension = doshGetExtension(Details.pszExecutable)) 1289 && (!stricmp(pszExtension, "CMD")) 1290 ) 1291 { 1292 CallBatchCorrectly(&Details, 1293 &strParamsPatched, 1294 "OS2_SHELL", 1295 "CMD.EXE"); 1296 } 1297 } 1298 break; 1299 1300 case PROG_VDM: // DOS fullscreen 1301 case PROG_WINDOWEDVDM: // DOS window 1302 { 1303 if ( (pszExtension = doshGetExtension(Details.pszExecutable)) 1304 && (!stricmp(pszExtension, "BAT")) 1305 ) 1306 { 1307 CallBatchCorrectly(&Details, 1308 &strParamsPatched, 1309 NULL, 1310 "COMMAND.COM"); 1311 } 1312 } 1313 break; 1314 } // end switch (Details.progt.progc) 1315 } 1380 break; 1381 } // end switch (Details.progt.progc) 1316 1382 } 1317 1383 } … … 1409 1475 cbEnvironment; 1410 1476 1477 #ifdef DEBUG_PROGRAMSTART 1478 _PmpfF((" new progc: 0x%lX", pcProgDetails->progt.progc)); 1479 _Pmpf((" pszTitle: %s", STRINGORNULL(Details.pszTitle))); 1480 _Pmpf((" pszExecutable: %s", STRINGORNULL(Details.pszExecutable))); 1481 _Pmpf((" pszParameters: %s", STRINGORNULL(Details.pszParameters))); 1482 _Pmpf((" pszIcon: %s", STRINGORNULL(Details.pszIcon))); 1483 #endif 1484 1411 1485 // allocate a chunk of tiled memory from OS/2 to make sure 1412 1486 // this is aligned on a 64K memory (backed up by a 16-bit
Note:
See TracChangeset
for help on using the changeset viewer.