Applied patch by Vasilis Kaotsis, and added him as an author (because you don't really
recognize the original anymore :-)). git-svn-id: file:///srv/svn/repos/haiku/haiku/trunk@19818 a95241bf-73f2-0310-859d-f6bbb57e9c96
This commit is contained in:
+142
-136
@@ -1,94 +1,116 @@
|
|||||||
// Author: Ryan Fleet
|
/*
|
||||||
// Created: 9th October 2002
|
* Copyright 2002-2007, Haiku, Inc. All rights reserved.
|
||||||
// Modified: 14th October 2002
|
* Distributed under the terms of the MIT License.
|
||||||
|
*
|
||||||
|
* Authors:
|
||||||
|
* Ryan Fleet
|
||||||
|
* Vasilis Kaoutsis
|
||||||
|
*/
|
||||||
|
|
||||||
#include <cstdio>
|
|
||||||
#include <cstring>
|
#include <Application.h>
|
||||||
#include <AppFileInfo.h>
|
#include <AppFileInfo.h>
|
||||||
|
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <string.h>
|
||||||
|
|
||||||
void help(void)
|
|
||||||
|
void
|
||||||
|
usage()
|
||||||
{
|
{
|
||||||
printf("usage: version [OPTION] FILENAME [FILENAME2, ...]\n");
|
printf("usage: version [OPTION] FILENAME [FILENAME2, ...]\n"
|
||||||
printf("Returns the version of a file.\n\n");
|
"Returns the version of a file.\n\n"
|
||||||
printf(" -h, --help this usage message\n");
|
" -h, --help this usage message\n"
|
||||||
printf(" -l, --long print long version information of FILENAME\n");
|
" -l, --long print long version information of FILENAME\n"
|
||||||
printf(" -n, --numerical print in numerical mode\n");
|
" -n, --numerical print in numerical mode\n"
|
||||||
printf(" (Major miDdle miNor Variety Internal)\n");
|
" (Major miDdle miNor Variety Internal)\n"
|
||||||
printf(" -s, --system print system version instead of app version\n");
|
" -s, --system print system version instead of app version\n"
|
||||||
printf(" --version print version information for this command\n");
|
" --version print version information for this command\n");
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int getversion(const char *filename, version_kind kind, bool bLongFlag, bool bNumericalFlag)
|
status_t
|
||||||
|
get_version(const char *filename, version_kind kind, bool longFlag, bool numericalFlag)
|
||||||
{
|
{
|
||||||
BFile file(filename, O_RDONLY);
|
BFile file(filename, O_RDONLY);
|
||||||
if(file.InitCheck() != B_OK)
|
if (file.InitCheck() != B_OK) {
|
||||||
{
|
|
||||||
printf("Couldn't get file info!\n");
|
printf("Couldn't get file info!\n");
|
||||||
return 1;
|
return B_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
BAppFileInfo info(&file);
|
BAppFileInfo info(&file);
|
||||||
if(info.InitCheck() != B_OK)
|
if (info.InitCheck() != B_OK) {
|
||||||
{
|
|
||||||
printf("Couldn't get file info!\n");
|
printf("Couldn't get file info!\n");
|
||||||
return 1;
|
return B_FILE_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
version_info version;
|
version_info version;
|
||||||
if(info.GetVersionInfo(&version, kind) != B_OK)
|
if (info.GetVersionInfo(&version, kind) != B_OK) {
|
||||||
{
|
|
||||||
printf("Version unknown!\n");
|
printf("Version unknown!\n");
|
||||||
return 1;
|
return B_ERROR;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(true == bLongFlag)
|
if (longFlag) {
|
||||||
{
|
|
||||||
printf("%s\n", version.long_info);
|
printf("%s\n", version.long_info);
|
||||||
return 0;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
if(true == bNumericalFlag)
|
if (numericalFlag) {
|
||||||
{
|
|
||||||
printf("%lu ", version.major);
|
printf("%lu ", version.major);
|
||||||
printf("%lu ", version.middle);
|
printf("%lu ", version.middle);
|
||||||
printf("%lu ", version.minor);
|
printf("%lu ", version.minor);
|
||||||
switch(version.variety)
|
|
||||||
{
|
switch (version.variety) {
|
||||||
case 0: printf("d "); break;
|
case B_DEVELOPMENT_VERSION:
|
||||||
case 1: printf("a "); break;
|
printf("d ");
|
||||||
case 2: printf("b "); break;
|
break;
|
||||||
case 3: printf("g "); break;
|
|
||||||
case 4: printf("gm "); break;
|
case B_ALPHA_VERSION:
|
||||||
case 5: printf("f "); break;
|
printf("a ");
|
||||||
};
|
break;
|
||||||
|
|
||||||
|
case B_BETA_VERSION:
|
||||||
|
printf("b ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_GAMMA_VERSION:
|
||||||
|
printf("g ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_GOLDEN_MASTER_VERSION:
|
||||||
|
printf("gm ");
|
||||||
|
break;
|
||||||
|
|
||||||
|
case B_FINAL_VERSION:
|
||||||
|
printf("f ");
|
||||||
|
break;
|
||||||
|
}
|
||||||
|
|
||||||
printf("%lu\n", version.internal);
|
printf("%lu\n", version.internal);
|
||||||
return 0;
|
return B_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
printf("%s\n", version.short_info);
|
printf("%s\n", version.short_info);
|
||||||
|
return B_OK;
|
||||||
return 0;
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/*
|
/*!
|
||||||
strLessEqual(string1, string2)
|
determines whether \a string1 contains at least one or more of the characters
|
||||||
determines whether string1 contains at least one or more of the characters
|
of \a string2 but none of which \a string2 doesn't contain.
|
||||||
of string2 but none of which string2 doesn't contain.
|
|
||||||
|
examples:
|
||||||
true == ("hel" == "help"); true == ("help" == "help"); true == ("h" == "help");
|
true == ("hel" == "help"); true == ("help" == "help"); true == ("h" == "help");
|
||||||
false == ("held" == "help"); false == ("helped" == "help");
|
false == ("held" == "help"); false == ("helped" == "help");
|
||||||
*/
|
*/
|
||||||
bool strLessEqual(const char *str1, const char *str2)
|
bool
|
||||||
|
str_less_equal(const char *str1, const char *str2)
|
||||||
{
|
{
|
||||||
char *ptr1 = const_cast<char*>(str1);
|
char *ptr1 = const_cast<char*>(str1);
|
||||||
char *ptr2 = const_cast<char*>(str2);
|
char *ptr2 = const_cast<char*>(str2);
|
||||||
|
|
||||||
while(*ptr1 != '\0')
|
while (*ptr1 != '\0') {
|
||||||
{
|
if (*ptr1 != *ptr2)
|
||||||
if(*ptr1 != *ptr2)
|
|
||||||
return false;
|
return false;
|
||||||
++ptr1;
|
++ptr1;
|
||||||
++ptr2;
|
++ptr2;
|
||||||
@@ -97,105 +119,89 @@ bool strLessEqual(const char *str1, const char *str2)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
int main(int argc, char *argv[])
|
int
|
||||||
|
main(int argc, char *argv[])
|
||||||
{
|
{
|
||||||
|
BApplication app("application/x.vnd.Haiku-version");
|
||||||
version_kind kind = B_APP_VERSION_KIND;
|
version_kind kind = B_APP_VERSION_KIND;
|
||||||
bool bLongFlag = false;
|
bool longFlag = false;
|
||||||
bool bNumericalFlag = false;
|
bool numericalFlag = false;
|
||||||
int i;
|
int i;
|
||||||
|
|
||||||
if(argc < 2)
|
if (argc < 2) {
|
||||||
|
usage();
|
||||||
return 0;
|
return 0;
|
||||||
|
}
|
||||||
|
|
||||||
for(i = 1; i < argc; ++i)
|
for (i = 1; i < argc; ++i) {
|
||||||
{
|
if (argv[i][0] == '-') {
|
||||||
if(strncmp(argv[i], "-", 1) == 0)
|
|
||||||
{
|
|
||||||
char *ptr = argv[i];
|
char *ptr = argv[i];
|
||||||
++ptr;
|
++ptr;
|
||||||
|
|
||||||
if(*ptr == '-')
|
if (*ptr == '-') {
|
||||||
{
|
bool lessEqual = false;
|
||||||
bool lequal = false;
|
|
||||||
++ptr;
|
++ptr;
|
||||||
|
|
||||||
if(*ptr == 'h')
|
if (*ptr == 'h') {
|
||||||
{
|
lessEqual = str_less_equal(ptr, "help");
|
||||||
lequal = strLessEqual(ptr, "help");
|
if (lessEqual) {
|
||||||
if(lequal == true)
|
usage();
|
||||||
{
|
|
||||||
help();
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
} else if (*ptr == 'l') {
|
||||||
|
lessEqual = str_less_equal(ptr, "long");
|
||||||
else if(*ptr == 'l')
|
if (lessEqual)
|
||||||
{
|
longFlag = true;
|
||||||
lequal = strLessEqual(ptr, "long");
|
} else if (*ptr == 'n') {
|
||||||
if(lequal == true)
|
lessEqual = str_less_equal(ptr, "numerical");
|
||||||
bLongFlag = true;
|
if (lessEqual)
|
||||||
}
|
numericalFlag = true;
|
||||||
|
} else if (*ptr == 's') {
|
||||||
else if(*ptr == 'n')
|
lessEqual = str_less_equal(ptr, "system");
|
||||||
{
|
if (lessEqual)
|
||||||
lequal = strLessEqual(ptr, "numerical");
|
|
||||||
if(lequal == true)
|
|
||||||
bNumericalFlag = true;
|
|
||||||
}
|
|
||||||
|
|
||||||
else if(*ptr == 's')
|
|
||||||
{
|
|
||||||
lequal = strLessEqual(ptr, "system");
|
|
||||||
if(lequal == true)
|
|
||||||
kind = B_SYSTEM_VERSION_KIND;
|
kind = B_SYSTEM_VERSION_KIND;
|
||||||
}
|
} else if (*ptr == 'v') {
|
||||||
|
lessEqual = str_less_equal(ptr, "version");
|
||||||
else if(*ptr == 'v')
|
if (lessEqual) {
|
||||||
{
|
get_version(argv[0], B_APP_VERSION_KIND, false, false);
|
||||||
lequal = strLessEqual(ptr, "version");
|
|
||||||
if(lequal == true)
|
|
||||||
{
|
|
||||||
getversion(argv[0], B_APP_VERSION_KIND, false, false);
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
if(lequal == false)
|
if (!lessEqual)
|
||||||
printf("%s unrecognized option `%s'\n", argv[0], argv[i]);
|
printf("%s unrecognized option `%s'\n", argv[0], argv[i]);
|
||||||
}
|
} else {
|
||||||
|
while (*ptr != '\0') {
|
||||||
else while(*ptr != '\0')
|
if (*ptr == 'h') {
|
||||||
{
|
usage();
|
||||||
if(*ptr == 'h')
|
return 0;
|
||||||
{
|
} else if (*ptr == 's')
|
||||||
help();
|
kind = B_SYSTEM_VERSION_KIND;
|
||||||
return 0;
|
else if (*ptr == 'l')
|
||||||
|
longFlag = true;
|
||||||
|
else if (*ptr == 'n')
|
||||||
|
numericalFlag = true;
|
||||||
|
else {
|
||||||
|
printf("%s: invalid option -- %c\n", argv[0], *ptr);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
if (argc < 3) {
|
||||||
|
printf("%s: missing FILENAME(S) \n", argv[0]);
|
||||||
|
return 1;
|
||||||
|
}
|
||||||
|
|
||||||
|
++ptr;
|
||||||
}
|
}
|
||||||
else if(*ptr == 's')
|
|
||||||
kind = B_SYSTEM_VERSION_KIND;
|
|
||||||
else if(*ptr == 'l')
|
|
||||||
bLongFlag = true;
|
|
||||||
else if(*ptr == 'n')
|
|
||||||
bNumericalFlag = true;
|
|
||||||
else
|
|
||||||
printf("%s: invalid option -- %c\n", argv[0], *ptr);
|
|
||||||
|
|
||||||
++ptr;
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
int status = 0;
|
for (i = 1; i < argc; ++i) {
|
||||||
int retval = 0;
|
if (argv[i][0] != '-'
|
||||||
for(i = 1; i < argc; ++i)
|
&& get_version(argv[i], kind, longFlag, numericalFlag) != B_OK)
|
||||||
{
|
return 1;
|
||||||
if(strncmp(argv[i], "-", 1) != 0)
|
|
||||||
{
|
|
||||||
status = getversion(argv[i], kind, bLongFlag, bNumericalFlag);
|
|
||||||
if(status != 0)
|
|
||||||
retval = 1;
|
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
return retval;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|||||||
Reference in New Issue
Block a user