From e64970f29dbbce99f28e1d29028854b95ee69f53 Mon Sep 17 00:00:00 2001 From: Maxence Guesdon Date: Fri, 4 Jul 2003 10:02:13 +0000 Subject: [PATCH] Don't overwrite HTML and LateX style files, generate style file for LaTeX git-svn-id: http://caml.inria.fr/svn/ocaml/trunk@5656 f963ae5c-01c2-4b8c-9fe0-0dff7051ff02 --- Changes | 3 +- ocamldoc/Makefile | 3 +- ocamldoc/Makefile.nt | 3 +- ocamldoc/odoc_html.ml | 15 ++++++-- ocamldoc/odoc_latex.ml | 21 ++++++++++ ocamldoc/odoc_latex_style.ml | 74 ++++++++++++++++++++++++++++++++++++ ocamldoc/odoc_messages.ml | 3 ++ 7 files changed, 115 insertions(+), 7 deletions(-) create mode 100644 ocamldoc/odoc_latex_style.ml diff --git a/Changes b/Changes index 1b752af23..f74158f99 100644 --- a/Changes +++ b/Changes @@ -132,7 +132,8 @@ OCamldoc: - handling recursive modules - handling private types - some fixes in html generation - +- don't overwrite existing style.css file when generating HTML +- create the ocamldoc.sty file when generating LaTeX (if it does not already exists) Objective Caml 3.06: -------------------- diff --git a/ocamldoc/Makefile b/ocamldoc/Makefile index 9b2d26776..ab25a4a25 100644 --- a/ocamldoc/Makefile +++ b/ocamldoc/Makefile @@ -112,6 +112,7 @@ EXECMOFILES=$(CMOFILES)\ odoc_ocamlhtml.cmo\ odoc_html.cmo\ odoc_man.cmo\ + odoc_latex_style.cmo \ odoc_latex.cmo\ odoc_texi.cmo\ odoc_dot.cmo @@ -229,7 +230,7 @@ odoc_crc.ml: $(CMIFILES) Odoc_sig Odoc_ast Odoc_control Odoc_inherit \ Odoc_search Odoc_cross Odoc_merge Odoc_analyse \ Odoc_dag2html Odoc_ocamlhtml Odoc_html Odoc_to_text \ - Odoc_latex Odoc_man Odoc_texi Odoc_scan > $@ + Odoc_latex_style Odoc_latex Odoc_man Odoc_texi Odoc_scan > $@ # Parsers and lexers dependencies : ################################### diff --git a/ocamldoc/Makefile.nt b/ocamldoc/Makefile.nt index 270d77d68..53dc034c8 100644 --- a/ocamldoc/Makefile.nt +++ b/ocamldoc/Makefile.nt @@ -109,6 +109,7 @@ EXECMOFILES=$(CMOFILES)\ odoc_ocamlhtml.cmo\ odoc_html.cmo\ odoc_man.cmo\ + odoc_latex_style.cmo \ odoc_latex.cmo\ odoc_texi.cmo\ odoc_dot.cmo\ @@ -266,7 +267,7 @@ odoc_crc.ml: $(CMIFILES) Odoc_sig Odoc_ast Odoc_control Odoc_inherit\ Odoc_search Odoc_cross Odoc_merge Odoc_analyse\ Odoc_dag2html Odoc_ocamlhtml Odoc_html Odoc_to_text \ - Odoc_latex Odoc_man Odoc_texi Odoc_scan > $@ + Odoc_latex_style Odoc_latex Odoc_man Odoc_texi Odoc_scan > $@ # generic rules : ################# diff --git a/ocamldoc/odoc_html.ml b/ocamldoc/odoc_html.ml index 4dbe44aeb..8b1480b54 100644 --- a/ocamldoc/odoc_html.ml +++ b/ocamldoc/odoc_html.ml @@ -582,10 +582,17 @@ class html = let default_style = String.concat "\n" default_style_options in ( try - let chanout = open_out (Filename.concat !Args.target_dir style_file) in - output_string chanout default_style ; - flush chanout ; - close_out chanout + let file = Filename.concat !Args.target_dir style_file in + if Sys.file_exists file then + Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file) + else + ( + let chanout = open_out file in + output_string chanout default_style ; + flush chanout ; + close_out chanout; + Odoc_info.verbose (Odoc_messages.file_generated file) + ) with Sys_error s -> prerr_endline s ; diff --git a/ocamldoc/odoc_latex.ml b/ocamldoc/odoc_latex.ml index 2985f89fe..c6f59f9bc 100644 --- a/ocamldoc/odoc_latex.ml +++ b/ocamldoc/odoc_latex.ml @@ -892,8 +892,29 @@ class latex = (match !Args.title with None -> "" | Some _ -> "\\maketitle\n")^ (if !Args.with_toc then "\\tableofcontents\n" else "") + (** Generate the LaTeX style file, if it does not exists. *) + method generate_style_file = + try + let dir = Filename.dirname !Args.out_file in + let file = Filename.concat dir "ocamldoc.sty" in + if Sys.file_exists file then + Odoc_info.verbose (Odoc_messages.file_exists_dont_generate file) + else + ( + let chanout = open_out file in + output_string chanout Odoc_latex_style.content ; + flush chanout ; + close_out chanout; + Odoc_info.verbose (Odoc_messages.file_generated file) + ) + with + Sys_error s -> + prerr_endline s ; + incr Odoc_info.errors ; + (** Generate the LaTeX file from a module list, in the {!Odoc_info.Args.out_file} file. *) method generate module_list = + self#generate_style_file ; if !Args.separate_files then ( let f m = diff --git a/ocamldoc/odoc_latex_style.ml b/ocamldoc/odoc_latex_style.ml new file mode 100644 index 000000000..34e81ffe0 --- /dev/null +++ b/ocamldoc/odoc_latex_style.ml @@ -0,0 +1,74 @@ +(***********************************************************************) +(* OCamldoc *) +(* *) +(* Maxence Guesdon, projet Cristal, INRIA Rocquencourt *) +(* *) +(* Copyright 2001 Institut National de Recherche en Informatique et *) +(* en Automatique. All rights reserved. This file is distributed *) +(* under the terms of the Q Public License version 1.0. *) +(* *) +(***********************************************************************) + +(** The content of the LaTeX style to generate when generating LaTeX code. *) + +let content =" +%% Support macros for LaTeX documentation generated by ocamldoc. +%% This file is in the public domain; do what you want with it. + +\\NeedsTeXFormat{LaTeX2e} +\\ProvidesPackage{ocamldoc} + [2001/12/04 v1.0 ocamldoc support] + +\\newenvironment{ocamldoccode}{% + \\bgroup + \\leftskip\\@totalleftmargin + \\rightskip\\z@skip + \\parindent\\z@ + \\parfillskip\\@flushglue + \\parskip\\z@skip + %\\noindent + \\@@par\\smallskip + \\@tempswafalse + \\def\\par{% + \\if@tempswa + \\leavevmode\\null\\@@par\\penalty\\interlinepenalty + \\else + \\@tempswatrue + \\ifhmode\\@@par\\penalty\\interlinepenalty\\fi + \\fi} + \\obeylines + \\verbatim@font + \\let\\org@prime~% + \\@noligs + \\let\\org@dospecials\\dospecials + \\g@remfrom@specials{\\\\} + \\g@remfrom@specials{\\{} + \\g@remfrom@specials{\\}} + \\let\\do\\@makeother + \\dospecials + \\let\\dospecials\\org@dospecials + \\frenchspacing\\@vobeyspaces + \\everypar \\expandafter{\\the\\everypar \\unpenalty}} +{\\egroup\\par} + +\\def\\g@remfrom@specials#1{% + \\def\\@new@specials{} + \\def\\@remove##1{% + \\ifx##1#1\\else + \\g@addto@macro\\@new@specials{\\do ##1}\\fi} + \\let\\do\\@remove\\dospecials + \\let\\dospecials\\@new@specials + } + +\\newenvironment{ocamldocdescription} +{\\list{}{\\rightmargin0pt \\topsep0pt}\\raggedright\\item\\relax} +{\\endlist\\medskip} + +\\newenvironment{ocamldoccomment} +{\\list{}{\\leftmargin 2\\leftmargini \\rightmargin0pt \\topsep0pt}\\raggedright\\item\\relax} +{\\endlist} + +\\let\\ocamldocvspace\\vspace +\\endinput +" + diff --git a/ocamldoc/odoc_messages.ml b/ocamldoc/odoc_messages.ml index 2fcebc3b3..ff9c5b2ac 100644 --- a/ocamldoc/odoc_messages.ml +++ b/ocamldoc/odoc_messages.ml @@ -245,6 +245,9 @@ let merging = "Merging..." let cross_referencing = "Cross referencing..." let generating_doc = "Generating documentation..." let loading f = "Loading "^f^"..." +let file_generated f = "File "^f^" generated." +let file_exists_dont_generate f = + "File "^f^" exists, we don't generate it." (** Messages for documentation generation.*)