From mboxrd@z Thu Jan 1 00:00:00 1970 Return-Path: X-Spam-Checker-Version: SpamAssassin 3.1.3 (2006-06-01) on yquem.inria.fr X-Spam-Level: X-Spam-Status: No, score=0.0 required=5.0 tests=none autolearn=disabled version=3.1.3 X-Original-To: caml-list@yquem.inria.fr Delivered-To: caml-list@yquem.inria.fr Received: from discorde.inria.fr (discorde.inria.fr [192.93.2.38]) by yquem.inria.fr (Postfix) with ESMTP id 8E4E5BC69 for ; Mon, 18 Jun 2007 06:18:21 +0200 (CEST) Received: from sys15.mail.msu.edu (sys15.mail.msu.edu [35.9.75.115]) by discorde.inria.fr (8.13.6/8.13.6) with ESMTP id l5I4IKSH018308 (version=TLSv1/SSLv3 cipher=DHE-RSA-AES256-SHA bits=256 verify=NO) for ; Mon, 18 Jun 2007 06:18:21 +0200 Received: from shawjef3 by sys15.mail.msu.edu with local (Exim 4.63 #1) id 1I08gz-0006sd-QS; Mon, 18 Jun 2007 00:18:17 -0400 From: "Jeffrey Loren Shaw" To: lists@philippewang.info Cc: caml-list@yquem.inria.fr Subject: Re: [Caml-list] Dynamic linking Date: Mon, 18 Jun 2007 00:18:17 -0400 Mime-Version: 1.0 Content-Type: text/plain; format=flowed; charset="utf-8" Content-Transfer-Encoding: 7bit Message-Id: X-Virus: None found by Clam AV X-Miltered: at discorde with ID 4676078C.000 by Joe's j-chkmail (http://j-chkmail . ensmp . fr)! X-Spam: no; 0.00; ocamlopt:01 foo:01 foo:01 -compile:01 bug:01 buffer:01 accum:01 buffer:01 accum:01 endline:01 infile:01 -compile:01 argv:01 argv:01 outchan:01 Philippe, here's a little program I wrote that you might find useful. compile: ocamlopt -o keepsource keepsource.ml usage: ./keepsource foo.ml creates a new file foo_keepsource.ml. If you compile it to the executable foo you can do ./foo -source to get the original source back. ./keepsource foo.ml -compile does the same thing bug gives you an executable named foo in addition to foo_keepsource.ml. It will only work on single-file programs, and I haven't tested it much. (* keepsource.ml *) let replace_quote str = let result = ref [] in for i = 0 to String.length str - 1 do match str.[i] with '\\' -> result := '\\'::'\\'::!result | '\"' -> result := '\"'::'\\'::!result | a -> result := a::!result done; let buffer = " " in List.fold_left (fun accum a -> buffer.[0] <- a; buffer ^ accum ) "" !result;; let print_help () = print_endline "usage: keepsource infile.ml (-compile)";; if Array.length Sys.argv = 1 then print_help ();; let sourcefile = Sys.argv.(1);; let sourcefile_keepsource = String.sub sourcefile 0 (String.length sourcefile - 3) ^ "_keepsource.ml";; if Sys.file_exists sourcefile then let inchan = open_in sourcefile in let source = ref [] in ( try while true do source := (input_line inchan)::!source done with End_of_file -> () ); close_in inchan; source := List.rev !source; let outchan = open_out sourcefile_keepsource in let output = output_string outchan in output "let sourcecode = \""; List.iter (fun s -> output (replace_quote s^"\n")) !source; output "\"\n\nlet main () = ("; List.iter (fun s -> output (s^"\n")) !source; output ");; if Array.length Sys.argv > 1 then if Sys.argv.(1) = \"-source\" then ( print_endline sourcecode; exit 0 ) else main () else main () "; close_out outchan;; if Array.length Sys.argv > 2 then if Sys.argv.(2) = "-compile" then let compile_command = "ocamlopt -o " ^ String.sub sourcefile 0 (String.length sourcefile - 3) ^ " "^ sourcefile_keepsource in ignore ( Sys.command compile_command )