/* surcouche pour les database */

fun DBgetIndex(file,keyword)=
	let ( _OpenDB file ) -> db in
	if ( db == nil ) then (_fooS "Can't open file DB.\n" ; nil ) else
	let (_NbFileDB db )-> i in	
	let nil -> retour in
	(

		while ( i > 0 ) do
		( if (strcmp _GetDB db i-1 0 keyword)==0 then set retour = i-1 else 0 ; set i=i-1 ) ;
		_CloseDB db ;
		retour
	) ;;

fun DBgetFieldIndex(file,index,field)=
let (_OpenDB file ) -> db in let ( _GetDB db index field ) -> u in
( _CloseDB db ; u ) ;;

fun DBgetFieldKeyword(file,keyword,field)=
let ( DBgetIndex file keyword ) -> idx in DBgetFieldIndex file idx field ;;

fun DBsetFieldIndex(file,index,field,value)=
let (_OpenDB file )-> db in ( _SetDB db index field value ; _CloseDB db  ) ;;

fun DBsetFieldKeyword (file,keyword,field,value)=
let ( DBgetIndex file keyword ) -> idx in DBsetFieldIndex file idx field value ;;

fun DBgetNbRecord(file)=let (_OpenDB file ) -> db in
let ( _NbFileDB db ) -> ret in ( _CloseDB db ; ret ) ;;

fun DBaddNewRecord(file)=let (_OpenDB file ) -> db in
let ( _NbFileDB db ) -> ret in
( _AddFileDB db ; _CloseDB db ; ret ) ;;

/* surcouche pour les inventaires */
fun INVgetNbRoot(file) = let (_OpenInv file) -> inv in
let ( _GetNbRootInv inv ) -> ret in
( _CloseInv inv ; ret ) ;;

fun INVaddRoot(file) = let (_OpenInv file) -> inv in
if inv==nil then (_fooS "ERROR :Inventory file unavailable.\n";nil) else 
let ( _GetNbRootInv inv ) -> ret in
( _AddRootInv inv ; _CloseInv inv ; ret ) ;;

fun INVaddItem(file,idx,item)= 
let(_OpenInv file)-> inv in (
_AddItemInv inv idx item ;
_CloseInv inv ) ;;

fun INVgetNbItem(file,idx)= let(_OpenInv file)-> inv in
let (_GetNbItemInv inv idx ) -> res in
( _CloseInv inv ; res ) ;;

fun INVgetItem(file,idx,item)=let (_OpenInv file) ->inv in
let (_GetItemInv inv idx item) -> obj in
( _CloseInv inv ; obj ) ;;

fun INVdelItem(file,idx,item)=let (_OpenInv file)->inv in
(
	_DelItemInv inv idx item ;
	_CloseInv inv 
) ;;

fun INVsetItem(file,idx,num,item)=let (_OpenInv file)-> inv in
(
	_SetItemInv inv idx num item ;
	_CloseInv inv 
) ;;

fun INVtest(file)=
let (_OpenInv file) -> inv in
let 0->ret in 
(
	if ( inv == nil ) then 0 else set ret = 1 ;
	_CloseInv inv ;
	ret 
);;