Commit e2332b93 e2332b935838321d3f771b1de45aa42d52ea2b7c by Sergey Poznyakoff

Create error reporting sources for GNU Mailutils

1 parent 24fb56a2
1 # generr.awk -- Create error reporting sources for GNU Mailutils
2 # Copyright (C) 2005 Free Software Foundation, Inc.
3 #
4 # GNU Mailutils 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, or (at
7 # your option) any later version.
8 #
9 # This program is distributed in the hope that it will be useful, but
10 # 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.
17 # 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
18
19 # This program creates error reporting source files (muerrno.c and errno.h)
20 # for GNU Mailutils.
21 #
22 # Usage:
23 # awk -f generr.awk errors muerrno.cin > muerrno.c
24 # awk -f generr.awk errors muerrno.hin > errno.h
25
26 BEGIN {
27 defno = 0
28 }
29
30 ARGIND == 1 && /^ *#/ { next }
31 ARGIND == 1 && NF == 0 { next }
32 ARGIND == 1 {
33 def[defno] = $1
34 match(substr($0,length($1)), "[ \\t]+")
35 text[defno] = substr($0,length($1)+RLENGTH+1)
36 defno++
37 }
38
39 ARGIND == 2 && /\$AUTOWARN/ {
40 match($0,"\\$AUTOWARN");
41 print substr($0,1,RSTART-1) "This file is generated automatically. Please, do not edit." substr($0,RSTART+RLENGTH)
42 next
43 }
44
45 ARGIND == 2 && $1 == "$MESSAGE_STRINGS" {
46 match($0, "[ \\t]+")
47 for (i = 0; i < defno; i++) {
48 printf "%*.*scase %s:\n", RLENGTH, RLENGTH, "", def[i]
49 printf "%*.*sreturn _(\"%s\");\n\n", RLENGTH+2,RLENGTH+2,"", text[i]
50 }
51 next
52 }
53
54 ARGIND == 2 && $1 == "$MESSAGE_CODES" {
55 match($0, "[ \\t]+")
56 for (i = 0; i < defno; i++) {
57 printf "%*.*scase %s:\n", RLENGTH, RLENGTH, "", def[i]
58 printf "%*.*sreturn \"%s\";\n\n", RLENGTH+2,RLENGTH+2,"", def[i]
59 }
60 next
61 }
62
63 ARGIND == 2 && $1 == "$MESSAGE_DEFS" {
64 for (i = 0; i < defno; i++) {
65 print "#define " def[i] " (MU_ERR_BASE+" i ")"
66 }
67 next
68 }
69
70 ARGIND == 2 {
71 print
72 }
73
74 # End of generr.awk