1:- module( lib_mkdoc, [lib_mkdoc/0,lib_mkdoc/1] ).    2
    3:- dynamic( lib_mkdoc:loaded/1 ).    4:- dynamic( lib_mkdoc:lib_index/5 ).    5
    6lib_mkdoc :- 
    7    lib_mkdoc( '.' ).
 lib_mkdoc(+Dir)
Make docs for lazy packs.

:- asserta( library_directory('/usr/local/users/nicos/local/git/lib/swipl-7.5.1/pack/lib/prolog/mkdoc') ). :- use_module( '/usr/local/users/nicos/local/git/lib/swipl-7.5.1/pack/lib/prolog/mkdoc/lib' ).

*/

   17lib_mkdoc( DirIn ) :-
   18    absolute_file_name( DirIn, Dir, [file_type(directory)] ),
   19    working_directory( Old, Dir ),
   20    directory_file_path( _LibRoot, Pack, Dir ),
   21    directory_file_path( Dir, prolog, PrologD ),
   22    file_name_extension( Pack, pl, PackF ),
   23    directory_file_path( PrologD, PackF, AbsPackF ),
   24    %
   25    directory_file_path( doc, PackF, DocF ),
   26    % shell( 'ln -s ../src doc/src' ),
   27    open( DocF, write, Out ),
   28    open( AbsPackF, read, In ),
   29    read( In, (:- module(Pack,Exports)) ),
   30    portray_clause( Out, (:- module(Pack,Exports)) ),
   31    directory_file_path( Dir, src, SrcD ),
   32    directory_file_path( SrcD, 'LibIndex.pl', SrcLib ),
   33    ( exists_file(SrcLib) -> 
   34        ensure_loaded( lib_mkdoc:SrcLib ),
   35        listing( lib_mkdoc:lib_index/5 )
   36        ;
   37        true
   38    ),
   39    set_prolog_flag( verbose_load, full ),
   40    % asserta( lib_mkdoc:loc(Dir,Out) ),
   41    absolute_file_name( pack('lib/prolog/mkdoc'), Mkdoc, [file_type(directory)] ),
   42    % asserta( library_directory(Mkdoc) ),
   43    % use_module( library(lib) ),
   44    % absolute_file_name( pack('lib/prolog/mkdoc/lib.pl'), LibPl, [file_errors(fail),access(exist)] ),
   45    % use_module( LibPl ),
   46    % export( lib_mkdoc:lib/1 ),
   47    % import( Pack:lib/1 ),
   48    % spy( lib:lib/1 ),
   49    % ensure_loaded( AbsPackF ),
   50    portray_clause( Out, library_directory(Mkdoc) ),
   51    directory_file_path( Mkdoc, lib, MkLib ),
   52    portray_clause( Out, (:- use_module(MkLib)) ),
   53    %  :- use_module( '/usr/local/users/nicos/local/git/lib/swipl-7.5.1/pack/lib/prolog/mkdoc/lib' ).
   54    nl( Out ),
   55    read( In, Term ),
   56    lib_mkdoc_stream( Term, In, Out ),
   57    close( In ),
   58    close( Out ),
   59
   60    open( DocF, append, OutA ),    % make sure we get the docs in the file too
   61    open( AbsPackF, read, InA ),
   62    read( InA, _ModDfn ),
   63    copy_stream_data( InA, OutA ),
   64    close( InA ),
   65    close( OutA ),
   66
   67    ensure_loaded( DocF ),
   68    doc_save( DocF, [doc_root('doc/html')] ),
   69    %
   70    working_directory( _, Old ).
   71
   72lib_mkdoc_stream( end_of_file, _In, _Out ) :- !.
   73lib_mkdoc_stream( (:- lib(Pn/Pa) ), In, Out ) :-
   74    lib_mkdoc:lib_index( Pn, Pa, _, _, File ),
   75    directory_file_path( src, File, SrcFile ),
   76    file_name_extension( SrcFile, pl, RelF ),
   77    exists_file( RelF ),
   78    !,
   79    lib_mkdoc_file( RelF, Out ),
   80    read( In, Next ),
   81    lib_mkdoc_stream( Next, In, Out ).
   82lib_mkdoc_stream( _Other, In, Out ) :-
   83    catch( read( In, Next ), _, Next = errored ),
   84    lib_mkdoc_stream( Next, In, Out ).
   85    
   86lib_mkdoc_file( RelF, _Out ) :-
   87    lib_mkdoc:loaded( RelF ),
   88    !.
   89lib_mkdoc_file( RelF, Out ) :-
   90    open( RelF, read, RelIn ),
   91    copy_stream_data( RelIn, Out ),
   92    close( RelIn ),
   93    asserta( lib_mkdoc:loaded( RelF ) )