Skip to content
Projects
Groups
Snippets
Help
Loading...
Help
Submit feedback
Contribute to GitLab
Sign in / Register
Toggle navigation
Sortix
Project
Project
Details
Activity
Releases
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Locked Files
Issues
412
Issues
412
List
Boards
Labels
Service Desk
Milestones
Merge Requests
2
Merge Requests
2
Wiki
Wiki
Members
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Commits
Issue Boards
Open sidebar
sortix
Sortix
Commits
d4bec88b
Commit
d4bec88b
authored
Oct 30, 2016
by
Jonas Termansen
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
Add REG_STARTEND.
parent
205a3e71
Changes
3
Hide whitespace changes
Inline
Side-by-side
Showing
3 changed files
with
28 additions
and
8 deletions
+28
-8
regex.h
libc/include/regex.h
+7
-1
regerror.c
libc/regex/regerror.c
+2
-1
regexec.c
libc/regex/regexec.c
+19
-6
No files found.
libc/include/regex.h
View file @
d4bec88b
/*
* Copyright (c) 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2015
, 2016
Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
...
...
@@ -140,6 +140,9 @@ typedef struct
#define REG_NOTBOL (1 << 0)
#define REG_NOTEOL (1 << 1)
#if __USE_SORTIX
#define REG_STARTEND (1 << 2)
#endif
#define REG_NOMATCH 1
#define REG_BADPAT 2
...
...
@@ -154,6 +157,9 @@ typedef struct
#define REG_ERANGE 11
#define REG_ESPACE 12
#define REG_BADRPT 13
#if __USE_SORTIX
#define REG_INVARG 14
#endif
#ifdef __cplusplus
extern
"C"
{
...
...
libc/regex/regerror.c
View file @
d4bec88b
/*
* Copyright (c) 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2015
, 2016
Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
...
...
@@ -43,6 +43,7 @@ size_t regerror(int errnum,
case
REG_ERANGE
:
msg
=
"Invalid endpoint in range expression"
;
break
;
case
REG_ESPACE
:
msg
=
"Out of memory"
;
break
;
case
REG_BADRPT
:
msg
=
"'?', '*', or '+' not preceded by valid regular expression"
;
break
;
case
REG_INVARG
:
msg
=
"Invalid arguments"
;
break
;
}
if
(
errbuf_size
)
strlcpy
(
errbuf
,
msg
,
errbuf_size
);
...
...
libc/regex/regexec.c
View file @
d4bec88b
/*
* Copyright (c) 2014, 2015 Jonas 'Sortie' Termansen.
* Copyright (c) 2014, 2015
, 2016
Jonas 'Sortie' Termansen.
*
* Permission to use, copy, modify, and distribute this software for any
* purpose with or without fee is hereby granted, provided that the above
...
...
@@ -21,6 +21,7 @@
#include <pthread.h>
#include <regex.h>
#include <stdbool.h>
#include <string.h>
#define QUEUE_CURRENT_STATE(new_state) \
{ \
...
...
@@ -105,6 +106,21 @@ int regexec(const regex_t* restrict regex_const,
if
(
regex
->
re_cflags
&
REG_NOSUB
)
nmatch
=
0
;
size_t
start
;
size_t
end
;
if
(
eflags
&
REG_STARTEND
)
{
if
(
pmatch
[
0
].
rm_so
<
0
||
pmatch
[
0
].
rm_eo
<
pmatch
[
0
].
rm_so
)
return
REG_INVARG
;
start
=
pmatch
[
0
].
rm_so
;
end
=
pmatch
[
0
].
rm_eo
;
}
else
{
start
=
0
;
end
=
strlen
(
string
);
}
for
(
size_t
i
=
0
;
i
<
nmatch
;
i
++
)
{
pmatch
[
i
].
rm_so
=
-
1
;
...
...
@@ -123,7 +139,7 @@ int regexec(const regex_t* restrict regex_const,
regex
->
re
->
re_is_current
=
0
;
for
(
size_t
i
=
0
;
true
;
i
++
)
for
(
size_t
i
=
start
;
i
<=
end
;
i
++
)
{
if
(
!
regex
->
re
->
re_is_current
&&
result
==
REG_NOMATCH
)
{
...
...
@@ -143,7 +159,7 @@ int regexec(const regex_t* restrict regex_const,
regex
->
re
->
re_matches
[
m
].
rm_eo
=
-
1
;
}
}
char
c
=
string
[
i
]
;
char
c
=
i
<
end
?
string
[
i
]
:
'\0'
;
for
(
struct
re
*
state
=
current_states
;
state
;
state
=
state
->
re_current_state_next
)
...
...
@@ -237,9 +253,6 @@ int regexec(const regex_t* restrict regex_const,
if
(
current_states
==
NULL
&&
result
==
0
)
break
;
if
(
c
==
'\0'
)
break
;
}
pthread_mutex_unlock
(
&
regex
->
re_lock
);
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment