<commit_before>#include <math.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

typedef unsigned long ulong;

void aninput(char* s);
short isleap(ulong year);
long dayofyear(ulong year, ulong month, ulong day);
long daydiff(ulong orgyear, ulong orgday, ulong usryear, ulong usrday);

static unsigned daytab[2][13]=
{
	{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
	{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};

static char* dayname[7]=
{
	"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
};

void aninput(char* s)
{
	ulong year, month, day;
	long diff;
	errno=0;

	sscanf(s, "%lu-%lu-%lu", &year, &month, &day);

	if(errno||!year||!month||!day)
	{
		fprintf(stderr, "error: no date of format YEAR-MONTH-DAY found\n");
		return;
	}
	/*1-1-1 was a monday*/
	diff=daydiff(1, 1, year, dayofyear(year, month, day));

	if(diff<0)
	{
		fprintf(stderr, "error: bad date format\n");
		return;
	}

	printf("%lu-%lu-%lu:%s\n", year, month, day, dayname[diff%7]);
}

short isleap(ulong year)
{
	return ((year%4==0&&year%100!=0)||(year%400==0));
}

long dayofyear(ulong year, ulong month, ulong day)
{
	ulong i, leap;

	leap=isleap(year);

	if(day>daytab[leap][month]||month>12)
		return -1;

	for(i=1;i<month;i++)
		day+=daytab[leap][i];
	return day;
}

long daydiff(ulong orgyear, ulong orgday, ulong usryear, ulong usrday)
{
	ulong leaps, years, days;
	if(!orgyear||!usryear||!orgday||!usrday)
		return -1;

	leaps=(usryear/4)-(usryear/100)+(usryear/400)+isleap(usryear);
	years=usryear-orgyear-leaps;
	days=(years* 365)+(leaps*366)+usrday-orgday;

	return days;
}

int main(int argc, char** argv)
{
	long count;
	char input[BUFSIZ];

	if(argc>1)
	{
		for(count=1; count<argc; count++)
			aninput(argv[count]);
		return 0;
	}

	while(fgets(input, BUFSIZ, stdin)!=NULL)
		aninput(input);

	return 0;
}
<commit_msg>Rewrote wd with bearable error handling.<commit_after>#include <math.h>
#include <stdio.h>
#include <string.h>
#include <errno.h>

typedef unsigned long ulong;

short isleap(ulong year);
long dayofyear(ulong year, ulong month, ulong day);
long daydiff(ulong orgyear, ulong orgday, ulong usryear, ulong usrday);

static unsigned daytab[2][13]=
{
	{0, 31, 28, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31},
	{0, 31, 29, 31, 30, 31, 30, 31, 31, 30, 31, 30, 31}
};

static char* dayname[7]=
{
	"Monday", "Tuesday", "Wednesday", "Thursday", "Friday", "Saturday", "Sunday"
};

short isleap(ulong year)
{
	return ((year%4==0&&year%100!=0)||(year%400==0));
}

long daydiff(ulong orgyear, ulong orgday, ulong usryear, ulong usrday)
{
	ulong leaps, years, days;

	leaps=((usryear-1)/4)-((usryear-1)/100)+((usryear-1)/400);
	years=usryear-orgyear-leaps;
	days=(years* 365)+(leaps*366)+usrday-orgday;

	return days;
}

long dayofyear(ulong year, ulong month, ulong day)
{
	ulong i;

	for(i=1;i<month;i++)
		day+=daytab[isleap(year)][i];
	return day;
}

int main(int argc, char** argv)
{
	int i;
	char c;
	ulong year, day, month;

	if(argc>1)
		for(i=1; i<argc; i++)
		{
			errno=0;
			sscanf(argv[i], "%lu-%lu-%lu", &year, &month, &day);
			if(errno||!year||!month||month>12||!day||day>daytab[isleap(year)][month])
			{
				fprintf(stderr, "error: no date of format YEAR-MONTH-DAY found\n");
				continue;
			}
			printf("%lu-%lu-%lu:%s\n", year, month, day,
				dayname[daydiff(1, 1, year, dayofyear(year, month, day))%7]);
		}
	else
		while(scanf("%lu-%lu-%lu", &year, &month, &day)!=EOF)
		{
			if(errno||!year||!month||month>12||!day||day>daytab[isleap(year)][month])
			{
				fprintf(stderr, "error: no date of format YEAR-MONTH-DAY found\n");
				while((c=fgetc(stdin))!=EOF&&c!='\n');
				continue;
			}
			printf("%lu-%lu-%lu:%s\n", year, month, day,
				dayname[daydiff(1, 1, year, dayofyear(year, month, day))%7]);
			errno=0;
		}

	return 0;
}

{'fraction_non_alphanumeric': 0.20542533579141428, 'fraction_numerical': 0.05003950487226758, 'mean_word_length': 4.798473282442748, 'pattern_counts': {'":': 0, '<': 16, '<?xml version=': 0, '>': 19, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 12, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '5534243', 'n_tokens_mistral': 1885, 'n_tokens_neox': 1638, 'n_words': 371}