<commit_before>{-# LANGUAGE ForeignFunctionInterface #-}

-- Import @openpty@.
#ifdef __APPLE__
#include <util.h>
#elif __linux__
#include <pty.h>
#else
#error "Can't find openpty"
#endif

#include <unistd.h>

module Openpty where

import Control.Applicative
import System.Posix.Types (Fd(Fd))
import Data.Word

import Foreign.C
import Foreign.Ptr
import Foreign.Marshal
import Foreign.Storable

foreign import ccall unsafe "openpty"
  c_openpty :: Ptr CInt -> Ptr CInt -> CString -> Ptr Termios -> Ptr Winsize -> IO CInt

foreign import ccall unsafe "ioctl"
  c_ioctl_winsize :: CInt -> CULong -> Ptr Winsize -> IO CInt

data Winsize = Winsize { wsRow, wsCol, wsXPixel, wsYPixel :: CUShort }

type Tcflag_t = #{type tcflag_t}
type Cc_t     = #{type cc_t}
type Speed_t  = #{type speed_t}

nccs :: Int
nccs = #{const NCCS}

data Termios = Termios<commit_msg>Make imports portable (Linux and OS X).<commit_after>{-# LANGUAGE ForeignFunctionInterface #-}

#include <sys/ioctl.h>
#include <termios.h>
#include <unistd.h>

module Openpty where

import Control.Applicative
import System.Posix.Types (Fd(Fd))
import Data.Word

import Foreign.C
import Foreign.Ptr
import Foreign.Marshal
import Foreign.Storable

foreign import ccall unsafe "openpty"
  c_openpty :: Ptr CInt -> Ptr CInt -> CString -> Ptr Termios -> Ptr Winsize -> IO CInt

foreign import ccall unsafe "ioctl"
  c_ioctl_winsize :: CInt -> CULong -> Ptr Winsize -> IO CInt

data Winsize = Winsize { wsRow, wsCol, wsXPixel, wsYPixel :: CUShort }

type Tcflag_t = #{type tcflag_t}
type Cc_t     = #{type cc_t}
type Speed_t  = #{type speed_t}

nccs :: Int
nccs = #{const NCCS}

data Termios = Termios
{'fraction_non_alphanumeric': 0.1119177253478524, 'fraction_numerical': 0.0, 'mean_word_length': 4.267515923566879, 'pattern_counts': {'":': 0, '<': 9, '<?xml version=': 0, '>': 25, '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': '3555466', 'n_tokens_mistral': 628, 'n_tokens_neox': 619, 'n_words': 185}