<commit_before>#define PERL_NO_GET_CONTEXT 1
#include <EXTERN.h>
#include <perl.h>
#include <perliol.h>
#define NO_XSLOCKS /* XSUB.h will otherwise override various things we need */
#include <XSUB.h>
#define NEED_sv_2pv_flags
#include "patchlevel.h" /* for local_patches */

const char * VERSION   = "0.999.999";
static const char * NAMESPACE = "mIRC";

#define BUFFER_SIZE  4096
#define WM_MCOMMAND  WM_USER + 200
#define WM_MEVALUATE WM_USER + 201

typedef struct {
    short major;
    short minor;
} MVERSION;

typedef struct {
    MVERSION mVersion;
    HWND   mHwnd;
    BOOL   mKeep;
} LOADINFO;

static PerlInterpreter *my_perl = NULL;

HWND mWnd;
BOOL loaded;
HANDLE hMapFile;
LPSTR mData;

EXTERN_C void xs_init ( pTHX );
EXTERN_C void boot_DynaLoader ( pTHX_ CV* cv );
EXTERN_C void boot_Win32CORE ( pTHX_ CV* cv );

EXTERN_C void xs_init( pTHX ) {
    PERL_UNUSED_CONTEXT;
    char *file = __FILE__;
    dXSUB_SYS;
    /* DynaLoader is a special case; Win32 is a special m[h?ea?d] case */
    newXS( "DynaLoader::boot_DynaLoader", boot_DynaLoader, file );

void
mIRC_execute ( const char * snippet ) {
    wsprintf( mData, snippet );
    SendMessage( mWnd, WM_MCOMMAND, ( WPARAM ) NULL, ( LPARAM ) NULL );
    return;
}

const char *
mIRC_evaluate ( const char * variable ) {
    lstrcpy( mData, variable );
    return SendMessage( mWnd, WM_MEVALUATE, ( WPARAM ) NULL, ( LPARAM ) NULL ) ?
           mData : "";
}

#ifdef PERLIO_LAYERS

#include "perliol.h"

typedef struct {
    struct _PerlIO base; /* Base "class" info */
    SV     *       var;
    SV     *       arg;
    Off_t          posn;
} PerlIOmIRC;


SSize_t PerlIOmIRC_read( pTHX_ PerlIO *f, void *vbuf, Size_t count ) {
    STDCHAR *buf = ( STDCHAR * ) vbuf;
    if ( f ) {
        if ( !( PerlIOBase( f )->flags & PERLIO_F_CANREAD ) ) {
            PerlIOBase( f )->flags |= PERLIO_F_ERROR;
            SETERRNO( EBADF, SS_IVCHAN );
            return 0;
        }
        while ( count > 0 ) {
get_cnt: {
                SSize_t avail = PerlIO_get_cnt( f );
                SSize_t take = 0;
                if ( avail > 0 )
                    take = ( ( SSize_t )count < avail ) ? ( SSize_t )count : avail;
                if ( take > 0 ) {
                    STDCHAR *ptr = PerlIO_get_ptr( f );
                    Copy( ptr, buf, take, STDCHAR );
                    PerlIO_set_ptrcnt( f, ptr + take, ( avail -= take ) );
                    count -= take;
                    buf += take;
                    if ( avail == 0 )  /* set_ptrcnt could have reset avail */
                        goto get_cnt;
                }
                if ( count > 0 && avail <= 0 ) {
                    if ( PerlIO_fill( f ) != 0 )
                        break;
                }
            }
        }
        return ( buf - ( STDCHAR * ) vbuf );
    }
    return 0;
}

}
void
    newXS( "Win32CORE::bootstrap", boot_Win32CORE, file );
}

PERLIO_FUNCS_DECL( PerlIO_mIRC ) = {
    sizeof( PerlIO_funcs ),
    "mIRC",
    sizeof( PerlIOmIRC ),
    PERLIO_K_RAW,<commit_msg>Send a signal with the appropriate file handle name to mIRC<commit_after>#define PERL_NO_GET_CONTEXT 1
#include <EXTERN.h>
#include <perl.h>
#include <perliol.h>
#define NO_XSLOCKS /* XSUB.h will otherwise override various things we need */
#include <XSUB.h>
#define NEED_sv_2pv_flags
#include "patchlevel.h" /* for local_patches */

const char * VERSION   = "0.999.999";
static const char * NAMESPACE = "mIRC";

#define BUFFER_SIZE  4096
#define WM_MCOMMAND  WM_USER + 200
#define WM_MEVALUATE WM_USER + 201

typedef struct {
    short major;
    short minor;
} MVERSION;

typedef struct {
    MVERSION mVersion;
    HWND   mHwnd;
    BOOL   mKeep;
} LOADINFO;

static PerlInterpreter *my_perl = NULL;

HWND mWnd;
BOOL loaded;
HANDLE hMapFile;
LPSTR mData;

EXTERN_C void xs_init ( pTHX );
EXTERN_C void boot_DynaLoader ( pTHX_ CV* cv );
EXTERN_C void boot_Win32CORE ( pTHX_ CV* cv );

EXTERN_C void xs_init( pTHX ) {
    PERL_UNUSED_CONTEXT;
    char *file = __FILE__;
    dXSUB_SYS;
    /* DynaLoader is a special case; Win32 is a special m[h?ea?d] case */
    newXS( "DynaLoader::boot_DynaLoader", boot_DynaLoader, file );

void
mIRC_execute ( const char * snippet ) {
    wsprintf( mData, snippet );
    SendMessage( mWnd, WM_MCOMMAND, ( WPARAM ) NULL, ( LPARAM ) NULL );
    return;
}

const char *
mIRC_evaluate ( const char * variable ) {
    lstrcpy( mData, variable );
    return SendMessage( mWnd, WM_MEVALUATE, ( WPARAM ) NULL, ( LPARAM ) NULL ) ?
           mData : "";
}

#ifdef PERLIO_LAYERS

#include "perliol.h"

typedef struct {
    struct _PerlIO base; /* Base "class" info */
    SV     *       var;
    SV     *       arg;
    Off_t          posn;
} PerlIOmIRC;


SSize_t PerlIOmIRC_read( pTHX_ PerlIO *f, void *vbuf, Size_t count ) {
    STDCHAR *buf = ( STDCHAR * ) vbuf;
    if ( f ) {
        if ( !( PerlIOBase( f )->flags & PERLIO_F_CANREAD ) ) {
            PerlIOBase( f )->flags |= PERLIO_F_ERROR;
            SETERRNO( EBADF, SS_IVCHAN );
            return 0;
        }
        while ( count > 0 ) {
get_cnt: {
                SSize_t avail = PerlIO_get_cnt( f );
                SSize_t take = 0;
                if ( avail > 0 )
                    take = ( ( SSize_t )count < avail ) ? ( SSize_t )count : avail;
                if ( take > 0 ) {
                    STDCHAR *ptr = PerlIO_get_ptr( f );
                    Copy( ptr, buf, take, STDCHAR );
                    PerlIO_set_ptrcnt( f, ptr + take, ( avail -= take ) );
                    count -= take;
                    buf += take;
                    if ( avail == 0 )  /* set_ptrcnt could have reset avail */
                        goto get_cnt;
                }
                if ( count > 0 && avail <= 0 ) {
                    if ( PerlIO_fill( f ) != 0 )
                        break;
                }
            }
        }
        return ( buf - ( STDCHAR * ) vbuf );
    }
    return 0;
}

SSize_t PerlIOmIRC_write( pTHX_ PerlIO * f, const void *vbuf, Size_t count ) {
    PerlIOmIRC * e = PerlIOSelf( f, PerlIOmIRC );
    AV * av = newAV();
    const char * fh = "UNKNOWN";
    if      ( f == PerlIO_stdin( ) )
        fh = "STDIN"; /* Should never get write */
    else if ( f == PerlIO_stdout( ) )
        fh = "STDOUT";
    else if ( f == PerlIO_stderr( ) )
        fh = "STDERR";
    mIRC_execute( form( "/.signal -n PERL_%s %s", fh, vbuf ) );
    return count;
}
void
    newXS( "Win32CORE::bootstrap", boot_Win32CORE, file );
}

PERLIO_FUNCS_DECL( PerlIO_mIRC ) = {
    sizeof( PerlIO_funcs ),
    "mIRC",
    sizeof( PerlIOmIRC ),
    PERLIO_K_RAW,
{'fraction_non_alphanumeric': 0.11082590970859127, 'fraction_numerical': 0.0111731843575419, 'mean_word_length': 1.9770786516853933, 'pattern_counts': {'":': 0, '<': 15, '<?xml version=': 0, '>': 23, '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': '3247289', 'n_tokens_mistral': 2512, 'n_tokens_neox': 2359, 'n_words': 620}