- Add detailed build and bootstrap instructions to README.md. - Convert all source and header files from .c/.h to .c.md/.h.md. - Add bootstrap.sh script for automated building across version history. - Update Makefile and sources.mk to reflect new markdown-based source organization.
948 B
948 B
#include <stdio.h>
#include "map.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);
}
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);
}
int8_t
map_write(t_map *map, const char *path, const char *source, const char *target)
{
FILE *f;
int8_t ret;
f = fopen(path, "w");
if (NULL == f)
{
perror(path);
return (1);
}
ret = write_header(f, source, target);
if (0 == ret)
ret = write_ranges(f, map);
fclose(f);
return (ret);
}