<commit_before>/* See LICENSE file */
#include <stdio.h>

int
main(int argc, char *argv[])
{
	if (argc != 2) {
		printf("usage: txt2ff STRING\n");
		return 1;
	}

	printf("TODO: write '%s' to a ff image.\n", argv[1]);

	return 0;
}<commit_msg>implement reading of header<commit_after>/* See LICENSE file */
#include <arpa/inet.h>

#include <stdarg.h>
#include <stdint.h>
#include <stdio.h>
#include <stdlib.h>
#include <string.h>

/* Function declarations */
static void die(const char *errstr, ...);
static void *ecalloc(size_t nmemb, size_t size);
static void readheader();

/* Global variables */
static char *buf;
static char *txt;
static FILE *fontfile;
static int em;
static int px;

/* Function definitions */
void
die(const char *fmt, ...) {
        va_list ap;

        va_start(ap, fmt);
        vfprintf(stderr, fmt, ap);
        va_end(ap);

        if (fmt[0] && fmt[strlen(fmt)-1] == ':') {
                fputc(' ', stderr);
                perror(NULL);
        }

        exit(EXIT_FAILURE);
}

void *
ecalloc(size_t nmemb, size_t size)
{
        void *p;
        if (!(p = calloc(nmemb, size)))
                perror(NULL);
        return p;
}

void
readheader()
{
	uint16_t skip;

	fread(buf, sizeof(char), 8, fontfile);
	if (strncmp(buf, "tinyfont", 8))
		die("not a tinyfont file\n");

	fread(buf, sizeof(uint16_t), 1, fontfile);
	skip = ntohs(*(uint16_t *)buf);
	fseek(fontfile, (long)skip, SEEK_CUR); /* copyright */

	fread(buf, sizeof(uint16_t), 1, fontfile);
	em = (int)ntohs(*(uint16_t *)buf);
}

int
main(int argc, char *argv[])
{
	if (argc != 4)
		die("usage: txt2ff fontfile px string\n");
	if (!(fontfile = fopen(argv[1], "r")))
		die("failed to open file\n");

	px = atoi(argv[2]);
	txt = argv[3];
	buf = ecalloc(1, BUFSIZ); /* TODO is it opposite? */

	readheader();

	return EXIT_SUCCESS;
}
{'fraction_non_alphanumeric': 0.1768893756845564, 'fraction_numerical': 0.014786418400876232, 'mean_word_length': 3.1807780320366135, 'pattern_counts': {'":': 0, '<': 10, '<?xml version=': 0, '>': 10, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3532642', 'n_tokens_mistral': 729, 'n_tokens_neox': 695, 'n_words': 185}