|         |      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 "TzCompiler.h" | 
|         |     20 #include "TzDocument.h" | 
|         |     21 #include "TzHelpers.h" | 
|         |     22 #include "TzScanner.h" | 
|         |     23 #include <iostream> | 
|         |     24 #include <io.h> | 
|         |     25 #include <direct.h> | 
|         |     26 #include <algorithm> | 
|         |     27  | 
|         |     28 using namespace std; | 
|         |     29  | 
|         |     30 //============================================================================ | 
|         |     31 // CTzCompiler::CTZCompiler | 
|         |     32 //============================================================================ | 
|         |     33 CTzCompiler::CTzCompiler(CTZDocument& aTzDocument) | 
|         |     34 :	iTzDocument(aTzDocument) | 
|         |     35 	{ | 
|         |     36 	} | 
|         |     37  | 
|         |     38 //============================================================================ | 
|         |     39 // CTzCompiler::Compile | 
|         |     40 // Directs the compilation process through the document | 
|         |     41 //============================================================================ | 
|         |     42 void CTzCompiler::CompileL() | 
|         |     43 	{ | 
|         |     44 	string outputString; | 
|         |     45 	//Use all files in the data directory | 
|         |     46 	 | 
|         |     47 	int numFiles = 0;		//Number of files scanned | 
|         |     48 	int scanSuccess = 0;	//Succesful scans | 
|         |     49  | 
|         |     50 	struct _finddata_t file; | 
|         |     51 	long fileHandle; | 
|         |     52 	string fileName; | 
|         |     53 	//Find all files in directory | 
|         |     54 	string inputFilePath = TzGlobals::iInputFilePath + "\\*"; | 
|         |     55 	fileHandle = _findfirst(inputFilePath.c_str(),&file); | 
|         |     56 	std::vector<std::string>::iterator iter; | 
|         |     57 	while (_findnext(fileHandle,&file) == 0) | 
|         |     58 		{ | 
|         |     59 		numFiles++; | 
|         |     60 		fileName.erase(); | 
|         |     61 		fileName  = file.name; | 
|         |     62 		if (!(strcmp(file.name, ".") == 0 ||  strcmp(file.name, "..") == 0)) | 
|         |     63 			{ | 
|         |     64 			TzGlobals::iAvailableFiles.push_back(file.name); | 
|         |     65  | 
|         |     66 			//Check that we don't want to exclude this file | 
|         |     67 			iter = find(TzGlobals::iExcludedFiles.begin(),TzGlobals::iExcludedFiles.end(),file.name); | 
|         |     68 			 | 
|         |     69 			if (iter != TzGlobals::iExcludedFiles.end()) | 
|         |     70 				{ | 
|         |     71 				//Don't process this file | 
|         |     72 				cout << "Ignoring " << file.name << endl; | 
|         |     73 				} | 
|         |     74 			else | 
|         |     75 				{ | 
|         |     76 				outputString.erase(); | 
|         |     77 				outputString = "Scanning "; | 
|         |     78 				outputString.append(file.name); | 
|         |     79 				CTzCpHelpers::PrintStep(outputString); | 
|         |     80 					 | 
|         |     81 				string tmpString = TzGlobals::iInputFilePath; | 
|         |     82 				tmpString.append(file.name); | 
|         |     83 				int result = iTzDocument.Scan(tmpString.c_str()); | 
|         |     84 				if (result == TzGlobals::ETzNone) | 
|         |     85 					{ | 
|         |     86 					scanSuccess++; | 
|         |     87 					} | 
|         |     88  | 
|         |     89 				CTzCpHelpers::PrintStepResult(result); | 
|         |     90 				} | 
|         |     91 			} | 
|         |     92  | 
|         |     93 		} | 
|         |     94  | 
|         |     95 	//Check at least one file was scanned.  If not we have a fatal error | 
|         |     96 	if (scanSuccess < 1) | 
|         |     97 		{ | 
|         |     98 		throw TzGlobals::ETzAbortNoInputFiles; | 
|         |     99 		} | 
|         |    100  | 
|         |    101 	if (iTzDocument.iErrors.size() > 0) | 
|         |    102 		{ | 
|         |    103 		cerr << "Scan failed" << endl; | 
|         |    104 		for (int x = 0; x < iTzDocument.iErrors.size();++x) | 
|         |    105 			{ | 
|         |    106 			cerr << iTzDocument.iErrors[x] << endl; | 
|         |    107 			} | 
|         |    108 		throw TzGlobals::ETzAbortScannerSyntaxError; | 
|         |    109 		} | 
|         |    110 	 | 
|         |    111 	//Assemble the parsed data into Symbian native database entities | 
|         |    112 	iTzDocument.AssembleL(); | 
|         |    113     CTzCpHelpers::PrintStepResult(TzGlobals::ETzNone); | 
|         |    114 	//Link the assembled objects  | 
|         |    115 	iTzDocument.Link(); | 
|         |    116 	CTzCpHelpers::PrintStepResult(TzGlobals::ETzNone); | 
|         |    117 	//Assign each zone a unique id | 
|         |    118 	iTzDocument.AssignZoneIds(); | 
|         |    119 	//Remove unwanted entities from the database | 
|         |    120 	iTzDocument.Exclude(); | 
|         |    121 	//Persist the database model to a binary Symbian file for inclusion in ROM | 
|         |    122 	iTzDocument.ExternaliseL(); | 
|         |    123 	CTzCpHelpers::PrintStepResult(TzGlobals::ETzNone); | 
|         |    124 	//Show warnings for missing zones | 
|         |    125 	iTzDocument.VerifyZoneIds(); | 
|         |    126 	//Move the database file to the required output directory | 
|         |    127 	iTzDocument.CopyDatabaseFileToOutputDirectory(); | 
|         |    128 	 | 
|         |    129 	cout << "Output files are:\t" << TzGlobals::iOutputFilePath.c_str() << endl; | 
|         |    130 	} | 
|         |    131  | 
|         |    132 //============================================================================ | 
|         |    133 // End of file | 
|         |    134 //============================================================================ | 
|         |    135 	 | 
|         |    136 		 |