PageRenderTime 42ms CodeModel.GetById 31ms app.highlight 8ms RepoModel.GetById 1ms 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
20use strict ; use warnings ;
21
22my @wantenums = qw( GimpImageBaseType
23                    GimpImageType
24                    GimpLayerModeEffects
25                    PropType
26                    XcfCompressionType
27                    );
28my %wantenums ;
29@wantenums{@wantenums} = (-1) x @wantenums ;
30
31my $last ;
32my @collect ;
33print join("\n *   ","/* Extracted from",@ARGV),"\n * by $0\n */\n" ;
34while( <> ) {
35    if( /^\s*typedef\s+enum\s/ ) {
36        @collect = ($_) ;
37    } elsif( /^\}\s+(\w+)\s*;/ && @collect ) {
38        my $enum = $1 ;
39        if( ++$wantenums{$enum} == 0 ) {
40            if( $enum eq 'GimpLayerModeEffects' ) {
41                push @collect, "  ,GIMP_NORMAL_NOPARTIAL_MODE=-1\n" ;
42            }
43            push @collect, $_ ;
44            print @collect ;
45            print "const char *show$enum($enum);\n" ;
46            print "#define ${enum}_LAST $last\n" ;
47        }
48        @collect = () ;
49    } elsif( @collect ) {
50        push @collect, $_ ;
51        $last = $1 if /^\s*(\w+)/ ;
52    }
53}
54for my $enum ( @wantenums ) {
55    my $count = 1 + $wantenums{$enum} ;
56    if( $count != 1 ) {
57        print STDERR "$count definitions of $enum\n" ;
58    }
59}
60    
61