home *** CD-ROM | disk | FTP | other *** search
/ Gold Fish 1 / GoldFishApril1994_CD2.img / d4xx / d473 / cnewssrc / cnews_src.lzh / libamiga / shell.c < prev    next >
C/C++ Source or Header  |  1990-12-25  |  816b  |  42 lines

  1. /*
  2.  *    shell
  3.  */
  4.  
  5. #include <stdio.h>
  6. #include <string.h>
  7. #include <stdlib.h>
  8.  
  9. int shell(char *cmd, char *in, char *out)
  10. {
  11.     static char *buff;
  12.     static int bsiz = 0;
  13.     register int tmp;
  14.  
  15.     if (!cmd || !*cmd)    return( -1 );
  16.  
  17.     if (!in || !*in)    in  = "NIL:";
  18.     if (!out || !*out)    out = "NIL:";
  19.  
  20.     if ((tmp = strlen(in) + strlen(out) + strlen(cmd) + 8) > bsiz)
  21.         buff = (char *) realloc((char *) buff, bsiz = tmp);
  22.     if (buff) {
  23.         register char *p;
  24.  
  25.         if ((p=strchr(cmd, ' ')) || (p=strchr(cmd, '\t'))) {
  26.             *p = '\0';
  27.             while (isspace(*++p))
  28.                 ;
  29.         }
  30.         sprintf(buff, "%s <%s >%s %s", cmd, in, out, p ? p : "");
  31.         fprintf(stderr, "%s\n", buff);
  32.         fflush(stdout);
  33.         fflush(stderr);
  34.         if (Execute(buff, 0L, 0L))
  35.             return( 0 );
  36.     } else {
  37.         fprintf(stderr, "No memory for command: \"%s\"\n", buff);
  38.         bsiz = 0;
  39.     }
  40.     return( 1 );
  41. }
  42.