home
***
CD-ROM
|
disk
|
FTP
|
other
***
search
/
OS/2 Shareware BBS: 2 BBS
/
02-BBS.zip
/
BTMTSRC3.ZIP
/
B_SPAWN.C
< prev
next >
Wrap
C/C++ Source or Header
|
1991-08-15
|
7KB
|
194 lines
/*--------------------------------------------------------------------------*/
/* */
/* */
/* ------------ Bit-Bucket Software, Co. */
/* \ 10001101 / Writers and Distributors of */
/* \ 011110 / Freely Available<tm> Software. */
/* \ 1011 / */
/* ------ */
/* */
/* (C) Copyright 1987-90, Bit Bucket Software Co., a Delaware Corporation. */
/* */
/* */
/* This module was originally written by Bob Hartman */
/* */
/* */
/* BinkleyTerm "Spawn" module */
/* */
/* */
/* For complete details of the licensing restrictions, please refer */
/* to the License agreement, which is published in its entirety in */
/* the MAKEFILE and BT.C, and also contained in the file LICENSE.240. */
/* */
/* USE OF THIS FILE IS SUBJECT TO THE RESTRICTIONS CONTAINED IN THE */
/* BINKLEYTERM LICENSING AGREEMENT. IF YOU DO NOT FIND THE TEXT OF */
/* THIS AGREEMENT IN ANY OF THE AFOREMENTIONED FILES, OR IF YOU DO */
/* NOT HAVE THESE FILES, YOU SHOULD IMMEDIATELY CONTACT BIT BUCKET */
/* SOFTWARE CO. AT ONE OF THE ADDRESSES LISTED BELOW. IN NO EVENT */
/* SHOULD YOU PROCEED TO USE THIS FILE WITHOUT HAVING ACCEPTED THE */
/* TERMS OF THE BINKLEYTERM LICENSING AGREEMENT, OR SUCH OTHER */
/* AGREEMENT AS YOU ARE ABLE TO REACH WITH BIT BUCKET SOFTWARE, CO. */
/* */
/* */
/* You can contact Bit Bucket Software Co. at any one of the following */
/* addresses: */
/* */
/* Bit Bucket Software Co. FidoNet 1:104/501, 1:132/491, 1:141/491 */
/* P.O. Box 460398 AlterNet 7:491/0 */
/* Aurora, CO 80046 BBS-Net 86:2030/1 */
/* Internet f491.n132.z1.fidonet.org */
/* */
/* Please feel free to contact us at any time to share your comments about */
/* our software and/or licensing policies. */
/* */
/*--------------------------------------------------------------------------*/
#include <stdio.h>
#include <time.h>
#include <stdlib.h>
#include <process.h>
#include <string.h>
#include <dos.h>
#ifdef OS_2
#define INCL_DOS
#include <os2.h>
#endif
#ifdef __TURBOC__
#include <dir.h>
#include <mem.h>
#else
#include <direct.h>
#include <memory.h>
#endif
#include "com.h"
#include "xfer.h"
#include "zmodem.h"
#include "keybd.h"
#include "sbuf.h"
#include "sched.h"
#include "externs.h"
#include "prototyp.h"
extern void hold_timer(void); /* CML */
extern void restart_timer(void); /* CML */
extern void hold_comthread(void); /* CML */
extern void restart_comthread(void); /* CML */
void b_spawn (cmd_str)
char *cmd_str;
{
#ifdef OS_2
char this_dir[80];
char *comspec;
getcwd (this_dir,79);
hold_timer(); /* CML */
hold_comthread(); /* CML */
if (cmd_str)
system (cmd_str);
else
{
if (comspec = getenv ("COMSPEC"))
spawnlp (P_WAIT, comspec, comspec, NULL);
}
restart_comthread(); /* CML */
/* Re-enable ourselves -- CML's code*/
if (Cominit (port_ptr) != 0x1954) /* FOSSIL back on */
{
printf ("\n%s\n", msgtxt[M_FOSSIL_GONE]);
exit (1);
}
restart_timer(); /* CML */
DosSelectDisk (*this_dir - 'A' + 1);
chdir (this_dir);
#else /* ifdef OS_2 */
char *p, *p1;
char **envp, *env, *save, **vp;
char this_dir[80];
int ecount;
unsigned j;
/* Save where we are */
(void) fflush (status_log);
(void) real_flush (fileno (status_log));
need_update = 0;
(void) getcwd (this_dir, 79);
if ((p = getenv ("COMSPEC")) == NULL)
p = "COMMAND.COM";
if (swapdir == NULL)
{
if (cmd_str != NULL)
(void) system (cmd_str);
else
(void) spawnlp (P_WAIT, p, p, NULL);
}
else
{
/*
* The following lines are really wierd. Basically, we need to
* pass a valid environment to DOS when we do the spawn. Unfortunately,
* it is very likely that we have changed the environment (like when
* we alter the prompt), and therefore we have to make yet another
* copy of it, and make sure it can be paragraph aligned. We pass the
* offset in paragraph format so it can just be added to the DS in
* order to get the actual paragraph location.
*/
ecount = 0;
envp = environ;
/* Count the chars in the environment */
for (vp = envp; *vp; ecount += (int) strlen (*vp++) + 1)
;
/* Add some fudge for nulls, etc */
ecount += 5;
/* Allocate space for a copy of the environment to be para aligned */
save = env = malloc ((unsigned int) (ecount + 15));
/* Align on a paragraph boundary - yucky, but it works */
*((unsigned int *)&env) = (*((unsigned int *)&env)+0xf) & (~0xf);
p1 = env;
/* Copy old environment to the new */
for (vp = envp; *vp; vp++)
p1 = strchr(strcpy(p1, *vp), '\0') + 1;
*p1++ = '\0';
*p1++ = '\0';
/* Now actually call our code that does the swapping */
swapper (p, swapdir, (int) strlen (cmd_str), cmd_str, ((unsigned) (env)) >> 4);
/* Free the stuff we allocated */
free (save);
}
/* Go back to the proper directory */
#ifdef __TURBOC__
setdisk ((unsigned) (this_dir[0] - 'A'));
#else /* __TURBOC__ */
_dos_setdrive ((unsigned) ((int) this_dir[0] - 'A' + 1), &j);
#endif
(void) chdir (this_dir);
#endif /* OS_2 */
}