/*
 * Copyright (c) 1995, 1996 Gunther Schadow.  All rights reserved.
 *
 * This program is free software; you can redistribute it and/or modify
 * it under the terms of the GNU General Public License as published by
 * the Free Software Foundation; either version 2 of the License, or
 * (at your option) any later version.
 * 
 * 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.  See the
 * GNU General Public License for more details.
 * 
 * You should have received a copy of the GNU General Public License
 * along with this program; if not, write to the Free Software
 * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
 */

/*
 * protocol database interfaces
 *  - filtering unboud variables (_)
 *  - changing representation of information (upper/lower-case,
 *	handling compund symbols etc.)
 */
:- module(db_inter,[repeat_field/6, required_field/2,
	            leng/2, evco/2, dtyp/2, nil/1, nonnil/1,
		    unimesg/3,unidesc/3]).

nil('').
nonnil('') :- !, fail.
nonnil(_).

/* FIXME!  "repfield<~w>" stuff belongs to desc-names.pl
 */
repeat_field(X,n,Type,Type,_,'') :- nil(X), !.
repeat_field(n,n,Type,Type,_,'') :- !.
repeat_field('',n,Type,Type,_,'') :- !.
repeat_field(y,y,Typ,Type,_,'') :- !,
	sformat(Type, "repfield<~w>", Typ).
repeat_field(Sym,Num,Typ,Type,_,'') :-
	concat('y/',Num,Sym), !,
	sformat(Type, "repfield<~w>", Typ).
repeat_field(Sym,Num,Typ,Type,_,'') :-
	concat(y,Num,Sym), !,
	sformat(Type, "repfield<~w>", Typ).
repeat_field(_,n,Type,Type,_,''). % always succeed

/* FIXME!  "required" stuff belongs to desc-names.pl
 */
required_field(r, required).
required_field('R', required).
required_field(_, optional).

leng(X,'') :- nil(X) ,!.
leng(X,X) :- !.

dtyp(X,'') :- nil(X) ,!.
dtyp(X,X) :- !.

evco(X,'') :- nil(X) ,!.
evco(X,X) :- !.

unimesg(M,E,M) :- nonvar(E), E = ''.
unimesg(M,E,N) :- var(N), !,
	concat_atom([M,'_',E],N).
unimesg(M,E,N) :-
	message(M,E,_,_),
	concat_atom([M,'_',E],N).
unimesg(M,'',M).

unidesc(D,E,Du) :-
	concat_atom([D,' ',E],Du).

