⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 fcio.cpp

📁 非常好用的五子棋游戏源码
💻 CPP
字号:
// Created:09-21-98
// By Jeff Connelly

// COMPRLIB data I/O.

// File I/O for ComprLib.

#include "stdafx.h"
#include <stdio.h>
#include <string.h>
//#include <unistd.h>
#include <io.h>

//#include "fcio.h"
#define EXPORTING
#include "comprlib.h"

// File I/O class implementation


// Initalization of static members
FILE* ComprLibFileIO::source_file = NULL;
FILE* ComprLibFileIO::dest_file = NULL;
long ComprLibFileIO::file_limit = 0;
void (*ComprLibFileIO::read_callback)(long) = NULL;

bool ComprLibFileIO::byte_stored_status = false;
int ComprLibFileIO::val_byte_stored = 0;

// Returns 'true' if there is more data to read, else false.  The global
// variable 'file_limit' can be set to deturmine the end of the file if you
// want all of the file not to be read.  If the file limit is set to 0,
// the end of data state will be based on result of 'feof' function.
bool ComprLibFileIO::end_of_data()
{
    if (file_limit)                  // Non-zero, use this value
        return ftell(source_file) >= file_limit;
    else
        return feof(source_file);
}

// Reads a byte and returns it's value
unsigned char ComprLibFileIO::read_byte()
{
    if (read_callback)
        read_callback (filelength(fileno(source_file)));

    // If a byte is stored, return it's value
    if (byte_stored_status)
    {
        byte_stored_status = false;
        return (unsigned char)val_byte_stored;
    }

    if (end_of_data())      // No more data left!
        return 0;       

    // Otherwise read a byte
    return (unsigned char)fgetc(source_file);
}

// Writes a byte to the output stream
void ComprLibFileIO::write_byte(unsigned char byte)
{
    fputc (byte, dest_file);
}

// Sets the position to the beginning of the file stream
void ComprLibFileIO::beginning_of_data()
{
    byte_stored_status = false;
    rewind (source_file);
}

// Returns the length of the input stream
long ComprLibFileIO::stream_size ()
{
    return filelength(fileno(source_file));

    fseek (source_file, 0, SEEK_END);
    return ftell (source_file);
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -