summaryrefslogtreecommitdiff
path: root/drivers
diff options
context:
space:
mode:
Diffstat (limited to 'drivers')
-rw-r--r--drivers/SCsub84
-rw-r--r--drivers/gl_context/SCsub24
-rw-r--r--drivers/gles2/shaders/SCsub10
-rw-r--r--drivers/nrex/README.md75
-rw-r--r--drivers/nrex/SCsub7
-rw-r--r--drivers/nrex/nrex.cpp1496
-rw-r--r--drivers/nrex/nrex.hpp176
-rw-r--r--drivers/nrex/nrex_config.h12
-rw-r--r--drivers/nrex/regex.cpp142
-rw-r--r--drivers/nrex/regex.h65
-rw-r--r--drivers/png/SCsub72
-rw-r--r--drivers/register_driver_types.cpp4
-rw-r--r--drivers/rtaudio/SCsub4
-rw-r--r--drivers/unix/SCsub14
-rw-r--r--drivers/unix/ip_unix.cpp9
-rw-r--r--drivers/unix/packet_peer_udp_posix.cpp27
-rw-r--r--drivers/unix/socket_helpers.h32
-rw-r--r--drivers/unix/stream_peer_tcp_posix.cpp4
-rw-r--r--drivers/unix/tcp_server_posix.cpp12
-rw-r--r--drivers/unix/tcp_server_posix.h2
-rw-r--r--drivers/zlib/SCsub24
21 files changed, 163 insertions, 2132 deletions
diff --git a/drivers/SCsub b/drivers/SCsub
index 1f1509efa8..08a189272f 100644
--- a/drivers/SCsub
+++ b/drivers/SCsub
@@ -2,85 +2,41 @@
Import('env')
-env.drivers_sources=[]
+env.drivers_sources = []
if ("builtin_zlib" in env and env["builtin_zlib"] == "yes"):
- SConscript("zlib/SCsub");
+ SConscript("zlib/SCsub")
# OS drivers
-SConscript('unix/SCsub');
-SConscript('windows/SCsub');
+SConscript('unix/SCsub')
+SConscript('windows/SCsub')
# Sounds drivers
-SConscript('alsa/SCsub');
-SConscript('pulseaudio/SCsub');
+SConscript('alsa/SCsub')
+SConscript('pulseaudio/SCsub')
if (env["platform"] == "windows"):
- SConscript("rtaudio/SCsub");
+ SConscript("rtaudio/SCsub")
if (env["xaudio2"] == "yes"):
- SConscript("xaudio2/SCsub");
+ SConscript("xaudio2/SCsub")
# Graphics drivers
-SConscript('gles2/SCsub');
-SConscript('gl_context/SCsub');
+SConscript('gles2/SCsub')
+SConscript('gl_context/SCsub')
# Core dependencies
-SConscript("png/SCsub");
-SConscript("nrex/SCsub");
+SConscript("png/SCsub")
# Tools override
# FIXME: Should likely be integrated in the tools/ codebase
-if (env["tools"]=="yes"):
- SConscript("convex_decomp/SCsub");
+if (env["tools"] == "yes"):
+ SConscript("convex_decomp/SCsub")
-if env['vsproj']=="yes":
- env.AddToVSProject(env.drivers_sources)
+if env['vsproj'] == "yes":
+ env.AddToVSProject(env.drivers_sources)
-
-# Split drivers, this used to be needed for windows until separate builders for windows were created
-# FIXME: Check if still needed now that the drivers were made more lightweight
-if (env.split_drivers):
- import string
-
- num = 0
- cur_base = ""
- max_src = 64
- list = []
- lib_list = []
-
- for f in env.drivers_sources:
- fname = ""
- if type(f) == type(""):
- fname = env.File(f).path
- else:
- fname = env.File(f)[0].path
- fname = fname.replace("\\", "/")
- base = string.join(fname.split("/")[:2], "/")
- if base != cur_base and len(list) > max_src:
- if num > 0:
- lib = env.Library("drivers"+str(num), list)
- lib_list.append(lib)
- list = []
- num = num+1
- cur_base = base
- list.append(f)
-
- lib = env.Library("drivers"+str(num), list)
- lib_list.append(lib)
-
- if len(lib_list) > 0:
- import os, sys
- if os.name=='posix' and sys.platform=='msys':
- env.Replace(ARFLAGS=['rcsT'])
-
- lib = env.Library("drivers_collated", lib_list)
- lib_list = [lib]
-
- drivers_base=[]
- env.add_source_files(drivers_base,"*.cpp")
- lib_list.insert(0, env.Library("drivers", drivers_base))
-
- env.Prepend(LIBS=lib_list)
+if env.split_drivers:
+ env.split_lib("drivers")
else:
- env.add_source_files(env.drivers_sources,"*.cpp")
- lib = env.Library("drivers",env.drivers_sources)
- env.Prepend(LIBS=[lib])
+ env.add_source_files(env.drivers_sources, "*.cpp")
+ lib = env.Library("drivers", env.drivers_sources)
+ env.Prepend(LIBS=[lib])
diff --git a/drivers/gl_context/SCsub b/drivers/gl_context/SCsub
index cf37e9fe36..a968c10cfd 100644
--- a/drivers/gl_context/SCsub
+++ b/drivers/gl_context/SCsub
@@ -2,20 +2,20 @@
Import('env')
-if (env["platform"] in ["haiku","osx","windows","x11"]):
- # Thirdparty source files
- if (env["glew"] != "system"): # builtin
- thirdparty_dir = "#thirdparty/glew/"
- thirdparty_sources = [
- "glew.c",
- ]
- thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
+if (env["platform"] in ["haiku", "osx", "windows", "x11"]):
+ # Thirdparty source files
+ if (env['builtin_glew'] != 'no'): # builtin
+ thirdparty_dir = "#thirdparty/glew/"
+ thirdparty_sources = [
+ "glew.c",
+ ]
+ thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
- env.add_source_files(env.drivers_sources, thirdparty_sources)
- env.Append(CPPFLAGS = ['-DGLEW_STATIC'])
- env.Append(CPPPATH = [thirdparty_dir])
+ env.add_source_files(env.drivers_sources, thirdparty_sources)
+ env.Append(CPPFLAGS=['-DGLEW_STATIC'])
+ env.Append(CPPPATH=[thirdparty_dir])
- env.Append(CPPFLAGS = ['-DGLEW_ENABLED'])
+ env.Append(CPPFLAGS=['-DGLEW_ENABLED'])
# Godot source files
env.add_source_files(env.drivers_sources, "*.cpp")
diff --git a/drivers/gles2/shaders/SCsub b/drivers/gles2/shaders/SCsub
index 1de5604321..bf4ec9485d 100644
--- a/drivers/gles2/shaders/SCsub
+++ b/drivers/gles2/shaders/SCsub
@@ -3,10 +3,10 @@
Import('env')
if env['BUILDERS'].has_key('GLSL120GLES'):
- env.GLSL120GLES('material.glsl');
- env.GLSL120GLES('canvas.glsl');
- env.GLSL120GLES('canvas_shadow.glsl');
- env.GLSL120GLES('blur.glsl');
- env.GLSL120GLES('copy.glsl');
+ env.GLSL120GLES('material.glsl')
+ env.GLSL120GLES('canvas.glsl')
+ env.GLSL120GLES('canvas_shadow.glsl')
+ env.GLSL120GLES('blur.glsl')
+ env.GLSL120GLES('copy.glsl')
Export('env')
diff --git a/drivers/nrex/README.md b/drivers/nrex/README.md
deleted file mode 100644
index 7a942b2452..0000000000
--- a/drivers/nrex/README.md
+++ /dev/null
@@ -1,75 +0,0 @@
-# NREX: Node RegEx
-
-[![Build Status](https://travis-ci.org/leezh/nrex.svg?branch=master)](https://travis-ci.org/leezh/nrex)
-
-** Version 0.2 **
-
-Small node-based regular expression library. It only does text pattern
-matchhing, not replacement. To use add the files `nrex.hpp`, `nrex.cpp`
-and `nrex_config.h` to your project and follow the example:
-
- nrex regex;
- regex.compile("^(fo+)bar$");
-
- nrex_result captures[regex.capture_size()];
- if (regex.match("foobar", captures))
- {
- std::cout << captures[0].start << std::endl;
- std::cout << captures[0].length << std::endl;
- }
-
-More details about its use is documented in `nrex.hpp`
-
-Currently supported features:
- * Capturing `()` and non-capturing `(?:)` groups
- * Any character `.` (includes newlines)
- * Shorthand caracter classes `\w\W\s\S\d\D`
- * POSIX character classes such as `[[:alnum:]]`
- * Bracket expressions such as `[A-Za-z]`
- * Simple quantifiers `?`, `*` and `+`
- * Range quantifiers `{0,1}`
- * Lazy (non-greedy) quantifiers `*?`
- * Begining `^` and end `$` anchors
- * Word boundaries `\b`
- * Alternation `|`
- * ASCII `\xFF` code points
- * Unicode `\uFFFF` code points
- * Positive `(?=)` and negative `(?!)` lookahead
- * Positive `(?<=)` and negative `(?<!)` lookbehind (fixed length and no alternations)
- * Backreferences `\1` and `\g{1}` (limited by default to 9 - can be unlimited)
-
-## License
-
-Copyright (c) 2015-2016, Zher Huei Lee
-All rights reserved.
-
-This software is provided 'as-is', without any express or implied
-warranty. In no event will the authors be held liable for any damages
-arising from the use of this software.
-
-Permission is granted to anyone to use this software for any purpose,
-including commercial applications, and to alter it and redistribute it
-freely, subject to the following restrictions:
-
- 1. The origin of this software must not be misrepresented; you must not
- claim that you wrote the original software. If you use this software
- in a product, an acknowledgment in the product documentation would
- be appreciated but is not required.
-
- 2. Altered source versions must be plainly marked as such, and must not
- be misrepresented as being the original software.
-
- 3. This notice may not be removed or altered from any source
- distribution.
-
-
-# Changes
-
-## Version 0.2 (2016-08-04)
- * Fixed capturing groups matching to invalid results
- * Fixed parents of recursive quantifiers not expanding properly
- * Fixed LookAhead sometimes adding to result
- * More verbose unit testing
-
-## Version 0.1 (2015-12-04)
- * Initial release
diff --git a/drivers/nrex/SCsub b/drivers/nrex/SCsub
deleted file mode 100644
index ee39fd2631..0000000000
--- a/drivers/nrex/SCsub
+++ /dev/null
@@ -1,7 +0,0 @@
-#!/usr/bin/env python
-
-Import('env')
-
-env.add_source_files(env.drivers_sources, "*.cpp")
-
-Export('env')
diff --git a/drivers/nrex/nrex.cpp b/drivers/nrex/nrex.cpp
deleted file mode 100644
index 69e04285e3..0000000000
--- a/drivers/nrex/nrex.cpp
+++ /dev/null
@@ -1,1496 +0,0 @@
-// NREX: Node RegEx
-// Version 0.2
-//
-// Copyright (c) 2015-2016, Zher Huei Lee
-// All rights reserved.
-//
-// This software is provided 'as-is', without any express or implied
-// warranty. In no event will the authors be held liable for any damages
-// arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it
-// freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not
-// claim that you wrote the original software. If you use this software
-// in a product, an acknowledgment in the product documentation would
-// be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such, and must not
-// be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source
-// distribution.
-//
-
-#include "nrex.hpp"
-
-#ifdef NREX_UNICODE
-#include <wctype.h>
-#include <wchar.h>
-#define NREX_ISALPHANUM iswalnum
-#define NREX_ISSPACE iswspace
-#define NREX_STRLEN wcslen
-#else
-#include <ctype.h>
-#include <string.h>
-#define NREX_ISALPHANUM isalnum
-#define NREX_ISSPACE isspace
-#define NREX_STRLEN strlen
-#endif
-
-#ifdef NREX_THROW_ERROR
-#define NREX_COMPILE_ERROR(M) throw nrex_compile_error(M)
-#else
-#define NREX_COMPILE_ERROR(M) reset(); return false
-#endif
-
-#ifndef NREX_NEW
-#define NREX_NEW(X) new X
-#define NREX_NEW_ARRAY(X, N) new X[N]
-#define NREX_DELETE(X) delete X
-#define NREX_DELETE_ARRAY(X) delete[] X
-#endif
-
-template<typename T>
-class nrex_array
-{
- private:
- T* _data;
- unsigned int _reserved;
- unsigned int _size;
- public:
- nrex_array()
- : _data(NREX_NEW_ARRAY(T, 2))
- , _reserved(2)
- , _size(0)
- {
- }
-
- nrex_array(unsigned int reserved)
- : _data(NREX_NEW_ARRAY(T, reserved ? reserved : 1))
- , _reserved(reserved ? reserved : 1)
- , _size(0)
- {
- }
-
- ~nrex_array()
- {
- NREX_DELETE_ARRAY(_data);
- }
-
- unsigned int size() const
- {
- return _size;
- }
-
- void reserve(unsigned int size)
- {
- if (size < _size) {
- size = _size;
- }
- if (size == 0) {
- size = 1;
- }
- T* old = _data;
- _data = NREX_NEW_ARRAY(T, size);
- _reserved = size;
- for (unsigned int i = 0; i < _size; ++i)
- {
- _data[i] = old[i];
- }
- NREX_DELETE_ARRAY(old);
- }
-
- void push(T item)
- {
- if (_size == _reserved)
- {
- reserve(_reserved * 2);
- }
- _data[_size] = item;
- _size++;
- }
-
- const T& top() const
- {
- return _data[_size - 1];
- }
-
- const T& operator[] (unsigned int i) const
- {
- return _data[i];
- }
-
- void pop()
- {
- if (_size > 0)
- {
- --_size;
- }
- }
-};
-
-static int nrex_parse_hex(nrex_char c)
-{
- if ('0' <= c && c <= '9')
- {
- return int(c - '0');
- }
- else if ('a' <= c && c <= 'f')
- {
- return int(c - 'a') + 10;
- }
- else if ('A' <= c && c <= 'F')
- {
- return int(c - 'A') + 10;
- }
- return -1;
-}
-
-static nrex_char nrex_unescape(const nrex_char*& c)
-{
- switch (c[1])
- {
- case '0': ++c; return '\0';
- case 'a': ++c; return '\a';
- case 'e': ++c; return '\e';
- case 'f': ++c; return '\f';
- case 'n': ++c; return '\n';
- case 'r': ++c; return '\r';
- case 't': ++c; return '\t';
- case 'v': ++c; return '\v';
- case 'b': ++c; return '\b';
- case 'x':
- {
- int point = 0;
- for (int i = 2; i <= 3; ++i)
- {
- int res = nrex_parse_hex(c[i]);
- if (res == -1)
- {
- return '\0';
- }
- point = (point << 4) + res;
- }
- c = &c[3];
- return nrex_char(point);
- }
- case 'u':
- {
- int point = 0;
- for (int i = 2; i <= 5; ++i)
- {
- int res = nrex_parse_hex(c[i]);
- if (res == -1)
- {
- return '\0';
- }
- point = (point << 4) + res;
- }
- c = &c[5];
- return nrex_char(point);
- }
- }
- return (++c)[0];
-}
-
-struct nrex_search
-{
- const nrex_char* str;
- nrex_result* captures;
- int end;
- bool complete;
- nrex_array<int> lookahead_pos;
-
- nrex_char at(int pos)
- {
- return str[pos];
- }
-
- nrex_search(const nrex_char* str, nrex_result* captures, int lookahead)
- : str(str)
- , captures(captures)
- , end(0)
- , lookahead_pos(lookahead)
- {
- }
-};
-
-struct nrex_node
-{
- nrex_node* next;
- nrex_node* previous;
- nrex_node* parent;
- bool quantifiable;
- int length;
-
- nrex_node(bool quantify = false)
- : next(NULL)
- , previous(NULL)
- , parent(NULL)
- , quantifiable(quantify)
- , length(-1)
- {
- }
-
- virtual ~nrex_node()
- {
- if (next)
- {
- NREX_DELETE(next);
- }
- }
-
- virtual int test(nrex_search* s, int pos) const
- {
- return next ? next->test(s, pos) : -1;
- }
-
- virtual int test_parent(nrex_search* s, int pos) const
- {
- if (next)
- {
- pos = next->test(s, pos);
- }
- if (pos >= 0)
- {
- s->complete = true;
- }
- if (parent && pos >= 0)
- {
- pos = parent->test_parent(s, pos);
- }
- if (pos < 0)
- {
- s->complete = false;
- }
- return pos;
- }
-
- void increment_length(int amount, bool subtract = false)
- {
- if (amount >= 0 && length >= 0)
- {
- if (!subtract)
- {
- length += amount;
- }
- else
- {
- length -= amount;
- }
- }
- else
- {
- length = -1;
- }
- if (parent)
- {
- parent->increment_length(amount, subtract);
- }
- }
-};
-
-enum nrex_group_type
-{
- nrex_group_capture,
- nrex_group_non_capture,
- nrex_group_bracket,
- nrex_group_look_ahead,
- nrex_group_look_behind,
-};
-
-struct nrex_node_group : public nrex_node
-{
- nrex_group_type type;
- int id;
- bool negate;
- nrex_array<nrex_node*> childset;
- nrex_node* back;
-
- nrex_node_group(nrex_group_type type, int id = 0)
- : nrex_node(true)
- , type(type)
- , id(id)
- , negate(false)
- , back(NULL)
- {
- if (type != nrex_group_bracket)
- {
- length = 0;
- }
- else
- {
- length = 1;
- }
- if (type == nrex_group_look_ahead || type == nrex_group_look_behind)
- {
- quantifiable = false;
- }
- }
-
- virtual ~nrex_node_group()
- {
- for (unsigned int i = 0; i < childset.size(); ++i)
- {
- NREX_DELETE(childset[i]);
- }
-
- }
-
- int test(nrex_search* s, int pos) const
- {
- int old_start;
- if (type == nrex_group_capture)
- {
- old_start = s->captures[id].start;
- s->captures[id].start = pos;
- }
- for (unsigned int i = 0; i < childset.size(); ++i)
- {
- s->complete = false;
- int offset = 0;
- if (type == nrex_group_look_behind)
- {
- if (pos < length)
- {
- return -1;
- }
- offset = length;
- }
- if (type == nrex_group_look_ahead)
- {
- s->lookahead_pos.push(pos);
- }
- int res = childset[i]->test(s, pos - offset);
- if (type == nrex_group_look_ahead)
- {
- s->lookahead_pos.pop();
- }
- if (s->complete)
- {
- return res;
- }
- if (negate)
- {
- if (res < 0)
- {
- res = pos + 1;
- }
- else
- {
- return -1;
- }
- if (i + 1 < childset.size())
- {
- continue;
- }
- }
- if (res >= 0)
- {
- if (type == nrex_group_capture)
- {
- s->captures[id].length = res - pos;
- }
- else if (type == nrex_group_look_ahead || type == nrex_group_look_behind)
- {
- res = pos;
- }
- return next ? next->test(s, res) : res;
- }
- }
- if (type == nrex_group_capture)
- {
- s->captures[id].start = old_start;
- }
- return -1;
- }
-
- virtual int test_parent(nrex_search* s, int pos) const
- {
- if (type == nrex_group_capture)
- {
- s->captures[id].length = pos - s->captures[id].start;
- }
- if (type == nrex_group_look_ahead)
- {
- pos = s->lookahead_pos[id];
- }
- return nrex_node::test_parent(s, pos);
- }
-
- void add_childset()
- {
- if (childset.size() > 0 && type != nrex_group_bracket)
- {
- length = -1;
- }
- back = NULL;
- }
-
- void add_child(nrex_node* node)
- {
- node->parent = this;
- node->previous = back;
- if (back && type != nrex_group_bracket)
- {
- back->next = node;
- }
- else
- {
- childset.push(node);
- }
- if (type != nrex_group_bracket)
- {
- increment_length(node->length);
- }
- back = node;
- }
-
- nrex_node* swap_back(nrex_node* node)
- {
- if (!back)
- {
- add_child(node);
- return NULL;
- }
- nrex_node* old = back;
- if (!old->previous)
- {
- childset.pop();
- }
- if (type != nrex_group_bracket)
- {
- increment_length(old->length, true);
- }
- back = old->previous;
- add_child(node);
- return old;
- }
-
- void pop_back()
- {
- if (back)
- {
- nrex_node* old = back;
- if (!old->previous)
- {
- childset.pop();
- }
- if (type != nrex_group_bracket)
- {
- increment_length(old->length, true);
- }
- back = old->previous;
- NREX_DELETE(old);
- }
- }
-};
-
-struct nrex_node_char : public nrex_node
-{
- nrex_char ch;
-
- nrex_node_char(nrex_char c)
- : nrex_node(true)
- , ch(c)
- {
- length = 1;
- }
-
- int test(nrex_search* s, int pos) const
- {
- if (s->end <= pos || 0 > pos || s->at(pos) != ch)
- {
- return -1;
- }
- return next ? next->test(s, pos + 1) : pos + 1;
- }
-};
-
-struct nrex_node_range : public nrex_node
-{
- nrex_char start;
- nrex_char end;
-
- nrex_node_range(nrex_char s, nrex_char e)
- : nrex_node(true)
- , start(s)
- , end(e)
- {
- length = 1;
- }
-
- int test(nrex_search* s, int pos) const
- {
- if (s->end <= pos || 0 > pos)
- {
- return -1;
- }
- nrex_char c = s->at(pos);
- if (c < start || end < c)
- {
- return -1;
- }
- return next ? next->test(s, pos + 1) : pos + 1;
- }
-};
-
-enum nrex_class_type
-{
- nrex_class_none,
- nrex_class_alnum,
- nrex_class_alpha,
- nrex_class_blank,
- nrex_class_cntrl,
- nrex_class_digit,
- nrex_class_graph,
- nrex_class_lower,
- nrex_class_print,
- nrex_class_punct,
- nrex_class_space,
- nrex_class_upper,
- nrex_class_xdigit,
- nrex_class_word
-};
-
-static bool nrex_compare_class(const nrex_char** pos, const char* text)
-{
- unsigned int i = 0;
- for (i = 0; text[i] != '\0'; ++i)
- {
- if ((*pos)[i] != text[i])
- {
- return false;
- }
- }
- if ((*pos)[i++] != ':' || (*pos)[i] != ']')
- {
- return false;
- }
- *pos = &(*pos)[i];
- return true;
-}
-
-#define NREX_COMPARE_CLASS(POS, NAME) if (nrex_compare_class(POS, #NAME)) return nrex_class_ ## NAME
-
-static nrex_class_type nrex_parse_class(const nrex_char** pos)
-{
- NREX_COMPARE_CLASS(pos, alnum);
- NREX_COMPARE_CLASS(pos, alpha);
- NREX_COMPARE_CLASS(pos, blank);
- NREX_COMPARE_CLASS(pos, cntrl);
- NREX_COMPARE_CLASS(pos, digit);
- NREX_COMPARE_CLASS(pos, graph);
- NREX_COMPARE_CLASS(pos, lower);
- NREX_COMPARE_CLASS(pos, print);
- NREX_COMPARE_CLASS(pos, punct);
- NREX_COMPARE_CLASS(pos, space);
- NREX_COMPARE_CLASS(pos, upper);
- NREX_COMPARE_CLASS(pos, xdigit);
- NREX_COMPARE_CLASS(pos, word);
- return nrex_class_none;
-}
-
-struct nrex_node_class : public nrex_node
-{
- nrex_class_type type;
-
- nrex_node_class(nrex_class_type t)
- : nrex_node(true)
- , type(t)
- {
- length = 1;
- }
-
- int test(nrex_search* s, int pos) const
- {
- if (s->end <= pos || 0 > pos)
- {
- return -1;
- }
- if (!test_class(s->at(pos)))
- {
- return -1;
- }
- return next ? next->test(s, pos + 1) : pos + 1;
- }
-
- bool test_class(nrex_char c) const
- {
- if ((0 <= c && c <= 0x1F) || c == 0x7F)
- {
- if (type == nrex_class_cntrl)
- {
- return true;
- }
- }
- else if (c < 0x7F)
- {
- if (type == nrex_class_print)
- {
- return true;
- }
- else if (type == nrex_class_graph && c != ' ')
- {
- return true;
- }
- else if ('0' <= c && c <= '9')
- {
- switch (type)
- {
- case nrex_class_alnum:
- case nrex_class_digit:
- case nrex_class_xdigit:
- case nrex_class_word:
- return true;
- default:
- break;
- }
- }
- else if ('A' <= c && c <= 'Z')
- {
- switch (type)
- {
- case nrex_class_alnum:
- case nrex_class_alpha:
- case nrex_class_upper:
- case nrex_class_word:
- return true;
- case nrex_class_xdigit:
- if (c <= 'F')
- {
- return true;
- }
- default:
- break;
- }
- }
- else if ('a' <= c && c <= 'z')
- {
- switch (type)
- {
- case nrex_class_alnum:
- case nrex_class_alpha:
- case nrex_class_lower:
- case nrex_class_word:
- return true;
- case nrex_class_xdigit:
- if (c <= 'f')
- {
- return true;
- }
- default:
- break;
- }
- }
- }
- switch (c)
- {
- case ' ':
- case '\t':
- if (type == nrex_class_blank)
- {
- return true;
- }
- case '\r':
- case '\n':
- case '\f':
- if (type == nrex_class_space)
- {
- return true;
- }
- break;
- case '_':
- if (type == nrex_class_word)
- {
- return true;
- }
- case ']':
- case '[':
- case '!':
- case '"':
- case '#':
- case '$':
- case '%':
- case '&':
- case '\'':
- case '(':
- case ')':
- case '*':
- case '+':
- case ',':
- case '.':
- case '/':
- case ':':
- case ';':
- case '<':
- case '=':
- case '>':
- case '?':
- case '@':
- case '\\':
- case '^':
- case '`':
- case '{':
- case '|':
- case '}':
- case '~':
- case '-':
- if (type == nrex_class_punct)
- {
- return true;
- }
- break;
- default:
- break;
- }
- return false;
- }
-};
-
-static bool nrex_is_shorthand(nrex_char repr)
-{
- switch (repr)
- {
- case 'W':
- case 'w':
- case 'D':
- case 'd':
- case 'S':
- case 's':
- return true;
- }
- return false;
-}
-
-struct nrex_node_shorthand : public nrex_node
-{
- nrex_char repr;
-
- nrex_node_shorthand(nrex_char c)
- : nrex_node(true)
- , repr(c)
- {
- length = 1;
- }
-
- int test(nrex_search* s, int pos) const
- {
- if (s->end <= pos || 0 > pos)
- {
- return -1;
- }
- bool found = false;
- bool invert = false;
- nrex_char c = s->at(pos);
- switch (repr)
- {
- case '.':
- found = true;
- break;
- case 'W':
- invert = true;
- case 'w':
- if (c == '_' || NREX_ISALPHANUM(c))
- {
- found = true;
- }
- break;
- case 'D':
- invert = true;
- case 'd':
- if ('0' <= c && c <= '9')
- {
- found = true;
- }
- break;
- case 'S':
- invert = true;
- case 's':
- if (NREX_ISSPACE(c))
- {
- found = true;
- }
- break;
- }
- if (found == invert)
- {
- return -1;
- }
- return next ? next->test(s, pos + 1) : pos + 1;
- }
-};
-
-static bool nrex_is_quantifier(nrex_char repr)
-{
- switch (repr)
- {
- case '?':
- case '*':
- case '+':
- case '{':
- return true;
- }
- return false;
-}
-
-struct nrex_node_quantifier : public nrex_node
-{
- int min;
- int max;
- bool greedy;
- nrex_node* child;
-
- nrex_node_quantifier(int min, int max)
- : nrex_node()
- , min(min)
- , max(max)
- , greedy(true)
- , child(NULL)
- {
- }
-
- virtual ~nrex_node_quantifier()
- {
- if (child)
- {
- NREX_DELETE(child);
- }
- }
-
- int test(nrex_search* s, int pos) const
- {
- return test_step(s, pos, 0, pos);
- }
-
- int test_step(nrex_search* s, int pos, int level, int start) const
- {
- if (pos > s->end)
- {
- return -1;
- }
- if (!greedy && level > min)
- {
- int res = pos;
- if (next)
- {
- res = next->test(s, res);
- }
- if (s->complete)
- {
- return res;
- }
- if (res >= 0 && parent->test_parent(s, res) >= 0)
- {
- return res;
- }
- }
- if (max >= 0 && level > max)
- {
- return -1;
- }
- if (level > 1 && level > min + 1 && pos == start)
- {
- return -1;
- }
- int res = pos;
- if (level >= 1)
- {
- res = child->test(s, pos);
- if (s->complete)
- {
- return res;
- }
- }
- if (res >= 0)
- {
- int res_step = test_step(s, res, level + 1, start);
- if (res_step >= 0)
- {
- return res_step;
- }
- else if (greedy && level >= min)
- {
- if (next)
- {
- res = next->test(s, res);
- }
- if (s->complete)
- {
- return res;
- }
- if (res >= 0 && parent->test_parent(s, res) >= 0)
- {
- return res;
- }
- }
- }
- return -1;
- }
-
- virtual int test_parent(nrex_search* s, int pos) const
- {
- s->complete = false;
- return pos;
- }
-};
-
-struct nrex_node_anchor : public nrex_node
-{
- bool end;
-
- nrex_node_anchor(bool end)
- : nrex_node()
- , end(end)
- {
- length = 0;
- }
-
- int test(nrex_search* s, int pos) const
- {
- if (!end && pos != 0)
- {
- return -1;
- }
- else if (end && pos != s->end)
- {
- return -1;
- }
- return next ? next->test(s, pos) : pos;
- }
-};
-
-struct nrex_node_word_boundary : public nrex_node
-{
- bool inverse;
-
- nrex_node_word_boundary(bool inverse)
- : nrex_node()
- , inverse(inverse)
- {
- length = 0;
- }
-
- int test(nrex_search* s, int pos) const
- {
- bool left = false;
- bool right = false;
- if (pos != 0)
- {
- nrex_char c = s->at(pos - 1);
- if (c == '_' || NREX_ISALPHANUM(c))
- {
- left = true;
- }
- }
- if (pos != s->end)
- {
- nrex_char c = s->at(pos);
- if (c == '_' || NREX_ISALPHANUM(c))
- {
- right = true;
- }
- }
- if ((left != right) == inverse)
- {
- return -1;
- }
- return next ? next->test(s, pos) : pos;
- }
-};
-
-struct nrex_node_backreference : public nrex_node
-{
- int ref;
-
- nrex_node_backreference(int ref)
- : nrex_node(true)
- , ref(ref)
- {
- length = -1;
- }
-
- int test(nrex_search* s, int pos) const
- {
- nrex_result& r = s->captures[ref];
- for (int i = 0; i < r.length; ++i)
- {
- if (pos + i >= s->end)
- {
- return -1;
- }
- if (s->at(r.start + i) != s->at(pos + i))
- {
- return -1;
- }
- }
- return next ? next->test(s, pos + r.length) : pos + r.length;
- }
-};
-
-bool nrex_has_lookbehind(nrex_array<nrex_node_group*>& stack)
-{
- for (unsigned int i = 0; i < stack.size(); i++)
- {
- if (stack[i]->type == nrex_group_look_behind)
- {
- return true;
- }
- }
- return false;
-}
-
-nrex::nrex()
- : _capturing(0)
- , _lookahead_depth(0)
- , _root(NULL)
-{
-}
-
-nrex::nrex(const nrex_char* pattern, int captures)
- : _capturing(0)
- , _lookahead_depth(0)
- , _root(NULL)
-{
- compile(pattern, captures);
-}
-
-nrex::~nrex()
-{
- if (_root)
- {
- NREX_DELETE(_root);
- }
-}
-
-bool nrex::valid() const
-{
- return (_root != NULL);
-}
-
-void nrex::reset()
-{
- _capturing = 0;
- _lookahead_depth = 0;
- if (_root)
- {
- NREX_DELETE(_root);
- }
- _root = NULL;
-}
-
-int nrex::capture_size() const
-{
- if (_root)
- {
- return _capturing + 1;
- }
- return 0;
-}
-
-bool nrex::compile(const nrex_char* pattern, int captures)
-{
- reset();
- nrex_node_group* root = NREX_NEW(nrex_node_group(nrex_group_capture, _capturing));
- nrex_array<nrex_node_group*> stack;
- stack.push(root);
- unsigned int lookahead_level = 0;
- _root = root;
-
- for (const nrex_char* c = pattern; c[0] != '\0'; ++c)
- {
- if (c[0] == '(')
- {
- if (c[1] == '?')
- {
- if (c[2] == ':')
- {
- c = &c[2];
- nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_group_non_capture));
- stack.top()->add_child(group);
- stack.push(group);
- }
- else if (c[2] == '!' || c[2] == '=')
- {
- c = &c[2];
- nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_group_look_ahead, lookahead_level++));
- group->negate = (c[0] == '!');
- stack.top()->add_child(group);
- stack.push(group);
- if (lookahead_level > _lookahead_depth)
- {
- _lookahead_depth = lookahead_level;
- }
- }
- else if (c[2] == '<' && (c[3] == '!' || c[3] == '='))
- {
- c = &c[3];
- nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_group_look_behind));
- group->negate = (c[0] == '!');
- stack.top()->add_child(group);
- stack.push(group);
- }
- else
- {
- NREX_COMPILE_ERROR("unrecognised qualifier for group");
- }
- }
- else if (captures >= 0 && _capturing < captures)
- {
- nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_group_capture, ++_capturing));
- stack.top()->add_child(group);
- stack.push(group);
- }
- else
- {
- nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_group_non_capture));
- stack.top()->add_child(group);
- stack.push(group);
- }
- }
- else if (c[0] == ')')
- {
- if (stack.size() > 1)
- {
- if (stack.top()->type == nrex_group_look_ahead)
- {
- --lookahead_level;
- }
- stack.pop();
- }
- else
- {
- NREX_COMPILE_ERROR("unexpected ')'");
- }
- }
- else if (c[0] == '[')
- {
- nrex_node_group* group = NREX_NEW(nrex_node_group(nrex_group_bracket));
- stack.top()->add_child(group);
- if (c[1] == '^')
- {
- group->negate = true;
- ++c;
- }
- bool first_child = true;
- nrex_char previous_child;
- bool previous_child_single = false;
- while (true)
- {
- group->add_childset();
- ++c;
- if (c[0] == '\0')
- {
- NREX_COMPILE_ERROR("unclosed bracket expression '['");
- }
- if (c[0] == '[' && c[1] == ':')
- {
- const nrex_char* d = &c[2];
- nrex_class_type cls = nrex_parse_class(&d);
- if (cls != nrex_class_none)
- {
- c = d;
- group->add_child(NREX_NEW(nrex_node_class(cls)));
- previous_child_single = false;
- }
- else
- {
- group->add_child(NREX_NEW(nrex_node_char('[')));
- previous_child = '[';
- previous_child_single = true;
- }
- }
- else if (c[0] == ']' && !first_child)
- {
- break;
- }
- else if (c[0] == '\\')
- {
- if (nrex_is_shorthand(c[1]))
- {
- group->add_child(NREX_NEW(nrex_node_shorthand(c[1])));
- ++c;
- previous_child_single = false;
- }
- else
- {
- const nrex_char* d = c;
- nrex_char unescaped = nrex_unescape(d);
- if (c == d)
- {
- NREX_COMPILE_ERROR("invalid escape token");
- }
- group->add_child(NREX_NEW(nrex_node_char(unescaped)));
- c = d;
- previous_child = unescaped;
- previous_child_single = true;
- }
- }
- else if (previous_child_single && c[0] == '-')
- {
- bool is_range = false;
- nrex_char next;
- if (c[1] != '\0' && c[1] != ']')
- {
- if (c[1] == '\\')
- {
- const nrex_char* d = ++c;
- next = nrex_unescape(d);
- if (c == d)
- {
- NREX_COMPILE_ERROR("invalid escape token in range");
- }
- }
- else
- {
- next = c[1];
- ++c;
- }
- is_range = true;
- }
- if (is_range)
- {
- if (next < previous_child)
- {
- NREX_COMPILE_ERROR("text range out of order");
- }
- group->pop_back();
- group->add_child(NREX_NEW(nrex_node_range(previous_child, next)));
- previous_child_single = false;
- }
- else
- {
- group->add_child(NREX_NEW(nrex_node_char(c[0])));
- previous_child = c[0];
- previous_child_single = true;
- }
- }
- else
- {
- group->add_child(NREX_NEW(nrex_node_char(c[0])));
- previous_child = c[0];
- previous_child_single = true;
- }
- first_child = false;
- }
- }
- else if (nrex_is_quantifier(c[0]))
- {
- int min = 0;
- int max = -1;
- bool valid_quantifier = true;
- if (c[0] == '?')
- {
- min = 0;
- max = 1;
- }
- else if (c[0] == '+')
- {
- min = 1;
- max = -1;
- }
- else if (c[0] == '*')
- {
- min = 0;
- max = -1;
- }
- else if (c[0] == '{')
- {
- bool max_set = false;
- const nrex_char* d = c;
- while (true)
- {
- ++d;
- if (d[0] == '\0')
- {
- valid_quantifier = false;
- break;
- }
- else if (d[0] == '}')
- {
- break;
- }
- else if (d[0] == ',')
- {
- max_set = true;
- continue;
- }
- else if (d[0] < '0' || '9' < d[0])
- {
- valid_quantifier = false;
- break;
- }
- if (max_set)
- {
- if (max < 0)
- {
- max = int(d[0] - '0');
- }
- else
- {
- max = max * 10 + int(d[0] - '0');
- }
- }
- else
- {
- min = min * 10 + int(d[0] - '0');
- }
- }
- if (!max_set)
- {
- max = min;
- }
- if (valid_quantifier)
- {
- c = d;
- }
- }
- if (valid_quantifier)
- {
- if (stack.top()->back == NULL || !stack.top()->back->quantifiable)
- {
- NREX_COMPILE_ERROR("element not quantifiable");
- }
- nrex_node_quantifier* quant = NREX_NEW(nrex_node_quantifier(min, max));
- if (min == max)
- {
- if (stack.top()->back->length >= 0)
- {
- quant->length = max * stack.top()->back->length;
- }
- }
- else
- {
- if (nrex_has_lookbehind(stack))
- {
- NREX_COMPILE_ERROR("variable length quantifiers inside lookbehind not supported");
- }
- }
- quant->child = stack.top()->swap_back(quant);
- quant->child->previous = NULL;
- quant->child->next = NULL;
- quant->child->parent = quant;
- if (c[1] == '?')
- {
- quant->greedy = false;
- ++c;
- }
- }
- else
- {
- stack.top()->add_child(NREX_NEW(nrex_node_char(c[0])));
- }
- }
- else if (c[0] == '|')
- {
- if (nrex_has_lookbehind(stack))
- {
- NREX_COMPILE_ERROR("alternations inside lookbehind not supported");
- }
- stack.top()->add_childset();
- }
- else if (c[0] == '^' || c[0] == '$')
- {
- stack.top()->add_child(NREX_NEW(nrex_node_anchor((c[0] == '$'))));
- }
- else if (c[0] == '.')
- {
- stack.top()->add_child(NREX_NEW(nrex_node_shorthand('.')));
- }
- else if (c[0] == '\\')
- {
- if (nrex_is_shorthand(c[1]))
- {
- stack.top()->add_child(NREX_NEW(nrex_node_shorthand(c[1])));
- ++c;
- }
- else if (('1' <= c[1] && c[1] <= '9') || (c[1] == 'g' && c[2] == '{'))
- {
- int ref = 0;
- bool unclosed = false;
- if (c[1] == 'g')
- {
- unclosed = true;
- c = &c[2];
- }
- while ('0' <= c[1] && c[1] <= '9')
- {
- ref = ref * 10 + int(c[1] - '0');
- ++c;
- }
- if (c[1] == '}')
- {
- unclosed = false;
- ++c;
- }
- if (ref > _capturing || ref <= 0 || unclosed)
- {
- NREX_COMPILE_ERROR("backreference to non-existent capture");
- }
- if (nrex_has_lookbehind(stack))
- {
- NREX_COMPILE_ERROR("backreferences inside lookbehind not supported");
- }
- stack.top()->add_child(NREX_NEW(nrex_node_backreference(ref)));
- }
- else if (c[1] == 'b' || c[1] == 'B')
- {
- stack.top()->add_child(NREX_NEW(nrex_node_word_boundary(c[1] == 'B')));
- ++c;
- }
- else
- {
- const nrex_char* d = c;
- nrex_char unescaped = nrex_unescape(d);
- if (c == d)
- {
- NREX_COMPILE_ERROR("invalid escape token");
- }
- stack.top()->add_child(NREX_NEW(nrex_node_char(unescaped)));
- c = d;
- }
- }
- else
- {
- stack.top()->add_child(NREX_NEW(nrex_node_char(c[0])));
- }
- }
- if (stack.size() > 1)
- {
- NREX_COMPILE_ERROR("unclosed group '('");
- }
- return true;
-}
-
-bool nrex::match(const nrex_char* str, nrex_result* captures, int offset, int end) const
-{
- if (!_root)
- {
- return false;
- }
- nrex_search s(str, captures, _lookahead_depth);
- if (end >= offset)
- {
- s.end = end;
- }
- else
- {
- s.end = NREX_STRLEN(str);
- }
- for (int i = offset; i <= s.end; ++i)
- {
- for (int c = 0; c <= _capturing; ++c)
- {
- captures[c].start = 0;
- captures[c].length = 0;
- }
- if (_root->test(&s, i) >= 0)
- {
- return true;
- }
- }
- return false;
-}
diff --git a/drivers/nrex/nrex.hpp b/drivers/nrex/nrex.hpp
deleted file mode 100644
index d30b7d0102..0000000000
--- a/drivers/nrex/nrex.hpp
+++ /dev/null
@@ -1,176 +0,0 @@
-// NREX: Node RegEx
-// Version 0.2
-//
-// Copyright (c) 2015-2016, Zher Huei Lee
-// All rights reserved.
-//
-// This software is provided 'as-is', without any express or implied
-// warranty. In no event will the authors be held liable for any damages
-// arising from the use of this software.
-//
-// Permission is granted to anyone to use this software for any purpose,
-// including commercial applications, and to alter it and redistribute it
-// freely, subject to the following restrictions:
-//
-// 1. The origin of this software must not be misrepresented; you must not
-// claim that you wrote the original software. If you use this software
-// in a product, an acknowledgment in the product documentation would
-// be appreciated but is not required.
-//
-// 2. Altered source versions must be plainly marked as such, and must not
-// be misrepresented as being the original software.
-//
-// 3. This notice may not be removed or altered from any source
-// distribution.
-//
-
-#ifndef NREX_HPP
-#define NREX_HPP
-
-#include "nrex_config.h"
-
-#ifdef NREX_UNICODE
-typedef wchar_t nrex_char;
-#else
-typedef char nrex_char;
-#endif
-
-/*!
- * \brief Struct to contain the range of a capture result
- *
- * The range provided is relative to the begining of the searched string.
- *
- * \see nrex_node::match()
- */
-struct nrex_result
-{
- public:
- int start; /*!< Start of text range */
- int length; /*!< Length of text range */
-};
-
-class nrex_node;
-
-/*!
- * \brief Holds the compiled regex pattern
- */
-class nrex
-{
- private:
- unsigned int _capturing;
- unsigned int _lookahead_depth;
- nrex_node* _root;
- public:
-
- /*!
- * \brief Initialises an empty regex container
- */
- nrex();
-
- /*!
- * \brief Initialises and compiles the regex pattern
- *
- * This calls nrex::compile() with the same arguments. To check whether
- * the compilation was successfull, use nrex::valid().
- *
- * If the NREX_THROW_ERROR was defined it would automatically throw a
- * runtime error nrex_compile_error if it encounters a problem when
- * parsing the pattern.
- *
- * \param pattern The regex pattern
- * \param captures The maximum number of capture groups to allow. Any
- * extra would be converted to non-capturing groups.
- * If negative, no limit would be imposed. Defaults
- * to 9.
- *
- * \see nrex::compile()
- */
- nrex(const nrex_char* pattern, int captures = 9);
-
- ~nrex();
-
- /*!
- * \brief Removes the compiled regex and frees up the memory
- */
- void reset();
-
- /*!
- * \brief Checks if there is a compiled regex being stored
- * \return True if present, False if not present
- */
- bool valid() const;
-
- /*!
- * \brief Provides number of captures the compiled regex uses
- *
- * This is used to provide the array size of the captures needed for
- * nrex::match() to work. The size is actually the number of capture
- * groups + one for the matching of the entire pattern. This can be
- * capped using the extra argument given in nrex::compile()
- * (default 10).
- *
- * \return The number of captures
- */
- int capture_size() const;
-
- /*!
- * \brief Compiles the provided regex pattern
- *
- * This automatically removes the existing compiled regex if already
- * present.
- *
- * If the NREX_THROW_ERROR was defined it would automatically throw a
- * runtime error nrex_compile_error if it encounters a problem when
- * parsing the pattern.
- *
- * \param pattern The regex pattern
- * \param captures The maximum number of capture groups to allow. Any
- * extra would be converted to non-capturing groups.
- * If negative, no limit would be imposed. Defaults
- * to 9.
- * \return True if the pattern was succesfully compiled
- */
- bool compile(const nrex_char* pattern, int captures = 9);
-
- /*!
- * \brief Uses the pattern to search through the provided string
- * \param str The text to search through. It only needs to be
- * null terminated if the end point is not provided.
- * This also determines the starting anchor.
- * \param captures The array of results to store the capture results.
- * The size of that array needs to be the same as the
- * size given in nrex::capture_size(). As it matches
- * the function fills the array with the results. 0 is
- * the result for the entire pattern, 1 and above
- * corresponds to the regex capture group if present.
- * \param offset The starting point of the search. This does not move
- * the starting anchor. Defaults to 0.
- * \param end The end point of the search. This also determines
- * the ending anchor. If a number less than the offset
- * is provided, the search would be done until null
- * termination. Defaults to -1.
- * \return True if a match was found. False otherwise.
- */
- bool match(const nrex_char* str, nrex_result* captures, int offset = 0, int end = -1) const;
-};
-
-#ifdef NREX_THROW_ERROR
-
-#include <stdexcept>
-
-class nrex_compile_error : std::runtime_error
-{
- public:
- nrex_compile_error(const char* message)
- : std::runtime_error(message)
- {
- }
-
- ~nrex_compile_error() throw()
- {
- }
-};
-
-#endif
-
-#endif // NREX_HPP
diff --git a/drivers/nrex/nrex_config.h b/drivers/nrex/nrex_config.h
deleted file mode 100644
index 540f34f8b4..0000000000
--- a/drivers/nrex/nrex_config.h
+++ /dev/null
@@ -1,12 +0,0 @@
-// Godot-specific configuration
-// To use this, replace nrex_config.h
-
-#include "core/os/memory.h"
-
-#define NREX_UNICODE
-//#define NREX_THROW_ERROR
-
-#define NREX_NEW(X) memnew(X)
-#define NREX_NEW_ARRAY(X, N) memnew_arr(X, N)
-#define NREX_DELETE(X) memdelete(X)
-#define NREX_DELETE_ARRAY(X) memdelete_arr(X)
diff --git a/drivers/nrex/regex.cpp b/drivers/nrex/regex.cpp
deleted file mode 100644
index 7bf14d14ad..0000000000
--- a/drivers/nrex/regex.cpp
+++ /dev/null
@@ -1,142 +0,0 @@
-/*************************************************************************/
-/* regex.cpp */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#include "regex.h"
-#include "nrex.hpp"
-#include "core/os/memory.h"
-
-void RegEx::_bind_methods() {
-
- ObjectTypeDB::bind_method(_MD("compile","pattern", "capture"),&RegEx::compile, DEFVAL(9));
- ObjectTypeDB::bind_method(_MD("find","text","start","end"),&RegEx::find, DEFVAL(0), DEFVAL(-1));
- ObjectTypeDB::bind_method(_MD("clear"),&RegEx::clear);
- ObjectTypeDB::bind_method(_MD("is_valid"),&RegEx::is_valid);
- ObjectTypeDB::bind_method(_MD("get_capture_count"),&RegEx::get_capture_count);
- ObjectTypeDB::bind_method(_MD("get_capture","capture"),&RegEx::get_capture);
- ObjectTypeDB::bind_method(_MD("get_capture_start","capture"),&RegEx::get_capture_start);
- ObjectTypeDB::bind_method(_MD("get_captures"),&RegEx::_bind_get_captures);
-
-};
-
-StringArray RegEx::_bind_get_captures() const {
-
- StringArray ret;
- int count = get_capture_count();
- for (int i=0; i<count; i++) {
-
- String c = get_capture(i);
- ret.push_back(c);
- };
-
- return ret;
-
-};
-
-void RegEx::clear() {
-
- text.clear();
- captures.clear();
- exp.reset();
-
-};
-
-bool RegEx::is_valid() const {
-
- return exp.valid();
-
-};
-
-int RegEx::get_capture_count() const {
-
- ERR_FAIL_COND_V( !exp.valid(), 0 );
-
- return exp.capture_size();
-}
-
-String RegEx::get_capture(int capture) const {
-
- ERR_FAIL_COND_V( get_capture_count() <= capture, String() );
-
- return text.substr(captures[capture].start, captures[capture].length);
-
-}
-
-int RegEx::get_capture_start(int capture) const {
-
- ERR_FAIL_COND_V( get_capture_count() <= capture, -1 );
-
- return captures[capture].start;
-
-}
-
-Error RegEx::compile(const String& p_pattern, int capture) {
-
- clear();
-
- exp.compile(p_pattern.c_str(), capture);
-
- ERR_FAIL_COND_V( !exp.valid(), FAILED );
-
- captures.resize(exp.capture_size());
-
- return OK;
-
-};
-
-int RegEx::find(const String& p_text, int p_start, int p_end) const {
-
- ERR_FAIL_COND_V( !exp.valid(), -1 );
- ERR_FAIL_COND_V( p_text.length() < p_start, -1 );
- ERR_FAIL_COND_V( p_text.length() < p_end, -1 );
-
- bool res = exp.match(p_text.c_str(), &captures[0], p_start, p_end);
-
- if (res) {
- text = p_text;
- return captures[0].start;
- }
- text.clear();
- return -1;
-
-};
-
-RegEx::RegEx(const String& p_pattern) {
-
- compile(p_pattern);
-
-};
-
-RegEx::RegEx() {
-
-};
-
-RegEx::~RegEx() {
-
- clear();
-
-};
diff --git a/drivers/nrex/regex.h b/drivers/nrex/regex.h
deleted file mode 100644
index 74495442c7..0000000000
--- a/drivers/nrex/regex.h
+++ /dev/null
@@ -1,65 +0,0 @@
-/*************************************************************************/
-/* regex.h */
-/*************************************************************************/
-/* This file is part of: */
-/* GODOT ENGINE */
-/* http://www.godotengine.org */
-/*************************************************************************/
-/* Copyright (c) 2007-2016 Juan Linietsky, Ariel Manzur. */
-/* */
-/* Permission is hereby granted, free of charge, to any person obtaining */
-/* a copy of this software and associated documentation files (the */
-/* "Software"), to deal in the Software without restriction, including */
-/* without limitation the rights to use, copy, modify, merge, publish, */
-/* distribute, sublicense, and/or sell copies of the Software, and to */
-/* permit persons to whom the Software is furnished to do so, subject to */
-/* the following conditions: */
-/* */
-/* The above copyright notice and this permission notice shall be */
-/* included in all copies or substantial portions of the Software. */
-/* */
-/* THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, */
-/* EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF */
-/* MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT.*/
-/* IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY */
-/* CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, */
-/* TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE */
-/* SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE. */
-/*************************************************************************/
-#ifndef REGEX_H
-#define REGEX_H
-
-#include "ustring.h"
-#include "vector.h"
-#include "core/reference.h"
-#include "nrex.hpp"
-
-class RegEx : public Reference {
-
- OBJ_TYPE(RegEx, Reference);
-
- mutable String text;
- mutable Vector<nrex_result> captures;
- nrex exp;
-
-protected:
-
- static void _bind_methods();
- StringArray _bind_get_captures() const;
-
-public:
-
- void clear();
- bool is_valid() const;
- int get_capture_count() const;
- int get_capture_start(int capture) const;
- String get_capture(int capture) const;
- Error compile(const String& p_pattern, int capture = 9);
- int find(const String& p_text, int p_start = 0, int p_end = -1) const;
-
- RegEx();
- RegEx(const String& p_pattern);
- ~RegEx();
-};
-
-#endif // REGEX_H
diff --git a/drivers/png/SCsub b/drivers/png/SCsub
index 04cb70e1c1..6684e36b20 100644
--- a/drivers/png/SCsub
+++ b/drivers/png/SCsub
@@ -5,44 +5,44 @@ Import('env')
env_png = env.Clone()
# Thirdparty source files
-if (env["libpng"] == "builtin"):
- thirdparty_dir = "#thirdparty/libpng/"
- thirdparty_sources = [
- "png.c",
- "pngerror.c",
- "pngget.c",
- "pngmem.c",
- "pngpread.c",
- "pngread.c",
- "pngrio.c",
- "pngrtran.c",
- "pngrutil.c",
- "pngset.c",
- "pngtrans.c",
- "pngwio.c",
- "pngwrite.c",
- "pngwtran.c",
- "pngwutil.c",
- ]
- thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
+if (env['builtin_libpng'] != 'no'):
+ thirdparty_dir = "#thirdparty/libpng/"
+ thirdparty_sources = [
+ "png.c",
+ "pngerror.c",
+ "pngget.c",
+ "pngmem.c",
+ "pngpread.c",
+ "pngread.c",
+ "pngrio.c",
+ "pngrtran.c",
+ "pngrutil.c",
+ "pngset.c",
+ "pngtrans.c",
+ "pngwio.c",
+ "pngwrite.c",
+ "pngwtran.c",
+ "pngwutil.c",
+ ]
+ thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
- env_png.add_source_files(env.drivers_sources, thirdparty_sources)
- env_png.Append(CPPPATH = [thirdparty_dir])
+ env_png.add_source_files(env.drivers_sources, thirdparty_sources)
+ env_png.Append(CPPPATH=[thirdparty_dir])
- # Currently .ASM filter_neon.S does not compile on NT.
- import os
- if ("neon_enabled" in env and env["neon_enabled"]) and os.name!="nt":
- env_png.Append(CPPFLAGS = ["-DPNG_ARM_NEON_OPT=2"])
- env_neon = env_png.Clone();
- if "S_compiler" in env:
- env_neon['CC'] = env['S_compiler']
- neon_sources = []
- neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/arm_init.c"))
- neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon_intrinsics.c"))
- neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon.S"))
- env.drivers_sources += neon_sources
- else:
- env_png.Append(CPPFLAGS = ["-DPNG_ARM_NEON_OPT=0"])
+ # Currently .ASM filter_neon.S does not compile on NT.
+ import os
+ if ("neon_enabled" in env and env["neon_enabled"]) and os.name != "nt":
+ env_png.Append(CPPFLAGS=["-DPNG_ARM_NEON_OPT=2"])
+ env_neon = env_png.Clone()
+ if "S_compiler" in env:
+ env_neon['CC'] = env['S_compiler']
+ neon_sources = []
+ neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/arm_init.c"))
+ neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon_intrinsics.c"))
+ neon_sources.append(env_neon.Object(thirdparty_dir + "/arm/filter_neon.S"))
+ env.drivers_sources += neon_sources
+ else:
+ env_png.Append(CPPFLAGS=["-DPNG_ARM_NEON_OPT=0"])
# Godot source files
env_png.add_source_files(env.drivers_sources, "*.cpp")
diff --git a/drivers/register_driver_types.cpp b/drivers/register_driver_types.cpp
index 7486d4f217..e0f35e81c4 100644
--- a/drivers/register_driver_types.cpp
+++ b/drivers/register_driver_types.cpp
@@ -40,8 +40,6 @@
#include "platform/windows/export/export.h"
#endif
-#include "drivers/nrex/regex.h"
-
static ImageLoaderPNG *image_loader_png=NULL;
static ResourceSaverPNG *resource_saver_png=NULL;
@@ -53,8 +51,6 @@ void register_core_driver_types() {
resource_saver_png = memnew( ResourceSaverPNG );
ResourceSaver::add_resource_format_saver(resource_saver_png);
-
- ObjectTypeDB::register_type<RegEx>();
}
void unregister_core_driver_types() {
diff --git a/drivers/rtaudio/SCsub b/drivers/rtaudio/SCsub
index f0273dd421..2b0a602965 100644
--- a/drivers/rtaudio/SCsub
+++ b/drivers/rtaudio/SCsub
@@ -7,12 +7,12 @@ Import('env')
# Thirdparty source files
thirdparty_dir = "#thirdparty/rtaudio/"
thirdparty_sources = [
- "RtAudio.cpp",
+ "RtAudio.cpp",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env.add_source_files(env.drivers_sources, thirdparty_sources)
-env.Append(CPPPATH = [thirdparty_dir])
+env.Append(CPPPATH=[thirdparty_dir])
# Driver source files
env.add_source_files(env.drivers_sources, "*.cpp")
diff --git a/drivers/unix/SCsub b/drivers/unix/SCsub
index fe427e747f..3766e782e4 100644
--- a/drivers/unix/SCsub
+++ b/drivers/unix/SCsub
@@ -2,13 +2,13 @@
Import('env')
-g_set_p='#ifdef UNIX_ENABLED\n'
-g_set_p+='#include "os_unix.h"\n'
-g_set_p+='String OS_Unix::get_global_settings_path() const {\n'
-g_set_p+='\treturn "' + env["unix_global_settings_path"]+'";\n'
-g_set_p+='}\n'
-g_set_p+='#endif'
-f = open("os_unix_global_settings_path.cpp","wb")
+g_set_p = '#ifdef UNIX_ENABLED\n'
+g_set_p += '#include "os_unix.h"\n'
+g_set_p += 'String OS_Unix::get_global_settings_path() const {\n'
+g_set_p += '\treturn "' + env["unix_global_settings_path"] + '";\n'
+g_set_p += '}\n'
+g_set_p += '#endif'
+f = open("os_unix_global_settings_path.cpp", "wb")
f.write(g_set_p)
f.close()
diff --git a/drivers/unix/ip_unix.cpp b/drivers/unix/ip_unix.cpp
index d6d1be3395..e3d32618ee 100644
--- a/drivers/unix/ip_unix.cpp
+++ b/drivers/unix/ip_unix.cpp
@@ -33,6 +33,13 @@
#include <string.h>
#ifdef WINDOWS_ENABLED
+ // Workaround mingw missing flags!
+ #ifndef AI_ADDRCONFIG
+ #define AI_ADDRCONFIG 0x00000400
+ #endif
+ #ifndef AI_V4MAPPED
+ #define AI_V4MAPPED 0x00000800
+ #endif
#ifdef WINRT_ENABLED
#include <ws2tcpip.h>
#include <winsock2.h>
@@ -90,8 +97,10 @@ IP_Address IP_Unix::_resolve_hostname(const String& p_hostname, IP_Address::Addr
hints.ai_family = AF_INET;
} else if (p_type == IP_Address::TYPE_IPV6) {
hints.ai_family = AF_INET6;
+ hints.ai_flags = 0;
} else {
hints.ai_family = AF_UNSPEC;
+ hints.ai_flags = (AI_V4MAPPED | AI_ADDRCONFIG);
};
int s = getaddrinfo(p_hostname.utf8().get_data(), NULL, &hints, &result);
diff --git a/drivers/unix/packet_peer_udp_posix.cpp b/drivers/unix/packet_peer_udp_posix.cpp
index d6fc697c6d..ed295f0459 100644
--- a/drivers/unix/packet_peer_udp_posix.cpp
+++ b/drivers/unix/packet_peer_udp_posix.cpp
@@ -119,17 +119,24 @@ int PacketPeerUDPPosix::get_max_packet_size() const{
return 512; // uhm maybe not
}
-Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_address_type, int p_recv_buffer_size) {
-
- ERR_FAIL_COND_V(p_address_type != IP_Address::TYPE_IPV4 && p_address_type != IP_Address::TYPE_IPV6, ERR_INVALID_PARAMETER);
+Error PacketPeerUDPPosix::listen(int p_port, IP_Address::AddrType p_type, int p_recv_buffer_size) {
close();
- int sock = _get_socket(p_address_type);
+ int sock = _get_socket(p_type);
+
if (sock == -1 )
return ERR_CANT_CREATE;
+ if(p_type == IP_Address::TYPE_IPV6) {
+ // Use IPv6 only socket
+ int yes = 1;
+ if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) {
+ WARN_PRINT("Unable to unset IPv4 address mapping over IPv6");
+ }
+ }
+
sockaddr_storage addr = {0};
- size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_address_type, NULL);
+ size_t addr_size = _set_listen_sockaddr(&addr, p_port, p_type, NULL);
if (bind(sock, (struct sockaddr*)&addr, addr_size) == -1 ) {
close();
@@ -168,7 +175,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
rb.write(&type, 1);
struct sockaddr_in* sin_from = (struct sockaddr_in*)&from;
rb.write((uint8_t*)&sin_from->sin_addr, 4);
- port = sin_from->sin_port;
+ port = ntohs(sin_from->sin_port);
} else if (from.ss_family == AF_INET6) {
@@ -178,7 +185,7 @@ Error PacketPeerUDPPosix::_poll(bool p_wait) {
struct sockaddr_in6* s6_from = (struct sockaddr_in6*)&from;
rb.write((uint8_t*)&s6_from->sin6_addr, 16);
- port = s6_from->sin6_port;
+ port = ntohs(s6_from->sin6_port);
} else {
// WARN_PRINT("Ignoring packet with unknown address family");
@@ -223,11 +230,7 @@ int PacketPeerUDPPosix::_get_socket(IP_Address::AddrType p_type) {
if (sockfd != -1)
return sockfd;
- int family = p_type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET;
-
- sockfd = socket(family, SOCK_DGRAM, IPPROTO_UDP);
- ERR_FAIL_COND_V( sockfd == -1, -1 );
- //fcntl(sockfd, F_SETFL, O_NONBLOCK);
+ sockfd = _socket_create(p_type, SOCK_DGRAM, IPPROTO_UDP);
return sockfd;
}
diff --git a/drivers/unix/socket_helpers.h b/drivers/unix/socket_helpers.h
index 4ee40e3d3d..3aaae82da2 100644
--- a/drivers/unix/socket_helpers.h
+++ b/drivers/unix/socket_helpers.h
@@ -3,6 +3,17 @@
#include <string.h>
+#ifdef WINDOWS_ENABLED
+ // Workaround mingw missing flags!
+ #ifndef IPV6_V6ONLY
+ #define IPV6_V6ONLY 27
+ #endif
+#endif
+
+#ifdef WINRT_ENABLED
+#define in6addr_any IN6ADDR_ANY_INIT
+#endif
+
// helpers for sockaddr -> IP_Address and back, should work for posix and winsock. All implementations should use this
static size_t _set_sockaddr(struct sockaddr_storage* p_addr, const IP_Address& p_ip, int p_port) {
@@ -45,6 +56,27 @@ static size_t _set_listen_sockaddr(struct sockaddr_storage* p_addr, int p_port,
};
};
+static int _socket_create(IP_Address::AddrType p_type, int type, int protocol) {
+
+ ERR_FAIL_COND_V(p_type > IP_Address::TYPE_ANY || p_type < IP_Address::TYPE_NONE, ERR_INVALID_PARAMETER);
+
+ int family = p_type == IP_Address::TYPE_IPV4 ? AF_INET : AF_INET6;
+ int sockfd = socket(family, type, protocol);
+
+ ERR_FAIL_COND_V( sockfd == -1, -1 );
+
+ if(family == AF_INET6) {
+ // Ensure IPv4 over IPv6 is enabled
+ int no = 0;
+ if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&no, sizeof(no)) != 0) {
+ WARN_PRINT("Unable to set IPv4 address mapping over IPv6");
+ }
+ }
+
+ return sockfd;
+}
+
+
static void _set_ip_addr_port(IP_Address& r_ip, int& r_port, struct sockaddr_storage* p_addr) {
if (p_addr->ss_family == AF_INET) {
diff --git a/drivers/unix/stream_peer_tcp_posix.cpp b/drivers/unix/stream_peer_tcp_posix.cpp
index f2915b0a16..b1636abd69 100644
--- a/drivers/unix/stream_peer_tcp_posix.cpp
+++ b/drivers/unix/stream_peer_tcp_posix.cpp
@@ -137,8 +137,8 @@ Error StreamPeerTCPPosix::connect(const IP_Address& p_host, uint16_t p_port) {
ERR_FAIL_COND_V( p_host.type == IP_Address::TYPE_NONE, ERR_INVALID_PARAMETER);
- int family = p_host.type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET;
- if ((sockfd = socket(family, SOCK_STREAM, 0)) == -1) {
+ sockfd = _socket_create(p_host.type, SOCK_STREAM, IPPROTO_TCP);
+ if (sockfd == -1) {
ERR_PRINT("Socket creation failed!");
disconnect();
//perror("socket");
diff --git a/drivers/unix/tcp_server_posix.cpp b/drivers/unix/tcp_server_posix.cpp
index 05b739804c..7028c1a107 100644
--- a/drivers/unix/tcp_server_posix.cpp
+++ b/drivers/unix/tcp_server_posix.cpp
@@ -71,9 +71,17 @@ void TCPServerPosix::make_default() {
Error TCPServerPosix::listen(uint16_t p_port, IP_Address::AddrType p_type, const List<String> *p_accepted_hosts) {
int sockfd;
- int family = p_type == IP_Address::TYPE_IPV6 ? AF_INET6 : AF_INET;
- sockfd = socket(family, SOCK_STREAM, 0);
+ sockfd = _socket_create(p_type, SOCK_STREAM, IPPROTO_TCP);
+
ERR_FAIL_COND_V(sockfd == -1, FAILED);
+
+ if(p_type == IP_Address::TYPE_IPV6) {
+ // Use IPv6 only socket
+ int yes = 1;
+ if(setsockopt(sockfd, IPPROTO_IPV6, IPV6_V6ONLY, (const char*)&yes, sizeof(yes)) != 0) {
+ WARN_PRINT("Unable to unset IPv4 address mapping over IPv6");
+ }
+ }
#ifndef NO_FCNTL
fcntl(sockfd, F_SETFL, O_NONBLOCK);
#else
diff --git a/drivers/unix/tcp_server_posix.h b/drivers/unix/tcp_server_posix.h
index 134ec494cb..a700b6ae0e 100644
--- a/drivers/unix/tcp_server_posix.h
+++ b/drivers/unix/tcp_server_posix.h
@@ -40,7 +40,7 @@ class TCPServerPosix : public TCP_Server {
public:
- virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type = IP_Address::TYPE_IPV4, const List<String> *p_accepted_hosts=NULL);
+ virtual Error listen(uint16_t p_port, IP_Address::AddrType p_type, const List<String> *p_accepted_hosts=NULL);
virtual bool is_connection_available() const;
virtual Ref<StreamPeerTCP> take_connection();
diff --git a/drivers/zlib/SCsub b/drivers/zlib/SCsub
index 6a099aff52..407deb5f6e 100644
--- a/drivers/zlib/SCsub
+++ b/drivers/zlib/SCsub
@@ -8,19 +8,19 @@ Import('env')
# No check here as already done in drivers/SCsub
thirdparty_dir = "#thirdparty/zlib/"
thirdparty_sources = [
- "adler32.c",
- "compress.c",
- "crc32.c",
- "deflate.c",
- "infback.c",
- "inffast.c",
- "inflate.c",
- "inftrees.c",
- "trees.c",
- "uncompr.c",
- "zutil.c",
+ "adler32.c",
+ "compress.c",
+ "crc32.c",
+ "deflate.c",
+ "infback.c",
+ "inffast.c",
+ "inflate.c",
+ "inftrees.c",
+ "trees.c",
+ "uncompr.c",
+ "zutil.c",
]
thirdparty_sources = [thirdparty_dir + file for file in thirdparty_sources]
env.add_source_files(env.drivers_sources, thirdparty_sources)
-env.Append(CPPPATH = [thirdparty_dir])
+env.Append(CPPPATH=[thirdparty_dir])