blob: b95fe104a93ca62865b6e40182b04bc4dfdff374 [file] [log] [blame]
Jari Aaltof73dda02001-11-13 17:56:06 +00001/* bashversion.c -- Display bash version information. */
2
3/* Copyright (C) 2001 Free Software Foundation, Inc.
4
5 This file is part of GNU Bash, the Bourne Again SHell.
6
7 Bash is free software; you can redistribute it and/or modify it under
8 the terms of the GNU General Public License as published by the Free
9 Software Foundation; either version 2, or (at your option) any later
10 version.
11
12 Bash is distributed in the hope that it will be useful, but WITHOUT ANY
13 WARRANTY; without even the implied warranty of MERCHANTABILITY or
14 FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
15 for more details.
16
17 You should have received a copy of the GNU General Public License along
18 with Bash; see the file COPYING. If not, write to the Free Software
19 Foundation, 59 Temple Place, Suite 330, Boston, MA 02111 USA. */
20
21#include "config.h"
22
23#include "stdc.h"
24
25#include <stdio.h>
26#include "bashansi.h"
27
28#include "version.h"
29#include "conftypes.h"
30
31#define RFLAG 0x0001
32#define VFLAG 0x0002
33#define MFLAG 0x0004
34#define PFLAG 0x0008
35#define SFLAG 0x0010
36#define LFLAG 0x0020
37#define XFLAG 0x0040
38
39extern int optind;
40extern char *optarg;
41
42extern char *dist_version;
43extern int patch_level;
44
45char *shell_name = "bash";
46char *progname;
47
48static void
49usage()
50{
51 fprintf(stderr, "%s: usage: %s [-hrvpmlsx]\n", progname, progname);
52}
53
54int
55main (argc, argv)
56 int argc;
57 char **argv;
58{
59 int opt, oflags;
60 char dv[128], *rv;
61
62 if (progname = strrchr (argv[0], '/'))
63 progname++;
64 else
65 progname = argv[0];
66
67 oflags = 0;
68 while ((opt = getopt(argc, argv, "hrvmpslx")) != EOF)
69 {
70 switch (opt)
71 {
72 case 'h':
73 usage ();
74 exit (0);
75 case 'r':
76 oflags |= RFLAG; /* release */
77 break;
78 case 'v':
79 oflags |= VFLAG; /* version */
80 break;
81 case 'm':
82 oflags |= MFLAG; /* machtype */
83 break;
84 case 'p':
85 oflags |= PFLAG; /* patchlevel */
86 break;
87 case 's': /* short version string */
88 oflags |= SFLAG;
89 break;
90 case 'l': /* long version string */
91 oflags |= LFLAG;
92 break;
93 case 'x': /* extended version information */
94 oflags |= XFLAG;
95 break;
96 default:
97 usage ();
98 exit (2);
99 }
100 }
101
102 argc -= optind;
103 argv += optind;
104
105 if (argc > 0)
106 {
107 usage ();
108 exit (2);
109 }
110
111 /* default behavior */
112 if (oflags == 0)
113 oflags = SFLAG;
114
115 if (oflags & (RFLAG|VFLAG))
116 {
117 strcpy (dv, dist_version);
118 rv = strchr (dv, '.');
119 if (rv)
120 *rv++ = '\0';
121 else
122 rv = "00";
123 }
124 if (oflags & RFLAG)
125 printf ("%s\n", dv);
126 else if (oflags & VFLAG)
127 printf ("%s\n", rv);
128 else if (oflags & MFLAG)
129 printf ("%s\n", MACHTYPE);
130 else if (oflags & PFLAG)
131 printf ("%d\n", patch_level);
132 else if (oflags & SFLAG)
133 printf ("%s\n", shell_version_string ());
134 else if (oflags & LFLAG)
135 show_shell_version (0);
136 else if (oflags & XFLAG)
137 show_shell_version (1);
138
139 exit (0);
140}