home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 8 Other
/
08-Other.zip
/
PMSTART.ZIP
/
PMSTART.C
< prev
next >
Wrap
C/C++ Source or Header
|
1989-09-14
|
8KB
|
316 lines
/****************************************************************\
|* OS2 1.1 Presentation Manager Start Command *|
|* by Massimo Pezzi *|
|* 611 Camino Dr. *|
|* Santa Clara, Ca 95050 *|
|* CompuServe id 71531,756 *|
|* user of Micro Foundry BBS (408) 258-3484 *|
\****************************************************************/
#define INCL_DOSSESMGR
#define INCL_DOSFILEMGR
#include <os2.h>
#include <string.h>
#include <stddef.h>
#include <stdio.h>
#include <ctype.h>
#include <stdlib.h>
#define _PARM(a) &argv[a][1]
#define NO_ERROR 0
#define SEMANTIC_ERROR 1
#define PROGRAM_NOT_FOUND 2
main (int argc, char *argv[]) {
static STARTDATA scntl = {
50, /* Length */
FALSE, /* Related */
FALSE, /* FgBg */
FALSE, /* TraceOpt */
"", /* PgmTitle */
"", /* PgmName */
"", /* PgmInputs */
"", /* TermQ */
0, /* Environment */
FALSE, /* InheritOpt */
0, /* SessionType */
"", /* IconFile */
0, /* PgmHandle */
0x0000, /* PgmControl */
0,0, /* InitXPos, InitYPos */
0,0 /* InitXSize, InitYSize */
};
static CHAR PgmArgs[255] = "",
PgmDrive[6] = "",
PgmDir[255] = "",
PgmName[10] = "",
PgmExt[8] = "",
IconName[255] = "",
PgmFName[255] = "",
PgmTitle[32] = "";
USHORT i,
name_found,
stype_found,
title_found,
exec_cmd,
retain_cmd,
idSession, id,
SearchCode,
SearchCnt,
exitrc;
CHAR SearchName[14],
SearchPath[255];
HDIR hdir = HDIR_SYSTEM;
FILEFINDBUF FFbufr;
if (argc <= 1) {
exitrc = SEMANTIC_ERROR;
goto enditall;
}
name_found = stype_found = title_found = exec_cmd = retain_cmd = FALSE;
exitrc = NO_ERROR;
for (i = 1; i < argc; i++) {
if (argv[i][0] == '/' || argv[i][0] == '-') {
if (0 == strnicmp(_PARM(i), "TIT:", 4))
strncpy(PgmTitle, &argv[i][5], sizeof(PgmTitle));
else if (0 == stricmp(_PARM(i), "BG"))
scntl.FgBg = TRUE;
else if (0 == stricmp(_PARM(i), "FS")) {
if (stype_found) continue;
scntl.SessionType = 1;
stype_found = TRUE;
}
else if (0 == stricmp(_PARM(i), "WIN")) {
if (stype_found) continue;
scntl.SessionType = 2;
stype_found = TRUE;
}
else if (0 == stricmp(_PARM(i), "PM")) {
if (stype_found) continue;
scntl.SessionType = 3;
stype_found = TRUE;
}
else if (0 == stricmp(_PARM(i), "MIN"))
scntl.PgmControl = (scntl.PgmControl & 0x8008) | 0x0004;
else if (0 == stricmp(_PARM(i), "MAX"))
scntl.PgmControl = (scntl.PgmControl & 0x8008) | 0x0002;
else if (0 == stricmp(_PARM(i), "NOC"))
scntl.PgmControl = scntl.PgmControl | 0x0008;
else if (0 == stricmp(_PARM(i), "INV"))
scntl.PgmControl = 0x0001;
else if (0 == stricmp(_PARM(i), "I"))
scntl.InheritOpt = TRUE;
else if (0 == stricmp(_PARM(i), "CMD"))
exec_cmd = TRUE;
else if (0 == stricmp(_PARM(i), "K"))
retain_cmd = TRUE;
else if (0 == stricmp(_PARM(i), "TRACE"))
scntl.TraceOpt = TRUE;
else {
exitrc = SEMANTIC_ERROR;
goto enditall;
}
}
else {
_splitpath(argv[i], PgmDrive, PgmDir, PgmName, PgmExt);
name_found = TRUE;
break;
}
}
if (!name_found) {
exitrc = SEMANTIC_ERROR;
goto enditall;
}
if (PgmDir[0]) {
strcpy(SearchPath, PgmDrive);
strcat(SearchPath, PgmDir);
SearchCode = SEARCH_PATH;
}
else {
strcpy(SearchPath, "PATH");
SearchCode = SEARCH_ENVIRONMENT + SEARCH_CUR_DIRECTORY;
}
strcpy(SearchName, PgmName);
if (PgmExt[0])
strcat(SearchName, PgmExt);
else
strcat(SearchName, ".*" );
memset(PgmFName, '\0', sizeof(PgmFName));
DosSearchPath(SearchCode,
SearchPath,
SearchName,
PgmFName,
sizeof(PgmFName));
if (PgmFName[0]) {
if (!PgmExt[0]) {
SearchCnt = 1;
_splitpath(PgmFName, PgmDrive, PgmDir, PgmName, PgmExt);
strcpy(PgmExt, ".COM");
_makepath(PgmFName, PgmDrive, PgmDir, PgmName, PgmExt);
hdir = HDIR_SYSTEM;
if (DosFindFirst(PgmFName,
&hdir,
FILE_NORMAL + FILE_READONLY + FILE_ARCHIVED,
&FFbufr,
sizeof(FFbufr),
&SearchCnt,
0L)) {
strcpy(PgmExt, ".CMD");
_makepath(PgmFName, PgmDrive, PgmDir, PgmName, PgmExt);
SearchCnt = 1;
hdir = HDIR_SYSTEM;
if (DosFindFirst(PgmFName,
&hdir,
FILE_NORMAL + FILE_READONLY + FILE_ARCHIVED,
&FFbufr,
sizeof(FFbufr),
&SearchCnt,
0L)) {
strcpy(PgmExt, ".EXE");
_makepath(PgmFName, PgmDrive, PgmDir, PgmName, PgmExt);
SearchCnt = 1;
hdir = HDIR_SYSTEM;
if (DosFindFirst(PgmFName,
&hdir,
FILE_NORMAL + FILE_READONLY + FILE_ARCHIVED,
&FFbufr,
sizeof(FFbufr),
&SearchCnt,
0L)) {
exitrc = PROGRAM_NOT_FOUND;
goto enditall;
}
}
}
}
}
else if (exec_cmd) {
strcpy(PgmName, argv[i]);
strcpy(PgmFName, argv[i]);
}
else {
exitrc = PROGRAM_NOT_FOUND;
goto enditall;
}
if (strcmp(PgmExt, ".CMD") == 0 || exec_cmd) {
if (scntl.SessionType == 3)
scntl.SessionType = 2;
scntl.PgmName = "CMD.EXE";
strcpy(PgmArgs, (retain_cmd ? "/K " : "/c "));
strcat(PgmArgs, PgmFName);
strcat(PgmArgs, " ");
}
else
scntl.PgmName = PgmFName;
for (i++; i < argc; i++) {
strcat(PgmArgs, argv[i]);
strcat(PgmArgs, " ");
}
scntl.PgmInputs = PgmArgs;
if (PgmTitle[0])
scntl.PgmTitle = PgmTitle;
else
scntl.PgmTitle = scntl.PgmName;
strcpy(SearchName, PgmName);
strcat(SearchName, ".ICO");
memset(IconName, '\0', sizeof(IconName));
DosSearchPath(SearchCode,
SearchPath,
SearchName,
IconName,
sizeof(IconName));
scntl.IconFile = IconName;
exitrc = DosStartSession( &scntl, &idSession, &id);
enditall:;
if (exitrc == PROGRAM_NOT_FOUND)
printf("unable to locate %s\n", argv[i]);
if (exitrc == SEMANTIC_ERROR) {
printf ("Start Session Options invalid or program name not specified\n");
printf ("Valid values are BG, FS, WIN, PM, MAX, CMD, K,\n");
printf (" MIN, NOC, INV, I, TRACE\n");
}
else if (exitrc != NO_ERROR)
printf("Start Session ended with rc = %i\n", exitrc);
else;
return exitrc;
}