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