File: pce_class_index.pl

package info (click to toggle)
swi-prolog 9.0.4%2Bdfsg-2
  • links: PTS, VCS
  • area: main
  • in suites: bookworm
  • size: 82,408 kB
  • sloc: ansic: 387,503; perl: 359,326; cpp: 6,613; lisp: 6,247; java: 5,540; sh: 3,147; javascript: 2,668; python: 1,900; ruby: 1,594; yacc: 845; makefile: 428; xml: 317; sed: 12; sql: 6
file content (119 lines) | stat: -rw-r--r-- 3,306 bytes parent folder | download | duplicates (4)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
/*  File:    pce_index.pl
    Author:  Jan Wielemaker
    Created: Mar 14 2003
    Purpose:
*/

:- module(pce_class_index,
          [ pce_make_library_index/1,   % +Dir
            pce_update_library_index/0
          ]).
:- use_module(library(pce_prolog_xref)).
:- use_module(library(lists)).

index_file('CLASSINDEX.pl').

%!  pce_make_library_index(+Dir)
%
%   Create a file CLASSINDEX.pl in Dir holding facts of the format
%
%!          class(Name, Super, Summary, File)
%
%   This file can be used for auto-loading as well as supporting
%   cross-referencing and syntax-highlighting.

pce_make_library_index(Dir) :-
    absolute_file_name(Dir,
                       [ file_type(directory),
                         access(exist)
                       ],
                       Path),
    working_directory(Old, Path),
    call_cleanup(make_library_index,
                 working_directory(_, Old)).

%       pce_update_library_index/0
%
%       Update out-of-date CLASSINDEX.pl files in defined library
%       directories.

pce_update_library_index :-
    index_file(File),
    (   absolute_file_name(library(File),
                           [ access(read),
                             access(write),
                             solutions(all),
                             file_errors(fail)
                           ],
                           AbsFile),
        file_directory_name(AbsFile, Dir),
        print_message(informational, pce(update_library_index(Dir))),
        pce_update_library_index(Dir),
        fail
    ;   true
    ).

pce_update_library_index(Dir) :-
    working_directory(Old, Dir),
    call_cleanup(update_library_index,
                 working_directory(_, Old)).

update_library_index :-
    expand_file_name('*.pl', Files),
    index_file(Index),
    (   library_index_out_of_date(Index, Files),
        catch(open(Index, write, Out), _, fail)
    ->  header(Out),
        call_cleanup(index_file_list(Files, Out),
                     close(Out))
    ;   true
    ).

make_library_index :-
    expand_file_name('*.pl', Files),
    index_file(Index),
    open(Index, write, Out),
    header(Out),
    call_cleanup(index_file_list(Files, Out),
                 close(Out)).

index_file_list([], _).
index_file_list([H|T], Out) :-
    index_file(H, Out),
    index_file_list(T, Out).

index_file('INDEX.pl', _) :- !.
index_file('MKINDEX.pl', _) :- !.
index_file('CLASSINDEX.pl', _) :- !.
index_file(File, Out) :-
    xref_source(File, [silent(true)]),
    (   xref_defined_class(File, Class, local(_Line, Super, Summary)),
        format(Out,
               'class(~q, ~q, ~q, ~q).~n',
               [Class, Super, Summary, File]),
        fail
    ;   true
    ),
    xref_clean(File).

header(Out) :-
    format(Out,
           '/*  $Id\c
               $\n\n    \c
               Creator: pce_make_library_index/1\n    \c
               Purpose: Provide index of XPCE classes in directory\n\c
               */\n\n',
           []).

library_index_out_of_date(Index, _Files) :-
    \+ exists_file(Index),
    !.
library_index_out_of_date(Index, Files) :-
    time_file(Index, IndexTime),
    (   time_file('.', DotTime),
        DotTime @> IndexTime
    ;   member(File, Files),
        time_file(File, FileTime),
        FileTime @> IndexTime
    ),
    !.