/* English.langmod */

/* Try not to open too many libraries, in fact it's best to stick to
basic exec stuff ;-) */

#include <stdio.h>
#include <proto/exec.h>

#include "langmod_protos.h"
#include "langmod.h"

/* The strings.... */

char *months_data[13] = {
   "",
   "January",
   "February",
   "March",
   "April",
   "May",
   "June",
   "July",
   "August",
   "September",
   "October",
   "November",
   "December"
};

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

char *engnums[] = {
	"",	
	"one",
	"two",
	"three",
	"four",
	"five",
	"six",
	"seven",
	"eight",
	"nine",
	"ten",
	"eleven",
	"twelve",
	"midnight",
	"midday",
	"quarter", "","","","",
	"twenty", "","","","",
	"twenty-five", "","","","",
	"half", "","","","",
	"five and twenty", "","","","",
	"twenty", "","","","",
	"quarter", "","","","",
	"ten", "","","","",
	"five"
};

__asm UBYTE *ECM_GetTimeStr(	register __a0 UBYTE *buffer,
								register __d1 ULONG bufsize,
								register __a1 ULONG *error,
								register __a2 struct EngTime *tm ) {
	char line1[200];
	long temp1;
	BOOL afternoon;
	
	*error=0;
	
	if(tm->hours>12) {
		tm->hours=tm->hours-12;
		afternoon=TRUE;
	} else {
		if(tm->hours==12)
			afternoon=TRUE;
		else
			afternoon=FALSE;
	}

	if(tm->hours==0)  /* Midnight! */
		tm->hours=12;

	strcpy(line1,"It's"); 
	temp1=(tm->minutes/5)*5;
	
	if((tm->minutes-temp1)<=2)
		strcat(line1," just gone");
	else 
		strcat(line1," nearly");

	if(tm->minutes>2 & tm->minutes<58) {
		strcat(line1," "); 
		if((tm->minutes-temp1)<=2)
			strcat(line1,engnums[(tm->minutes/5)*5]);
		else 
			strcat(line1,engnums[((tm->minutes/5)+1)*5]);
	}

	if(tm->minutes>2 & tm->minutes<58) {
		if(tm->minutes<=32) 
			strcat(line1," past");
		else 
			strcat(line1," to");
	}

	strcat(line1," "); 
	if(tm->minutes<=32) {
		if(tm->hours==12) {
			if(afternoon) {
				if(tm->minutes>2) 
					strcat(line1,engnums[14]);
				else 
					strcat(line1,engnums[12]);
			} else {
				if(tm->minutes>2) 
					strcat(line1,engnums[13]);
				else 
					strcat(line1,engnums[12]);
            } 
		} else 
			strcat(line1,engnums[tm->hours]);
	} else {
		if(tm->hours==12) 
			strcat(line1,engnums[1]);
		else {
			if(tm->hours==11) {
				if(afternoon) {
					if(tm->minutes<58) 
						strcat(line1,engnums[13]);
					else 
						strcat(line1,engnums[12]);
				} else {
					if(tm->minutes<58) 
						strcat(line1,engnums[14]);
					else 
						strcat(line1,engnums[12]);
				}
			} else 
				strcat(line1,engnums[tm->hours+1]);
		}
	}

	if((tm->minutes<3) | (tm->minutes>57) ) 
    	strcat(line1," o'clock");

	if(afternoon)
		strcat(line1," (pm)");
	else
		strcat(line1," (am)");
		
	
	if(strlen(line1) > bufsize) {
		*error=ERR_BUFSIZE;
		return(0);
	}

	strcpy(buffer,line1);

	return(buffer);

}

__asm UBYTE *ECM_GetDateStr(	register __a0 UBYTE *buffer,
								register __d1 ULONG bufsize,
								register __a1 ULONG *error,
								register __a2 struct EngTime *tm) {
	char line2[200];
	char tmp[10];
	
	*error=0;
	
	strcpy(line2,days_data[tm->wday]);

	switch(tm->days) {
		case 1:
			/* First day */
			strcat(line2," 1st ");
		break;
		case 2:  
			strcat(line2," 2nd ");
		break;
		case 3:
			strcat(line2," 3rd ");
		break;
		case 21:
			strcat(line2," 21st ");
		break;
		case 22:
			strcat(line2," 22nd ");
		break;
		case 23:
			strcat(line2," 23rd ");
		break;
		case 30:
			strcat(line2," 30th ");
		break; 
		case 31:
			strcat(line2," 31st ");
		break;
		default:
			sprintf(tmp," %ld",tm->days);
			strcat(line2,tmp);
			strcat(line2,"th ");
		break;
	} /* End of switch(tm->days) */
	
	strcat(line2,months_data[tm->months]);
	strcat(line2,", "); 
	sprintf(tmp,"%ld",tm->years);
	strcat(line2,tmp);
	
	if(strlen(line2) > bufsize) {
		*error=ERR_BUFSIZE;
		return(0);
	}

	strcpy(buffer,line2);
	
	return(buffer);

}
