From: Bruno Haible Date: Wed, 23 Apr 2003 11:45:55 +0000 (+0000) Subject: Export some functions for use by write-properties.c. X-Git-Tag: v0.12~71 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=dadea2b3e0a76361db82b90fbeefb5440b306aee;p=thirdparty%2Fgettext.git Export some functions for use by write-properties.c. --- diff --git a/gettext-tools/src/ChangeLog b/gettext-tools/src/ChangeLog index b6086f0c9..802ed8334 100644 --- a/gettext-tools/src/ChangeLog +++ b/gettext-tools/src/ChangeLog @@ -1,3 +1,15 @@ +2003-04-13 Bruno Haible + + * write-po.h (message_print_comment, message_print_comment_dot, + message_print_comment_filepos, message_print_comment_flags): New + declarations. + * write-po.c: Reorder functions. + (message_print_comment, message_print_comment_dot, + message_print_comment_filepos, message_print_comment_flags): New + functions, extracted from message_print. + (message_print): Use them. + (message_print_obsolete): Use message_print_comment. + 2003-04-22 Bruno Haible * plural-table.c (plural_table): Add an entry about Faroese. diff --git a/gettext-tools/src/write-po.c b/gettext-tools/src/write-po.c index 32d6fcc9c..862bc2964 100644 --- a/gettext-tools/src/write-po.c +++ b/gettext-tools/src/write-po.c @@ -55,66 +55,11 @@ #endif -/* This variable controls the page width when printing messages. - Defaults to PAGE_WIDTH if not set. Zero (0) given to message_page_- - width_set will result in no wrapping being performed. */ -static size_t page_width = PAGE_WIDTH; - -void -message_page_width_set (size_t n) -{ - if (n == 0) - { - page_width = INT_MAX; - return; - } - - if (n < 20) - n = 20; - - page_width = n; -} - - -/* This variable controls the extent to which the page width applies. - True means it applies to message strings and file reference lines. - False means it applies to file reference lines only. */ -static bool wrap_strings = true; +/* =================== Putting together a #, flags line. =================== */ -void -message_page_width_ignore () -{ - wrap_strings = false; -} - - -/* These three variables control the output style of the message_print - function. Interface functions for them are to be used. */ -static bool indent = false; -static bool uniforum = false; -static bool escape = false; - -void -message_print_style_indent () -{ - indent = true; -} - -void -message_print_style_uniforum () -{ - uniforum = true; -} - -void -message_print_style_escape (bool flag) -{ - escape = flag; -} - - -/* Local functions. */ +/* Convert IS_FORMAT in the context of programming language LANG to a flag + string for use in #, flags. */ static const char * make_format_description_string (enum is_format is_format, const char *lang, @@ -146,6 +91,8 @@ make_format_description_string (enum is_format is_format, const char *lang, } +/* Return true if IS_FORMAT is worth mentioning in a #, flags list. */ + static bool significant_format_p (enum is_format is_format) { @@ -153,6 +100,8 @@ significant_format_p (enum is_format is_format) } +/* Return true if one of IS_FORMAT is worth mentioning in a #, flags list. */ + static bool has_significant_format_p (const enum is_format is_format[NFORMATS]) { @@ -165,6 +114,8 @@ has_significant_format_p (const enum is_format is_format[NFORMATS]) } +/* Convert a wrapping flag DO_WRAP to a string for use in #, flags. */ + static const char * make_c_width_description_string (enum is_wrap do_wrap) { @@ -186,6 +137,245 @@ make_c_width_description_string (enum is_wrap do_wrap) } +/* ================ Output parts of a message, as comments. ================ */ + + +/* Output mp->comment as a set of comment lines. */ + +void +message_print_comment (const message_ty *mp, FILE *fp) +{ + if (mp->comment != NULL) + { + size_t j; + + for (j = 0; j < mp->comment->nitems; ++j) + { + const char *s = mp->comment->item[j]; + do + { + const char *e; + putc ('#', fp); + if (*s != '\0' && *s != ' ') + putc (' ', fp); + e = strchr (s, '\n'); + if (e == NULL) + { + fputs (s, fp); + s = NULL; + } + else + { + fwrite (s, 1, e - s, fp); + s = e + 1; + } + putc ('\n', fp); + } + while (s != NULL); + } + } +} + + +/* Output mp->comment_dot as a set of comment lines. */ + +void +message_print_comment_dot (const message_ty *mp, FILE *fp) +{ + if (mp->comment_dot != NULL) + { + size_t j; + + for (j = 0; j < mp->comment_dot->nitems; ++j) + { + const char *s = mp->comment_dot->item[j]; + putc ('#', fp); + putc ('.', fp); + if (*s != '\0' && *s != ' ') + putc (' ', fp); + fputs (s, fp); + putc ('\n', fp); + } + } +} + + +/* Output mp->filepos as a set of comment lines. */ + +void +message_print_comment_filepos (const message_ty *mp, FILE *fp, + bool uniforum, size_t page_width) +{ + if (mp->filepos_count != 0) + { + if (uniforum) + { + size_t j; + + for (j = 0; j < mp->filepos_count; ++j) + { + lex_pos_ty *pp = &mp->filepos[j]; + char *cp = pp->file_name; + while (cp[0] == '.' && cp[1] == '/') + cp += 2; + /* There are two Sun formats to choose from: SunOS and + Solaris. Use the Solaris form here. */ + fprintf (fp, "# File: %s, line: %ld\n", + cp, (long) pp->line_number); + } + } + else + { + size_t column; + size_t j; + + fputs ("#:", fp); + column = 2; + for (j = 0; j < mp->filepos_count; ++j) + { + lex_pos_ty *pp; + char buffer[21]; + char *cp; + size_t len; + + pp = &mp->filepos[j]; + cp = pp->file_name; + while (cp[0] == '.' && cp[1] == '/') + cp += 2; + /* Some xgettext input formats, like RST, lack line numbers. */ + if (pp->line_number == (size_t)(-1)) + buffer[0] = '\0'; + else + sprintf (buffer, ":%ld", (long) pp->line_number); + len = strlen (cp) + strlen (buffer) + 1; + if (column > 2 && column + len >= page_width) + { + fputs ("\n#:", fp); + column = 2; + } + fprintf (fp, " %s%s", cp, buffer); + column += len; + } + putc ('\n', fp); + } + } +} + + +/* Output mp->is_fuzzy, mp->is_format, mp->do_wrap as a comment line. */ + +void +message_print_comment_flags (const message_ty *mp, FILE *fp, bool debug) +{ + if ((mp->is_fuzzy && mp->msgstr[0] != '\0') + || has_significant_format_p (mp->is_format) + || mp->do_wrap == no) + { + bool first_flag = true; + size_t i; + + putc ('#', fp); + putc (',', fp); + + /* We don't print the fuzzy flag if the msgstr is empty. This + might be introduced by the user but we want to normalize the + output. */ + if (mp->is_fuzzy && mp->msgstr[0] != '\0') + { + fputs (" fuzzy", fp); + first_flag = false; + } + + for (i = 0; i < NFORMATS; i++) + if (significant_format_p (mp->is_format[i])) + { + if (!first_flag) + putc (',', fp); + + fputs (make_format_description_string (mp->is_format[i], + format_language[i], debug), + fp); + first_flag = false; + } + + if (mp->do_wrap == no) + { + if (!first_flag) + putc (',', fp); + + fputs (make_c_width_description_string (mp->do_wrap), fp); + first_flag = false; + } + + putc ('\n', fp); + } +} + + +/* =========== Some parameters for use by 'msgdomain_list_print'. ========== */ + + +/* This variable controls the page width when printing messages. + Defaults to PAGE_WIDTH if not set. Zero (0) given to message_page_- + width_set will result in no wrapping being performed. */ +static size_t page_width = PAGE_WIDTH; + +void +message_page_width_set (size_t n) +{ + if (n == 0) + { + page_width = INT_MAX; + return; + } + + if (n < 20) + n = 20; + + page_width = n; +} + + +/* This variable controls the extent to which the page width applies. + True means it applies to message strings and file reference lines. + False means it applies to file reference lines only. */ +static bool wrap_strings = true; + +void +message_page_width_ignore () +{ + wrap_strings = false; +} + + +/* These three variables control the output style of the message_print + function. Interface functions for them are to be used. */ +static bool indent = false; +static bool uniforum = false; +static bool escape = false; + +void +message_print_style_indent () +{ + indent = true; +} + +void +message_print_style_uniforum () +{ + uniforum = true; +} + +void +message_print_style_escape (bool flag) +{ + escape = flag; +} + + +/* ================ msgdomain_list_print() and subroutines. ================ */ + + /* A version of memcpy optimized for the case n <= 1. */ static inline void memcpy_small (void *dst, const void *src, size_t n) @@ -600,12 +790,11 @@ print_blank_line (FILE *fp) putc ('\n', fp); } + static void message_print (const message_ty *mp, FILE *fp, const char *charset, bool blank_line, bool debug) { - size_t j; - /* Separate messages with a blank line. Uniforum doesn't like blank lines, so use an empty comment (unless there already is one). */ if (blank_line && (!uniforum @@ -615,139 +804,18 @@ message_print (const message_ty *mp, FILE *fp, const char *charset, print_blank_line (fp); /* Print translator comment if available. */ - if (mp->comment != NULL) - for (j = 0; j < mp->comment->nitems; ++j) - { - const char *s = mp->comment->item[j]; - do - { - const char *e; - putc ('#', fp); - if (*s != '\0' && *s != ' ') - putc (' ', fp); - e = strchr (s, '\n'); - if (e == NULL) - { - fputs (s, fp); - s = NULL; - } - else - { - fwrite (s, 1, e - s, fp); - s = e + 1; - } - putc ('\n', fp); - } - while (s != NULL); - } + message_print_comment (mp, fp); - if (mp->comment_dot != NULL) - for (j = 0; j < mp->comment_dot->nitems; ++j) - { - const char *s = mp->comment_dot->item[j]; - putc ('#', fp); - putc ('.', fp); - if (*s != '\0' && *s != ' ') - putc (' ', fp); - fputs (s, fp); - putc ('\n', fp); - } + /* Print xgettext extracted comments. */ + message_print_comment_dot (mp, fp); /* Print the file position comments. This will help a human who is trying to navigate the sources. There is no problem of getting repeated positions, because duplicates are checked for. */ - if (mp->filepos_count != 0) - { - if (uniforum) - for (j = 0; j < mp->filepos_count; ++j) - { - lex_pos_ty *pp = &mp->filepos[j]; - char *cp = pp->file_name; - while (cp[0] == '.' && cp[1] == '/') - cp += 2; - /* There are two Sun formats to choose from: SunOS and - Solaris. Use the Solaris form here. */ - fprintf (fp, "# File: %s, line: %ld\n", - cp, (long) pp->line_number); - } - else - { - size_t column; - - fputs ("#:", fp); - column = 2; - for (j = 0; j < mp->filepos_count; ++j) - { - lex_pos_ty *pp; - char buffer[21]; - char *cp; - size_t len; - - pp = &mp->filepos[j]; - cp = pp->file_name; - while (cp[0] == '.' && cp[1] == '/') - cp += 2; - /* Some xgettext input formats, like RST, lack line numbers. */ - if (pp->line_number == (size_t)(-1)) - buffer[0] = '\0'; - else - sprintf (buffer, ":%ld", (long) pp->line_number); - len = strlen (cp) + strlen (buffer) + 1; - if (column > 2 && column + len >= page_width) - { - fputs ("\n#:", fp); - column = 2; - } - fprintf (fp, " %s%s", cp, buffer); - column += len; - } - putc ('\n', fp); - } - } + message_print_comment_filepos (mp, fp, uniforum, page_width); /* Print flag information in special comment. */ - if ((mp->is_fuzzy && mp->msgstr[0] != '\0') - || has_significant_format_p (mp->is_format) - || mp->do_wrap == no) - { - bool first_flag = true; - size_t i; - - putc ('#', fp); - putc (',', fp); - - /* We don't print the fuzzy flag if the msgstr is empty. This - might be introduced by the user but we want to normalize the - output. */ - if (mp->is_fuzzy && mp->msgstr[0] != '\0') - { - fputs (" fuzzy", fp); - first_flag = false; - } - - for (i = 0; i < NFORMATS; i++) - if (significant_format_p (mp->is_format[i])) - { - if (!first_flag) - putc (',', fp); - - fputs (make_format_description_string (mp->is_format[i], - format_language[i], debug), - fp); - first_flag = false; - } - - if (mp->do_wrap == no) - { - if (!first_flag) - putc (',', fp); - - fputs (make_c_width_description_string (mp->do_wrap), fp); - first_flag = false; - } - - putc ('\n', fp); - } + message_print_comment_flags (mp, fp, debug); /* Print each of the message components. Wrap them nicely so they are as readable as possible. If there is no recorded msgstr for @@ -787,8 +855,6 @@ static void message_print_obsolete (const message_ty *mp, FILE *fp, const char *charset, bool blank_line) { - size_t j; - /* If msgstr is the empty string we print nothing. */ if (mp->msgstr[0] == '\0') return; @@ -799,31 +865,7 @@ message_print_obsolete (const message_ty *mp, FILE *fp, const char *charset, print_blank_line (fp); /* Print translator comment if available. */ - if (mp->comment) - for (j = 0; j < mp->comment->nitems; ++j) - { - const char *s = mp->comment->item[j]; - do - { - const char *e; - putc ('#', fp); - if (*s != '\0' && *s != ' ') - putc (' ', fp); - e = strchr (s, '\n'); - if (e == NULL) - { - fputs (s, fp); - s = NULL; - } - else - { - fwrite (s, 1, e - s, fp); - s = e + 1; - } - putc ('\n', fp); - } - while (s != NULL); - } + message_print_comment (mp, fp); /* Print flag information in special comment. */ if (mp->is_fuzzy) @@ -998,6 +1040,9 @@ msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, } +/* =============================== Sorting. ================================ */ + + static int cmp_by_msgid (const void *va, const void *vb) { diff --git a/gettext-tools/src/write-po.h b/gettext-tools/src/write-po.h index ffebda4ad..261a7840d 100644 --- a/gettext-tools/src/write-po.h +++ b/gettext-tools/src/write-po.h @@ -1,5 +1,5 @@ /* GNU gettext - internationalization aids - Copyright (C) 1995-1998, 2000-2002 Free Software Foundation, Inc. + Copyright (C) 1995-1998, 2000-2003 Free Software Foundation, Inc. This file was written by Peter Miller @@ -23,7 +23,21 @@ #include "message.h" #include +#include +/* These functions output parts of a message, as comments. */ +extern void + message_print_comment (const message_ty *mp, FILE *fp); +extern void + message_print_comment_dot (const message_ty *mp, FILE *fp); +extern void + message_print_comment_filepos (const message_ty *mp, FILE *fp, + bool uniforum, size_t page_width); +extern void + message_print_comment_flags (const message_ty *mp, FILE *fp, + bool debug); + +/* These functions set some parameters for use by 'msgdomain_list_print'. */ extern void message_page_width_set (size_t width); extern void @@ -35,10 +49,14 @@ extern void extern void message_print_style_escape (bool flag); +/* Output MDLP into a PO file with the given FILENAME, according to the + parameters set by the functions above. */ extern void msgdomain_list_print (msgdomain_list_ty *mdlp, const char *filename, bool force, bool debug); + +/* Sort MDLP destructively according to the given criterion. */ extern void msgdomain_list_sort_by_msgid (msgdomain_list_ty *mdlp); extern void