<commit_before>import libc

public protocol PosixSubsystem {
    func system(_ command: String) -> Int32
    func fileExists(_ path: String) -> Bool
    func fail(_ message: String, cancelled: Bool)
}

extension PosixSubsystem {
    public func fail(_ message: String) {
        self.fail(message, cancelled: false)
    }
}

public struct Shell: PosixSubsystem {

    public func system(_ command: String) -> Int32 {
        return libc.system(command)
    }

    public func fileExists(_ path: String) -> Bool {
        return libc.system("ls \(path) > /dev/null 2>&1") == 0
    }

    public func fail(_ message: String, cancelled: Bool) {
        print()
        print("Error: \(message)")
        if !cancelled {
            print("Note: Make sure you are using Swift 3.0 Snapshot 06-06")
        }
        libc.exit(1)
    }
}

public protocol Runnable {
    func run(in: PosixSubsystem) throws
}

public typealias ShellCommand = String

extension ShellCommand: Runnable {

    public func run(in shell: PosixSubsystem) throws {
        let result = shell.system(self)

        if result == 2 {
            throw Error.cancelled
        } else if result != 0 {
            throw Error.system(result)
        }
    }
    
}

// Utility functions

@noreturn public func fail(_ message: String, cancelled: Bool = false) {
    print()
    print("Error: \(message)")
    if !cancelled {
        print("Note: Make sure you are using Swift 3.0 Snapshot 06-06")
    }
    exit(1)
}

enum Error: ErrorProtocol { // Errors pertaining to running commands
    case system(Int32)
    case cancelled
    case terminalSize
}


func runWithOutput(_ command: String) throws -> String { // Command needs to use the absolute path for the executable
    // Run the command
    let fp = popen(command, "r")

    defer {
        pclose(fp)
    }

    if let fp = fp {
        // Get the output of the command
        let pathSize: Int32 = 1035<commit_msg>Added FIXME<commit_after>import libc

public protocol PosixSubsystem {
    func system(_ command: String) -> Int32
    func fileExists(_ path: String) -> Bool
    func fail(_ message: String, cancelled: Bool)
}

extension PosixSubsystem {
    public func fail(_ message: String) {
        self.fail(message, cancelled: false)
    }
}

public struct Shell: PosixSubsystem {

    public func system(_ command: String) -> Int32 {
        return libc.system(command)
    }

    public func fileExists(_ path: String) -> Bool {
        return libc.system("ls \(path) > /dev/null 2>&1") == 0
    }

    public func fail(_ message: String, cancelled: Bool) {
        print()
        print("Error: \(message)")
        if !cancelled {
            print("Note: Make sure you are using Swift 3.0 Snapshot 06-06")
        }
        libc.exit(1)
    }
}

public protocol Runnable {
    func run(in: PosixSubsystem) throws
}

public typealias ShellCommand = String

extension ShellCommand: Runnable {

    public func run(in shell: PosixSubsystem) throws {
        let result = shell.system(self)

        if result == 2 {
            throw Error.cancelled
        } else if result != 0 {
            throw Error.system(result)
        }
    }
    
}

// Utility functions

// FIXME: remove once all commands are migrated to Shell.fail
@noreturn public func fail(_ message: String, cancelled: Bool = false) {
    print()
    print("Error: \(message)")
    if !cancelled {
        print("Note: Make sure you are using Swift 3.0 Snapshot 06-06")
    }
    exit(1)
}

enum Error: ErrorProtocol { // Errors pertaining to running commands
    case system(Int32)
    case cancelled
    case terminalSize
}


func runWithOutput(_ command: String) throws -> String { // Command needs to use the absolute path for the executable
    // Run the command
    let fp = popen(command, "r")

    defer {
        pclose(fp)
    }

    if let fp = fp {
        // Get the output of the command
        let pathSize: Int32 = 1035
{'fraction_non_alphanumeric': 0.09908536585365854, 'fraction_numerical': 0.015752032520325202, 'mean_word_length': 2.3910422049956934, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 17, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5497001', 'n_tokens_mistral': 1215, 'n_tokens_neox': 1127, 'n_words': 393}