#include <stdio.h>
#include <stdbool.h>
#include <getopt.h>
#include <ctype.h>

#include "blockdev.h"
#include "vfs.h"

extern void adainit (void);
extern void adafinal (void);

struct program_options {
	char *devname;
};

static int get_options(int argc, char* argv[], struct program_options* opt);

static void fs_tests(void);
static void fs_test_file(const char *path);

int main(int argc, char* argv[])
{
	struct program_options opt = { 0, };
	int ret = -1;

	adainit();

	if (get_options(argc, argv, &opt)) {
		goto final;
	}


	if (devopen(opt.devname, NULL) != 1) {
		goto final;
	}

	fs_tests();

	devclose();
	ret = 0;

final:
	adafinal();
	return ret;
}



static void fprint_help(FILE* to, char * pname)
{
	fprintf(to, "Usage: %s\n"
		"  -d | --dev <path> \t File to use as block device\n"
		, pname);
}

static int get_options(int argc, char* argv[], struct program_options *opt){
	const struct option long_options[] = {
		{"dev", required_argument, NULL, 'd'},
		{NULL, 0, NULL, 0},
	};

	int c, option_index = 0;
	while ((c = getopt_long(argc, argv, "d:", long_options, &option_index)) != -1) {
		switch (c) {
		case 'd':
			opt->devname = optarg;
			break;
		default:
			fprint_help(stderr, argv[0]);
			return -1;
		}
	}

	if (argc == 1) {
		fprintf(stderr, "%s needs arguments.\n", argv[0]);
		fprint_help(stderr, argv[0]);
		return -1;
	}

	if (opt->devname == NULL) {
		fprintf(stderr, "Argument \"--dev/-d\" missing.\n");
		return -1;
	}
	return 0;
}

static void fs_tests(void)
{
	if (!mount_fs(NULL)) {
		fprintf(stderr, "ERROR: Failed to mount FS.\n");
		return;
	}

	fs_test_file("/test");
	fs_test_file("/dir/test");
	fs_test_file("/dir/subdir/test");
}

static void fs_test_file(const char *path)
{
	if (!file_open(path)) {
		fprintf(stderr, "ERROR: Failed to open `%s'.\n", path);
		return;
	}

	unsigned char motd[1024];
	const int read = file_read(motd, sizeof(motd));
	if (read < 0) {
		fprintf(stderr, "ERROR: Failed to read from `%s'.\n", path);
		return;
	}

	for (size_t i = 0; i < (size_t)(read + 15) / 16 * 16; ++i) {
		if (i % 16 == 0)
			printf("%06x:  ", i);
		else if (i % 8 == 0)
			printf(" ");
		if (i < read)
			printf("%02x ", motd[i]);
		else
			printf("   ");
		if (i % 16 == 15) {
			printf(" |");
			for (size_t j = i - 15; j <= (i < read ? i : read - 1); ++j)
				printf("%c", isprint(motd[j]) ? motd[j] : '.');
			for (size_t j = i % 16 + 1; j < 16; ++j)
				printf(" ");
			printf("|\n");
		}
	}
	printf("\n");

	file_close();
}
