Bug#1000010: ohcount: depends on obsolete pcre3 library

2023-12-21 Thread Sylvestre Ledru

oh, cool, thanks :)

I will upload it /i/n a second


Le 21/12/2023 à 21:33, Yavor Doganov a écrit :

Control: tags -1 + patch

Please find a patch attached.

Bug#1000010: ohcount: depends on obsolete pcre3 library

2023-12-21 Thread Yavor Doganov
Control: tags -1 + patch

Please find a patch attached.
Description: Port to PCRE2.
Bug-Debian: https://bugs.debian.org/110
Author: Yavor Doganov 
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 
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include 
 
 /**
  * @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 
+#define PCRE2_CODE_UNIT_WIDTH 8
+#include 
 
 // 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, , , NULL);
-
-   if (pcre_exec(keyword, NULL, p, mystrnlen(p, 1), 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,
+   , , NULL);
+   md = pcre2_match_data_create(30, NULL);
+   if (pcre2_match(keyword, (PCRE2_SPTR)p, mystrnlen(p, 1),
+   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, , , NULL);
-
-   if (pcre_exec(construct, NULL, p, mystrnlen(p, 1), 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,
+ , , NULL);
+
+   if (pcre2_match(construct, (PCRE2_SPTR)p, mystrnlen(p, 1),
+   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;