* gettext-tools/src/po-gram.h (struct po_parser_state): New type.
(po_gram_parse): Add 'struct po_parser_state *ps' parameter.
* gettext-tools/src/po-gram-gen.y: Add %parse-param declaration.
Access ps->plural_counter instead of plural_counter.
(plural_counter): Remove variable.
* gettext-tools/src/po-lex.h (po_gram_error): Add 'struct po_parser_state *ps'
parameter.
* gettext-tools/src/po-lex.c: Include po-gram.h.
(po_gram_error): Add 'struct po_parser_state *ps' parameter.
(mbfile_getc, control_sequence): Update po_gram_error calls.
* gettext-tools/src/read-po.c (po_parse): Pass a 'struct po_parser_state *' to
po_gram_parse.
#define _(str) gettext (str)
-static long plural_counter;
-
#define check_obsolete(value1,value2) \
if ((value1).obsolete != (value2).obsolete) \
po_gram_error_at_line (&(value2).pos, _("inconsistent use of #~"));
generated parsers in the same program. */
%define api.prefix {po_gram_}
+%parse-param {struct po_parser_state *ps}
+
%token COMMENT
%token DOMAIN
%token JUNK
: MSGID_PLURAL string_list
{
check_obsolete ($1, $2);
- plural_counter = 0;
+ ps->plural_counter = 0;
$$.string = string_list_concat_destroy (&$2.stringlist);
$$.pos = $1.pos;
$$.obsolete = $1.obsolete;
check_obsolete ($1, $3);
check_obsolete ($1, $4);
check_obsolete ($1, $5);
- if ($3.number != plural_counter)
+ if ($3.number != ps->plural_counter)
{
- if (plural_counter == 0)
+ if (ps->plural_counter == 0)
po_gram_error_at_line (&$1.pos, _("first plural form has nonzero index"));
else
po_gram_error_at_line (&$1.pos, _("plural form has wrong index"));
}
- plural_counter++;
+ ps->plural_counter++;
$$.rhs.msgstr = string_list_concat_destroy (&$5.stringlist);
$$.rhs.msgstr_len = strlen ($$.rhs.msgstr) + 1;
$$.pos = $1.pos;
/* GNU gettext - internationalization aids
- Copyright (C) 1995, 2002-2003, 2006 Free Software Foundation, Inc.
+ Copyright (C) 1995-2023 Free Software Foundation, Inc.
This file was written by Peter Miller <millerp@canb.auug.org.au>
extern "C" {
#endif
-extern int po_gram_parse (void);
+/* Input, output, and local variables of a PO parser instance. */
+struct po_parser_state
+{
+ /* Input variables. */
+ /* Output variables. */
+ /* Local variables. */
+ long plural_counter;
+};
+
+extern int po_gram_parse (struct po_parser_state *ps);
#ifdef __cplusplus
}
#include "pos.h"
#include "message.h"
#include "str-list.h"
+#include "po-gram.h"
#include "po-gram-gen.h"
#define _(str) gettext(str)
/* VARARGS1 */
void
-po_gram_error (const char *fmt, ...)
+po_gram_error (struct po_parser_state *ps, const char *fmt, ...)
{
va_list ap;
char *buffer;
/* An invalid multibyte sequence was encountered. */
/* Return a single byte. */
if (signal_eilseq)
- po_gram_error (_("invalid multibyte sequence"));
+ po_gram_error (NULL, _("invalid multibyte sequence"));
bytes = 1;
mbc->uc_valid = false;
break;
if (ferror (mbf->fp))
goto eof;
if (signal_eilseq)
- po_gram_error (_("incomplete multibyte sequence at end of file"));
+ po_gram_error (NULL, _("incomplete multibyte sequence at end of file"));
bytes = mbf->bufcount;
mbc->uc_valid = false;
break;
if (c == '\n')
{
if (signal_eilseq)
- po_gram_error (_("incomplete multibyte sequence at end of line"));
+ po_gram_error (NULL, _("incomplete multibyte sequence at end of line"));
bytes = mbf->bufcount - 1;
mbc->uc_valid = false;
break;
/* scratchbuf contains an out-of-range Unicode character
(> 0x10ffff). */
if (signal_eilseq)
- po_gram_error (_("invalid multibyte sequence"));
+ po_gram_error (NULL, _("invalid multibyte sequence"));
mbc->uc_valid = false;
break;
}
/* FIXME: \u and \U are not handled. */
}
lex_ungetc (mbc);
- po_gram_error (_("invalid control sequence"));
+ po_gram_error (NULL, _("invalid control sequence"));
return ' ';
}
Switch this on or off. */
extern void po_lex_pass_obsolete_entries (bool flag);
-extern void po_gram_error (const char *fmt, ...)
- __attribute__ ((__format__ (__printf__, 1, 2)));
+struct po_parser_state;
+extern void po_gram_error (struct po_parser_state *ps, const char *fmt, ...)
+ __attribute__ ((__format__ (__printf__, 2, 3)));
extern void po_gram_error_at_line (const lex_pos_ty *pos, const char *fmt, ...)
__attribute__ ((__format__ (__printf__, 2, 3)));
const char *real_filename, const char *logical_filename,
bool is_pot_role)
{
+ struct po_parser_state ps;
lex_start (fp, real_filename, logical_filename, is_pot_role);
- po_gram_parse ();
+ po_gram_parse (&ps);
lex_end ();
}