#include "xalloc.h"
#include "xallocsa.h"
#include "c-strstr.h"
+#include "ostream.h"
#include "xvasprintf.h"
#include "po-xerror.h"
#include "gettext.h"
/* Output mp->comment as a set of comment lines. */
void
-message_print_comment (const message_ty *mp, FILE *fp)
+message_print_comment (const message_ty *mp, ostream_t stream)
{
if (mp->comment != NULL)
{
do
{
const char *e;
- putc ('#', fp);
+ ostream_write_str (stream, "#");
if (*s != '\0' && *s != ' ')
- putc (' ', fp);
+ ostream_write_str (stream, " ");
e = strchr (s, '\n');
if (e == NULL)
{
- fputs (s, fp);
+ ostream_write_str (stream, s);
s = NULL;
}
else
{
- fwrite (s, 1, e - s, fp);
+ ostream_write_mem (stream, s, e - s);
s = e + 1;
}
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
while (s != NULL);
}
/* Output mp->comment_dot as a set of comment lines. */
void
-message_print_comment_dot (const message_ty *mp, FILE *fp)
+message_print_comment_dot (const message_ty *mp, ostream_t stream)
{
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);
+ ostream_write_str (stream, "#.");
if (*s != '\0' && *s != ' ')
- putc (' ', fp);
- fputs (s, fp);
- putc ('\n', fp);
+ ostream_write_str (stream, " ");
+ ostream_write_str (stream, s);
+ ostream_write_str (stream, "\n");
}
}
}
/* Output mp->filepos as a set of comment lines. */
void
-message_print_comment_filepos (const message_ty *mp, FILE *fp,
+message_print_comment_filepos (const message_ty *mp, ostream_t stream,
bool uniforum, size_t page_width)
{
if (mp->filepos_count != 0)
{
lex_pos_ty *pp = &mp->filepos[j];
char *cp = pp->file_name;
+ char *str;
+
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);
+ str = xasprintf ("# File: %s, line: %ld\n",
+ cp, (long) pp->line_number);
+ ostream_write_str (stream, str);
+ free (str);
}
}
else
size_t column;
size_t j;
- fputs ("#:", fp);
+ ostream_write_str (stream, "#:");
column = 2;
for (j = 0; j < mp->filepos_count; ++j)
{
len = strlen (cp) + strlen (buffer) + 1;
if (column > 2 && column + len >= page_width)
{
- fputs ("\n#:", fp);
+ ostream_write_str (stream, "\n#:");
column = 2;
}
- fprintf (fp, " %s%s", cp, buffer);
+ ostream_write_str (stream, " ");
+ ostream_write_str (stream, cp);
+ ostream_write_str (stream, buffer);
column += len;
}
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
}
}
/* 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)
+message_print_comment_flags (const message_ty *mp, ostream_t stream, bool debug)
{
if ((mp->is_fuzzy && mp->msgstr[0] != '\0')
|| has_significant_format_p (mp->is_format)
bool first_flag = true;
size_t i;
- putc ('#', fp);
- putc (',', fp);
+ ostream_write_str (stream, "#,");
/* 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);
+ ostream_write_str (stream, " fuzzy");
first_flag = false;
}
if (significant_format_p (mp->is_format[i]))
{
if (!first_flag)
- putc (',', fp);
+ ostream_write_str (stream, ",");
- fputs (make_format_description_string (mp->is_format[i],
- format_language[i], debug),
- fp);
+ ostream_write_str (stream,
+ make_format_description_string (mp->is_format[i],
+ format_language[i],
+ debug));
first_flag = false;
}
if (mp->do_wrap == no)
{
if (!first_flag)
- putc (',', fp);
+ ostream_write_str (stream, ",");
- fputs (make_c_width_description_string (mp->do_wrap), fp);
+ ostream_write_str (stream,
+ make_c_width_description_string (mp->do_wrap));
first_flag = false;
}
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
}
static void
-wrap (const message_ty *mp, FILE *fp, const char *line_prefix, int extra_indent,
+wrap (const message_ty *mp, ostream_t stream,
+ const char *line_prefix, int extra_indent,
const char *name, const char *value,
enum is_wrap do_wrap, size_t page_width,
const char *charset)
|| memchr (linebreaks, UC_BREAK_POSSIBLE, portion_len) != NULL))
{
if (line_prefix != NULL)
- fputs (line_prefix, fp);
- fputs (name, fp);
- fputs (" \"\"\n", fp);
+ ostream_write_str (stream, line_prefix);
+ ostream_write_str (stream, name);
+ ostream_write_str (stream, " \"\"\n");
first_line = false;
/* Recompute startcol and linebreaks. */
goto recompute;
if (line_prefix != NULL)
{
- fputs (line_prefix, fp);
+ ostream_write_str (stream, line_prefix);
currcol = strlen (line_prefix);
}
if (first_line)
{
- fputs (name, fp);
+ ostream_write_str (stream, name);
currcol += strlen (name);
if (indent)
{
if (extra_indent > 0)
- fwrite (" ", 1, extra_indent, fp);
+ ostream_write_mem (stream, " ", extra_indent);
currcol += extra_indent;
- fwrite (" ", 1, 8 - (currcol & 7), fp);
+ ostream_write_mem (stream, " ", 8 - (currcol & 7));
currcol = (currcol + 8) & ~7;
}
else
{
- putc (' ', fp);
+ ostream_write_str (stream, " ");
currcol++;
}
first_line = false;
if (indent)
{
if (extra_indent > 0)
- fwrite (" ", 1, extra_indent, fp);
+ ostream_write_mem (stream, " ", extra_indent);
currcol += extra_indent;
- fwrite (" ", 1, 8 - (currcol & 7), fp);
+ ostream_write_mem (stream, " ", 8 - (currcol & 7));
currcol = (currcol + 8) & ~7;
}
}
}
/* Print the portion itself, with linebreaks where necessary. */
- putc ('"', fp);
+ ostream_write_str (stream, "\"");
for (i = 0; i < portion_len; i++)
{
if (linebreaks[i] == UC_BREAK_POSSIBLE)
{
int currcol;
- fputs ("\"\n", fp);
+ ostream_write_str (stream, "\"\n");
currcol = 0;
/* INDENT-S. */
if (line_prefix != NULL)
{
- fputs (line_prefix, fp);
+ ostream_write_str (stream, line_prefix);
currcol = strlen (line_prefix);
}
if (indent)
{
- fwrite (" ", 1, 8 - (currcol & 7), fp);
+ ostream_write_mem (stream, " ", 8 - (currcol & 7));
currcol = (currcol + 8) & ~7;
}
- putc ('"', fp);
+ ostream_write_str (stream, "\"");
}
- putc (portion[i], fp);
+ ostream_write_mem (stream, &portion[i], 1);
}
- fputs ("\"\n", fp);
+ ostream_write_str (stream, "\"\n");
free (linebreaks);
free (overrides);
static void
-print_blank_line (FILE *fp)
+print_blank_line (ostream_t stream)
{
if (uniforum)
- fputs ("#\n", fp);
+ ostream_write_str (stream, "#\n");
else
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
static void
-message_print (const message_ty *mp, FILE *fp, const char *charset,
- size_t page_width, bool blank_line, bool debug)
+message_print (const message_ty *mp, ostream_t stream,
+ const char *charset, size_t page_width, bool blank_line,
+ bool debug)
{
int extra_indent;
|| mp->comment == NULL
|| mp->comment->nitems == 0
|| mp->comment->item[0][0] != '\0'))
- print_blank_line (fp);
+ print_blank_line (stream);
/* Print translator comment if available. */
- message_print_comment (mp, fp);
+ message_print_comment (mp, stream);
/* Print xgettext extracted comments. */
- message_print_comment_dot (mp, fp);
+ message_print_comment_dot (mp, stream);
/* 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. */
- message_print_comment_filepos (mp, fp, uniforum, page_width);
+ message_print_comment_filepos (mp, stream, uniforum, page_width);
/* Print flag information in special comment. */
- message_print_comment_flags (mp, fp, debug);
+ message_print_comment_flags (mp, stream, debug);
/* Print the previous msgid. This helps the translator when the msgid has
only slightly changed. */
if (mp->prev_msgctxt != NULL)
- wrap (mp, fp, "#| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap,
+ wrap (mp, stream, "#| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap,
page_width, charset);
if (mp->prev_msgid != NULL)
- wrap (mp, fp, "#| ", 0, "msgid", mp->prev_msgid, mp->do_wrap, page_width,
- charset);
- if (mp->prev_msgid_plural != NULL)
- wrap (mp, fp, "#| ", 0, "msgid_plural", mp->prev_msgid_plural, mp->do_wrap,
+ wrap (mp, stream, "#| ", 0, "msgid", mp->prev_msgid, mp->do_wrap,
page_width, charset);
+ if (mp->prev_msgid_plural != NULL)
+ wrap (mp, stream, "#| ", 0, "msgid_plural", mp->prev_msgid_plural,
+ mp->do_wrap, page_width, charset);
extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
|| mp->prev_msgid_plural != NULL
? 3
free (warning_message);
}
if (mp->msgctxt != NULL)
- wrap (mp, fp, NULL, extra_indent, "msgctxt", mp->msgctxt, mp->do_wrap,
- page_width, charset);
- wrap (mp, fp, NULL, extra_indent, "msgid", mp->msgid, mp->do_wrap,
+ wrap (mp, stream, NULL, extra_indent, "msgctxt", mp->msgctxt, mp->do_wrap,
page_width, charset);
+ wrap (mp, stream, NULL, extra_indent, "msgid", mp->msgid, mp->do_wrap,
+ page_width, charset);
if (mp->msgid_plural != NULL)
- wrap (mp, fp, NULL, extra_indent, "msgid_plural", mp->msgid_plural,
+ wrap (mp, stream, NULL, extra_indent, "msgid_plural", mp->msgid_plural,
mp->do_wrap, page_width, charset);
if (mp->msgid_plural == NULL)
- wrap (mp, fp, NULL, extra_indent, "msgstr", mp->msgstr, mp->do_wrap,
+ wrap (mp, stream, NULL, extra_indent, "msgstr", mp->msgstr, mp->do_wrap,
page_width, charset);
else
{
p += strlen (p) + 1, i++)
{
sprintf (prefix_buf, "msgstr[%u]", i);
- wrap (mp, fp, NULL, extra_indent, prefix_buf, p, mp->do_wrap,
+ wrap (mp, stream, NULL, extra_indent, prefix_buf, p, mp->do_wrap,
page_width, charset);
}
}
static void
-message_print_obsolete (const message_ty *mp, FILE *fp, const char *charset,
- size_t page_width, bool blank_line)
+message_print_obsolete (const message_ty *mp, ostream_t stream,
+ const char *charset, size_t page_width, bool blank_line)
{
int extra_indent;
/* 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)
- print_blank_line (fp);
+ print_blank_line (stream);
/* Print translator comment if available. */
- message_print_comment (mp, fp);
+ message_print_comment (mp, stream);
/* Print xgettext extracted comments (normally empty). */
- message_print_comment_dot (mp, fp);
+ message_print_comment_dot (mp, stream);
/* Print the file position comments (normally empty). */
- message_print_comment_filepos (mp, fp, uniforum, page_width);
+ message_print_comment_filepos (mp, stream, uniforum, page_width);
/* Print flag information in special comment. */
if (mp->is_fuzzy)
{
bool first = true;
- putc ('#', fp);
- putc (',', fp);
+ ostream_write_str (stream, "#,");
if (mp->is_fuzzy)
{
- fputs (" fuzzy", fp);
+ ostream_write_str (stream, " fuzzy");
first = false;
}
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
/* Print the previous msgid. This helps the translator when the msgid has
only slightly changed. */
if (mp->prev_msgctxt != NULL)
- wrap (mp, fp, "#~| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap,
+ wrap (mp, stream, "#~| ", 0, "msgctxt", mp->prev_msgctxt, mp->do_wrap,
page_width, charset);
if (mp->prev_msgid != NULL)
- wrap (mp, fp, "#~| ", 0, "msgid", mp->prev_msgid, mp->do_wrap, page_width,
- charset);
- if (mp->prev_msgid_plural != NULL)
- wrap (mp, fp, "#~| ", 0, "msgid_plural", mp->prev_msgid_plural, mp->do_wrap,
+ wrap (mp, stream, "#~| ", 0, "msgid", mp->prev_msgid, mp->do_wrap,
page_width, charset);
+ if (mp->prev_msgid_plural != NULL)
+ wrap (mp, stream, "#~| ", 0, "msgid_plural", mp->prev_msgid_plural,
+ mp->do_wrap, page_width, charset);
extra_indent = (mp->prev_msgctxt != NULL || mp->prev_msgid != NULL
|| mp->prev_msgid_plural != NULL
? 1
free (warning_message);
}
if (mp->msgctxt != NULL)
- wrap (mp, fp, "#~ ", extra_indent, "msgctxt", mp->msgctxt, mp->do_wrap,
+ wrap (mp, stream, "#~ ", extra_indent, "msgctxt", mp->msgctxt, mp->do_wrap,
page_width, charset);
- wrap (mp, fp, "#~ ", extra_indent, "msgid", mp->msgid, mp->do_wrap,
+ wrap (mp, stream, "#~ ", extra_indent, "msgid", mp->msgid, mp->do_wrap,
page_width, charset);
if (mp->msgid_plural != NULL)
- wrap (mp, fp, "#~ ", extra_indent, "msgid_plural", mp->msgid_plural,
+ wrap (mp, stream, "#~ ", extra_indent, "msgid_plural", mp->msgid_plural,
mp->do_wrap, page_width, charset);
if (mp->msgid_plural == NULL)
- wrap (mp, fp, "#~ ", extra_indent, "msgstr", mp->msgstr, mp->do_wrap,
+ wrap (mp, stream, "#~ ", extra_indent, "msgstr", mp->msgstr, mp->do_wrap,
page_width, charset);
else
{
p += strlen (p) + 1, i++)
{
sprintf (prefix_buf, "msgstr[%u]", i);
- wrap (mp, fp, "#~ ", extra_indent, prefix_buf, p, mp->do_wrap,
+ wrap (mp, stream, "#~ ", extra_indent, prefix_buf, p, mp->do_wrap,
page_width, charset);
}
}
static void
-msgdomain_list_print_po (msgdomain_list_ty *mdlp, FILE *fp, size_t page_width,
- bool debug)
+msgdomain_list_print_po (msgdomain_list_ty *mdlp, ostream_t stream,
+ size_t page_width, bool debug)
{
size_t j, k;
bool blank_line;
&& strcmp (mdlp->item[k]->domain, MESSAGE_DOMAIN_DEFAULT) == 0))
{
if (blank_line)
- print_blank_line (fp);
- fprintf (fp, "domain \"%s\"\n", mdlp->item[k]->domain);
+ print_blank_line (stream);
+ ostream_write_str (stream, "domain \"");
+ ostream_write_str (stream, mdlp->item[k]->domain);
+ ostream_write_str (stream, "\"\n");
blank_line = true;
}
for (j = 0; j < mlp->nitems; ++j)
if (!mlp->item[j]->obsolete)
{
- message_print (mlp->item[j], fp, charset, page_width, blank_line,
- debug);
+ message_print (mlp->item[j], stream, charset, page_width,
+ blank_line, debug);
blank_line = true;
}
for (j = 0; j < mlp->nitems; ++j)
if (mlp->item[j]->obsolete)
{
- message_print_obsolete (mlp->item[j], fp, charset, page_width,
+ message_print_obsolete (mlp->item[j], stream, charset, page_width,
blank_line);
blank_line = true;
}
#include "msgl-iconv.h"
#include "po-charset.h"
#include "utf8-ucs4.h"
+#include "ostream.h"
#include "write-po.h"
#include "xalloc.h"
return result;
}
-/* Writes a key or value to the file, without newline. */
+/* Writes a key or value to the stream, without newline. */
static void
-write_escaped_string (FILE *fp, const char *str, bool in_key)
+write_escaped_string (ostream_t stream, const char *str, bool in_key)
{
static const char hexdigit[] = "0123456789abcdef";
const char *str_limit = str + strlen (str);
str += u8_mbtouc (&uc, (const unsigned char *) str, str_limit - str);
/* Whitespace must be escaped. */
if (uc == 0x0020 && (first || in_key))
- {
- putc ('\\', fp);
- putc (' ', fp);
- }
+ ostream_write_str (stream, "\\ ");
else if (uc == 0x0009)
- {
- putc ('\\', fp);
- putc ('t', fp);
- }
+ ostream_write_str (stream, "\\t");
else if (uc == 0x000a)
- {
- putc ('\\', fp);
- putc ('n', fp);
- }
+ ostream_write_str (stream, "\\n");
else if (uc == 0x000d)
- {
- putc ('\\', fp);
- putc ('r', fp);
- }
+ ostream_write_str (stream, "\\r");
else if (uc == 0x000c)
- {
- putc ('\\', fp);
- putc ('f', fp);
- }
+ ostream_write_str (stream, "\\f");
else if (/* Backslash must be escaped. */
uc == '\\'
/* Possible comment introducers must be escaped. */
/* Key terminators must be escaped. */
|| uc == '=' || uc == ':')
{
- putc ('\\', fp);
- putc (uc, fp);
+ char seq[2];
+ seq[0] = '\\';
+ seq[1] = uc;
+ ostream_write_mem (stream, seq, 2);
}
else if (uc >= 0x0020 && uc <= 0x007e)
{
We could treat non-ASCII ISO-8859-1 characters (0x0080..0x00FF)
the same way, but there is no point in doing this; Sun's
nativetoascii doesn't do it either. */
- putc (uc, fp);
+ char seq[1];
+ seq[0] = uc;
+ ostream_write_mem (stream, seq, 1);
}
else if (uc < 0x10000)
{
/* Single UCS-2 'char' */
- fprintf (fp, "\\u%c%c%c%c",
- hexdigit[(uc >> 12) & 0x0f], hexdigit[(uc >> 8) & 0x0f],
- hexdigit[(uc >> 4) & 0x0f], hexdigit[uc & 0x0f]);
+ char seq[6];
+ seq[0] = '\\';
+ seq[1] = 'u';
+ seq[2] = hexdigit[(uc >> 12) & 0x0f];
+ seq[3] = hexdigit[(uc >> 8) & 0x0f];
+ seq[4] = hexdigit[(uc >> 4) & 0x0f];
+ seq[5] = hexdigit[uc & 0x0f];
+ ostream_write_mem (stream, seq, 6);
}
else
{
/* UTF-16 surrogate: two 'char's. */
unsigned int uc1 = 0xd800 + ((uc - 0x10000) >> 10);
unsigned int uc2 = 0xdc00 + ((uc - 0x10000) & 0x3ff);
- fprintf (fp, "\\u%c%c%c%c",
- hexdigit[(uc1 >> 12) & 0x0f], hexdigit[(uc1 >> 8) & 0x0f],
- hexdigit[(uc1 >> 4) & 0x0f], hexdigit[uc1 & 0x0f]);
- fprintf (fp, "\\u%c%c%c%c",
- hexdigit[(uc2 >> 12) & 0x0f], hexdigit[(uc2 >> 8) & 0x0f],
- hexdigit[(uc2 >> 4) & 0x0f], hexdigit[uc2 & 0x0f]);
+ char seq[6];
+ seq[0] = '\\';
+ seq[1] = 'u';
+ seq[2] = hexdigit[(uc1 >> 12) & 0x0f];
+ seq[3] = hexdigit[(uc1 >> 8) & 0x0f];
+ seq[4] = hexdigit[(uc1 >> 4) & 0x0f];
+ seq[5] = hexdigit[uc1 & 0x0f];
+ ostream_write_mem (stream, seq, 6);
+ seq[0] = '\\';
+ seq[1] = 'u';
+ seq[2] = hexdigit[(uc2 >> 12) & 0x0f];
+ seq[3] = hexdigit[(uc2 >> 8) & 0x0f];
+ seq[4] = hexdigit[(uc2 >> 4) & 0x0f];
+ seq[5] = hexdigit[uc2 & 0x0f];
+ ostream_write_mem (stream, seq, 6);
}
first = false;
}
}
-/* Writes a message to the file. */
+/* Writes a message to the stream. */
static void
-write_message (FILE *fp, const message_ty *mp, size_t page_width, bool debug)
+write_message (ostream_t stream, const message_ty *mp,
+ size_t page_width, bool debug)
{
/* Print translator comment if available. */
- message_print_comment (mp, fp);
+ message_print_comment (mp, stream);
/* Print xgettext extracted comments. */
- message_print_comment_dot (mp, fp);
+ message_print_comment_dot (mp, stream);
/* Print the file position comments. */
- message_print_comment_filepos (mp, fp, false, page_width);
+ message_print_comment_filepos (mp, stream, false, page_width);
/* Print flag information in special comment. */
- message_print_comment_flags (mp, fp, debug);
+ message_print_comment_flags (mp, stream, debug);
/* Put a comment mark if the message is the header or untranslated or
fuzzy. */
if (is_header (mp)
|| mp->msgstr[0] == '\0'
|| (mp->is_fuzzy && !is_header (mp)))
- putc ('!', fp);
+ ostream_write_str (stream, "!");
/* Now write the untranslated string and the translated string. */
- write_escaped_string (fp, mp->msgid, true);
- putc ('=', fp);
- write_escaped_string (fp, mp->msgstr, false);
+ write_escaped_string (stream, mp->msgid, true);
+ ostream_write_str (stream, "=");
+ write_escaped_string (stream, mp->msgstr, false);
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
-/* Writes an entire message list to the file. */
+/* Writes an entire message list to the stream. */
static void
-write_properties (FILE *fp, message_list_ty *mlp, const char *canon_encoding,
- size_t page_width, bool debug)
+write_properties (ostream_t stream, message_list_ty *mlp,
+ const char *canon_encoding, size_t page_width, bool debug)
{
bool blank_line;
size_t j, i;
if (mp->msgid_plural == NULL && !mp->obsolete)
{
if (blank_line)
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
- write_message (fp, mp, page_width, debug);
+ write_message (stream, mp, page_width, debug);
blank_line = true;
}
/* Output the contents of a PO file in Java .properties syntax. */
static void
-msgdomain_list_print_properties (msgdomain_list_ty *mdlp, FILE *fp,
+msgdomain_list_print_properties (msgdomain_list_ty *mdlp, ostream_t stream,
size_t page_width, bool debug)
{
message_list_ty *mlp;
mlp = mdlp->item[0]->messages;
else
mlp = message_list_alloc (false);
- write_properties (fp, mlp, mdlp->encoding, page_width, debug);
+ write_properties (stream, mlp, mdlp->encoding, page_width, debug);
}
/* Describes a PO file in Java .properties syntax. */
#include "write-stringtable.h"
#include <stdbool.h>
-#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "msgl-iconv.h"
#include "po-charset.h"
#include "c-strstr.h"
+#include "ostream.h"
+#include "xvasprintf.h"
#include "write-po.h"
/* The format of NeXTstep/GNUstep .strings files is documented in
UTF-16 instead of UCS-2, we use UTF-8 with BOM. BOMs are bad because they
get in the way when concatenating files, but here we have no choice. */
-/* Writes a key or value to the file, without newline. */
+/* Writes a key or value to the stream, without newline. */
static void
-write_escaped_string (FILE *fp, const char *str)
+write_escaped_string (ostream_t stream, const char *str)
{
const char *str_limit = str + strlen (str);
- putc ('"', fp);
+ ostream_write_str (stream, "\"");
while (str < str_limit)
{
unsigned char c = (unsigned char) *str++;
if (c == '\t')
- {
- putc ('\\', fp);
- putc ('t', fp);
- }
+ ostream_write_str (stream, "\\t");
else if (c == '\n')
- {
- putc ('\\', fp);
- putc ('n', fp);
- }
+ ostream_write_str (stream, "\\n");
else if (c == '\r')
- {
- putc ('\\', fp);
- putc ('r', fp);
- }
+ ostream_write_str (stream, "\\r");
else if (c == '\f')
- {
- putc ('\\', fp);
- putc ('f', fp);
- }
+ ostream_write_str (stream, "\\f");
else if (c == '\\' || c == '"')
{
- putc ('\\', fp);
- putc (c, fp);
+ char seq[2];
+ seq[0] = '\\';
+ seq[1] = c;
+ ostream_write_mem (stream, seq, 2);
}
else
- putc (c, fp);
+ {
+ char seq[1];
+ seq[0] = c;
+ ostream_write_mem (stream, seq, 1);
+ }
}
- putc ('"', fp);
+ ostream_write_str (stream, "\"");
}
-/* Writes a message to the file. */
+/* Writes a message to the stream. */
static void
-write_message (FILE *fp, const message_ty *mp, size_t page_width, bool debug)
+write_message (ostream_t stream, const message_ty *mp,
+ size_t page_width, bool debug)
{
/* Print translator comment if available. */
if (mp->comment != NULL)
whether we need C++ style for it. */
if (c_strstr (s, "*/") == NULL)
{
- fputs ("/*", fp);
+ ostream_write_str (stream, "/*");
if (*s != '\0' && *s != '\n' && *s != ' ')
- putc (' ', fp);
- fputs (s, fp);
- fputs (" */\n", fp);
+ ostream_write_str (stream, " ");
+ ostream_write_str (stream, s);
+ ostream_write_str (stream, " */\n");
}
else
do
{
const char *e;
- fputs ("//", fp);
+ ostream_write_str (stream, "//");
if (*s != '\0' && *s != '\n' && *s != ' ')
- putc (' ', fp);
+ ostream_write_str (stream, " ");
e = strchr (s, '\n');
if (e == NULL)
{
- fputs (s, fp);
+ ostream_write_str (stream, s);
s = NULL;
}
else
{
- fwrite (s, 1, e - s, fp);
+ ostream_write_mem (stream, s, e - s);
s = e + 1;
}
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
while (s != NULL);
}
whether we need C++ style for it. */
if (c_strstr (s, "*/") == NULL)
{
- fputs ("/* Comment: ", fp);
- fputs (s, fp);
- fputs (" */\n", fp);
+ ostream_write_str (stream, "/* Comment: ");
+ ostream_write_str (stream, s);
+ ostream_write_str (stream, " */\n");
}
else
{
do
{
const char *e;
- fputs ("//", fp);
+ ostream_write_str (stream, "//");
if (first || (*s != '\0' && *s != '\n' && *s != ' '))
- putc (' ', fp);
+ ostream_write_str (stream, " ");
if (first)
- fputs ("Comment: ", fp);
+ ostream_write_str (stream, "Comment: ");
e = strchr (s, '\n');
if (e == NULL)
{
- fputs (s, fp);
+ ostream_write_str (stream, s);
s = NULL;
}
else
{
- fwrite (s, 1, e - s, fp);
+ ostream_write_mem (stream, s, e - s);
s = e + 1;
}
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
first = false;
}
while (s != NULL);
{
lex_pos_ty *pp = &mp->filepos[j];
char *cp = pp->file_name;
+ char *str;
+
while (cp[0] == '.' && cp[1] == '/')
cp += 2;
- fprintf (fp, "/* File: %s:%ld */\n", cp, (long) pp->line_number);
+ str = xasprintf ("/* File: %s:%ld */\n", cp, (long) pp->line_number);
+ ostream_write_str (stream, str);
+ free (str);
}
}
/* Print flag information in special comment. */
if (mp->is_fuzzy || mp->msgstr[0] == '\0')
- fputs ("/* Flag: untranslated */\n", fp);
+ ostream_write_str (stream, "/* Flag: untranslated */\n");
if (mp->obsolete)
- fputs ("/* Flag: unmatched */\n", fp);
+ ostream_write_str (stream, "/* Flag: unmatched */\n");
{
size_t i;
for (i = 0; i < NFORMATS; i++)
if (significant_format_p (mp->is_format[i]))
{
- fputs ("/* Flag:", fp);
- fputs (make_format_description_string (mp->is_format[i],
- format_language[i], debug),
- fp);
- fputs (" */\n", fp);
+ ostream_write_str (stream, "/* Flag:");
+ ostream_write_str (stream,
+ make_format_description_string (mp->is_format[i],
+ format_language[i],
+ debug));
+ ostream_write_str (stream, " */\n");
}
}
/* Now write the untranslated string and the translated string. */
- write_escaped_string (fp, mp->msgid);
- fputs (" = ", fp);
+ write_escaped_string (stream, mp->msgid);
+ ostream_write_str (stream, " = ");
if (mp->msgstr[0] != '\0')
{
if (mp->is_fuzzy)
{
/* Output the msgid as value, so that at runtime the untranslated
string is returned. */
- write_escaped_string (fp, mp->msgid);
+ write_escaped_string (stream, mp->msgid);
/* Output the msgstr as a comment, so that at runtime
propertyListFromStringsFileFormat ignores it. */
if (c_strstr (mp->msgstr, "*/") == NULL)
{
- fputs (" /* = ", fp);
- write_escaped_string (fp, mp->msgstr);
- fputs (" */", fp);
+ ostream_write_str (stream, " /* = ");
+ write_escaped_string (stream, mp->msgstr);
+ ostream_write_str (stream, " */");
}
else
{
- fputs ("; // = ", fp);
- write_escaped_string (fp, mp->msgstr);
+ ostream_write_str (stream, "; // = ");
+ write_escaped_string (stream, mp->msgstr);
}
}
else
- write_escaped_string (fp, mp->msgstr);
+ write_escaped_string (stream, mp->msgstr);
}
else
{
/* Output the msgid as value, so that at runtime the untranslated
string is returned. */
- write_escaped_string (fp, mp->msgid);
+ write_escaped_string (stream, mp->msgid);
}
- putc (';', fp);
+ ostream_write_str (stream, ";");
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
}
-/* Writes an entire message list to the file. */
+/* Writes an entire message list to the stream. */
static void
-write_stringtable (FILE *fp, message_list_ty *mlp, const char *canon_encoding,
- size_t page_width, bool debug)
+write_stringtable (ostream_t stream, message_list_ty *mlp,
+ const char *canon_encoding, size_t page_width, bool debug)
{
bool blank_line;
size_t j;
/* Output the BOM. */
if (!is_ascii_message_list (mlp))
- fputs ("\xef\xbb\xbf", fp);
+ ostream_write_str (stream, "\xef\xbb\xbf");
/* Loop through the messages. */
blank_line = false;
if (mp->msgid_plural == NULL)
{
if (blank_line)
- putc ('\n', fp);
+ ostream_write_str (stream, "\n");
- write_message (fp, mp, page_width, debug);
+ write_message (stream, mp, page_width, debug);
blank_line = true;
}
/* Output the contents of a PO file in .strings syntax. */
static void
-msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, FILE *fp,
+msgdomain_list_print_stringtable (msgdomain_list_ty *mdlp, ostream_t stream,
size_t page_width, bool debug)
{
message_list_ty *mlp;
mlp = mdlp->item[0]->messages;
else
mlp = message_list_alloc (false);
- write_stringtable (fp, mlp, mdlp->encoding, page_width, debug);
+ write_stringtable (stream, mlp, mdlp->encoding, page_width, debug);
}
/* Describes a PO file in .strings syntax. */