X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fpxp%2Fpxp%2Ftools%2Finsert_variant;fp=helm%2FDEVEL%2Fpxp%2Fpxp%2Ftools%2Finsert_variant;h=cb592bb8699634b2225720f6ce0b2943c552ac1b;hb=c03d2c1fdab8d228cb88aaba5ca0f556318bebc5;hp=0000000000000000000000000000000000000000;hpb=758057e85325f94cd88583feb1fdf6b038e35055;p=helm.git diff --git a/helm/DEVEL/pxp/pxp/tools/insert_variant b/helm/DEVEL/pxp/pxp/tools/insert_variant new file mode 100755 index 000000000..cb592bb86 --- /dev/null +++ b/helm/DEVEL/pxp/pxp/tools/insert_variant @@ -0,0 +1,105 @@ +#! /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), + " 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. + * + * + *)