ladybird/Libraries/LibC
Emanuel Sprung 55450055d8 LibRegex: Add a regular expression library
This commit is a mix of several commits, squashed into one because the
commits before 'Move regex to own Library and fix all the broken stuff'
were not fixable in any elegant way.
The commits are listed below for "historical" purposes:

- AK: Add options/flags and Errors for regular expressions

Flags can be provided for any possible flavour by adding a new scoped enum.
Handling of flags is done by templated Options class and the overloaded
'|' and '&' operators.

- AK: Add Lexer for regular expressions

The lexer parses the input and extracts tokens needed to parse a regular
expression.

- AK: Add regex Parser and PosixExtendedParser

This patchset adds a abstract parser class that can be derived to implement
different parsers. A parser produces bytecode to be executed within the
regex matcher.

- AK: Add regex matcher

This patchset adds an regex matcher based on the principles of the T-REX VM.
The bytecode pruduced by the respective Parser is put into the matcher and
the VM will recursively execute the bytecode according to the available OpCodes.
Possible improvement: the recursion could be replaced by multi threading capabilities.

To match a Regular expression, e.g. for the Posix standard regular expression matcher
use the following API:

```
Pattern<PosixExtendedParser> pattern("^.*$");
auto result = pattern.match("Well, hello friends!\nHello World!"); // Match whole needle

EXPECT(result.count == 1);
EXPECT(result.matches.at(0).view.starts_with("Well"));
EXPECT(result.matches.at(0).view.end() == "!");

result = pattern.match("Well, hello friends!\nHello World!", PosixFlags::Multiline); // Match line by line

EXPECT(result.count == 2);
EXPECT(result.matches.at(0).view == "Well, hello friends!");
EXPECT(result.matches.at(1).view == "Hello World!");

EXPECT(pattern.has_match("Well,....")); // Just check if match without a result, which saves some resources.
```

- AK: Rework regex to work with opcodes objects

This patchsets reworks the matcher to work on a more structured base.
For that an abstract OpCode class and derived classes for the specific
OpCodes have been added. The respective opcode logic is contained in
each respective execute() method.

- AK: Add benchmark for regex

- AK: Some optimization in regex for runtime and memory

- LibRegex: Move regex to own Library and fix all the broken stuff

Now regex works again and grep utility is also in place for testing.
This commit also fixes the use of regex.h in C by making `regex_t`
an opaque (-ish) type, which makes its behaviour consistent between
C and C++ compilers.
Previously, <regex.h> would've blown C compilers up, and even if it
didn't, would've caused a leak in C code, and not in C++ code (due to
the existence of `OwnPtr` inside the struct).

To make this whole ordeal easier to deal with (for now), this pulls the
definitions of `reg*()` into LibRegex.

pros:
- The circular dependency between LibC and LibRegex is broken
- Eaiser to test (without accidentally pulling in the host's libc!)

cons:
- Using any of the regex.h functions will require the user to link -lregex
- The symbols will be missing from libc, which will be a big surprise
  down the line (especially with shared libs).

Co-Authored-By: Ali Mohammad Pur <ali.mpfard@gmail.com>
2020-11-27 21:32:41 +01:00
..
arpa LibC: Fix a warning when building LibC with -O2 2020-10-20 18:10:22 +02:00
bits LibC: Add POSIX1 minimum limits to limits.h 2020-11-10 14:39:38 +01:00
net Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
netinet LibC: Add some missing netinet macros required by OpenSSH 2020-09-27 01:02:11 +02:00
sys LibPthread: Implement pthread_once() 2020-11-24 21:36:28 +01:00
alloca.h
assert.cpp LibC: Remove endless loop after abort() call 2020-05-26 14:35:10 +02:00
assert.h LibC: Make sure assert() expands to *something* in non-DEBUG builds 2020-08-11 20:29:14 +02:00
byteswap.h Meta: Add missing copyright headers 2020-04-06 11:09:01 +02:00
CMakeLists.txt CMake: Use CONFIGURE_DEPENDS in existing globs. 2020-10-29 11:52:47 +01:00
crt0.cpp LibC: Avoid ninja-imports of system functions 2020-08-12 20:40:59 +02:00
crti.S
crtn.S
ctype.cpp LibC: Remove an unneeded string.h include in ctype.h/cpp 2020-09-27 21:15:25 +02:00
ctype.h LibC: Remove an unneeded string.h include in ctype.h/cpp 2020-09-27 21:15:25 +02:00
cxxabi.cpp LibC: Move C++ABI functions to cxxabi.cpp, typecheck cxa_atexit 2020-08-12 20:40:59 +02:00
dirent.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
dirent.h
dlfcn.cpp Meta+LibC through LibHTTP: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
dlfcn.h
endian.h LibC: Fix big endian definitions 2020-02-19 16:08:28 +01:00
errno.h
errno_numbers.h Kernel+LibC: Don't allow a directory to become a subdirectory of itself 2020-11-01 19:21:19 +01:00
fcntl.cpp LibC: Missing varargs cleanup in fcntl 2020-08-17 09:17:57 +02:00
fcntl.h Kernel+LibC: Switch isatty() to use a fcntl() 2020-05-20 08:31:31 +02:00
fd_set.h
float.h Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
getopt.cpp LibC: Don't include things required for getopt_long in unistd.h 2020-09-06 21:36:36 +02:00
getopt.h LibC: Include cdefs.h in getopt.h 2020-09-27 01:02:11 +02:00
grp.cpp LibC: Use AK::String-backed buffers instead of static buffers 2020-08-30 17:35:27 +02:00
grp.h
iconv.h Meta+LibC through LibHTTP: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
inttypes.h LibC: Add some missing macros to inttypes.h 2020-02-20 06:51:16 +01:00
ioctl.cpp LibC: Missing varargs cleanup in ioctl 2020-08-17 09:17:57 +02:00
libcinit.cpp LibC: Move C++ABI functions to cxxabi.cpp, typecheck cxa_atexit 2020-08-12 20:40:59 +02:00
libgen.cpp
libgen.h
limits.h LibC: Add POSIX1 minimum limits to limits.h 2020-11-10 14:39:38 +01:00
locale.cpp LibC: Use dbgln() in setlocale() 2020-10-30 17:03:28 +01:00
locale.h
malloc.cpp LibC: Notify UE at the start of free() instead of at the end 2020-11-16 15:11:02 +01:00
mallocdefs.h LibC: Move some of malloc's data structures into mallocdefs.h 2020-11-14 22:51:49 +01:00
memory.h Meta: Add a script check the presence of "#pragma once" in header files 2020-05-29 07:59:45 +02:00
mman.cpp Kernel+LibC: Use uintptr_t as the main type in the syscall interface 2020-10-12 19:53:25 +02:00
mman.h Kernel+LibC: Add minherit() and MAP_INHERIT_ZERO 2020-04-12 20:22:26 +02:00
mntent.cpp
mntent.h
netdb.cpp Everywhere: Fix typos 2020-10-02 16:03:17 +02:00
netdb.h LibC: getprotoent() family of functions 2020-04-18 10:11:55 +02:00
paths.h LibC: Add paths.h with some default mail directory for now 2020-09-27 01:02:11 +02:00
poll.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
poll.h LibC+Kernel: Implement ppoll 2020-06-23 14:12:20 +02:00
pwd.cpp LibC: Use AK::String-backed buffers instead of static buffers 2020-08-30 17:35:27 +02:00
pwd.h LibC: Implement putpwent() 2020-02-02 10:58:45 +01:00
qsort.cpp LibC: Remove unused data member in the qsort() implementation 2020-08-24 18:22:09 +02:00
regex.h LibRegex: Add a regular expression library 2020-11-27 21:32:41 +01:00
scanf.cpp LibC: Add FIXME for vsscanf 2020-09-27 01:02:11 +02:00
sched.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
sched.h
serenity.cpp Kernel+LibC: Use uintptr_t as the main type in the syscall interface 2020-10-12 19:53:25 +02:00
serenity.h Kernel+LibC: Use uintptr_t as the main type in the syscall interface 2020-10-12 19:53:25 +02:00
setjmp.h Meta+LibC through LibHTTP: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
setjmp.S
signal.cpp Userland+LibC: Add "kill -l" to show all known signal names/numbers 2020-10-29 23:32:18 +01:00
signal.h Userland+LibC: Add "kill -l" to show all known signal names/numbers 2020-10-29 23:32:18 +01:00
signal_numbers.h Kernel+LibC+UE: Introduce SIGINFO (generated with ^T) 2020-09-09 21:10:23 +02:00
spawn.cpp Meta+LibC through LibHTTP: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
spawn.h Add manpages for posix_spawn 2020-07-06 10:01:14 +02:00
stat.cpp LibC: Move stat(), lstat() and fstat() to <sys/stat.h> 2020-08-11 20:29:14 +02:00
stdarg.h Kernel: Absorb LibBareMetal back into the kernel 2020-05-16 12:00:04 +02:00
stdbool.h
stddef.h Meta+LibC through LibHTTP: Make clang-format-10 clean 2020-09-25 21:18:17 +02:00
stdint.h
stdio.cpp AK: Make the return type of dbgputstr consistent. 2020-10-04 19:18:32 +02:00
stdio.h AK: Make the return type of dbgputstr consistent. 2020-10-04 19:18:32 +02:00
stdlib.cpp LibC: Ensure mkstemp generates a pattern 6 characters in length 2020-11-15 09:38:35 +01:00
stdlib.h LibC: Made mbtowc return int instead of size_t 2020-09-27 01:02:11 +02:00
string.cpp LibC: strtok_r() should not go past the last token 2020-11-14 11:24:42 +01:00
string.h LibC: Don't advertise wrong functions 2020-09-12 13:46:15 +02:00
strings.cpp
strings.h
syslog.cpp AK: Add a forward declaration header 2020-02-14 23:31:18 +01:00
syslog.h LibC: We still need to use NULL (not nullptr) in C headers 2020-10-14 13:57:51 +02:00
termcap.cpp LibC: Deprecate strcpy(), strncpy(), strcat() and strncat() :^) 2020-08-30 17:35:27 +02:00
termcap.h
termios.cpp LibC: Implement tcflush(3) 2020-07-11 11:33:33 +02:00
termios.h LibC: Implement cf{g,s}et{i,o}speed 2020-07-04 10:49:36 +02:00
time.cpp Kernel+LibC: Add adjtime(2) 2020-11-10 19:03:08 +01:00
time.h LibC: Make difftime a function 2020-10-15 13:45:00 +02:00
times.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
ulimit.cpp LibC: Log calls to getrusage 2020-05-07 23:32:11 +02:00
ulimit.h
unistd.cpp Kernel: Make copy_to/from_user safe and remove unnecessary checks 2020-09-13 21:19:15 +02:00
unistd.h Kernel: Implement _SC_OPEN_MAX 2020-09-27 01:02:11 +02:00
utime.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
utime.h
utmp.h LibC: Add missing utmp backwards compatibility hacks and user/dead process macros 2020-09-27 01:02:11 +02:00
utsname.cpp Kernel: Move headers intended for userspace use into Kernel/API/ 2020-07-04 17:22:23 +02:00
wchar.cpp
wchar.h