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-2017 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 = 13;
10 static const int CLD_MINOR = 0;
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 string Url = "$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  Split( Url, "/", Part, SPM_RELAX );
45  if( Part.size() >= 3 )
46  {
47  // the last two parts are "source" and "version.h $", we don't need them...
48  // the one before is the relevant identifier (e.g. "trunk", "newmole", "c08.01")
49  // for conciseness we will refer to it below as the "branch"
50  string Branch = Part[Part.size()-3];
51 
52  bool lgReleaseTag = ( Url.find("/tags/release/") != string::npos );
53  bool lgPatchTag = ( Url.find("/tags/patch_versions/") != string::npos );
54  bool lgDevelopTag = ( Url.find("/tags/develop/") != string::npos );
55  // this expects a branch name like "c08_branch"
56  lgReleaseBranch = ( Url.find("/branches/") != string::npos &&
57  Branch.size() == 10 && Branch[0] == 'c' &&
58  Branch.find("_branch") != string::npos );
59 
60  lgRelease = ( lgReleaseTag || lgPatchTag );
61 
62  // determine if this is a beta version
63  string::size_type ptr;
64  if( lgDevelopTag && ( ptr = Branch.find( "_rc" ) ) != string::npos )
65  // this expects a branch name like "c08.00_rc1"
66  sscanf( Branch.substr( ptr+3 ).c_str(), "%ld", &nBetaVer );
67  else
68  nBetaVer = 0;
69 
70  int nMajorLevel=0, nMinorLevel=0, nPatchLevel=0;
71 
72  if( lgReleaseBranch || lgRelease || nBetaVer > 0 )
73  {
74  // this expects a branch name starting with "c08"
75  sscanf( Branch.substr(1,2).c_str(), "%d", &nMajorLevel );
76  if( nMajorLevel != CLD_MAJOR )
77  fprintf( ioQQQ, "PROBLEM - CLD_MAJOR mismatch, please check version.h\n" );
78  }
79 
80  if( lgRelease || nBetaVer > 0 )
81  {
82  // this expects a branch name starting with "c08.01"
83  sscanf( Branch.substr(4,2).c_str(), "%d", &nMinorLevel );
84  if( nMinorLevel != CLD_MINOR )
85  fprintf( ioQQQ, "PROBLEM - CLD_MINOR mismatch, please check version.h\n" );
86  }
87 
88  if( lgPatchTag )
89  {
90  // this expects a branch name like "c08.01_pl02"
91  sscanf( Branch.substr(9,2).c_str(), "%d", &nPatchLevel );
92  if( nPatchLevel != CLD_PATCH )
93  fprintf( ioQQQ, "PROBLEM - CLD_PATCH mismatch, please check version.h\n" );
94  // c08.00_pl00 is identical to release c08.00, so pass it off as the latter...
95  if( nPatchLevel == 0 )
96  lgReleaseTag = true;
97  }
98 
99  string pps = ( isdigit(svn_revision[0]) ) ? "r" : "";
100 
101  if( lgReleaseTag )
102  // this expects a branch name like "c08.01"
103  strncpy( chVersion, Branch.substr(1,5).c_str(), INPUT_LINE_LENGTH );
104  else if( lgPatchTag )
105  // this expects a branch name like "c08.01_pl02"
106  sprintf( chVersion, "%s (patch level %d)", Branch.substr(1,5).c_str(), nPatchLevel );
107  else if( nBetaVer > 0 )
108  // this expects a branch name like "c08.00_rc1"
109  sprintf( chVersion, "%s beta %ld (prerelease)", Branch.substr(1,5).c_str(), nBetaVer );
110  else if( lgReleaseBranch )
111  // this expects a branch name like "c08_branch"
112  sprintf( chVersion, "(%s, %s%s, prerelease)", Branch.c_str(), pps.c_str(), svn_revision );
113  else
114  // the branch name can be anything except "c??_branch"
115  sprintf( chVersion, "(%s, %s%s, experimental)", Branch.c_str(), pps.c_str(), svn_revision );
116  }
117  else
118  {
119  // create a default version string in case HeadURL was not expanded
120 
121  /* is this a release branch? */
122  lgReleaseBranch = false;
123  /* is this a release version? */
124  lgRelease = false;
125 
126  /* is this a beta version? 0 for no
127  * if this is non-zero then lgRelease above should be false */
128  nBetaVer = 0;
129 
130  if( lgRelease )
131  {
132  if( CLD_PATCH > 0 )
133  sprintf( chVersion, "%2.2i.%2.2i (patch level %d)",
135  else
136  sprintf( chVersion, "%2.2i.%2.2i", CLD_MAJOR, CLD_MINOR );
137  }
138  else if( nBetaVer > 0 )
139  {
140  sprintf( chVersion, "%2.2i.%2.2i beta %ld (prerelease)",
142  }
143  else
144  {
145  sprintf( chVersion, "%2.2i.%2.2i.%2.2i", YEAR%100, MONTH+1, DAY );
146  }
147  }
148 
149  sprintf( chDate, "%2.2i%3.3s%2.2i", YEAR%100, chMonth[MONTH], DAY );
150 
151  char mode[8];
152  if( sizeof(int) == 4 && sizeof(long) == 4 && sizeof(long*) == 4 )
153  strncpy( mode, "ILP32", sizeof(mode) );
154  else if( sizeof(int) == 4 && sizeof(long) == 4 && sizeof(long*) == 8 )
155  strncpy( mode, "IL32P64", sizeof(mode) );
156  else if( sizeof(int) == 4 && sizeof(long) == 8 && sizeof(long*) == 8 )
157  strncpy( mode, "I32LP64", sizeof(mode) );
158  else if( sizeof(int) == 8 && sizeof(long) == 8 && sizeof(long*) == 8 )
159  strncpy( mode, "ILP64", sizeof(mode) );
160  else
161  strncpy( mode, "UNKN", sizeof(mode) );
162 
163  bool flag[2];
164  flag[0] = ( cpu.i().min_float()/2.f > 0.f );
165  flag[1] = ( cpu.i().min_double()/2. > 0. );
166 
167  /* now generate info on how we were compiled, including compiler version */
168  sprintf( chInfo,
169  "Cloudy compiled on %s in OS %s using the %s %i compiler. Mode %s, "
170  "denormalized float: %c double: %c.",
171  __DATE__, __OS, __COMP, __COMP_VER, mode, TorF(flag[0]), TorF(flag[1]) );
172 }
bool lgRelease
Definition: version.h:28
t_cpu_i & i()
Definition: cpu.h:415
static const int CLD_PATCH
Definition: version.cpp:11
char TorF(bool l)
Definition: cddefines.h:753
char chVersion[INPUT_LINE_LENGTH]
Definition: version.h:19
FILE * ioQQQ
Definition: cddefines.cpp:7
double min_double() const
Definition: cpu.h:355
#define MONTH
Definition: date.h:16
static const int CLD_MINOR
Definition: version.cpp:10
char chDate[INPUT_LINE_LENGTH]
Definition: version.h:16
long int nBetaVer
Definition: version.h:22
#define __COMP
Definition: cpu.h:553
#define DAY
Definition: date.h:18
const int INPUT_LINE_LENGTH
Definition: cddefines.h:301
static const int CLD_MAJOR
Definition: version.cpp:9
sys_float min_float() const
Definition: cpu.h:354
t_version()
Definition: version.cpp:21
#define YEAR
Definition: date.h:14
int fprintf(const Output &stream, const char *format,...)
Definition: service.cpp:1217
#define __COMP_VER
Definition: cpu.h:554
void Split(const string &str, const string &sep, vector< string > &lst, split_mode mode)
Definition: service.cpp:108
bool lgReleaseBranch
Definition: version.h:25
char chInfo[INPUT_LINE_LENGTH]
Definition: version.h:32
#define __OS
Definition: cpu.h:629
static t_cpu cpu
Definition: cpu.h:423
static const string Url
Definition: version.cpp:19
static const char * svn_revision
Definition: version.cpp:16