modified: diffout.py
[GalaxyCodeBases.git] / c_cpp / etc / calc / version.c
blob3490f175ef49fb17aa10a9721344dad754a41a4b
1 /*
2 * version - determine the version of calc
4 * Copyright (C) 1999-2007 David I. Bell and Landon Curt Noll
6 * Primary author: David I. Bell
8 * Calc is open software; you can redistribute it and/or modify it under
9 * the terms of the version 2.1 of the GNU Lesser General Public License
10 * as published by the Free Software Foundation.
12 * Calc is distributed in the hope that it will be useful, but WITHOUT
13 * ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
14 * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General
15 * Public License for more details.
17 * A copy of version 2.1 of the GNU Lesser General Public License is
18 * distributed with calc under the filename COPYING-LGPL. You should have
19 * received a copy with calc; if not, write to Free Software Foundation, Inc.
20 * 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
22 * @(#) $Revision: 30.19 $
23 * @(#) $Id: version.c,v 30.19 2013/08/11 08:41:38 chongo Exp $
24 * @(#) $Source: /usr/local/src/bin/calc/RCS/version.c,v $
26 * Under source code control: 1990/05/22 11:00:58
27 * File existed as early as: 1990
29 * chongo <was here> /\oo/\ http://www.isthe.com/chongo/
30 * Share and enjoy! :-) http://www.isthe.com/chongo/tech/comp/calc/
34 #include <stdio.h>
35 #include <errno.h>
36 #include <string.h>
38 #if defined(CALC_VER)
39 # include <stdlib.h>
40 # include <unistd.h>
41 # define STATIC static
42 static char *program;
43 #else
44 # include "calc.h"
45 #endif
47 #include "have_unused.h"
49 #define MAJOR_VER 2 /* major library version */
50 #define MINOR_VER 12 /* minor library version */
51 #define MAJOR_PATCH 4 /* major software level under library version */
52 #define MINOR_PATCH 10 /* minor software level or 0 if not patched */
56 * calc version constants
58 int calc_major_ver = MAJOR_VER;
59 int calc_minor_ver = MINOR_VER;
60 int calc_major_patch = MAJOR_PATCH;
61 int calc_minor_patch = MINOR_PATCH;
65 * stored version
67 STATIC char *stored_version = NULL; /* version formed if != NULL */
71 * stored license info - has a side effect of copyrighting the binary
73 char *Copyright = "\n"
74 "calc - arbitrary precision calculator\n"
75 "\n"
76 "@(#) Copyright (C) 2007 David I. Bell, Landon Curt Noll and Ernest Bowen\n"
77 "\n"
78 "Initial author: David I. Bell\n"
79 "\n"
80 "Calc is open software; you can redistribute it and/or modify it under\n"
81 "the terms of the version 2.1 of the GNU Lesser General Public License\n"
82 "as published by the Free Software Foundation.\n"
83 "\n"
84 "Calc is distributed in the hope that it will be useful, but WITHOUT\n"
85 "ANY WARRANTY; without even the implied warranty of MERCHANTABILITY\n"
86 "or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Lesser General\n"
87 "Public License for more details.\n"
88 "\n"
89 "A copy of version 2.1 of the GNU Lesser General Public License is\n"
90 "distributed with calc under the filename COPYING-LGPL. You should have\n"
91 "received a copy with calc; if not, write to Free Software Foundation, Inc.\n"
92 "51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.\n"
93 "\n"
94 "@(#) For license details use the command:\thelp copying\n"
95 "The COPYING-LGPL file may be viewed with:\thelp copying-lgpl\n"
96 "\n";
100 * version - return version string
102 * This function returns a malloced version string. This version
103 * string does not contain the title, just:
105 * x.y.z.w
107 char *
108 version(void)
110 char verbuf[BUFSIZ+1]; /* form version string here */
113 * return previously stored version if one exists
115 if (stored_version) {
116 return stored_version;
120 * form the version buffer
122 snprintf(verbuf, BUFSIZ,
123 "%d.%d.%d.%d", calc_major_ver, calc_minor_ver,
124 calc_major_patch, calc_minor_patch);
127 * save the versions string into a newly malloced buffer
129 stored_version = (char *)malloc(strlen(verbuf)+1);
130 if (stored_version == NULL) {
131 fprintf(stderr, "%s: cannot malloc version string\n", program);
132 exit(70);
134 strcpy(stored_version, verbuf);
137 * return the newly malloced buffer
139 return stored_version;
143 #if defined(CALC_VER)
147 * print_rpm_version - print just the version string, rpm style
149 * This function prints a version string, rpm style:
151 * x.y.z.w-r
152 * x.y.z-r
154 * where 'r' comes from the content of the release file.
156 void
157 print_rpm_version(char *release)
159 FILE *file; /* open file */
160 char buf[BUFSIZ+1]; /* release file buffer */
161 char *p;
164 * obtain the release
166 file = fopen(release, "r");
167 if (file == NULL) {
168 fprintf(stderr, "%s: cannot open %s: %s\n",
169 program, release, strerror(errno));
170 exit(71);
172 buf[BUFSIZ] = '\0';
173 if (fgets(buf, BUFSIZ, file) == NULL) {
174 fprintf(stderr, "%s: cannot read %s: %s\n",
175 program, release, strerror(errno));
176 exit(72);
178 p = strchr(buf, '\n');
179 if (p != NULL) {
180 *p = '\0';
184 * form the version buffer
186 if (MINOR_PATCH > 0) {
187 printf("%d.%d.%d.%d-%s\n", calc_major_ver, calc_minor_ver,
188 calc_major_patch, calc_minor_patch, buf);
189 } else {
190 printf("%d.%d.%d-%s\n", calc_major_ver, calc_minor_ver,
191 calc_major_patch, buf);
193 return;
198 * print_rpm_major - print just the major part version string
200 * This function prints the major part version string:
202 * x.y.z
204 void
205 print_rpm_major(void)
208 * form the version buffer
210 printf("%d.%d.%d\n", calc_major_ver, calc_minor_ver,
211 calc_major_patch);
212 return;
217 * print_rpm_release - print just the rpm release
219 * This function prints the rpm release:
223 * where 'r' comes from the content of the release file.
225 void
226 print_rpm_release(char *release)
228 FILE *file; /* open file */
229 char buf[BUFSIZ+1]; /* release file buffer */
230 char *p;
233 * obtain the release
235 file = fopen(release, "r");
236 if (file == NULL) {
237 fprintf(stderr, "%s: cannot open %s: %s\n",
238 program, release, strerror(errno));
239 exit(73);
241 buf[BUFSIZ] = '\0';
242 if (fgets(buf, BUFSIZ, file) == NULL) {
243 fprintf(stderr, "%s: cannot read %s: %s\n",
244 program, release, strerror(errno));
245 exit(74);
247 p = strchr(buf, '\n');
248 if (p != NULL) {
249 *p = '\0';
253 * form the version buffer
255 printf("%s\n", buf);
256 return;
261 * version - print the calc version
263 /*ARGSUSED*/
265 main(int argc, char *argv[])
267 program = argv[0];
268 if (argc == 3 && strcmp(argv[1], "-r") == 0) {
269 print_rpm_version(argv[2]);
271 } else if (argc == 3 && strcmp(argv[1], "-R") == 0) {
272 print_rpm_release(argv[2]);
274 } else if (argc == 2 && strcmp(argv[1], "-V") == 0) {
275 print_rpm_major();
277 } else if (argc == 1) {
278 printf("%s\n", version());
280 } else {
281 fprintf(stderr,
282 "usage: %s [-V] [-R release_file] [-r release_file]\n",
283 program);
284 exit(75);
286 return 0;
289 #endif /* CALC_VER */