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, write to the Free Software
16 # Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA.
18 # As a special exception, g10 Code GmbH gives unlimited permission to
19 # copy, distribute and modify the C source files that are the output
20 # of mkheader.awk. You need not follow the terms of the GNU General
21 # Public License when using or distributing such scripts, even though
22 # portions of the text of mkheader.awk appear in them. The GNU
23 # General Public License (GPL) does govern all other use of the material
24 # that constitutes the mkheader.awk program.
26 # Certain portions of the mkheader.awk source text are designed to be
27 # copied (in certain cases, depending on the input) into the output of
28 # mkheader.awk. We call these the "data" portions. The rest of the
29 # mkheader.awk source text consists of comments plus executable code
30 # that decides which of the data portions to output in any given case.
31 # We call these comments and executable code the "non-data" portions.
32 # mkheader.h never copies any of the non-data portions into its output.
34 # This special exception to the GPL applies to versions of mkheader.awk
35 # released by g10 Code GmbH. When you make and distribute a modified version
36 # of mkheader.awk, you may extend this special exception to the GPL to
37 # apply to your modified version as well, *unless* your modified version
38 # has the potential to copy into its output some of the text that was the
39 # non-data portion of the version that you started with. (In other words,
40 # unless your change moves or copies text from the non-data portions to the
41 # data portions.) If your modification has such potential, you must delete
42 # any notice of this special exception to the GPL from your modified version.
44 # This script processes gpg-error.h.in in an awful way.
45 # Its input is, one after another, the content of the err-sources.h.in file,
46 # the err-codes.h.in file, the errnos.in file, and then gpg-error.h.in.
47 # There is nothing fancy about this.
49 # An alternative would be to use getline to get the content of the first three files,
50 # but then we need to pre-process gpg-error.h.in with configure to get
51 # at the full path of the files in @srcdir@.
55 # sources_nr holds the number of error sources.
57 # codes_nr holds the number of error codes.
59 # errnos_nr holds the number of system errors.
62 # These variables walk us through our input.
65 between_sources_and_codes = 0;
67 between_codes_and_errnos = 0;
71 print "/* Output of mkheader.awk. DO NOT EDIT. */";
77 if ($1 ~ /^[0123456789]+$/)
86 sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
94 between_sources_and_codes = 1;
98 # Remember the error source number and symbol of each error source.
99 sources_idx[sources_nr] = $1;
100 sources_sym[sources_nr] = $2;
105 between_sources_and_codes {
106 if ($1 ~ /^[0123456789]+$/)
108 between_sources_and_codes = 0;
115 sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
123 between_codes_and_errnos = 1;
127 # Remember the error code number and symbol of each error source.
128 codes_idx[codes_nr] = $1;
129 codes_sym[codes_nr] = $2;
134 between_codes_and_errnos {
137 between_codes_and_errnos = 0;
144 sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
151 # Note that this assumes that gpg-error.h.in doesn't start with a digit.
157 errnos_idx[errnos_nr] = "GPG_ERR_SYSTEM_ERROR | " $1;
158 errnos_sym[errnos_nr] = "GPG_ERR_" $2;
164 if ($0 ~ /^@include err-sources/)
166 for (i = 0; i < sources_nr; i++)
168 print " " sources_sym[i] " = " sources_idx[i] ",";
169 # print "#define " sources_sym[i] " (" sources_idx[i] ")";
172 else if ($0 ~ /^@include err-codes/)
174 for (i = 0; i < codes_nr; i++)
176 print " " codes_sym[i] " = " codes_idx[i] ",";
177 # print "#define " codes_sym[i] " (" codes_idx[i] ")";
180 else if ($0 ~ /^@include errnos/)
182 for (i = 0; i < errnos_nr; i++)
184 print " " errnos_sym[i] " = " errnos_idx[i] ",";
185 # print "#define " errnos_sym[i] " (" errnos_idx[i] ")";