[PATCH 1/4] hvsupport: Introduce parseSymsFile

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



The code for parsing the different public syms files only differs
in the filenames and version prefix.

Unify it to a single subroutine.
---
 docs/hvsupport.pl | 168 ++++++++++++++++--------------------------------------
 1 file changed, 50 insertions(+), 118 deletions(-)

diff --git a/docs/hvsupport.pl b/docs/hvsupport.pl
index 44a30ce..7a6f1ac 100755
--- a/docs/hvsupport.pl
+++ b/docs/hvsupport.pl
@@ -44,136 +44,66 @@ find({
             push @srcs, $_ if $_ !~ /vbox_driver\.c/;
         }
     }, no_chdir => 1}, $srcdir);
-my $line;
 
-# Get the list of all public APIs and their corresponding version
+sub parseSymsFile {
+    my $apisref = shift;
+    my $prefix = shift;
+    my $filename = shift;
+    my $xmlfilename = shift;
 
-my %apis;
-open FILE, "<$symslibvirt"
-    or die "cannot read $symslibvirt: $!";
-
-my $vers;
-my $prevvers;
-my $apixpath = XML::XPath->new(filename => "$srcdir/../docs/libvirt-api.xml");
-while (defined($line = <FILE>)) {
-    chomp $line;
-    next if $line =~ /^\s*#/;
-    next if $line =~ /^\s*$/;
-    next if $line =~ /^\s*(global|local):/;
-    if ($line =~ /^\s*LIBVIRT_(\d+\.\d+\.\d+)\s*{\s*$/) {
-        if (defined $vers) {
-            die "malformed syms file";
-        }
-        $vers = $1;
-    } elsif ($line =~ /\s*}\s*;\s*$/) {
-        if (defined $prevvers) {
-            die "malformed syms file";
-        }
-        $prevvers = $vers;
-        $vers = undef;
-    } elsif ($line =~ /\s*}\s*LIBVIRT_(\d+\.\d+\.\d+)\s*;\s*$/) {
-        if ($1 ne $prevvers) {
-            die "malformed syms file $1 != $vers";
-        }
-        $prevvers = $vers;
-        $vers = undef;
-    } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
-        my $file = $apixpath->find("/api/symbols/function[\@name='$1']/\@file");
-        $apis{$1} = {};
-        $apis{$1}->{vers} = $vers;
-        $apis{$1}->{file} = $file;
-    } else {
-        die "unexpected data $line\n";
-    }
-}
+    my $line;
+    my $vers;
+    my $prevvers;
 
-close FILE;
+    my $apixpath = XML::XPath->new(filename => $xmlfilename);
 
+    open FILE, "<$filename"
+        or die "cannot read $filename: $!";
 
-# And the same for the QEMU specific APIs
-
-open FILE, "<$symsqemu"
-    or die "cannot read $symsqemu: $!";
-
-$prevvers = undef;
-$vers = undef;
-$apixpath = XML::XPath->new(filename => "$srcdir/../docs/libvirt-qemu-api.xml");
-while (defined($line = <FILE>)) {
-    chomp $line;
-    next if $line =~ /^\s*#/;
-    next if $line =~ /^\s*$/;
-    next if $line =~ /^\s*(global|local):/;
-    if ($line =~ /^\s*LIBVIRT_QEMU_(\d+\.\d+\.\d+)\s*{\s*$/) {
-        if (defined $vers) {
-            die "malformed syms file";
-        }
-        $vers = $1;
-    } elsif ($line =~ /\s*}\s*;\s*$/) {
-        if (defined $prevvers) {
-            die "malformed syms file";
-        }
-        $prevvers = $vers;
-        $vers = undef;
-    } elsif ($line =~ /\s*}\s*LIBVIRT_QEMU_(\d+\.\d+\.\d+)\s*;\s*$/) {
-        if ($1 ne $prevvers) {
-            die "malformed syms file $1 != $vers";
+    while (defined($line = <FILE>)) {
+        chomp $line;
+        next if $line =~ /^\s*#/;
+        next if $line =~ /^\s*$/;
+        next if $line =~ /^\s*(global|local):/;
+        if ($line =~ /^\s*${prefix}_(\d+\.\d+\.\d+)\s*{\s*$/) {
+            if (defined $vers) {
+                die "malformed syms file";
+            }
+            $vers = $1;
+        } elsif ($line =~ /\s*}\s*;\s*$/) {
+            if (defined $prevvers) {
+                die "malformed syms file";
+            }
+            $prevvers = $vers;
+            $vers = undef;
+        } elsif ($line =~ /\s*}\s*${prefix}_(\d+\.\d+\.\d+)\s*;\s*$/) {
+            if ($1 ne $prevvers) {
+                die "malformed syms file $1 != $vers";
+            }
+            $prevvers = $vers;
+            $vers = undef;
+        } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
+            my $file = $apixpath->find("/api/symbols/function[\@name='$1']/\@file");
+            $$apisref{$1} = {};
+            $$apisref{$1}->{vers} = $vers;
+            $$apisref{$1}->{file} = $file;
+        } else {
+            die "unexpected data $line\n";
         }
-        $prevvers = $vers;
-        $vers = undef;
-    } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
-        my $file = $apixpath->find("/api/symbols/function[\@name='$1']/\@file");
-        $apis{$1} = {};
-        $apis{$1}->{vers} = $vers;
-        $apis{$1}->{file} = $file;
-    } else {
-        die "unexpected data $line\n";
     }
+
+    close FILE;
 }
 
-close FILE;
+my %apis;
+# Get the list of all public APIs and their corresponding version
+parseSymsFile(\%apis, "LIBVIRT", $symslibvirt, "$srcdir/../docs/libvirt-api.xml");
 
+# And the same for the QEMU specific APIs
+parseSymsFile(\%apis, "LIBVIRT_QEMU", $symsqemu, "$srcdir/../docs/libvirt-qemu-api.xml");
 
 # And the same for the LXC specific APIs
-
-open FILE, "<$symslxc"
-    or die "cannot read $symslxc: $!";
-
-$prevvers = undef;
-$vers = undef;
-$apixpath = XML::XPath->new(filename => "$srcdir/../docs/libvirt-lxc-api.xml");
-while (defined($line = <FILE>)) {
-    chomp $line;
-    next if $line =~ /^\s*#/;
-    next if $line =~ /^\s*$/;
-    next if $line =~ /^\s*(global|local):/;
-    if ($line =~ /^\s*LIBVIRT_LXC_(\d+\.\d+\.\d+)\s*{\s*$/) {
-        if (defined $vers) {
-            die "malformed syms file";
-        }
-        $vers = $1;
-    } elsif ($line =~ /\s*}\s*;\s*$/) {
-        if (defined $prevvers) {
-            die "malformed syms file";
-        }
-        $prevvers = $vers;
-        $vers = undef;
-    } elsif ($line =~ /\s*}\s*LIBVIRT_LXC_(\d+\.\d+\.\d+)\s*;\s*$/) {
-        if ($1 ne $prevvers) {
-            die "malformed syms file $1 != $vers";
-        }
-        $prevvers = $vers;
-        $vers = undef;
-    } elsif ($line =~ /\s*(\w+)\s*;\s*$/) {
-        my $file = $apixpath->find("/api/symbols/function[\@name='$1']/\@file");
-        $apis{$1} = {};
-        $apis{$1}->{vers} = $vers;
-        $apis{$1}->{file} = $file;
-    } else {
-        die "unexpected data $line\n";
-    }
-}
-
-close FILE;
+parseSymsFile(\%apis, "LIBVIRT_LXC", $symslxc, "$srcdir/../docs/libvirt-lxc-api.xml");
 
 
 # Some special things which aren't public APIs,
@@ -206,6 +136,8 @@ $apis{virDomainMigrateConfirm3Params}->{vers} = "1.1.0";
 # and driver struct fields. This lets us later match
 # update the driver impls with the public APis.
 
+my $line;
+
 # Group name -> hash of APIs { fields -> api name }
 my %groups;
 my $ingrp;
-- 
2.7.3

--
libvir-list mailing list
libvir-list@xxxxxxxxxx
https://www.redhat.com/mailman/listinfo/libvir-list



[Index of Archives]     [Virt Tools]     [Libvirt Users]     [Lib OS Info]     [Fedora Users]     [Fedora Desktop]     [Fedora SELinux]     [Big List of Linux Books]     [Yosemite News]     [KDE Users]     [Fedora Tools]