#include <assert.h>
#include <stdio.h>
#include <stdlib.h>
#include <time.h>

#include "csv.h"

static int
test(FILE *f)
{
	int   line = 0;
	csv_t csv  = { 0 };

	while ( csv_read(&csv, f) ) {
		++line;
	}

	return line;
}

int
main(int argc, char *argv[])
{
	if ( argc != 2 ) {
		fprintf(stderr, "usage: %s testfile\n", argv[0]);
		return EXIT_FAILURE;
	}

	FILE *in = fopen(argv[1], "r");
	if ( in == NULL ) {
		fprintf(stderr, "failed to open testfile...\n");
		return EXIT_FAILURE;
	}

	clock_t start = clock();

	int lines = test(in);

	clock_t end = clock();

	fclose(in);

	printf("%d lines processed, duration: %.3lf sec\n", lines, ((double) (end - start)) / CLOCKS_PER_SEC);

	return EXIT_SUCCESS;
}
