+++ /dev/null
-#! /bin/sh
-# (*
-exec ocaml "$0" "$@"
-*) directory ".";;
-
-(* $Id$
- * ----------------------------------------------------------------------
- *
- *)
-
-let get_arg variant insert_line =
- (* returns the argument of an "#insert" line *)
- let s = ref "" in
- for i = 8 to String.length insert_line - 1 do
- match insert_line.[i] with
- ' ' -> ()
- | '*' ->
- (* replace '*' with 'variant' *)
- s := !s ^ variant
- | c ->
- s := !s ^ String.make 1 c
- done;
- !s
-;;
-
-
-let edit_file variant name =
- let basename = Filename.chop_suffix name ".src" in
- let mllname = basename ^ "_" ^ variant ^ ".mll" in
- let chin = open_in name in
- let chout = open_out mllname in
- output_string chout "(* File generated by insert_variant; DO NOT EDIT! *)\n";
- begin try
- while true do
- let line = input_line chin in
- (* We do not have Str here. *)
- if String.length line >= 8 & String.sub line 0 8 = "#insert " then begin
- let insname = get_arg variant line in
- (* Copy the file 'insname' to chout *)
- let chcopy = open_in insname in
- let n = in_channel_length chcopy in
- let s = String.create n in
- really_input chcopy s 0 n;
- close_in chcopy;
- output_string chout s;
- end
- else begin
- output_string chout line;
- output_char chout '\n';
- end
- done
- with
- End_of_file -> ()
- end;
- close_in chin;
- close_out chout
-;;
-
-
-let main() =
- let variant = ref "" in
- let files = ref [] in
- Arg.current := 0; (* Because of a OCaml-3.00 bug *)
- Arg.parse
- [ "-variant", Arg.String (fun s -> variant := s),
- "<name> Set the variant (character encoding)";
- ]
- (fun s -> files := !files @ [s])
- "insert_variant [ options ] file.src ...
-
-Reads the files, replaces the #insert lines by the referred files, and
-writes the file file_variant.mll.
-
-The #insert lines include the specified file into the source. The
-asterisk (*) is replaced by the name of the variant.
-
-Options:
-";
-
- if !variant = "" then
- failwith "No variant specified!";
-
- List.iter
- (fun name -> edit_file !variant name)
- !files
-;;
-
-
-main();;
-
-(* ======================================================================
- * History:
- *
- * $Log$
- * Revision 1.1 2000/11/17 09:57:35 lpadovan
- * Initial revision
- *
- * Revision 1.2 2000/05/20 21:14:33 gerd
- * Workaround for an OCaml 3.00 bug.
- *
- * Revision 1.1 2000/05/20 20:30:15 gerd
- * Initial revision.
- *
- *
- *)