~pixelherodev/DSM-9

a9302f584835e0c2fb46af8dac2d76c23d2648d7 — Noam Preil a day ago e80b01a
due: add -c and -o for count and offset control
1 files changed, 28 insertions(+), 11 deletions(-)

M due.c
M due.c => due.c +28 -11
@@ 14,16 14,30 @@
#include "dsm9.h"
#include "util.h"

struct{
	uint32_t count, offset;
} conf;

void
parse_arguments(dsm9deck *deck, int argc, char **argv)
{
	double dt;
	for(int i = 1; i < argc; i += 1){
		delta();
		if(!dsm9load(argv[i], deck))
			fprintf(stderr, "Failed to load deck into new format\n");
		dt = delta();
		printf("Loaded deck of %d cards into new format in %fs\n", deck->cardnum, dt);
		if(strcmp(argv[i], "-c") == 0){
			i += 1;
			conf.count = atol(argv[i]);
		}
		else if(strcmp(argv[i], "-o") == 0){
			i += 1;
			conf.offset = atol(argv[i]);
		}
		else {
			delta();
			if(!dsm9load(argv[i], deck))
				fprintf(stderr, "Failed to load deck into new format\n");
			dt = delta();
			printf("Loaded deck of %d cards into new format in %fs\n", deck->cardnum, dt);
		}
	}
}



@@ 31,17 45,20 @@ int
main(int argc, char **argv)
{
	dsm9deck deck;
	uint32_t count = 30, index;
	uint32_t index;
	char *name;
	conf.count = 30;
	conf.offset = 0;
	int new = 0;
	memset(&deck, 0, sizeof(deck));
	parse_arguments(&deck, argc, argv);
	if(deck.accel.duecount + deck.accel.newcount < count)
		count = deck.accel.duecount + deck.accel.newcount;
	if(count != 0)
	uint32_t total = deck.accel.duecount + deck.accel.newcount;
	if(conf.count > total - conf.offset)
		conf.count = total - conf.offset;
	if(conf.count != 0)
		puts("Due:");
	for(uint32_t i = 0; i < count; i += 1){
		if(!new && i == deck.accel.duecount)
	for(uint32_t i = conf.offset; i < conf.count + conf.offset; i += 1){
		if(!new && i >= deck.accel.duecount)
			new = 1;
		index = new ? deck.accel.new[i - deck.accel.duecount] : deck.accel.due[i];
		name = dsm9cardname(&deck, index);