OSDN Git Service

Moved all terminal support functions into MUtilities library.
[mutilities/MUtilities.git] / src / Version.cpp
1 ///////////////////////////////////////////////////////////////////////////////
2 // MuldeR's Utilities for Qt
3 // Copyright (C) 2004-2014 LoRd_MuldeR <MuldeR2@GMX.de>
4 //
5 // This library is free software; you can redistribute it and/or
6 // modify it under the terms of the GNU Lesser General Public
7 // License as published by the Free Software Foundation; either
8 // version 2.1 of the License, or (at your option) any later version.
9 //
10 // This library is distributed in the hope that it will be useful,
11 // but WITHOUT ANY WARRANTY; without even the implied warranty of
12 // MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
13 // Lesser General Public License for more details.
14 //
15 // You should have received a copy of the GNU Lesser General Public
16 // License along with this library; if not, write to the Free Software
17 // Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA  02110-1301  USA
18 //
19 // http://www.gnu.org/licenses/lgpl-2.1.txt
20 //////////////////////////////////////////////////////////////////////////////////
21
22 #define MUTILS_INC_CONFIG 1
23
24 #include <MUtils/Version.h>
25
26 //Internal
27 #include <MUtils/Global.h>
28 #include <MUtils/Exception.h>
29 #include "Config.h"
30
31 #ifdef _MSC_VER
32 #define _snscanf(X, Y, Z, ...) _snscanf_s((X), (Y), (Z), __VA_ARGS__)
33 #endif
34
35 ///////////////////////////////////////////////////////////////////////////////
36 // HELPER FUNCTIONS
37 ///////////////////////////////////////////////////////////////////////////////
38
39 static const char *g_months_lut[] = {"Jan", "Feb", "Mar", "Apr", "May", "Jun", "Jul", "Aug", "Sep", "Oct", "Nov", "Dec"};
40
41 static int month2int(const char *str)
42 {
43         int ret = 0;
44
45         for(int j = 0; j < 12; j++)
46         {
47                 if(!_strcmpi(str, g_months_lut[j]))
48                 {
49                         ret = j+1;
50                         break;
51                 }
52         }
53
54         return ret;
55 }
56
57 static const QDate decode_date_str(const char *const date_str)
58 {
59         bool ok = true;
60         int date[3] = {0, 0, 0};
61         char month_s[4];
62
63         ok = ok && (_snscanf(&date_str[0x0], 3, "%s", &month_s) == 1);
64         ok = ok && ((date[1] = month2int(month_s)) > 0);
65         ok = ok && (_snscanf(&date_str[0x4], 2, "%d", &date[2]) == 1);
66         ok = ok && (_snscanf(&date_str[0x7], 4, "%d", &date[0]) == 1);
67
68         if(!ok)
69         {
70                 MUTILS_THROW("Internal error: Date format could not be recognized!");
71         }
72         
73         //qWarning("MUtils::Version::build_date: y=%d, m=%d, d=%d", date[0], date[1], date[2]);
74         return QDate(date[0], date[1], date[2]);
75 }
76
77 static const QTime decode_time_str(const char *const time_str)
78 {
79         bool ok = true;
80         int time[3] = {0, 0, 0};
81
82         ok = ok && (_snscanf(&time_str[0x0], 2, "%d", &time[0]) == 1);
83         ok = ok && (_snscanf(&time_str[0x3], 2, "%d", &time[1]) == 1);
84         ok = ok && (_snscanf(&time_str[0x6], 2, "%d", &time[2]) == 1);
85
86         if(!ok)
87         {
88                 MUTILS_THROW("Internal error: Time format could not be recognized!");
89         }
90
91         //qWarning("MUtils::Version::build_date: h=%d, m=%d, s=%d", time[0], time[1], time[2]);
92         return QTime(time[0], time[1], time[2]);
93 }
94
95 ///////////////////////////////////////////////////////////////////////////////
96 // LIB VERSION
97 ///////////////////////////////////////////////////////////////////////////////
98
99 const QDate MUtils::Version::lib_build_date(void)
100 {
101         static const char *const BUILD_DATE = __DATE__;
102         return decode_date_str(BUILD_DATE);
103 }
104
105 const QTime MUtils::Version::lib_build_time(void)
106 {
107         static const char *const BUILD_TIME = __TIME__;
108         return decode_time_str(BUILD_TIME);
109 }
110
111 const quint32 &MUtils::Version::lib_version_major(void)
112 {
113         static const quint32 VERSION_MAJOR = VER_MUTILS_MAJOR;
114         return VERSION_MAJOR;
115 }
116
117 const quint32 &MUtils::Version::lib_version_minor(void)
118 {
119         static const quint32 VERSION_MINOR = (10 * VER_MUTILS_MINOR_HI) + VER_MUTILS_MINOR_LO;
120         return VERSION_MINOR;
121 }
122
123
124 ///////////////////////////////////////////////////////////////////////////////
125 // APP VERSION
126 ///////////////////////////////////////////////////////////////////////////////
127
128 const QDate MUtils::Version::app_build_date(const char *const date_str)
129 {
130         return decode_date_str(date_str);
131 }
132
133 const QTime MUtils::Version::app_build_time(const char *const time_str)
134 {
135         return decode_time_str(time_str);
136 }
137
138 ///////////////////////////////////////////////////////////////////////////////