Category : OS/2 Files
Archive   : KSH48.ZIP
Filename : OS2.C

 
Output of file : OS2.C contained in archive : KSH48.ZIP
#define INCL_DOS
#define INCL_DOSSESMGR
#define INCL_DOSERRORS
#include

#include
#include
#include
#include
#include
#include
#include
#include

int getegid(void)
{
return 0;
}

int geteuid(void)
{
return 0;
}

void noinherit(int fd)
{
DosSetFHState(fd, OPEN_FLAGS_NOINHERIT);
}

int getdup(int fd, int base)
{
int newfd, type;

for (newfd = base; newfd < _NFILES; newfd++)
if (ioctl(newfd, FGETHTYPE, &type) != -1)
continue;
else
return dup2(fd, newfd);

return -1;
}

static int isfullscreen(void)
{
PTIB ptib;
PPIB ppib;

DosGetInfoBlocks(&ptib, &ppib);
return (ppib -> pib_ultype != SSF_TYPE_WINDOWABLEVIO);
}

static int newsession(int type, int mode, char *cmd, char **args, char **env)
{
STARTDATA sd;
STATUSDATA st;
REQUESTDATA qr;
ULONG sid, pid, len, cnt, rc;
PVOID ptr;
BYTE prio;
static char queue[18];

static HQUEUE qid = -1;
char *ap, *ep, *p;

for ( cnt = 1, len = 0; args[cnt] != NULL; cnt++ )
len += strlen(args[cnt]) + 1;
p = ap = alloca(len + 2);
*p = 0;
for ( cnt = 1, len = 0; args[cnt] != NULL; cnt++ )
{
if ( cnt > 1 )
*p++ = ' ';
strcpy(p, args[cnt]);
p += strlen(p);
}

for ( cnt = 0, len = 0; env[cnt] != NULL; cnt++ )
len += strlen(env[cnt]) + 1;
p = ep = alloca(len + 2);
*p = 0;
for ( cnt = 0, len = 0; env[cnt] != NULL; cnt++ )
{
strcpy(p, env[cnt]);
p += strlen(p) + 1;
}
*p = 0;

if ( mode == P_WAIT && qid == -1 )
{
sprintf(queue, "\\queues\\ksh%04d", getpid());
if ( DosCreateQueue(&qid, QUE_FIFO, queue) )
return -1;
}

sd.Length = sizeof(sd);
sd.Related = (mode == P_WAIT);
sd.FgBg = FALSE;
sd.TraceOpt = FALSE;
sd.PgmTitle = NULL;
sd.PgmName = cmd;
sd.PgmInputs = (PBYTE) ap;
sd.TermQ = (mode == P_WAIT) ? (PBYTE) queue : NULL;
sd.Environment = (PBYTE) ep;
sd.InheritOpt = FALSE;
sd.SessionType = type;
sd.IconFile = NULL;
sd.PgmHandle = 0;
sd.PgmControl = 0;

if ( DosStartSession(&sd, &sid, &pid) )
return errno = ENOEXEC, -1;

if ( mode == P_WAIT )
{
st.Length = sizeof(st);
st.SelectInd = SET_SESSION_UNCHANGED;
st.BondInd = SET_SESSION_BOND;
DosSetSession(sid, &st);
if ( DosReadQueue(qid, &qr, &len, &ptr, 0, DCWW_WAIT, &prio, 0) )
return -1;
rc = ((PUSHORT)ptr)[1];
DosFreeMem(ptr);
exit(rc);
}
else
exit(0);
}

int _execve(char *cmd, char **args, char **env)
{
ULONG apptype;
char path[256], *p;
int rc;

strcpy(path, cmd);

for ( p = path; *p; p++ )
if ( *p == '/' )
*p = '\\';

if ( DosQueryAppType(path, &apptype) == 0 )
{
if (apptype & FAPPTYP_DOS)
return newsession(isfullscreen() ? SSF_TYPE_VDM : SSF_TYPE_WINDOWEDVDM,
P_NOWAIT, path, args, env);

if ((apptype & FAPPTYP_WINDOWSREAL) || (apptype & FAPPTYP_WINDOWSPROT) )
return newsession(isfullscreen() ? SSF_TYPE_VDM : SSF_TYPE_WINDOWEDVDM,
P_NOWAIT, path, args, env);

if ( (apptype & FAPPTYP_EXETYPE) == FAPPTYP_WINDOWAPI )
return newsession(SSF_TYPE_PM, P_NOWAIT, path, args, env);

if ( (apptype & FAPPTYP_EXETYPE) == FAPPTYP_NOTWINDOWCOMPAT ||
(apptype & FAPPTYP_EXETYPE) == FAPPTYP_NOTSPEC )
if ( !isfullscreen() )
return newsession(SSF_TYPE_FULLSCREEN, P_WAIT, path, args, env);
}

if ( (rc = spawnve(P_WAIT, path, args, env)) != -1 )
exit(rc);

return -1;
}

void UnixName(char *path)
{
for ( ; *path; path++ )
if ( *path == '\\' )
*path = '/';
}

char *index_sep(char *path)
{
char *p1 = strchr(path, '\\');
char *p2 = strchr(path, '/');
if ( !p1 ) return p2;
if ( !p2 ) return p1;
return (p1 > p2) ? p2 : p1;
}

char *rindex_sep(char *path)
{
char *p1 = strrchr(path, '\\');
char *p2 = strrchr(path, '/');
if ( !p1 ) return p2;
if ( !p2 ) return p1;
return (p1 > p2) ? p1 : p2;
}


  3 Responses to “Category : OS/2 Files
Archive   : KSH48.ZIP
Filename : OS2.C

  1. Very nice! Thank you for this wonderful archive. I wonder why I found it only now. Long live the BBS file archives!

  2. This is so awesome! 😀 I’d be cool if you could download an entire archive of this at once, though.

  3. But one thing that puzzles me is the “mtswslnkmcjklsdlsbdmMICROSOFT” string. There is an article about it here. It is definitely worth a read: http://www.os2museum.com/wp/mtswslnk/