Commit 6121089d authored by Drew's avatar Drew

Port to Linux

parent 39c72258
......@@ -25,7 +25,11 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.*/
#if os(OSX)
import Darwin
#elseif os(Linux)
import Glibc
#endif
protocol CarolineEngine {
func testAll(tests: [CarolineTest])
......
FROM drewcrawford/swift:latest
#install atbuild
RUN apt-get update && apt-get install --no-install-recommends xz-utils -y
ADD https://github.com/AnarchyTools/atbuild/releases/download/0.8.2/atbuild-0.8.2-linux.tar.xz /atbuild.tar.xz
RUN tar xf atbuild.tar.xz -C /usr/local
ADD . /Caroline
WORKDIR Caroline
RUN atbuild check
\ No newline at end of file
......@@ -39,5 +39,9 @@
:tool "shell"
:script "bin/SimpleTest"
}
:check {
:dependencies ["simpletest"]
:tool "nop"
}
}
)
\ No newline at end of file
......@@ -25,7 +25,11 @@ CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.*/
#if os(OSX)
import Darwin
#elseif os(Linux)
import Glibc
#endif
enum FileUtilsError: ErrorProtocol {
case OpenError(Int)
......
......@@ -30,7 +30,11 @@ POSSIBILITY OF SUCH DAMAGE.*/
/// let r = try! Regex(pattern: "class[[:space:]]+([[:alnum:]]+)[[:space:]]*:CarolineTest[[:space:]]*\\{")
/// print(try! r.match("prefix stuff class Foo:CarolineTest {"))
#if os(OSX)
import Darwin
#elseif os(Linux)
import Glibc
#endif
enum RegexError: ErrorProtocol {
/////The regexec() function failed to match
......@@ -58,18 +62,39 @@ enum RegexError: ErrorProtocol {
/// `?', `*', or `+' operand invalid
case Repeat
/// empty (sub)expression
///- note: This error is only thrown on OSX
case Empty
/// cannot happen - you found a bug [in libc]
///- note: This error is only thrown on OSX
case Bug
/// e.g. negative-length string
///- note: This error is only thrown on OSX
case InvalidArgument
/// (bad multibyte character)
///- note: This error is only thrown on OSX
case IllegalByteSequence
/// Invalid use of back reference operator.
///- note: This error is only thrown on Linux
case BadBackReference
///A nonspecific error
///- note: This error is only thrown on Linux
case NonSpecific
///Compiled regular expression requires a pattern buffer larger than 64kb.
///- note: This error is only thrown on Linux
case ExpressionTooComplex
/// An error not in the POSIX specification.
case ErrorNotInSpecification(Int)
init(fromRegDiagnostic diagnostic: Int32) {
switch(diagnostic) {
#if os(OSX)
let os_diagnostic = diagnostic
#elseif os(Linux)
let os_diagnostic = reg_errcode_t(diagnostic)
#endif
switch(os_diagnostic) {
case REG_NOMATCH:
self = RegexError.NoMatch
case REG_BADPAT:
......@@ -94,15 +119,44 @@ enum RegexError: ErrorProtocol {
self = RegexError.OutOfMemory
case REG_BADRPT:
self = RegexError.Repeat
case REG_EMPTY:
self = RegexError.Empty
case REG_ASSERT:
self = RegexError.Bug
case REG_INVARG:
self = RegexError.InvalidArgument
case REG_ILLSEQ:
self = RegexError.IllegalByteSequence
default:
//additional errors supported on Linux
#if os(Linux)
switch(os_diagnostic) {
case REG_BADBR:
self = RegexError.BadBackReference
return
case REG_EEND:
self = RegexError.NonSpecific
return
case REG_ESIZE:
self = RegexError.ExpressionTooComplex
return
default:
break
}
#endif
//additional errors supported on OSX
#if os(OSX)
switch(os_diagnostic) {
case REG_EMPTY:
self = RegexError.Empty
return
case REG_ASSERT:
self = RegexError.Bug
return
case REG_INVARG:
self = RegexError.InvalidArgument
return
case REG_ILLSEQ:
self = RegexError.IllegalByteSequence
return
default:
break
}
#endif
self = RegexError.ErrorNotInSpecification(Int(diagnostic))
}
}
......@@ -210,7 +264,13 @@ struct Regex {
var weDontMutateThis = self.regexImp.regext
var matches: [regmatch_t] = [regmatch_t](repeating: regmatch_t(), count: self.regexImp.regext.re_nsub + 1)
let result = regexec(&weDontMutateThis, string, matches.count, &matches, 0)
if result == REG_NOMATCH { return nil }
#if os(OSX)
let os_nomatch = REG_NOMATCH
#elseif os(Linux)
let os_nomatch = REG_NOMATCH.rawValue
#endif
if result == os_nomatch { return nil }
if result != 0 {
throw RegexError(fromRegDiagnostic: result)
}
......
......@@ -27,7 +27,11 @@ ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
POSSIBILITY OF SUCH DAMAGE.
*/
#if os(OSX)
import Darwin
#elseif os(Linux)
import Glibc
#endif
func usage() {
print("caroline-static-tool 0.1-dev")
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment