summaryrefslogtreecommitdiff
path: root/fluid/proj
diff options
context:
space:
mode:
Diffstat (limited to 'fluid/proj')
-rw-r--r--fluid/proj/i18n.cxx124
-rw-r--r--fluid/proj/i18n.h36
2 files changed, 116 insertions, 44 deletions
diff --git a/fluid/proj/i18n.cxx b/fluid/proj/i18n.cxx
index dc4380bd4..71ba892a1 100644
--- a/fluid/proj/i18n.cxx
+++ b/fluid/proj/i18n.cxx
@@ -19,74 +19,136 @@
#include "io/Project_Reader.h"
#include "io/Project_Writer.h"
-using namespace fld;
+static char *dup_str(const char *s) {
+ return s ? fl_strdup(s) : 0;
+}
+
+fld::proj::I18n::I18n(Project &p) : project_(p) {
+ type = FLD_I18N_TYPE_NONE;
+ gnu_include = fl_strdup("<libintl.h>");
+ gnu_conditional = 0;
+ gnu_function = fl_strdup("gettext");
+ gnu_static_function = fl_strdup("gettext_noop");
+ posix_include = fl_strdup("<nl_types.h>");
+ posix_conditional = 0;
+ posix_file = 0;
+ posix_set = fl_strdup("1");
+}
+
+fld::proj::I18n::~I18n() {
+ if (gnu_include) free(gnu_include);
+ if (gnu_conditional) free(gnu_conditional);
+ if (gnu_function) free(gnu_function);
+ if (gnu_static_function) free(gnu_static_function);
+ if (posix_include) free(posix_include);
+ if (posix_conditional) free(posix_conditional);
+ if (posix_file) free(posix_file);
+ if (posix_set) free(posix_set);
+}
+
+void fld::proj::I18n::set_gnu_include(const char *s) {
+ if (gnu_include) free(gnu_include);
+ gnu_include = dup_str(s);
+}
+
+void fld::proj::I18n::set_gnu_conditional(const char *s) {
+ if (gnu_conditional) free(gnu_conditional);
+ gnu_conditional = dup_str(s);
+}
-using namespace fld::proj;
+void fld::proj::I18n::set_gnu_function(const char *s) {
+ if (gnu_function) free(gnu_function);
+ gnu_function = dup_str(s);
+}
+
+void fld::proj::I18n::set_gnu_static_function(const char *s) {
+ if (gnu_static_function) free(gnu_static_function);
+ gnu_static_function = dup_str(s);
+}
+
+void fld::proj::I18n::set_posix_include(const char *s) {
+ if (posix_include) free(posix_include);
+ posix_include = dup_str(s);
+}
+void fld::proj::I18n::set_posix_conditional(const char *s) {
+ if (posix_conditional) free(posix_conditional);
+ posix_conditional = dup_str(s);
+}
+
+void fld::proj::I18n::set_posix_file(const char *s) {
+ if (posix_file) free(posix_file);
+ posix_file = dup_str(s);
+}
+
+void fld::proj::I18n::set_posix_set(const char *s) {
+ if (posix_set) free(posix_set);
+ posix_set = dup_str(s);
+}
/**
Reset all project setting to create a new empty project.
*/
-void I18n::reset() {
+void fld::proj::I18n::reset() {
type = FLD_I18N_TYPE_NONE;
- gnu_include = "<libintl.h>";
- gnu_conditional = "";
- gnu_function = "gettext";
- gnu_static_function = "gettext_noop";
+ set_gnu_include("<libintl.h>");
+ set_gnu_conditional(0);
+ set_gnu_function("gettext");
+ set_gnu_static_function("gettext_noop");
- posix_include = "<nl_types.h>";
- posix_conditional = "";
- posix_file = "";
- posix_set = "1";
+ set_posix_include("<nl_types.h>");
+ set_posix_conditional(0);
+ set_posix_file(0);
+ set_posix_set("1");
}
-void I18n::read(io::Project_Reader &f, const char *key) {
+void fld::proj::I18n::read(io::Project_Reader &f, const char *key) {
if (!strcmp(key, "i18n_type")) {
- type = static_cast<fld::I18n_Type>(atoi(f.read_word()));
+ type = (fld::I18n_Type)(atoi(f.read_word()));
} else if (!strcmp(key, "i18n_gnu_function")) {
- gnu_function = f.read_word();
+ set_gnu_function(f.read_word());
} else if (!strcmp(key, "i18n_gnu_static_function")) {
- gnu_static_function = f.read_word();
+ set_gnu_static_function(f.read_word());
} else if (!strcmp(key, "i18n_pos_file")) {
- posix_file = f.read_word();
+ set_posix_file(f.read_word());
} else if (!strcmp(key, "i18n_pos_set")) {
- posix_set = f.read_word();
+ set_posix_set(f.read_word());
} else if (!strcmp(key, "i18n_include")) {
if (type == FLD_I18N_TYPE_GNU) {
- gnu_include = f.read_word();
+ set_gnu_include(f.read_word());
} else if (type == FLD_I18N_TYPE_POSIX) {
- posix_include = f.read_word();
+ set_posix_include(f.read_word());
}
} else if (!strcmp(key, "i18n_conditional")) {
if (type == FLD_I18N_TYPE_GNU) {
- gnu_conditional = f.read_word();
+ set_gnu_conditional(f.read_word());
} else if (type == FLD_I18N_TYPE_POSIX) {
- posix_conditional = f.read_word();
+ set_posix_conditional(f.read_word());
}
}
}
-void I18n::write(io::Project_Writer &f) const {
+void fld::proj::I18n::write(io::Project_Writer &f) const {
if ((type != FLD_I18N_TYPE_NONE)) {
- f.write_string("\ni18n_type %d", static_cast<int>(type));
+ f.write_string("\ni18n_type %d", (int)(type));
switch (type) {
case FLD_I18N_TYPE_NONE:
break;
case FLD_I18N_TYPE_GNU : /* GNU gettext */
- f.write_string("\ni18n_include"); f.write_word(gnu_include);
- f.write_string("\ni18n_conditional"); f.write_word(gnu_conditional);
- f.write_string("\ni18n_gnu_function"); f.write_word(gnu_function);
- f.write_string("\ni18n_gnu_static_function"); f.write_word(gnu_static_function);
+ f.write_string("\ni18n_include"); f.write_word(gnu_include ? gnu_include : "");
+ f.write_string("\ni18n_conditional"); f.write_word(gnu_conditional ? gnu_conditional : "");
+ f.write_string("\ni18n_gnu_function"); f.write_word(gnu_function ? gnu_function : "");
+ f.write_string("\ni18n_gnu_static_function"); f.write_word(gnu_static_function ? gnu_static_function : "");
break;
case FLD_I18N_TYPE_POSIX : /* POSIX catgets */
- f.write_string("\ni18n_include"); f.write_word(posix_include);
- f.write_string("\ni18n_conditional"); f.write_word(posix_conditional);
- if (!posix_file.empty()) {
+ f.write_string("\ni18n_include"); f.write_word(posix_include ? posix_include : "");
+ f.write_string("\ni18n_conditional"); f.write_word(posix_conditional ? posix_conditional : "");
+ if (posix_file && posix_file[0]) {
f.write_string("\ni18n_pos_file");
f.write_word(posix_file);
}
- f.write_string("\ni18n_pos_set"); f.write_word(posix_set);
+ f.write_string("\ni18n_pos_set"); f.write_word(posix_set ? posix_set : "");
break;
}
}
diff --git a/fluid/proj/i18n.h b/fluid/proj/i18n.h
index 0d9119ca2..65ef72bf6 100644
--- a/fluid/proj/i18n.h
+++ b/fluid/proj/i18n.h
@@ -17,7 +17,9 @@
#ifndef FLUID_PROJ_I18N_H
#define FLUID_PROJ_I18N_H
-#include <string>
+#include <FL/fl_string_functions.h>
+#include <stdlib.h>
+#include <string.h>
namespace fld {
@@ -54,35 +56,44 @@ public:
Project &project_;
/// One of the available internationalization types.
- fld::I18n_Type type = FLD_I18N_TYPE_NONE;
+ fld::I18n_Type type;
/// Include file for GNU i18n, writes an #include statement into the source
/// file. This is usually `<libintl.h>` or `"gettext.h"` for GNU gettext.
- std::string gnu_include = "<libintl.h>";
+ char *gnu_include;
// Optional name of a macro for conditional i18n compilation.
- std::string gnu_conditional = "";
+ char *gnu_conditional;
/// For the gettext/intl.h options, this is the function that translates text
/// at runtime. This is usually "gettext" or "_".
- std::string gnu_function = "gettext";
+ char *gnu_function;
/// For the gettext/intl.h options, this is the function that marks the translation
/// of text at initialisation time. This is usually "gettext_noop" or "N_".
- std::string gnu_static_function = "gettext_noop";
+ char *gnu_static_function;
/// Include file for Posix i18n, write a #include statement into the source
/// file. This is usually `<nl_types.h>` for Posix catgets.
- std::string posix_include = "<nl_types.h>";
+ char *posix_include;
// Optional name of a macro for conditional i18n compilation.
- std::string posix_conditional = "";
+ char *posix_conditional;
/// Name of the nl_catd database
- std::string posix_file = "";
+ char *posix_file;
/// Message set ID for the catalog.
- std::string posix_set = "1";
+ char *posix_set;
public: // Methods
- I18n(Project &p) : project_(p) {};
- ~I18n() = default;
+ I18n(Project &p);
+ ~I18n();
void reset();
void read(io::Project_Reader &f, const char *key);
void write(io::Project_Writer &f) const;
+
+ void set_gnu_include(const char *s);
+ void set_gnu_conditional(const char *s);
+ void set_gnu_function(const char *s);
+ void set_gnu_static_function(const char *s);
+ void set_posix_include(const char *s);
+ void set_posix_conditional(const char *s);
+ void set_posix_file(const char *s);
+ void set_posix_set(const char *s);
};
} // namespace proj
@@ -91,4 +102,3 @@ public: // Methods
#endif // FLUID_PROJ_I18N_H
-