#ifdef AFTER_LIBIOFILE_INSTALLED
#include <iofile.h>
#else
#include "iofile.h"
#endif


int main(int argc, char **argv)
{
	FILE *fp;
	long len;
	unsigned char *buffer, ch;
	unsigned long lun;
	
	if(argc  == 3) {

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * filep = check_n_openfile ( name, mode );
 *
 * this function return the pointer 'filep' to the file which 'name' was passed
 * as first argument opened in 'mode' (es.: "r+", "wt", etc.). In case of fatal 
 * error 'filep' will be set to NULL.
 */	
		printf("\nTrying to open '%s' in '%s' mode\n", argv[1], argv[2]);		
		fp = check_n_openfile(argv[1], argv[2]);
		printf("File pointer address is: 0x%lx\n", (unsigned long)fp);
		if(fp == NULL)
			return 1;

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * lung = get_file_lenght ( filep );
 *
 * this function return the lenght 'lung' of the file pointed by 'filep' passed
 * as first parameter, that point to opened file which you're interested in.
 */		
		printf("\nTrying to check '%s' file lenght\n", argv[1]);		
		lun =  get_file_lenght (fp);
		printf("File lenght is: %ld\n", lun);

/* * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * * *
 * buffer = read_file_to_buffer (name, mode, &lun);
 *
 * this function try to access to the file specified by path in the first 
 * parameter 'name' and check if it possibile open it in 'mode' (es.: "r+", 
 * "rt", etc.), check the lenght and store it in 'lun', alloc the necessary 
 * memory, open the file and read it into allocated buffer. If each of these
 * will succeded it will return the pointer to allocated buffer which contain
 * the file contenent otherwise it will return NULL.
 */		
		printf("\nTrying to read '%s' file\n", argv[1]);
		buffer = read_file_to_buffer (argv[1], argv[2], &len);
		printf("File pointer address is: 0x%lx\n", (unsigned long)fp);
		printf("File lenght is: %ld\n", len);
		if(fp == NULL || len <= 0) 
			return 2;
				
		printf("Would you see the '%s' file contenent [s/N]?\n", argv[1]);
		scanf("%c", &ch);
		if(ch == 's' || ch == 'S')
			printf("%s", buffer);
		free(buffer);
	} else {
		printf("\nI/O FILE LIBRERY TEST\n");
		printf("\ntest (filename) (mode)\n");
		printf("\nes.: \"test test.c rt\"\n");
	}
	
	return 0;
}