add regex compatability to utils and enable it for serenity OS
This commit is contained in:
parent
4372104e0e
commit
4745fcf1c7
|
@ -28,10 +28,10 @@
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
#include <regex.h>
|
|
||||||
#include <dom/dom.h>
|
#include <dom/dom.h>
|
||||||
|
|
||||||
#include "utils/config.h"
|
#include "utils/config.h"
|
||||||
|
#include "utils/regex.h"
|
||||||
#include "utils/corestrings.h"
|
#include "utils/corestrings.h"
|
||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
#include "utils/nsurl.h"
|
#include "utils/nsurl.h"
|
||||||
|
|
|
@ -26,11 +26,11 @@
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
#include "utils/config.h"
|
||||||
#include "utils/utils.h"
|
#include "utils/utils.h"
|
||||||
#include "utils/log.h"
|
#include "utils/log.h"
|
||||||
#include "utils/nsurl.h"
|
#include "utils/nsurl.h"
|
||||||
#include "utils/nsoption.h"
|
#include "utils/nsoption.h"
|
||||||
#include "utils/config.h"
|
|
||||||
#include "netsurf/bitmap.h"
|
#include "netsurf/bitmap.h"
|
||||||
#include "netsurf/content.h"
|
#include "netsurf/content.h"
|
||||||
#include "netsurf/plotters.h"
|
#include "netsurf/plotters.h"
|
||||||
|
|
|
@ -16,8 +16,8 @@
|
||||||
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
#ifndef _NETSURF_UTILS_CONFIG_H_
|
#ifndef NETSURF_UTILS_CONFIG_H_
|
||||||
#define _NETSURF_UTILS_CONFIG_H_
|
#define NETSURF_UTILS_CONFIG_H_
|
||||||
|
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
|
@ -35,10 +35,10 @@
|
||||||
char *strndup(const char *s, size_t n);
|
char *strndup(const char *s, size_t n);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#if (defined(_GNU_SOURCE) || \
|
#if ((defined(_GNU_SOURCE) || \
|
||||||
defined(__APPLE__) || \
|
defined(__APPLE__) || \
|
||||||
defined(__HAIKU__) || \
|
defined(__HAIKU__) || \
|
||||||
defined(__OpenBSD__) &&\
|
defined(__OpenBSD__)) && \
|
||||||
!defined(__serenity__))
|
!defined(__serenity__))
|
||||||
#define HAVE_STRCASESTR
|
#define HAVE_STRCASESTR
|
||||||
#else
|
#else
|
||||||
|
@ -68,14 +68,18 @@ char *strchrnul(const char *s, int c);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HAVE_SYS_SELECT
|
#define HAVE_SYS_SELECT
|
||||||
#define HAVE_INETATON
|
|
||||||
#define HAVE_POSIX_INET_HEADERS
|
#define HAVE_POSIX_INET_HEADERS
|
||||||
#if (defined(_WIN32))
|
#if (defined(_WIN32))
|
||||||
#undef HAVE_INETATON
|
|
||||||
#undef HAVE_SYS_SELECT
|
#undef HAVE_SYS_SELECT
|
||||||
#undef HAVE_POSIX_INET_HEADERS
|
#undef HAVE_POSIX_INET_HEADERS
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HAVE_INETATON
|
||||||
|
#if (defined(_WIN32) || \
|
||||||
|
defined(__serenity__))
|
||||||
|
#undef HAVE_INETATON
|
||||||
|
#endif
|
||||||
|
|
||||||
#define HAVE_INETPTON
|
#define HAVE_INETPTON
|
||||||
#if (defined(_WIN32))
|
#if (defined(_WIN32))
|
||||||
#undef HAVE_INETPTON
|
#undef HAVE_INETPTON
|
||||||
|
@ -113,10 +117,16 @@ char *realpath(const char *path, char *resolved_path);
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#define HAVE_SCANDIR
|
#define HAVE_SCANDIR
|
||||||
#if (defined(_WIN32))
|
#if (defined(_WIN32) || \
|
||||||
|
defined(__serenity__))
|
||||||
#undef HAVE_SCANDIR
|
#undef HAVE_SCANDIR
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
#define HAVE_REGEX
|
||||||
|
#if (defined(__serenity__))
|
||||||
|
#undef HAVE_REGEX
|
||||||
|
#endif
|
||||||
|
|
||||||
/* This section toggles build options on and off.
|
/* This section toggles build options on and off.
|
||||||
* Simply undefine a symbol to turn the relevant feature 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
|
#define WITH_MMAP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* amiga */
|
/* IPv6 */
|
||||||
#if (defined(__amigaos4__) || \
|
#if (defined(__amigaos4__) || \
|
||||||
defined(__AMIGA__) || \
|
defined(__AMIGA__) || \
|
||||||
defined(nsatari) || \
|
defined(nsatari) || \
|
||||||
|
|
|
@ -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
|
|
@ -24,7 +24,9 @@
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <strings.h>
|
#include <strings.h>
|
||||||
|
#include <sys/types.h>
|
||||||
#include <sys/stat.h>
|
#include <sys/stat.h>
|
||||||
|
#include <unistd.h>
|
||||||
|
|
||||||
#include "utils/messages.h"
|
#include "utils/messages.h"
|
||||||
#include "utils/dirent.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;
|
return NSERROR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
/* exported interface documented in utils/utils.h */
|
/* exported interface documented in utils/utils.h */
|
||||||
nserror snstrjoin(char **str, size_t *size, char sep, size_t nelm, ...)
|
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
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#ifndef HAVE_STRNDUP
|
#ifndef HAVE_STRNDUP
|
||||||
|
|
||||||
/**
|
/**
|
||||||
* Duplicate up to n characters of a string.
|
* Duplicate up to n characters of a string.
|
||||||
*/
|
*/
|
||||||
|
|
||||||
char *strndup(const char *s, size_t n)
|
char *strndup(const char *s, size_t n)
|
||||||
{
|
{
|
||||||
size_t len;
|
size_t len;
|
||||||
|
@ -393,6 +396,7 @@ char *strchrnul (const char *s, int c_in)
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_UTSNAME
|
#ifndef HAVE_UTSNAME
|
||||||
|
|
||||||
#include "utils/utsname.h"
|
#include "utils/utsname.h"
|
||||||
|
|
||||||
int uname(struct utsname *buf) {
|
int uname(struct utsname *buf) {
|
||||||
|
@ -404,9 +408,11 @@ int uname(struct utsname *buf) {
|
||||||
|
|
||||||
return 0;
|
return 0;
|
||||||
}
|
}
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
#ifndef HAVE_REALPATH
|
#ifndef HAVE_REALPATH
|
||||||
|
|
||||||
char *realpath(const char *path, char *resolved_path)
|
char *realpath(const char *path, char *resolved_path)
|
||||||
{
|
{
|
||||||
char *ret;
|
char *ret;
|
||||||
|
@ -419,8 +425,9 @@ char *realpath(const char *path, char *resolved_path)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
#ifndef HAVE_INETATON
|
#endif
|
||||||
|
|
||||||
|
#ifndef HAVE_INETATON
|
||||||
|
|
||||||
int inet_aton(const char *cp, struct in_addr *inp)
|
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
|
#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
|
#endif
|
||||||
|
|
Loading…
Reference in New Issue