home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / mm-0.90 / prepatch.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  2.1 KB  |  88 lines

  1. /*
  2.  * Copyright (c) 1986, 1990 by The Trustees of Columbia University in
  3.  * the City of New York.  Permission is granted to any individual or
  4.  * institution to use, copy, or redistribute this software so long as it
  5.  * is not sold for profit, provided this copyright notice is retained.
  6.  */
  7.  
  8. #ifndef lint
  9. static char *rcsid = "$Header: /f/src2/encore.bin/cucca/mm/tarring-it-up/RCS/prepatch.c,v 2.1 90/10/04 18:25:34 melissa Exp $";
  10. #endif
  11.  
  12. /*
  13.  * see if patch exists on this system
  14.  * if patch exists, return false.
  15.  * if argc == 1, return true.
  16.  * if patch doesn't exist, return true.
  17.  */
  18. #include "config.h"
  19. #include "osfiles.h"
  20. #include "compat.h"
  21.  
  22. main(argc, argv, envp) 
  23. int argc;
  24. char **argv, **envp;
  25. {
  26.     int i;
  27.     struct stat sb;
  28.  
  29.     if (argc == 1)            /* success.   no need to do more */
  30.     return(0);
  31.  
  32.     if (argc == 2)
  33.     if (strcmp(argv[1], "patch.00") == 0 || stat(argv[1], &sb) < 0)
  34.         return(0);
  35.  
  36.     if (inpath("patch"))        /* found it.   fail, so patch can */
  37.     return(dopatch(argc-1,argv+1));
  38.     
  39.     fprintf(stderr,"\
  40. Your system does not seem to have the 'patch' program installed (or at\n\
  41. least it is not in your path.  Hence, the following patch files cannot\n\
  42. be applied.  You should apply them by hand before compiling MM, or\n\
  43. pick up a copy of the patch program.  It is probably available from\n\
  44. the same place you got MM.\n");
  45.     for(i = 1; i < argc; i++)
  46.     fprintf(stderr,"\t%s\n", argv[i]);
  47.     return(1);
  48. }
  49.  
  50.  
  51. inpath(fname)
  52. char *fname;
  53. {
  54.     extern char *getenv(), *index();
  55.     char *path = getenv("PATH");
  56.     char *cp = path;
  57.     char *cp1,c;
  58.     struct stat sb;
  59.     int buf[MAXPATHLEN];
  60.     
  61.     while((cp1 = index(cp,':')) != NULL) {
  62.     c = *cp1;
  63.     *cp1 = '\0';
  64.     sprintf(buf,"%s/%s",cp,fname);
  65.     if (stat(buf,&sb) == 0)        /* does it exist? */
  66.         if (sb.st_mode & 0111)
  67.         return(1);
  68.     *cp1 = c;
  69.     cp = cp1+1;
  70.     }
  71.     return(0);
  72. }
  73.  
  74. dopatch(count,files)
  75. int count;
  76. char **files;
  77. {
  78.     int i;
  79.     int ret=0;
  80.     char buf[MAXPATHLEN+20];
  81.     for(i = 0; i < count; i++) {
  82.     sprintf(buf,"patch < %s", files[i]);
  83.     fprintf(stderr, "%s\n", buf);
  84.     ret |= system(buf);
  85.     }
  86.     return(ret);
  87. }
  88.