<commit_before>/* io_stdio.c
 *  Copyright: (When this is determined...it will go here)
 *  CVS Info
 *      $Id$
 *  Overview:
 *      This is the Parrot IO STDIO layer. This may provide a subset of
 *      full functionality, but must compile on any system with the
 *      ANSI C standard library.  Also note that unlike the other low-level
 *      IO layers (UNIX, Win32), this is _buffered_ IO, out of necessity.
 * 
 *  Data Structure and Algorithms:
 *  History:
 *      Adapted from io_unix.c by <NAME> (<EMAIL>)
 *  Notes:
 *  References:
 */

#include <stdio.h>
#include "parrot/parrot.h"

#ifdef PIO_OS_STDIO

/* Defined at bottom */
extern ParrotIOLayerAPI pio_stdio_layer_api;

ParrotIOLayer pio_stdio_layer = {
    NULL,
    "stdio",
    PIO_L_TERMINAL,
    &pio_stdio_layer_api,
    0, 0
};


/*
 * Currently keeping layer prototypes local to each layer
 * file.
 */

INTVAL PIO_stdio_init(theINTERP, ParrotIOLayer *layer);
ParrotIO *PIO_stdio_open(theINTERP, ParrotIOLayer *layer,
                        const char *spath, INTVAL flags);
ParrotIO *PIO_stdio_fdopen(theINTERP, ParrotIOLayer *layer,
                          PIOHANDLE fd, INTVAL flags);
INTVAL PIO_stdio_close(theINTERP, ParrotIOLayer *layer, ParrotIO *io);
void PIO_stdio_flush(theINTERP, ParrotIOLayer *layer, ParrotIO *io);
size_t PIO_stdio_read(theINTERP, ParrotIOLayer *layer,
                     ParrotIO *io, void *buffer, size_t len);
size_t PIO_stdio_write(theINTERP, ParrotIOLayer *layer,
                      ParrotIO *io, const void *buffer, size_t len);
INTVAL PIO_stdio_puts(theINTERP, ParrotIOLayer *l, ParrotIO *io, const char *s);
INTVAL PIO_stdio_seek(theINTERP, ParrotIOLayer *l, ParrotIO *io,
                     INTVAL hi, INTVAL lo, INTVAL whence);
PIOOFF_T PIO_stdio_tell(theINTERP, ParrotIOLayer *l, ParrotIO *io);




char *
flags_to_stdio(INTVAL flags)
{
    if ((flags & (PIO_F_WRITE | PIO_F_READ | PIO_F_APPEND)) ==
        (PIO_F_WRITE | PIO_F_READ | PIO_F_APPEND)) {
        return "a+b";
    }
    else if ((flags & (PIO_F_WRITE | PIO_F_READ | PIO_F_TRUNC)) == 
             (PIO_F_WRITE | PIO_F_READ | PIO_F_TRUNC)) {
        return "w+b";
    }
    else if ((flags & (PIO_F_WRITE | PIO_F_READ)) == 
             (PIO_F_WRITE | PIO_F_READ)) {
        return "r+b";
    }
    else if (flags & PIO_F_APPEND) {
        return "ab";
    }    
    else if (flags & PIO_F_WRITE) {
        return "wb";
    }
    else if (flags & PIO_F_READ) {
        return "rb";
    }
}


/*
 * Setup standard streams, etc.
 */
INTVAL
PIO_stdio_init(theINTERP, ParrotIOLayer *layer)
{
    PIO_STDIN(interpreter) =
        PIO_stdio_fdopen(interpreter, layer, stdin, PIO_F_READ);

    PIO_STDOUT(interpreter) =
        PIO_stdio_fdopen(interpreter, layer, stdout, PIO_F_WRITE);

    PIO_STDERR(interpreter) =
        PIO_stdio_fdopen(interpreter, layer, stderr, PIO_F_WRITE);

    return 0;
}


/*
 * Open modes (read, write, append, etc.) are done in pseudo-Perl
 * style using <, >, etc.
 */
ParrotIO *
PIO_stdio_open(theINTERP, ParrotIOLayer *layer,
              const char *spath, INTVAL flags)
{
    ParrotIO *io;
    char *oflags;
    INTVAL type;
    FILE *fptr;
    type = PIO_TYPE_FILE;<commit_msg>Fix some warnings that slipped in<commit_after>/* io_stdio.c
 *  Copyright: (When this is determined...it will go here)
 *  CVS Info
 *      $Id$
 *  Overview:
 *      This is the Parrot IO STDIO layer. This may provide a subset of
 *      full functionality, but must compile on any system with the
 *      ANSI C standard library.  Also note that unlike the other low-level
 *      IO layers (UNIX, Win32), this is _buffered_ IO, out of necessity.
 * 
 *  Data Structure and Algorithms:
 *  History:
 *      Adapted from io_unix.c by <NAME> (<EMAIL>)
 *  Notes:
 *  References:
 */

#include <stdio.h>
#include "parrot/parrot.h"

#ifdef PIO_OS_STDIO

/* Defined at bottom */
extern ParrotIOLayerAPI pio_stdio_layer_api;

ParrotIOLayer pio_stdio_layer = {
    NULL,
    "stdio",
    PIO_L_TERMINAL,
    &pio_stdio_layer_api,
    0, 0
};


/*
 * Currently keeping layer prototypes local to each layer
 * file.
 */
const char * flags_to_stdio(INTVAL flags);

INTVAL PIO_stdio_init(theINTERP, ParrotIOLayer *layer);
ParrotIO *PIO_stdio_open(theINTERP, ParrotIOLayer *layer,
                        const char *spath, INTVAL flags);
ParrotIO *PIO_stdio_fdopen(theINTERP, ParrotIOLayer *layer,
                          PIOHANDLE fd, INTVAL flags);
INTVAL PIO_stdio_close(theINTERP, ParrotIOLayer *layer, ParrotIO *io);
void PIO_stdio_flush(theINTERP, ParrotIOLayer *layer, ParrotIO *io);
size_t PIO_stdio_read(theINTERP, ParrotIOLayer *layer,
                     ParrotIO *io, void *buffer, size_t len);
size_t PIO_stdio_write(theINTERP, ParrotIOLayer *layer,
                      ParrotIO *io, const void *buffer, size_t len);
INTVAL PIO_stdio_puts(theINTERP, ParrotIOLayer *l, ParrotIO *io, const char *s);
INTVAL PIO_stdio_seek(theINTERP, ParrotIOLayer *l, ParrotIO *io,
                     INTVAL hi, INTVAL lo, INTVAL whence);
PIOOFF_T PIO_stdio_tell(theINTERP, ParrotIOLayer *l, ParrotIO *io);




const char *
flags_to_stdio(INTVAL flags)
{
    if ((flags & (PIO_F_WRITE | PIO_F_READ | PIO_F_APPEND)) ==
        (PIO_F_WRITE | PIO_F_READ | PIO_F_APPEND)) {
        return "a+b";
    }
    else if ((flags & (PIO_F_WRITE | PIO_F_READ | PIO_F_TRUNC)) == 
             (PIO_F_WRITE | PIO_F_READ | PIO_F_TRUNC)) {
        return "w+b";
    }
    else if ((flags & (PIO_F_WRITE | PIO_F_READ)) == 
             (PIO_F_WRITE | PIO_F_READ)) {
        return "r+b";
    }
    else if (flags & PIO_F_APPEND) {
        return "ab";
    }    
    else if (flags & PIO_F_WRITE) {
        return "wb";
    }
    else {
        /* PIO_F_READ, hopefully */
        return "rb";
    }
}


/*
 * Setup standard streams, etc.
 */
INTVAL
PIO_stdio_init(theINTERP, ParrotIOLayer *layer)
{
    PIO_STDIN(interpreter) =
        PIO_stdio_fdopen(interpreter, layer, stdin, PIO_F_READ);

    PIO_STDOUT(interpreter) =
        PIO_stdio_fdopen(interpreter, layer, stdout, PIO_F_WRITE);

    PIO_STDERR(interpreter) =
        PIO_stdio_fdopen(interpreter, layer, stderr, PIO_F_WRITE);

    return 0;
}


/*
 * Open modes (read, write, append, etc.) are done in pseudo-Perl
 * style using <, >, etc.
 */
ParrotIO *
PIO_stdio_open(theINTERP, ParrotIOLayer *layer,
              const char *spath, INTVAL flags)
{
    ParrotIO *io;
    const char *oflags;
    INTVAL type;
    FILE *fptr;
    type = PIO_TYPE_FILE;
{'fraction_non_alphanumeric': 0.10408006158583526, 'fraction_numerical': 0.001539645881447267, 'mean_word_length': 2.9298245614035086, 'pattern_counts': {'":': 0, '<': 11, '<?xml version=': 0, '>': 11, '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': '1299027', 'n_tokens_mistral': 2492, 'n_tokens_neox': 2415, 'n_words': 589}