home *** CD-ROM | disk | FTP | other *** search
/ Magazyn Exec 5 / CD_Magazyn_EXEC_nr_5.iso / Programy / MorphOS / morphosdev-150201.lha / emultools / getoddstructs.pl < prev    next >
Encoding:
Perl Script  |  2001-02-14  |  660 b   |  42 lines

  1. #! /bin/perl
  2. #
  3. # usage: getoddstructs file.h >file.c
  4. #
  5. # generate a C program that displays the list of structures that
  6. # have a length not multiple of 4.
  7. #
  8.  
  9. require 5.002;
  10.  
  11. undef $/;
  12.  
  13. die "no include" if not $include=@ARGV[0];
  14. print STDERR "Copying $include...\n";
  15.  
  16. open(INP,"<$include");
  17. $source=<INP>;
  18.  
  19. print "#include <stdio.h>\n";
  20. print $source;
  21.  
  22. print "int main() {\n";
  23.  
  24. $source=~ s/^(\s*)struct((.|\n)*?)({(.|\n)*?});/&ins_struct($2)/meg;
  25.  
  26. print "}\n";
  27.  
  28. close(INP);
  29.  
  30. sub ins_struct
  31. {
  32.     local ($name)=@_;
  33.  
  34.     if( $name=~/^(\s*)(\w*)(\s*)$/ ) {
  35.     $name=$2;
  36.     print '  if(sizeof(struct '.$name.')&3) printf("'.$name.'\n");'."\n";
  37.     }
  38.  
  39.     return "";
  40. }
  41.  
  42.