2 * Copyright 2002-2007, Haiku, Inc. All rights reserved.
3 * Distributed under the terms of the MIT License.
11 #include <Application.h>
12 #include <AppFileInfo.h>
21 printf("usage: version [OPTION] FILENAME [FILENAME2, ...]\n"
22 "Returns the version of a file.\n\n"
23 " -h, --help this usage message\n"
24 " -l, --long print long version information of FILENAME\n"
25 " -n, --numerical print in numerical mode\n"
26 " (Major miDdle miNor Variety Internal)\n"
27 " -s, --system print system version instead of app version\n"
28 " --version print version information for this command\n");
33 get_version(const char *filename
, version_kind kind
, bool longFlag
, bool numericalFlag
)
35 BFile
file(filename
, O_RDONLY
);
36 if (file
.InitCheck() != B_OK
) {
37 printf("Couldn't get file info!\n");
41 BAppFileInfo
info(&file
);
42 if (info
.InitCheck() != B_OK
) {
43 printf("Couldn't get file info!\n");
48 if (info
.GetVersionInfo(&version
, kind
) != B_OK
) {
49 printf("Version unknown!\n");
54 printf("%s\n", version
.long_info
);
59 printf("%lu ", version
.major
);
60 printf("%lu ", version
.middle
);
61 printf("%lu ", version
.minor
);
63 switch (version
.variety
) {
64 case B_DEVELOPMENT_VERSION
:
80 case B_GOLDEN_MASTER_VERSION
:
89 printf("%lu\n", version
.internal
);
93 printf("%s\n", version
.short_info
);
99 determines whether \a string1 contains at least one or more of the characters
100 of \a string2 but none of which \a string2 doesn't contain.
103 true == ("hel" == "help"); true == ("help" == "help"); true == ("h" == "help");
104 false == ("held" == "help"); false == ("helped" == "help");
107 str_less_equal(const char *str1
, const char *str2
)
109 char *ptr1
= const_cast<char*>(str1
);
110 char *ptr2
= const_cast<char*>(str2
);
112 while (*ptr1
!= '\0') {
123 main(int argc
, char *argv
[])
125 BApplication
app("application/x.vnd.Haiku-version");
126 version_kind kind
= B_APP_VERSION_KIND
;
127 bool longFlag
= false;
128 bool numericalFlag
= false;
136 for (i
= 1; i
< argc
; ++i
) {
137 if (argv
[i
][0] == '-') {
142 bool lessEqual
= false;
146 lessEqual
= str_less_equal(ptr
, "help");
151 } else if (*ptr
== 'l') {
152 lessEqual
= str_less_equal(ptr
, "long");
155 } else if (*ptr
== 'n') {
156 lessEqual
= str_less_equal(ptr
, "numerical");
158 numericalFlag
= true;
159 } else if (*ptr
== 's') {
160 lessEqual
= str_less_equal(ptr
, "system");
162 kind
= B_SYSTEM_VERSION_KIND
;
163 } else if (*ptr
== 'v') {
164 lessEqual
= str_less_equal(ptr
, "version");
166 get_version(argv
[0], B_APP_VERSION_KIND
, false, false);
172 printf("%s unrecognized option `%s'\n", argv
[0], argv
[i
]);
174 while (*ptr
!= '\0') {
178 } else if (*ptr
== 's')
179 kind
= B_SYSTEM_VERSION_KIND
;
180 else if (*ptr
== 'l')
182 else if (*ptr
== 'n')
183 numericalFlag
= true;
185 printf("%s: invalid option -- %c\n", argv
[0], *ptr
);
190 printf("%s: missing FILENAME(S) \n", argv
[0]);
200 for (i
= 1; i
< argc
; ++i
) {
201 if (argv
[i
][0] != '-'
202 && get_version(argv
[i
], kind
, longFlag
, numericalFlag
) != B_OK
)