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. */
23 #include <sys/types.h>
24 #include "posixstat.h"
38 int buildver = 0, patchlevel = 0;
39 int dist = 0, build = 0, patch = 0;
40 int dist_inc = 0, build_inc = 0, patch_inc = 0;
41 int dot_dist_needs_making = 0;
47 while (arg_index < argc && argv[arg_index][0] == '-')
49 if (strcmp (argv[arg_index], "-dist") == 0)
54 else if (strcmp (argv[arg_index], "-build") == 0)
59 else if (strcmp (argv[arg_index], "-patch") == 0)
64 else if (strcmp (argv[arg_index], "-dir") == 0)
66 dir = argv[++arg_index];
69 fprintf (stderr, "%s: `-dir' requires an argument\n", progname);
72 if (stat (dir, &sb) < 0)
74 fprintf (stderr, "%s: cannot stat %s\n", progname, dir);
77 if ((sb.st_mode & S_IFMT) != S_IFDIR)
79 fprintf (stderr, "%s: not a directory\n", progname);
85 fprintf (stderr, "%s: unknown option: %s\n", progname, argv[arg_index]);
86 fprintf (stderr, "usage: %s [-dist|-patch|-build] [-dir directory]\n", progname);
92 if (get_float_from_file (".distribution", &distver) == 0)
93 dot_dist_needs_making++;
95 if (get_int_from_file (".patchlevel", &patchlevel) == 0)
101 if (get_int_from_file (".build", &buildver) == 0)
104 /* Setting distribution version. */
105 if (dist && arg_index < argc)
106 if (sscanf (argv[arg_index], "%f", &distver) != 1)
108 fprintf (stderr, "%s: Bad input `%s'. Expected float value for -dist.\n",
109 progname, argv[arg_index]);
118 /* Setting patchlevel via argument. */
119 if (patch && arg_index < argc)
120 if (sscanf (argv[arg_index], "%d", &patchlevel) != 1)
122 fprintf (stderr, "%s: Bad input `%s'. Expected int value for -patch.\n",
123 progname, argv[arg_index]);
132 if (build && arg_index < argc)
133 if (sscanf (argv[arg_index], "%d", &buildver) != 1)
135 fprintf (stderr, "%s: Bad input `%s'. Expected int value for -build.\n",
136 progname, argv[arg_index]);
145 if (dot_dist_needs_making && !distver)
147 fprintf (stderr, "%s: There is no `.distribution' file to infer from.\n", progname);
152 distver = distver + 0.01;
160 file = must_open ("newversion.h", "w");
162 /* Output the leading comment. */
164 "/* Version control for the shell. This file gets changed when you say\n\
165 `make newversion' to the Makefile. It is created by newversion.aux. */\n");
167 fprintf (file, "\n/* The distribution version number of this shell. */\n");
168 fprintf (file, "#define DISTVERSION \"%.2f\"\n", distver);
170 fprintf (file, "\n/* The patch level of this version of the shell. */\n");
171 fprintf (file, "#define PATCHLEVEL %d\n", patchlevel);
173 fprintf (file, "\n/* The last built version of this shell. */\n");
174 fprintf (file, "#define BUILDVERSION %d\n", buildver);
176 fprintf (file, "\n/* A version string for use by sccs and the what command. */\n\n");
177 fprintf (file, "#define SCCSVERSION \"@(#)Bash version %.2f.%d(%d) GNU\"\n\n",
178 distver, patchlevel, buildver);
182 file = must_open (".build", "w");
183 fprintf (file, "%d\n", buildver);
186 /* Making a new distribution. */
189 file = must_open (".distribution", "w");
190 fprintf (file, "%.2f\n", distver);
194 /* Releasing a new patch level. */
197 file = must_open (".patchlevel", "w");
198 fprintf (file, "%d\n", patchlevel);
213 dlen = strlen (dir) + 1;
214 ret = (char *)malloc (dlen + strlen (fn) + 1);
217 fprintf (stderr, "%s: malloc failed\n", progname);
221 sprintf (ret, "%s/%s", dir, fn);
228 get_float_from_file (filename, var)
236 name = makename (filename);
237 stream = fopen (name, "r");
239 if (stream == (FILE *)NULL)
241 result = fscanf (stream, "%f\n", var);
243 return (result == 1);
246 get_int_from_file (filename, var)
254 name = makename (filename);
255 stream = fopen (name, "r");
257 if (stream == (FILE *)NULL)
259 result = fscanf (stream, "%d\n", var);
261 return (result == 1);
265 must_open (name, mode)
268 FILE *temp = fopen (name, mode);
272 fprintf (stderr, "%s: Cannot open `%s' for mode `%s'.\n",
273 progname, name, mode);
276 "Perhaps you don't have %s permission to the file or directory.\n",
277 (strcmp (mode, "w") == 0) ? "write" : "read");