develooper Front page | perl.perl5.porters | Postings from January 2005

h2hp: 2 fix

Thread Next
From:
Olivier Thauvin
Date:
January 28, 2005 08:08
Subject:
h2hp: 2 fix
Message ID:
200501281653.15708.olivier.thauvin@aerov.jussieu.fr
Here a patch for h2ph:

- first regexp dont skip #define dcl insert into enum like:

typedef enum {
  VAR1 = X;
#define VAR2 VAR1
  VAR3 = Y;
}

The second check is to avoir empty sub creation (normally fix by my first 
path) else if parsing is wrong it create something like:
sub () { VAL; };
which of course failed at compilation...

BTW:
[olivier@andromede tmp]$ perl -v
This is perl, v5.8.6 built for i386-linux
[olivier@andromede tmp]$ rpm -q perl
perl-5.8.6-4mdk

Comment welcome.

--- /usr/bin/h2ph       2005-01-27 12:24:07.000000000 +0100
+++ /tmp/h2ph   2005-01-28 16:28:20.322388280 +0100
@@ -242,6 +242,8 @@
                chomp $next;
                # drop "#define FOO FOO" in enums
                $next =~ s/^\s*#\s*define\s+(\w+)\s+\1\s*$//;
+        # define in enum, doing like it is a value of enum
+               $next =~ s/^\s*#\s*define\s+(\w+)\s+(\w+)\s*$/$1 = $2,/;
                $_ .= $next;
                print OUT "# $next\n" if $opt_D;
            }
@@ -254,6 +256,8 @@
            my $enum_val = -1;
            foreach my $enum (@enum_subs) {
                my ($enum_name, $enum_value) = $enum =~ /^([a-zA-Z_]\w*)(=.+)?
$/;
+        # if no enum_name, passing else it create 'sub () { VAL; }' which 
make invalid code
+        $enum_name or next;
                $enum_value =~ s/^=//;
                $enum_val = (length($enum_value) ? $enum_value : $enum_val + 
1);
                if ($opt_h) {

-- 
/****************************
* La distro du 24ème siècle *
* http://octoz.zarb.org/    *
****************************/

Thread Next


nntp.perl.org: Perl Programming lists via nntp and http.
Comments to Ask Bjørn Hansen at ask@perl.org | Group listing | About