/*
* Ficl softcore generator.
* Generates both uncompressed and Lempel-Ziv compressed versions.
* Strips blank lines, strips full-line comments, collapses whitespace.
* Chops, blends, dices, makes julienne fries.
*
* Contributed by Larry Hastings, larry@hastings.org
*/
#include <ctype.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>
#include "ficl.h"
#ifndef SOFTCORE_OUT
#endif
extern size_t
void
{
int i;
while (length) {
fprintf(f, "\t");
for (i = 0; (i < 8) && length; i++) {
/*
* if you don't do this little stuff, you get ugly
* sign-extended 0xFFFFFF6b crap.
*/
length--;
}
fprintf(f, "\n");
}
}
void
{
while (*data) {
if (*data == '\n') {
if (!lineIsBlank)
fprintf(f, "\\n\"\n");
} else {
if (lineIsBlank) {
fputc('\t', f);
fputc('"', f);
lineIsBlank = 0; /* false */
}
if (*data == '"')
fprintf(f, "\\\"");
else if (*data == '\\')
fprintf(f, "\\\\");
else
}
data++;
}
if (!lineIsBlank)
fprintf(f, "\"");
}
int
{
int i;
FILE *f;
time(¤tTimeT);
"%Y/%m/%d %H:%M:%S", currentTime);
*trace++ = ' ';
for (i = 1; i < argc; i++) {
int size;
/*
* This ensures there's always whitespace space between files.
* It *also* ensures that src[-1] is always safe in comment
* detection code below. (Any leading whitespace will be
* thrown away in a later pass.)
* --lch
*/
*trace++ = ' ';
fclose(f);
}
*trace = 0;
#define IS_EOL_COMMENT(x) \
#define IS_BLOCK_COMMENT(x) \
while (*src) {
/* ignore leading whitespace, or entirely blank lines */
src++;
/* if the line is commented out */
if (IS_EOL_COMMENT(src)) {
/* throw away this entire line */
src++;
continue;
}
/*
* This is where we'd throw away mid-line comments, but
* that's simply unsafe. Things like
* start-prefixes
* : \ postpone \ ;
* : ( postpone ( ;
* get broken that way.
* --lch
*/
}
/* strip trailing whitespace */
dst--;
dst--;
dst++;
/* and end the line */
*dst++ = '\n';
}
*dst = 0;
/*
* now make a second pass to collapse all contiguous whitespace
* to a single space.
*/
while (*src) {
src++;
else {
src++;
}
}
*dst = 0;
if (f == NULL) {
" for writing! giving up.\n");
exit(-1);
}
fprintf(f,
"/*\n"
"** Ficl softcore\n"
"** both uncompressed and LZ4 compressed versions.\n"
"**\n"
"** Generated %s\n"
"**/\n"
"\n"
"#include \"ficl.h\"\n"
"\n"
"\n", cleverTime);
fprintf(f, "static size_t ficlSoftcoreUncompressedSize = %d; "
"/* not including trailing null */\n", uncompressedSize);
fprintf(f, "\n");
fprintf(f, "#if !FICL_WANT_LZ4_SOFTCORE\n");
fprintf(f, "\n");
fprintf(f, "static char ficlSoftcoreUncompressed[] =\n");
fprintf(f, ";\n");
fprintf(f, "\n");
fprintf(f, "#else /* !FICL_WANT_LZ4_SOFTCORE */\n");
fprintf(f, "\n");
fprintf(f, "extern int lz4_decompress(void *, void *, size_t, "
"size_t, int);\n\n");
fprintf(f, "static unsigned char ficlSoftcoreCompressed[%d] = "
"{\n", compressedSize);
fprintf(f, "\t};\n");
fprintf(f, "\n");
fprintf(f, "#endif /* !FICL_WANT_LZ4_SOFTCORE */\n");
fprintf(f,
"\n"
"\n"
"void ficlSystemCompileSoftCore(ficlSystem *system)\n"
"{\n"
" ficlVm *vm = system->vmList;\n"
" int returnValue;\n"
" ficlCell oldSourceID = vm->sourceId;\n"
" ficlString s;\n"
"#if FICL_WANT_LZ4_SOFTCORE\n"
" char *ficlSoftcoreUncompressed = malloc(ficlSoftcoreUncompressedSize+1);\n"
" returnValue = lz4_decompress(ficlSoftcoreCompressed, "
"ficlSoftcoreUncompressed, sizeof(ficlSoftcoreCompressed), "
"ficlSoftcoreUncompressedSize+1, 0);\n"
" FICL_VM_ASSERT(vm, returnValue == 0);\n"
"#endif /* FICL_WANT_LZ4_SOFTCORE */\n"
" vm->sourceId.i = -1;\n"
" FICL_STRING_SET_POINTER(s, (char *)(ficlSoftcoreUncompressed));\n"
" FICL_STRING_SET_LENGTH(s, ficlSoftcoreUncompressedSize);\n"
" returnValue = ficlVmExecuteString(vm, s);\n"
" vm->sourceId = oldSourceID;\n"
"#if FICL_WANT_LZ4_SOFTCORE\n"
" free(ficlSoftcoreUncompressed);\n"
"#endif /* FICL_WANT_LZ4_SOFTCORE */\n"
" FICL_VM_ASSERT(vm, returnValue != FICL_VM_STATUS_ERROR_EXIT);\n"
" return;\n"
"}\n\n"
"/* end-of-file */\n");
return (0);
}