File: man_server.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 (50 lines) | stat: -rwxr-xr-x 1,167 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
#!/usr/bin/env swipl

:- doc_collect(true).
:- use_module(library(pldoc/doc_library)).
:- use_module(library(lists)).

:- doc_load_library.

%!  main
%
%   Start the documentation server and wait. Does not provide access
%   to the toplevel, so it can be run as a background process.
%
%   Start as
%
%       ==
%       ./man_server.pl [--daemon] [--workers=N] [--port=Port] [--root=Path]
%       ==

main :-
    current_prolog_flag(argv, Argv),
    start_server(Argv),
    wait(Argv).

start_server(Argv) :-
    av_option(port(Port), Argv, 8008),
    av_option(workers(Workers), Argv, 4),
    av_option(root(Root), Argv, '/pldoc'),
    assert(http:location(pldoc, Root, [priority(10)])),
    doc_server(Port,
               [ workers(Workers)
               ]).

wait(Argv) :-
    memberchk('--daemon', Argv),
    !,
    thread_get_message(_),
    halt.
wait(_).

av_option(Option, Argv, Default) :-
    Option =.. [Name,Value],
    (   format(atom(Prefix), '--~w=', [Name]),
        member(Av, Argv),
        atom_concat(Prefix, ValueAtom, Av),
        atom_codes(ValueAtom, Codes),
        name(Value0, Codes)
    ->  Value = Value0
    ;   Value = Default
    ).