-
Notifications
You must be signed in to change notification settings - Fork 9
/
Copy pathCLib.pl
121 lines (95 loc) · 3.04 KB
/
CLib.pl
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
### Class CLib: Create a clib file ############################################
BEGIN {
package CLib;
sub new {
my $proto = shift;
my %params = @_;
my $class = ref($proto) || $proto;
my $self = {};
$self->{SFD} = $params{'sfd'};
$self->{VERSION} = 1;
bless ($self, $class);
return $self;
}
sub header {
my $self = shift;
my $sfd = $self->{SFD};
my $id = $$sfd{'id'};
my $v = $id;
my $d = $id;
$v =~ s/^\$[I]d: .*? ([0-9.]+).*/$1/;
$d =~ s,^\$[I]d: .*? [0-9.]+ (\d{4})/(\d{2})/(\d{2}).*,($3.$2.$1),;
print "/* Automatically generated header (sfdc SFDC_VERSION)! Do not edit! */\n";
print "\n";
print "#ifndef CLIB_$$sfd{'BASENAME'}_PROTOS_H\n";
print "#define CLIB_$$sfd{'BASENAME'}_PROTOS_H\n";
print "\n";
print "/*\n";
print "** \$VER: $$sfd{'basename'}_protos.h $v $d\n";
print "**\n";
print "** C prototypes. For use with 32 bit integers only.\n";
print "**\n";
print "** $$sfd{'copyright'}\n";
print "** All Rights Reserved\n";
print "*/\n";
print "\n";
foreach my $inc (@{$$sfd{'includes'}}) {
print "#include $inc\n";
}
foreach my $td (@{$$sfd{'typedefs'}}) {
print "typedef $td;\n";
}
print "\n";
print "#ifdef __cplusplus\n";
print "extern \"C\" {\n";
print "#endif /* __cplusplus */\n";
print "\n";
$self->{VERSION} = 1;
}
sub function {
my $self = shift;
my %params = @_;
my $prototype = $params{'prototype'};
my $sfd = $self->{SFD};
# Don't process private functions
if ($prototype->{private}) {
return;
}
if ($self->{VERSION} != $$prototype{'version'}) {
$self->{VERSION} = $$prototype{'version'};
print "\n";
print "/*--- functions in V$self->{VERSION} or higher ---*/\n";
}
if ($$prototype{'comment'} ne '') {
my $comment = $$prototype{'comment'};
$comment =~ s,^(\s?)(.*)$,/*$1$2$1*/,mg;
print "\n";
print "$comment\n";
}
my $args = join (', ',@{$$prototype{'args'}});
if ($args eq '') {
$args = "void";
}
print "$$prototype{'return'} $$prototype{'funcname'}($args)";
if ($$classes{'target'} eq 'morphos' &&
$$prototype{'type'} eq 'varargs' &&
$$prototype{'subtype'} ne 'tagcall') {
print " __attribute__((varargs68k))";
}
if ($classes->{target} eq 'amigaos4' &&
$prototype->{type} eq 'varargs') {
print " __attribute__((linearvarargs))";
}
print ";\n";
}
sub footer {
my $self = shift;
my $sfd = $self->{SFD};
print "\n";
print "#ifdef __cplusplus\n";
print "}\n";
print "#endif /* __cplusplus */\n";
print "\n";
print "#endif /* CLIB_$$sfd{'BASENAME'}_PROTOS_H */\n";
}
}