add regex compatability to utils and enable it for serenity OS

This commit is contained in:
Vincent Sanders 2019-10-12 14:50:49 +01:00
parent 4372104e0e
commit 4745fcf1c7
5 changed files with 130 additions and 14 deletions

View File

@ -28,10 +28,10 @@
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <regex.h>
#include <dom/dom.h>
#include "utils/config.h"
#include "utils/regex.h"
#include "utils/corestrings.h"
#include "utils/log.h"
#include "utils/nsurl.h"

View File

@ -26,11 +26,11 @@
#include <string.h>
#include "utils/config.h"
#include "utils/utils.h"
#include "utils/log.h"
#include "utils/nsurl.h"
#include "utils/nsoption.h"
#include "utils/config.h"
#include "netsurf/bitmap.h"
#include "netsurf/content.h"
#include "netsurf/plotters.h"

View File

@ -16,8 +16,8 @@
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef _NETSURF_UTILS_CONFIG_H_
#define _NETSURF_UTILS_CONFIG_H_
#ifndef NETSURF_UTILS_CONFIG_H_
#define NETSURF_UTILS_CONFIG_H_
#include <stddef.h>
@ -35,10 +35,10 @@
char *strndup(const char *s, size_t n);
#endif
#if (defined(_GNU_SOURCE) || \
defined(__APPLE__) || \
defined(__HAIKU__) || \
defined(__OpenBSD__) &&\
#if ((defined(_GNU_SOURCE) || \
defined(__APPLE__) || \
defined(__HAIKU__) || \
defined(__OpenBSD__)) && \
!defined(__serenity__))
#define HAVE_STRCASESTR
#else
@ -68,14 +68,18 @@ char *strchrnul(const char *s, int c);
#endif
#define HAVE_SYS_SELECT
#define HAVE_INETATON
#define HAVE_POSIX_INET_HEADERS
#if (defined(_WIN32))
#undef HAVE_INETATON
#undef HAVE_SYS_SELECT
#undef HAVE_POSIX_INET_HEADERS
#endif
#define HAVE_INETATON
#if (defined(_WIN32) || \
defined(__serenity__))
#undef HAVE_INETATON
#endif
#define HAVE_INETPTON
#if (defined(_WIN32))
#undef HAVE_INETPTON
@ -113,10 +117,16 @@ char *realpath(const char *path, char *resolved_path);
#endif
#define HAVE_SCANDIR
#if (defined(_WIN32))
#if (defined(_WIN32) || \
defined(__serenity__))
#undef HAVE_SCANDIR
#endif
#define HAVE_REGEX
#if (defined(__serenity__))
#undef HAVE_REGEX
#endif
/* This section toggles build options on and off.
* Simply undefine a symbol to turn the relevant feature off.
*
@ -142,7 +152,7 @@ char *realpath(const char *path, char *resolved_path);
#define WITH_MMAP
#endif
/* amiga */
/* IPv6 */
#if (defined(__amigaos4__) || \
defined(__AMIGA__) || \
defined(nsatari) || \

63
utils/regex.h Normal file
View File

@ -0,0 +1,63 @@
/*
* Copyright 2019 Vincent Sanders <vince@netxurf-browser.org>
*
* This file is part of NetSurf, http://www.netsurf-browser.org/
*
* NetSurf is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; version 2 of the License.
*
* NetSurf is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program. If not, see <http://www.gnu.org/licenses/>.
*/
#ifndef NETSURF_UTILS_REGEX_H_
#define NETSURF_UTILS_REGEX_H_
#include "utils/config.h"
#ifdef HAVE_REGEX
#include <sys/types.h>
#include <regex.h>
#else
#define REG_NOMATCH 1
#define REG_EXTENDED 1
#define REG_ICASE (1 << 1)
#define REG_NEWLINE (1 << 2)
#define REG_NOSUB (1 << 3)
typedef ssize_t regoff_t;
typedef struct {
size_t re_nsub; /* Number of parenthesized subexpressions.*/
} regex_t;
typedef struct {
regoff_t rm_so; /* Byte offset from start of string to start
* of substring.
*/
regoff_t rm_eo; /* Byte offset from start of string of the
* first character after the end of substring.
*/
} regmatch_t;
int regcomp(regex_t *restrict preg, const char *restrictregex, int cflags);
size_t regerror(int errorcode, const regex_t *restrict preg, char *restrict errbuf, size_t errbuf_size);
int regexec(const regex_t *restrict preg, const char *restrict string, size_t nmatch, regmatch_t pmatch[restrict], int eflags);
void regfree(regex_t *preg);
#endif
#endif

View File

@ -24,7 +24,9 @@
#include <stdio.h>
#include <string.h>
#include <strings.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include "utils/messages.h"
#include "utils/dirent.h"
@ -172,6 +174,7 @@ nserror vsnstrjoin(char **str, size_t *size, char sep, size_t nelm, va_list ap)
return NSERROR_OK;
}
/* exported interface documented in utils/utils.h */
nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...)
{
@ -263,12 +266,12 @@ char *strcasestr(const char *haystack, const char *needle)
#endif
#ifndef HAVE_STRNDUP
/**
* Duplicate up to n characters of a string.
*/
char *strndup(const char *s, size_t n)
{
size_t len;
@ -393,6 +396,7 @@ char *strchrnul (const char *s, int c_in)
#endif
#ifndef HAVE_UTSNAME
#include "utils/utsname.h"
int uname(struct utsname *buf) {
@ -404,9 +408,11 @@ int uname(struct utsname *buf) {
return 0;
}
#endif
#ifndef HAVE_REALPATH
char *realpath(const char *path, char *resolved_path)
{
char *ret;
@ -419,8 +425,9 @@ char *realpath(const char *path, char *resolved_path)
return ret;
}
#ifndef HAVE_INETATON
#endif
#ifndef HAVE_INETATON
int inet_aton(const char *cp, struct in_addr *inp)
{
@ -470,4 +477,40 @@ int inet_pton(int af, const char *src, void *dst)
#endif
#ifndef HAVE_REGEX
#include "utils/regex.h"
int
regcomp(regex_t *restrict preg, const char *restrictregex, int cflags)
{
return 0;
}
size_t
regerror(int errorcode,
const regex_t *restrict preg,
char *restrict errbuf,
size_t errbuf_size)
{
if ((errbuf != NULL) && (errbuf_size != 0)) {
*errbuf = 0;
}
return 0;
}
int
regexec(const regex_t *restrict preg,
const char *restrict string,
size_t nmatch,
regmatch_t pmatch[restrict],
int eflags)
{
return REG_NOMATCH;
}
void regfree(regex_t *preg)
{
}
#endif