1 (******************************************************************************)
5 (* Claudio Sacerdoti Coen <sacerdot@cs.unibo.it> *)
8 (* This is the parser that reads the configuration file of helm *)
10 (******************************************************************************)
12 exception MalformedDir of string
14 (* this should be the only hard coded constant *)
18 Sys.getenv "HELM_CONFIGURATION_DIR"
20 Not_found -> "/projects/helm/V7/phd/local/etc/helm"
22 if prefix.[(String.length prefix) - 1] = '/' then
23 raise (MalformedDir prefix) ;
24 prefix ^ "/configuration.xml";;
31 print_endline ("WARNING: " ^ w) ;
32 (raise Warnings : unit)
37 let module Y = Pxp_yacc in
39 let config = {Y.default_config with Y.warner = new warner} in
40 Some (Y.parse_document_entity config (Y.from_file filename) Y.default_spec)
43 prerr_endline ("Warning: configuration file not found, or incorrect: " ^ Pxp_types.string_of_exn e) ;
47 exception Impossible;;
49 let vars = Hashtbl.create 14;;
51 (* resolve <value-of> tags and returns the string values of the variable tags *)
53 let module D = Pxp_document in
56 | he::tl when he#node_type = D.T_element "value-of" ->
57 (match he#attribute "var" with
58 Pxp_types.Value var -> Hashtbl.find vars var
59 | _ -> raise Impossible
61 | he::tl when he#node_type = D.T_data ->
63 | _ -> raise Impossible
66 (* we trust the xml file to be valid because of the validating xml parser *)
68 match xml_document () with
74 match n#node_type with
75 Pxp_document.T_element var ->
76 Hashtbl.add vars var (resolve (n#sub_nodes))
77 | _ -> raise Impossible
82 (* try to read a configuration variable, given its name into the
83 * configuration.xml file and its name into the shell environment.
84 * The shell variable, if present, has precedence over configuration.xml
86 let read_configuration_var_env xml_name env_name =
91 Not_found -> Hashtbl.find vars xml_name
94 Printf.printf "Sorry, cannot find variable `%s', please check your configuration\n" xml_name ;
98 let read_configuration_var xml_name =
100 Hashtbl.find vars xml_name
103 Printf.printf "Sorry, cannot find variable `%s', please check your configuration\n" xml_name ;
107 let tmp_dir = read_configuration_var_env "tmp_dir" "HELM_TMP_DIR";;
108 let getter_url = read_configuration_var_env "getter_url" "HELM_GETTER_URL";;
109 let processor_url = read_configuration_var_env "processor_url" "HELM_PROCESSOR_URL";;
110 let annotations_dir = read_configuration_var_env "annotations_dir" "HELM_ANNOTATIONS_DIR"
111 let annotations_url = read_configuration_var_env "annotations_url" "HELM_ANNOTATIONS_URL"
113 let _ = Hashtbl.clear vars;;