BFC-Compiler
A C23 Brainfuck compiler
Loading...
Searching...
No Matches
bfc_io.h File Reference

Source-file loading and source-line access. More...

#include <stddef.h>
#include "bfc_error.h"

Go to the source code of this file.

Data Structures

struct  bfc_program_t
 Owning representation of a loaded source file. More...

Typedefs

typedef struct bfc_program_t bfc_program_t
 Owning representation of a loaded source file.

Functions

bfc_error_t bfc_program_create (bfc_program_t **program, char const *file_path)
 Loads an entire source file into memory.
void bfc_program_destroy (bfc_program_t **pprogram)
 Releases a source program and nulls the caller pointer.
char const * bfc_program_getname (bfc_program_t const *const program)
 Returns the base name of the source path.
char * bfc_program_getline (bfc_program_t const *const program, size_t const n)
 Copies one source line into a new allocation.

Detailed Description

Source-file loading and source-line access.

Defines the owning source-program object and its lifecycle.

Typedef Documentation

◆ bfc_program_t

typedef struct bfc_program_t bfc_program_t

Owning representation of a loaded source file.

Note
path and buffer are released by bfc_program_destroy().

Function Documentation

◆ bfc_program_create()

bfc_error_t bfc_program_create ( bfc_program_t ** program,
char const * file_path )

Loads an entire source file into memory.

Loads a source file, copies its path, and counts addressable source lines.

Parameters
[out]programReceives the allocated source object.
[in]file_pathPath of the source file to load.
Returns
BFC_ERR_OK on success; otherwise an I/O or allocation error.
Note
Release the result with bfc_program_destroy().

Loads an entire source file into memory.

◆ bfc_program_destroy()

void bfc_program_destroy ( bfc_program_t ** pprogram)

Releases a source program and nulls the caller pointer.

Releases the source path, source bytes, and program object.

Releases a source program and nulls the caller pointer.

◆ bfc_program_getline()

char * bfc_program_getline ( bfc_program_t const *const program,
size_t const n )
nodiscard

Copies one source line into a new allocation.

Copies one requested source line for diagnostic rendering.

Parameters
[in]programLoaded source program.
[in]nOne-based line number.
Returns
A newly allocated line string, or nullptr when unavailable.
Note
The caller must free the returned string.

Copies one source line into a new allocation.

◆ bfc_program_getname()

char const * bfc_program_getname ( bfc_program_t const * program)
nodiscard

Returns the base name of the source path.

Returns a borrowed pointer to the final path component.

Returns
A borrowed pointer into program->path; do not free it.

Returns the base name of the source path.