<URL: http://bugs.freeciv.org/Ticket/Display.html?id=38138 >
Support to save strings with gettext marking to registry code. - ML
diff -Nurd -X.diff_ignore freeciv/utility/registry.c freeciv/utility/registry.c --- freeciv/utility/registry.c 2007-03-12 19:21:42.000000000 +0200 +++ freeciv/utility/registry.c 2007-03-14 15:24:23.000000000 +0200 @@ -186,6 +186,7 @@ int dim; /* vector's size */ int used; /* number of times entry looked up */ char *comment; /* comment, may be NULL */ + bool gettext_marking; /* should use gettext marking when saved? */ }; /* create a 'struct entry_list' and related functions: */ @@ -823,8 +824,15 @@ if(icol>0) fz_fprintf(fs, ","); - if(pentry->svalue) + if(pentry->svalue) { + if (pentry->gettext_marking) { + fz_fprintf(fs, "_("); + } fz_fprintf(fs, "\"%s\"", moutstr(pentry->svalue)); + if (pentry->gettext_marking) { + fz_fprintf(fs, ")"); + } + } else fz_fprintf(fs, "%d", pentry->ivalue); @@ -850,7 +858,10 @@ fz_fprintf(fs, ", \"%s\"", moutstr(pentry->vec_values[i])); } } else if (pentry->svalue) { - fz_fprintf(fs, "%s=\"%s\"", pentry->name, moutstr(pentry->svalue)); + fz_fprintf(fs, "%s=%s\"%s\"%s", pentry->name, + pentry->gettext_marking ? "_(" : "", + moutstr(pentry->svalue), + pentry->gettext_marking ? ")" : ""); } else { fz_fprintf(fs, "%s=%d", pentry->name, pentry->ivalue); } @@ -960,6 +971,7 @@ pentry->vec_values = NULL; pentry->dim = 0; pentry->comment = NULL; + pentry->gettext_marking = FALSE; } /************************************************************************** @@ -984,6 +996,7 @@ pentry->vec_values = NULL; pentry->dim = 0; pentry->comment = sbuf_strdup(my_section_file->sb, comment); + pentry->gettext_marking = FALSE; } /************************************************************************** @@ -1013,6 +1026,7 @@ pentry->vec_values = NULL; pentry->dim = 0; pentry->comment = NULL; + pentry->gettext_marking = FALSE; } /************************************************************************** @@ -1034,6 +1048,7 @@ pentry->vec_values = NULL; pentry->dim = 0; pentry->comment = NULL; + pentry->gettext_marking = FALSE; } /************************************************************************** @@ -1056,6 +1071,53 @@ pentry->vec_values = NULL; pentry->dim = 0; pentry->comment = sbuf_strdup(my_section_file->sb, comment); + pentry->gettext_marking = FALSE; +} + +/************************************************************************** + Insert string that will get gettext marking when saved to disk +**************************************************************************/ +void secfile_insert_str_gettext(struct section_file *my_section_file, + const char *sval, const char *path, ...) +{ + struct entry *pentry; + char buf[MAX_LEN_BUFFER]; + va_list ap; + + va_start(ap, path); + my_vsnprintf(buf, sizeof(buf), path, ap); + va_end(ap); + + pentry = section_file_insert_internal(my_section_file, buf); + pentry->svalue = sbuf_strdup(my_section_file->sb, sval); + pentry->vec_values = NULL; + pentry->dim = 0; + pentry->comment = NULL; + pentry->gettext_marking = TRUE; +} + +/************************************************************************** + Insert string that will get gettext marking when saved to disk + Also comment is saved after string. +**************************************************************************/ +void secfile_insert_str_gettext_comment(struct section_file *my_section_file, + char *sval, const char *const comment, + const char *path, ...) +{ + struct entry *pentry; + char buf[MAX_LEN_BUFFER]; + va_list ap; + + va_start(ap, path); + my_vsnprintf(buf, sizeof(buf), path, ap); + va_end(ap); + + pentry = section_file_insert_internal(my_section_file, buf); + pentry->svalue = sbuf_strdup(my_section_file->sb, sval); + pentry->vec_values = NULL; + pentry->dim = 0; + pentry->comment = sbuf_strdup(my_section_file->sb, comment); + pentry->gettext_marking = TRUE; } /************************************************************************** diff -Nurd -X.diff_ignore freeciv/utility/registry.h freeciv/utility/registry.h --- freeciv/utility/registry.h 2007-03-05 21:09:34.000000000 +0200 +++ freeciv/utility/registry.h 2007-03-14 14:35:27.000000000 +0200 @@ -68,6 +68,13 @@ const char **values, int dim, const char *path, ...) fc__attribute((__format__ (__printf__, 4, 5))); +void secfile_insert_str_gettext(struct section_file *my_section_file, + const char *sval, const char *path, ...) + fc__attribute((__format__ (__printf__, 3, 4))); +void secfile_insert_str_gettext_comment(struct section_file *my_section_file, + char *sval, const char *const comment, + const char *path, ...) + fc__attribute((__format__ (__printf__, 4, 5))); bool section_file_lookup(struct section_file *my_section_file, const char *path, ...)
_______________________________________________ Freeciv-dev mailing list Freeciv-dev@gna.org https://mail.gna.org/listinfo/freeciv-dev