|
1 // Copyright (c) 2004-2009 Nokia Corporation and/or its subsidiary(-ies). |
|
2 // All rights reserved. |
|
3 // This component and the accompanying materials are made available |
|
4 // under the terms of "Eclipse Public License v1.0" |
|
5 // which accompanies this distribution, and is available |
|
6 // at the URL "http://www.eclipse.org/legal/epl-v10.html". |
|
7 // |
|
8 // Initial Contributors: |
|
9 // Nokia Corporation - initial contribution. |
|
10 // |
|
11 // Contributors: |
|
12 // |
|
13 // Description: |
|
14 // DST TZ Database Compiler |
|
15 // |
|
16 // |
|
17 |
|
18 #include "TzGlobals.h" |
|
19 #include "TzHelpers.h" |
|
20 #include "TzTables.h" |
|
21 #include <fstream> |
|
22 #include <iostream> |
|
23 #include <algorithm> |
|
24 using namespace std; |
|
25 //============================================================================ |
|
26 // CTzCpHelpers::GetMonth |
|
27 //============================================================================ |
|
28 int CTzCpHelpers::GetMonth(string aMonthString) |
|
29 { |
|
30 int month = -1; |
|
31 if (aMonthString == "Jan") {month = EJan;} |
|
32 else if (aMonthString == "Feb") {month = EFeb;} |
|
33 else if (aMonthString == "Mar") {month = EMar;} |
|
34 else if (aMonthString == "Apr") {month = EApr;} |
|
35 else if (aMonthString == "May") {month = EMay;} |
|
36 else if (aMonthString == "Jun") {month = EJun;} |
|
37 else if (aMonthString == "Jul") {month = EJul;} |
|
38 else if (aMonthString == "Aug") {month = EAug;} |
|
39 else if (aMonthString == "Sep") {month = ESep;} |
|
40 else if (aMonthString == "Oct") {month = EOct;} |
|
41 else if (aMonthString == "Nov") {month = ENov;} |
|
42 else if (aMonthString == "Dec") {month = EDec;} |
|
43 return month; |
|
44 } |
|
45 //============================================================================ |
|
46 // CTzCpHelpers::GetDay |
|
47 //============================================================================ |
|
48 int CTzCpHelpers::GetDay(string aDayString) |
|
49 { |
|
50 // aDayString can come in the form "Sun>=7" or as "7" |
|
51 // Return 0 if no day of week is contained in the string |
|
52 int day = 0; |
|
53 // day could be expressed as "Mon" or as "Monday" |
|
54 if (strstr(aDayString.c_str(),"Mon") != NULL) { day = EMon;} |
|
55 else if (strstr(aDayString.c_str(),"Tue") != NULL) { day = ETue;} |
|
56 else if (strstr(aDayString.c_str(),"Wed") != NULL) { day = EWed;} |
|
57 else if (strstr(aDayString.c_str(),"Thu") != NULL) { day = EThu;} |
|
58 else if (strstr(aDayString.c_str(),"Fri") != NULL) { day = EFri;} |
|
59 else if (strstr(aDayString.c_str(),"Sat") != NULL) { day = ESat;} |
|
60 else if (strstr(aDayString.c_str(),"Sun") != NULL) { day = ESun;} |
|
61 return day; |
|
62 } |
|
63 //============================================================================ |
|
64 // CTzHelpers::GetTimeOfDayInMinutes |
|
65 // Expects a string containing a time in the format 'HH:MM' or just the number |
|
66 // of hours (eg- 'H') and returns the time in minutes. The ':' may not be |
|
67 // specified in some rule files if there are no minutes. |
|
68 //============================================================================ |
|
69 TInt16 CTzCpHelpers::GetTimeOfDayInMinutes(std::string aTimeString) |
|
70 { |
|
71 bool negativeTime = false; |
|
72 string tmpString; |
|
73 //Check for negative number |
|
74 if (aTimeString[0] == '-') |
|
75 { |
|
76 negativeTime = true; |
|
77 tmpString = (aTimeString.substr(1)); |
|
78 } |
|
79 else |
|
80 { |
|
81 tmpString = aTimeString; |
|
82 } |
|
83 |
|
84 int hours = atoi(tmpString.c_str()); |
|
85 |
|
86 // Get the number of minutes. If the colon isn't specified then there are |
|
87 // 0 minutes. |
|
88 int minutes =0; |
|
89 int breakAt = tmpString.find_first_of(':'); |
|
90 if (breakAt != string::npos) |
|
91 { |
|
92 minutes = atoi(tmpString.substr(breakAt+1).c_str()); |
|
93 } |
|
94 |
|
95 int timeInMinutes = (hours*60) + minutes; |
|
96 if (negativeTime) |
|
97 { |
|
98 timeInMinutes *= -1; |
|
99 } |
|
100 return timeInMinutes; |
|
101 } |
|
102 //============================================================================ |
|
103 // CTzCpHelpers::GetTimeReference |
|
104 //============================================================================ |
|
105 int CTzCpHelpers::GetTimeReference(std::string aTimeString) |
|
106 { |
|
107 int timeRefValue = ETzWallTimeReference; |
|
108 char timeRef = aTimeString.c_str()[aTimeString.length()-1]; |
|
109 switch (timeRef) |
|
110 { |
|
111 case 'u': |
|
112 timeRefValue = ETzUtcTimeReference; |
|
113 break; |
|
114 case 's': |
|
115 timeRefValue = ETzStdTimeReference; |
|
116 break; |
|
117 default: |
|
118 timeRefValue = ETzWallTimeReference; |
|
119 break; |
|
120 } |
|
121 return timeRefValue; |
|
122 } |
|
123 //============================================================================ |
|
124 // CTzCpHelpers::GetFileSizeInBytes |
|
125 //============================================================================ |
|
126 int CTzCpHelpers::GetFileSizeInBytes(std::string aFileName) |
|
127 { |
|
128 ifstream aFile; |
|
129 aFile.open(aFileName.c_str()); |
|
130 aFile.seekg(0,ifstream::end); |
|
131 int fileSize = aFile.tellg(); |
|
132 aFile.seekg(0); |
|
133 aFile.close(); |
|
134 return fileSize; |
|
135 } |
|
136 //============================================================================ |
|
137 // CTzCpHelpers::PrintStep |
|
138 //============================================================================ |
|
139 void CTzCpHelpers::PrintStep(std::string aStep) |
|
140 { |
|
141 cout.width(50); |
|
142 cout << aStep; |
|
143 } |
|
144 //============================================================================ |
|
145 // CTzCpHelpers::PrintStepResult |
|
146 //============================================================================ |
|
147 void CTzCpHelpers::PrintStepResult(int aResult) |
|
148 { |
|
149 switch (aResult) |
|
150 { |
|
151 case TzGlobals::ETzNone: |
|
152 cerr << "OK" << endl; |
|
153 break; |
|
154 case TzGlobals::ETzAbortNoInputFiles: |
|
155 cerr << "Error - Input files not found." << endl; |
|
156 break; |
|
157 case TzGlobals::ETzAbortCreateDatabaseFile: |
|
158 cerr << "Error - Could not create database file." << endl; |
|
159 break; |
|
160 case TzGlobals::ETzAbortScannerSyntaxError: |
|
161 cerr << "Error - Syntax errors in source files." << endl; |
|
162 break; |
|
163 case TzGlobals::ETzAbortScannerFileIOError: |
|
164 cerr << "Error - Could not open source file for reading." << endl; |
|
165 break; |
|
166 default: |
|
167 cerr << "Error - Unknown" << endl; |
|
168 break; |
|
169 } |
|
170 } |
|
171 |
|
172 //============================================================================ |
|
173 // End of file |
|
174 //============================================================================ |