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

Table-driven command-line parser. More...

#include "bfc_cli.h"
#include <stddef.h>
#include <stdio.h>
#include <string.h>
#include "bfc_common.h"

Data Structures

struct  bfc_option_t
 Metadata and behaviour for one command-line option. More...

Typedefs

typedef bfc_error_t(* bfc_option_handler_t) (bfc_args_t *args, const char *value)
 Option callback signature used by the table-driven parser.

Functions

static bfc_error_t bfc_set_help (bfc_args_t *args, const char *value)
 Sets the help-request flag.
static bfc_error_t bfc_set_assemble (bfc_args_t *args, const char *value)
 Enables assembly-only output.
static bfc_error_t bfc_set_no_comments (bfc_args_t *args, const char *value)
 Disables the semicolon-comment extension.
static bfc_error_t bfc_set_output (bfc_args_t *args, const char *value)
 Stores the borrowed output-path argument after duplicate detection.
static bfc_error_t bfc_set_target (bfc_args_t *args, const char *value)
 Stores the borrowed target-triple argument after duplicate detection.
static bfc_error_t bfc_set_version (bfc_args_t *args, const char *value)
 Sets the version-print flag.
static const bfc_option_tbfc_find_option (const char *argument)
 Finds option metadata by exact short or long spelling.
void bfc_cmd_help (void)
 Renders usage text from the same option table used for parsing.
bfc_error_t bfc_process_args (bfc_args_t *cmd_args, int argc, char *const argv[])
 Parses options, option values, the end-of-options marker, and one input path.

Variables

static const bfc_option_t BFC_OPTIONS []
 Single source of truth for option parsing and help rendering.

Detailed Description

Table-driven command-line parser.

Defines option metadata, handlers, help rendering, positional-input rules, and the end-of-options marker.

Typedef Documentation

◆ bfc_option_handler_t

typedef bfc_error_t(* bfc_option_handler_t) (bfc_args_t *args, const char *value)

Option callback signature used by the table-driven parser.

Function Documentation

◆ bfc_cmd_help()

void bfc_cmd_help ( void )

Renders usage text from the same option table used for parsing.

Prints command-line usage and option descriptions.

Renders usage text from the same option table used for parsing.

◆ bfc_find_option()

const bfc_option_t * bfc_find_option ( const char * argument)
static

Finds option metadata by exact short or long spelling.

◆ bfc_process_args()

bfc_error_t bfc_process_args ( bfc_args_t * cmd_args,
int argc,
char *const argv[] )

Parses options, option values, the end-of-options marker, and one input path.

Parses compiler command-line arguments.

Parses options, option values, the end-of-options marker, and one input path.

Parameters
[out]cmd_argsReceives zero-initialized parsed arguments.
[in]argcArgument count.
[in]argvArgument vector.
Returns
BFC_ERR_OK on success; otherwise an argument error.

◆ bfc_set_assemble()

bfc_error_t bfc_set_assemble ( bfc_args_t * args,
const char * value )
static

Enables assembly-only output.

◆ bfc_set_help()

bfc_error_t bfc_set_help ( bfc_args_t * args,
const char * value )
static

Sets the help-request flag.

◆ bfc_set_no_comments()

bfc_error_t bfc_set_no_comments ( bfc_args_t * args,
const char * value )
static

Disables the semicolon-comment extension.

◆ bfc_set_output()

bfc_error_t bfc_set_output ( bfc_args_t * args,
const char * value )
static

Stores the borrowed output-path argument after duplicate detection.

◆ bfc_set_target()

bfc_error_t bfc_set_target ( bfc_args_t * args,
const char * value )
static

Stores the borrowed target-triple argument after duplicate detection.

◆ bfc_set_version()

bfc_error_t bfc_set_version ( bfc_args_t * args,
const char * value )
static

Sets the version-print flag.

Variable Documentation

◆ BFC_OPTIONS

const bfc_option_t BFC_OPTIONS[]
static

Single source of truth for option parsing and help rendering.