Skip to content
Open
Show file tree
Hide file tree
Changes from 2 commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 2 additions & 2 deletions Makefile.am
Original file line number Diff line number Diff line change
Expand Up @@ -13,14 +13,14 @@ bti_CFLAGS = \
$(LIBCURL_CFLAGS) \
$(XML_CFLAGS) \
$(JSON_CFLAGS) \
$(LIBPCRE_CFLAGS) \
$(PCRE2_CFLAGS) \
$(LIBOAUTH_CFLAGS)

bti_LDADD = \
$(LIBCURL_LIBS) \
$(XML_LIBS) \
$(JSON_LIBS) \
$(LIBPCRE_LIBS) \
$(PCRE2_LIBS) \
$(LIBOAUTH_LIBS)

dist_man_MANS = \
Expand Down
33 changes: 23 additions & 10 deletions bti.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,9 @@

#define _GNU_SOURCE

#define is_error(ptr) (ptr == NULL)

#define PCRE2_CODE_UNIT_WIDTH 8
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
Expand All @@ -33,7 +36,7 @@
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <json-c/json.h>
#include <pcre.h>
#include <pcre2.h>
#include <termios.h>
#include <dlfcn.h>
#include <oauth.h>
Expand Down Expand Up @@ -1260,20 +1263,22 @@ static int find_urls(const char *tweet, int **pranges)
"(([a-zA-Z][0-9a-zA-Z+\\-\\.]*:)/{1,3}"
"[0-9a-zA-Z;/~?:@&=+$\\.\\-_'()%]+)"
"(#[0-9a-zA-Z;/?:@&=+$\\.\\-_!~*'()%]+)?";
pcre *re;
pcre2_code *re;
const char *errptr;
int errorcode;
int erroffset;
int ovector[10] = {0,};
//int ovector[10] = {0,};
PCRE2_SIZE *ovector;
const size_t ovsize = sizeof(ovector)/sizeof(*ovector);
int startoffset, tweetlen;
int i, rc;
int rbound = 10;
int rcount = 0;
int *ranges = malloc(sizeof(int) * rbound);

re = pcre_compile(re_magic,
PCRE_NO_AUTO_CAPTURE,
&errptr, &erroffset, NULL);
re = pcre2_compile((PCRE2_SPTR)re_magic, PCRE2_ZERO_TERMINATED,
PCRE2_NO_AUTO_CAPTURE,
&errorcode, (PCRE2_SIZE*) &erroffset, NULL);
if (!re) {
fprintf(stderr, "pcre_compile @%u: %s\n", erroffset, errptr);
exit(1);
Expand All @@ -1282,9 +1287,11 @@ static int find_urls(const char *tweet, int **pranges)
tweetlen = strlen(tweet);
for (startoffset = 0; startoffset < tweetlen; ) {

rc = pcre_exec(re, NULL, tweet, strlen(tweet), startoffset, 0,
ovector, ovsize);
if (rc == PCRE_ERROR_NOMATCH)
pcre2_match_data *match_data;
match_data = pcre2_match_data_create_from_pattern(re, NULL);

rc = pcre2_match(re, (PCRE2_SPTR)tweet, strlen(tweet), startoffset, 0, match_data, NULL);
if (rc == PCRE2_ERROR_NOMATCH)
break;

if (rc < 0) {
Expand All @@ -1293,6 +1300,9 @@ static int find_urls(const char *tweet, int **pranges)
exit(1);
}

ovector = pcre2_get_ovector_pointer(match_data);
fprintf(stderr,"Match succeeded at offset %d to %d\n", (int)ovector[0], (int)ovector[1]);

for (i = 0; i < rc; i += 2) {
if ((rcount+2) == rbound) {
rbound *= 2;
Expand All @@ -1306,7 +1316,10 @@ static int find_urls(const char *tweet, int **pranges)
startoffset = ovector[1];
}

pcre_free(re);
//pcre2_match_data_free(re);
pcre2_code_free(re);

for (int i=0; i<rcount; i+=2) fprintf(stderr,"RANGE %d from %d to %d\n",i,ranges[i],ranges[i+1]);

*pranges = ranges;
return rcount;
Expand Down
3 changes: 2 additions & 1 deletion config.c
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@

#define _GNU_SOURCE

#define PCRE2_CODE_UNIT_WIDTH 8
#include <stdio.h>
#include <stdlib.h>
#include <stddef.h>
Expand All @@ -32,7 +33,7 @@
#include <libxml/xmlmemory.h>
#include <libxml/parser.h>
#include <libxml/tree.h>
#include <pcre.h>
#include <pcre2.h>
#include <termios.h>
#include <dlfcn.h>
#include <oauth.h>
Expand Down
6 changes: 4 additions & 2 deletions configure.ac
Original file line number Diff line number Diff line change
@@ -1,7 +1,8 @@
AC_INIT([bti], [034], [[email protected]])
AC_PREREQ(2.60)

AM_INIT_AUTOMAKE(bti, 034)
#AM_INIT_AUTOMAKE(bti, 034)
AM_INIT_AUTOMAKE

m4_ifdef([AM_SILENT_RULES], [AM_SILENT_RULES([yes])])

Expand All @@ -15,7 +16,8 @@ AC_PATH_PROG([XSLTPROC], [xsltproc])
PKG_PROG_PKG_CONFIG()

PKG_CHECK_MODULES(LIBOAUTH, oauth)
PKG_CHECK_MODULES(LIBPCRE, libpcre)
#PKG_CHECK_MODULES(LIBPCRE2, libpcre2)
PKG_CHECK_MODULES(PCRE2, [libpcre2-8 libpcre2-32])
Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Just curious: why -8 and -32?
On my Debian/unstable system I can see:

/usr/lib/x86_64-linux-gnu/pkgconfig/libpcre2-16.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/libpcre2-32.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/libpcre2-8.pc
/usr/lib/x86_64-linux-gnu/pkgconfig/libpcre2-posix.pc

Copy link
Copy Markdown
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've removed the -32

PKG_CHECK_MODULES([LIBCURL], [libcurl])
PKG_CHECK_MODULES([XML], [libxml-2.0])
PKG_CHECK_MODULES([JSON], [json-c])
Expand Down