Imported from ../bash-2.0.tar.gz.
[platform/upstream/bash.git] / support / mkversion.c
similarity index 81%
rename from newversion.c
rename to support/mkversion.c
index bdba480..8164a8f 100644 (file)
@@ -20,12 +20,16 @@ You should have received a copy of the GNU General Public License along
 with Bash; see the file COPYING.  If not, write to the Free Software
 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
 
+#include "config.h"
+
 #include <sys/types.h>
 #include "posixstat.h"
 #include <stdio.h>
+#include "bashansi.h"
 
 char *progname;
 char *dir;
+char *status;
 
 FILE *must_open ();
 
@@ -44,6 +48,7 @@ main (argc, argv)
 
   progname = argv[0];
 
+  status = dir = (char *)0;
   while (arg_index < argc && argv[arg_index][0] == '-')
     {
       if (strcmp (argv[arg_index], "-dist") == 0)
@@ -80,6 +85,15 @@ main (argc, argv)
              exit (1);
            }
        }
+      else if (strcmp (argv[arg_index], "-status") == 0)
+        {
+          status = argv[++arg_index];
+         if (status == 0)
+           {
+             fprintf (stderr, "%s: `-status' requires an argument\n", progname);
+             exit (1);
+           }
+        }
       else
        {
          fprintf (stderr, "%s: unknown option: %s\n", progname, argv[arg_index]);
@@ -89,16 +103,16 @@ main (argc, argv)
       arg_index++;
     }
 
-  if (get_float_from_file (".distribution", &distver) == 0)
+  if (get_float_from_file (".distribution", &distver, 1) == 0)
     dot_dist_needs_making++;
 
-  if (get_int_from_file (".patchlevel", &patchlevel) == 0)
+  if (get_int_from_file (".patchlevel", &patchlevel, 1) == 0)
     {
       patchlevel = 0;
       patch_inc = 0;
     }
 
-  if (get_int_from_file (".build", &buildver) == 0)
+  if (get_int_from_file (".build", &buildver, 0) == 0)
     buildver = 0;
 
   /* Setting distribution version. */
@@ -162,7 +176,7 @@ main (argc, argv)
   /* Output the leading comment. */
   fprintf (file, 
 "/* Version control for the shell.  This file gets changed when you say\n\
-   `make newversion' to the Makefile.  It is created by newversion.aux. */\n");
+   `make newversion' to the Makefile.  It is created by mkversion. */\n");
 
   fprintf (file, "\n/* The distribution version number of this shell. */\n");
   fprintf (file, "#define DISTVERSION \"%.2f\"\n", distver);
@@ -173,9 +187,19 @@ main (argc, argv)
   fprintf (file, "\n/* The last built version of this shell. */\n");
   fprintf (file, "#define BUILDVERSION %d\n", buildver);
 
+  if (status)
+    {
+      fprintf (file, "\n/* The release status of this shell. */\n");
+      fprintf (file, "#define RELSTATUS \"%s\"\n", status);
+    }
+
   fprintf (file, "\n/* A version string for use by sccs and the what command. */\n\n");
-  fprintf (file, "#define SCCSVERSION \"@(#)Bash version %.2f.%d(%d) GNU\"\n\n",
-    distver, patchlevel, buildver);
+  if (status)
+    fprintf (file, "#define SCCSVERSION \"@(#)Bash version %.2f.%d(%d) %s GNU\"\n\n",
+      distver, patchlevel, buildver, status);
+  else
+    fprintf (file, "#define SCCSVERSION \"@(#)Bash version %.2f.%d(%d) GNU\"\n\n",
+      distver, patchlevel, buildver);
 
   fclose (file);
 
@@ -203,37 +227,37 @@ main (argc, argv)
 }
 
 char *
-makename (fn)
+makename (fn, from_srcdir)
      char *fn;
 {
   char *ret;
-  int dlen = 0;
+  int dlen;
 
-  if (dir)
-    dlen = strlen (dir) + 1;
+  dlen = (from_srcdir && dir) ? strlen (dir) + 1 : 0;
   ret = (char *)malloc (dlen + strlen (fn) + 1);
   if (ret == 0)
     {
       fprintf (stderr, "%s: malloc failed\n", progname);
       exit (1);
     }
-  if (dir)
+  if (from_srcdir && dir)
     sprintf (ret, "%s/%s", dir, fn);
   else
-    strcpy (ret, fn);
+    (void)strcpy (ret, fn);
 
   return ret;
 }
 
-get_float_from_file (filename, var)
+get_float_from_file (filename, var, from_srcdir)
      char *filename;
      float *var;
+     int from_srcdir;
 {
   FILE *stream;
   int result;
   char *name;
 
-  name = makename (filename);
+  name = makename (filename, from_srcdir);
   stream = fopen (name, "r");
   free (name);
   if (stream == (FILE *)NULL)
@@ -243,15 +267,15 @@ get_float_from_file (filename, var)
   return (result == 1);
 }
 
-get_int_from_file (filename, var)
+get_int_from_file (filename, var, from_srcdir)
      char *filename;
-     int *var;
+     int *var, from_srcdir;
 {
   FILE *stream;
   int result;
   char *name;
 
-  name = makename (filename);
+  name = makename (filename, from_srcdir);
   stream = fopen (name, "r");
   free (name);
   if (stream == (FILE *)NULL)