2
# Copyright (C) 2003, 2004 g10 Code GmbH
4
# This program is free software; you can redistribute it and/or
5
# modify it under the terms of the GNU General Public License as
6
# published by the Free Software Foundation; either version 2 of
7
# the License, or (at your option) any later version.
9
# This program is distributed in the hope that it will be useful,
10
# but WITHOUT ANY WARRANTY; without even the implied warranty of
11
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
# General Public License for more details.
14
# You should have received a copy of the GNU General Public License
15
# along with this program; if not, see <http://www.gnu.org/licenses/>.
17
# As a special exception, g10 Code GmbH gives unlimited permission to
18
# copy, distribute and modify the C source files that are the output
19
# of mkstrtable.awk. You need not follow the terms of the GNU General
20
# Public License when using or distributing such scripts, even though
21
# portions of the text of mkstrtable.awk appear in them. The GNU
22
# General Public License (GPL) does govern all other use of the material
23
# that constitutes the mkstrtable.awk program.
25
# Certain portions of the mkstrtable.awk source text are designed to be
26
# copied (in certain cases, depending on the input) into the output of
27
# mkstrtable.awk. We call these the "data" portions. The rest of the
28
# mkstrtable.awk source text consists of comments plus executable code
29
# that decides which of the data portions to output in any given case.
30
# We call these comments and executable code the "non-data" portions.
31
# mkstrtable.h never copies any of the non-data portions into its output.
33
# This special exception to the GPL applies to versions of mkstrtable.awk
34
# released by g10 Code GmbH. When you make and distribute a modified version
35
# of mkstrtable.awk, you may extend this special exception to the GPL to
36
# apply to your modified version as well, *unless* your modified version
37
# has the potential to copy into its output some of the text that was the
38
# non-data portion of the version that you started with. (In other words,
39
# unless your change moves or copies text from the non-data portions to the
40
# data portions.) If your modification has such potential, you must delete
41
# any notice of this special exception to the GPL from your modified version.
43
# This script outputs a source file that does define the following
46
# static const char msgstr[];
47
# A string containing all messages in the list.
49
# static const int msgidx[];
50
# A list of index numbers, one for each message, that points to the
51
# beginning of the string in msgstr.
54
# A macro that maps code numbers to idx numbers. If a DEFAULT MESSAGE
55
# is provided (see below), its index will be returned for unknown codes.
56
# Otherwise -1 is returned for codes that do not appear in the list.
57
# You can lookup the message with code CODE with:
58
# msgstr + msgidx[msgidxof (code)].
60
# The input file has the following format:
61
# CODE1 ... MESSAGE1 (code nr, <tab>, something, <tab>, msg)
62
# CODE2 ... MESSAGE2 (code nr, <tab>, something, <tab>, msg)
64
# CODEn ... MESSAGEn (code nr, <tab>, something, <tab>, msg)
65
# ... DEFAULT-MESSAGE (<tab>, something, <tab>, fall-back msg)
67
# Comments (starting with # and ending at the end of the line) are removed,
68
# as is trailing whitespace. The last line is optional; if no DEFAULT
69
# MESSAGE is given, msgidxof will return the number -1 for unknown
72
# The field to be used is specified with the variable "textidx" on
73
# the command line. It defaults to 2.
75
# The variable nogettext can be set to 1 to suppress gettext markers.
77
# The variable prefix can be used to prepend a string to each message.
79
# The variable namespace can be used to prepend a string to each
80
# variable and macro name.
84
# cpos holds the current position in the message string.
86
# msg holds the number of messages.
88
print "/* Output of mkstrtable.awk. DO NOT EDIT. */";
93
# nogettext can be set to 1 to suppress gettext noop markers.
99
if ($1 ~ /^[0123456789]+$/)
101
print "/* The purpose of this complex string table is to produce";
102
print " optimal code with a minimum of relocations. */";
104
print "static const char " namespace "msgstr[] = ";
113
sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
118
# Print the string msgstr line by line. We delay output by one line to be able
119
# to treat the last line differently (see END).
123
print " \"" last_msgstr "\" \"\\0\"";
125
print " gettext_noop (\"" last_msgstr "\") \"\\0\"";
127
last_msgstr = prefix $textidx;
129
# Remember the error code and msgidx of each error message.
132
cpos += length (last_msgstr) + 1;
143
coded_msgs = msg - 1;
148
print " \"" prefix last_msgstr "\";";
150
print " gettext_noop (\"" prefix last_msgstr "\");";
152
print "static const int " namespace "msgidx[] =";
154
for (i = 0; i < coded_msgs; i++)
155
print " " pos[i] ",";
156
print " " pos[coded_msgs];
159
print "#define " namespace "msgidxof(code) (0 ? -1 \\";
165
for (i = 1; i < coded_msgs; i++)
167
if (code[i] == stop + 1)
171
print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \
173
skip += code[i] - stop - 1;
178
print " : ((code >= " start ") && (code <= " stop ")) ? (code - " \
181
print " : " stop + 1 " - " skip ")";