/**********************************************************************
 
	Copyright (C) 2003 Hirohisa MORI <joshua@nichibun.ac.jp>
 
	This program is free software; you can redistribute it 
	and/or modify it under the terms of the GLOBALBASE 
	Library General Public License (G-LGPL) as published by 

	http://www.globalbase.org/
 
	This program is distributed in the hope that it will be 
	useful, but WITHOUT ANY WARRANTY; without even the 
	implied warranty of MERCHANTABILITY or FITNESS FOR A 
	PARTICULAR PURPOSE.

**********************************************************************/

/*
 *  © 1997-2000 Metrowerks Corp.
 *
 *  Questions and comments to:
 *       <mailto:support@metrowerks.com>
 *       <http://www.metrowerks.com/>
 */

#include 	<stdio.h>
#include	<fcntl.h>
#include	"memory_debug.h"
#include	"pdb.h"
#include	"filespace.h"
#include	"favt.h"
#include	"change_endian.h"


int
cmp_integer(void * d1,void * d2)
{
int dd1,dd2;
	dd1 = *(int*)d1;
	dd2 = *(int*)d2;
	if ( dd1 > dd2 )
		return 1;
	if ( dd1 < dd2 )
		return -1;
	return 0;
}

void endian_func(void * data,int size)
{
int * d;
	d = data;
	change_endian_i(*d);
}

/*
int main(void)
{
PDB * p;
FAVT_ROOT * r;
FAVT_NODE * n;
int i;
unsigned int rt;
void * ptr;
int del;
	printf("start test\n");
	init_favt();
	p = open_filespace("test.file",O_CREAT|O_TRUNC|O_RDWR,0644,
		PF_USEFREELIST,
		FT_ADDRESS_LUMP,0,0,0);
	r = favt_alloc_root(p,0x100,endian_func);
	rt = r->h.fofs;

	del = 0;
	for ( i = 0 ; i < 10000 ; i ++ ) {
		r = get_root(p,rt,endian_func);
		n = favt_alloc_node(r,&i,sizeof(i));
		favt_insert(r,&r->node,n,cmp_integer);
		if ( (i % 20) == 0 ) {
			for ( ; del < i ; del += 2 ) {
				r = get_root(p,rt,endian_func);
				n = favt_delete(r,&r->node,&del,cmp_integer);
				favt_free_node(n);
			}
		}
	}
	close_filespace(p);
printf("--\n");
	p = open_filespace("test.file",O_RDWR,0644,0,
		FT_ADDRESS_LUMP,0,0,0);
	if ( p == 0 )
		er_panic("test0");
	rt = 0;
	ptr = get_file_record(&rt,p,PNT_FAVT_ROOT);
	if ( ptr == 0 ) {
		fprintf(stderr,"cannot find root\n");
		exit(1);
	}
	d_f_ree(ptr);
	r = get_root(p,rt,endian_func);
	if ( r == 0 )
		er_panic("test");
	favt_test(r,root_node(r),cmp_integer);

	p = open_filespace("test.file",O_RDWR,0644,0,
		FT_ADDRESS_LUMP,0,0,0);
	if ( p == 0 )
		er_panic("test0");

	check_filespace(p);
	if ( check_freelist(p) < 0 )
		er_panic("no freelist\n");
	close_filespace(p);

	return 0;
}
*/
