Kaydet (Commit) ccaeb1c2 authored tarafından Zolnai Tamás's avatar Zolnai Tamás

Localize files of a directory in lexical order

To avoid big diffs, stem from platform dependent order.

Change-Id: I848a14de2c4e7af2f3a2d9a0fdb005c289cfead2
üst 0054b438
...@@ -23,6 +23,8 @@ ...@@ -23,6 +23,8 @@
#include <cstdlib> #include <cstdlib>
#include <iostream> #include <iostream>
#include <string> #include <string>
#include <vector>
#include <algorithm>
#include "osl/file.h" #include "osl/file.h"
#include "osl/file.hxx" #include "osl/file.hxx"
...@@ -252,6 +254,54 @@ bool handleFile( ...@@ -252,6 +254,54 @@ bool handleFile(
return false; return false;
} }
void handleFilesOfDir(
std::vector<OUString>& aFiles, const OString& rProject,
const OString& rProjectRoot, const OString& rPotDir )
{
///Handle files in lexical order
std::sort(aFiles.begin(), aFiles.end());
typedef std::vector<OUString>::const_iterator citer_t;
bool bFirstLocFile = true; ///< First file in directory which needs localization
for( citer_t aIt = aFiles.begin(); aIt != aFiles.end(); ++aIt )
{
if (handleFile( rProject, rProjectRoot, *aIt, rPotDir, bFirstLocFile))
{
bFirstLocFile = false;
}
}
if( !bFirstLocFile )
{
//Delete pot file if it contain only the header
OString sPotFile = rPotDir.concat(".pot");
PoIfstream aPOStream( sPotFile );
PoEntry aPO;
aPOStream.readEntry( aPO );
bool bDel = aPOStream.eof();
aPOStream.close();
if( bDel )
{
system(OString("rm " + sPotFile).getStr());
}
}
//Remove empty pot directories
OUString sPoPath =
OStringToOUString(
rPotDir.copy(0,rPotDir.lastIndexOf('/')), RTL_TEXTENCODING_UTF8);
OUString sPoUrl;
if (osl::FileBase::getFileURLFromSystemPath(sPoPath, sPoUrl)
!= osl::FileBase::E_None)
{
cerr << "Error: Cannot convert pathname to URL in " << __FILE__ << ", in line " << __LINE__ << "\n"
<< OUStringToOString(sPoPath, RTL_TEXTENCODING_UTF8).getStr() << "\n";
throw false; //TODO
}
osl::Directory::remove(sPoUrl);
}
bool includeProject(const OString& rProject) { bool includeProject(const OString& rProject) {
static OString projects[] = { static OString projects[] = {
"accessibility", "accessibility",
...@@ -338,7 +388,7 @@ void handleDirectory( ...@@ -338,7 +388,7 @@ void handleDirectory(
<< "Error: Cannot open directory: " << rUrl << '\n'; << "Error: Cannot open directory: " << rUrl << '\n';
throw false; //TODO throw false; //TODO
} }
bool bFirstLocFile = true; std::vector<OUString> aFileNames;
for (;;) { for (;;) {
osl::DirectoryItem item; osl::DirectoryItem item;
osl::FileBase::RC e = dir.getNextItem(item); osl::FileBase::RC e = dir.getNextItem(item);
...@@ -356,7 +406,7 @@ void handleDirectory( ...@@ -356,7 +406,7 @@ void handleDirectory(
cerr << "Error: Cannot get file status\n"; cerr << "Error: Cannot get file status\n";
throw false; //TODO throw false; //TODO
} }
const OString sFileName = const OString sDirName =
OUStringToOString(stat.getFileName(),RTL_TEXTENCODING_UTF8); OUStringToOString(stat.getFileName(),RTL_TEXTENCODING_UTF8);
switch (nLevel) { switch (nLevel) {
case -1: // the clone or src directory case -1: // the clone or src directory
...@@ -368,12 +418,12 @@ void handleDirectory( ...@@ -368,12 +418,12 @@ void handleDirectory(
break; break;
case 0: // a root directory case 0: // a root directory
if (stat.getFileType() == osl::FileStatus::Directory) { if (stat.getFileType() == osl::FileStatus::Directory) {
if (includeProject(sFileName)) { if (includeProject(sDirName)) {
handleDirectory( handleDirectory(
stat.getFileURL(), 1, sFileName, stat.getFileURL(), 1, sDirName,
OString(), rPotDir.concat("/").concat(sFileName)); OString(), rPotDir.concat("/").concat(sDirName));
} else if ( sFileName == "clone" || } else if ( sDirName == "clone" ||
sFileName == "src" ) sDirName == "src" )
{ {
handleDirectory( handleDirectory(
stat.getFileURL(), -1, OString(), OString(), rPotDir); stat.getFileURL(), -1, OString(), OString(), rPotDir);
...@@ -381,54 +431,33 @@ void handleDirectory( ...@@ -381,54 +431,33 @@ void handleDirectory(
} }
break; break;
default: default:
if (stat.getFileType() == osl::FileStatus::Directory) { if (stat.getFileType() == osl::FileStatus::Directory)
{
OString pr(rProjectRoot); OString pr(rProjectRoot);
if (!pr.isEmpty()) { if (!pr.isEmpty()) {
pr += OString('/'); pr += OString('/');
} }
pr += OString(".."); pr += OString("..");
handleDirectory( handleDirectory(
stat.getFileURL(), 2, rProject, pr, rPotDir.concat("/").concat(sFileName)); stat.getFileURL(), 2, rProject, pr, rPotDir.concat("/").concat(sDirName));
} else { }
if( handleFile( rProject, rProjectRoot, stat.getFileURL(), else
rPotDir, bFirstLocFile) ) {
bFirstLocFile = false; aFileNames.push_back(stat.getFileURL());
} }
break; break;
} }
} }
if (dir.close() != osl::FileBase::E_None) { if( !aFileNames.empty() )
cerr << "Error: Cannot close directory\n";
throw false; //TODO
}
if( bFirstLocFile == false )
{
//Delete pot file if it contain only the header
OString sPotFile = rPotDir.concat(".pot");
PoIfstream aPOStream( sPotFile );
PoEntry aPO;
aPOStream.readEntry( aPO );
bool bDel = aPOStream.eof();
aPOStream.close();
if( bDel )
{ {
system(OString("rm " + sPotFile).getStr()); handleFilesOfDir( aFileNames, rProject, rProjectRoot, rPotDir );
} }
}
//Remove empty pot directories if (dir.close() != osl::FileBase::E_None) {
OUString sPoPath = cerr << "Error: Cannot close directory\n";
OStringToOUString(
rPotDir.copy(0,rPotDir.lastIndexOf('/')), RTL_TEXTENCODING_UTF8);
OUString sPoUrl;
if (osl::FileBase::getFileURLFromSystemPath(sPoPath, sPoUrl)
!= osl::FileBase::E_None)
{
cerr << "Error: Cannot convert pathname to URL in " << __FILE__ << ", in line " << __LINE__ << "\n"
<< OUStringToOString(sPoPath, RTL_TEXTENCODING_UTF8).getStr() << "\n";
throw false; //TODO throw false; //TODO
} }
osl::Directory::remove(sPoUrl);
} }
void handleProjects(char * sSourceRoot, char const * sDestRoot) void handleProjects(char * sSourceRoot, char const * sDestRoot)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment