PageRenderTime 63ms CodeModel.GetById 38ms RepoModel.GetById 0ms app.codeStats 0ms

/xcftools-1.0.7/mkenumsh.pl

#
Perl | 61 lines | 38 code | 5 blank | 18 comment | 9 complexity | 1046000dd0658cb99c3a6c326d33616a MD5 | raw file
  1. #! /usr/bin/perl
  2. # This short script extracts enum definitions from files stolen
  3. # from the Gimp's sources.
  4. #
  5. # This file was written by Henning Makholm <henning@makholm.net>
  6. # It is hereby in the public domain.
  7. #
  8. # In jurisdictions that do not recognise grants of copyright to the
  9. # public domain: I, the author and (presumably, in those jurisdictions)
  10. # copyright holder, hereby permit anyone to distribute and use this code,
  11. # in source code or binary form, with or without modifications. This
  12. # permission is world-wide and irrevocable.
  13. #
  14. # Of course, I will not be liable for any errors or shortcomings in the
  15. # code, since I give it away without asking any compenstations.
  16. #
  17. # If you use or distribute this code, I would appreciate receiving
  18. # credit for writing it, in whichever way you find proper and customary.
  19. use strict ; use warnings ;
  20. my @wantenums = qw( GimpImageBaseType
  21. GimpImageType
  22. GimpLayerModeEffects
  23. PropType
  24. XcfCompressionType
  25. );
  26. my %wantenums ;
  27. @wantenums{@wantenums} = (-1) x @wantenums ;
  28. my $last ;
  29. my @collect ;
  30. print join("\n * ","/* Extracted from",@ARGV),"\n * by $0\n */\n" ;
  31. while( <> ) {
  32. if( /^\s*typedef\s+enum\s/ ) {
  33. @collect = ($_) ;
  34. } elsif( /^\}\s+(\w+)\s*;/ && @collect ) {
  35. my $enum = $1 ;
  36. if( ++$wantenums{$enum} == 0 ) {
  37. if( $enum eq 'GimpLayerModeEffects' ) {
  38. push @collect, " ,GIMP_NORMAL_NOPARTIAL_MODE=-1\n" ;
  39. }
  40. push @collect, $_ ;
  41. print @collect ;
  42. print "const char *show$enum($enum);\n" ;
  43. print "#define ${enum}_LAST $last\n" ;
  44. }
  45. @collect = () ;
  46. } elsif( @collect ) {
  47. push @collect, $_ ;
  48. $last = $1 if /^\s*(\w+)/ ;
  49. }
  50. }
  51. for my $enum ( @wantenums ) {
  52. my $count = 1 + $wantenums{$enum} ;
  53. if( $count != 1 ) {
  54. print STDERR "$count definitions of $enum\n" ;
  55. }
  56. }