cloudy  trunk
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Friends Macros Pages
version.cpp
Go to the documentation of this file.
1 /* This file is part of Cloudy and is copyright (C)1978-2022 by Gary J. Ferland and
2  * others. For conditions of distribution and use see copyright notice in license.txt */
3 
4 #include "cddefines.h"
5 #include "date.h"
6 #include "version.h"
7 #include "service.h"
8 
9 static const int CLD_MAJOR = 17;
10 static const int CLD_MINOR = 2;
11 static const int CLD_PATCH = 0;
12 
13 #ifdef SVN_REVISION
14 static const char* svn_revision = SVN_REVISION;
15 #else
16 static const char* svn_revision = "rev_not_set";
17 #endif
18 
19 static const char* cUrl = "$HeadURL: svn://svn.nublado.org/cloudy/branches/c17_branch/source/version.cpp $";
20 
22 {
23  static const char chMonth[12][4] =
24  { "Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec" };
25 
26  // first analyze the URL to determine where we live, the chVersion string is derived from that
27  // the code below is based on the following naming scheme:
28  //
29  // /branches/c08_branch -- release branch, all bug fixes are submitted here
30  //
31  // /tags/develop/c08.00_rc1 -- release candidates go here
32  //
33  // /tags/release/c08.00 -- first official release
34  // /tags/release/c08.01 -- first bug-fix rollup, etc...
35  //
36  // /tags/patch_versions/c08.00_pl00 -- identical to /tags/release/c08.00
37  // /tags/patch_versions/c08.00_pl01 -- first patch update, etc...
38  //
39  // /trunk -- this will be labeled as "experimental"
40  // /tags/stable -- ditto
41  // /branches/* -- ditto, note that "*" can be anything except c??_branch
42 
43  vector<string> Part;
44  string Url = cUrl;
45  Split( Url, "/", Part, SPM_RELAX );
46  if( Part.size() >= 3 )
47  {
48  // the last two parts are "source" and "version.cpp $", we don't need them...
49  // the one before is the relevant identifier (e.g. "trunk", "newmole", "c08.01")
50  // for conciseness we will refer to it below as the "branch"
51  string Branch = Part[Part.size()-3];
52 
53  bool lgReleaseTag = ( Url.find("/tags/release/") != string::npos );
54  bool lgPatchTag = ( Url.find("/tags/patch_versions/") != string::npos );
55  bool lgDevelopTag = ( Url.find("/tags/develop/") != string::npos );
56  // this expects a branch name like "c08_branch"
57  lgReleaseBranch = ( Url.find("/branches/") != string::npos &&
58  Branch.size() == 10 && Branch[0] == 'c' &&
59  Branch.find("_branch") != string::npos );
60 
61  lgRelease = ( lgReleaseTag || lgPatchTag );
62 
63  // determine if this is a beta version
64  string::size_type ptr;
65  if( lgDevelopTag && ( ptr = Branch.find( "_rc" ) ) != string::npos )
66  // this expects a branch name like "c08.00_rc1"
67  sscanf( Branch.substr( ptr+3 ).c_str(), "%ld", &nBetaVer );
68  else
69  nBetaVer = 0;
70 
71  // beta versions are always generated from the release branch...
72  if( nBetaVer > 0 )
73  lgReleaseBranch = true;
74 
75  int nMajorLevel=0, nMinorLevel=0, nPatchLevel=0;
76 
77  if( lgReleaseBranch || lgRelease || nBetaVer > 0 )
78  {
79  // this expects a branch name starting with "c08"
80  sscanf( Branch.substr(1,2).c_str(), "%d", &nMajorLevel );
81  if( nMajorLevel != CLD_MAJOR )
82  fprintf( ioQQQ, "PROBLEM - CLD_MAJOR mismatch, please check version.cpp\n" );
83  }
84 
85  if( lgRelease || nBetaVer > 0 )
86  {
87  // this expects a branch name starting with "c08.01"
88  sscanf( Branch.substr(4,2).c_str(), "%d", &nMinorLevel );
89  if( nMinorLevel != CLD_MINOR )
90  fprintf( ioQQQ, "PROBLEM - CLD_MINOR mismatch, please check version.cpp\n" );
91  }
92 
93  if( lgPatchTag )
94  {
95  // this expects a branch name like "c08.01_pl02"
96  sscanf( Branch.substr(9,2).c_str(), "%d", &nPatchLevel );
97  if( nPatchLevel != CLD_PATCH )
98  fprintf( ioQQQ, "PROBLEM - CLD_PATCH mismatch, please check version.cpp\n" );
99  // c08.00_pl00 is identical to release c08.00, so pass it off as the latter...
100  if( nPatchLevel == 0 )
101  lgReleaseTag = true;
102  }
103 
104  string pps = ( isdigit(svn_revision[0]) ) ? "r" : "";
105 
106  if( lgReleaseTag )
107  // this expects a branch name like "c08.01"
108  strcpy( chVersion, Branch.substr(1,5).c_str() );
109  else if( lgPatchTag )
110  // this expects a branch name like "c08.01_pl02"
111  sprintf( chVersion, "%s (patch level %d)", Branch.substr(1,5).c_str(), nPatchLevel );
112  else if( nBetaVer > 0 )
113  // this expects a branch name like "c08.00_rc1"
114  sprintf( chVersion, "%s beta %ld (prerelease)", Branch.substr(1,5).c_str(), nBetaVer );
115  else if( lgReleaseBranch )
116  // this expects a branch name like "c08_branch"
117  sprintf( chVersion, "(%s, %s%s, prerelease)", Branch.c_str(), pps.c_str(), svn_revision );
118  else
119  // the branch name can be anything except "c??_branch"
120  sprintf( chVersion, "(%s, %s%s, experimental)", Branch.c_str(), pps.c_str(), svn_revision );
121  }
122  else
123  {
124  // create a default version string in case HeadURL was not expanded
125 
126  /* is this a release branch? */
127  lgReleaseBranch = true;
128  /* is this a release version? */
129  lgRelease = true;
130 
131  /* is this a beta version? 0 for no
132  * if this is non-zero then lgRelease above should be false */
133  nBetaVer = 0;
134 
135  if( lgRelease )
136  {
137  if( CLD_PATCH > 0 )
138  sprintf( chVersion, "%2.2i.%2.2i (patch level %d)",
140  else
141  sprintf( chVersion, "%2.2i.%2.2i", CLD_MAJOR, CLD_MINOR );
142  }
143  else if( nBetaVer > 0 )
144  {
145  sprintf( chVersion, "%2.2i.%2.2i beta %ld (prerelease)",
147  }
148  else
149  {
150  sprintf( chVersion, "%2.2i.%2.2i.%2.2i", YEAR%100, MONTH+1, DAY );
151  }
152  }
153 
154  sprintf( chDate, "%2.2i%3.3s%2.2i", YEAR%100, chMonth[MONTH], DAY );
155 
156  char mode[8];
157  if( sizeof(int) == 4 && sizeof(long) == 4 && sizeof(long*) == 4 )
158  strncpy( mode, "ILP32", sizeof(mode) );
159  else if( sizeof(int) == 4 && sizeof(long) == 4 && sizeof(long*) == 8 )
160  strncpy( mode, "IL32P64", sizeof(mode) );
161  else if( sizeof(int) == 4 && sizeof(long) == 8 && sizeof(long*) == 8 )
162  strncpy( mode, "I32LP64", sizeof(mode) );
163  else if( sizeof(int) == 8 && sizeof(long) == 8 && sizeof(long*) == 8 )
164  strncpy( mode, "ILP64", sizeof(mode) );
165  else
166  strncpy( mode, "UNKN", sizeof(mode) );
167 
168  bool flag[2];
169  flag[0] = ( cpu.i().min_float()/2.f > 0.f );
170  flag[1] = ( cpu.i().min_double()/2. > 0. );
171 
172  /* now generate info on how we were compiled, including compiler version */
173  sprintf( chInfo,
174  "Cloudy compiled on %s in OS %s using the %s %i compiler. Mode %s, "
175  "denormalized float: %c double: %c.",
176  __DATE__, __OS, __COMP, __COMP_VER, mode, TorF(flag[0]), TorF(flag[1]) );
177 }
bool lgRelease
Definition: version.h:28
t_cpu_i & i()
Definition: cpu.h:419
static const int CLD_PATCH
Definition: version.cpp:11
char TorF(bool l)
Definition: cddefines.h:749
char chVersion[INPUT_LINE_LENGTH]
Definition: version.h:19
FILE * ioQQQ
Definition: cddefines.cpp:7
double min_double() const
Definition: cpu.h:358
#define MONTH
Definition: date.h:14
static const int CLD_MINOR
Definition: version.cpp:10
char chDate[INPUT_LINE_LENGTH]
Definition: version.h:16
static const char * cUrl
Definition: version.cpp:19
long int nBetaVer
Definition: version.h:22
#define __COMP
Definition: cpu.h:565
#define DAY
Definition: date.h:16
static const int CLD_MAJOR
Definition: version.cpp:9
sys_float min_float() const
Definition: cpu.h:357
t_version()
Definition: version.cpp:21
#define YEAR
Definition: date.h:12
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1121
#define __COMP_VER
Definition: cpu.h:566
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
Definition: service.cpp:106
bool lgReleaseBranch
Definition: version.h:25
char chInfo[INPUT_LINE_LENGTH]
Definition: version.h:32
#define __OS
Definition: cpu.h:641
static t_cpu cpu
Definition: cpu.h:427
static const char * svn_revision
Definition: version.cpp:16