
read_alc_defs(F,DList):-
    readin_alc(F,G),
    build_alc_def(G,' ',[_|DList]),!.

readin_alc(IP,P):-
    see(IP),
    read_to_eof_alc(P),
    seen.

build_alc_def([],D,[D]):-!.

build_alc_def(['(defconcept'|A],D,[D|R]):-
    build_alc_def(A,'(defconcept',R).
build_alc_def(['(defprimconcept'|A],D,[D|R]):-
    build_alc_def(A,'(defprimconcept',R).
build_alc_def([X|A],D,R):-
    concat(D,' ',DX),
    concat(DX,X,DXX),
    build_alc_def(A,DXX,R).




read_to_eof_alc(I):-
        get0(C),
        read_lines_alc(C,[I]),!.

read_lines_alc(-1,[]):-!. %  EOF
read_lines_alc(C,[Line|L]):-
        read_line_alc(C,Line,D),!,
        read_lines_alc(D,L),!.

read_line_alc(-1,[],-1). %  EOF
read_line_alc(A,[W],D):- stopword(A,W),get0(D),!.
%read_line_alc(C,[Word|Line],L):-
%        word(C,Word),
%        get0(D),
%        read_line_alc(D,Line,L),!.
read_line_alc(C,Result,L):-
        read_word_alc(C,Word,D),!,
        read_line_alc(D,Line,L),!,
        check_name_alc(Word,Line,Result).

check_name_alc([],L,L):-!. % don't add '' to output
check_name_alc(W,L,[S|L]):-
        name(S,W).

read_word_alc(-1,[],-1):-!. %  EOF
%read_word_alc(A,[],A):- word_alc(A,_).
%read_word_alc(A,[],A):- stopword(A,_).
read_word_alc(10,[],D):- get0(D),!. % nl
read_word_alc(32,[],D):- get0(D),!. % space
read_word_alc(C,[C|I],L):-
        get0(D),
        read_word_alc(D,I,L),!.


word(37,'%').
word(40,'(').
word(41,')').
word(44,',').
word(47,'/').
word(60,'<').
word(62,'>').
stopword(46,'.'). % .
stopword(33,'!'). % !
stopword(63,'?'). % ? 

