[Haiku-commits] r31335 - in haiku/branches/components/gsoc-locale-kit: headers/os/locale headers/private/locale src/add-ons/locale/catalogs src/add-ons/locale/catalogs/plaintext src/add-ons/locale/catalogs/zeta src/bin/locale src/kits/locale
zooey at BerliOS
zooey at mail.berlios.de
Tue Jun 30 17:34:46 CEST 2009
Author: zooey
Date: 2009-06-30 17:34:44 +0200 (Tue, 30 Jun 2009)
New Revision: 31335
ViewCVS: http://svn.berlios.de/viewcvs/haiku?rev=31335&view=rev
Added:
haiku/branches/components/gsoc-locale-kit/headers/private/locale/DefaultCatalog.h
haiku/branches/components/gsoc-locale-kit/headers/private/locale/HashMapCatalog.h
haiku/branches/components/gsoc-locale-kit/headers/private/locale/PlainTextCatalog.h
haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/
haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Catalog.cpp
haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Jamfile
haiku/branches/components/gsoc-locale-kit/src/kits/locale/HashMapCatalog.cpp
Removed:
haiku/branches/components/gsoc-locale-kit/headers/os/locale/DefaultCatalog.h
Modified:
haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/Jamfile
haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/zeta/Catalog.cpp
haiku/branches/components/gsoc-locale-kit/src/bin/locale/Jamfile
haiku/branches/components/gsoc-locale-kit/src/bin/locale/collectcatkeys.cpp
haiku/branches/components/gsoc-locale-kit/src/bin/locale/dumpcatalog.cpp
haiku/branches/components/gsoc-locale-kit/src/bin/locale/linkcatkeys.cpp
haiku/branches/components/gsoc-locale-kit/src/kits/locale/Collator.cpp
haiku/branches/components/gsoc-locale-kit/src/kits/locale/Country.cpp
haiku/branches/components/gsoc-locale-kit/src/kits/locale/DefaultCatalog.cpp
haiku/branches/components/gsoc-locale-kit/src/kits/locale/Jamfile
haiku/branches/components/gsoc-locale-kit/src/kits/locale/LocaleRoster.cpp
Log:
applying patch by Adrien with changes by myself:
* implement a plaintext catalog which will be used as the target of collecting
the strings from a sourcefile - the final (i.e. "linked") catalog will still
be in binary form
* several coding style adjustments (the original locale kit didn't follow
haiku's guidelines precisely)
Deleted: haiku/branches/components/gsoc-locale-kit/headers/os/locale/DefaultCatalog.h
Added: haiku/branches/components/gsoc-locale-kit/headers/private/locale/DefaultCatalog.h
===================================================================
--- haiku/branches/components/gsoc-locale-kit/headers/private/locale/DefaultCatalog.h 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/headers/private/locale/DefaultCatalog.h 2009-06-30 15:34:44 UTC (rev 31335)
@@ -0,0 +1,65 @@
+#ifndef _DEFAULT_CATALOG_H_
+#define _DEFAULT_CATALOG_H_
+
+
+#include <DataIO.h>
+#include <HashMapCatalog.h>
+#include <String.h>
+
+
+class BFile;
+
+namespace BPrivate {
+
+
+/*
+ * The implementation of the Locale Kit's standard catalog-type.
+ * Currently it only maps CatKey to a BString (the translated string),
+ * but the value-type might change to add support for shortcuts and/or
+ * graphical data (button-images and the like).
+ */
+class DefaultCatalog : public BHashMapCatalog {
+ public:
+ DefaultCatalog(const char *signature, const char *language,
+ int32 fingerprint);
+ // constructor for normal use
+ DefaultCatalog(entry_ref *appOrAddOnRef);
+ // constructor for embedded catalog
+ DefaultCatalog(const char *path, const char *signature,
+ const char *language);
+ // constructor for editor-app
+
+ ~DefaultCatalog();
+
+
+ // implementation for editor-interface:
+ status_t ReadFromFile(const char *path = NULL);
+ status_t ReadFromAttribute(entry_ref *appOrAddOnRef);
+ status_t ReadFromResource(entry_ref *appOrAddOnRef);
+ status_t WriteToFile(const char *path = NULL);
+ status_t WriteToAttribute(entry_ref *appOrAddOnRef);
+ status_t WriteToResource(entry_ref *appOrAddOnRef);
+
+ static BCatalogAddOn *Instantiate(const char *signature,
+ const char *language, int32 fingerprint);
+ static BCatalogAddOn *InstantiateEmbedded(entry_ref *appOrAddOnRef);
+ static BCatalogAddOn *Create(const char *signature,
+ const char *language);
+
+ static const uint8 kDefaultCatalogAddOnPriority;
+ static const char *kCatMimeType;
+
+ private:
+ status_t Flatten(BDataIO *dataIO);
+ status_t Unflatten(BDataIO *dataIO);
+ void UpdateAttributes(BFile& catalogFile);
+
+ mutable BString fPath;
+};
+
+
+} // namespace BPrivate
+
+using namespace BPrivate;
+
+#endif /* _DEFAULT_CATALOG_H_ */
Added: haiku/branches/components/gsoc-locale-kit/headers/private/locale/HashMapCatalog.h
===================================================================
--- haiku/branches/components/gsoc-locale-kit/headers/private/locale/HashMapCatalog.h 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/headers/private/locale/HashMapCatalog.h 2009-06-30 15:34:44 UTC (rev 31335)
@@ -0,0 +1,202 @@
+/*
+ * This file declares all the things we need to add to a catalog add-on to be
+ * able to use it in the developper tools (linkcatkeys, dumpcatalog, and the
+ * catalog editor, when we will have one.
+ */
+
+#ifndef _HASH_MAP_CATALOG_H_
+#define _HASH_MAP_CATALOG_H_
+
+
+#if __GNUC__ > 2
+# include <ext/hash_map>
+#else
+# include <hash_map>
+#endif
+
+#include <assert.h>
+
+#include <Catalog.h>
+
+
+namespace BPrivate {
+
+/*
+ * The key-type for the hash_map which maps native strings or IDs to
+ * the corresponding translated string.
+ * The key-type should be efficient to use if it is just created by an ID
+ * but it should also support being created from up to three strings,
+ * which as a whole specify the key to the translated string.
+ */
+struct CatKey {
+ BString fString;
+ // The native string
+ BString fContext;
+ // The context of the string's usage
+ BString fComment;
+ // A comment that can be used to separate strings that
+ // are identical otherwise in the native language, but different in the
+ // translation (useful for the translator)
+ size_t fHashVal;
+ // the hash-value of the key, computed from the three strings
+ uint32 fFlags;
+ // with respect to the catalog-editor, each translation can be
+ // in different states (empty, unchecked, checked, etc.).
+ // This state (and potential other flags) lives in the fFlags member.
+
+ CatKey(const char *str, const char *ctx, const char *cmt);
+ CatKey(uint32 id);
+ CatKey();
+
+ bool operator== (const CatKey& right) const;
+ status_t GetStringParts(BString* str, BString* ctx, BString* cmt) const;
+ static size_t HashFun(const char* s, int startvalue=0);
+ // The hash function is called 3 times, cumulating the 3 strings to calculate the key
+};
+
+} // namespace BPrivate
+
+
+#if __GNUC__ > 2
+namespace __gnu_cxx {
+#endif // __GNUC__ > 2
+
+template<>
+struct hash<BPrivate::CatKey> {
+ size_t operator() (const BPrivate::CatKey &key) const;
+};
+
+#if __GNUC__ > 2
+} // namespace __gnu_cxx
+#endif // __GNUC__ > 2
+
+
+namespace BPrivate {
+
+class BHashMapCatalog: public BCatalogAddOn {
+ protected:
+ int32 ComputeFingerprint() const;
+#if __GNUC__ > 2
+ typedef __gnu_cxx::hash_map<CatKey, BString,
+ __gnu_cxx::hash<CatKey>, std::equal_to<CatKey> > CatMap;
+#else
+ typedef hash_map<CatKey, BString, hash<CatKey>,
+ std::equal_to<CatKey> > CatMap;
+#endif
+ CatMap fCatMap;
+
+ public:
+ BHashMapCatalog(const char* signature, const char* language, int32 fingerprint);
+ // Constructor for normal use
+ //
+ // overrides of BCatalogAddOn:
+ const char *GetString(const char *string, const char *context = NULL,
+ const char *comment = NULL);
+ const char *GetString(uint32 id);
+ const char *GetString(const CatKey& key);
+ //
+ status_t SetString(const char *string, const char *translated,
+ const char *context = NULL, const char *comment = NULL);
+ status_t SetString(int32 id, const char *translated);
+ status_t SetString(const CatKey& key, const char *translated);
+
+ // implementation for editor-interface
+ virtual status_t ReadFromFile(const char *path = NULL) {return B_NOT_SUPPORTED;}
+ virtual status_t ReadFromAttribute(entry_ref *appOrAddOnRef) {return B_NOT_SUPPORTED;}
+ virtual status_t ReadFromResource(entry_ref *appOrAddOnRef) {return B_NOT_SUPPORTED;}
+ virtual status_t WriteToFile(const char *path = NULL) {return B_NOT_SUPPORTED;}
+ virtual status_t WriteToAttribute(entry_ref *appOrAddOnRef) {return B_NOT_SUPPORTED;}
+ virtual status_t WriteToResource(entry_ref *appOrAddOnRef) {return B_NOT_SUPPORTED;}
+
+ void UpdateFingerprint();
+ //
+ void MakeEmpty();
+ int32 CountItems() const;
+
+ /*
+ * CatWalker allows to walk trough all the strings stored in the
+ * catalog. We need that for dumpcatalog, linkcatkeys (to extract the
+ * data from the plaintext catalog) and in the catalog editor (to
+ * display the list of strings in a given catalog).
+ */
+ class CatWalker {
+ public:
+ //CatWalker() {}; // if you use this there is no way to set fPos and fEnd properly..
+ CatWalker(BHashMapCatalog* catalog);
+ bool AtEnd() const;
+ const CatKey& GetKey() const;
+ const char *GetValue() const;
+ void Next();
+ private:
+ CatMap::iterator fPos;
+ CatMap::iterator fEnd;
+ };
+ friend class CatWalker;
+ status_t GetWalker(CatWalker *walker);
+
+
+};
+
+
+inline BHashMapCatalog::BHashMapCatalog(const char* signature,
+ const char* language, int32 fingerprint)
+ :
+ BCatalogAddOn(signature, language, fingerprint)
+{
+}
+
+
+inline
+BHashMapCatalog::CatWalker::CatWalker(BHashMapCatalog* catalog)
+ :
+ fPos(catalog->fCatMap.begin()),
+ fEnd(catalog->fCatMap.end())
+{
+}
+
+
+inline bool
+BHashMapCatalog::CatWalker::AtEnd() const
+{
+ return fPos == fEnd;
+}
+
+
+inline const CatKey &
+BHashMapCatalog::CatWalker::GetKey() const
+{
+ assert(fPos != fEnd);
+ return fPos->first;
+}
+
+
+inline const char *
+BHashMapCatalog::CatWalker::GetValue() const
+{
+ assert(fPos != fEnd);
+ return fPos->second.String();
+}
+
+
+inline void
+BHashMapCatalog::CatWalker::Next()
+{
+ ++fPos;
+}
+
+
+inline status_t
+BHashMapCatalog::GetWalker(CatWalker *walker)
+{
+ if (!walker)
+ return B_BAD_VALUE;
+ *walker = CatWalker(this);
+ return B_OK;
+}
+
+
+} // namespace BPrivate
+
+using namespace BPrivate;
+
+#endif // _HASH_MAP_CATALOG_H_
Added: haiku/branches/components/gsoc-locale-kit/headers/private/locale/PlainTextCatalog.h
===================================================================
--- haiku/branches/components/gsoc-locale-kit/headers/private/locale/PlainTextCatalog.h 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/headers/private/locale/PlainTextCatalog.h 2009-06-30 15:34:44 UTC (rev 31335)
@@ -0,0 +1,49 @@
+#ifndef _PLAINTEXT_CATALOG_H_
+#define _PLAINTEXT_CATALOG_H_
+
+
+#include <HashMapCatalog.h>
+#include <DataIO.h>
+#include <String.h>
+
+
+class BFile;
+
+namespace BPrivate {
+
+class PlainTextCatalog : public BHashMapCatalog {
+ public:
+ PlainTextCatalog(const char *signature, const char *language,
+ int32 fingerprint);
+ // constructor for normal use
+ PlainTextCatalog(entry_ref *appOrAddOnRef);
+ // constructor for embedded catalog
+ PlainTextCatalog(const char *path, const char *signature,
+ const char *language);
+ // constructor for editor-app
+
+ ~PlainTextCatalog();
+
+
+ // implementation for editor-interface:
+ status_t ReadFromFile(const char *path = NULL);
+ status_t WriteToFile(const char *path = NULL);
+
+ static BCatalogAddOn *Instantiate(const char *signature,
+ const char *language, int32 fingerprint);
+
+ static const char *kCatMimeType;
+
+ private:
+ void UpdateAttributes(BFile& catalogFile);
+ void UpdateAttributes(const char* path);
+
+ mutable BString fPath;
+};
+
+} // namespace BPrivate
+
+using BPrivate::PlainTextCatalog;
+
+
+#endif /* _PLAINTEXT_CATALOG_H_ */
Modified: haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/Jamfile
===================================================================
--- haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/Jamfile 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/Jamfile 2009-06-30 15:34:44 UTC (rev 31335)
@@ -4,7 +4,9 @@
NotFile LocaleKitCatalogAddons ;
Depends LocaleKitCatalogAddons
:
+ <catalog-addon>plaintext
<catalog-addon>zeta
;
+SubInclude HAIKU_TOP src add-ons locale catalogs plaintext ;
SubInclude HAIKU_TOP src add-ons locale catalogs zeta ;
Added: haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Catalog.cpp
===================================================================
--- haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Catalog.cpp 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Catalog.cpp 2009-06-30 15:34:44 UTC (rev 31335)
@@ -0,0 +1,422 @@
+/*
+** Copyright 2009 Adrien Destugues, pulkomandy at gmail.com. All rights reserved.
+** Distributed under the terms of the MIT License.
+*/
+
+#include <PlainTextCatalog.h>
+
+#include <assert.h>
+#include <cstdio>
+#include <iostream>
+#include <fstream>
+#include <memory>
+#include <new>
+#include <sstream>
+#include <string>
+
+#include <syslog.h>
+
+#include <Application.h>
+#include <Directory.h>
+#include <File.h>
+#include <FindDirectory.h>
+#include <fs_attr.h>
+#include <Message.h>
+#include <Mime.h>
+#include <Path.h>
+#include <Resources.h>
+#include <Roster.h>
+#include <String.h>
+
+#include <LocaleRoster.h>
+#include <Catalog.h>
+
+
+#if __GNUC__ > 2
+using __gnu_cxx::hash;
+#endif
+
+using std::auto_ptr;
+using std::min;
+using std::max;
+using std::pair;
+
+
+/*
+ * This file implements the plain text catalog-type for the Haiku
+ * locale kit. It is not meant to be used in applications like other add ons,
+ * but only as a way to get an easy to translate file for developers.
+ */
+
+
+extern "C" uint32 adler32(uint32 adler, const uint8 *buf, uint32 len);
+ // definition lives in adler32.c
+
+static const char *kCatFolder = "catalogs";
+static const char *kCatExtension = ".txt";
+
+const char *PlainTextCatalog::kCatMimeType
+ = "locale/x-vnd.Be.locale-catalog.plaintext";
+
+static int16 kCatArchiveVersion = 1;
+ // version of the catalog archive structure, bump this if you change it!
+
+
+/*
+ * constructs a PlainTextCatalog with given signature and language and reads
+ * the catalog from disk.
+ * InitCheck() will be B_OK if catalog could be loaded successfully, it will
+ * give an appropriate error-code otherwise.
+ */
+PlainTextCatalog::PlainTextCatalog(const char *signature, const char *language,
+ int32 fingerprint)
+ :
+ BHashMapCatalog(signature, language, fingerprint)
+{
+ // give highest priority to catalog living in sub-folder of app's folder:
+ app_info appInfo;
+ be_app->GetAppInfo(&appInfo);
+ node_ref nref;
+ nref.device = appInfo.ref.device;
+ nref.node = appInfo.ref.directory;
+ BDirectory appDir(&nref);
+ BString catalogName("locale/");
+ catalogName << kCatFolder
+ << "/" << fSignature
+ << "/" << fLanguageName
+ << kCatExtension;
+ BPath catalogPath(&appDir, catalogName.String());
+ status_t status = ReadFromFile(catalogPath.Path());
+
+ if (status != B_OK) {
+ // look in common-etc folder (/boot/home/config/etc):
+ BPath commonEtcPath;
+ find_directory(B_COMMON_ETC_DIRECTORY, &commonEtcPath);
+ if (commonEtcPath.InitCheck() == B_OK) {
+ catalogName = BString(commonEtcPath.Path())
+ << "/locale/" << kCatFolder
+ << "/" << fSignature
+ << "/" << fLanguageName
+ << kCatExtension;
+ status = ReadFromFile(catalogName.String());
+ }
+ }
+
+ if (status != B_OK) {
+ // look in system-etc folder (/boot/beos/etc):
+ BPath systemEtcPath;
+ find_directory(B_BEOS_ETC_DIRECTORY, &systemEtcPath);
+ if (systemEtcPath.InitCheck() == B_OK) {
+ catalogName = BString(systemEtcPath.Path())
+ << "/locale/" << kCatFolder
+ << "/" << fSignature
+ << "/" << fLanguageName
+ << kCatExtension;
+ status = ReadFromFile(catalogName.String());
+ }
+ }
+
+ fInitCheck = status;
+ log_team(LOG_DEBUG,
+ "trying to load default-catalog(sig=%s, lang=%s) results in %s",
+ signature, language, strerror(fInitCheck));
+}
+
+
+/*
+ * constructs an empty PlainTextCatalog with given sig and language.
+ * This is used for editing/testing purposes.
+ * InitCheck() will always be B_OK.
+ */
+PlainTextCatalog::PlainTextCatalog(const char *path, const char *signature,
+ const char *language)
+ :
+ BHashMapCatalog(signature, language, 0),
+ fPath(path)
+{
+ fInitCheck = B_OK;
+}
+
+
+PlainTextCatalog::~PlainTextCatalog()
+{
+}
+
+
+status_t
+PlainTextCatalog::ReadFromFile(const char *path)
+{
+ std::fstream catalogFile;
+ std::string currentItem;
+
+ if (!path)
+ path = fPath.String();
+
+ catalogFile.open(path, std::fstream::in);
+ if (!catalogFile.is_open()) {
+ log_team(LOG_DEBUG, "couldn't open catalog at %s", path);
+ return B_ENTRY_NOT_FOUND;
+ }
+
+ // Now read all the data from the file
+
+ // The first line holds some info about the catalog :
+ // ArchiveVersion \t LanguageName \t Signature \t FingerPrint
+ if (std::getline(catalogFile, currentItem, '\t').good()) {
+ // Get the archive version
+ int arcver= -1;
+ std::istringstream ss(currentItem);
+ ss >> arcver;
+ if (ss.fail()) {
+ // can't convert to int
+ log_team(LOG_DEBUG,
+ "Unable to extract archive version ( string: %s ) from %s",
+ currentItem.c_str(), path);
+ return B_ERROR;
+ }
+
+ if (arcver != kCatArchiveVersion) {
+ // wrong version
+ log_team(LOG_DEBUG,
+ "Wrong archive version ! Got %d instead of %d from %s", arcver,
+ kCatArchiveVersion, path);
+ return B_ERROR;
+ }
+ } else {
+ log_team(LOG_DEBUG, "Unable to read from catalog %s", path);
+ return B_ERROR;
+ }
+
+ if (std::getline(catalogFile, currentItem, '\t').good()) {
+ // Get the language
+ fLanguageName << currentItem.c_str() ;
+ } else {
+ log_team(LOG_DEBUG, "Unable to get language from %s", path);
+ return B_ERROR;
+ }
+
+ if (std::getline(catalogFile, currentItem, '\t').good()) {
+ // Get the signature
+ fSignature << currentItem.c_str() ;
+ } else {
+ log_team(LOG_DEBUG, "Unable to get signature from %s", path);
+ return B_ERROR;
+ }
+
+ if (std::getline(catalogFile, currentItem).good()) {
+ // Get the fingerprint
+ std::istringstream ss(currentItem);
+ int foundFingerprint;
+ ss >> foundFingerprint;
+ if (ss.fail()) {
+ log_team(LOG_DEBUG, "Unable to get fingerprint (%s) from %s",
+ currentItem.c_str(), path);
+ return B_ERROR;
+ }
+
+ if (fFingerprint!=0 && fFingerprint != foundFingerprint) {
+ return B_MISMATCHED_VALUES;
+ }
+ } else {
+ log_team(LOG_DEBUG, "Unable to get fingerprint from %s", path);
+ return B_ERROR;
+ }
+
+ // We managed to open the file, so we remember it's the one we are using
+ fPath = path;
+ log_team(LOG_DEBUG, "found plaintext catalog at %s", path);
+
+ std::string originalString;
+ std::string context;
+ std::string comment;
+ std::string stringKey;
+ std::string translated;
+
+ uint32 key;
+
+ while (std::getline(catalogFile, originalString,'\t').good()) {
+ // Each line is : "original string \t key \t translated string"
+ // However, the original string is also tab-separated because it
+ // also holds the context and comment
+
+ if (!std::getline(catalogFile,context,'\t').good()) {
+ log_team(LOG_DEBUG, "Unable to get context for string %s from %s",
+ originalString.c_str(), path);
+ return B_ERROR;
+ }
+
+ if (!std::getline(catalogFile,comment,'\t').good()) {
+ log_team(LOG_DEBUG, "Unable to get comment for string %s from %s",
+ originalString.c_str(), path);
+ return B_ERROR;
+ }
+
+ if (!std::getline(catalogFile,stringKey,'\t').good()) {
+ log_team(LOG_DEBUG,
+ "Unable to get key for string %s (%s / %s) from %s",
+ originalString.c_str(), context.c_str(), comment.c_str(), path);
+ return B_ERROR;
+ }
+
+ if (!std::getline(catalogFile,translated).good()) {
+ log_team(LOG_DEBUG,
+ "Unable to get translated text for string %s from %s",
+ originalString.c_str(), path);
+ return B_ERROR;
+ }
+
+ std::istringstream ss( stringKey );
+ ss >> key;
+ if (ss.fail()) {
+ //something happened
+ log_team(LOG_DEBUG,
+ "Unable to convert key %s (%d) for string %s (%s / %s) from %s",
+ stringKey.c_str(), key, originalString.c_str(), context.c_str(),
+ comment.c_str(), path);
+ return B_ERROR;
+ }
+
+ // We could do that :
+ // setstring(originalString, translated, context, comment);
+ // But we already have the key, and we have to make sure it does not
+ // change.
+ SetString(key, translated.c_str());
+ log_team(LOG_DEBUG, "Added string %s (key %d) from file %s",
+ originalString.c_str(), key, path);
+ }
+
+ catalogFile.close();
+
+ // some information living in member variables needs to be copied
+ // to attributes. Although these attributes should have been written
+ // when creating the catalog, we make sure that they exist there:
+ UpdateAttributes(path);
+ return B_OK;
+}
+
+
+status_t
+PlainTextCatalog::WriteToFile(const char *path)
+{
+ BString textContent;
+ BFile catalogFile;
+
+ if (path)
+ fPath = path;
+ status_t res = catalogFile.SetTo(fPath.String(),
+ B_WRITE_ONLY | B_CREATE_FILE | B_ERASE_FILE);
+ if (res != B_OK)
+ return res;
+
+ UpdateFingerprint();
+ // make sure we have the correct fingerprint before we flatten it
+
+
+ textContent << kCatArchiveVersion << "\t" << fLanguageName.String() << "\t"
+ << fSignature.String() << "\t" << fFingerprint << "\n";
+
+ res = catalogFile.Write(textContent.String(),textContent.Length());
+ if(res != textContent.Length())
+ return res;
+
+ CatMap::const_iterator iter;
+ for (iter = fCatMap.begin(); iter!=fCatMap.end(); ++iter) {
+ textContent.Truncate(0);
+ textContent << iter->first.fString.String() << "\t" <<
+ iter->first.fContext.String() << "\t" <<
+ iter->first.fComment.String() << "\t" << iter->first.fHashVal
+ << "\t" << iter->second.String() << "\n";
+ res = catalogFile.Write(textContent.String(),textContent.Length());
+ if(res != textContent.Length())
+ return res;
+ }
+
+ // set mimetype-, language- and signature-attributes:
+ UpdateAttributes(catalogFile);
+ // finally write fingerprint:
+ catalogFile.WriteAttr(BLocaleRoster::kCatFingerprintAttr, B_INT32_TYPE,
+ 0, &fFingerprint, sizeof(int32));
+
+ return B_OK;
+}
+
+
+/*
+ * writes mimetype, language-name and signature of catalog into the
+ * catalog-file.
+ */
+void
+PlainTextCatalog::UpdateAttributes(BFile& catalogFile)
+{
+ static const int bufSize = 256;
+ char buf[bufSize];
+ if (catalogFile.ReadAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0, &buf, bufSize)
+ <= 0
+ || strcmp(kCatMimeType, buf) != 0) {
+ catalogFile.WriteAttr("BEOS:TYPE", B_MIME_STRING_TYPE, 0,
+ kCatMimeType, strlen(kCatMimeType)+1);
+ }
+ if (catalogFile.ReadAttr(BLocaleRoster::kCatLangAttr, B_STRING_TYPE, 0,
+ &buf, bufSize) <= 0
+ || fLanguageName != buf) {
+ catalogFile.WriteAttr(BLocaleRoster::kCatLangAttr, B_STRING_TYPE, 0,
+ fLanguageName.String(), fLanguageName.Length()+1);
+ }
+ if (catalogFile.ReadAttr(BLocaleRoster::kCatSigAttr, B_STRING_TYPE, 0,
+ &buf, bufSize) <= 0
+ || fSignature != buf) {
+ catalogFile.WriteAttr(BLocaleRoster::kCatSigAttr, B_STRING_TYPE, 0,
+ fSignature.String(), fSignature.Length()+1);
+ }
+}
+
+
+void
+PlainTextCatalog::UpdateAttributes(const char* path)
+{
+ BEntry entry(path);
+ BFile node(&entry, B_READ_WRITE);
+ UpdateAttributes(node);
+}
+
+
+BCatalogAddOn *
+PlainTextCatalog::Instantiate(const char *signature, const char *language,
+ int32 fingerprint)
+{
+ PlainTextCatalog *catalog
+ = new(std::nothrow) PlainTextCatalog(signature, language, fingerprint);
+ if (catalog && catalog->InitCheck() != B_OK) {
+ delete catalog;
+ return NULL;
+ }
+ return catalog;
+}
+
+
+extern "C" BCatalogAddOn *
+instantiate_catalog(const char *signature, const char *language,
+ int32 fingerprint)
+{
+ PlainTextCatalog *catalog
+ = new(std::nothrow) PlainTextCatalog(signature, language, fingerprint);
+ if (catalog && catalog->InitCheck() != B_OK) {
+ delete catalog;
+ return NULL;
+ }
+ return catalog;
+}
+
+
+extern "C"
+BCatalogAddOn *create_catalog(const char *signature,
+ const char *language)
+{
+ PlainTextCatalog *catalog =
+ new(std::nothrow) PlainTextCatalog("emptycat", signature, language);
+ return catalog;
+}
+
+
+uint8 gCatalogAddOnPriority = 99;
+ // give low priority to this add on, we don't want it to be actually used
Added: haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Jamfile
===================================================================
--- haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Jamfile 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/plaintext/Jamfile 2009-06-30 15:34:44 UTC (rev 31335)
@@ -0,0 +1,9 @@
+SubDir HAIKU_TOP src add-ons locale catalogs plaintext ;
+
+UsePublicHeaders locale ;
+UsePrivateHeaders locale ;
+
+Addon <catalog-addon>plaintext
+ : Catalog.cpp
+ : be $(TARGET_LIBSTDC++) liblocale.so
+ ;
Modified: haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/zeta/Catalog.cpp
===================================================================
--- haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/zeta/Catalog.cpp 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/src/add-ons/locale/catalogs/zeta/Catalog.cpp 2009-06-30 15:34:44 UTC (rev 31335)
@@ -1,8 +1,10 @@
-/*
+/*
** Copyright 2003, Oliver Tappe, zooey at hirschkaefer.de. All rights reserved.
** Distributed under the terms of the OpenBeOS License.
*/
+#include <new>
+
#include <syslog.h>
#include <Application.h>
@@ -23,7 +25,7 @@
class ZetaCatalog : public BCatalogAddOn {
public:
- ZetaCatalog(const char *signature, const char *language,
+ ZetaCatalog(const char *signature, const char *language,
int32 fingerprint);
~ZetaCatalog();
@@ -35,22 +37,22 @@
};
-ZetaCatalog::ZetaCatalog(const char *signature, const char *language,
+ZetaCatalog::ZetaCatalog(const char *signature, const char *language,
int32 fingerprint)
:
BCatalogAddOn(signature, language, fingerprint)
{
app_info appInfo;
- be_app->GetAppInfo(&appInfo);
+ be_app->GetAppInfo(&appInfo);
node_ref nref;
nref.device = appInfo.ref.device;
nref.node = appInfo.ref.directory;
BDirectory appDir( &nref);
- // ToDo: implement loading of zeta-catalog
+ // ToDo: implement loading of zeta-catalog
fInitCheck = EOPNOTSUPP;
- log_team(LOG_DEBUG,
+ log_team(LOG_DEBUG,
"trying to load zeta-catalog with sig %s for lang %s results in %s",
signature, language, strerror(fInitCheck));
}
@@ -77,7 +79,8 @@
extern "C" BCatalogAddOn *
instantiate_catalog(const char *signature, const char *language, int32 fingerprint)
{
- ZetaCatalog *catalog = new ZetaCatalog(signature, language, fingerprint);
+ ZetaCatalog *catalog
+ = new(std::nothrow) ZetaCatalog(signature, language, fingerprint);
if (catalog && catalog->InitCheck() != B_OK) {
delete catalog;
return NULL;
Modified: haiku/branches/components/gsoc-locale-kit/src/bin/locale/Jamfile
===================================================================
--- haiku/branches/components/gsoc-locale-kit/src/bin/locale/Jamfile 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/src/bin/locale/Jamfile 2009-06-30 15:34:44 UTC (rev 31335)
@@ -3,6 +3,7 @@
SEARCH_SOURCE += [ FDirName $(HAIKU_TOP) src kits tracker ] ;
UsePublicHeaders locale ;
+UsePrivateHeaders locale ;
BinCommand collectcatkeys : collectcatkeys.cpp RegExp.cpp : be liblocale.so ;
Modified: haiku/branches/components/gsoc-locale-kit/src/bin/locale/collectcatkeys.cpp
===================================================================
--- haiku/branches/components/gsoc-locale-kit/src/bin/locale/collectcatkeys.cpp 2009-06-30 15:34:08 UTC (rev 31334)
+++ haiku/branches/components/gsoc-locale-kit/src/bin/locale/collectcatkeys.cpp 2009-06-30 15:34:44 UTC (rev 31335)
@@ -1,8 +1,13 @@
-/*
-** Copyright 2003, Oliver Tappe, zooey at hirschkaefer.de. All rights reserved.
-** Distributed under the terms of the OpenBeOS License.
-*/
+/*
+ * Copyright 2003-2009, Haiku.
+ * Distributed under the terms of the MIT License.
+ *
+ * Authors:
+ * Oliver Tappe, zooey at hirschkaefer.de
+ * Adrien Destugues, pulkomandy at gmail.com
+ */
+
#include <cctype>
#include <cerrno>
#include <cstdio>
@@ -13,8 +18,10 @@
#include <Entry.h>
#include <File.h>
#include "RegExp.h"
+#include <StorageDefs.h>
#include <String.h>
+
bool showKeys = false;
bool showSummary = false;
bool showWarnings = false;
@@ -34,7 +41,7 @@
void
-usage()
+usage()
{
fprintf(stderr,
"usage: collectcatkeys [-pvw] [-r <regex>] [-o <outfile>] [-l <catalogLanguage>]\n"
@@ -56,7 +63,7 @@
fetchStr(const char *&in, BString &str, bool lookForID)
{
int parLevel = 0;
- while(isspace(*in) || *in == '(') {
+ while (isspace(*in) || *in == '(') {
if (*in == '(')
parLevel++;
in++;
@@ -98,7 +105,8 @@
}
} else
return false;
- while(isspace(*in) || *in == ')') {
+
+ while (isspace(*in) || *in == ')') {
if (*in == ')') {
if (!parLevel)
return true;
@@ -145,7 +153,7 @@
}
status_t res;
const char *in = inputStr.String();
- while(rx.RunMatcher(rxprg, in)) {
+ while (rx.RunMatcher(rxprg, in)) {
const char *start = rxprg->startp[0];
in = rxprg->endp[0];
if (fetchKey(in)) {
@@ -154,18 +162,21 @@
printf("CatKey(%ld)\n", id);
res = catalog->SetString(id, "");
if (res != B_OK) {
- fprintf(stderr, "couldn't add key %ld - error: %s\n",
+ fprintf(stderr, "couldn't add key %ld - error: %s\n",
id, strerror(res));
exit(-1);
}
} else {
- if (showKeys)
- printf("CatKey(\"%s\", \"%s\", \"%s\")\n", str.String(),
+ if (showKeys) {
+ printf("CatKey(\"%s\", \"%s\", \"%s\")\n", str.String(),
ctx.String(), cmt.String());
- res = catalog->SetString(str.String(), str.String(), ctx.String(), cmt.String());
+ }
+ res = catalog->SetString(str.String(), str.String(),
+ ctx.String(), cmt.String());
if (res != B_OK) {
- fprintf(stderr, "couldn't add key %s,%s,%s - error: %s\n",
- str.String(), ctx.String(), cmt.String(), strerror(res));
+ fprintf(stderr, "couldn't add key %s,%s,%s - error: %s\n",
+ str.String(), ctx.String(), cmt.String(),
+ strerror(res));
exit(-1);
}
}
@@ -174,9 +185,10 @@
BString match;
if (end)
match.SetTo(start, end-start+1);
- else
- // can't determine end of statement, we output next 40 characters
+ else {
+ // can't determine end of statement, we output next 40 chars
match.SetTo(start, 40);
+ }
fprintf(stderr, "Warning: couldn't resolve catalog-access:\n\t%s\n",
match.String());
}
@@ -221,7 +233,7 @@
}
}
if (!outputFile.Length() && inputFile) {
- // generate default output-file from input-file by replacing
+ // generate default output-file from input-file by replacing
// the extension with '.catkeys':
outputFile = inputFile;
int32 dot = outputFile.FindLast('.');
@@ -231,11 +243,11 @@
}
if (!inputFile || !catalogSig || !outputFile.Length() || !catalogLang)
usage();
-
+
BFile inFile;
status_t res = inFile.SetTo(inputFile, B_READ_ONLY);
if (res != B_OK) {
- fprintf(stderr, "unable to open inputfile %s - error: %s\n", inputFile,
[... truncated: 1485 lines follow ...]
More information about the Haiku-commits
mailing list