Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with HTTPS or Subversion.

Download ZIP
Newer
Older
100644 75 lines (59 sloc) 2.523 kb
fccc685 Initial open-source release
MLstate authored
1 (*
2 Copyright © 2011 MLstate
3
4 This file is part of OPA.
5
6 OPA is free software: you can redistribute it and/or modify it under the
7 terms of the GNU Affero General Public License, version 3, as published by
8 the Free Software Foundation.
9
10 OPA is distributed in the hope that it will be useful, but WITHOUT ANY
11 WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS
12 FOR A PARTICULAR PURPOSE. See the GNU Affero General Public License for
13 more details.
14
15 You should have received a copy of the GNU Affero General Public License
16 along with OPA. If not, see <http://www.gnu.org/licenses/>.
17 *)
18 (** This module provides a function to register source code of the application.
19
20 Calls to this BSL function are inserted by the compiler in the compilation
21 pass RegisterAppSrcCode.
22
23 It is subsequently used to present application's source code at the URL:
24 _internal_/src_code.
25
26
27 @author Adam Koprowski
28 *)
29
30 let (|>) = InfixOperator.(|>)
31
32 let src : (string, bool * string) Hashtbl.t = Hashtbl.create 20
33
34 let aux_register_src_code special fn content =
35 Hashtbl.replace src fn (special, content)
36
37 (** Registers a file named [fn] with its source code [content], as part
38 of the application sources.
39 This call is inserted by the compiler into the application. *)
40 ##register [opacapi] register_src_code : string, string -> void
41 let register_src_code fn content =
42 aux_register_src_code false fn content
43
44 (** As [register_src_code], but marks the file as special. *)
45 ##register [opacapi] register_special_src_code : string, string -> void
46 let register_special_src_code fn content =
47 aux_register_src_code true fn content
48
49 (** Returns the list of registered files (see [register_src_code]),
50 constituting the sources of the application. *)
51 ##register get_file_list : -> opa[list(string)]
52 let get_file_list () =
53 let cmp_srcs src1 src2 =
54 match src1, src2 with
55 | (false, _), (true, _) -> -1
56 | (true, _), (false, _) -> 1
57 | (_, s1), (_, s2) -> String.compare s1 s2
58 in
59 let caml_list =
60 Hashtbl.fold (fun x (s, _) xs -> (s, x)::xs) src []
61 |> List.sort cmp_srcs
62 |> List.map snd
63 in
64 BslNativeLib.caml_list_to_opa_list Base.identity caml_list
65
66 (** Returns the content of the file [fn], or [""] if such files
67 was not registered with [register_src_code]. *)
68 ##register get_file_content : string -> string
69 let get_file_content fn =
70 try
71 let _, content = Hashtbl.find src fn in
72 content
73 with
74 Not_found -> ""
Something went wrong with that request. Please try again.