improve of cmpl.
[bush.git] / tools / srcpkgversion.c
blob1654cde10c16bf59b764f58167b35e395d184998
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 "stdio.h"
24 #include "stdlib.h"
25 #include "string.h"
26 #include "unistd.h"
28 #include "stdc.h"
30 #include <stdio.h>
32 #if defined (HAVE_UNISTD_H)
33 # include <unistd.h>
34 #endif
36 //#include "bushansi.h"
38 #include "version.h"
39 //#include "conftypes.h"
41 #define RFLAG 0x0001
42 #define VFLAG 0x0002
43 #define MFLAG 0x0004
44 #define PFLAG 0x0008
45 #define SFLAG 0x0010
46 #define LFLAG 0x0020
47 #define XFLAG 0x0040
49 extern int optind;
50 extern char *optarg;
52 extern char *dist_version;
53 extern int patch_level;
55 extern char *shell_version_string PARAMS((void));
56 extern void show_shell_version PARAMS((int));
58 char *shell_name = "bush";
59 char *progname;
61 static void
62 usage()
64 fprintf(stderr, "%s: usage: %s [-hrvpmlsx]\n", progname, progname);
67 int
68 main (argc, argv)
69 int argc;
70 char **argv;
72 int opt, oflags;
73 char dv[128], *rv;
75 if (progname = strrchr (argv[0], '/'))
76 progname++;
77 else
78 progname = argv[0];
80 oflags = 0;
81 while ((opt = getopt(argc, argv, "hrvmpslx")) != EOF)
83 switch (opt)
85 case 'h':
86 usage ();
87 exit (0);
88 case 'r':
89 oflags |= RFLAG; /* release */
90 break;
91 case 'v':
92 oflags |= VFLAG; /* version */
93 break;
94 case 'm':
95 oflags |= MFLAG; /* machtype */
96 break;
97 case 'p':
98 oflags |= PFLAG; /* patchlevel */
99 break;
100 case 's': /* short version string */
101 oflags |= SFLAG;
102 break;
103 case 'l': /* long version string */
104 oflags |= LFLAG;
105 break;
106 case 'x': /* extended version information */
107 oflags |= XFLAG;
108 break;
109 default:
110 usage ();
111 exit (2);
115 argc -= optind;
116 argv += optind;
118 if (argc > 0)
120 usage ();
121 exit (2);
124 /* default behavior */
125 if (oflags == 0)
126 oflags = SFLAG;
128 if (oflags & (RFLAG|VFLAG))
130 strcpy (dv, dist_version);
131 rv = strchr (dv, '.');
132 if (rv)
133 *rv++ = '\0';
134 else
135 rv = "00";
137 if (oflags & RFLAG)
138 printf ("%s\n", dv);
139 else if (oflags & VFLAG)
140 printf ("%s\n", rv);
141 else if (oflags & MFLAG)
142 printf ("%s\n", MACHTYPE);
143 else if (oflags & PFLAG)
144 printf ("%d\n", patch_level);
145 else if (oflags & SFLAG)
146 printf ("%s\n", shell_version_string ());
147 else if (oflags & LFLAG)
148 show_shell_version (0);
149 else if (oflags & XFLAG)
150 show_shell_version (1);
152 exit (0);