Compare commits
No commits in common. "main" and "v2.0.0" have entirely different histories.
25 changed files with 53 additions and 785 deletions
|
|
@ -109,7 +109,7 @@ Multiple matching code blocks are concatenated with a blank line separator.
|
||||||
## Building
|
## Building
|
||||||
|
|
||||||
c-md is self-hosted
|
c-md is self-hosted
|
||||||
([dogfooding](https://en.wikipedia.org/wiki/Self-hosting_(compilers))). The
|
(dogfooding)[https://en.wikipedia.org/wiki/Self-hosting_(compilers)]. The
|
||||||
source code is written in `.c.md` format and requires c-md itself to build.
|
source code is written in `.c.md` format and requires c-md itself to build.
|
||||||
|
|
||||||
### First Build (Bootstrap)
|
### First Build (Bootstrap)
|
||||||
|
|
|
||||||
|
|
@ -1,18 +1,9 @@
|
||||||
# cli.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef CLI_H
|
#ifndef CLI_H
|
||||||
# define CLI_H
|
# define CLI_H
|
||||||
|
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
```
|
|
||||||
|
|
||||||
## Types
|
|
||||||
|
|
||||||
### `t_args`
|
|
||||||
Struct to hold command-line arguments.
|
|
||||||
```c
|
|
||||||
typedef struct s_args
|
typedef struct s_args
|
||||||
{
|
{
|
||||||
const char *ext;
|
const char *ext;
|
||||||
|
|
@ -21,24 +12,12 @@ typedef struct s_args
|
||||||
const char *map_path;
|
const char *map_path;
|
||||||
uint8_t show_help;
|
uint8_t show_help;
|
||||||
} t_args;
|
} t_args;
|
||||||
```
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### [`cli_parse`](/srcs/cli/cli.c.md#cli_parse)
|
|
||||||
Parses command-line arguments and populates the t_args structure.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
cli_parse(t_args *args, int32_t argc, char **argv);
|
cli_parse(t_args *args, int32_t argc, char **argv);
|
||||||
```
|
|
||||||
|
|
||||||
### [`cli_print_help`](/srcs/cli/help.c.md#cli_printhelp)
|
|
||||||
Prints help information for the command-line interface.
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
cli_print_help(const char *progname);
|
cli_print_help(const char *progname);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
# map_internal.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef MAP_INTERNAL_H
|
#ifndef MAP_INTERNAL_H
|
||||||
# define MAP_INTERNAL_H
|
# define MAP_INTERNAL_H
|
||||||
|
|
@ -8,19 +5,17 @@
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include "map.h"
|
# include "map.h"
|
||||||
# define MAP_INIT_CAP 16 // Default initial capacity for the map
|
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
# define MAP_INIT_CAP 16
|
||||||
|
|
||||||
### [`map_grow`](/srcs/map/core.c.md#map_grow)
|
|
||||||
Grows the map's capacity when needed.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
map_grow(t_map *map);
|
map_grow(t_map *map);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
int8_t
|
||||||
```c
|
write_header(FILE *f, const char *source, const char *target);
|
||||||
|
|
||||||
|
int8_t
|
||||||
|
write_ranges(FILE *f, t_map *map);
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
# transpile_internal.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef TRANSPILE_INTERNAL_H
|
#ifndef TRANSPILE_INTERNAL_H
|
||||||
# define TRANSPILE_INTERNAL_H
|
# define TRANSPILE_INTERNAL_H
|
||||||
|
|
@ -8,13 +5,7 @@
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include "map.h"
|
# include "map.h"
|
||||||
```
|
|
||||||
|
|
||||||
## Types
|
|
||||||
|
|
||||||
### `t_state`
|
|
||||||
Struct to hold the state of the transpilation process.
|
|
||||||
```c
|
|
||||||
typedef struct s_state
|
typedef struct s_state
|
||||||
{
|
{
|
||||||
FILE *in;
|
FILE *in;
|
||||||
|
|
@ -28,39 +19,21 @@ typedef struct s_state
|
||||||
uint8_t in_block;
|
uint8_t in_block;
|
||||||
uint8_t first_block;
|
uint8_t first_block;
|
||||||
} t_state;
|
} t_state;
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### [`state_init`](/srcs/transpile/state.c.md#state_init)
|
|
||||||
Initializes the transpilation state.
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
state_init(t_state *s, FILE *in, FILE *out, const char *ext, t_map *map);
|
state_init(t_state *s, FILE *in, FILE *out, const char *ext, t_map *map);
|
||||||
```
|
|
||||||
|
|
||||||
### [`handle_fence_open`](/srcs/transpile/fence.c.md#handle_fence_open)
|
int8_t
|
||||||
Handles the opening of a code fence in the input.
|
process_line(t_state *s, char *line);
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
handle_fence_open(t_state *s, char *line);
|
handle_fence_open(t_state *s, char *line);
|
||||||
```
|
|
||||||
|
|
||||||
### [`handle_fence_close`](/srcs/transpile/fence.c.md#handle_fence_open)
|
|
||||||
Handles the closing of a code fence in the input.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
handle_fence_close(t_state *s);
|
handle_fence_close(t_state *s);
|
||||||
```
|
|
||||||
|
|
||||||
### [`handle_code_line`](/srcs/transpile/code.c.md#handle_code_line)
|
|
||||||
Handles a regular line of code in the input.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
handle_code_line(t_state *s, char *line);
|
handle_code_line(t_state *s, char *line);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,40 +1,21 @@
|
||||||
# io.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef IO_H
|
#ifndef IO_H
|
||||||
# define IO_H
|
# define IO_H
|
||||||
|
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
```
|
|
||||||
|
|
||||||
## Types
|
|
||||||
```c
|
|
||||||
typedef struct s_io
|
typedef struct s_io
|
||||||
{
|
{
|
||||||
FILE *in;
|
FILE *in;
|
||||||
FILE *out;
|
FILE *out;
|
||||||
} t_io;
|
} t_io;
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### [`io_open`](/srcs/io/streams.c.md#io_open)
|
|
||||||
Opens input and output streams based on provided file paths.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
io_open(t_io *io, const char *input_path, const char *output_path);
|
io_open(t_io *io, const char *input_path, const char *output_path);
|
||||||
```
|
|
||||||
|
|
||||||
### [`io_close`](/srcs/io/streams.c.md#io_close)
|
|
||||||
Closes the input and output streams if they are not stdin or stdout.
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
io_close(t_io *io);
|
io_close(t_io *io);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,20 +1,10 @@
|
||||||
# map.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef MAP_H
|
#ifndef MAP_H
|
||||||
# define MAP_H
|
# define MAP_H
|
||||||
|
|
||||||
# include <stddef.h>
|
# include <stddef.h>
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
```
|
|
||||||
|
|
||||||
## Types
|
|
||||||
|
|
||||||
### `t_range`
|
|
||||||
A structure representing a mapping range between source and destination
|
|
||||||
addresses.
|
|
||||||
```c
|
|
||||||
typedef struct s_range
|
typedef struct s_range
|
||||||
{
|
{
|
||||||
uint32_t src_start;
|
uint32_t src_start;
|
||||||
|
|
@ -22,51 +12,26 @@ typedef struct s_range
|
||||||
uint32_t dst_start;
|
uint32_t dst_start;
|
||||||
uint32_t dst_end;
|
uint32_t dst_end;
|
||||||
} t_range;
|
} t_range;
|
||||||
```
|
|
||||||
|
|
||||||
### `t_map`
|
|
||||||
A structure representing a collection of mapping ranges.
|
|
||||||
```c
|
|
||||||
typedef struct s_map
|
typedef struct s_map
|
||||||
{
|
{
|
||||||
t_range *ranges;
|
t_range *ranges;
|
||||||
size_t count;
|
size_t count;
|
||||||
size_t capacity;
|
size_t capacity;
|
||||||
} t_map;
|
} t_map;
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### [`map_init`](/srcs/map/core.c.md#map_init)
|
|
||||||
Initialize a mapping structure.
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
map_init(t_map *map);
|
map_init(t_map *map);
|
||||||
```
|
|
||||||
|
|
||||||
### [`map_add`](/srcs/map/core.c.md#map_add)
|
|
||||||
Add a new mapping range to the mapping structure.
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
map_add(t_map *map, uint32_t src_start, uint32_t src_end,
|
map_add(t_map *map, uint32_t src_start, uint32_t src_end,
|
||||||
uint32_t dst_start, uint32_t dst_end);
|
uint32_t dst_start, uint32_t dst_end);
|
||||||
```
|
|
||||||
|
|
||||||
### [`map_write`](/srcs/map/io.c.md#map_write)
|
|
||||||
Write the mapping information to a file.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
map_write(t_map *map, const char *path, const char *source, const char *target);
|
map_write(t_map *map, const char *path, const char *source, const char *target);
|
||||||
```
|
|
||||||
|
|
||||||
### [`map_free`](/srcs/map/core.c.md#map_free)
|
|
||||||
Free the resources associated with the mapping structure.
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
map_free(t_map *map);
|
map_free(t_map *map);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,6 +1,3 @@
|
||||||
# transpile.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef TRANSPILE_H
|
#ifndef TRANSPILE_H
|
||||||
# define TRANSPILE_H
|
# define TRANSPILE_H
|
||||||
|
|
@ -8,16 +5,9 @@
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
# include "map.h"
|
# include "map.h"
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
### [`transpile`](/srcs/transpile/core.c.md#transpile)
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
transpile(FILE *in, FILE *out, const char *ext, t_map *map);
|
transpile(FILE *in, FILE *out, const char *ext, t_map *map);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,51 +1,24 @@
|
||||||
# utils.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef UTILS_H
|
#ifndef UTILS_H
|
||||||
# define UTILS_H
|
# define UTILS_H
|
||||||
|
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include <stdio.h>
|
# include <stdio.h>
|
||||||
```
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### [`read_line`](/srcs/utils/io/read_line.c.md#read_line)
|
|
||||||
Get a line from a file.
|
|
||||||
```c
|
|
||||||
char *
|
char *
|
||||||
read_line(FILE *f);
|
read_line(FILE *f);
|
||||||
```
|
|
||||||
|
|
||||||
### [`starts_with`](/srcs/utils/string/starts_with.c.md#starts_with)
|
|
||||||
Check if a string starts with a given prefix.
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
starts_with(const char *str, const char *prefix);
|
starts_with(const char *str, const char *prefix);
|
||||||
```
|
|
||||||
|
|
||||||
### [`extract_fence_ext`](/srcs/utils/string/extract_fence_ext.c.md#extract_fence_ext)
|
|
||||||
Extract the extension from a fence string.
|
|
||||||
```c
|
|
||||||
char *
|
char *
|
||||||
extract_fence_ext(const char *fence);
|
extract_fence_ext(const char *fence);
|
||||||
```
|
|
||||||
|
|
||||||
### [`extract_file_ext`](/srcs/utils/string/extract_file_ext.c.md#extract_file_ext)
|
|
||||||
Extract the file extension from a file path.
|
|
||||||
```c
|
|
||||||
const char *
|
const char *
|
||||||
extract_file_ext(const char *path);
|
extract_file_ext(const char *path);
|
||||||
```
|
|
||||||
|
|
||||||
### [`infer_ext_from_filename`](/srcs/utils/string/infer_ext_from_filename.c.md#infer_ext_from_filename)
|
|
||||||
Infer the file extension from a filename.
|
|
||||||
```c
|
|
||||||
const char *
|
const char *
|
||||||
infer_ext_from_filename(const char *path);
|
infer_ext_from_filename(const char *path);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,12 @@
|
||||||
# validator.h
|
|
||||||
|
|
||||||
## Include Guard
|
|
||||||
```c
|
```c
|
||||||
#ifndef VALIDATOR_H
|
#ifndef VALIDATOR_H
|
||||||
# define VALIDATOR_H
|
# define VALIDATOR_H
|
||||||
|
|
||||||
# include <stdint.h>
|
# include <stdint.h>
|
||||||
# include "cli.h"
|
# include "cli.h"
|
||||||
```
|
|
||||||
|
|
||||||
## Functions
|
|
||||||
|
|
||||||
### [`validator_validate_args`](/srcs/validator/validator.c.md#validator_validate_args)
|
|
||||||
This function checks and validates the content of the `t_args` structure,
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
validator_validate_args(t_args *args);
|
validator_validate_args(t_args *args);
|
||||||
```
|
|
||||||
|
|
||||||
## End Guard
|
|
||||||
```c
|
|
||||||
#endif
|
#endif
|
||||||
```
|
```
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,18 @@
|
||||||
# cli.c
|
|
||||||
The command-line interface (CLI) parser for the c-md transpiler.
|
|
||||||
Handles parsing command-line arguments and populating the t_args structure.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
|
|
||||||
### Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
#include <getopt.h>
|
#include <getopt.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
### Structs and Type Definitions
|
|
||||||
|
|
||||||
Function pointer type for option handlers.
|
|
||||||
```c
|
|
||||||
typedef void (*t_handler)(t_args *, const char *);
|
typedef void (*t_handler)(t_args *, const char *);
|
||||||
```
|
|
||||||
|
|
||||||
Struct to map short options to their handlers.
|
|
||||||
```c
|
|
||||||
typedef struct s_opt
|
typedef struct s_opt
|
||||||
{
|
{
|
||||||
int8_t short_opt;
|
int8_t short_opt;
|
||||||
t_handler handler;
|
t_handler handler;
|
||||||
} t_opt;
|
} t_opt;
|
||||||
```
|
|
||||||
|
|
||||||
### Forward Declarations
|
|
||||||
```c
|
|
||||||
static void handle_help(t_args *args, const char *value);
|
static void handle_help(t_args *args, const char *value);
|
||||||
static void handle_ext(t_args *args, const char *value);
|
static void handle_ext(t_args *args, const char *value);
|
||||||
static void handle_input(t_args *args, const char *value);
|
static void handle_input(t_args *args, const char *value);
|
||||||
|
|
@ -41,12 +20,7 @@ static void handle_output(t_args *args, const char *value);
|
||||||
static void handle_map(t_args *args, const char *value);
|
static void handle_map(t_args *args, const char *value);
|
||||||
static t_handler find_handler(int8_t opt);
|
static t_handler find_handler(int8_t opt);
|
||||||
static void init_args(t_args *args);
|
static void init_args(t_args *args);
|
||||||
```
|
|
||||||
|
|
||||||
### Static Variables
|
|
||||||
|
|
||||||
Initialize the mapping of options to their handlers.
|
|
||||||
```c
|
|
||||||
static const t_opt g_opts[] = {
|
static const t_opt g_opts[] = {
|
||||||
{'h', handle_help},
|
{'h', handle_help},
|
||||||
{'e', handle_ext},
|
{'e', handle_ext},
|
||||||
|
|
@ -55,11 +29,7 @@ static const t_opt g_opts[] = {
|
||||||
{'m', handle_map},
|
{'m', handle_map},
|
||||||
{0, NULL}
|
{0, NULL}
|
||||||
};
|
};
|
||||||
```
|
|
||||||
|
|
||||||
Initialize the long options for getopt_long.
|
|
||||||
See `man getopt` for details.
|
|
||||||
```c
|
|
||||||
static struct option g_long_opts[] = {
|
static struct option g_long_opts[] = {
|
||||||
{"help", no_argument, NULL, 'h'},
|
{"help", no_argument, NULL, 'h'},
|
||||||
{"ext", required_argument, NULL, 'e'},
|
{"ext", required_argument, NULL, 'e'},
|
||||||
|
|
@ -68,23 +38,7 @@ static struct option g_long_opts[] = {
|
||||||
{"map", required_argument, NULL, 'm'},
|
{"map", required_argument, NULL, 'm'},
|
||||||
{NULL, 0, NULL, 0}
|
{NULL, 0, NULL, 0}
|
||||||
};
|
};
|
||||||
```
|
|
||||||
|
|
||||||
### Function Definitions
|
|
||||||
|
|
||||||
### `cli_parse`
|
|
||||||
Parses command-line arguments and populates the t_args structure.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `args`: Pointer to the t_args structure to populate.
|
|
||||||
- `argc`: Argument count.
|
|
||||||
- `argv`: argv.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Returns 0 on success, or -1 on failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
cli_parse(t_args *args, int32_t argc, char **argv)
|
cli_parse(t_args *args, int32_t argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -101,16 +55,7 @@ cli_parse(t_args *args, int32_t argc, char **argv)
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `init_args`
|
|
||||||
Initializes the t_args structure with default values.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `args`: Pointer to the t_args structure to initialize.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
init_args(t_args *args)
|
init_args(t_args *args)
|
||||||
{
|
{
|
||||||
|
|
@ -120,19 +65,7 @@ init_args(t_args *args)
|
||||||
args->map_path = NULL;
|
args->map_path = NULL;
|
||||||
args->show_help = 0;
|
args->show_help = 0;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `find_handler`
|
|
||||||
Finds the handler function for a given option.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `opt`: The short option character.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Returns the corresponding handler function, or NULL if not found.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
static t_handler
|
static t_handler
|
||||||
find_handler(int8_t opt)
|
find_handler(int8_t opt)
|
||||||
{
|
{
|
||||||
|
|
@ -147,52 +80,32 @@ find_handler(int8_t opt)
|
||||||
}
|
}
|
||||||
return (NULL);
|
return (NULL);
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `handle_help`
|
|
||||||
Sets the show_help flag in t_args.
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
handle_help(t_args *args, const char *value)
|
handle_help(t_args *args, const char *value)
|
||||||
{
|
{
|
||||||
(void)value;
|
(void)value;
|
||||||
args->show_help = 1;
|
args->show_help = 1;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `handle_ext`
|
|
||||||
Sets the file extension in t_args.
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
handle_ext(t_args *args, const char *value)
|
handle_ext(t_args *args, const char *value)
|
||||||
{
|
{
|
||||||
args->ext = value;
|
args->ext = value;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `handle_input`
|
|
||||||
Sets the input file path in t_args.
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
handle_input(t_args *args, const char *value)
|
handle_input(t_args *args, const char *value)
|
||||||
{
|
{
|
||||||
args->input = value;
|
args->input = value;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `handle_output`
|
|
||||||
Sets the output file path in t_args.
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
handle_output(t_args *args, const char *value)
|
handle_output(t_args *args, const char *value)
|
||||||
{
|
{
|
||||||
args->output = value;
|
args->output = value;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `handle_map`
|
|
||||||
Sets the mapping file path in t_args.
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
handle_map(t_args *args, const char *value)
|
handle_map(t_args *args, const char *value)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,23 +1,8 @@
|
||||||
# help.c
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "cli.h"
|
#include "cli.h"
|
||||||
```
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
### `cli_print_help`
|
|
||||||
Prints the help message for the command-line interface.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `progname`: Name of the program.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
cli_print_help(const char *progname)
|
cli_print_help(const char *progname)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,35 +1,8 @@
|
||||||
# streams.c
|
|
||||||
Funtions for handling input and output streams.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `io_open`
|
|
||||||
Opens input and output streams based on provided file paths.
|
|
||||||
if input_path is NULL, stdin is used.
|
|
||||||
if output_path is NULL, stdout is used.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `io`: Pointer to the t_io structure to hold the opened streams.
|
|
||||||
- `input_path`: Path to the input file, or NULL for stdin.
|
|
||||||
- `output_path`: Path to the output file, or NULL for stdout.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Returns 0 on success, or 1 on failure.
|
|
||||||
The caller is responsible for closing the streams using `io_close`.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
io_open(t_io *io, const char *input_path, const char *output_path)
|
io_open(t_io *io, const char *input_path, const char *output_path)
|
||||||
{
|
{
|
||||||
|
|
@ -49,16 +22,7 @@ io_open(t_io *io, const char *input_path, const char *output_path)
|
||||||
}
|
}
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `io_close`
|
|
||||||
Closes the input and output streams if they are not stdin or stdout.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `io`: Pointer to the t_io structure containing the streams to close.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
io_close(t_io *io)
|
io_close(t_io *io)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,10 +1,3 @@
|
||||||
# main.c
|
|
||||||
|
|
||||||
Entry point of the c-md transpiler.
|
|
||||||
|
|
||||||
Parse command-line arguments, validate them, and run the transpilation process.
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
@ -14,20 +7,10 @@ Parse command-line arguments, validate them, and run the transpilation process.
|
||||||
#include "transpile.h"
|
#include "transpile.h"
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "io.h"
|
#include "io.h"
|
||||||
```
|
|
||||||
|
|
||||||
## Forward Declarations
|
|
||||||
|
|
||||||
```c
|
|
||||||
static int8_t run(t_args *args);
|
static int8_t run(t_args *args);
|
||||||
static void print_error(int8_t code, const char *progname);
|
static void print_error(int8_t code, const char *progname);
|
||||||
```
|
|
||||||
|
|
||||||
## Main Function
|
|
||||||
|
|
||||||
Program entry point: parse arguments, validate, and run transpilation.
|
|
||||||
|
|
||||||
```c
|
|
||||||
int
|
int
|
||||||
main(int argc, char **argv)
|
main(int argc, char **argv)
|
||||||
{
|
{
|
||||||
|
|
@ -52,17 +35,7 @@ main(int argc, char **argv)
|
||||||
}
|
}
|
||||||
return (run(&args));
|
return (run(&args));
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
## Print Error Function
|
|
||||||
|
|
||||||
print_error: Print error messages based on validation code.
|
|
||||||
|
|
||||||
error codes:
|
|
||||||
1. Missing -e when reading from stdin
|
|
||||||
2. Missing -e when filename does not imply extension
|
|
||||||
|
|
||||||
```c
|
|
||||||
static void
|
static void
|
||||||
print_error(int8_t code, const char *progname)
|
print_error(int8_t code, const char *progname)
|
||||||
{
|
{
|
||||||
|
|
@ -72,13 +45,7 @@ print_error(int8_t code, const char *progname)
|
||||||
fprintf(stderr, "Error: -e required (cannot infer from filename)\n");
|
fprintf(stderr, "Error: -e required (cannot infer from filename)\n");
|
||||||
cli_print_help(progname);
|
cli_print_help(progname);
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
## Run Function
|
|
||||||
|
|
||||||
Run the transpilation process with given arguments.
|
|
||||||
|
|
||||||
```c
|
|
||||||
static int8_t
|
static int8_t
|
||||||
run(t_args *args)
|
run(t_args *args)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,31 +1,9 @@
|
||||||
# core.c
|
|
||||||
Core functions of the map feature.
|
|
||||||
Handles initialization, addition, freeing, and growing of the map structure.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "internal/map_internal.h"
|
#include "internal/map_internal.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `map_init`
|
|
||||||
Initializes the map structure.
|
|
||||||
Every map structure must be initialized before use.
|
|
||||||
They also must be freed with `map_free` when no longer needed.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `map`: Pointer to the map structure to initialize.
|
|
||||||
|
|
||||||
##### Implementation
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
map_init(t_map *map)
|
map_init(t_map *map)
|
||||||
{
|
{
|
||||||
|
|
@ -33,20 +11,7 @@ map_init(t_map *map)
|
||||||
map->count = 0;
|
map->count = 0;
|
||||||
map->capacity = 0;
|
map->capacity = 0;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `map_add`
|
|
||||||
Adds a new range to the map structure.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `map`: Pointer to the map structure.
|
|
||||||
- `src_start`: Start of the source range.
|
|
||||||
- `src_end`: End of the source range.
|
|
||||||
- `dst_start`: Start of the destination range.
|
|
||||||
- `dst_end`: End of the destination range.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
map_add(t_map *map, uint32_t src_start, uint32_t src_end,
|
map_add(t_map *map, uint32_t src_start, uint32_t src_end,
|
||||||
uint32_t dst_start, uint32_t dst_end)
|
uint32_t dst_start, uint32_t dst_end)
|
||||||
|
|
@ -65,16 +30,7 @@ map_add(t_map *map, uint32_t src_start, uint32_t src_end,
|
||||||
range->dst_end = dst_end;
|
range->dst_end = dst_end;
|
||||||
map->count++;
|
map->count++;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `map_free`
|
|
||||||
Frees the resources allocated with the map structure.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `map`: Pointer to the map structure to free.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
map_free(t_map *map)
|
map_free(t_map *map)
|
||||||
{
|
{
|
||||||
|
|
@ -83,21 +39,7 @@ map_free(t_map *map)
|
||||||
map->count = 0;
|
map->count = 0;
|
||||||
map->capacity = 0;
|
map->capacity = 0;
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `map_grow`
|
|
||||||
Grows the capacity of the map structure.
|
|
||||||
Multiplies the current capacity by 2, or sets it to an initial value if it's
|
|
||||||
zero.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `map`: Pointer to the map structure to grow.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Returns 0 on success, or 1 on memory allocation failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
map_grow(t_map *map)
|
map_grow(t_map *map)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
118
srcs/map/io.c.md
118
srcs/map/io.c.md
|
|
@ -1,42 +1,41 @@
|
||||||
# io.c
|
|
||||||
Input/output functions for c-md mapping files.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "map.h"
|
#include "map.h"
|
||||||
#include "internal/map_internal.h"
|
#include "internal/map_internal.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
int8_t
|
||||||
|
write_header(FILE *f, const char *source, const char *target)
|
||||||
|
{
|
||||||
|
if (0 > fprintf(f, "C-MD MAP v1\n"))
|
||||||
|
return (1);
|
||||||
|
if (0 > fprintf(f, "source: %s\n", source))
|
||||||
|
return (1);
|
||||||
|
if (0 > fprintf(f, "target: %s\n", target))
|
||||||
|
return (1);
|
||||||
|
if (0 > fprintf(f, "---\n"))
|
||||||
|
return (1);
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
## Forward Declarations
|
int8_t
|
||||||
```c
|
write_ranges(FILE *f, t_map *map)
|
||||||
static int8_t write_header(FILE *f, const char *source, const char *target);
|
{
|
||||||
static int8_t write_ranges(FILE *f, t_map *map);
|
size_t i;
|
||||||
```
|
t_range *r;
|
||||||
|
|
||||||
---
|
i = 0;
|
||||||
|
while (i < map->count)
|
||||||
|
{
|
||||||
|
r = &map->ranges[i];
|
||||||
|
if (0 > fprintf(f, "%u-%u:%u-%u\n",
|
||||||
|
r->src_start, r->src_end, r->dst_start, r->dst_end))
|
||||||
|
return (1);
|
||||||
|
i++;
|
||||||
|
}
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `map_write`
|
|
||||||
Writes a c-md mapping file to the specified path.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `map`: Pointer to the mapping structure.
|
|
||||||
- `path`: Pointer to the output file path string.
|
|
||||||
- `source`: Pointer to the source file name string.
|
|
||||||
- `target`: Pointer to the target file name string.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Return 0 on success, or 1 on failure.
|
|
||||||
|
|
||||||
##### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
map_write(t_map *map, const char *path, const char *source, const char *target)
|
map_write(t_map *map, const char *path, const char *source, const char *target)
|
||||||
{
|
{
|
||||||
|
|
@ -56,62 +55,3 @@ map_write(t_map *map, const char *path, const char *source, const char *target)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `write_header`
|
|
||||||
Writes the header of a c-md mapping file. (v1 format)
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `f`: Pointer to the output file.
|
|
||||||
- `source`: Pointer to the source file name string.
|
|
||||||
- `target`: Pointer to the target file name string.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Return 0 on success, or 1 on failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
|
||||||
write_header(FILE *f, const char *source, const char *target)
|
|
||||||
{
|
|
||||||
if (0 > fprintf(f, "C-MD MAP v1\n"))
|
|
||||||
return (1);
|
|
||||||
if (0 > fprintf(f, "source: %s\n", source))
|
|
||||||
return (1);
|
|
||||||
if (0 > fprintf(f, "target: %s\n", target))
|
|
||||||
return (1);
|
|
||||||
if (0 > fprintf(f, "---\n"))
|
|
||||||
return (1);
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
||||||
### `write_ranges`
|
|
||||||
Writes the ranges of a c-md mapping file.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `f`: Pointer to the output file.
|
|
||||||
- `map`: Pointer to the mapping structure.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Return 0 on success, or 1 on failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
|
||||||
write_ranges(FILE *f, t_map *map)
|
|
||||||
{
|
|
||||||
size_t i;
|
|
||||||
t_range *r;
|
|
||||||
|
|
||||||
i = 0;
|
|
||||||
while (i < map->count)
|
|
||||||
{
|
|
||||||
r = &map->ranges[i];
|
|
||||||
if (0 > fprintf(f, "%u-%u:%u-%u\n",
|
|
||||||
r->src_start, r->src_end, r->dst_start, r->dst_end))
|
|
||||||
return (1);
|
|
||||||
i++;
|
|
||||||
}
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
```
|
|
||||||
|
|
|
||||||
|
|
@ -1,33 +1,8 @@
|
||||||
# code.c
|
|
||||||
Handle a single line of code by writing it to the output file and updating the
|
|
||||||
state.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdio.h>
|
#include <stdio.h>
|
||||||
|
|
||||||
#include "internal/transpile_internal.h"
|
#include "internal/transpile_internal.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `handle_code_line`
|
|
||||||
Handle a single line of code by writing it to the output file and updating the
|
|
||||||
state.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `s`: Pointer to the current state structure.
|
|
||||||
- `line`: Pointer to the line of code to be handled.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Return 0 on success, or 1 on failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
handle_code_line(t_state *s, char *line)
|
handle_code_line(t_state *s, char *line)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,43 +1,23 @@
|
||||||
# core.c
|
|
||||||
Core funtion of the transpiler.
|
|
||||||
Handles reading lines and processing them according to the current state.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
|
|
||||||
#include "transpile.h"
|
#include "transpile.h"
|
||||||
#include "internal/transpile_internal.h"
|
#include "internal/transpile_internal.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
int8_t
|
||||||
|
process_line(t_state *s, char *line)
|
||||||
|
{
|
||||||
|
s->src_line++;
|
||||||
|
if (0 == s->in_block && starts_with(line, "```"))
|
||||||
|
return (handle_fence_open(s, line));
|
||||||
|
if (1 == s->in_block && starts_with(line, "```"))
|
||||||
|
return (handle_fence_close(s));
|
||||||
|
if (1 == s->in_block)
|
||||||
|
return (handle_code_line(s, line));
|
||||||
|
return (0);
|
||||||
|
}
|
||||||
|
|
||||||
## Forward Declarations
|
|
||||||
|
|
||||||
```c
|
|
||||||
static int8_t process_line(t_state *s, char *line);
|
|
||||||
```
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `transpile`
|
|
||||||
Transpiles input from a file to an output file based on the specified extension
|
|
||||||
and mapping.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `in`: Pointer to the input file.
|
|
||||||
- `out`: Pointer to the output file.
|
|
||||||
- `ext`: Pointer to the file extension string.
|
|
||||||
- `map`: Pointer to the mapping structure.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Return 0 on success, or a non-zero error code on failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
transpile(FILE *in, FILE *out, const char *ext, t_map *map)
|
transpile(FILE *in, FILE *out, const char *ext, t_map *map)
|
||||||
{
|
{
|
||||||
|
|
@ -58,29 +38,3 @@ transpile(FILE *in, FILE *out, const char *ext, t_map *map)
|
||||||
return (ret);
|
return (ret);
|
||||||
}
|
}
|
||||||
```
|
```
|
||||||
|
|
||||||
### `process_line`
|
|
||||||
Processes a single line of input based on the current state.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `s`: Pointer to the current state structure.
|
|
||||||
- `line`: Pointer to the line of text to process.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Return 0 on success, or a non-zero error code on failure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
static int8_t
|
|
||||||
process_line(t_state *s, char *line)
|
|
||||||
{
|
|
||||||
s->src_line++;
|
|
||||||
if (0 == s->in_block && starts_with(line, "```"))
|
|
||||||
return (handle_fence_open(s, line));
|
|
||||||
if (1 == s->in_block && starts_with(line, "```"))
|
|
||||||
return (handle_fence_close(s));
|
|
||||||
if (1 == s->in_block)
|
|
||||||
return (handle_code_line(s, line));
|
|
||||||
return (0);
|
|
||||||
}
|
|
||||||
|
|
||||||
|
|
|
||||||
|
|
@ -1,9 +1,3 @@
|
||||||
# fence.c
|
|
||||||
Handles opening and closing of fenced code blocks in the transpilation process.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
@ -11,24 +5,7 @@ Handles opening and closing of fenced code blocks in the transpilation process.
|
||||||
|
|
||||||
#include "internal/transpile_internal.h"
|
#include "internal/transpile_internal.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `handle_fence_open`
|
|
||||||
Handles the opening of a fenced code block.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `s`: Pointer to the current transpilation state.
|
|
||||||
- `line`: Pointer to the current line being processed.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Returns `0` on success, `1` on error.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
handle_fence_open(t_state *s, char *line)
|
handle_fence_open(t_state *s, char *line)
|
||||||
{
|
{
|
||||||
|
|
@ -55,16 +32,7 @@ handle_fence_open(t_state *s, char *line)
|
||||||
s->block_dst_start = s->dst_line + 1;
|
s->block_dst_start = s->dst_line + 1;
|
||||||
return (0);
|
return (0);
|
||||||
}
|
}
|
||||||
```
|
|
||||||
|
|
||||||
### `handle_fence_close`
|
|
||||||
Handles the closing of a fenced code block.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `s`: Pointer to the current transpilation state.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
handle_fence_close(t_state *s)
|
handle_fence_close(t_state *s)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,29 +1,6 @@
|
||||||
# state.c
|
|
||||||
|
|
||||||
Initialize the transpilation state structure.
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include "internal/transpile_internal.h"
|
#include "internal/transpile_internal.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Description
|
|
||||||
### `state_init`
|
|
||||||
|
|
||||||
Initialize the transpilation state structure.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `s`: Pointer to the state structure to initialize.
|
|
||||||
- `in`: Input file pointer.
|
|
||||||
- `out`: Output file pointer.
|
|
||||||
- `ext`: Pointer to the extracted code fence extension string.
|
|
||||||
- `map`: Pointer to the mapping structure.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
|
|
||||||
```c
|
|
||||||
void
|
void
|
||||||
state_init(t_state *s, FILE *in, FILE *out, const char *ext, t_map *map)
|
state_init(t_state *s, FILE *in, FILE *out, const char *ext, t_map *map)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,12 +1,3 @@
|
||||||
# read_line.c
|
|
||||||
|
|
||||||
Get a line from a file.
|
|
||||||
depends on POSIX getline
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
|
|
||||||
```c
|
```c
|
||||||
#define _POSIX_C_SOURCE 200809L
|
#define _POSIX_C_SOURCE 200809L
|
||||||
|
|
||||||
|
|
@ -14,29 +5,7 @@ depends on POSIX getline
|
||||||
#include <sys/types.h>
|
#include <sys/types.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Description
|
|
||||||
|
|
||||||
### `read_line`
|
|
||||||
|
|
||||||
Get a line from a file.
|
|
||||||
|
|
||||||
#### Parameter
|
|
||||||
- `f`: Pointer to a `FILE` object representing the input file.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
|
|
||||||
Returns a pointer to the read line (dynamically allocated) or `NULL` on failure
|
|
||||||
or end of file.
|
|
||||||
|
|
||||||
Return value must be freed by the caller.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
|
|
||||||
```c
|
|
||||||
char *
|
char *
|
||||||
read_line(FILE *f)
|
read_line(FILE *f)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,38 +1,10 @@
|
||||||
# extract_fence_ext.c
|
|
||||||
|
|
||||||
Extract the extension from a markdown code fence.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stdlib.h>
|
#include <stdlib.h>
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Description
|
|
||||||
|
|
||||||
### `extract_fence_ext`
|
|
||||||
Extracts the extension from a markdown code fence string.
|
|
||||||
|
|
||||||
#### Parameter
|
|
||||||
- `fence`: Pointer to a null-terminated string representing the code fence.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
|
|
||||||
Returns a dynamically allocated string containing the extracted extension, or
|
|
||||||
`NULL` if no extension is found or if the input is not a valid code fence.
|
|
||||||
|
|
||||||
Return value must be freed by the caller.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
|
|
||||||
```c
|
|
||||||
char *
|
char *
|
||||||
extract_fence_ext(const char *fence)
|
extract_fence_ext(const char *fence)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,8 @@
|
||||||
# extract_file_ext.c
|
|
||||||
|
|
||||||
Get the file extension from a given file path.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Description
|
|
||||||
|
|
||||||
### `extract_file_ext`
|
|
||||||
Get the file extension from a given file path.
|
|
||||||
|
|
||||||
#### Parameter
|
|
||||||
- `path`: The file path string.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
|
|
||||||
Returns a pointer to the file extension within the path string, or `NULL` if
|
|
||||||
no extension is found.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
|
|
||||||
```c
|
|
||||||
const char *
|
const char *
|
||||||
extract_file_ext(const char *path)
|
extract_file_ext(const char *path)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,30 +1,8 @@
|
||||||
# infer_ext_from_filename.c
|
|
||||||
Infer file extension from filename ending with .md
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Descriptions
|
|
||||||
|
|
||||||
### `infer_ext_from_filename`
|
|
||||||
Infer the file extension from a filename that ends with `.md`.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `path`: Pointer to the filename string.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
Returns a pointer to a static buffer containing the inferred extension, or
|
|
||||||
`NULL` if no valid
|
|
||||||
|
|
||||||
```c
|
|
||||||
const char *
|
const char *
|
||||||
infer_ext_from_filename(const char *path)
|
infer_ext_from_filename(const char *path)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,34 +1,9 @@
|
||||||
# starts_with.c
|
|
||||||
|
|
||||||
Checks if a string starts with a given prefix.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
#include <stdint.h>
|
#include <stdint.h>
|
||||||
|
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Description
|
|
||||||
|
|
||||||
### `starts_with`
|
|
||||||
|
|
||||||
Checks if the string `str` starts with the substring `prefix`.
|
|
||||||
|
|
||||||
#### Parameters
|
|
||||||
- `str`: The main string to check.
|
|
||||||
- `prefix`: The prefix to look for at the start of `str`.
|
|
||||||
|
|
||||||
#### Return Value
|
|
||||||
- Returns `1` (true) if `str` starts with `prefix`.
|
|
||||||
- Returns `0` (false) otherwise.
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
starts_with(const char *str, const char *prefix)
|
starts_with(const char *str, const char *prefix)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
|
|
@ -1,39 +1,9 @@
|
||||||
# validator.c
|
|
||||||
|
|
||||||
Validate command-line arguments.
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Includes
|
|
||||||
```c
|
```c
|
||||||
#include <stddef.h>
|
#include <stddef.h>
|
||||||
|
|
||||||
#include "validator.h"
|
#include "validator.h"
|
||||||
#include "utils.h"
|
#include "utils.h"
|
||||||
```
|
|
||||||
|
|
||||||
---
|
|
||||||
|
|
||||||
## Function Description
|
|
||||||
|
|
||||||
### `validator_validate_args`
|
|
||||||
|
|
||||||
Checks and validates the content of the `t_args` structure, ensuring required
|
|
||||||
file input and extension arguments are consistent.
|
|
||||||
|
|
||||||
#### Parameter
|
|
||||||
- `args`: Pointer to a `t_args` structure containing command-line arguments.
|
|
||||||
|
|
||||||
#### Return Codes
|
|
||||||
|
|
||||||
| Code | Meaning |
|
|
||||||
|------|-----------------------------------------------------------------|
|
|
||||||
| 0 | Arguments are valid |
|
|
||||||
| 1 | Both input file and extension are missing |
|
|
||||||
| 2 | Extension is missing and cannot be inferred from input filename |
|
|
||||||
|
|
||||||
#### Implementation
|
|
||||||
```c
|
|
||||||
int8_t
|
int8_t
|
||||||
validator_validate_args(t_args *args)
|
validator_validate_args(t_args *args)
|
||||||
{
|
{
|
||||||
|
|
|
||||||
Loading…
Add table
Reference in a new issue