home *** CD-ROM | disk | FTP | other *** search
/ Columbia Kermit / kermit.zip / archives / ckc072.zip / cktock.c < prev    next >
C/C++ Source or Header  |  1988-08-16  |  2KB  |  61 lines

  1. /*  xktock.c - Copy experimental C-Kermit files xk*.* to ck*.*  */
  2. /*  F. da Cruz, CUCCA, Aug 87  */
  3.  
  4. #include <stdio.h>
  5.  
  6. char name[500], cmd[500], msg[100];    /* Name, command, & message buffers */
  7.  
  8. main(argc,argv) int argc; char **argv; {
  9.     int i;
  10.  
  11.     if (argc < 2) usage();        /* Need files on command line. */
  12.  
  13. /* For each file, if name starts with "xk" change first letter to "c". */
  14. /* If file of that name already exists, exit with a warning message.   */
  15.  
  16.     for (i = 1; i < argc; i++) {    /* Loop for each file. */
  17.     strcpy(name,argv[i]);
  18.     if ((name[0] == 'x') && (name[1] == 'k')) {
  19.         *name = 'c';
  20.         if (!access(name,0)) {
  21.         fprintf(stderr,"Error: %s already exists\n",name);
  22.         printf(stderr,
  23.           "Please dispose of your ck*.* files and run this again.\n");
  24.         usage();
  25.         }
  26.         movefile(argv[i],name);    /* All OK, rename the file. */
  27.     }
  28.     }
  29.     if (!access("ckuker.mak",0)) {    /* Handle the Makefile specially. */
  30.     movefile("ckuker.mak","Makefile");
  31.     }  else {
  32.     fprintf(stderr,"\nError: Makefile (ckuker.mak) missing!\n");
  33.     exit(1);
  34.     }
  35.     printf("\nDone.  Now you can make C-Kermit for your system.\n");
  36.     printf("See the Makefile for instructions.\n");
  37.     exit(0);
  38. }
  39.   
  40. movefile(n1,n2) char *n1, *n2; {    /* Function to rename a file.  */
  41.     int a;
  42.     sprintf(cmd,"mv %s %s",n1,n2);    /* Construct command */
  43.     printf(cmd);            /* Echo it. */
  44.     a = system(cmd);            /* Run it.  */
  45.     if ((a == 127) || (a < 0)) {    /* Handle errors. */
  46.     sprintf(msg,"\n%s failed (%d)",a,cmd);
  47.     perror(msg);
  48.     exit(1);
  49.     } else printf(" (ok)\n");
  50. }
  51.  
  52. usage() {                /* Usage message & exit */
  53.     fprintf(stderr,"\nUsage: xktock xk*\n\n");
  54.     fprintf(stderr,"This programs renames the experimental C-Kermit files\n");
  55.     fprintf(stderr,"from xk*.* to ck*.* so that you can build them using\n");
  56.     fprintf(stderr,"the Makefile.  Before running this program, put all\n");
  57.     fprintf(stderr,"xk*.* files in a directory by themselves and cd to\n");
  58.     fprintf(stderr,"that directory.\n\n");
  59.     exit(1);
  60. }
  61.