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

Source-file input and line extraction. More...

#include "bfc_io.h"
#include "bfc_error.h"
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>
#include "bfc_memory.h"

Functions

bfc_error_t bfc_program_create (bfc_program_t **program, char const *file_path)
 Loads a source file, copies its path, and counts addressable source lines.
void bfc_program_destroy (bfc_program_t **pprogram)
 Releases the source path, source bytes, and program object.
char const * bfc_program_getname (bfc_program_t const *program)
 Returns a borrowed pointer to the final path component.
char * bfc_program_getline (bfc_program_t const *const program, size_t const n)
 Copies one requested source line for diagnostic rendering.

Detailed Description

Source-file input and line extraction.

Loads the complete source file, tracks line count, stores the source path, and returns allocated diagnostic lines.

Function Documentation

◆ bfc_program_create()

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

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

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().

◆ bfc_program_destroy()

void bfc_program_destroy ( bfc_program_t ** pprogram)

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

Releases a source program and nulls the caller pointer.

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

◆ bfc_program_getline()

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

Copies one requested source line for diagnostic rendering.

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.

◆ bfc_program_getname()

char const * bfc_program_getname ( bfc_program_t const *const program)
nodiscard

Returns a borrowed pointer to the final path component.

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.