home *** CD-ROM | disk | FTP | other *** search
/ AmigActive 15 / AACD15.ISO / AACD / System / MorphOS / Developer / emultools / _geninclude.pl next >
Encoding:
Perl Script  |  2000-11-02  |  2.7 KB  |  98 lines

  1. #! /bin/perl
  2. #
  3. # Extends include-header-files with __attribute__((packed))
  4. # to make ixemul and os-includes ppc-compatible
  5. #
  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
  8. #                           exec/types.h only :(
  9. #
  10. require 5.002;
  11.  
  12.  
  13. undef $/;
  14.  
  15. die "no include" if not $include=@ARGV[0];
  16. print STDERR "Copying $include ... ";
  17.  
  18. open(INP,"<$include");
  19. $source=<INP>;
  20.  
  21. # Check for additional patches here...
  22. # user.h, (screens.h), setjmp.h...
  23.  
  24. if( $include=~ /include\/user.h$/i ) { $source=~ s/(\W)jmp_buf(\W)/$1jmp_buf_m68k$2/g; }
  25. if( $include=~ /include\/setjmp.h$/i ) {
  26.   $source=~ s/(#define\s+_JBLEN)(\s+\d+)/$1_M68K $2\n$1\t\t26+17*2/;
  27.   $source=~ s/(typedef\s+int\s+sigjmp_buf)(.*)(_JBLEN)(.*)/$1_m68k$2$3_M68K$4\n$1$2$3$4/;
  28.   $source=~ s/(typedef\s+int\s+jmp_buf)(.*)(_JBLEN)(.*)/$1_m68k$2$3_M68K$4\n$1$2$3$4/;
  29. }
  30. if( $include=~ /include\/sys\/syscall.h$/i ) { $source=~ s/#ifndef\s+?_KERNEL(.*?)#endif//s; }
  31.  
  32. #
  33. #
  34.  
  35. $source=~ s/\/\*.*?\*\///sg;  # Sorry, no comments
  36. $source=~ s/^struct((.|\n)*?)({(.|\n)*?});/&ins_packed_struct($1,$3)/meg;
  37. # ToDo: same for typdef
  38. #$source=~ s/^typedef((.|\n)*?)((\w|\n)*?);/&ins_packed_typedef($1,$3)/meg;
  39. print $source;
  40.  
  41. close(INP);
  42. print STDERR "Applied ";
  43. print STDERR ($source=~ s/__attribute/__attribute/g) || "no";
  44. print STDERR " patches.\n";
  45.  
  46. sub ins_packed_struct
  47. {
  48.     local ($name,$text)=@_;
  49.     local ($return);
  50.  
  51.  
  52. #    $text=~ s/(LONG|struct)([^;])/$1$2 __attribute__((aligned(2))) /g;
  53.  
  54.     $return="struct".$name.$text." __attribute__((packed));";
  55.  
  56. #FIXME: /* ; */ is not recogniced and 2-word types(eg. unsigned int) as well
  57. #FIXED!?
  58.     $return=~ s/^(\s*)(\w*)(\s*)([a-zA-Z_]*)(.*?);/&ins_align($1,$2,$3,$4,$5)/ge;
  59.  
  60.     return $return;
  61. }
  62. sub ins_packed_typedef
  63. {
  64.     local ($text,$name)=@_;
  65.     local ($return);
  66.  
  67.  
  68. #    $text=~ s/(LONG|struct)([^;])/$1$2 __attribute__((aligned(2))) /g;
  69.  
  70. #    $return="struct".$name.$text." __attribute__((packed));";
  71.  
  72. #FIXME: /* ; */ is not recogniced and 2-word types(eg. unsigned int) as well
  73. #FIXED!?
  74. #    $return=~ s/^(\s*)(\w*)(\s*)([a-zA-Z_]*)(.*?);/&ins_align($1,$2,$3,$4,$5)/ge;
  75.  
  76.     return "typedef $name;";
  77. }
  78.  
  79. sub ins_align
  80. {
  81.     local ($space,$type,$space2,$type2,$part1)=@_;
  82.  
  83.     if( $type=~ /^([AC]PTR|STRPTR|LONG|LONGBITS|ULONG|FLOAT|DOUBLE)$/ ) {
  84.         $type=$type." __attribute__((aligned(2)))";
  85.     } elsif( $type=~ /^struct$/ ) {
  86.         if( $part1=~ /^\s*\*/ ) {
  87.             $type2=$type2." __attribute__((aligned(2)))";
  88.         }
  89.     } elsif( $type=~ /^unsigned$/ ) {
  90.         $type2=$type2." __attribute__((aligned(2)))";
  91.     } elsif( $type=~ /^(int|long)$/ ) {
  92.         $type=$type." __attribute__((aligned(2)))";
  93.     } elsif( $part1=~ /^(\*|\(\*)/ ) {
  94.         $type=$type." __attribute__((aligned(2)))";
  95.     }
  96.     return $space.$type.$space2.$type2.$part1.";";
  97. }
  98.