]> matita.cs.unibo.it Git - helm.git/commitdiff
added table_creator (comman line frontend to SqlStatements)
authorEnrico Tassi <enrico.tassi@inria.fr>
Tue, 3 May 2005 13:39:34 +0000 (13:39 +0000)
committerEnrico Tassi <enrico.tassi@inria.fr>
Tue, 3 May 2005 13:39:34 +0000 (13:39 +0000)
helm/ocaml/metadata/table_creator/.depend [new file with mode: 0644]
helm/ocaml/metadata/table_creator/Makefile [new file with mode: 0644]
helm/ocaml/metadata/table_creator/table_creator.ml [new file with mode: 0644]

diff --git a/helm/ocaml/metadata/table_creator/.depend b/helm/ocaml/metadata/table_creator/.depend
new file mode 100644 (file)
index 0000000..1cf113d
--- /dev/null
@@ -0,0 +1,4 @@
+sql.cmo: sql.cmi 
+sql.cmx: sql.cmi 
+table_creator.cmo: sql.cmi 
+table_creator.cmx: sql.cmx 
diff --git a/helm/ocaml/metadata/table_creator/Makefile b/helm/ocaml/metadata/table_creator/Makefile
new file mode 100644 (file)
index 0000000..8b08e6d
--- /dev/null
@@ -0,0 +1,20 @@
+REQUIRES = mysql helm-metadata
+
+INTERFACE_FILES = 
+IMPLEMENTATION_FILES = $(INTERFACE_FILES:%.mli=%.ml) 
+EXTRA_OBJECTS_TO_INSTALL =
+EXTRA_OBJECTS_TO_CLEAN =table_creator table_creator.opt
+
+all: table_creator
+opt: table_creator.opt
+
+table_creator: table_creator.ml
+       $(OCAMLFIND) ocamlc \
+               -thread -package mysql,helm-metadata -linkpkg -o $@ $<
+
+table_creator.opt: table_creator.ml
+       $(OCAMLFIND) ocamlopt \
+               -thread -package mysql,helm-metadata -linkpkg -o $@ $<
+               
+include ../../Makefile.common
+include .depend
diff --git a/helm/ocaml/metadata/table_creator/table_creator.ml b/helm/ocaml/metadata/table_creator/table_creator.ml
new file mode 100644 (file)
index 0000000..7cd3b35
--- /dev/null
@@ -0,0 +1,45 @@
+
+let map =
+  (MetadataTypes.library_obj_tbl,`RefObj) ::
+  (MetadataTypes.library_sort_tbl,`RefSort) ::
+  (MetadataTypes.library_rel_tbl,`RefRel) ::
+  (MetadataTypes.library_name_tbl,`ObjectName) ::
+(*  (MetadataTypes.library_???_tbl,`Owners) :: *)
+  (MetadataTypes.library_count_tbl,`Count) :: []
+
+let usage argv_o =
+  prerr_string "\nusage:";
+  prerr_string ("\t" ^ argv_o ^ " [-index] tablename[=rename]\n\n");
+  prerr_string "known tables:";
+  List.iter (fun (n,_) -> prerr_string (" " ^ n)) map;
+  prerr_endline "\n"
+
+let eq_RE = Str.regexp "="
+  
+let parse_args l =
+  List.map (fun s -> 
+    let parts = Str.split eq_RE s in
+    let len = List.length parts in
+    assert (len = 1 || len = 2);
+    if len = 1 then (s,s) else (List.nth parts 0, List.nth parts 1)) 
+  l
+  
+let main () =
+  let len = Array.length Sys.argv in
+  if len < 2 then 
+    begin
+    usage Sys.argv.(0);
+    exit 1
+    end
+  else
+    begin
+      let from, index = if Sys.argv.(1) = "-index" then 2,true else 1,false in
+      let todo = Array.to_list (Array.sub Sys.argv from (len - from)) in
+      let todo = parse_args todo in
+      let todo = List.map (fun (x,name) -> name, (List.assoc x map)) todo in
+      print_endline (SqlStatements.create_tables todo);
+      if index then print_endline (SqlStatements.create_indexes todo)
+    end
+
+let _ = main ()
+