Author: jani
Date: Tue Mar 12 18:36:43 2013
New Revision: 1455664

URL: http://svn.apache.org/r1455664
Log:
turnaround of total .po handling, tested, prepare for convert 

Modified:
    openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx
    openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx
    openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx
    openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx
    openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx
    openoffice/branches/l10n/main/l10ntools/source/gLang.hxx

Modified: openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx?rev=1455664&r1=1455663&r2=1455664&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gConPoWrap.cxx Tue Mar 12 
18:36:43 2013
@@ -73,7 +73,7 @@ void convert_po::startLook(char *syyText
     return;
 
   // split key into filename and real key
-  i         = msKey.find(":");
+  i = msKey.find("#");
   sFileName = msKey.substr(0, i);
   sNewKey   = msKey.substr(i+1);
 
@@ -160,6 +160,7 @@ void convert_po::handleNL(char *syyText)
 {
   mbExpectId  =
   mbExpectStr = false;
+  ++miLineNo;
 }
 
 
@@ -234,7 +235,7 @@ void convert_po::save(const std::string&
 {
   std::ostream outFile(&outBuffer);
 
-  outFile << std::endl << "#: " << sFileName << ":" << sKey << std::endl;
+  outFile << std::endl << "#: " << sFileName << "#" << sKey << std::endl;
   if (bFuzzy)
     outFile << "#, fuzzy" << std::endl;
   outFile << "msgid  \"" << sENUStext << "\"" << std::endl

Modified: openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx?rev=1455664&r1=1455663&r2=1455664&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gHandler.cxx Tue Mar 12 
18:36:43 2013
@@ -21,6 +21,8 @@
 #include <iostream>
 #include "gLang.hxx"
 #include <cstdlib>
+#include <iostream>
+#include <fstream>
 
 
 
@@ -36,6 +38,8 @@
 
 /**********************   I M P L E M E N T A T I O N   **********************/
 handler::handler()
+                :
+                 mbForceSave(false)
 {
 }
 
@@ -100,13 +104,13 @@ void handler::checkCommandLine(int argc,
           throw std::string("missing argument to ") + argv[argNow-1];
 
         // is it a known parameter
-        if      (sArg == "-d") l10nMem::setShowDebug();  
-        else if (sArg == "-f") eGotArg   = ARG_F;      
-        else if (sArg == "-k") bKid      = true;      
-        else if (sArg == "-o") eGotArg   = ARG_O;      
-        else if (sArg == "-s") eGotArg   = ARG_S;      
-        else if (sArg == "-t") eGotArg   = ARG_T;      
-        else if (sArg == "-v") l10nMem::setShowVerbose();  
+        if      (sArg == "-d") {l10nMem::setShowDebug();               }
+        else if (sArg == "-f") {eGotArg   = ARG_F;                     }
+        else if (sArg == "-k") {bKid      = true;                      }
+        else if (sArg == "-o") {eGotArg   = ARG_O; mbForceSave = true; }      
+        else if (sArg == "-s") {eGotArg   = ARG_S;                     }
+        else if (sArg == "-t") {eGotArg   = ARG_T;                     }
+        else if (sArg == "-v") {l10nMem::setShowVerbose();             }
         else throw std::string("unknown parameter: ") + sArg;
       }
       else
@@ -133,12 +137,12 @@ void handler::checkCommandLine(int argc,
     // check parameters according to function
     if (mvSourceFiles.size())
     {
-      if (meWorkMode == DO_CONVERT || meWorkMode == DO_GENERATE)
-        throw "-f <files> is only valid using \"extract\" and \"merge\"";
+      if (meWorkMode == DO_GENERATE)
+        throw "-f <files> is not valid with \"generate\"";
     }
     else
     {
-      if (meWorkMode == DO_EXTRACT || meWorkMode == DO_MERGE)
+      if (meWorkMode == DO_CONVERT || meWorkMode == DO_EXTRACT || meWorkMode 
== DO_MERGE)
         throw "-f <files> is mandatory";
     }
     if (msTargetDir.size())
@@ -187,6 +191,12 @@ void handler::checkCommandLine(int argc,
   }
 
   // update directories to include final /
+  nLen = msSourceDir.find("/help_");
+  if (nLen != (int)std::string::npos)
+  {
+    msSourceDir.erase(nLen+1);
+    msSourceDir.append("helpcontent2");
+  }
   nLen = msSourceDir.size();
   if (nLen && msSourceDir.at(nLen-1) != '/')
     msSourceDir.append("/");
@@ -211,6 +221,10 @@ void handler::checkCommandLine(int argc,
   }
   while (next != (int)std::string::npos);
 
+  // check if source files list needs to be coverted
+  if (mvSourceFiles[0] == "USEFILE:")
+    readFileWithSources();
+
   // tell system
   l10nMem::showVerbose("gLang starting to " + sWorkText + " from module " + 
msModuleName);
 }
@@ -264,7 +278,7 @@ void handler::runExtractMerge(bool bMerg
   }
 
   // and generate language file
-  mcMemory.save(msPoOutDir, bKid, (msPoDir != msPoOutDir));
+  mcMemory.save(msPoOutDir, bKid, mbForceSave);
 }
 
 
@@ -293,7 +307,7 @@ void handler::runConvert()
   }
 
   // and generate language file
-  mcMemory.save(msPoOutDir, false, (msPoDir != msPoOutDir));
+  mcMemory.save(msPoOutDir, false, mbForceSave);
 }
 
 
@@ -363,7 +377,7 @@ void handler::showManual()
     "    The result is stored in <target dir>/<files>\n"
     "\n"
     "  genLang convert <module> <po dir> <languages> [-v] [-d]\\\n"
-    "          [-o <po outdir>] -s <source dir>\n"
+    "          [-o <po outdir>] -s <source dir> -f <files>\n"
     "    reads sdf generated .po <files> from\n"
     "    <source dir>/*lang/<module>.po\n"
     "    and merges with\n"
@@ -400,6 +414,9 @@ void handler::showManual()
     "  -f <files>\n"
     "     list of files containing messages to be extracted\n"
     "     \"convert\" expect sdf generated po files, to be converted\n"
+    "     instead of passing a list of files, it is possible to pass\n"
+    "     a file contains the list, by using:\n"
+    "     -f USEFILE: <filename>\n"
     "  -k\n"
     "     generate kid id (hex) for all messages in the source code,\n"
     "     solely for QA\n"
@@ -448,3 +465,32 @@ void handler::loadL10MEM()
     convert_gen(mcMemory, sLoad, sMod).execute(false, true);
   }
 }
+
+
+
+/**********************   I M P L E M E N T A T I O N   **********************/
+void handler::readFileWithSources()
+{
+  std::ifstream fInput;
+  char          buf[256];
+
+
+  if (mvSourceFiles.size() < 2)
+    throw l10nMem::showError("missing file with sources (-f USEFILE: 
<filename>)");
+
+  fInput.open (mvSourceFiles[1].c_str(), std::ifstream::in);
+  if (!fInput.is_open())
+    throw l10nMem::showError("Cannot open file with sources (-f), trying to 
open" + mvSourceFiles[1]);
+
+  mvSourceFiles.clear();
+
+  while (fInput.good())
+  {
+    fInput.getline(buf, sizeof(buf));
+    if (!buf[0])
+      continue;
+    mvSourceFiles.push_back(buf);
+  }
+
+  fInput.close();
+}
\ No newline at end of file

Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx?rev=1455664&r1=1455663&r2=1455664&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.cxx Tue Mar 12 
18:36:43 2013
@@ -19,7 +19,7 @@
  * 
  *************************************************************/
 #include "gL10nMem.hxx"
-#include <algorithm>
+//#include <algorithm>
 #include <iostream>
 #include <fstream>
 #include <sstream>
@@ -91,8 +91,6 @@ void l10nMem::setLanguage(const std::str
      { l10nMem_impl::mcImpl->mcDb.setLanguage(sL, bC, bK); }
 void l10nMem::loadEntryKey(int iL, const std::string& sS, const std::string& 
sK, const std::string& sO, const std::string& sT, bool               bI)
      { l10nMem_impl::mcImpl->loadEntryKey(iL, sS, sK, sO, sT, bI); }
-bool l10nMem::checkKey(const std::string& sKey, const std::string& sText)
-     { return l10nMem_impl::mcImpl->mcDb.locateKey(0, sKey, sText, false); }
 void l10nMem::setSourceKey(int iL, const std::string& sF, const std::string& 
sK, const std::string& sT)
      { l10nMem_impl::mcImpl->setSourceKey(iL, sF, sK, sT); }
 void l10nMem::save(const std::string& sT, bool bK, bool bF)
@@ -188,15 +186,14 @@ void l10nMem_impl::setSourceKey(int     
                                 const std::string& sText)
 {
   // if key exist update state
-  if (mcDb.findFileName(sSourceFile, mcDb.miCurENUSinx+1, true) &&
-      mcDb.locateKey(iLineNo, sKey, sText, false))
+  if (mcDb.locateKey(iLineNo, sSourceFile, sKey, sText, false))
   {
     mcDb.mcENUSlist[mcDb.miCurENUSinx].meState = l10nMem::ENTRY_NORMAL;
   }
   else
   {
     // add key, if changed text this is wrong but handled in reorganize
-    mcDb.addKey(iLineNo, sKey, sText, l10nMem::ENTRY_ADDED);
+    mcDb.addKey(iLineNo, sSourceFile, sKey, sText, l10nMem::ENTRY_ADDED);
   }
 }
 
@@ -308,11 +305,16 @@ bool l10nMem_impl::needWrite(const std::
     if (cur.meState == l10nMem::ENTRY_ADDED)
       ++iCntAdded;
     if (cur.meState == l10nMem::ENTRY_CHANGED)
+    {
       ++iCntChanged;
+      if (mcDb.mbConvertMode)
+        cur.meState = l10nMem::ENTRY_NORMAL;
+    }
     if (cur.meState == l10nMem::ENTRY_DELETED)
       ++iCntDeleted;
   }
-  iCntDeleted -= iCntChanged;
+  if (!mcDb.mbConvertMode)
+    iCntDeleted -= iCntChanged;
   if (!iCntAdded && !iCntChanged && !iCntDeleted)
   {
     std::cout << "genLang: No changes in " <<   sFileName;
@@ -340,12 +342,55 @@ void l10nMem_impl::convEntryKey(int     
                                const std::string& sText,
                                bool               bIsFuzzy)
 {
-  std::string x;
-  iLineNo     = iLineNo;
-  x           = sSourceFile;
-  x           = sKey;
-  x           = sOrgText;
-  x           = sText;
-  bIsFuzzy    = bIsFuzzy;
-  //JIX (convLangKey)
+  int         i, iSize;
+  std::string sNewKey = sKey;
+
+
+  // adjust miCurFileInx as needed
+  // same filename as last ?
+  if (sSourceFile != mcDb.mcFileList[mcDb.miCurFileInx].msPureName)
+  {
+    iSize = mcDb.mcFileList.size();
+
+    // match filename
+    for (i = 1; i < iSize && sSourceFile != mcDb.mcFileList[i].msPureName; 
++i) ;
+    if (i == iSize)
+    {
+      showError("filename(" + sSourceFile + ") not found!", iLineNo);
+      return;
+    }
+    mcDb.miCurFileInx = i;
+  }
+
+  // Calculate possible entries
+  l10nMem_file_entry& curF = mcDb.mcFileList[mcDb.miCurFileInx];
+  i     = curF.miStart;
+  iSize = curF.miEnd;
+
+  // Loop through possible en_US entries
+  for (; i <= iSize; ++i)
+  {
+    l10nMem_enus_entry& curE = mcDb.mcENUSlist[i];
+
+    // The entry cannot be converted twice
+    if (curE.meState != l10nMem::ENTRY_NORMAL)
+      continue;
+
+    // The text must match
+    if (sOrgText != curE.msText)
+      continue;
+
+    // The keys must match
+    if (sNewKey != curE.msKey)
+      continue;
+
+    // update language text
+    l10nMem_lang_entry& curL = curE.mcLangList[mcDb.miCurLangInx];
+    curL.msText  = sText;
+    curL.mbFuzzy = bIsFuzzy;
+    curE.meState = l10nMem::ENTRY_CHANGED;
+    return;
+  }
+
+  showError("key(" + sKey + ") with msgId(" + sOrgText + ") cannot be 
matched", iLineNo);
 }

Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx?rev=1455664&r1=1455663&r2=1455664&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMem.hxx Tue Mar 12 
18:36:43 2013
@@ -75,7 +75,8 @@ class l10nMem_file_entry
     l10nMem_file_entry(const std::string& sFileName, int iStart);
     ~l10nMem_file_entry();
 
-    std::string msFileName;  // file Name
+    std::string msFileName;  // file Name with relative path
+    std::string msPureName;  // just filename
     int         miStart;     // start index of entries in mcMasterEntries 
(l10Mem_db::mcENUS)
     int         miEnd;       // last index of entries in mcMasterEntries 
(l10Mem_db::mcENUS)
 };
@@ -92,7 +93,6 @@ class l10nMem_db
     int                             miCurFileInx;
     int                             miCurLangInx;
     int                             miCurENUSinx;
-    int                             miCurLastENUSinx;
     bool                            mbNeedWrite;
     bool                            mbConvertMode;
     std::vector<l10nMem_enus_entry> mcENUSlist;
@@ -107,7 +107,7 @@ class l10nMem_db
     void setLanguage    (const std::string& sLanguage,
                          bool               bCreate,
                         bool                bConvert);
-    bool findFileName   (const std::string& sSourceFile, int iStart, bool 
bCreate);                         
+    bool findFileName   (const std::string& sSourceFile);                      
   
     void loadLangKey    (int                iLineNo,
                          const std::string& sSourceFile,
                          const std::string& sKey,
@@ -117,11 +117,13 @@ class l10nMem_db
 
 
     bool locateKey      (int                iLineNo,
+                         const std::string& sSourceFile,
                          const std::string& sKey,
                          const std::string& sText,
-                         bool               bThrow = true);
+                         bool               bThrow);
     void reorganize     ();
     void addKey         (int                  iLineNo,
+                         const std::string&   sSourceFile,
                          const std::string&   sKey,
                          const std::string&   sText,
                          l10nMem::ENTRY_STATE eStat);

Modified: openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx?rev=1455664&r1=1455663&r2=1455664&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gL10nMemDB.cxx Tue Mar 12 
18:36:43 2013
@@ -19,6 +19,10 @@
  * 
  *************************************************************/
 #include "gL10nMem.hxx"
+#include <iostream>
+#include <fstream>
+#include <sstream>
+
 
 /*****************************************************************************
  **********************   G L 1 0 N M E M D B . C X X   **********************
@@ -64,7 +68,9 @@ l10nMem_enus_entry::l10nMem_enus_entry(c
                                        miFileInx(iFileInx),
                                        miLineNo(iLineNo)
 {
-  for (int i = 0; i < iLangSize; ++i)
+  int i;
+
+  for (i = 0; i < iLangSize; ++i)
     mcLangList.push_back(l10nMem_lang_entry("", false));
 }
 
@@ -84,6 +90,12 @@ l10nMem_file_entry::l10nMem_file_entry(c
                                        miStart(iStart),
                                        miEnd(iStart)
 {
+  // Store fileName without relative path
+  int i = msFileName.rfind("/");
+  if (i == (int)std::string::npos)
+    msPureName = msFileName;
+  else
+    msPureName = msFileName.substr(i+1);
 }
 
 
@@ -101,7 +113,6 @@ l10nMem_db::l10nMem_db()
                        miCurFileInx(0),
                        miCurLangInx(0),
                        miCurENUSinx(0),
-                       miCurLastENUSinx(0),
                        mbNeedWrite(false),
                        mbConvertMode(false)
 {
@@ -125,15 +136,8 @@ void l10nMem_db::loadENUSkey(int        
                              const std::string& sKey,
                              const std::string& sText)
 {
-  // create file name if needed
-  if (mcFileList[miCurFileInx].msFileName != sSourceFile)
-  {
-    miCurFileInx = mcFileList.size();
-    mcFileList.push_back(l10nMem_file_entry(sSourceFile, miCurENUSinx+1));
-  }
-
   // add it to vector and update file pointer
-  addKey(iLineNo, sKey, sText, l10nMem::ENTRY_DELETED);
+  addKey(iLineNo, sSourceFile, sKey, sText, l10nMem::ENTRY_DELETED);
 }
 
 
@@ -143,9 +147,15 @@ void l10nMem_db::setLanguage(const std::
                              bool               bCreate,
                              bool               bConvert)
 {
-  int iSize = mcLangList.size();
+  int i, iSize;
 
   // regular load or convert of old po files
+  if (bConvert)
+  {
+    iSize = mcENUSlist.size();
+    for (i = 0; i < iSize; ++i)
+      mcENUSlist[i].meState = l10nMem::ENTRY_NORMAL;
+  }
   mbConvertMode = bConvert;
   miCurFileInx  = 0;
 
@@ -161,6 +171,7 @@ void l10nMem_db::setLanguage(const std::
     throw l10nMem::showError("en_US is loaded automatically");
 
   // check if language is already loaded
+  iSize = mcLangList.size();
   for (miCurLangInx = 0; miCurLangInx < iSize && mcLangList[miCurLangInx] != 
sLanguage; ++miCurLangInx) ;
   if (miCurLangInx < iSize)
   {    
@@ -178,14 +189,14 @@ void l10nMem_db::setLanguage(const std::
 
   // add language to all ENUS entries
   iSize = mcENUSlist.size();
-  for (int i = 0; i < iSize; ++i)
+  for (i = 0; i < iSize; ++i)
     mcENUSlist[i].mcLangList.push_back(l10nMem_lang_entry("", false));
 }
 
 
 
 /**********************   I M P L E M E N T A T I O N   **********************/
-bool l10nMem_db::findFileName(const std::string& sSourceFile, int iStart, bool 
bCreate)
+bool l10nMem_db::findFileName(const std::string& sSourceFile)
 {
   int iSize = mcFileList.size();
 
@@ -195,16 +206,16 @@ bool l10nMem_db::findFileName(const std:
   if (++miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == 
sSourceFile)
     return true;
 
-  for (miCurFileInx = 0;
-       miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName == 
sSourceFile;
+  for (miCurFileInx = 1;
+       miCurFileInx < iSize && mcFileList[miCurFileInx].msFileName != 
sSourceFile;
        ++miCurFileInx) ;
-
-  if (bCreate && miCurFileInx < iSize)
+  if (miCurFileInx == iSize)
   {
-    mcFileList.push_back(l10nMem_file_entry(sSourceFile, iStart));
-    miCurFileInx = iSize;
+    miCurFileInx = 0;
+    return false;
   }
-  return (miCurFileInx < iSize);
+  else
+    return true;
 }
 
 
@@ -217,10 +228,8 @@ void l10nMem_db::loadLangKey(int        
                              const std::string& sText,
                              bool               bFuzzy)
 {
-  if (!findFileName(sSourceFile, false, 0))
-    throw l10nMem::showError(".po file contains unknown filename: " + 
sSourceFile);
-
-  locateKey(iLineNo, sKey, sOrgText);
+  if (!locateKey(iLineNo, sSourceFile, sKey, sOrgText, true))
+    throw l10nMem::showError(".po file contains unknown filename: " + 
sSourceFile + " or key: " + sKey);
 
   l10nMem_lang_entry& xCur = mcENUSlist[miCurENUSinx].mcLangList[miCurLangInx];
   xCur.msText  = sText;
@@ -246,6 +255,7 @@ void l10nMem_db::reorganize()
     if (cur.meState == l10nMem::ENTRY_DELETED)
       listDel.push_back(iE);
   }
+
   if (!listDel.size() || !listAdd.size())
     return;
 
@@ -255,43 +265,57 @@ void l10nMem_db::reorganize()
   for (iE = 0; iE < iEsize; ++iE)
   {
     l10nMem_enus_entry& curAdd = mcENUSlist[listAdd[iE]];
-    for (iD = 0; iD < iDsize && mcENUSlist[listDel[iD]].msKey != curAdd.msKey; 
++iD) ;
+    for (iD = 0; iD < iDsize; ++iD)
+    {
+      l10nMem_enus_entry& curE = mcENUSlist[listDel[iD]];
+
+      if (curE.miFileInx != curAdd.miFileInx)
+        continue;
+      if (curE.msKey == curAdd.msKey)
+        break;
+      if (curE.msText == curAdd.msText)
+        break;
+    }
     if (iD == iDsize)
       continue;
 
     // Update deleted entry (original), because lang is connected here
     l10nMem_enus_entry& curDel = mcENUSlist[listDel[iD]];
-    curDel.msText  = curAdd.msText;
-    curDel.meState = l10nMem::ENTRY_CHANGED;
-    curAdd.meState = l10nMem::ENTRY_DELETED;
+    curDel.msText    = curAdd.msText;
+    curDel.msKey     = curAdd.msKey;
+    curDel.meState   = l10nMem::ENTRY_CHANGED;
+    curAdd.meState   = l10nMem::ENTRY_DELETED;
   }
-  // JIX (reorganize)
 }
 
 
 
 /**********************   I M P L E M E N T A T I O N   **********************/
 bool l10nMem_db::locateKey(int                iLineNo,
+                           const std::string& sSourceFile,
                            const std::string& sKey,
                            const std::string& sText,
                            bool               bThrow)
 {
-  // Start from beginning of file and to end
-  l10nMem_file_entry& cCur  = mcFileList[miCurFileInx];
+  // Position file pointer
+  if (!findFileName(sSourceFile))
+    return false;
 
-  // Fast check first
-  if (miCurENUSinx < (int)mcENUSlist.size() -1)
+  // Fast check, to see if next key is the one (normal with load and source 
without change)
+  if (++miCurENUSinx < (int)mcENUSlist.size())
   {
-    l10nMem_enus_entry& nowEntry = mcENUSlist[++miCurENUSinx];
+    l10nMem_enus_entry& nowEntry = mcENUSlist[miCurENUSinx];
     if (nowEntry.msText == sText && nowEntry.msKey == sKey)
       return true;
   }
 
+  // Start from beginning of file and to end
+  l10nMem_file_entry& cCur  = mcFileList[miCurFileInx];
+
   // Find match with key and text
   for (miCurENUSinx = cCur.miStart; miCurENUSinx <= cCur.miEnd; ++miCurENUSinx)
   {
     l10nMem_enus_entry& cEntry = mcENUSlist[miCurENUSinx];
-
     if (cEntry.msText == sText && cEntry.msKey == sKey)
       return true;
   }
@@ -305,13 +329,44 @@ bool l10nMem_db::locateKey(int          
 
 /**********************   I M P L E M E N T A T I O N   **********************/
 void l10nMem_db::addKey(int                  iLineNo,
+                        const std::string&   sSourceFile,
                         const std::string&   sKey,
                         const std::string&   sText,
                         l10nMem::ENTRY_STATE eStat)
 {
-  // JIX. addKey, handle fuzzy bit in lang (if changed).
-  miCurENUSinx = mcENUSlist.size();
-  mcENUSlist.push_back(l10nMem_enus_entry(sKey, sText, iLineNo, miCurFileInx,
-                                          mcLangList.size(), eStat));
-  miCurLastENUSinx = mcFileList[miCurFileInx].miEnd = miCurENUSinx;
+  // check file
+  if (!findFileName(sSourceFile))
+  {
+    // prepare for new entry
+    miCurENUSinx = mcENUSlist.size();
+    miCurFileInx = mcFileList.size();
+
+    // Create file
+    mcFileList.push_back(l10nMem_file_entry(sSourceFile, miCurENUSinx));
+   
+    // and add entry at the back (no problem since it is a new file)
+    mcENUSlist.push_back(l10nMem_enus_entry(sKey, sText, iLineNo, miCurFileInx,
+                                            mcLangList.size(), eStat));
+    mcFileList[miCurFileInx].miEnd = miCurENUSinx;
+  }
+  else
+  {
+    int iFsize                                   = mcFileList.size();
+    l10nMem_file_entry& curF                     = mcFileList[miCurFileInx];
+    std::vector<l10nMem_enus_entry>::iterator it = mcENUSlist.begin();
+
+    // file is registred, so we need to add the entry at the end of the file 
range
+    curF.miEnd++;
+    mcENUSlist.insert(it + curF.miEnd,
+                      l10nMem_enus_entry(sKey, sText, iLineNo, miCurFileInx,
+                                         mcLangList.size(), eStat));
+    for (int i = miCurFileInx+1; i < iFsize; ++i)
+    {
+      l10nMem_file_entry& curF2 = mcFileList[i];
+      if (curF2.miStart >= curF.miEnd)
+        curF2.miStart++;
+      if (curF2.miEnd >= curF.miEnd)
+        curF2.miEnd++;
+    }
+  }
 }

Modified: openoffice/branches/l10n/main/l10ntools/source/gLang.hxx
URL: 
http://svn.apache.org/viewvc/openoffice/branches/l10n/main/l10ntools/source/gLang.hxx?rev=1455664&r1=1455663&r2=1455664&view=diff
==============================================================================
--- openoffice/branches/l10n/main/l10ntools/source/gLang.hxx (original)
+++ openoffice/branches/l10n/main/l10ntools/source/gLang.hxx Tue Mar 12 
18:36:43 2013
@@ -77,8 +77,6 @@ class l10nMem
                         const std::string& sText,
                         bool               bIsFuzzy);
 
-    bool checkKey     (const std::string& sKey,
-                       const std::string& sText);
     void setSourceKey (int                iLineNo,
                        const std::string& sFilename,
                        const std::string& sKey,
@@ -135,6 +133,7 @@ class handler
     std::string              msPoDir;
     std::string              msSourceDir;
     std::string              msTargetDir;
+    bool                     mbForceSave;
     std::vector<std::string> mvSourceFiles;
     std::vector<std::string> mvLanguages;
 
@@ -145,5 +144,6 @@ class handler
     void showUsage(std::string& sErr);
     void showManual();
     void loadL10MEM();
+    void readFileWithSources();
 };
 #endif


Reply via email to