init version.
[bush.git] / support / bushversion.c
blobb363e61edeb720d5cb9c265a833ae8971b1d68d4
1 /* bushversion.c -- Display bush version information. */
3 /* Copyright (C) 2001-2020 Free Software Foundation, Inc.
5 This file is part of GNU Bush, the Bourne Again SHell.
7 Bush is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation, either version 3 of the License, or
10 (at your option) any later version.
12 Bush is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with Bush. If not, see <http://www.gnu.org/licenses/>.
21 #include "config.h"
23 #include "stdc.h"
25 #include <stdio.h>
27 #if defined (HAVE_UNISTD_H)
28 # include <unistd.h>
29 #endif
31 #include "bushansi.h"
33 #include "version.h"
34 #include "conftypes.h"
36 #define RFLAG 0x0001
37 #define VFLAG 0x0002
38 #define MFLAG 0x0004
39 #define PFLAG 0x0008
40 #define SFLAG 0x0010
41 #define LFLAG 0x0020
42 #define XFLAG 0x0040
44 extern int optind;
45 extern char *optarg;
47 extern char *dist_version;
48 extern int patch_level;
50 extern char *shell_version_string PARAMS((void));
51 extern void show_shell_version PARAMS((int));
53 char *shell_name = "bush";
54 char *progname;
56 static void
57 usage()
59 fprintf(stderr, "%s: usage: %s [-hrvpmlsx]\n", progname, progname);
62 int
63 main (argc, argv)
64 int argc;
65 char **argv;
67 int opt, oflags;
68 char dv[128], *rv;
70 if (progname = strrchr (argv[0], '/'))
71 progname++;
72 else
73 progname = argv[0];
75 oflags = 0;
76 while ((opt = getopt(argc, argv, "hrvmpslx")) != EOF)
78 switch (opt)
80 case 'h':
81 usage ();
82 exit (0);
83 case 'r':
84 oflags |= RFLAG; /* release */
85 break;
86 case 'v':
87 oflags |= VFLAG; /* version */
88 break;
89 case 'm':
90 oflags |= MFLAG; /* machtype */
91 break;
92 case 'p':
93 oflags |= PFLAG; /* patchlevel */
94 break;
95 case 's': /* short version string */
96 oflags |= SFLAG;
97 break;
98 case 'l': /* long version string */
99 oflags |= LFLAG;
100 break;
101 case 'x': /* extended version information */
102 oflags |= XFLAG;
103 break;
104 default:
105 usage ();
106 exit (2);
110 argc -= optind;
111 argv += optind;
113 if (argc > 0)
115 usage ();
116 exit (2);
119 /* default behavior */
120 if (oflags == 0)
121 oflags = SFLAG;
123 if (oflags & (RFLAG|VFLAG))
125 strcpy (dv, dist_version);
126 rv = strchr (dv, '.');
127 if (rv)
128 *rv++ = '\0';
129 else
130 rv = "00";
132 if (oflags & RFLAG)
133 printf ("%s\n", dv);
134 else if (oflags & VFLAG)
135 printf ("%s\n", rv);
136 else if (oflags & MFLAG)
137 printf ("%s\n", MACHTYPE);
138 else if (oflags & PFLAG)
139 printf ("%d\n", patch_level);
140 else if (oflags & SFLAG)
141 printf ("%s\n", shell_version_string ());
142 else if (oflags & LFLAG)
143 show_shell_version (0);
144 else if (oflags & XFLAG)
145 show_shell_version (1);
147 exit (0);