Skip to content
This repository

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Fetching contributors…

Cannot retrieve contributors at this time

file 161 lines (134 sloc) 3.932 kb
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 146 147 148 149 150 151 152 153 154 155 156 157 158 159 160 161
/*
This file is part of Warzone 2100.
Copyright (C) 2007 Giel van Schijndel
Copyright (C) 2007-2011 Warzone 2100 Project

Warzone 2100 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 of the License, or
(at your option) any later version.

Warzone 2100 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 Warzone 2100; if not, write to the Free Software
Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
*/

#include "lib/framework/frame.h"
#include "lib/framework/debug.h"
#include "lib/framework/string_ext.h"
#include "lib/framework/stdio_ext.h"
#include "version.h"
#include "stringdef.h"

#include "src/autorevision.h"

extern const char *BACKEND;

// Two-step process to put quotes around anything, including preprocessor definitions.
#define EXPAND(token) #token
#define QUOTE(token) EXPAND(token)

#define VCS_SHORT_HASH_QUOTED QUOTE(VCS_SHORT_HASH)
#define VCS_URI_QUOTED QUOTE(VCS_URI)
#define VCS_DATE_QUOTED QUOTE(VCS_DATE)

static const char vcs_date_cstr[] = QUOTE(VCS_DATE);
static const char vcs_uri_cstr[] = QUOTE(VCS_URI);

unsigned int version_getRevision()
{
return VCS_NUM;
}

const char* version_getVersionString()
{
static const char* version_string = "3.1_beta2";

if (version_string == NULL)
{
if (strncmp(vcs_uri_cstr, "tags/", strlen("tags/")) == 0)
{
version_string = vcs_uri_cstr + strlen("tags/");
}
else if (strcmp(vcs_uri_cstr, "trunk") == 0)
{
version_string = "TRUNK " VCS_SHORT_HASH_QUOTED;
}
else if (strncmp(vcs_uri_cstr, "branches/", strlen("branches/")) == 0)
{
version_string = (VCS_URI_QUOTED " branch " VCS_SHORT_HASH_QUOTED) + strlen("branches/");
}
else if (strncmp(vcs_uri_cstr, "refs/heads/", strlen("refs/heads/")) == 0)
{
version_string = (VCS_URI_QUOTED " branch " VCS_SHORT_HASH_QUOTED) + strlen("refs/heads/");
}
else if (VCS_NUM != 0)
{
version_string = VCS_URI_QUOTED " " VCS_SHORT_HASH_QUOTED;
}
else
{
version_string = VCS_SHORT_HASH_QUOTED;
}
}

return version_string;
}

bool version_modified()
{
return VCS_WC_MODIFIED;
}

const char* version_getBuildDate()
{
return __DATE__;
}

const char* version_getBuildTime()
{
return __TIME__;
}

const char* version_getVcsDate()
{
#if (VCS_NUM == 0)
return "";
#else
static char vcs_date[sizeof(vcs_date_cstr) - 9] = { '\0' };

if (vcs_date[0] == '\0')
{
sstrcpy(vcs_date, vcs_date_cstr);
}

return vcs_date;
#endif
}

const char* version_getVcsTime()
{
#if (VCS_NUM == 0)
return "";
#else
return VCS_DATE_QUOTED + sizeof(VCS_DATE_QUOTED) - 8 - 1;
#endif
}

const char* version_getFormattedVersionString()
{
static char versionString[MAX_STR_LENGTH] = {'\0'};

if (versionString[0] == '\0')
{
// Compose the working copy state string
#if (VCS_WC_MODIFIED)
const char* wc_state = _(" (modified locally)");
#else
const char* wc_state = "";
#endif

// Compose the build type string
#ifdef DEBUG
const char* build_type = _(" - DEBUG");
#else
const char* build_type = "";
#endif

const char* build_date = NULL;

if (strncmp(vcs_uri_cstr, "tags/", strlen("tags/")) != 0)
{
sasprintf((char**)&build_date, _(" - Built %s"), version_getBuildDate());
}
else
{
build_date = "";
}

// Construct the version string
// TRANSLATORS: This string looks as follows when expanded.
// "Version <version name/number> <working copy state><BUILD DATE><BUILD TYPE>"
snprintf(versionString, MAX_STR_LENGTH, _("Version %s-%s%s%s%s"), BACKEND, version_getVersionString(), wc_state, build_date, build_type);
}

return versionString;
}
Something went wrong with that request. Please try again.