home *** CD-ROM | disk | FTP | other *** search
/ InfoMagic Internet Tools 1993 July / Internet Tools.iso / RockRidge / mail / mm / mm-0.90 / mkversion.c < prev    next >
Encoding:
C/C++ Source or Header  |  1990-12-18  |  3.1 KB  |  164 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/mkversion.c,v 2.3 90/10/04 18:24:51 melissa Exp $";
  10. #endif
  11.  
  12. /*
  13.  * mkversion:
  14.  * create a version string for MM
  15.  */
  16.  
  17. #include "config.h"
  18. #include "osfiles.h"
  19. #include "compat.h"
  20. #include "mm-patchlevel.h"
  21.  
  22. #define PROGNAME "Columbia MM"        /* program name */
  23.  
  24. #ifndef MM_MAJOR
  25. #define MM_MAJOR 0
  26. #endif
  27. #ifndef MM_MINOR
  28. #define MM_MINOR 0
  29. #endif
  30. #ifndef MM_PATCH
  31. #define MM_PATCH 0
  32. #endif
  33. #ifndef MM_EDIT
  34. #define MM_EDIT 0
  35. #endif
  36.  
  37. int maj = MM_MAJOR, min = MM_MINOR, pat = MM_PATCH, edit = MM_EDIT;
  38.  
  39. main (argc, argv) 
  40. int argc;
  41. char **argv;
  42. {
  43.     FILE *fp;
  44.     char *user, *host, *whoami (), *getlocalhostname (), *daytime ();
  45.     int fn = 0;
  46.  
  47.     if (argc > 2)
  48.     usage ();
  49.  
  50.     scanversion ();
  51.  
  52.     if (argc == 2) {
  53.     if (argv[1][0] == '-' || argv[1][0] == '+')
  54.         ++argv[1];
  55.     switch (argv[1][0]) {
  56.       case 'e':
  57.       case 'm':
  58.       case 'M':
  59.         fn = argv[1][0];
  60.         if (argv[1][1] == 0)
  61.         break;
  62.       default:
  63.         usage ();
  64.     }
  65.     }
  66.  
  67.     switch (fn) {
  68.       case 'M':
  69.     maj++;
  70.     min = edit = 0;
  71.     break;
  72.       case 'm':
  73.     min++;
  74.     edit = 0;
  75.     break;
  76.       case 'e':
  77.     edit++;
  78.     break;
  79.     }
  80.     
  81.     printf ("Updating version.h for %s %d.%d.%d(%d)\n", 
  82.         PROGNAME, maj, min, pat, edit);
  83.  
  84.     fp = fopen ("version.h", "w");
  85.     if (!fp) {
  86.     perror ("mkversion: fopen: version.h");
  87.     exit (1);
  88.     }
  89.     
  90.     fprintf (fp, "/*\n * %s\n */\n\n",
  91.          "This file is automatically generated by \"mkversion\"");
  92.  
  93.     fprintf (fp, "#include \"mm-patchlevel.h\"\n");
  94.     fprintf (fp, "#define MM_MAJOR %d\n", maj);
  95.     fprintf (fp, "#define MM_MINOR %d\n", min);
  96.     fprintf (fp, "#define MM_EDIT %d\n", edit);
  97.     fprintf (fp, "#define MM_VERSION \"%s, version %d.%d.%d(%d)\"\n",
  98.          PROGNAME, maj, min, pat, edit);
  99.  
  100.     user = whoami ();
  101.     host = getlocalhostname ();
  102.  
  103.     fprintf (fp, "#define MM_COMPILED \"");
  104.     if (user) {
  105.     if (host)
  106.         fprintf (fp, "by %s@%s ", user, host);
  107.     else
  108.         fprintf (fp, "by %s ", user);
  109.     }
  110.     fprintf (fp, "on %s\"\n", ctad ((time_t) 0));
  111.     
  112.     if (fclose (fp) == EOF) {
  113.     perror ("mkversion: fclose");
  114.     exit (1);
  115.     }
  116.  
  117.     exit (0);
  118. }
  119.  
  120. usage ()
  121. {
  122.     fprintf (stderr, "usage: mkversion [ e | m | M ]\n");
  123.     exit (1);
  124. }
  125.  
  126. scanversion ()
  127. {
  128.     int n;
  129.     char line[512];
  130.     FILE *fp;
  131.  
  132.     fp = fopen ("version.h", "r");
  133.     if (fp) {
  134.     while (fgets (line, sizeof line, fp) == line) {
  135.         if (sscanf (line, "#define MM_MAJOR %d", &n) == 1)
  136.         maj = n;
  137.         else if (sscanf (line, "#define MM_MINOR %d", &n) == 1)
  138.         min = n;
  139.         else if (sscanf (line, "#define MM_EDIT %d", &n) == 1)
  140.         edit = n;
  141.     }
  142.     fclose (fp);
  143.     }
  144. }
  145.  
  146. /*
  147.  * stubs for MM's fancy popen routines
  148.  */
  149.  
  150. FILE *
  151. mm_popen (command, type)
  152. char *command, *type;
  153. {
  154.     FILE *stream;
  155.  
  156.     return (popen(command, type));
  157. }
  158.  
  159. mm_pclose (stream)
  160. FILE *stream;
  161. {
  162.     return(pclose (stream));
  163. }
  164.