home *** CD-ROM | disk | FTP | other *** search
/ Jason Aller Floppy Collection / 125.img / PRO-C4.ZIP / BENCH1.ZIP / BENCH / DOCMD.C < prev    next >
Encoding:
C/C++ Source or Header  |  1990-05-28  |  2.5 KB  |  123 lines

  1. /* ==( bench/docmd.c )== */
  2.  
  3. /* ----------------------------------------------- */
  4. /* Pro-C  Copyright (C) 1988 - 1990 Vestronix Inc. */
  5. /* Modification to this source is not supported    */
  6. /* by Vestronix Inc.                               */
  7. /*            All Rights Reserved                  */
  8. /* ----------------------------------------------- */
  9. /* Written   Nig   1-Jan-87                        */
  10. /* Modified  Geo  11-Dec-89  See comments below    */
  11. /* ----------------------------------------------- */
  12. /* %W%  (%H% %T%) */
  13.  
  14. /*
  15.  *  Modifications
  16.  *
  17.  *  15-Dec-89  Geo - taken out do_dos call do_cmd
  18.  *  11-Dec-89  Geo - V2 version
  19.  *  25-Oct-89  Geo - 1.32 Merge
  20. */
  21.  
  22. # include <stdio.h>
  23. # include <bench.h>
  24.  
  25. #define MSG703 "Change Working Directory Error"
  26.  
  27. # ifdef UNIX
  28. int do_cmd(va_alist)
  29. va_dcl
  30. # else
  31. int do_cmd(char *va_alist, ...)
  32. # endif
  33. {
  34.     char buffer[51];       /*  Buffer for current working directory  */
  35.     char buffer2[51];
  36.     char cmdbuf[125];
  37.     int res;
  38.     va_list ap;
  39.     char *fmt;
  40.  
  41.    if (getcwd(buffer, sizeof(buffer)) == NULL)  /* Store cwd in buffer  */
  42.        errmsg(MSG703);  /*  getcwd error  */
  43.  
  44. #ifdef MOUSE
  45.     mouse_cursor(OFF);
  46. #endif
  47.    /* Make the monitor look normal */
  48.    resetscr();
  49.  
  50. # ifdef UNIX
  51.     va_start(ap);
  52.     fmt = va_arg(ap, char *);
  53. # else
  54.     va_start(ap, va_alist);
  55.     fmt = va_alist;
  56. # endif
  57.  
  58.     /* A shell */
  59.     if (fmt == NULL)
  60.     {
  61.     char *sh;
  62.  
  63.        fprintf(stderr, "\nType EXIT to return to Pro-C ...\n");
  64.         fflush(stderr);
  65.  
  66. # ifdef MSDOS
  67. #  define SHELLENV "COMSPEC"
  68. #  define DSHELL "command.com"
  69. # endif
  70. # ifdef UNIX
  71. #  define SHELLENV "SHELL"
  72. #  define DSHELL "/bin/sh"
  73. # endif
  74.  
  75. #ifdef MOUSE
  76.         mouse_cursor(OFF);
  77.         mouse_end();
  78. #endif
  79.  
  80.         if ((sh = getenv(SHELLENV)) == NULL)
  81.             sh = DSHELL;
  82.         /* Will get round to doing a fork() with wait (U) exec/spawn (D) - GEO */
  83.        res = system(sh);
  84.  
  85. #ifdef MOUSE
  86.         mouse_init();
  87. #endif
  88.     }
  89.     else
  90.     {
  91.         strcpy(cmdbuf, fmt);
  92.  
  93.         while ((fmt = va_arg(ap, char *)) != NULL)
  94.         {
  95.             strcat(cmdbuf, " ");
  96.             strcat(cmdbuf, fmt);
  97.         }
  98.  
  99.         va_end(ap);
  100.  
  101.        res = system(cmdbuf);
  102.     }
  103.  
  104. # ifdef MSDOS
  105.     getcwd(buffer2, sizeof(buffer2));
  106.     if (*buffer != *buffer2)                /* Drive has been changed */
  107.     {                                            /* So get back to original */
  108.         strcpy(buffer2, buffer);
  109.         buffer2[2] = '\0';
  110.         system(buffer2);
  111.     }
  112. # endif
  113.  
  114.    /* Restore current directory, just in case */
  115.    chdir(buffer);
  116.  
  117.    redraws();
  118. #ifdef MOUSE
  119.     mouse_cursor(ON);
  120. #endif
  121.    return(res);
  122. }
  123.