Commit 39f738f6958750d1ec527e84a67170d6236c96c2
1 parent
0b4d1595
Exists in
master
and in
3 other branches
Adding more translation methods.
Showing
4 changed files
with
37 additions
and
213 deletions
Show diff stats
src/core/properties/get.c
| ... | ... | @@ -34,6 +34,30 @@ |
| 34 | 34 | #include <lib3270/properties.h> |
| 35 | 35 | #include <utilc.h> |
| 36 | 36 | |
| 37 | + LIB3270_EXPORT const char * lib3270_property_get_name(const LIB3270_PROPERTY * property) { | |
| 38 | + | |
| 39 | + if(property && property->name) | |
| 40 | + return property->name; | |
| 41 | + | |
| 42 | + return ""; | |
| 43 | + | |
| 44 | + } | |
| 45 | + | |
| 46 | + LIB3270_EXPORT const char * lib3270_property_get_tooltip(const LIB3270_PROPERTY * property) { | |
| 47 | + | |
| 48 | + if(property) { | |
| 49 | + | |
| 50 | + if(property->description && *property->description) | |
| 51 | + return dgettext(GETTEXT_PACKAGE,property->description); | |
| 52 | + | |
| 53 | + if(property->summary && *property->summary) | |
| 54 | + return dgettext(GETTEXT_PACKAGE,property->summary); | |
| 55 | + | |
| 56 | + } | |
| 57 | + | |
| 58 | + return ""; | |
| 59 | + } | |
| 60 | + | |
| 37 | 61 | LIB3270_EXPORT const char * lib3270_property_get_label(const LIB3270_PROPERTY * property) { |
| 38 | 62 | |
| 39 | 63 | if(property && property->label) | ... | ... |
src/core/util.c
| ... | ... | @@ -138,219 +138,6 @@ xs_error(const char *fmt, ...) |
| 138 | 138 | lib3270_free(r); |
| 139 | 139 | } |
| 140 | 140 | |
| 141 | -/* | |
| 142 | -/// | |
| 143 | -/// @brief Definition resource splitter. | |
| 144 | -/// | |
| 145 | -/// Definition resource splitter, for resources of the repeating form: | |
| 146 | -/// left: right\n | |
| 147 | -/// | |
| 148 | -/// Can be called iteratively to parse a list. | |
| 149 | -/// Returns 1 for success, 0 for EOF, -1 for error. | |
| 150 | -/// | |
| 151 | -/// Note: Modifies the input string. | |
| 152 | -/// | |
| 153 | -int | |
| 154 | -split_dresource(char **st, char **left, char **right) | |
| 155 | -{ | |
| 156 | - char *s = *st; | |
| 157 | - char *t; | |
| 158 | - Boolean quote; | |
| 159 | - | |
| 160 | - // Skip leading white space. | |
| 161 | - while (my_isspace(*s)) | |
| 162 | - s++; | |
| 163 | - | |
| 164 | - // If nothing left, EOF. | |
| 165 | - if (!*s) | |
| 166 | - return 0; | |
| 167 | - | |
| 168 | - // There must be a left-hand side. | |
| 169 | - if (*s == ':') | |
| 170 | - return -1; | |
| 171 | - | |
| 172 | - // Scan until an unquoted colon is found. | |
| 173 | - *left = s; | |
| 174 | - for (; *s && *s != ':' && *s != '\n'; s++) | |
| 175 | - if (*s == '\\' && *(s+1) == ':') | |
| 176 | - s++; | |
| 177 | - if (*s != ':') | |
| 178 | - return -1; | |
| 179 | - | |
| 180 | - // Stip white space before the colon. | |
| 181 | - for (t = s-1; my_isspace(*t); t--) | |
| 182 | - *t = '\0'; | |
| 183 | - | |
| 184 | - // Terminate the left-hand side. | |
| 185 | - *(s++) = '\0'; | |
| 186 | - | |
| 187 | - // Skip white space after the colon. | |
| 188 | - while (*s != '\n' && my_isspace(*s)) | |
| 189 | - s++; | |
| 190 | - | |
| 191 | - // There must be a right-hand side. | |
| 192 | - if (!*s || *s == '\n') | |
| 193 | - return -1; | |
| 194 | - | |
| 195 | - // Scan until an unquoted newline is found. | |
| 196 | - *right = s; | |
| 197 | - quote = False; | |
| 198 | - for (; *s; s++) { | |
| 199 | - if (*s == '\\' && *(s+1) == '"') | |
| 200 | - s++; | |
| 201 | - else if (*s == '"')split_dresource | |
| 202 | - quote = !quote; | |
| 203 | - else if (!quote && *s == '\n') | |
| 204 | - break; | |
| 205 | - } | |
| 206 | - | |
| 207 | - // Strip white space before the newline. | |
| 208 | - if (*s) { | |
| 209 | - t = s; | |
| 210 | - *st = s+1; | |
| 211 | - } else { | |
| 212 | - t = s-1; | |
| 213 | - *st = s; | |
| 214 | - } | |
| 215 | - while (my_isspace(*t)) | |
| 216 | - *t-- = '\0'; | |
| 217 | - | |
| 218 | - // Done. | |
| 219 | - return 1; | |
| 220 | -} | |
| 221 | -*/ | |
| 222 | - | |
| 223 | -/* | |
| 224 | -/// | |
| 225 | -/// @brief Split a DBCS resource into its parts. | |
| 226 | -/// | |
| 227 | -/// Returns the number of parts found: | |
| 228 | -/// -1 error (empty sub-field) | |
| 229 | -/// 0 nothing found | |
| 230 | -/// 1 one and just one thing found | |
| 231 | -/// 2 two things found | |
| 232 | -/// 3 more than two things found | |
| 233 | -/// | |
| 234 | -int | |
| 235 | -split_dbcs_resource(const char *value, char sep, char **part1, char **part2) | |
| 236 | -{ | |
| 237 | - int n_parts = 0; | |
| 238 | - const char *s = value; | |
| 239 | - const char *f_start = CN; // start of sub-field | |
| 240 | - const char *f_end = CN; // end of sub-field | |
| 241 | - char c; | |
| 242 | - char **rp; | |
| 243 | - | |
| 244 | - *part1 = CN; | |
| 245 | - *part2 = CN; | |
| 246 | - | |
| 247 | - for( ; ; ) { | |
| 248 | - c = *s; | |
| 249 | - if (c == sep || c == '\0') { | |
| 250 | - if (f_start == CN) | |
| 251 | - return -1; | |
| 252 | - if (f_end == CN) | |
| 253 | - f_end = s; | |
| 254 | - if (f_end == f_start) { | |
| 255 | - if (c == sep) { | |
| 256 | - if (*part1) { | |
| 257 | - lib3270_free(*part1); | |
| 258 | - *part1 = NULL; | |
| 259 | - } | |
| 260 | - if (*part2) { | |
| 261 | - lib3270_free(*part2); | |
| 262 | - *part2 = NULL; | |
| 263 | - } | |
| 264 | - return -1; | |
| 265 | - } else | |
| 266 | - return n_parts; | |
| 267 | - } | |
| 268 | - switch (n_parts) { | |
| 269 | - case 0: | |
| 270 | - rp = part1; | |
| 271 | - break; | |
| 272 | - case 1: | |
| 273 | - rp = part2; | |
| 274 | - break; | |
| 275 | - default: | |
| 276 | - return 3; | |
| 277 | - } | |
| 278 | - *rp = lib3270_malloc(f_end - f_start + 1); | |
| 279 | - strncpy(*rp, f_start, f_end - f_start); | |
| 280 | - (*rp)[f_end - f_start] = '\0'; | |
| 281 | - f_end = CN; | |
| 282 | - f_start = CN; | |
| 283 | - n_parts++; | |
| 284 | - if (c == '\0') | |
| 285 | - return n_parts; | |
| 286 | - } else if (isspace(c)) { | |
| 287 | - if (f_end == CN) | |
| 288 | - f_end = s; | |
| 289 | - } else { | |
| 290 | - if (f_start == CN) | |
| 291 | - f_start = s; | |
| 292 | - f_end = CN; | |
| 293 | - } | |
| 294 | - s++; | |
| 295 | - } | |
| 296 | -} | |
| 297 | -*/ | |
| 298 | - | |
| 299 | -/* | |
| 300 | -#if defined(X3270_DISPLAY) | |
| 301 | -/// | |
| 302 | -/// @brief List resource splitter, for lists of elements speparated by newlines. | |
| 303 | -/// | |
| 304 | -/// Can be called iteratively. | |
| 305 | -/// Returns 1 for success, 0 for EOF, -1 for error. | |
| 306 | -/// | |
| 307 | -int | |
| 308 | -split_lresource(char **st, char **value) | |
| 309 | -{ | |
| 310 | - char *s = *st; | |
| 311 | - char *t; | |
| 312 | - Boolean quote; | |
| 313 | - | |
| 314 | - // Skip leading white space. | |
| 315 | - while (my_isspace(*s)) | |
| 316 | - s++; | |
| 317 | - | |
| 318 | - // If nothing left, EOF. | |
| 319 | - if (!*s) | |
| 320 | - return 0; | |
| 321 | - | |
| 322 | - // Save starting point. | |
| 323 | - *value = s; | |
| 324 | - | |
| 325 | - // Scan until an unquoted newline is found. | |
| 326 | - quote = False; | |
| 327 | - for (; *s; s++) { | |
| 328 | - if (*s == '\\' && *(s+1) == '"') | |
| 329 | - s++; | |
| 330 | - else if (*s == '"') | |
| 331 | - quote = !quote; | |
| 332 | - else if (!quote && *s == '\n') | |
| 333 | - break; | |
| 334 | - } | |
| 335 | - | |
| 336 | - // Strip white space before the newline. | |
| 337 | - if (*s) { | |
| 338 | - t = s; | |
| 339 | - *st = s+1; | |
| 340 | - } else { | |
| 341 | - t = s-1; | |
| 342 | - *st = s; | |
| 343 | - } | |
| 344 | - while (my_isspace(*t)) | |
| 345 | - *t-- = '\0'; | |
| 346 | - | |
| 347 | - // Done. | |
| 348 | - return 1; | |
| 349 | -} | |
| 350 | -#endif | |
| 351 | -*/ | |
| 352 | - | |
| 353 | - | |
| 354 | 141 | /** |
| 355 | 142 | * @brief Expands a character in the manner of "cat -v". |
| 356 | 143 | */ |
| ... | ... | @@ -835,3 +622,6 @@ int lib3270_compare_alnum(const char *s1, const char *s2) |
| 835 | 622 | return 0; |
| 836 | 623 | } |
| 837 | 624 | |
| 625 | +LIB3270_EXPORT const char * lib3270_get_translation_domain() { | |
| 626 | + return GETTEXT_PACKAGE; | |
| 627 | +} | ... | ... |
src/include/lib3270.h
| ... | ... | @@ -1668,6 +1668,12 @@ |
| 1668 | 1668 | */ |
| 1669 | 1669 | LIB3270_EXPORT void lib3270_action_group_notify(H3270 *hSession, LIB3270_ACTION_GROUP group); |
| 1670 | 1670 | |
| 1671 | + /** | |
| 1672 | + * @brief Get lib3270's translation domain (for use with dgettext). | |
| 1673 | + * | |
| 1674 | + */ | |
| 1675 | + LIB3270_EXPORT const char * lib3270_get_translation_domain(); | |
| 1676 | + | |
| 1671 | 1677 | #ifdef __cplusplus |
| 1672 | 1678 | } |
| 1673 | 1679 | #endif | ... | ... |
src/include/lib3270/properties.h
| ... | ... | @@ -186,6 +186,10 @@ |
| 186 | 186 | */ |
| 187 | 187 | LIB3270_EXPORT const char * lib3270_property_get_label(const LIB3270_PROPERTY * property); |
| 188 | 188 | |
| 189 | + | |
| 190 | + LIB3270_EXPORT const char * lib3270_property_get_name(const LIB3270_PROPERTY * property); | |
| 191 | + LIB3270_EXPORT const char * lib3270_property_get_tooltip(const LIB3270_PROPERTY * property); | |
| 192 | + | |
| 189 | 193 | /** |
| 190 | 194 | * @brief Get property description. |
| 191 | 195 | * | ... | ... |