1 /* xgettext RST backend.
2 Copyright (C) 2001-2003, 2005-2009 Free Software Foundation, Inc.
4 This file was written by Bruno Haible <haible@clisp.cons.org>, 2001.
6 This program is free software: you can redistribute it and/or modify
7 it under the terms of the GNU General Public License as published by
8 the Free Software Foundation; either version 3 of the License, or
9 (at your option) any later version.
11 This program is distributed in the hope that it will be useful,
12 but WITHOUT ANY WARRANTY; without even the implied warranty of
13 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 GNU General Public License for more details.
16 You should have received a copy of the GNU General Public License
17 along with this program. If not, see <http://www.gnu.org/licenses/>. */
35 #include "error-progname.h"
39 #define _(s) gettext(s)
41 /* RST stands for Resource String Table.
43 An RST file consists of several string definitions. A string definition
44 starts at the beginning of a line and looks like this:
45 ModuleName.ConstName=StringExpression
46 A StringExpression consists of string pieces of the form 'xyz',
47 single characters of the form #nnn (decimal integer), and +
48 at the end of the line to designate continuation on the next line.
49 String definitions can be separated by blank lines or comment lines
52 This backend attempts to be functionally equivalent to the 'rstconv'
53 program, part of the Free Pascal run time library, written by
54 Sebastian Guenther. Except that the locations are output as
55 "ModuleName.ConstName", not "ModuleName:ConstName".
60 const char *real_filename, const char *logical_filename,
61 flag_context_list_table_ty *flag_table,
62 msgdomain_list_ty *mdlp)
66 message_list_ty *mlp = mdlp->item[0]->messages;
82 /* Ignore blank line. */
89 /* Ignore comment line. */
94 while (c != EOF && c != '\n');
101 /* Read ModuleName.ConstName. */
105 if (c == EOF || c == '\n')
107 error_with_progname = false;
108 error (EXIT_FAILURE, 0, _("%s:%d: invalid string definition"),
109 logical_filename, line_number);
110 error_with_progname = true;
112 if (bufpos >= bufmax)
114 bufmax = 2 * bufmax + 10;
115 buffer = xrealloc (buffer, bufmax);
119 buffer[bufpos++] = c;
121 if (c == EOF && ferror (f))
124 buffer[bufpos] = '\0';
125 location = xstrdup (buffer);
127 /* Read StringExpression. */
144 /* Embedded single quotes like 'abc''def' don't occur.
145 See fpc-1.0.4/compiler/cresstr.pas. */
146 if (c == EOF || c == '\n' || c == '\'')
148 if (bufpos >= bufmax)
150 bufmax = 2 * bufmax + 10;
151 buffer = xrealloc (buffer, bufmax);
153 buffer[bufpos++] = c;
167 if (c == EOF && ferror (f))
169 if (c == EOF || !c_isdigit (c))
171 error_with_progname = false;
172 error (EXIT_FAILURE, 0, _("%s:%d: missing number after #"),
173 logical_filename, line_number);
174 error_with_progname = true;
180 if (c == EOF || !c_isdigit (c))
182 n = n * 10 + (c - '0');
184 if (bufpos >= bufmax)
186 bufmax = 2 * bufmax + 10;
187 buffer = xrealloc (buffer, bufmax);
189 buffer[bufpos++] = (unsigned char) n;
206 error_with_progname = false;
207 error (EXIT_FAILURE, 0, _("%s:%d: invalid string expression"),
208 logical_filename, line_number);
209 error_with_progname = true;
212 if (bufpos >= bufmax)
214 bufmax = 2 * bufmax + 10;
215 buffer = xrealloc (buffer, bufmax);
217 buffer[bufpos] = '\0';
218 msgid = xstrdup (buffer);
220 pos.file_name = location;
221 pos.line_number = (size_t)(-1);
223 remember_a_message (mlp, NULL, msgid, null_context, &pos, NULL, NULL);
225 /* Here c is the last read character: EOF or '\n'. */
233 error (EXIT_FAILURE, errno, _("error while reading \"%s\""),