home *** CD-ROM | disk | FTP | other *** search
/ ftp.whtech.com / ftp.whtech.com.7z / ftp.whtech.com / emulators / v9t9 / linux / sources / V9t9 / source / fixgtkcallbacks.pl < prev    next >
Encoding:
Text File  |  2006-10-19  |  1.3 KB  |  71 lines

  1. #
  2. #  gtkcallbacks.c is generated with repeats of existing functions.
  3. #
  4. #  this script identifies the existing functions and deletes the
  5. #  empty new ones.
  6. #
  7.  
  8. %function_map = ();
  9. $filename = $ARGV[0];
  10.  
  11. open(FILE, "<$filename") || die;
  12. open(NEW, ">$filename.tmp") || die;
  13.  
  14. $changed = 0;
  15.  
  16. $ifcount = 0;
  17. while (<FILE>) {
  18.   my $line = $_;
  19.  
  20.   if ($line =~ /\#if/) {
  21.     print NEW $line;
  22.     $ifcount++;
  23.     while ($ifcount) {
  24.       $line = <FILE>;
  25.       print NEW $line;
  26.       if ($line =~ /\#endif/) {
  27.         $ifcount--;
  28.       } elsif ($line =~ /\#if/) {
  29.         $ifcount++;
  30.       }
  31.     }
  32.   }
  33.  
  34.   # look for return type on one line, and decl on next
  35.   elsif ($line =~ /^void|^gboolean/) {
  36.     my $decl = <FILE>;
  37.     if ($decl =~ /^(on_[^( ]*)/) {
  38.  
  39. #      print "function '$1'\n";
  40.  
  41.       if (defined($function_map{$1})) {
  42.         print "duplicate '$1'!\n";
  43.         # skip
  44.         while (<FILE> !~ /^}/) { };
  45.         $changed = 1;
  46.       } else {
  47.         $function_map{$1} = "1";
  48.         print NEW $line;
  49.         print NEW $decl;
  50.       }
  51.  
  52.     } else {
  53.       print NEW $line;
  54.       print NEW $decl;
  55.     }
  56.   } else {
  57.     print NEW $line;
  58.   }
  59. }
  60. close(FILE);
  61. close(NEW);
  62.  
  63. if ($changed) {
  64.   rename("$filename.old2", "$filename.old3");
  65.   rename("$filename.old", "$filename.old2");
  66.   rename("$filename", "$filename.old") || die;
  67.   rename("$filename.tmp", "$filename") || die;
  68. } else {
  69.   print "No changes to $filename\n";
  70. }
  71.