home *** CD-ROM | disk | FTP | other *** search
- /*
- * Shell to a program, swapping to EMS or Disk
- * Written by P.J. Muller
- */
-
- #include <dos.h>
- #include <stdlib.h>
- #include <string.h>
- #include <process.h>
- #include "execswap.h" /* link with EXECSWAP.OBJ */
- #include "shell.h"
-
- unsigned char swapping_enabled = 1;
- void (far *shell_message)(char swapmode, long amount) = NULL;
-
- extern void far *_brklvl;
-
- /*
- * Execute a Dos command
- * If path==NULL, execute COMSPEC
- * command may be NULL
- * Return TRUE iff ok
- */
-
- unsigned char shell(char *path, char *command)
- {
- void far *top;
- unsigned int status = 1;
- char temp[100];
- char ctemp[140];
-
- /* Default parameters */
-
- if (path == NULL)
- if ((path = getenv("COMSPEC")) == NULL)
- return 0;
-
- /* Check for non-swapping mode */
-
- if (!swapping_enabled) {
- if (shell_message != NULL)
- shell_message(SWAP_NONE, 0);
-
- if (spawnlp(P_WAIT, path, path, command, NULL) == -1)
- return 0;
- else
- return 1;
- } /* if */
-
- /* Swapping mode: Convert to Pascal strings */
-
- if (command == NULL)
- command = "";
-
- strcpy(temp+1, path);
- temp[0] = strlen(temp+1); /* Pascal string */
-
- strcpy(ctemp+1, command);
- ctemp[0] = strlen(ctemp+1); /* Pascal string */
-
- /* Get size to swap, could probably do better here */
-
- /* top = MK_FP(*(int *)MK_FP(_psp, 2), 0); */
- top = _brklvl;
- #ifndef __LARGE__
- #error Dunno if the line above will work
- #endif
-
- if (!InitExecSwap(top, "")) {
- return 0;
- } else {
- if (shell_message != NULL)
- shell_message(EmsAllocated() ? SWAP_EMS : SWAP_DISK, BytesSwapped());
-
- /* SwapVectors */
- status = ExecWithSwap(temp, ctemp);
- /* SwapVectors */
- } /* else */
-
- ShutdownExecSwap(); /* Must be called */
-
- return (status == 0);
- } /* shell */