On Wed, Dec 26, 2001 at 07:17:14PM +0100, Stefano Zacchiroli wrote:
> Here you are: a small OCaml script that add or remove entries from
grrrrr ... I forget to attach the script.
Cheers.
--
Stefano "Zack" Zacchiroli <zack@cs.unibo.it> ICQ# 33538863
Home Page: http://www.cs.unibo.it/~zacchiro
Undergraduate student of Computer Science @ University of Bologna, Italy
- Information wants to be Open -
#!/usr/bin/ocamlrun /usr/bin/ocaml
(*
Add or remove path entries to the standard path that ocaml use to find
dynamic loadable extension. That path is kept in a path file, usually
"/usr/lib/ocaml/ld.conf".
Distributed freely under the term of the GNU General Public License.
Author: Stefano "Zack" Zacchiroli <zack@debian.org>
Wed Dec 26 19:21:20 CET 2001
*)
let pathfile = "/usr/lib/ocaml/ld.conf";;
let tmppathfile = pathfile ^ ".debian.tmp";;
type action = Add | Remove | NoAct;;
let path = ref "";;
let action = ref NoAct;;
let help_string = "
Usage: dh_ocaml.ml -a <path>
dh_ocaml.ml -r <path>
"
let input_list inchan =
let llist = ref [] in
begin try
while true do
let line = input_line inchan in llist := line :: !llist
done with End_of_file -> llist := List.rev !llist
end;
!llist;;
let output_list outchan = List.iter (fun s -> output_string outchan (s ^ "\n"));;
let addpath entry path = if List.mem entry path then path else path @ [entry];;
let removepath entry = List.filter (fun x -> x <> entry);;
let _ = Arg.parse
[ "-a", Arg.String (fun s -> path := s; action := Add),
"add given path to the dynamic loading standard path";
"-r", Arg.String (fun s -> path := s; action := Remove),
"remove the given path from the dynamic loading standard path" ]
(fun _ -> print_endline help_string; exit 1)
help_string;;
let (pfile, newpfile) = (open_in pathfile, open_out tmppathfile) in
let oldpath = input_list pfile in
let newpath = match !action with
| Add -> addpath !path oldpath
| Remove -> removepath !path oldpath
| NoAct -> failwith "Huh? What I have to do? (try --help)"
in
output_list newpfile newpath;
close_in pfile;
close_out newpfile;
Sys.rename tmppathfile pathfile
Attachment:
pgpByAlT0EJWu.pgp
Description: PGP signature