Here's a new patch that I think better implements support for architecture 
wildcards for quinn-diff. This uses the 'Dpkg::Arch' Perl module directly via 
an embedded Perl interpreter. The old patch should be discarded.

This patch leaves out autogenerated files from autoreconf.

-- 
Regards,
Andres
diff --git a/configure.in b/configure.in
index b64cf24..6a02624 100644
--- a/configure.in
+++ b/configure.in
@@ -82,6 +82,12 @@ esac
 dnl Checks for libraries.
 dnl AC_CHECK_LIB(glib, g_hash_table_lookup)
 AM_PATH_GLIB_2_0()
+AC_CHECK_LIB(perl, main,
+  [PERL_CFLAGS=$(perl -MExtUtils::Embed -e ccopts)
+   PERL_LDFLAGS=$(perl -MExtUtils::Embed -e ldopts)],
+)
+AC_SUBST([PERL_CFLAGS])
+AC_SUBST([PERL_LDFLAGS])
 
 dnl Checks for header files.
 AC_HEADER_STDC
diff --git a/debian/control b/debian/control
index 986769f..e187295 100644
--- a/debian/control
+++ b/debian/control
@@ -2,7 +2,7 @@ Source: quinn-diff
 Section: devel
 Priority: extra
 Maintainer: Luk Claes <l...@debian.org>
-Build-Depends: libglib2.0-dev, docbook-utils
+Build-Depends: libglib2.0-dev, libperl-dev, docbook-utils
 Standards-Version: 3.8.0
 
 Package: quinn-diff
diff --git a/src/Makefile.am b/src/Makefile.am
index f37d93c..c10c414 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -1,4 +1,4 @@
 bin_PROGRAMS = quinn-diff
 quinn_diff_SOURCES = error.c nfmalloc.c xmalloc.c getopt.c getopt1.c init.c list.c arch_specific.c vercmp.c output.c utils.c parse_sources.c parse_packages.c main.c arch_specific.h common.h error.h getopt.h init.h list.h nfmalloc.h output.h parse_sources.h parse_packages.h utils.h vercmp.h xmalloc.h globals.h
-quinn_diff_LDADD = @EFENCE@ @CCMALLOC@ @GLIB_LIBS@
-AM_CFLAGS = @GLIB_CFLAGS@
+quinn_diff_LDADD = @EFENCE@ @CCMALLOC@ @GLIB_LIBS@ @PERL_LDFLAGS@
+AM_CFLAGS = @GLIB_CFLAGS@ @PERL_CFLAGS@
diff --git a/src/main.c b/src/main.c
index b899e0d..693e31f 100644
--- a/src/main.c
+++ b/src/main.c
@@ -33,10 +33,28 @@
 #define GLOBAL
 #include "globals.h"
 
+/* This is used in utils.c in_arch_list() for architecture wildcard support
+ * via Dpkg::Arch Perl module */
+PerlInterpreter *my_perl;
+
 int
 main (int argc, char **argv)
 {
 
+  /* Initialize, allocate, and construct the Perl interpreter */
+  PERL_SYS_INIT(&argc, &argv);
+  my_perl = perl_alloc();
+  perl_construct(my_perl);
+
+  /* Run the interpreter embedded and exit at perl_destruct() */
+  char *embedding[] = { "", "-e", "0" };
+  perl_parse(my_perl, NULL, 3, embedding, NULL);
+  PL_exit_flags |= PERL_EXIT_DESTRUCT_END;
+  perl_run(my_perl);
+
+  /* Load the Dpkg::Arch Perl module as 'use Dpkg::Arch qw(debarch_is)' */
+  load_module(0, newSVpvs("Dpkg::Arch"), NULL, newSVpvs("debarch_is"));
+
   sources_info *sources;
   packages_info *packages;
 
@@ -103,6 +121,9 @@ main (int argc, char **argv)
   xfree (sources);
   xfree (packages);
   xfree (packages_architecture);
+  perl_destruct(my_perl);
+  perl_free(my_perl);
+  PERL_SYS_TERM();
 
   return (0);
 
diff --git a/src/utils.c b/src/utils.c
index 3cbd674..6e962a8 100644
--- a/src/utils.c
+++ b/src/utils.c
@@ -25,6 +25,9 @@
 #include "utils.h"
 #include "xmalloc.h"
 
+/* Use the interpreter from main.c */
+extern PerlInterpreter *my_perl;
+
 /* Two common functions used by all the hash tables */
 
 /*
@@ -287,20 +290,32 @@ xstrdup (const char *s)
 boolean
 in_arch_list(const char *arch_list, const char *arch)
 {
-  char **archs;
-  int i;
-
-  if ((archs = g_strsplit(arch_list," ",0)) != NULL)
-    {
-      for ( i = 0 ; archs[i] ; i++ )
-	{
-	  if (!strcmp(archs[i],arch))
-	    {
-	      g_strfreev(archs);
-	      return TRUE;
-	    }
-	}
-      g_strfreev(archs);
+  char *archs = strdup(arch_list);
+  char *archtok = strtok(archs, " ");
+  char *perl_code = malloc(1);
+
+  while (archtok != NULL)
+  {
+    /* First create our perl code */
+    int size = strlen("debarch_is(") + strlen(arch) + strlen(",") +
+      strlen(archtok) + strlen(")") + 1;
+    perl_code = (char*)realloc(perl_code,size);
+    if (!perl_code)
+      fubar (SYSERR, "in_arch_list: could not allocate memory for perl code.");
+    sprintf(perl_code, "debarch_is(%s,%s)",arch,archtok);
+
+    /* Now run the code. We check the scalar value (which is an integer)
+     * returned from the debarch_is() subroutine */
+    if(SvIVx(eval_pv(perl_code, TRUE))) {
+      free(perl_code);
+      free(archs);
+      return TRUE;
     }
+
+    /* Go on to the next architecture in the list */
+    archtok = strtok(NULL, " ");
+  }
+  free(perl_code);
+  free(archs);
   return FALSE;
 }
diff --git a/src/utils.h b/src/utils.h
index e70784b..249450e 100644
--- a/src/utils.h
+++ b/src/utils.h
@@ -19,6 +19,10 @@
 #ifndef __UTILS_H__
 #define __UTILS_H__
 
+/* For supporting architecture wildcards via Dpkg::Arch Perl module */
+#include <EXTERN.h>
+#include <perl.h>
+
 #include <glib.h>
 #include "list.h"
 

Reply via email to