/* español.langmod 1.0.4ß */

/* 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"

#define MINLIMIT	2

/* The strings.... */

char *months_data[]={
	"enero",                     /* January */
	"febrero",
	"marzo",
	"abril",
	"mayo",
	"junio",
	"julio",
	"agosto",
	"septiembre",
	"octubre",
	"noviembre",
	"diciembre"                  /* December */
};

char *days_data[] = {
	"Domingo",                   /* Sunday */
	"Lunes",
	"Martes",
	"Miércoles",
	"Jueves",
	"Viernes",
	"Sábado",                    /* Saturday */
};

char *eng_time[] = {
	"una",                       /* One */
	"dos",
	"tres",
	"cuatro",
	"cinco",
	"seis",
	"siete",
	"ocho",
	"nueve",
	"diez",
	"once",
	"doce"                       /* Twelve */
};

char *eng_int_min[] = {
	"en punto ",                 /* =00 min */
	"",
	"y cinco ",                  /* ~05 min */
	"y diez ",                   /* ~10 min */
	"y cuarto ",                 /* ~15 min */
	"y veinte ",                 /* ~20 min */
	"y veinticinco ",            /* ~25 min */
	"y media ",                  /* ~30 min */
	"menos veinticinco ",        /* ~35 min */
	"menos veinte ",             /* ~40 min */
	"menos cuarto ",             /* ~45 min */
	"menos diez ",               /* ~50 min */
	"menos cinco "               /* ~55 min */
};

__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;

   /* First words... */
   if(((tm->hours==1  && tm->minutes < (30+MINLIMIT)) || (tm->hours==0  && tm->minutes >= (30+MINLIMIT))) ||
      ((tm->hours==13 && tm->minutes < (30+MINLIMIT)) || (tm->hours==12 && tm->minutes >= (30+MINLIMIT)))) {
        strcpy(line1,"Es la");
     }
    else strcpy(line1,"Son las");

   /* Separator */
   strcat(line1," ");

   /* Rounding minutes */
   temp1=(tm->minutes/5)*5;

   /* Adjust the scale (24 hrs -> 12 hrs) */
   /* 1.- AM or PM */
   afternoon=FALSE;
   if(tm->hours>=12) afternoon=TRUE;
   /* 2.- Scaling hour */
   if(tm->hours>12) tm->hours=tm->hours-12;
    /* Midnight case */
    else if(tm->hours==0) tm->hours=12;

   /* Hour */
   if(tm->minutes<=(30+MINLIMIT)) strcat(line1,eng_time[tm->hours-1]);
     else {
        if(tm->hours==12) strcat(line1,eng_time[0]);
          else strcat(line1,eng_time[tm->hours]);
        }
   /* Separator */
   strcat(line1," ");

   /* O'Clock? */
   if(tm->minutes==0) strcat(line1,eng_int_min[0]);
     /* Minutes (now separator included in the string) */
     else {
      if((tm->minutes-temp1)<=MINLIMIT)
        strcat(line1,eng_int_min[(tm->minutes/5)+1]);
       else {
         if(tm->minutes<=(50+MINLIMIT)) strcat(line1,eng_int_min[(tm->minutes/5)+2]);
          else strcat(line1,eng_int_min[1]);
         }
      }

  /* Final part */
  if(!afternoon) {
    /* Morning (AM) */
    if(tm->hours==12 && tm->minutes <= (30+MINLIMIT))
      strcat(line1,"de la noche");

    if((tm->hours==12 && tm->minutes > (30+MINLIMIT)) ||
       (tm->hours>=1  && tm->hours<4) ||
       (tm->hours==4  && tm->minutes <= (30+MINLIMIT)))
       strcat(line1,"de la madrugada");

    if((tm->hours==4  && tm->minutes > (30+MINLIMIT)) ||
       (tm->hours>=5  && tm->hours < 11) ||
       (tm->hours==11 && tm->minutes <= (30+MINLIMIT)))
       strcat(line1,"de la mañana");

    if(tm->hours==11 && tm->minutes > (30+MINLIMIT))
      strcat(line1,"del mediodía");
    }
   else {
    /* Afternoon (PM) */
    if(tm->hours==12 && tm->minutes <= (30+MINLIMIT))
      strcat(line1,"del mediodía");

    if((tm->hours==12 && tm->minutes > (30+MINLIMIT)) ||
       (tm->hours>=1  && tm->hours<8) ||
       (tm->hours==8  && tm->minutes <= (30+MINLIMIT)))
       strcat(line1,"de la tarde");

    if((tm->hours==8 && tm->minutes > (30+MINLIMIT)) ||
       (tm->hours>=9 && tm->hours<12))
       strcat(line1,"de la noche");
    }

   /* Special cases */
    if(tm->hours==12  && tm->minutes==0) {
      if(afternoon) strcpy(line1,"Es mediodía");
       else strcpy(line1,"Es medianoche");
   }

   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]);
	strcat(line2,",");
	sprintf(tmp," %ld ",tm->days);
	strcat(line2,tmp);
	strcat(line2,"de ");
	strcat(line2,months_data[tm->months-1]);
	strcat(line2," de");
	sprintf(tmp," %ld",tm->years);
	strcat(line2,tmp);

	if(strlen(line2) > bufsize) {
		*error=ERR_BUFSIZE;
		return(0);
	}

	strcpy(buffer,line2);

	return(buffer);

}
