1 /* xgettext RST backend.
2 Copyright (C) 2001-2003, 2005-2009, 2015 Free Software Foundation,
5 This file was written by Bruno Haible <haible@clisp.cons.org>, 2001.
7 This program is free software: you can redistribute it and/or modify
8 it under the terms of the GNU General Public License as published by
9 the Free Software Foundation; either version 3 of the License, or
10 (at your option) any later version.
12 This program is distributed in the hope that it will be useful,
13 but WITHOUT ANY WARRANTY; without even the implied warranty of
14 MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
15 GNU General Public License for more details.
17 You should have received a copy of the GNU General Public License
18 along with this program. If not, see <http://www.gnu.org/licenses/>. */
36 #include "error-progname.h"
40 #define _(s) gettext(s)
42 /* RST stands for Resource String Table.
44 An RST file consists of several string definitions. A string definition
45 starts at the beginning of a line and looks like this:
46 ModuleName.ConstName=StringExpression
47 A StringExpression consists of string pieces of the form 'xyz',
48 single characters of the form #nnn (decimal integer), and +
49 at the end of the line to designate continuation on the next line.
50 String definitions can be separated by blank lines or comment lines
53 This backend attempts to be functionally equivalent to the 'rstconv'
54 program, part of the Free Pascal run time library, written by
55 Sebastian Guenther. Except that the locations are output as
56 "ModuleName.ConstName", not "ModuleName:ConstName".
61 const char *real_filename, const char *logical_filename,
62 flag_context_list_table_ty *flag_table,
63 msgdomain_list_ty *mdlp)
67 message_list_ty *mlp = mdlp->item[0]->messages;
83 /* Ignore blank line. */
90 /* Ignore comment line. */
95 while (c != EOF && c != '\n');
102 /* Read ModuleName.ConstName. */
106 if (c == EOF || c == '\n')
108 error_with_progname = false;
109 error (EXIT_FAILURE, 0, _("%s:%d: invalid string definition"),
110 logical_filename, line_number);
111 error_with_progname = true;
113 if (bufpos >= bufmax)
115 bufmax = 2 * bufmax + 10;
116 buffer = xrealloc (buffer, bufmax);
120 buffer[bufpos++] = c;
122 if (c == EOF && ferror (f))
125 buffer[bufpos] = '\0';
126 location = xstrdup (buffer);
128 /* Read StringExpression. */
145 /* Embedded single quotes like 'abc''def' don't occur.
146 See fpc-1.0.4/compiler/cresstr.pas. */
147 if (c == EOF || c == '\n' || c == '\'')
149 if (bufpos >= bufmax)
151 bufmax = 2 * bufmax + 10;
152 buffer = xrealloc (buffer, bufmax);
154 buffer[bufpos++] = c;
168 if (c == EOF && ferror (f))
170 if (c == EOF || !c_isdigit (c))
172 error_with_progname = false;
173 error (EXIT_FAILURE, 0, _("%s:%d: missing number after #"),
174 logical_filename, line_number);
175 error_with_progname = true;
181 if (c == EOF || !c_isdigit (c))
183 n = n * 10 + (c - '0');
185 if (bufpos >= bufmax)
187 bufmax = 2 * bufmax + 10;
188 buffer = xrealloc (buffer, bufmax);
190 buffer[bufpos++] = (unsigned char) n;
207 error_with_progname = false;
208 error (EXIT_FAILURE, 0, _("%s:%d: invalid string expression"),
209 logical_filename, line_number);
210 error_with_progname = true;
213 if (bufpos >= bufmax)
215 bufmax = 2 * bufmax + 10;
216 buffer = xrealloc (buffer, bufmax);
218 buffer[bufpos] = '\0';
219 msgid = xstrdup (buffer);
221 pos.file_name = location;
222 pos.line_number = (size_t)(-1);
224 remember_a_message (mlp, NULL, msgid, null_context, &pos, NULL, NULL);
226 /* Here c is the last read character: EOF or '\n'. */
234 error (EXIT_FAILURE, errno, _("error while reading \"%s\""),