amp@546: let read_line () = amp@546: try amp@546: Some (read_line ()) amp@546: with End_of_file -> None amp@546: amp@546: let print_bsd_licence () = begin amp@546: print_endline " * Three-clause BSD Licence"; amp@546: print_endline " *"; amp@546: print_endline " * All rights reserved."; amp@546: print_endline " *"; amp@546: print_endline " * Redistribution and use in source and binary forms, with or without"; amp@546: print_endline " * modification, are permitted provided that the following conditions are met:"; amp@546: print_endline " *"; amp@546: print_endline " * - Redistributions of source code must retain the above copyright notice,"; amp@546: print_endline " * this list of conditions and the following disclaimer."; amp@546: print_endline " * - Redistributions in binary form must reproduce the above copyright notice,"; amp@546: print_endline " * this list of conditions and the following disclaimer in the documentation"; amp@546: print_endline " * and/or other materials provided with the distribution."; amp@546: print_endline " * - The names of contributors may not be used to endorse or promote products"; amp@546: print_endline " * derived from this software without specific prior written permission."; amp@546: print_endline " *"; amp@546: print_endline " * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS \"AS IS\""; amp@546: print_endline " * AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE"; amp@546: print_endline " * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE"; amp@546: print_endline " * ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS BE"; amp@546: print_endline " * LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR "; amp@546: print_endline " * CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF"; amp@546: print_endline " * SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS"; amp@546: print_endline " * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN"; amp@546: print_endline " * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)"; amp@546: print_endline " * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE"; amp@546: print_endline " * POSSIBILITY OF SUCH DAMAGE." amp@546: end amp@546: amp@546: let rec initial () = amp@546: match read_line () with amp@546: | None -> () amp@546: | Some line -> amp@546: let trimmed = String.trim line in amp@546: if String.length trimmed >= 12 && String.sub trimmed 0 12 = "(* Copyright" then begin amp@546: print_endline line; amp@546: copyright_block () amp@546: end else amp@546: print_endline line; amp@546: initial () amp@546: amp@546: and copyright_block () = amp@546: match read_line () with amp@546: | None -> () amp@546: | Some line -> amp@546: let trimmed = String.trim line in amp@546: if String.length trimmed >= 2 && String.sub trimmed 0 2 = "*)" then begin amp@546: print_endline line; amp@546: initial () amp@546: end else if String.length trimmed >= 31 && String.sub trimmed 0 31 = "* This work is licensed under a" then begin amp@546: print_endline line; amp@546: print_bsd_licence (); amp@546: drop_to_end_comment () amp@546: end else amp@546: print_endline line; amp@546: copyright_block () amp@546: amp@546: and drop_to_end_comment () = amp@546: match read_line () with amp@546: | None -> () amp@546: | Some line -> amp@546: let trimmed = String.trim line in amp@546: if String.length trimmed >= 2 && String.sub trimmed 0 2 = "*)" then begin amp@546: print_endline line; amp@546: initial () amp@546: end else amp@546: drop_to_end_comment () amp@546: amp@546: let () = initial ()