replaced stdio in many parts of samba with a XFILE. XFILE is a cut-down
[tprouty/samba.git] / source / script / mkproto.awk
1 BEGIN {
2   inheader=0;
3 #  use_ldap_define = 0;
4   current_file="";
5   if (headername=="") {
6     headername="_PROTO_H_";
7   }
8
9   print "#ifndef",headername
10   print "#define",headername
11   print "/* This file is automatically generated with \"make proto\". DO NOT EDIT */"
12   print ""
13 }
14
15 END {
16   print "#endif /* _PROTO_H_ */"
17 }
18
19 {
20   if (FILENAME!=current_file) {
21 #    if (use_ldap_define)
22 #    {
23 #      print "#endif /* USE_LDAP */"
24 #      use_ldap_define = 0;
25 #    }
26     print ""
27     print "/* The following definitions come from",FILENAME," */"
28     print ""
29     current_file=FILENAME
30   }
31   if (inheader) {
32     if (match($0,"[)][ \t]*$")) {
33       inheader = 0;
34       printf "%s;\n",$0;
35     } else {
36       printf "%s\n",$0;
37     }
38     next;
39   }
40 }
41
42 # special handling for code merge of TNG to head
43 /^#define OLD_NTDOMAIN 1/ {
44   printf "#if OLD_NTDOMAIN\n"
45 }
46 /^#undef OLD_NTDOMAIN/ {
47   printf "#endif\n"
48 }
49 /^#define NEW_NTDOMAIN 1/ {
50   printf "#if NEW_NTDOMAIN\n"
51 }
52 /^#undef NEW_NTDOMAIN/ {
53   printf "#endif\n"
54 }
55
56 # we handle the loadparm.c fns separately
57
58 /^FN_LOCAL_BOOL/ {
59   split($0,a,"[,()]")
60   printf "BOOL %s(int );\n", a[2]
61 }
62
63 /^FN_LOCAL_LIST/ {
64   split($0,a,"[,()]")
65   printf "char **%s(int );\n", a[2]
66 }
67
68 /^FN_LOCAL_STRING/ {
69   split($0,a,"[,()]")
70   printf "char *%s(int );\n", a[2]
71 }
72
73 /^FN_LOCAL_INT/ {
74   split($0,a,"[,()]")
75   printf "int %s(int );\n", a[2]
76 }
77
78 /^FN_LOCAL_CHAR/ {
79   split($0,a,"[,()]")
80   printf "char %s(int );\n", a[2]
81 }
82
83 /^FN_GLOBAL_BOOL/ {
84   split($0,a,"[,()]")
85   printf "BOOL %s(void);\n", a[2]
86 }
87
88 /^FN_GLOBAL_LIST/ {
89   split($0,a,"[,()]")
90   printf "char **%s(void);\n", a[2]
91 }
92
93 /^FN_GLOBAL_STRING/ {
94   split($0,a,"[,()]")
95   printf "char *%s(void);\n", a[2]
96 }
97
98 /^FN_GLOBAL_INT/ {
99   split($0,a,"[,()]")
100   printf "int %s(void);\n", a[2]
101 }
102
103 /^static|^extern/ || !/^[a-zA-Z]/ || /[;]/ {
104   next;
105 }
106
107 #
108 # We have to split up the start
109 # matching as we now have so many start
110 # types that it can cause some versions
111 # of nawk/awk to choke and fail on
112 # the full match. JRA.
113 #
114
115 {
116   gotstart = 0;
117   if( $0 ~ /^const|^connection_struct|^pipes_struct|^file_fd_struct|^files_struct|^connection_struct|^uid_t|^gid_t|^unsigned|^mode_t|^DIR|^user|^int|^pid_t|^ino_t|^off_t/ ) {
118     gotstart = 1;
119   }
120
121   if( $0 ~ /^vuser_key|^UNISTR2|^LOCAL_GRP|^DOMAIN_GRP|^SMB_STRUCT_DIRENT|^SEC_ACL|^SEC_DESC|^SEC_DESC_BUF|^DOM_SID|^RPC_HND_NODE|^BYTE/ ) {
122     gotstart = 1;
123   }
124
125   if( $0 ~ /^TDB_CONTEXT|^TDB_DATA|^smb_ucs2_t|^TALLOC_CTX|^hash_element|^NT_DEVICEMODE|^enum.*\(|^NT_USER_TOKEN|^SAM_ACCOUNT/ ) {
126     gotstart = 1;
127   }
128
129   if( $0 ~ /^smb_iconv_t|^long|^char|^uint|^NTSTATUS|^WERROR|^struct|^BOOL|^void|^time|^smb_shm_offset_t|^shm_offset_t|^FILE|^XFILE|^SMB_OFF_T|^size_t|^ssize_t|^SMB_BIG_UINT/ ) {
130     gotstart = 1;
131   }
132
133   if( $0 ~ /^SAM_ACCT_INFO_NODE|^SMB_ACL_T/ ) {
134     gotstart = 1;
135   }
136
137   if(!gotstart) {
138     next;
139   }
140 }
141
142
143 /[(].*[)][ \t]*$/ {
144     printf "%s;\n",$0;
145     next;
146 }
147
148 /[(]/ {
149   inheader=1;
150   printf "%s\n",$0;
151   next;
152 }
153