Debian Codegraph @

lang/cl/mkerrcodes.awk

raw
1 # mkerrcodes.awk
2 # Copyright (C) 2004, 2005, 2006 g10 Code GmbH
3 #
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.
8 #
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.
13 #
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.
17 #
18 # As a special exception, g10 Code GmbH gives unlimited permission to
19 # copy, distribute and modify the lisp source files that are the output
20 # of mkerrcodes.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 mkerrcodes.awk appear in them. The GNU
23 # General Public License (GPL) does govern all other use of the material
24 # that constitutes the mkerrcodes.awk program.
25 #
26 # Certain portions of the mkerrcodes.awk source text are designed to be
27 # copied (in certain cases, depending on the input) into the output of
28 # mkerrcodes.awk. We call these the "data" portions. The rest of the
29 # mkerrcodes.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 # mkerrcodes.awk never copies any of the non-data portions into its output.
33 #
34 # This special exception to the GPL applies to versions of mkerrcodes.awk
35 # released by g10 Code GmbH. When you make and distribute a modified version
36 # of mkerrcodes.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.
43
44 # The input file is in the following format:
45 # [CODE SYMBOL...]
46 # @errnos@
47 # [CODE SYMBOL...]
48 #
49 # The difference between the sections is how symbol is transformed.
50 # The second section gets GPG_ERR_ prepended before processing.
51 #
52 # Comments (starting with # and ending at the end of the line) are removed,
53 # as is trailing whitespace.
54
55 BEGIN {
56 FS="[ \t]+";
57 print ";;;; Output of mkerrcodes.awk. DO NOT EDIT.";
58 print "";
59 print ";;; Copyright (C) 2006 g10 Code GmbH";
60 print ";;;";
61 print ";;; This file is part of libgpg-error.";
62 print ";;;";
63 print ";;; libgpg-error is free software; you can redistribute it and/or";
64 print ";;; modify it under the terms of the GNU Lesser General Public License";
65 print ";;; as published by the Free Software Foundation; either version 2.1 of";
66 print ";;; the License, or (at your option) any later version.";
67 print ";;;";
68 print ";;; libgpg-error is distributed in the hope that it will be useful, but";
69 print ";;; WITHOUT ANY WARRANTY; without even the implied warranty of";
70 print ";;; MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU";
71 print ";;; Lesser General Public License for more details.";
72 print ";;;";
73 print ";;; You should have received a copy of the GNU Lesser General Public";
74 print ";;; License along with libgpg-error; if not, write to the Free";
75 print ";;; Software Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA";
76 print ";;; 02111-1307, USA.";
77 print "";
78
79 header = 1;
80 errnos = 0;
81 }
82
83 /^#/ { next; }
84
85 header {
86 if (errnos)
87 {
88 if ($1 ~ /^[0123456789]+$/)
89 {
90 header = 0;
91
92 print "";
93 print " ;; The following error codes map system errors.";
94 }
95 }
96 else
97 {
98 if ($1 ~ /^[0123456789]+$/)
99 {
100 header = 0;
101
102 print "(in-package :gpg-error)";
103 print "";
104 print ";;; The error code type gpg-err-code-t.";
105 print "";
106 print ";;; This is used for system error codes.";
107 print "(defconstant +gpg-err-system-error+ (ash 1 15))";
108 print "";
109 print ";;; This is one more than the largest allowed entry.";
110 print "(defconstant +gpg-err-code-dim+ 65536)";
111 print "";
112 print ";;; A helper macro to have the keyword values evaluated.";
113 print "(defmacro defcenum-eval (type doc &rest vals)";
114 print " `(defcenum ,type ,doc";
115 print " ,@(loop for v in vals";
116 print " collect `(,(first v) ,(eval (second v))))))";
117 print "";
118 print "(defcenum-eval gpg-err-code-t";
119 print " \"The GPG error code type.\"";
120 }
121 }
122 }
123
124 !header {
125 sub (/#.+/, "");
126 sub (/[ ]+$/, ""); # Strip trailing space and tab characters.
127
128 if (/^$/)
129 next;
130
131 # The following can happen for GPG_ERR_CODE_DIM.
132 if ($1 == "")
133 next;
134
135 if (/^@errnos@$/)
136 {
137 header = 1;
138 errnos = 1;
139 next;
140 }
141
142 $2 = tolower($2);
143 gsub ("_", "-", $2);
144
145 if (errnos)
146 print " (:gpg-err-" $2 " (logior +gpg-err-system-error+ " $1 "))";
147 else
148 print " (:" $2 " " $1 ")";
149 }
150
151 END {
152 # I am very sorry to break lisp coding style here.
153 print ")";
154 }