1 /* Simple program to make new version numbers for the shell.
2 Big deal, but it was getting out of hand to do everything
5 /* Copyright (C) 1989 Free Software Foundation, Inc.
7 This file is part of GNU Bash, the Bourne Again SHell.
9 Bash is free software; you can redistribute it and/or modify it under
10 the terms of the GNU General Public License as published by the Free
11 Software Foundation; either version 1, or (at your option) any later
14 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
15 WARRANTY; without even the implied warranty of MERCHANTABILITY or
16 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
19 You should have received a copy of the GNU General Public License along
20 with Bash; see the file COPYING. If not, write to the Free Software
21 Foundation, 675 Mass Ave, Cambridge, MA 02139, USA. */
25 #include <sys/types.h>
26 #include "posixstat.h"
42 int buildver = 0, patchlevel = 0;
43 int dist = 0, build = 0, patch = 0;
44 int dist_inc = 0, build_inc = 0, patch_inc = 0;
45 int dot_dist_needs_making = 0;
51 status = dir = (char *)0;
52 while (arg_index < argc && argv[arg_index][0] == '-')
54 if (strcmp (argv[arg_index], "-dist") == 0)
59 else if (strcmp (argv[arg_index], "-build") == 0)
64 else if (strcmp (argv[arg_index], "-patch") == 0)
69 else if (strcmp (argv[arg_index], "-dir") == 0)
71 dir = argv[++arg_index];
74 fprintf (stderr, "%s: `-dir' requires an argument\n", progname);
77 if (stat (dir, &sb) < 0)
79 fprintf (stderr, "%s: cannot stat %s\n", progname, dir);
82 if ((sb.st_mode & S_IFMT) != S_IFDIR)
84 fprintf (stderr, "%s: not a directory\n", progname);
88 else if (strcmp (argv[arg_index], "-status") == 0)
90 status = argv[++arg_index];
93 fprintf (stderr, "%s: `-status' requires an argument\n", progname);
99 fprintf (stderr, "%s: unknown option: %s\n", progname, argv[arg_index]);
100 fprintf (stderr, "usage: %s [-dist|-patch|-build] [-dir directory]\n", progname);
106 if (get_float_from_file (".distribution", &distver, 1) == 0)
107 dot_dist_needs_making++;
109 if (get_int_from_file (".patchlevel", &patchlevel, 1) == 0)
115 if (get_int_from_file (".build", &buildver, 0) == 0)
118 /* Setting distribution version. */
119 if (dist && arg_index < argc)
120 if (sscanf (argv[arg_index], "%f", &distver) != 1)
122 fprintf (stderr, "%s: Bad input `%s'. Expected float value for -dist.\n",
123 progname, argv[arg_index]);
132 /* Setting patchlevel via argument. */
133 if (patch && arg_index < argc)
134 if (sscanf (argv[arg_index], "%d", &patchlevel) != 1)
136 fprintf (stderr, "%s: Bad input `%s'. Expected int value for -patch.\n",
137 progname, argv[arg_index]);
146 if (build && arg_index < argc)
147 if (sscanf (argv[arg_index], "%d", &buildver) != 1)
149 fprintf (stderr, "%s: Bad input `%s'. Expected int value for -build.\n",
150 progname, argv[arg_index]);
159 if (dot_dist_needs_making && !distver)
161 fprintf (stderr, "%s: There is no `.distribution' file to infer from.\n", progname);
166 distver = distver + 0.01;
174 file = must_open ("newversion.h", "w");
176 /* Output the leading comment. */
178 "/* Version control for the shell. This file gets changed when you say\n\
179 `make newversion' to the Makefile. It is created by mkversion. */\n");
181 fprintf (file, "\n/* The distribution version number of this shell. */\n");
182 fprintf (file, "#define DISTVERSION \"%.2f\"\n", distver);
184 fprintf (file, "\n/* The patch level of this version of the shell. */\n");
185 fprintf (file, "#define PATCHLEVEL %d\n", patchlevel);
187 fprintf (file, "\n/* The last built version of this shell. */\n");
188 fprintf (file, "#define BUILDVERSION %d\n", buildver);
192 fprintf (file, "\n/* The release status of this shell. */\n");
193 fprintf (file, "#define RELSTATUS \"%s\"\n", status);
196 fprintf (file, "\n/* A version string for use by sccs and the what command. */\n\n");
198 fprintf (file, "#define SCCSVERSION \"@(#)Bash version %.2f.%d(%d) %s GNU\"\n\n",
199 distver, patchlevel, buildver, status);
201 fprintf (file, "#define SCCSVERSION \"@(#)Bash version %.2f.%d(%d) GNU\"\n\n",
202 distver, patchlevel, buildver);
206 file = must_open (".build", "w");
207 fprintf (file, "%d\n", buildver);
210 /* Making a new distribution. */
213 file = must_open (".distribution", "w");
214 fprintf (file, "%.2f\n", distver);
218 /* Releasing a new patch level. */
221 file = must_open (".patchlevel", "w");
222 fprintf (file, "%d\n", patchlevel);
230 makename (fn, from_srcdir)
236 dlen = (from_srcdir && dir) ? strlen (dir) + 1 : 0;
237 ret = (char *)malloc (dlen + strlen (fn) + 1);
240 fprintf (stderr, "%s: malloc failed\n", progname);
243 if (from_srcdir && dir)
244 sprintf (ret, "%s/%s", dir, fn);
246 (void)strcpy (ret, fn);
251 get_float_from_file (filename, var, from_srcdir)
260 name = makename (filename, from_srcdir);
261 stream = fopen (name, "r");
263 if (stream == (FILE *)NULL)
265 result = fscanf (stream, "%f\n", var);
267 return (result == 1);
270 get_int_from_file (filename, var, from_srcdir)
272 int *var, from_srcdir;
278 name = makename (filename, from_srcdir);
279 stream = fopen (name, "r");
281 if (stream == (FILE *)NULL)
283 result = fscanf (stream, "%d\n", var);
285 return (result == 1);
289 must_open (name, mode)
292 FILE *temp = fopen (name, mode);
296 fprintf (stderr, "%s: Cannot open `%s' for mode `%s'.\n",
297 progname, name, mode);
300 "Perhaps you don't have %s permission to the file or directory.\n",
301 (strcmp (mode, "w") == 0) ? "write" : "read");