]> matita.cs.unibo.it Git - helm.git/blob - helm/metadata/create2/touch/touch.ml
New procedure to create metadata committed and old procedure removed.
[helm.git] / helm / metadata / create2 / touch / touch.ml
1 (* Copyright (C) 2000, HELM Team.
2  * 
3  * This file is part of HELM, an Hypertextual, Electronic
4  * Library of Mathematics, developed at the Computer Science
5  * Department, University of Bologna, Italy.
6  * 
7  * HELM is free software; you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License
9  * as published by the Free Software Foundation; either version 2
10  * of the License, or (at your option) any later version.
11  * 
12  * HELM is distributed in the hope that it will be useful,
13  * but WITHOUT ANY WARRANTY; without even the implied warranty of
14  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15  * GNU General Public License for more details.
16  *
17  * You should have received a copy of the GNU General Public License
18  * along with HELM; if not, write to the Free Software
19  * Foundation, Inc., 59 Temple Place - Suite 330, Boston,
20  * MA  02111-1307, USA.
21  * 
22  * For details, see the HELM World-Wide-Web page,
23  * http://cs.unibo.it/helm/.
24  *)
25
26 (******************************************************************************)
27 (*                                                                            *)
28 (*                               PROJECT HELM                                 *)
29 (*                                                                            *)
30 (*                Claudio Sacerdoti Coen <sacerdot@cs.unibo.it>               *)
31 (*                                 03/04/2001                                 *)
32 (*                                                                            *)
33 (*                            Missing description                             *)
34 (*                                                                            *)
35 (******************************************************************************)
36
37 let iteri foo =
38  let counter = ref 0 in
39   List.iter (function e -> incr counter ; foo e !counter)
40 ;;
41
42 let pathname_of_uri uristring =
43  "backward" ^
44   Str.replace_first (Str.regexp "^cic:") "" uristring
45 ;;
46
47 let make_dirs dirpath =
48  ignore (Unix.system ("mkdir -p \"" ^ dirpath ^ "\""))
49 ;;
50
51 let touch_file rdf_string_uri =
52  let module U = UriManager in
53   let rdf_uri = U.uri_of_string rdf_string_uri in
54    make_dirs (pathname_of_uri (U.buri_of_uri rdf_uri)) ;
55    ignore (
56     Unix.system
57      ("touch \"" ^ (pathname_of_uri rdf_string_uri) ^ "\"")
58    )
59 ;;
60
61 let get_obj uri =
62  let cicfilename = Getter.getxml uri in
63   let res =
64    match CicParser.term_of_xml cicfilename uri false with
65       (annobj, None) ->
66         Deannotate.deannotate_obj annobj
67     | _ -> assert false
68   in
69    Unix.unlink cicfilename ;
70    res
71 ;;
72
73 let touch_obj string_uri =
74  let module U = UriManager in
75  let module C = Cic in
76   function
77      Some (C.InductiveDefinition (itys,_,_)) ->
78       iteri
79        (fun (_,_,_,cons) n ->
80          let sn = string_of_int n in
81           touch_file
82            (string_uri ^ "," ^ sn) ;
83           iteri
84            (fun (_,_,_) m ->
85              let sm = string_of_int m in
86               touch_file
87                (string_uri ^ "," ^ sn ^ "," ^ sm)
88            ) cons
89        ) itys
90    | Some _ -> assert false
91    | None ->
92       touch_file string_uri
93 ;;
94
95 let touch string_uri =
96  let module S = String in
97  let module U = UriManager in
98   print_endline ("Now touching metadata file for " ^ string_uri) ;
99   flush stdout ;
100   let uri = U.uri_of_string string_uri in
101   let obj =
102    if S.sub string_uri (S.length string_uri - 3) 3 = "ind" then
103     Some (get_obj uri)
104    else
105     None
106   in
107    touch_obj string_uri obj
108 ;;
109
110 let _ =
111  let usage_msg = "usage: touch[.opt] URI" in
112  let uri = ref "" in
113   Arg.parse []
114    (fun x ->
115      if x = "" then
116       begin
117        prerr_string "No URI provided.\n" ;
118        Arg.usage [] usage_msg ;
119        exit (-1)
120       end
121      else if !uri = "" then
122       uri := x
123      else
124       begin
125        prerr_string "More than two arguments provided.\n" ;
126        Arg.usage [] usage_msg ;
127        exit (-1)
128       end
129    ) usage_msg ;
130    if !uri = "" then
131     begin
132      prerr_string "No URI provided.\n" ;
133      Arg.usage [] usage_msg ;
134      exit (-1)
135     end ;
136    touch !uri
137 ;;