home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / c-kermit / dokermit.c < prev    next >
C/C++ Source or Header  |  2020-01-01  |  935b  |  48 lines

  1. /*  d o k e r m i t  --  do a list of Kermit commands  */
  2.  
  3. /*
  4.    Usage: "dokermit command, command, command, ..."
  5.    Encloses the command list in -C "..." and adds ", exit",
  6.    invokes the real Kermit program with it, and returns
  7.    the Kermit program's exit status.
  8.  
  9.    F. da Cruz, Colubmia University, Feb 2001.
  10. */   
  11.  
  12. #include <stdio.h>
  13.  
  14. #define BUFLEN 10240
  15. #define NUL '\0'
  16.  
  17. char buf[BUFLEN] = { NUL, NUL };
  18.  
  19. main(argc,argv) int argc; char *argv[]; {
  20.     int i, k, n = BUFLEN;
  21.     char * s, * p = buf;
  22.  
  23.     argv[argc++] = ", exit\"";
  24.  
  25.     for (i = 0; i < argc; i++) {
  26.     s = (i == 0) ? "kermit -C \"" : argv[i];
  27.     k = strlen(s);
  28.     if (k < 1)
  29.       continue;
  30.     if (k > n) {
  31.         printf("?Command too long -- %d max\n", BUFLEN);
  32.         exit(1);
  33.     }
  34.     strncpy(p,s,k);
  35.     p += k;
  36.     n -= k;
  37.     if (i == 0 || i == (argc - 2))
  38.       continue;
  39.     if (i == (argc - 1))
  40.       break;
  41.     *p++ = ' ';
  42.     n--;
  43.     }          
  44.     *p = NUL;
  45.     exit(system(buf) & 0xff);
  46. }
  47.  
  48.