Control: tags -1 + patch

Please find a patch attached.
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/1000010
Author: Yavor Doganov <ya...@gnu.org>
Forwarded: no
Last-Update: 2023-12-21
---

--- ohcount-4.0.0.orig/build
+++ ohcount-4.0.0/build
@@ -31,7 +31,7 @@
   # You shouldn't have to change the following.
   CFLAGS="-fno-common -g"
   WARN="-Wall -Wno-parentheses"
-  SHARED="-dynamiclib -L$LIB_DIR -lpcre"
+  SHARED="-dynamiclib -L$LIB_DIR -lpcre2-8"
   SHARED_NAME=libohcount.dylib
   RB_SHARED="-dynamic -bundle -lruby"
   RB_SHARED_NAME=ohcount.bundle
@@ -97,7 +97,7 @@
   build_parser_o
   echo "Building Ohcount"
   mkdir -p bin/
-  sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre -lmagic" || exit 1
+  sh -c "$cc src/ohcount.c $files -o bin/ohcount -lpcre2-8 -lmagic" || exit 1
 }
 
 build_test_suite()
@@ -105,7 +105,7 @@
   build_hash_headers
   build_parser_o
   echo "Building test suite"
-  sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre 
-lmagic" \
+  sh -c "$cc test/unit/all_tests.c $files -o test/unit/run_tests -lpcre2-8 
-lmagic" \
     || exit 1
 }
 
@@ -127,10 +127,10 @@
        mkdir -p ruby/$arch
     echo $cc $RB_SHARED ruby/ohcount_wrap.c $files -o 
ruby/$arch/$RB_SHARED_NAME \
     -I$RUBY_HEADER_DIR -I$RUBY_CONFIG_DIR  
-I/usr/include/$rbconfig_arch/ruby-$RUBY_VERSION  \
-    -lpcre -lmagic
+    -lpcre2-8 -lmagic
   sh -c "$cc $RB_SHARED ruby/ohcount_wrap.c $files -o 
ruby/$arch/$RB_SHARED_NAME \
     -I$RUBY_HEADER_DIR -I$RUBY_CONFIG_DIR  
-I/usr/include/$rbconfig_arch/ruby-$RUBY_VERSION  \
-    -lpcre -lmagic" || exit 1
+    -lpcre2-8 -lmagic" || exit 1
   sh -c "cd test/unit/ruby && ruby ruby_test.rb" || exit 1
 }
 
--- ohcount-4.0.0.orig/src/structs.h
+++ ohcount-4.0.0/src/structs.h
@@ -4,7 +4,8 @@
 #ifndef OHCOUNT_STRUCTS_H
 #define OHCOUNT_STRUCTS_H
 
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
 
 /**
  * @struct License
@@ -24,7 +25,7 @@
   const char *re;
 
   /** PCRE flags for re. (Typically PCRE_CASELESS or PCRE_MULTILINE). */
-  int re_flags;
+  uint32_t re_flags;
 
   /**
    * A PCRE regular expression for text that matches re, but should not match
@@ -33,13 +34,13 @@
   const char *exclude_re;
 
   /** PCRE flags for exclude_re. */
-  int exclude_re_flags;
+  uint32_t exclude_re_flags;
 
   /** The PCRE object for re. (This field is set automatically.) */
-  pcre *regexp;
+  pcre2_code *regexp;
 
   /** The PCRE object for exclude_re. (This field is set automatically.) */
-  pcre *exclude_regexp;
+  pcre2_code *exclude_regexp;
 
 } License;
 
--- ohcount-4.0.0.orig/src/detector.c
+++ ohcount-4.0.0/src/detector.c
@@ -889,7 +889,8 @@
   return NULL; // only blanks
 }
 
-#include <pcre.h>
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include <pcre2.h>
 
 // strnlen is not available on OS X, so we roll our own
 size_t mystrnlen(const char *begin, size_t maxlen) {
@@ -906,24 +907,35 @@
          return NULL;
 
        /* prepare regular expressions */
-       const char *error;
-       int erroffset;
+       int error;
+       PCRE2_SIZE erroffset;
 
        /* try harder with optional spaces */
-       pcre *keyword;
-       keyword = 
pcre_compile("^\\s*(ensure|content|notify|require|source)\\s+=>",
-                       PCRE_MULTILINE, &error, &erroffset, NULL);
-
-       if (pcre_exec(keyword, NULL, p, mystrnlen(p, 10000), 0, 0, NULL, 0) > 
-1)
+       pcre2_code *keyword;
+       pcre2_match_data *md;
+       keyword = pcre2_compile((PCRE2_SPTR)
+                               
"^\\s*(ensure|content|notify|require|source)\\s+=>",
+                               PCRE2_ZERO_TERMINATED, PCRE2_MULTILINE,
+                               &error, &erroffset, NULL);
+       md = pcre2_match_data_create(30, NULL);
+       if (pcre2_match(keyword, (PCRE2_SPTR)p, mystrnlen(p, 10000),
+                       0, 0, md, NULL) > -1) {
+               pcre2_match_data_free(md);
                return LANG_PUPPET;
+       }
 
        /* check for standard puppet constructs */
-       pcre *construct;
-       construct = 
pcre_compile("^\\s*(define\\s+[\\w:-]+\\s*\\(|class\\s+[\\w:-]+(\\s+inherits\\s+[\\w:-]+)?\\s*[\\({]|node\\s+\\'?[\\w:\\.-]+\\'?\\s*{|import\\s+\"|include\\s+[\"']?[\\w:-][\"']?)",
-                       PCRE_MULTILINE, &error, &erroffset, NULL);
-
-       if (pcre_exec(construct, NULL, p, mystrnlen(p, 10000), 0, 0, NULL, 0) > 
-1)
+       pcre2_code *construct;
+       construct = 
pcre2_compile((PCRE2_SPTR)"^\\s*(define\\s+[\\w:-]+\\s*\\(|class\\s+[\\w:-]+(\\s+inherits\\s+[\\w:-]+)?\\s*[\\({]|node\\s+\\'?[\\w:\\.-]+\\'?\\s*{|import\\s+\"|include\\s+[\"']?[\\w:-][\"']?)",
+                                 PCRE2_ZERO_TERMINATED, PCRE2_MULTILINE,
+                                 &error, &erroffset, NULL);
+
+       if (pcre2_match(construct, (PCRE2_SPTR)p, mystrnlen(p, 10000),
+                       0, 0, md, NULL) > -1) {
+               pcre2_match_data_free(md);
                return LANG_PUPPET;
+       }
+       pcre2_match_data_free(md);
 
        return LANG_PASCAL;
 }
@@ -934,11 +946,19 @@
     return NULL;
 
   // Check for a perl shebang on first line of file
-       const char *error;
-       int erroffset;
-       pcre *re = pcre_compile("#![^\\n]*perl", PCRE_CASELESS, &error, 
&erroffset, NULL);
-  if (pcre_exec(re, NULL, contents, mystrnlen(contents, 100), 0, 
PCRE_ANCHORED, NULL, 0) > -1)
+  int error;
+  PCRE2_SIZE erroffset;
+  pcre2_match_data *md;
+  pcre2_code *re = pcre2_compile((PCRE2_SPTR)"#![^\\n]*perl",
+                                 PCRE2_ZERO_TERMINATED, PCRE2_CASELESS,
+                                 &error, &erroffset, NULL);
+  md = pcre2_match_data_create_from_pattern(re, NULL);
+  if (pcre2_match(re, (PCRE2_SPTR)contents, mystrnlen(contents, 100),
+                  0, PCRE2_ANCHORED, md, NULL) > -1) {
+    pcre2_match_data_free(md);
     return LANG_PERL;
+  }
+  pcre2_match_data_free(md);
 
   // Check for prolog :- rules
   if (strstr(contents, ":- ") || strstr(contents, ":-\n"))
--- ohcount-4.0.0.orig/src/licenses.c
+++ ohcount-4.0.0/src/licenses.c
@@ -15,7 +15,7 @@
     "http://www.opensource.org/licenses/afl-3.0.php";,
     "Academic Free License",
     "\\bAcademic\\s*Free\\s*License\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -25,7 +25,7 @@
     "http://www.opensource.org/licenses/apl1.0.php";,
     "Adaptive Public License",
     "\\bAdaptive\\s*Public\\s*License\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -35,7 +35,7 @@
     "http://www.affero.org/oagpl.html";,
     "GNU Affero General Public License",
     "\\bGNU\\s+Affero\\s+General\\s+Public\\s+License\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -45,7 +45,7 @@
     "http://www.opensource.org/licenses/apachepl.php";,
     "Apache Software License",
     
"(\\bApache\\s*Software\\s*License(?![\\s,]*2))|(\\bapache\\s*license(?![\\s,]*2))",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -55,7 +55,7 @@
     "http://www.opensource.org/licenses/apache2.0.php";,
     "Apache License, 2.0",
     "\\bapache\\s+(software\\s+)?license,?\\s+(version\\s+)?2",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -65,7 +65,7 @@
     "http://www.opensource.org/licenses/apsl-2.0.php";,
     "Apple Public Source License",
     "\\bApple\\s*Public\\s*Source\\s*License\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -75,7 +75,7 @@
     "http://www.opensource.org/licenses/artistic-license.php";,
     "Artistic license",
     "\\bartistic\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -85,7 +85,7 @@
     "http://www.opensource.org/licenses/attribution.php";,
     "Attribution Assurance Licenses",
     "\\battribution\\s*assurance\\s*license(s)?\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -95,7 +95,7 @@
     "http://www.boost.org/LICENSE_1_0.txt";,
     "Boost Software License - Version 1.0 - August 17th, 2003",
     "\\bboost\\s*software\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -105,7 +105,7 @@
     "http://www.opensource.org/licenses/bsd-license.php";,
     "New BSD license",
     "(\\bbsd\\s*license\\b)|(The Regents of the University of California)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -115,7 +115,7 @@
     "http://www.cecill.info/licences/Licence_CeCILL_V2-en.html";,
     "CeCILL license",
     "\\bcecill\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -125,7 +125,7 @@
     "http://www.cecill.info/licences/Licence_CeCILL-B_V1-en.html";,
     "CeCILL-B license",
     "\\bcecill-b\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -135,7 +135,7 @@
     "http://www.cecill.info/licences/Licence_CeCILL-C_V1-en.html";,
     "CeCILL-C license",
     "\\bcecill-c\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -145,7 +145,7 @@
     "http://www.opensource.org/licenses/ca-tosl1.1.php";,
     "Computer Associates Trusted Open Source License 1.1",
     "\\bcomputer\\s*associates\\s*trusted\\s*open\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -155,7 +155,7 @@
     "http://www.opensource.org/licenses/cddl1.php";,
     "Common Development and Distribution License",
     "\\bcommon\\s*development\\s*and\\s*distribution\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -165,7 +165,7 @@
     "http://www.opensource.org/licenses/cpl1.0.php";,
     "Common Public License 1.0",
     "\\bcommon\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -175,7 +175,7 @@
     "http://www.opensource.org/licenses/cuaoffice.php";,
     "CUA Office Public License Version 1.0",
     "\\bCUA\\s*office\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -185,7 +185,7 @@
     "http://www.opensource.org/licenses/eudatagrid.php";,
     "EU DataGrid Software License",
     "\\beu\\s*datagrid\\s*software\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -195,7 +195,7 @@
     "http://www.opensource.org/licenses/eclipse-1.0.php";,
     "Eclipse Public License",
     "\\beclipse\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -205,7 +205,7 @@
     "http://www.opensource.org/licenses/ecl1.php";,
     "Educational Community License",
     "\\beducational\\s*community\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -215,7 +215,7 @@
     "http://www.opensource.org/licenses/eiffel.php";,
     "Eiffel Forum License",
     "\\beiffel\\s*forum\\s*license(?![,V\\s]*2)\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -225,7 +225,7 @@
     "http://www.opensource.org/licenses/ver2_eiffel.php";,
     "Eiffel Forum License V2.0",
     "\\beiffel\\s*forum\\s*license [,V\\s]*2",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -235,7 +235,7 @@
     "http://www.opensource.org/licenses/entessa.php";,
     "Entessa Public License",
     "\\bentessa\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -245,7 +245,7 @@
     "http://www.opensource.org/licenses/fair.php";,
     "Fair License",
     "\\bfair\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -255,7 +255,7 @@
     "http://www.opensource.org/licenses/frameworx.php";,
     "Frameworx License",
     "\\bframeworx\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -265,7 +265,7 @@
     "http://www.gnu.org/licenses/gpl-3.0.html";,
     "GNU General Public License 3.0",
     "\\b(GNU GENERAL PUBLIC LICENSE|GPL).{0,100}(Version)? 3.{0,50}later",
-    PCRE_CASELESS | PCRE_MULTILINE,
+    PCRE2_CASELESS | PCRE2_MULTILINE,
     NULL,
     0,
     NULL, NULL
@@ -275,9 +275,9 @@
     "http://www.gnu.org/licenses/gpl-3.0.html";,
     "GNU General Public License 3.0",
     "GNU (GENERAL PUBLIC LICENSE|GPL).{0,100}(Version |v)3",
-    PCRE_CASELESS | PCRE_MULTILINE,
+    PCRE2_CASELESS | PCRE2_MULTILINE,
     "((at your option) any later version)|(GENERAL PUBLIC LICENSE.*GENERAL 
PUBLIC LICENSE)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL, NULL
   },
   {
@@ -285,7 +285,7 @@
     "http://www.gnu.org/licenses/lgpl-3.0.html";,
     "GNU Lesser General Public License 3.0",
     
"((\\blgpl\\b)|(\\bgnu\\s*(library|lesser)\\s*(general\\s*)?(public\\s*)?license\\b)|(\\b(lesser|library)\\s*gpl\\b)).{0,10}(\\bas
 published by the free software 
foundation\\b)?.{0,10}(\\bversion\\b)?.{0,10}\\b3(\\.0)?\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -295,7 +295,7 @@
     "http://www.opensource.org/licenses/gpl-license.php";,
     "GNU General Public License (GPL)",
     
"(\\bgpl\\b)|(\\bgplv2\\b)|(\\bgnu\\s*general\\s*public\\s*license\\b)|(\\bwww\\.gnu\\.org\\/licenses\\/gpl\\.txt\\b)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -305,7 +305,7 @@
     "http://www.opensource.org/licenses/lgpl-license.php";,
     "GNU Library or \"Lesser\" GPL (LGPL)",
     
"(\\blgpl\\b)|(\\bgnu\\s*(library|lesser)\\s*(general\\s*)?(public\\s*)?license\\b)|(\\b(lesser|library)\\s*gpl\\b)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -315,7 +315,7 @@
     "http://www.opensource.org/licenses/historical.php";,
     "Historical Permission Notice and Disclaimer",
     "\\bhistorical\\s*permission\\s*notice\\s*and\\s*disclaimer\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -325,7 +325,7 @@
     "http://i9os.googlecode.com/svn/trunk/Documentation/Licenses/i9_License";,
     "i9 License",
     "\\bi9\\s*\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -335,7 +335,7 @@
     "http://www.opensource.org/licenses/ibmpl.php";,
     "IBM Public License",
     "\\bibm\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -345,7 +345,7 @@
     "http://www.opensource.org/licenses/intel-open-source-license.php";,
     "Intel Open Source License",
     "\\bintel\\s*open\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -355,7 +355,7 @@
     "http://www.opensource.org/licenses/jabberpl.php";,
     "Jabber Open Source License",
     "\\bjabber\\s*open\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -365,7 +365,7 @@
     "http://www.opensource.org/licenses/plan9.php";,
     "Lucent Public License (Plan9)",
     "\\blucent\\s*public\\s*license[\\s(]*plan9",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -375,7 +375,7 @@
     "http://www.opensource.org/licenses/lucent1.02.php";,
     "Lucent Public License Version 1.02",
     "\\blucent\\s*public\\s*license\\s*(version)?\\s+1",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -385,7 +385,7 @@
     "http://www.opensource.org/licenses/mit-license.php";,
     "MIT license",
     "(\\bmit\\s*license\\b)|(\\bMIT\\/X11\\s*licensed?\\b)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -395,7 +395,7 @@
     "http://www.opensource.org/licenses/mitrepl.php";,
     "MITRE Collaborative Virtual Workspace License (CVW License)",
     "\\bmitre\\s*collaborative\\s*virtual\\s*workspace\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -405,7 +405,7 @@
     "http://www.opensource.org/licenses/motosoto.php";,
     "Motosoto License",
     "\\bmotosoto\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -415,7 +415,7 @@
     "http://www.opensource.org/licenses/mozilla1.0.php";,
     "Mozilla Public License 1.0 (MPL)",
     "\\bmozilla\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -425,7 +425,7 @@
     "http://www.opensource.org/licenses/mozilla1.1.php";,
     "Mozilla Public License 1.1 (MPL)",
     "\\bmozilla\\s*public\\s*license 1\\.1\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -435,7 +435,7 @@
     "http://www.opensource.org/licenses/nasa1.3.php";,
     "NASA Open Source Agreement 1.3",
     "\\bnasa\\s*open\\s*source\\s*agreement\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -445,7 +445,7 @@
     "http://www.opensource.org/licenses/naumen.php";,
     "Naumen Public License",
     "\\bnaumen\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -455,7 +455,7 @@
     "http://www.opensource.org/licenses/nethack.php";,
     "Nethack General Public License",
     "\\bnethack\\s*general\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -465,7 +465,7 @@
     "http://www.opensource.org/licenses/nokia.php";,
     "Nokia Open Source License",
     "\\bnokia\\s*open\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -475,7 +475,7 @@
     "http://www.opensource.org/licenses/oclc2.php";,
     "OCLC Research Public License 2.0",
     "\\boclc\\s*research\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -485,7 +485,7 @@
     "http://www.opensource.org/licenses/opengroup.php";,
     "Open Group Test Suite License",
     "\\bopen\\s*group\\s*test\\s*suite\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -495,7 +495,7 @@
     "http://www.opensource.org/licenses/osl-3.0.php";,
     "Open Software License",
     "\\bopen\\s*software\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -505,7 +505,7 @@
     "http://www.opensource.org/licenses/php.php";,
     "PHP License",
     "\\bphp\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -515,7 +515,7 @@
     "http://www.opensource.org/licenses/pythonpl.php";,
     "Python license",
     "\\bpython\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -525,7 +525,7 @@
     "http://www.opensource.org/licenses/PythonSoftFoundation.php";,
     "Python Software Foundation License",
     "\\bpython\\s*software\\s*foundation\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -535,7 +535,7 @@
     "http://www.opensource.org/licenses/qtpl.php";,
     "Qt Public License (QPL)",
     "\\bqt\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -545,7 +545,7 @@
     "http://www.opensource.org/licenses/real.php";,
     "RealNetworks Public Source License V1.0",
     "\\brealnetworks\\s*public\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -555,7 +555,7 @@
     "http://www.opensource.org/licenses/rpl.php";,
     "Reciprocal Public License",
     "\\breciprocal\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -565,7 +565,7 @@
     "http://www.opensource.org/licenses/ricohpl.php";,
     "Ricoh Source Code Public License",
     "\\bricoh\\s*source\\s*code\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -575,7 +575,7 @@
     "http://www.opensource.org/licenses/sleepycat.php";,
     "Sleepycat License",
     "\\bsleepycat\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -585,7 +585,7 @@
     "http://www.sugarcrm.com/SPL";,
     "SugarCRM Public License 1.1.3",
     "\\bsugar\\s*public\\s*license\\s*version\\s*1\\.1\\.3\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -595,7 +595,7 @@
     "http://www.opensource.org/licenses/sisslpl.php";,
     "Sun Industry Standards Source License (SISSL)",
     "\\bsun\\s*industry\\s*standards\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -605,7 +605,7 @@
     "http://www.opensource.org/licenses/sunpublic.php";,
     "Sun Public License",
     "\\bsun\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -615,7 +615,7 @@
     "http://www.opensource.org/licenses/sybase.php";,
     "Sybase Open Watcom Public License 1.0",
     "\\bsybase\\s*open\\s*watcom\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -625,7 +625,7 @@
     "http://www.opensource.org/licenses/UoI-NCSA.php";,
     "University of Illinois/NCSA Open Source License",
     "\\buniversity\\s*of\\s*illinois\\/ncsa\\s*open\\s*source\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -635,7 +635,7 @@
     "http://www.opensource.org/licenses/vovidapl.php";,
     "Vovida Software License v. 1.0",
     "\\bvovida\\s*software\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -645,7 +645,7 @@
     "http://www.opensource.org/licenses/W3C.php";,
     "W3C License",
     "\\bw3c\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -655,7 +655,7 @@
     "http://www.opensource.org/licenses/wxwindows.php";,
     "wxWindows Library License",
     "\\bwxwindows\\s*library\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -665,7 +665,7 @@
     "http://www.opensource.org/licenses/xnet.php";,
     "X.Net License",
     "\\bx\\.net\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -675,7 +675,7 @@
     "http://www.opensource.org/licenses/zpl.php";,
     "Zope Public License",
     "\\bzope\\s*public\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -685,7 +685,7 @@
     "http://www.opensource.org/licenses/zlib-license.php";,
     "zlib/libpng license",
     "\\bzlib\\/libpng\\s*license\\b",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -695,7 +695,7 @@
     "",
     "Apache-ish License",
     "(\\bapache-style.*license\\b)|(\\bapache-like.*license\\b)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -705,7 +705,7 @@
     "",
     "BSD-ish License",
     "Copyright\\s.{1,40}All rights reserved.{0,40}Redistribution and use in 
source and binary forms, with or without.{0,20}modification, are permitted 
provided that the following conditions.{0,20}\\sare met.{1,40}Redistributions 
of source code must retain the above copyright\\s.*notice, this list of 
conditions and the following disclaimer\\.\\s+.*Redistributions in binary form 
must reproduce the above.*copyright\\s+.{0,10}notice, this list of conditions 
and the following.*disclaimer in the\\s+.*documentation.*(The (name|names) of 
the (author|contributors) may not|Neither the name of the).*be used to endorse 
or promote\\s+.*products\\s+.*derived\\s+.*from this software without specific 
prior written\\s+.*permission.*HOWEVER\\s+.*CAUSED AND ON ANY.*THEORY OF 
LIABILITY, WHETHER IN CONTRACT",
-    PCRE_MULTILINE,
+    PCRE2_MULTILINE,
     "The Regents of the University of California",
     0,
     NULL, NULL
@@ -715,9 +715,9 @@
     "",
     "BSD-ish (2 clause) License",
     "Copyright\\s.{1,60}All rights reserved.{1,40}Redistribution and use in 
source and binary forms, with or without.{0,20}modification, are permitted 
provided that the following conditions.{0,20}\\sare 
met.{0,20}\\s{1,20}.{0,20}Redistributions of source code must retain the above 
copyright\\s+.*notice, this list of conditions and the following 
disclaimer.\\s+.*Redistributions in binary form must reproduce the above 
copyright\\s+.*notice, this list of conditions and the following disclaimer in 
the\\s+.*documentation and\\/or other materials provided with the 
distribution\\.\\s+.*HOWEVER CAUSED AND ON ANY.*THEORY OF LIABILITY, WHETHER IN 
CONTRACT",
-    PCRE_MULTILINE,
+    PCRE2_MULTILINE,
     "(The Regents of the University of California)|(used to endorse or 
promote\\s+.*products\\s+.*prior\\s+.*written\\s+.*permission\\.)",
-    PCRE_MULTILINE,
+    PCRE2_MULTILINE,
     NULL, NULL
   },
   {
@@ -725,7 +725,7 @@
     "",
     "WTF Public License",
     
"(\\bwtfpl\\b)|(\\bwtf\\s*public\\s*license\\b)|(\\b(do\\s*)?what\\s*the\\s*\\fuck\\s*public\\s*license\\b)",
-    PCRE_CASELESS,
+    PCRE2_CASELESS,
     NULL,
     0,
     NULL, NULL
@@ -738,24 +738,26 @@
 void compile_regexps() {
   if (license_map_length == 0)
     return;
-  const char *err;
-  int erroffset;
+  int err;
+  PCRE2_SIZE erroffset;
   int i;
   for (i = 0; i < license_map_length; i++) {
     License *l = &license_map[i];
-    int flags;
+    uint32_t flags;
     if (l->re) {
       flags = l->re_flags;
-      if (flags & PCRE_MULTILINE)
-        flags |= PCRE_DOTALL;
-      l->regexp = pcre_compile(l->re, flags, &err, &erroffset, NULL);
+      if (flags & PCRE2_MULTILINE)
+        flags |= PCRE2_DOTALL;
+      l->regexp = pcre2_compile((PCRE2_SPTR)l->re, PCRE2_ZERO_TERMINATED,
+                                flags, &err, &erroffset, NULL);
     }
     if (l->exclude_re) {
       flags = l->exclude_re_flags;
-      if (flags & PCRE_MULTILINE)
-        flags |= PCRE_DOTALL;
-      l->exclude_regexp = pcre_compile(l->exclude_re, flags, &err, &erroffset,
-                                       NULL);
+      if (flags & PCRE2_MULTILINE)
+        flags |= PCRE2_DOTALL;
+      l->exclude_regexp = pcre2_compile((PCRE2_SPTR)l->exclude_re,
+                                        PCRE2_ZERO_TERMINATED,
+                                        flags, &err, &erroffset, NULL);
     }
   }
 }
@@ -788,8 +790,10 @@
 
   char *p, *q;
   int i, j, k;
-  int ovector[30]; // recommended by PCRE
+  pcre2_match_data* md;
+  PCRE2_SIZE *ovector;
   ParsedLanguageList *iter_language;
+  md = pcre2_match_data_create(30, NULL);
   iter_language = 
ohcount_sourcefile_get_parsed_language_list(sourcefile)->head;
   if (iter_language) {
     int potential_licenses_s[license_map_length];
@@ -803,6 +807,7 @@
 
       char *buffer = malloc(buffer_len+1);
       if (buffer == NULL) {
+        pcre2_match_data_free(md);
         fprintf(stderr, "out of memory in ohcount_detect_license");
         exit(-1);
       }
@@ -825,13 +830,14 @@
       for (j = 0; j < license_map_length; j++) {
         potential_licenses_s[j] = -1;
         potential_licenses_e[j] = -1;
-        if (pcre_exec(license_map[j].regexp, NULL, buffer, q - buffer, 0, 0,
-                      ovector, 30) >= 0) {
-          int m0 = ovector[0], m1 = ovector[1];
+        if (pcre2_match(license_map[j].regexp, (PCRE2_SPTR)buffer,
+                        q - buffer, 0, 0, md, NULL) >= 0) {
+          ovector = pcre2_get_ovector_pointer(md);
+          int m0 = (int) ovector[0], m1 = (int) ovector[1];
           // Exclude terms that may not exist in the license.
           if (license_map[j].exclude_re &&
-              pcre_exec(license_map[j].exclude_regexp, NULL, buffer + m0, m1 - 
m0,
-                        0, 0, ovector, 30) >= 0)
+              pcre2_match(license_map[j].exclude_regexp, (PCRE2_SPTR)buffer
+                          + m0, m1 - m0, 0, 0, md, NULL) >= 0)
             continue;
           potential_licenses_s[j] = m0;
           potential_licenses_e[j] = m1;
@@ -880,6 +886,7 @@
       }
     }
   }
+  pcre2_match_data_free(md);
 
   return list;
 }

Reply via email to