1 # Make prototypes from .c files
17 my $private_func_re = "^_";
24 getopts
('x:m:o:p:dqE:R:P:') || die "foo";
42 $private_func_re = $opt_R;
45 'multiline-proto' => 1,
47 'function-blocking' => 0,
48 'gnuc-attribute' => 1,
52 foreach $i (split(/,/, $opt_m)) {
54 $flags{"multiline-proto"} = 0;
56 $flags{"function-blocking"} = 0;
57 $flags{"gnuc-attribute"} = 0;
60 if(substr($i, 0, 3) eq "no-") {
61 $flags{substr($i, 3)} = 0;
72 open(EXP
, '<', $opt_x) || die "open ${opt_x}";
73 my $obj = JSON
->new->utf8->decode(<EXP
>);
76 foreach my $x (keys %$obj) {
77 if (defined $obj->{$x}->{"export"}) {
78 $exported{$x} = $obj->{$x};
80 if (defined $obj->{$x}->{"deprecated"}) {
81 $deprecated{$x} = $obj->{$x}->{"deprecated"};
87 print $brace, " ", $_ if($debug);
92 if ( s@
/\
*\
*(.*)@@
) { $comment = 1; $doxygen = 1; $funcdoc = $1;
93 } elsif ( s@
/\
*.*@@
) { $comment = 1;
94 } elsif ($comment && s@
.*\
*/@@
) { $comment = 0; $doxygen = 0;
95 } elsif ($doxygen) { $funcdoc .= $_; next;
96 } elsif ($comment) { next; }
101 if($if_0 && /^\#endif/) {
124 if(!/^static/ && !/^PRIVATE/){
126 if(m/(.*)(__attribute__\s?\(.*\))/) {
130 if(m/(.*)\s(\w+DEPRECATED_FUNCTION)\s?(\(.*\))(.*)/) {
131 $depfunction{$2} = 1;
135 if(m/(.*)\s(\w+DEPRECATED)(.*)/) {
139 if(m/(.*)\s(HEIMDAL_\w+_ATTRIBUTE)\s?(\(.*\))?(.*)/) {
147 while(s/\(([^()]*),(.*)\)/($1\$$2)/g){}
148 s/\<\s*void\s*\>/<>/;
149 # remove parameter names
150 if($opt_P eq "remove") {
151 s/(\s*)([a-zA-Z0-9_]+)([,>])/$3/g;
153 s/\(\*(\s*)([a-zA-Z0-9_]+)\)/(*)/g;
154 } elsif($opt_P eq "comment") {
155 s/([a-zA-Z0-9_]+)([,>])/\/\
*$1\
*\
/$2/g;
156 s/\(\*([a-zA-Z0-9_]+)\)/(*\/\
*$1\
*\
/)/g;
159 # add newlines before parameters
160 if($flags{"multiline-proto"}) {
167 # match function name
168 /([a-zA-Z0-9_]+)\s*\</;
177 # only add newline if more than one parameter
178 if($flags{"multiline-proto"} && /,/){
184 # insert newline before function name
185 if($flags{"multiline-proto"}) {
186 s/(.*)\s([a-zA-Z0-9_]+ \Q$LP\E)/$1\n$2/;
192 $documentation{$f} = $funcdoc;
195 if ($apple && exists $exported{$f}) {
196 $ios = $exported{$f}{ios
};
197 $ios = "NA" if (!defined $ios);
198 $mac = $exported{$f}{macos
};
199 $mac = "NA" if (!defined $mac);
200 die "$f neither" if ($mac eq "NA" and $ios eq "NA");
201 $_ = $_ . " __OSX_AVAILABLE_STARTING(__MAC_${mac}, __IPHONE_${ios})";
203 if (exists $deprecated{$f}) {
204 $_ = $_ . " GSSAPI_DEPRECATED_FUNCTION(\"$deprecated{$f}\")";
205 $depfunction{GSSAPI_DEPRECATED_FUNCTION
} = 1;
220 $line = $line . " " . $_;
224 die "reached end of code and still in doxygen comment" if ($doxygen);
225 die "reached end of code and still in comment" if ($comment);
237 open(OUT
, ">${opt_o}.new");
238 $block = &foo
($opt_o);
240 $block = "__public_h__";
244 open(PRIV
, ">${opt_p}.new");
245 $private = &foo
($opt_p);
247 $private = "__private_h__";
253 $public_h_header .= "/* This is a generated file */
260 $public_h_header .= "#ifdef __STDC__
273 $public_h_header .= "#include <stdarg.h>
277 $public_h_trailer = "";
279 $private_h_header = "/* This is a generated file */
285 $private_h_header .= "#ifdef __STDC__
298 $private_h_header .= "#include <stdarg.h>
302 $private_h_trailer = "";
305 foreach(sort keys %funcs){
306 if(/^(DllMain|main)$/) { next }
307 if ($funcs{$_} =~ /\^/) {
308 $beginblock = "#ifdef __BLOCKS__\n";
309 $endblock = "#endif /* __BLOCKS__ */\n";
311 $beginblock = $endblock = "";
313 # if we have an export table and doesn't have content, or matches private RE
314 if((scalar(keys(%exported)) ne 0 && !exists $exported{$_} ) || /$private_func_re/) {
315 $private_h .= $beginblock;
316 # if ($apple and not /$private_func_re/) {
317 # $private_h .= "#define $_ __ApplePrivate_${_}\n";
319 $private_h .= $funcs{$_} . "\n" ;
320 $private_h .= $endblock . "\n";
321 if($funcs{$_} =~ /__attribute__/) {
322 $private_attribute_seen = 1;
325 if($documentation{$_}) {
326 $public_h .= "/**\n";
327 $public_h .= "$documentation{$_}";
328 $public_h .= " */\n\n";
330 if($flags{"function-blocking"}) {
332 if($exported{$_} =~ /proto/) {
333 $public_h .= "#if !defined(HAVE_$fupper) || defined(NEED_${fupper}_PROTO)\n";
335 $public_h .= "#ifndef HAVE_$fupper\n";
338 $public_h .= $beginblock . $funcs{$_} . "\n" . $endblock;
339 if($funcs{$_} =~ /__attribute__/) {
340 $public_attribute_seen = 1;
342 if($flags{"function-blocking"}) {
343 $public_h .= "#endif\n";
349 if($flags{"gnuc-attribute"}) {
350 if ($public_attribute_seen) {
351 $public_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
352 #define __attribute__(x)
358 if ($private_attribute_seen) {
359 $private_h_header .= "#if !defined(__GNUC__) && !defined(__attribute__)
360 #define __attribute__(x)
369 foreach (keys %depfunction) {
370 $depstr .= "#ifndef $_
371 #ifndef __has_extension
372 #define __has_extension(x) 0
373 #define ${_}has_extension 1
375 #if __has_extension(attribute_deprecated_with_message)
376 #define $_(x) __attribute__((__deprecated__(x)))
377 #elif defined(__GNUC__) && ((__GNUC__ > 3) || ((__GNUC__ == 3) && (__GNUC_MINOR__ >= 1 )))
378 #define $_(X) __attribute__((__deprecated__))
382 #ifdef ${_}has_extension
383 #undef __has_extension
384 #undef ${_}has_extension
390 $public_h_trailer .= "#undef $_
393 $private_h_trailer .= "#undef $_
399 $public_h_header .= $depstr;
400 $private_h_header .= $depstr;
404 $public_h_header .= "#ifdef __cplusplus
409 $public_h_trailer = "#ifdef __cplusplus
413 " . $public_h_trailer;
417 $public_h_header .= "#ifndef $opt_E
418 #ifndef ${opt_E}_FUNCTION
420 #define ${opt_E}_FUNCTION __declspec(dllimport)
421 #define ${opt_E}_CALL __stdcall
422 #define ${opt_E}_VARIABLE __declspec(dllimport)
424 #define ${opt_E}_FUNCTION
425 #define ${opt_E}_CALL
426 #define ${opt_E}_VARIABLE
432 $private_h_header .= "#ifndef $opt_E
433 #ifndef ${opt_E}_FUNCTION
435 #define ${opt_E}_FUNCTION __declspec(dllimport)
436 #define ${opt_E}_CALL __stdcall
437 #define ${opt_E}_VARIABLE __declspec(dllimport)
439 #define ${opt_E}_FUNCTION
440 #define ${opt_E}_CALL
441 #define ${opt_E}_VARIABLE
449 $public_h_trailer .= $undepstr;
450 $private_h_trailer .= $undepstr;
452 if ($public_h ne "" && $flags{"header"}) {
453 $public_h = $public_h_header . $public_h .
454 $public_h_trailer . "#endif /* DOXY */\n#endif /* $block */\n";
456 if ($private_h ne "" && $flags{"header"}) {
457 $private_h = $private_h_header . $private_h .
458 $private_h_trailer . "#endif /* $private */\n";
465 print PRIV
$private_h;
473 if (compare
("${opt_o}.new", ${opt_o
}) != 0) {
474 printf("updating ${opt_o}\n");
475 rename("${opt_o}.new", ${opt_o
});
477 unlink("${opt_o}.new");
482 if (compare
("${opt_p}.new", ${opt_p
}) != 0) {
483 printf("updating ${opt_p}\n");
484 rename("${opt_p}.new", ${opt_p
});
486 unlink("${opt_p}.new");