home *** CD-ROM | disk | FTP | other *** search
- /* ==( bench/docmd.c )== */
-
- /* ----------------------------------------------- */
- /* Pro-C Copyright (C) 1988 - 1990 Vestronix Inc. */
- /* Modification to this source is not supported */
- /* by Vestronix Inc. */
- /* All Rights Reserved */
- /* ----------------------------------------------- */
- /* Written Nig 1-Jan-87 */
- /* Modified Geo 11-Dec-89 See comments below */
- /* ----------------------------------------------- */
- /* %W% (%H% %T%) */
-
- /*
- * Modifications
- *
- * 15-Dec-89 Geo - taken out do_dos call do_cmd
- * 11-Dec-89 Geo - V2 version
- * 25-Oct-89 Geo - 1.32 Merge
- */
-
- # include <stdio.h>
- # include <bench.h>
-
- #define MSG703 "Change Working Directory Error"
-
- # ifdef UNIX
- int do_cmd(va_alist)
- va_dcl
- # else
- int do_cmd(char *va_alist, ...)
- # endif
- {
- char buffer[51]; /* Buffer for current working directory */
- char buffer2[51];
- char cmdbuf[125];
- int res;
- va_list ap;
- char *fmt;
-
- if (getcwd(buffer, sizeof(buffer)) == NULL) /* Store cwd in buffer */
- errmsg(MSG703); /* getcwd error */
-
- #ifdef MOUSE
- mouse_cursor(OFF);
- #endif
- /* Make the monitor look normal */
- resetscr();
-
- # ifdef UNIX
- va_start(ap);
- fmt = va_arg(ap, char *);
- # else
- va_start(ap, va_alist);
- fmt = va_alist;
- # endif
-
- /* A shell */
- if (fmt == NULL)
- {
- char *sh;
-
- fprintf(stderr, "\nType EXIT to return to Pro-C ...\n");
- fflush(stderr);
-
- # ifdef MSDOS
- # define SHELLENV "COMSPEC"
- # define DSHELL "command.com"
- # endif
- # ifdef UNIX
- # define SHELLENV "SHELL"
- # define DSHELL "/bin/sh"
- # endif
-
- #ifdef MOUSE
- mouse_cursor(OFF);
- mouse_end();
- #endif
-
- if ((sh = getenv(SHELLENV)) == NULL)
- sh = DSHELL;
- /* Will get round to doing a fork() with wait (U) exec/spawn (D) - GEO */
- res = system(sh);
-
- #ifdef MOUSE
- mouse_init();
- #endif
- }
- else
- {
- strcpy(cmdbuf, fmt);
-
- while ((fmt = va_arg(ap, char *)) != NULL)
- {
- strcat(cmdbuf, " ");
- strcat(cmdbuf, fmt);
- }
-
- va_end(ap);
-
- res = system(cmdbuf);
- }
-
- # ifdef MSDOS
- getcwd(buffer2, sizeof(buffer2));
- if (*buffer != *buffer2) /* Drive has been changed */
- { /* So get back to original */
- strcpy(buffer2, buffer);
- buffer2[2] = '\0';
- system(buffer2);
- }
- # endif
-
- /* Restore current directory, just in case */
- chdir(buffer);
-
- redraws();
- #ifdef MOUSE
- mouse_cursor(ON);
- #endif
- return(res);
- }
-