added prelude noja script that's embedded into the executable
This commit is contained in:
@@ -1,6 +0,0 @@
|
||||
a = [];
|
||||
i = 0;
|
||||
while(i<100000000):{
|
||||
a[i]= "ciao mondo mmododooddododododododododododdodododododd";
|
||||
i = i+1;
|
||||
}
|
||||
@@ -0,0 +1,66 @@
|
||||
#include <stdio.h>
|
||||
#include <assert.h>
|
||||
#include <stdint.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdbool.h>
|
||||
|
||||
// gcc embedder.c -o embedder -Wall -Wextra
|
||||
|
||||
int main(int argc, char **argv)
|
||||
{
|
||||
const char *variable = "__variable_name__";
|
||||
const char *input = NULL;
|
||||
const char *output = "output.c";
|
||||
if (argc < 3) {
|
||||
fprintf(stderr, "Usage: %s <input> <variable-name> [<output>]\n",
|
||||
argv[0]);
|
||||
return -1;
|
||||
}
|
||||
|
||||
input = argv[1];
|
||||
variable = argv[2];
|
||||
if (argc > 3)
|
||||
output = argv[3];
|
||||
|
||||
FILE *in_stream = fopen(input, "rb");
|
||||
if (in_stream == NULL) {
|
||||
fprintf(stderr, "Error: Failed to open \"%s\"\n", input);
|
||||
return -1;
|
||||
}
|
||||
|
||||
FILE *out_stream = fopen(output, "wb");
|
||||
if (out_stream == NULL) {
|
||||
fprintf(stderr, "Error: Failed to open \"%s\"\n", output);
|
||||
fclose(in_stream);
|
||||
return -1;
|
||||
}
|
||||
|
||||
fprintf(out_stream, "const unsigned char %s[] = {\n\t", variable);
|
||||
|
||||
size_t w = 0;
|
||||
bool done = false;
|
||||
while (!done) {
|
||||
uint8_t buffer[1024];
|
||||
size_t num = fread(buffer, 1, sizeof(buffer), in_stream);
|
||||
if (num < sizeof(buffer)) {
|
||||
if (ferror(in_stream)) {
|
||||
abort();
|
||||
} else {
|
||||
assert(feof(in_stream));
|
||||
done = true;
|
||||
}
|
||||
}
|
||||
|
||||
for (size_t i = 0; i < num; i++, w++) {
|
||||
fprintf(out_stream, "%3d, ", buffer[i]);
|
||||
if ((w+1) % 16 == 0)
|
||||
fprintf(out_stream, "\n\t");
|
||||
}
|
||||
}
|
||||
|
||||
fprintf(out_stream, "\n};\n");
|
||||
|
||||
fclose(in_stream);
|
||||
fclose(out_stream);
|
||||
return 0;
|
||||
}
|
||||
Reference in New Issue
Block a user