if (msgctxt == NULL && msgid[0] == '\0' && !obsolete)
po_lex_charset_set (msgstr, gram_pos.file_name, ps->gram_pot_role);
- po_callback_message (msgctxt,
+ po_callback_message (ps->catr,
+ msgctxt,
msgid, msgid_pos, msgid_plural,
msgstr, msgstr_len, msgstr_pos,
prev_msgctxt, prev_msgid, prev_msgid_plural,
comment
: COMMENT
{
- po_callback_comment_dispatcher ($1.string);
+ po_callback_comment_dispatcher (ps->catr, $1.string);
}
;
domain
: DOMAIN STRING
{
- po_callback_domain ($2.string);
+ po_callback_domain (ps->catr, $2.string);
}
;
/* GNU gettext - internationalization aids
- Copyright (C) 1995-2023 Free Software Foundation, Inc.
+ Copyright (C) 1995-2024 Free Software Foundation, Inc.
This file was written by Peter Miller <millerp@canb.auug.org.au>
# include "unistr.h"
#endif
+#include "read-catalog-abstract.h"
+
#ifdef __cplusplus
extern "C" {
#endif
{
/* ----- Input variables ----- */
+ /* The catalog reader that implements the callbacks. */
+ struct abstract_catalog_reader_ty *catr;
+
/* Whether the PO file is in the role of a POT file. */
bool gram_pot_role;
#include "po-xerror.h"
#include "gettext.h"
-/* Local variables. */
-static abstract_catalog_reader_ty *callback_arg;
-
/* ========================================================================= */
/* Allocating and freeing instances of abstract_catalog_reader_ty. */
/* Exported functions. */
-static inline void
-parse_start (abstract_catalog_reader_ty *catr)
-{
- /* The parse will call the po_callback_... functions (see below)
- when the various directive are recognised. The callback_arg
- variable is used to tell these functions which instance is to
- have the relevant method invoked. */
- callback_arg = catr;
-
- call_parse_brief (catr);
-}
-
-static inline void
-parse_end (abstract_catalog_reader_ty *catr)
-{
- call_parse_debrief (catr);
- callback_arg = NULL;
-}
-
-
void
catalog_reader_parse (abstract_catalog_reader_ty *catr, FILE *fp,
const char *real_filename, const char *logical_filename,
error_message_count = 0;
/* Parse the stream's content. */
- parse_start (catr);
+ call_parse_brief (catr);
input_syntax->parse (catr, fp, real_filename, logical_filename, is_pot_role);
- parse_end (catr);
+ call_parse_debrief (catr);
if (error_message_count > 0)
po_xerror (PO_SEVERITY_FATAL_ERROR, NULL,
/* This function is called by po_gram_lex() whenever a domain directive
has been seen. */
void
-po_callback_domain (char *name)
+po_callback_domain (abstract_catalog_reader_ty *catr, char *name)
{
- /* assert(callback_arg); */
- call_directive_domain (callback_arg, name);
+ call_directive_domain (catr, name);
}
/* This function is called by po_gram_lex() whenever a message has been
seen. */
void
-po_callback_message (char *msgctxt,
+po_callback_message (abstract_catalog_reader_ty *catr,
+ char *msgctxt,
char *msgid, lex_pos_ty *msgid_pos, char *msgid_plural,
char *msgstr, size_t msgstr_len, lex_pos_ty *msgstr_pos,
char *prev_msgctxt,
char *prev_msgid_plural,
bool force_fuzzy, bool obsolete)
{
- /* assert(callback_arg); */
- call_directive_message (callback_arg, msgctxt,
+ call_directive_message (catr, msgctxt,
msgid, msgid_pos, msgid_plural,
msgstr, msgstr_len, msgstr_pos,
prev_msgctxt, prev_msgid, prev_msgid_plural,
void
-po_callback_comment (const char *s)
+po_callback_comment (abstract_catalog_reader_ty *catr, const char *s)
{
- /* assert(callback_arg); */
- call_comment (callback_arg, s);
+ call_comment (catr, s);
}
void
-po_callback_comment_dot (const char *s)
+po_callback_comment_dot (abstract_catalog_reader_ty *catr, const char *s)
{
- /* assert(callback_arg); */
- call_comment_dot (callback_arg, s);
+ call_comment_dot (catr, s);
}
/* This function is called by po_parse_comment_filepos(), once for each
file name. */
void
-po_callback_comment_filepos (const char *file_name, size_t line_number)
+po_callback_comment_filepos (abstract_catalog_reader_ty *catr,
+ const char *file_name, size_t line_number)
{
- /* assert(callback_arg); */
- call_comment_filepos (callback_arg, file_name, line_number);
+ call_comment_filepos (catr, file_name, line_number);
}
void
-po_callback_comment_special (const char *s)
+po_callback_comment_special (abstract_catalog_reader_ty *catr, const char *s)
{
- /* assert(callback_arg); */
- call_comment_special (callback_arg, s);
+ call_comment_special (catr, s);
}
U+2068 FILENAME U+2069.
Call po_callback_comment_filepos for each of them. */
static void
-po_parse_comment_filepos (const char *s)
+po_parse_comment_filepos (abstract_catalog_reader_ty *catr, const char *s)
{
while (*s != '\0')
{
memcpy (filename, filename_start, filename_length);
filename[filename_length] = '\0';
- po_callback_comment_filepos (filename, n);
+ po_callback_comment_filepos (catr, filename, n);
free (filename);
memcpy (filename, filename_start, filename_length);
filename[filename_length] = '\0';
- po_callback_comment_filepos (filename, n);
+ po_callback_comment_filepos (catr, filename, n);
free (filename);
memcpy (filename, filename_start, filename_length);
filename[filename_length] = '\0';
- po_callback_comment_filepos (filename, n);
+ po_callback_comment_filepos (catr, filename, n);
free (filename);
memcpy (filename, filename_start, filename_length);
filename[filename_length] = '\0';
- po_callback_comment_filepos (filename, (size_t)(-1));
+ po_callback_comment_filepos (catr, filename, (size_t)(-1));
free (filename);
}
NUMBER ::= [0-9]+
Return true if parsed, false if not a comment of this form. */
static bool
-po_parse_comment_solaris_filepos (const char *s)
+po_parse_comment_solaris_filepos (abstract_catalog_reader_ty *catr,
+ const char *s)
{
if (s[0] == ' '
&& (s[1] == 'F' || s[1] == 'f')
memcpy (string, string_start, string_length);
string[string_length] = '\0';
- po_callback_comment_filepos (string, n);
+ po_callback_comment_filepos (catr, string, n);
free (string);
return true;
call_comment_filepos (via po_parse_comment_filepos), or
call_comment_special. */
void
-po_callback_comment_dispatcher (const char *s)
+po_callback_comment_dispatcher (abstract_catalog_reader_ty *catr, const char *s)
{
if (*s == '.')
{
consider it part of the comment, therefore remove it here. */
if (*s == ' ')
s++;
- po_callback_comment_dot (s);
+ po_callback_comment_dot (catr, s);
}
else if (*s == ':')
{
/* Parse the file location string. The appropriate callback will be
invoked. */
- po_parse_comment_filepos (s + 1);
+ po_parse_comment_filepos (catr, s + 1);
}
else if (*s == ',' || *s == '!')
{
/* Get all entries in the special comment line. */
- po_callback_comment_special (s + 1);
+ po_callback_comment_special (catr, s + 1);
}
else
{
/* It looks like a plain vanilla comment, but Solaris-style file
position lines do, too. Try to parse the lot. If the parse
succeeds, the appropriate callback will be invoked. */
- if (po_parse_comment_solaris_filepos (s))
+ if (po_parse_comment_solaris_filepos (catr, s))
/* Do nothing, it is a Sun-style file pos line. */ ;
else
{
consider it part of the comment, therefore remove it here. */
if (*s == ' ')
s++;
- po_callback_comment (s);
+ po_callback_comment (catr, s);
}
}
}
/* Callbacks used by po-gram.y or po-lex.c, indirectly from
catalog_reader_parse. */
-extern void po_callback_domain (char *name);
-extern void po_callback_message (char *msgctxt,
+extern void po_callback_domain (abstract_catalog_reader_ty *catr, char *name);
+extern void po_callback_message (abstract_catalog_reader_ty *catr,
+ char *msgctxt,
char *msgid, lex_pos_ty *msgid_pos,
char *msgid_plural,
char *msgstr, size_t msgstr_len,
char *prev_msgctxt,
char *prev_msgid, char *prev_msgid_plural,
bool force_fuzzy, bool obsolete);
-extern void po_callback_comment (const char *s);
-extern void po_callback_comment_dot (const char *s);
-extern void po_callback_comment_filepos (const char *file_name,
+extern void po_callback_comment (abstract_catalog_reader_ty *catr,
+ const char *s);
+extern void po_callback_comment_dot (abstract_catalog_reader_ty *catr,
+ const char *s);
+extern void po_callback_comment_filepos (abstract_catalog_reader_ty *catr,
+ const char *file_name,
size_t line_number);
-extern void po_callback_comment_special (const char *s);
-extern void po_callback_comment_dispatcher (const char *s);
+extern void po_callback_comment_special (abstract_catalog_reader_ty *catr,
+ const char *s);
+extern void po_callback_comment_dispatcher (abstract_catalog_reader_ty *catr,
+ const char *s);
/* Parse a special comment and put the result in *fuzzyp, formatp, *rangep,
*wrapp. */
bool is_pot_role)
{
struct po_parser_state ps;
+ ps.catr = catr;
ps.gram_pot_role = is_pot_role;
lex_start (&ps, fp, real_filename, logical_filename);
po_gram_parse (&ps);
buffer[buflen] = '\0';
po_callback_comment_dispatcher (
+ catr,
conv_from_java (
assume_utf8 ? buffer : conv_from_iso_8859_1 (buffer)));
}
and if it is not already header/fuzzy/untranslated. */
force_fuzzy = (hidden && msgid[0] != '\0' && msgstr[0] != '\0');
- po_callback_message (NULL, msgid, &msgid_pos, NULL,
+ po_callback_message (catr,
+ NULL, msgid, &msgid_pos, NULL,
msgstr, strlen (msgstr) + 1, &msgstr_pos,
NULL, NULL, NULL,
force_fuzzy, false);
}
static inline void
-special_comment_finish ()
+special_comment_finish (abstract_catalog_reader_ty *catr)
{
if (special_comment != NULL)
{
- po_callback_comment_special (special_comment);
+ po_callback_comment_special (catr, special_comment);
free (special_comment);
special_comment = NULL;
}
}
static void
-comment_line_end (size_t chars_to_remove, bool test_for_fuzzy_msgstr)
+comment_line_end (abstract_catalog_reader_ty *catr,
+ size_t chars_to_remove, bool test_for_fuzzy_msgstr)
{
char *line;
special_comment_add (line + 6);
else if (strlen (line) >= 9 && memcmp (line, "Comment: ", 9) == 0)
/* A comment extracted from the source. */
- po_callback_comment_dot (line + 9);
+ po_callback_comment_dot (catr, line + 9);
else
{
char *last_colon;
{
/* A "File: <filename>:<number>" type comment. */
*last_colon = '\0';
- po_callback_comment_filepos (line + 6, number);
+ po_callback_comment_filepos (catr, line + 6, number);
}
else
- po_callback_comment (line);
+ po_callback_comment (catr, line);
}
}
character. */
static int
-phase4_getc ()
+phase4_getc (abstract_catalog_reader_ty *catr)
{
int c;
{
case '\n':
seen_newline = true;
- comment_line_end (1, false);
+ comment_line_end (catr, 1, false);
comment_start ();
last_was_star = false;
trailing_stars = 0;
if (last_was_star)
{
/* Drop additional stars at the end of the comment. */
- comment_line_end (trailing_stars + 1,
+ comment_line_end (catr, trailing_stars + 1,
expect_fuzzy_msgstr_as_c_comment
&& !seen_newline);
break;
if (!(buflen == 0 && (c == ' ' || c == '\t')))
comment_add (c);
}
- comment_line_end (0, expect_fuzzy_msgstr_as_cxx_comment);
+ comment_line_end (catr, 0, expect_fuzzy_msgstr_as_cxx_comment);
return '\n';
}
}
Return the string in UTF-8 encoding, or NULL if no string is seen.
Return the start position of the string in *pos. */
static char *
-read_string (lex_pos_ty *pos)
+read_string (abstract_catalog_reader_ty *catr, lex_pos_ty *pos)
{
static int *buffer;
static size_t bufmax;
/* Skip whitespace before the string. */
do
- c = phase4_getc ();
+ c = phase4_getc (catr);
while (is_whitespace (c));
if (c == UEOF)
po_xerror (PO_SEVERITY_ERROR, NULL,
real_file_name, gram_pos.line_number, (size_t)(-1), false,
_("warning: syntax error"));
- for (; c != UEOF && !is_quotable (c); c = phase4_getc ())
+ for (; c != UEOF && !is_quotable (c); c = phase4_getc (catr))
{
if (buflen >= bufmax)
{
fuzzy_msgstr = NULL;
/* Read the key and all the comments preceding it. */
- msgid = read_string (&msgid_pos);
+ msgid = read_string (catr, &msgid_pos);
if (msgid == NULL)
break;
- special_comment_finish ();
+ special_comment_finish (catr);
/* Skip whitespace. */
do
- c = phase4_getc ();
+ c = phase4_getc (catr);
while (is_whitespace (c));
/* Expect a '=' or ';'. */
necessarily designate an untranslated entry. */
msgstr = xstrdup ("");
msgstr_pos = msgid_pos;
- po_callback_message (NULL, msgid, &msgid_pos, NULL,
+ po_callback_message (catr,
+ NULL, msgid, &msgid_pos, NULL,
msgstr, strlen (msgstr) + 1, &msgstr_pos,
NULL, NULL, NULL,
false, next_is_obsolete);
else if (c == '=')
{
/* Read the value. */
- msgstr = read_string (&msgstr_pos);
+ msgstr = read_string (catr, &msgstr_pos);
if (msgstr == NULL)
{
po_xerror (PO_SEVERITY_ERROR, NULL,
expect_fuzzy_msgstr_as_c_comment = next_is_fuzzy;
do
{
- c = phase4_getc ();
+ c = phase4_getc (catr);
if (fuzzy_msgstr != NULL)
expect_fuzzy_msgstr_as_c_comment = false;
}
phase3_ungetc (c);
expect_fuzzy_msgstr_as_cxx_comment = true;
- c = phase4_getc ();
+ c = phase4_getc (catr);
phase4_ungetc (c);
expect_fuzzy_msgstr_as_cxx_comment = false;
}
msgstr = fuzzy_msgstr;
/* A key/value pair. */
- po_callback_message (NULL, msgid, &msgid_pos, NULL,
+ po_callback_message (catr,
+ NULL, msgid, &msgid_pos, NULL,
msgstr, strlen (msgstr) + 1, &msgstr_pos,
NULL, NULL, NULL,
false, next_is_obsolete);