blob: c726a56d0880be76fb28d9f884c681ff142f80a3 (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
|
//
// Fluid Project Internationalization code for the Fast Light Tool Kit (FLTK).
//
// Copyright 2025 by Bill Spitzak and others.
//
// This library is free software. Distribution and use rights are outlined in
// the file "COPYING" which should have been included with this file. If this
// file is missing or damaged, see the license at:
//
// https://www.fltk.org/COPYING.php
//
// Please see the following page on how to report bugs and issues:
//
// https://www.fltk.org/bugs.php
//
#include "proj/i18n.h"
#include "io/Project_Reader.h"
#include "io/Project_Writer.h"
static char *dup_str(const char *s) {
return s ? fl_strdup(s) : 0;
}
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");
}
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 I18n::set_gnu_include(const char *s) {
if (gnu_include) free(gnu_include);
gnu_include = dup_str(s);
}
void I18n::set_gnu_conditional(const char *s) {
if (gnu_conditional) free(gnu_conditional);
gnu_conditional = dup_str(s);
}
void I18n::set_gnu_function(const char *s) {
if (gnu_function) free(gnu_function);
gnu_function = dup_str(s);
}
void I18n::set_gnu_static_function(const char *s) {
if (gnu_static_function) free(gnu_static_function);
gnu_static_function = dup_str(s);
}
void I18n::set_posix_include(const char *s) {
if (posix_include) free(posix_include);
posix_include = dup_str(s);
}
void I18n::set_posix_conditional(const char *s) {
if (posix_conditional) free(posix_conditional);
posix_conditional = dup_str(s);
}
void I18n::set_posix_file(const char *s) {
if (posix_file) free(posix_file);
posix_file = dup_str(s);
}
void 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() {
type = FLD_I18N_TYPE_NONE;
set_gnu_include("<libintl.h>");
set_gnu_conditional(0);
set_gnu_function("gettext");
set_gnu_static_function("gettext_noop");
set_posix_include("<nl_types.h>");
set_posix_conditional(0);
set_posix_file(0);
set_posix_set("1");
}
void I18n::read(Project_Reader &f, const char *key) {
if (!strcmp(key, "i18n_type")) {
type = (I18n_Type)(atoi(f.read_word()));
} else if (!strcmp(key, "i18n_gnu_function")) {
set_gnu_function(f.read_word());
} else if (!strcmp(key, "i18n_gnu_static_function")) {
set_gnu_static_function(f.read_word());
} else if (!strcmp(key, "i18n_pos_file")) {
set_posix_file(f.read_word());
} else if (!strcmp(key, "i18n_pos_set")) {
set_posix_set(f.read_word());
} else if (!strcmp(key, "i18n_include")) {
if (type == FLD_I18N_TYPE_GNU) {
set_gnu_include(f.read_word());
} else if (type == FLD_I18N_TYPE_POSIX) {
set_posix_include(f.read_word());
}
} else if (!strcmp(key, "i18n_conditional")) {
if (type == FLD_I18N_TYPE_GNU) {
set_gnu_conditional(f.read_word());
} else if (type == FLD_I18N_TYPE_POSIX) {
set_posix_conditional(f.read_word());
}
}
}
void I18n::write(Project_Writer &f) const {
if ((type != FLD_I18N_TYPE_NONE)) {
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 ? 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 ? 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 ? posix_set : "");
break;
}
}
}
|