X-Git-Url: http://matita.cs.unibo.it/gitweb/?a=blobdiff_plain;f=helm%2FDEVEL%2Fpxp%2Fpxp%2Fdoc%2Fmanual%2Fsrc%2Fgetcode.ml;fp=helm%2FDEVEL%2Fpxp%2Fpxp%2Fdoc%2Fmanual%2Fsrc%2Fgetcode.ml;h=4db669036a0b474d31bb2a37750c190628db296f;hb=c03d2c1fdab8d228cb88aaba5ca0f556318bebc5;hp=0000000000000000000000000000000000000000;hpb=758057e85325f94cd88583feb1fdf6b038e35055;p=helm.git diff --git a/helm/DEVEL/pxp/pxp/doc/manual/src/getcode.ml b/helm/DEVEL/pxp/pxp/doc/manual/src/getcode.ml new file mode 100755 index 000000000..4db669036 --- /dev/null +++ b/helm/DEVEL/pxp/pxp/doc/manual/src/getcode.ml @@ -0,0 +1,56 @@ +#! /bin/sh +# (* +exec ocamlfattop "$0" +*) directory ".";; + +open Str;; + +let name_re = regexp "(\\*\\$[ \t]*\\([a-zA-Z0-9.-]*\\)[ \t]*\\*)";; +let subst_re = regexp "[<>&'%]";; + +let begin_entity name = + "\n" +;; + + +let text = ref "" in +let within_entity = ref false in +try + while true do + let line = read_line() in + if string_match name_re line 0 then begin + let name = matched_group 1 line in + if !within_entity then + text := !text ^ "\n" ^ end_entity(); + within_entity := false; + if name <> "-" then begin + text := !text ^ begin_entity name; + within_entity := true + end + end + else + if !within_entity then begin + let line' = + global_substitute subst_re + (fun s -> + let s' = matched_group 0 s in + match s' with + "<" -> "<" + | ">" -> ">" + | "&" -> "&" + | "'" -> "'" + | "%" -> "&percent;" + | _ -> assert false) + line + in + text := !text ^ "\n" ^ line' + end + done; +with End_of_file -> + if !within_entity then + text := !text ^ "\n" ^ end_entity(); + print_string !text +;;