mirror of
https://forge.fsky.io/lda/Parsee.git
synced 2026-03-13 13:45:10 +00:00
[ADD/WIP] build.c script, raise to 0.1
This commit is contained in:
parent
34bd036ab7
commit
8ce69d0829
4 changed files with 844 additions and 5 deletions
54
tools/b64.c
Normal file
54
tools/b64.c
Normal file
|
|
@ -0,0 +1,54 @@
|
|||
/* b64.c - Generates a C string symbol stored as Base64
|
||||
* ============================================================
|
||||
* Under CC0, as its a rather useful example of a KappaChat tool.
|
||||
* See LICENSE for more information about Parsee's licensing. */
|
||||
|
||||
#include <Cytoplasm/HashMap.h>
|
||||
#include <Cytoplasm/Stream.h>
|
||||
#include <Cytoplasm/Base64.h>
|
||||
#include <Cytoplasm/Memory.h>
|
||||
#include <Cytoplasm/Array.h>
|
||||
|
||||
#include <stdlib.h>
|
||||
|
||||
int
|
||||
Main(Array *args, HashMap *env)
|
||||
{
|
||||
char *file = ArrayGet(args, 1);
|
||||
char *symbol = ArrayGet(args, 2);
|
||||
char *out = ArrayGet(args, 3);
|
||||
|
||||
Stream *inStream;
|
||||
uint8_t *bytes;
|
||||
size_t len;
|
||||
int o;
|
||||
|
||||
char *b64;
|
||||
Stream *outStream;
|
||||
|
||||
if (!file || !symbol || !out)
|
||||
{
|
||||
return EXIT_FAILURE;
|
||||
}
|
||||
|
||||
inStream = StreamOpen(file, "rb");
|
||||
bytes = NULL;
|
||||
len = 0;
|
||||
while ((o = StreamGetc(inStream)) != EOF)
|
||||
{
|
||||
bytes = Realloc(bytes, len + 1);
|
||||
bytes[len++] = o;
|
||||
}
|
||||
StreamClose(inStream);
|
||||
|
||||
b64 = Base64Encode((const char *) bytes, len);
|
||||
Free(bytes);
|
||||
outStream = StreamOpen(out, "w");
|
||||
StreamPrintf(outStream, "const char %s[] = ", symbol);
|
||||
StreamPrintf(outStream, "\"%s\";\n", b64);
|
||||
Free(b64);
|
||||
StreamFlush(outStream);
|
||||
StreamClose(outStream);
|
||||
|
||||
return EXIT_SUCCESS;
|
||||
}
|
||||
Loading…
Add table
Add a link
Reference in a new issue