#include <stdio.h>
#include <string.h>
#include <stdlib.h>
#include <alphaint.h>


int main () {
	size_t size, bts;
	int i, j, r;
	char *line;
	char *p="ánimo, que este código os servirá para trabajar con UTF-8";
	char words[21][9]= {
		"cañada","plaça","bueno","arroyo","piña","caño","rápido",
		"árbol","boro","placa","piraos","capilla","bólido","boa",
		"rareza","bozal","rabia","amule","piraña","ácaro","cabeza"
	};
	char temp[10];
	char *a="pañuelo", *b="patata";
	
	line = malloc (200);
	strcpy (line,"ánimo, que este código os servirá para trabajar con UTF-8\0");
	strcpy(line, p);
	size = UTF8long (line, UTF8);
	bts = strlen(line); 
	printf ("This is a test for the alphaint.c library.\nIt writes a phrase and some spanish words as a example of alphabetical using UTF-8. It uses spanish words because english words don't use accents :).\n\n");
	
	printf ("The string is: %s\n", line);
	printf ("And has %ld caracters long but it needs %ld bytes.\n", size, bts);
	UpperCase (line, UTF8);
	printf ("Changing the first letter to upercase: %s\n",line);
	StringToUpper (line, UTF8);
	printf ("Now, all letters to upercase: %s\n", line);
	LowerCase (line, UTF8);
	printf ("Now, with the first letter in lowercase: %s\n",line);
	StringToLower (line, UTF8);
	printf ("And all letters in lowercase: %s\n",line);
	StringToUpper (line, UTF8);
	printf ("And finaly, all letters converted to uppercase: %s\n\n\n",line);

	printf ("Now, i can ordering some spanish accentued words in UTF-8.\n\n");
	printf ("Without ordering:\n");
	for (i=0; i<21; i++) {
		printf ("%s ",words[i]);
	}

	for (j=0; j<20; j++) {
		for (i=0; i<20; i++) {
			if (AlphaComp(words[i], words[i+1], UTF8, GREATER_THAN)) {
				strcpy (temp,words[i]);
				strcpy (words[i], words[i+1]);
				strcpy (words[i+1],temp);
			}
		}
	}

	printf ("\n\nOrdered:\n");
        for (i=0;i<21; i++) {
                printf ("%s ",words[i]);
        }

	printf ("\n\nSome comparations:\n");
	printf ("Comparing %s y %s\n", a, b);
	r = AlphaComp (a, b, UTF8, GREATER_THAN);
	printf ("greather than result is: %d\n", r);
	r = AlphaComp (a, b, UTF8, LESS_THAN);
	printf ("less than result is: %d\n", r);
	r = AlphaComp (a, b, UTF8, EQUAL_TO);
	printf ("equal to result is: %d\n", r);

	printf ("\n\nIf you have any question, send me a message answering it. :)\n");
	return 0;
}
