1 (***********************************************************************)
4 (* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *)
6 (* Copyright 2001 Institut National de Recherche en Informatique et *)
7 (* en Automatique. All rights reserved. This file is distributed *)
8 (* under the terms of the Q Public License version 1.0. *)
10 (***********************************************************************)
12 (* cvsid $Id: odoc_args.ml 9229 2009-04-09 13:56:38Z guesdon $ *)
14 (** Command-line arguments. *)
18 module M = Odoc_messages
25 let include_dirs = Clflags.include_dirs
27 class type doc_generator =
29 method generate : Odoc_module.t_module list -> unit
32 let doc_generator = ref (None : doc_generator option)
34 let merge_options = ref ([] : Odoc_types.merge_option list)
36 let out_file = ref M.default_out_file
38 let dot_include_all = ref false
40 let dot_types = ref false
42 let dot_reduce = ref false
44 let dot_colors = ref (List.flatten M.default_dot_colors)
46 let man_suffix = ref M.default_man_suffix
47 let man_section = ref M.default_man_section
49 let man_mini = ref false
51 (** Analysis of a string defining options. Return the list of
52 options according to the list giving associations between
53 [(character, _)] and a list of options. *)
54 let analyse_option_string l s =
56 (fun acc -> fun ((c,_), v) ->
57 if String.contains s c then
64 (** Analysis of a string defining the merge options to be used.
65 Returns the list of options specified.*)
66 let analyse_merge_options s =
68 (M.merge_description, [Odoc_types.Merge_description]) ;
69 (M.merge_author, [Odoc_types.Merge_author]) ;
70 (M.merge_version, [Odoc_types.Merge_version]) ;
71 (M.merge_see, [Odoc_types.Merge_see]) ;
72 (M.merge_since, [Odoc_types.Merge_since]) ;
73 (M.merge_deprecated, [Odoc_types.Merge_deprecated]) ;
74 (M.merge_param, [Odoc_types.Merge_param]) ;
75 (M.merge_raised_exception, [Odoc_types.Merge_raised_exception]) ;
76 (M.merge_return_value, [Odoc_types.Merge_return_value]) ;
77 (M.merge_custom, [Odoc_types.Merge_custom]) ;
78 (M.merge_all, Odoc_types.all_merge_options)
81 analyse_option_string l s
83 let classic = Clflags.classic
85 let dump = ref (None : string option)
87 let load = ref ([] : string list)
89 (** Allow arbitrary recursive types. *)
90 let recursive_types = Clflags.recursive_types
92 let verbose = ref false
94 (** Optional preprocessor command. *)
95 let preprocessor = Clflags.preprocessor
97 let sort_modules = ref false
99 let no_custom_tags = ref false
101 let no_stop = ref false
103 let remove_stars = ref false
105 let keep_code = ref false
107 let inverse_merge_ml_mli = ref false
109 let filter_with_module_constraints = ref true
111 let title = ref (None : string option)
113 let intro_file = ref (None : string option)
115 let with_parameter_list = ref false
117 let hidden_modules = ref ([] : string list)
119 let target_dir = ref Filename.current_dir_name
121 let css_style = ref None
123 let index_only = ref false
125 let colorize_code = ref false
127 let html_short_functors = ref false
129 let with_header = ref true
131 let with_trailer = ref true
133 let separate_files = ref false
135 let latex_titles = ref [
143 let with_toc = ref true
145 let with_index = ref true
147 let esc_8bits = ref false
149 let info_section = ref "Objective Caml"
151 let info_entry = ref []
155 let f_latex_title s =
157 let pos = String.index s ',' in
158 let n = int_of_string (String.sub s 0 pos) in
159 let len = String.length s in
160 let command = String.sub s (pos + 1) (len - pos - 1) in
161 latex_titles := List.remove_assoc n !latex_titles ;
162 latex_titles := (n, command) :: !latex_titles
165 | Invalid_argument _ ->
166 incr Odoc_global.errors ;
167 prerr_endline (M.wrong_format s)
169 let add_hidden_modules s =
170 let l = Str.split (Str.regexp ",") s in
173 let name = Str.global_replace (Str.regexp "[ \n\r\t]+") "" n in
178 'A'..'Z' -> hidden_modules := name :: !hidden_modules
180 incr Odoc_global.errors;
181 prerr_endline (M.not_a_module_name name)
185 let latex_value_prefix = ref M.default_latex_value_prefix
186 let latex_type_prefix = ref M.default_latex_type_prefix
187 let latex_exception_prefix = ref M.default_latex_exception_prefix
188 let latex_module_prefix = ref M.default_latex_module_prefix
189 let latex_module_type_prefix = ref M.default_latex_module_type_prefix
190 let latex_class_prefix = ref M.default_latex_class_prefix
191 let latex_class_type_prefix = ref M.default_latex_class_type_prefix
192 let latex_attribute_prefix = ref M.default_latex_attribute_prefix
193 let latex_method_prefix = ref M.default_latex_method_prefix
195 let set_doc_generator (dg_opt : doc_generator option) = doc_generator := dg_opt
197 (** The default html generator. Initialized in the parse function, to be used during the command line analysis.*)
198 let default_html_generator = ref (None : doc_generator option)
200 (** The default latex generator. Initialized in the parse function, to be used during the command line analysis.*)
201 let default_latex_generator = ref (None : doc_generator option)
203 (** The default texinfo generator. Initialized in the parse function, to be used during the command line analysis.*)
204 let default_texi_generator = ref (None : doc_generator option)
206 (** The default man pages generator. Initialized in the parse function, to be used during the command line analysis.*)
207 let default_man_generator = ref (None : doc_generator option)
209 (** The default dot generator. Initialized in the parse function, to be used during the command line analysis.*)
210 let default_dot_generator = ref (None : doc_generator option)
212 (** The default option list *)
214 "-version", Arg.Unit (fun () -> print_string M.message_version ; print_newline () ; exit 0) , M.option_version ;
215 "-v", Arg.Unit (fun () -> verbose := true), M.verbose_mode ;
216 "-I", Arg.String (fun s -> include_dirs := (Misc.expand_directory Config.standard_library s) :: !include_dirs), M.include_dirs ;
217 "-pp", Arg.String (fun s -> preprocessor := Some s), M.preprocess ;
218 "-impl", Arg.String (fun s -> files := !files @ [Impl_file s]), M.option_impl ;
219 "-intf", Arg.String (fun s -> files := !files @ [Intf_file s]), M.option_intf ;
220 "-text", Arg.String (fun s -> files := !files @ [Text_file s]), M.option_text ;
221 "-rectypes", Arg.Set recursive_types, M.rectypes ;
222 "-nolabels", Arg.Unit (fun () -> classic := true), M.nolabels ;
223 "-warn-error", Arg.Set Odoc_global.warn_error, M.werr ;
224 "-hide-warnings", Arg.Clear Odoc_config.print_warnings, M.hide_warnings ;
225 "-o", Arg.String (fun s -> out_file := s), M.out_file ;
226 "-d", Arg.String (fun s -> target_dir := s), M.target_dir ;
227 "-sort", Arg.Unit (fun () -> sort_modules := true), M.sort_modules ;
228 "-no-stop", Arg.Set no_stop, M.no_stop ;
229 "-no-custom-tags", Arg.Set no_custom_tags, M.no_custom_tags ;
230 "-stars", Arg.Set remove_stars, M.remove_stars ;
231 "-inv-merge-ml-mli", Arg.Set inverse_merge_ml_mli, M.inverse_merge_ml_mli ;
232 "-no-module-constraint-filter", Arg.Clear filter_with_module_constraints,
233 M.no_filter_with_module_constraints ;
235 "-keep-code", Arg.Set keep_code, M.keep_code^"\n" ;
237 "-dump", Arg.String (fun s -> dump := Some s), M.dump ;
238 "-load", Arg.String (fun s -> load := !load @ [s]), M.load^"\n" ;
240 "-t", Arg.String (fun s -> title := Some s), M.option_title ;
241 "-intro", Arg.String (fun s -> intro_file := Some s), M.option_intro ;
242 "-hide", Arg.String add_hidden_modules, M.hide_modules ;
243 "-m", Arg.String (fun s -> merge_options := !merge_options @ (analyse_merge_options s)),
245 "\n\n *** choosing a generator ***\n";
248 "-html", Arg.Unit (fun () -> set_doc_generator !default_html_generator), M.generate_html ;
249 "-latex", Arg.Unit (fun () -> set_doc_generator !default_latex_generator), M.generate_latex ;
250 "-texi", Arg.Unit (fun () -> set_doc_generator !default_texi_generator), M.generate_texinfo ;
251 "-man", Arg.Unit (fun () -> set_doc_generator !default_man_generator), M.generate_man ;
252 "-dot", Arg.Unit (fun () -> set_doc_generator !default_dot_generator), M.generate_dot ;
253 "-customdir", Arg.Unit (fun () -> Printf.printf "%s\n" Odoc_config.custom_generators_path; exit 0),
254 M.display_custom_generators_dir ;
255 "-i", Arg.String (fun s -> ()), M.add_load_dir ;
256 "-g", Arg.String (fun s -> ()), M.load_file ^
257 "\n\n *** HTML options ***\n";
259 (* html only options *)
260 "-all-params", Arg.Set with_parameter_list, M.with_parameter_list ;
261 "-css-style", Arg.String (fun s -> css_style := Some s), M.css_style ;
262 "-index-only", Arg.Set index_only, M.index_only ;
263 "-colorize-code", Arg.Set colorize_code, M.colorize_code ;
264 "-short-functors", Arg.Set html_short_functors, M.html_short_functors ^
265 "\n\n *** LaTeX options ***\n";
267 (* latex only options *)
268 "-noheader", Arg.Unit (fun () -> with_header := false), M.no_header ;
269 "-notrailer", Arg.Unit (fun () -> with_trailer := false), M.no_trailer ;
270 "-sepfiles", Arg.Set separate_files, M.separate_files ;
271 "-latextitle", Arg.String f_latex_title, M.latex_title latex_titles ;
272 "-latex-value-prefix", Arg.String (fun s -> latex_value_prefix := s), M.latex_value_prefix ;
273 "-latex-type-prefix", Arg.String (fun s -> latex_type_prefix := s), M.latex_type_prefix ;
274 "-latex-exception-prefix", Arg.String (fun s -> latex_exception_prefix := s), M.latex_exception_prefix ;
275 "-latex-attribute-prefix", Arg.String (fun s -> latex_attribute_prefix := s), M.latex_attribute_prefix ;
276 "-latex-method-prefix", Arg.String (fun s -> latex_method_prefix := s), M.latex_method_prefix ;
277 "-latex-module-prefix", Arg.String (fun s -> latex_module_prefix := s), M.latex_module_prefix ;
278 "-latex-module-type-prefix", Arg.String (fun s -> latex_module_type_prefix := s), M.latex_module_type_prefix ;
279 "-latex-class-prefix", Arg.String (fun s -> latex_class_prefix := s), M.latex_class_prefix ;
280 "-latex-class-type-prefix", Arg.String (fun s -> latex_class_type_prefix := s), M.latex_class_type_prefix ;
281 "-notoc", Arg.Unit (fun () -> with_toc := false),
283 "\n\n *** texinfo options ***\n";
285 (* tex only options *)
286 "-noindex", Arg.Clear with_index, M.no_index ;
287 "-esc8", Arg.Set esc_8bits, M.esc_8bits ;
288 "-info-section", Arg.String ((:=) info_section), M.info_section ;
289 "-info-entry", Arg.String (fun s -> info_entry := !info_entry @ [ s ]),
291 "\n\n *** dot options ***\n";
293 (* dot only options *)
294 "-dot-colors", Arg.String (fun s -> dot_colors := Str.split (Str.regexp_string ",") s), M.dot_colors ;
295 "-dot-include-all", Arg.Set dot_include_all, M.dot_include_all ;
296 "-dot-types", Arg.Set dot_types, M.dot_types ;
297 "-dot-reduce", Arg.Set dot_reduce, M.dot_reduce^
298 "\n\n *** man pages options ***\n";
300 (* man only options *)
301 "-man-mini", Arg.Set man_mini, M.man_mini ;
302 "-man-suffix", Arg.String (fun s -> man_suffix := s), M.man_suffix ;
303 "-man-section", Arg.String (fun s -> man_section := s), M.man_section ;
309 let rec iter = function
317 options := iter !options
319 let parse ~html_generator ~latex_generator ~texi_generator ~man_generator ~dot_generator =
322 if Filename.check_suffix f "ml" then
325 if Filename.check_suffix f "mli" then
328 if Filename.check_suffix f "txt" then
331 failwith (Odoc_messages.unknown_extension f)
333 files := !files @ [sf]
335 default_html_generator := Some html_generator ;
336 default_latex_generator := Some latex_generator ;
337 default_texi_generator := Some texi_generator ;
338 default_man_generator := Some man_generator ;
339 default_dot_generator := Some dot_generator ;
340 let _ = Arg.parse !options
342 (M.usage^M.options_are)
344 (* we sort the hidden modules by name, to be sure that for example,
345 A.B is before A, so we will match against A.B before A in
346 Odoc_name.hide_modules.*)
347 hidden_modules := List.sort (fun a -> fun b -> - (compare a b)) !hidden_modules