Crossfire Server, Trunk
bufferreader.h File Reference
#include "microtar.h"
#include "logger.h"
+ Include dependency graph for bufferreader.h:
+ This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Typedefs

typedef struct BufferReader BufferReader
 

Functions

BufferReaderbufferreader_create ()
 
size_t bufferreader_current_line (BufferReader *br)
 
char * bufferreader_data (BufferReader *br)
 
size_t bufferreader_data_length (BufferReader *br)
 
void bufferreader_destroy (BufferReader *br)
 
char * bufferreader_get_line (BufferReader *br, char *buffer, size_t length)
 
BufferReaderbufferreader_init_from_file (BufferReader *br, const char *filepath, const char *failureMessage, LogLevel failureLevel)
 
void bufferreader_init_from_tar_file (BufferReader *br, mtar_t *tar, mtar_header_t *h)
 
char * bufferreader_next_line (BufferReader *br)
 

Detailed Description

Implements a buffer reader.

Usage is: BufferReader *reader = bufferreader_create(); bufferreader_init_from_file(reader, opened_file); char *buf: while ((buf = bufferreader_next_line(reader)) != NULL) { (...) } bufferreader_destroy(reader);

Alternative is to access the buffer's full data through bufferreader_data() and bufferreader_data_length().

Buffer may and should be reused to avoid allocating/freeing memory all the time.

No function ever fails. In case not enough memory is available, {} is called.

Definition in file bufferreader.h.

Typedef Documentation

◆ BufferReader

typedef struct BufferReader BufferReader

The reader state.

Definition at line 50 of file bufferreader.h.

Function Documentation

◆ bufferreader_create()

BufferReader* bufferreader_create ( )

Create a new BufferReader.

Returns
new buffer, never NULL.

Definition at line 31 of file bufferreader.c.

References fatal(), and OUT_OF_MEMORY.

Referenced by AssetCollector::AssetCollector(), bufferreader_init_from_file(), and TarLoader::TarLoader().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bufferreader_current_line()

size_t bufferreader_current_line ( BufferReader br)

Return the index of the last line returned by bufferreader_next_line().

Parameters
brbuffer to get the line index of.
Returns
line index, starting from 1.

Definition at line 131 of file bufferreader.c.

References BufferReader::line_index.

Referenced by init_formulae(), MessageLoader::load(), TreasureLoader::load(), load_bells(), load_citylife(), TreasureLoader::loadTreasure(), and LicenseManager::readLicense().

+ Here is the caller graph for this function:

◆ bufferreader_data()

char* bufferreader_data ( BufferReader br)

Get the whole buffer, independently of the calls to bufferreader_next_line().

Parameters
brbuffer.
Returns
buffer data, may be NULL.

Definition at line 139 of file bufferreader.c.

References BufferReader::buf.

Referenced by PngLoader::load(), and tar_read().

+ Here is the caller graph for this function:

◆ bufferreader_data_length()

size_t bufferreader_data_length ( BufferReader br)

Return the length of the buffer data.

Parameters
brbuffer.
Returns
buffer length.

Definition at line 135 of file bufferreader.c.

References BufferReader::buffer_length.

Referenced by PngLoader::load(), and tar_read().

+ Here is the caller graph for this function:

◆ bufferreader_destroy()

void bufferreader_destroy ( BufferReader br)

Destroy a BufferReader.

Parameters
brbuffer to destroy, pointer becomes invalid after the call.

Definition at line 40 of file bufferreader.c.

References BufferReader::buf.

Referenced by accounts_load(), display_help_file(), AssetCollector::~AssetCollector(), and TarLoader::~TarLoader().

+ Here is the caller graph for this function:

◆ bufferreader_get_line()

char* bufferreader_get_line ( BufferReader br,
char *  buffer,
size_t  length 
)

Copy the next line in the buffer, keeping the newline.

Parameters
brbuffer to get the line from.
bufferwhere to put the line.
lengthmaximum length of buffer.
Returns
NULL if no more data is available, buffer else.

Definition at line 110 of file bufferreader.c.

References BufferReader::current_line, BufferReader::line_index, and MIN.

Referenced by load_object_from_reader().

+ Here is the caller graph for this function:

◆ bufferreader_init_from_file()

BufferReader* bufferreader_init_from_file ( BufferReader br,
const char *  filepath,
const char *  failureMessage,
LogLevel  failureLevel 
)

Initialize or create a BufferReader from a file path. The whole file is read into memory.

Parameters
brbuffer to initialize, if NULL then a new BufferReader is created.
filepathpath of the file to read.
failureMessagemessage to LOG() in case of open failure. Must contain 2 placeholders 's' for the filepath and the error message.
failureLevellog level to use in case of failure.
Returns
BufferReader with the file contents, NULL in case of error, in which case a LOG() is emitted.

Definition at line 65 of file bufferreader.c.

References BufferReader::buf, BufferReader::buffer_length, bufferreader_create(), bufferreader_init_for_length(), mad_mage_user::file, llevError, and LOG().

Referenced by accounts_load(), display_help_file(), and AssetCollector::processFiles().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bufferreader_init_from_tar_file()

void bufferreader_init_from_tar_file ( BufferReader br,
mtar_t tar,
mtar_header_t h 
)

Initialize a BufferReader from a tar file entry.

Parameters
brbuffer to initialize.
tartar file pointer.
hheader in the tar file to initialize for.

Definition at line 88 of file bufferreader.c.

References BufferReader::buf, bufferreader_init_for_length(), mtar_read_data(), and mtar_header_t::size.

Referenced by TarLoader::load().

+ Here is the call graph for this function:
+ Here is the caller graph for this function:

◆ bufferreader_next_line()

char* bufferreader_next_line ( BufferReader br)

Return the next line in the buffer, as separated by a newline.

Parameters
brbuffer to get the line from.
Returns
NULL if end of buffer is reached, else a null-terminated string.

Definition at line 93 of file bufferreader.c.

References BufferReader::current_line, and BufferReader::line_index.

Referenced by accounts_load(), display_help_file(), init_artifacts(), init_attackmess(), init_formulae(), FacesetLoader::load(), MessageLoader::load(), FaceLoader::load(), TreasureLoader::load(), load_bells(), load_citylife(), load_materials(), load_races(), FaceLoader::loadAnimationBlock(), TreasureLoader::loadTreasure(), and LicenseManager::readLicense().

+ Here is the caller graph for this function: