#include <stdlib.h>
#include <stdio.h>
#include <limits.h>
#include <string.h>
#include <assert.h>
#include <err.h>
#include <iconv.h>
#include <errno.h>
#include <locale.h>
#include <langinfo.h>
#include <squash.h>
#include <fspec/bcode.h>
#include <fspec/lexer.h>
#include <fspec/validator.h>
#include "util/membuf.h"
#define ARRAY_SIZE(x) (sizeof(x) / sizeof(x[0]))
#if 0
#endif
static FILE*
fopen_or_die(const char *path, const char *mode)
{
assert(path && mode);
FILE *f;
if (!(f = fopen(path, mode)))
err(EXIT_FAILURE, "fopen(%s, %s)", path, mode);
return f;
}
#define container_of(ptr, type, member) ((type *)((char *)(1 ? (ptr) : &((type *)0)->member) - offsetof(type, member)))
struct lexer {
struct fspec_lexer lexer;
struct membuf output;
FILE *file;
};
static size_t
fspec_lexer_write(struct fspec_lexer *lexer, const enum fspec_lexer_section section, const void *output, const size_t size, const size_t nmemb)
{
assert(lexer && output);
(void)lexer, (void)section, (void)size, (void)nmemb;
return nmemb;
}
static size_t
fspec_lexer_read(struct fspec_lexer *lexer, void *input, const size_t size, const size_t nmemb)
{
assert(lexer && input);
struct lexer *l = container_of(lexer, struct lexer, lexer);
return fread(input, size, nmemb, l->file);
}
#if 0
#endif
int
main(int argc, const char *argv[])
{
if (argc < 2)
errx(EXIT_FAILURE, "usage: %s file.spec < data", argv[0]);
char output[4096];
{
char input[4096];
struct lexer l = {
.lexer = {
.ops.read = fspec_lexer_read,
.ops.write = fspec_lexer_write,
.mem.input = { .data = input, .len = sizeof(input) },
},
.file = fopen_or_die(argv[1], "rb"),
.output.mem = { .data = output, .len = sizeof(output) },
};
if (!fspec_lexer_parse(&l.lexer, argv[1]))
exit(EXIT_FAILURE);
fclose(l.file);
}
#if 0
#endif
return EXIT_SUCCESS;
}
|