3 # Extends include-header-files with __attribute__((packed))
4 # to make ixemul and os-includes ppc-compatible
6 # 07.06.98 Samuel Devulder: __attribute((aligned(2)) for all >2 byte elements
7 # 18.06.98 Holger Jakob: It is not enough to use a modified
9 # 21.05.2000 Emmanuel Lesueur: don't put __attribute__((aligned(2)) for structure
10 # elements that are on correct boudaries.
14 # structs that have a length non multiple of 4:
23 AvailFontsHeader
=> 2,
27 ClipboardUnitPartial
=> 2,
39 DiscResourceUnit
=> 2,
61 MPEGBorderParams
=> 1,
68 PrinterExtendedData
=> 2,
94 die "no include" if not $include=@ARGV[0];
95 #print STDERR "Copying $include ... ";
97 open(INP
,"<$include");
100 # Check for additional patches here...
101 # user.h, (screens.h), setjmp.h...
103 #if( $include=~ /include\/user.h$/i ) { $source=~ s/(\W)jmp_buf(\W)/$1jmp_buf_m68k$2/g; }
104 #if( $include=~ /include\/setjmp.h$/i ) {
105 # $source=~ s/(#define\s+_JBLEN)(\s+\d+)/$1_M68K $2\n$1\t\t26+17*2/;
106 # $source=~ s/(typedef\s+int\s+sigjmp_buf)(.*)(_JBLEN)(.*)/$1_m68k$2$3_M68K$4\n$1$2$3$4/;
107 # $source=~ s/(typedef\s+int\s+jmp_buf)(.*)(_JBLEN)(.*)/$1_m68k$2$3_M68K$4\n$1$2$3$4/;
109 if( $include=~ /include\/sys\
/syscall.h$/i ) { $source=~ s/#ifndef\s+?_KERNEL(.*?)#endif//s; }
114 $source=~ s/\/\*.*?\*\///sg; # Sorry, no comments
115 $source=~ s/^(\s*)struct((.|\n)*?)({(.|\n)*?});/&ins_packed_struct($2,$4)/meg;
116 # ToDo: same for typdef
117 #$source=~ s/^typedef((.|\n)*?)((\w|\n)*?);/&ins_packed_typedef($1,$3)/meg;
121 #print STDERR "Applied ";
122 #print STDERR ($source=~ s/__attribute/__attribute/g) || "no";
123 #print STDERR " patches.\n";
128 sub ins_packed_struct
130 local ($name,$text)=@_;
136 # $text=~ s/(LONG|struct)([^;])/$1$2 __attribute__((aligned(2))) /g;
138 $return="struct".$name.$text." __attribute__((packed));";
140 #FIXME: /* ; */ is not recogniced and 2-word types(eg. unsigned int) as well
142 $return=~ s/^(\s*)(\w*)(\s*)([a-zA-Z0-9_]*)(.*?);/&ins_align($1,$2,$3,$4,$5)/ge;
144 if($max_align>1 && $alignment>0 && ($alignment&1)!=0) {
145 $return=~ s/(.*)}(\s*__attribute__\(\(packed\)\).*)/$1\tchar __pad__;\n}$2/;
149 sub ins_packed_typedef
151 local ($text,$name)=@_;
155 # $text=~ s/(LONG|struct)([^;])/$1$2 __attribute__((aligned(2))) /g;
157 # $return="struct".$name.$text." __attribute__((packed));";
159 #FIXME: /* ; */ is not recogniced and 2-word types(eg. unsigned int) as well
161 # $return=~ s/^(\s*)(\w*)(\s*)([a-zA-Z_]*)(.*?);/&ins_align($1,$2,$3,$4,$5)/ge;
163 return "typedef $name;";
168 local ($space,$type,$space2,$type2,$part1)=@_;
172 if ( $part1=~ /^\s*\*/ ) {
174 if ( $alignment!= 0 ) {
175 if ( $part1=~ /^\s*(\**)(\w*)(.*)/ ) {
176 $part1=$1." __attribute__((aligned(2))) ".$2.$3;
179 } elsif( $type=~ /^(BYTE|UBYTE|BYTEBITS|TEXT|char)$/ ) {
181 } elsif( $type=~ /^(WORD|UWORD|SHORT|USHORT|BOOL|COUNT|UCOUNT|WORDBITS|short)$/ ) {
183 $type=$type." __attribute__((aligned(2)))";
186 } elsif( $type=~ /^struct$/ ) {
187 if ($alignment != 0) {
188 $type2=$type2." __attribute__((aligned(2)))";
190 if( exists $oddstructs{$type2} ) {
191 $size=$oddstructs{$type2};
195 } elsif( $alignment!=0 ) {
196 if( $type=~ /^([AC]PTR|STRPTR|LONG|LONGBITS|ULONG|FLOAT|DOUBLE|BPTR|BSTR)$/ ) {
197 $type=$type." __attribute__((aligned(2)))";
199 } elsif( $type=~ /^unsigned$/ ) {
200 $type2=$type2." __attribute__((aligned(2)))";
202 } elsif( $type=~ /^(int|long)$/ ) {
203 $type=$type." __attribute__((aligned(2)))";
205 } elsif( $part1=~ /^(\*|\(\*)/ ) {
206 $type=$type." __attribute__((aligned(2)))";
210 if( $alignment==1 && $size>1 ) {
212 } elsif( $alignment==3 && $size>1) {
215 if( $size!=0 && $alignment!=-1 ) {
217 while ($alignment!=-1 && $x=~/\[/) {
218 if( $x=~ /\[(\d*)\](.*)/ ) {
229 if( $alignment!=-1 ) {
230 $alignment=($alignment+$size)&3;
233 if( $size > $max_align) {
236 # return "/* ".$alignment.",".$max_align." */ ".$space.$type.$space2.$type2.$part1.";";
237 return $space.$type.$space2.$type2.$part1.";";