add: program to generate the README.md from
README_COMPLET.md
This commit is contained in:
parent
be3ae772cb
commit
31ee578f5f
1
.gitignore
vendored
Normal file
1
.gitignore
vendored
Normal file
@ -0,0 +1 @@
|
||||
a.out
|
71
create_short.c
Normal file
71
create_short.c
Normal file
@ -0,0 +1,71 @@
|
||||
#include <sys/stat.h>
|
||||
#include <fcntl.h>
|
||||
#include <string.h>
|
||||
#include <unistd.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdio.h>
|
||||
|
||||
#define BUTTON "\n### [More](https://urlz.fr/mqBB)"
|
||||
#define TOTAL_SIZE 2272
|
||||
#define MAX_SIZE TOTAL_SIZE - strlen(BUTTON)
|
||||
|
||||
char* read_file(const char* path)
|
||||
{
|
||||
char* content;
|
||||
int fd;
|
||||
|
||||
fd = open(path, O_RDONLY);
|
||||
if (fd == -1)
|
||||
goto open_fail;
|
||||
|
||||
content = malloc((TOTAL_SIZE + 1) * sizeof(char));
|
||||
if (content == NULL)
|
||||
goto alloc_fail;
|
||||
|
||||
int written = read(fd, content, MAX_SIZE);
|
||||
if (written == -1)
|
||||
goto read_fail;
|
||||
|
||||
content[written] = '\0';
|
||||
|
||||
close(fd);
|
||||
return content;
|
||||
|
||||
read_fail:
|
||||
alloc_fail:
|
||||
free(content);
|
||||
|
||||
open_fail:
|
||||
close(fd);
|
||||
return NULL;
|
||||
}
|
||||
|
||||
int write_file(const char* path, const char* content)
|
||||
{
|
||||
int fd = open(path, O_WRONLY | O_TRUNC);
|
||||
|
||||
if (fd == -1)
|
||||
return 1;
|
||||
|
||||
return write(fd, content, strlen(content));
|
||||
}
|
||||
|
||||
int main(int ac, char **av)
|
||||
{
|
||||
char* path;
|
||||
|
||||
if (ac > 2)
|
||||
path = av[1];
|
||||
else
|
||||
path = "README_COMPLET.md";
|
||||
|
||||
char* content = read_file(path);
|
||||
if (content == NULL)
|
||||
return 1;
|
||||
|
||||
strcat(content, BUTTON);
|
||||
|
||||
int ret = write_file("README.md", content);
|
||||
free(content);
|
||||
return ret;
|
||||
}
|
2
create_short.sh
Executable file
2
create_short.sh
Executable file
@ -0,0 +1,2 @@
|
||||
gcc -g -Wall -Werror -Wextra create_short.c &&
|
||||
./a.out
|
Loading…
Reference in New Issue
Block a user