7 * ----------------------------------------------------------------------
11 let get_arg variant insert_line =
12 (* returns the argument of an "#insert" line *)
14 for i = 8 to String.length insert_line - 1 do
15 match insert_line.[i] with
18 (* replace '*' with 'variant' *)
21 s := !s ^ String.make 1 c
27 let edit_file variant name =
28 let basename = Filename.chop_suffix name ".src" in
29 let mllname = basename ^ "_" ^ variant ^ ".mll" in
30 let chin = open_in name in
31 let chout = open_out mllname in
32 output_string chout "(* File generated by insert_variant; DO NOT EDIT! *)\n";
35 let line = input_line chin in
36 (* We do not have Str here. *)
37 if String.length line >= 8 & String.sub line 0 8 = "#insert " then begin
38 let insname = get_arg variant line in
39 (* Copy the file 'insname' to chout *)
40 let chcopy = open_in insname in
41 let n = in_channel_length chcopy in
42 let s = String.create n in
43 really_input chcopy s 0 n;
45 output_string chout s;
48 output_string chout line;
49 output_char chout '\n';
61 let variant = ref "" in
63 Arg.current := 0; (* Because of a OCaml-3.00 bug *)
65 [ "-variant", Arg.String (fun s -> variant := s),
66 "<name> Set the variant (character encoding)";
68 (fun s -> files := !files @ [s])
69 "insert_variant [ options ] file.src ...
71 Reads the files, replaces the #insert lines by the referred files, and
72 writes the file file_variant.mll.
74 The #insert lines include the specified file into the source. The
75 asterisk (*) is replaced by the name of the variant.
81 failwith "No variant specified!";
84 (fun name -> edit_file !variant name)
91 (* ======================================================================
95 * Revision 1.1 2000/11/17 09:57:35 lpadovan
98 * Revision 1.2 2000/05/20 21:14:33 gerd
99 * Workaround for an OCaml 3.00 bug.
101 * Revision 1.1 2000/05/20 20:30:15 gerd