gconfig.ml 14.5 KB
Newer Older
MARCHE Claude's avatar
MARCHE Claude committed
1 2 3 4

open Format
open Why

MARCHE Claude's avatar
MARCHE Claude committed
5 6 7 8 9
type prover_data =
    { prover_id : string;
      prover_name : string;
      prover_version : string;
      command : string;
10 11
      driver_name : string;
      driver : Driver.driver;
12
      mutable editor : string;
MARCHE Claude's avatar
MARCHE Claude committed
13 14
    }

MARCHE Claude's avatar
MARCHE Claude committed
15 16 17 18
type t = 
    { mutable window_width : int;
      mutable window_height : int;
      mutable tree_width : int;
19
      mutable task_height : int;
20
      mutable time_limit : int;
MARCHE Claude's avatar
MARCHE Claude committed
21
      mutable verbose : int;
22
      mutable max_running_processes : int;
MARCHE Claude's avatar
MARCHE Claude committed
23
      mutable provers : prover_data list;
24
      mutable default_editor : string;
MARCHE Claude's avatar
MARCHE Claude committed
25 26 27 28 29 30
    }

let default = 
  { window_width = 1024;
    window_height = 768;
    tree_width = 512;
31
    task_height = 384;
32
    time_limit = 2;
MARCHE Claude's avatar
MARCHE Claude committed
33
    verbose = 0;
34
    max_running_processes = 2;
MARCHE Claude's avatar
MARCHE Claude committed
35
    provers = [];
36
    default_editor = "";
MARCHE Claude's avatar
MARCHE Claude committed
37 38
  }

39
let conf_file = Filename.concat (Rc.get_home_dir ()) ".why.conf"
MARCHE Claude's avatar
MARCHE Claude committed
40

MARCHE Claude's avatar
MARCHE Claude committed
41
let save_prover fmt p =
42 43
  fprintf fmt "[prover %s]@\n" p.prover_id;
  fprintf fmt "name = \"%s\"@\n" p.prover_name;
MARCHE Claude's avatar
MARCHE Claude committed
44
  fprintf fmt "version = \"%s\"@\n" p.prover_version;
45 46
  fprintf fmt "command = \"%s\"@\n" p.command;
  fprintf fmt "driver = \"%s\"@\n" p.driver_name;  
MARCHE Claude's avatar
MARCHE Claude committed
47
  if p.editor <> "" then fprintf fmt "editor = \"%s\"@\n" p.editor;  
MARCHE Claude's avatar
MARCHE Claude committed
48 49
  fprintf fmt "@."

MARCHE Claude's avatar
MARCHE Claude committed
50 51 52 53 54 55 56
let save_config config =
  let ch = open_out conf_file in
  let fmt = formatter_of_out_channel ch in
  fprintf fmt "[main]@\n";
  fprintf fmt "width = %d@\n" config.window_width;
  fprintf fmt "height = %d@\n" config.window_height;
  fprintf fmt "tree_width = %d@\n" config.tree_width;
57
  fprintf fmt "task_height = %d@\n" config.task_height;
58
  fprintf fmt "time_limit = %d@\n" config.time_limit;
MARCHE Claude's avatar
MARCHE Claude committed
59
  fprintf fmt "verbose = %d@\n" config.verbose;
60
  fprintf fmt "max_processes = %d@\n" config.max_running_processes;
61
  fprintf fmt "default_editor = \"%s\"@\n" config.default_editor;  
MARCHE Claude's avatar
MARCHE Claude committed
62
  fprintf fmt "@.";
MARCHE Claude's avatar
MARCHE Claude committed
63
  List.iter (save_prover fmt) config.provers; 
MARCHE Claude's avatar
MARCHE Claude committed
64 65 66 67 68 69 70
  close_out ch

let load_main c (key, value) = 
  match key with
    | "width" -> c.window_width <- Rc.int value
    | "height" -> c.window_height <- Rc.int value
    | "tree_width" -> c.tree_width <- Rc.int value
71
    | "task_height" -> c.task_height <- Rc.int value
72
    | "time_limit" -> c.time_limit <- Rc.int value
MARCHE Claude's avatar
MARCHE Claude committed
73
    | "verbose" -> c.verbose <- Rc.int value
74
    | "max_processes" -> c.max_running_processes <- Rc.int value
75
    | "default_editor" -> c.default_editor <- Rc.string value
MARCHE Claude's avatar
MARCHE Claude committed
76 77
    | s -> 
        eprintf "Warning: ignore unknown key [%s] in whyide config file@." s
MARCHE Claude's avatar
MARCHE Claude committed
78 79 80



81
let get_prover_data env id name ver c d e = 
82
  let f = Filename.concat Whyconf.datadir d in
83
  try
84
    let dr = Driver.load_driver env f in
85 86 87 88 89 90
    { prover_id = id ;
      prover_name = name;
      prover_version = ver;
      command = c;
      driver_name = d;
      driver = dr; 
91
      editor = e;
92
    }
93 94 95 96 97 98 99 100 101 102 103 104
  with 
    | Loc.Located(p,e) ->
        eprintf "Syntax error %a in driver %s for prover %s (%s).@\nprover disabled@."
          Loc.report_position p f name (Printexc.to_string e);
        Printexc.print_backtrace stdout;
        raise Not_found

    | e ->
        eprintf "Failed to load driver %s for prover %s (%s).@\nprover disabled@."
          f name (Printexc.to_string e);
        Printexc.print_backtrace stdout;
        raise Not_found
MARCHE Claude's avatar
MARCHE Claude committed
105

106 107
let load_prover env id l =
  let name = ref "?" in
MARCHE Claude's avatar
MARCHE Claude committed
108
  let v = ref "?" in
109 110
  let c = ref "?" in
  let d = ref "?" in
111
  let e = ref "" in
MARCHE Claude's avatar
MARCHE Claude committed
112 113 114
  List.iter
    (fun (key, value) -> 
	match key with
115
	  | "name" -> name := Rc.string value
MARCHE Claude's avatar
MARCHE Claude committed
116
	  | "version" -> v := Rc.string value
117 118
          | "command" -> c := Rc.string value
          | "driver" -> d := Rc.string value
119
          | "editor" -> e := Rc.string value
MARCHE Claude's avatar
MARCHE Claude committed
120 121 122
	  | s -> 
            eprintf "Warning: ignore unknown key [%s] in prover data of whyide config file@." s)
    l;
123
  get_prover_data env id !name !v !c !d !e
MARCHE Claude's avatar
MARCHE Claude committed
124
        
125
let load env c (key, al) = 
MARCHE Claude's avatar
MARCHE Claude committed
126
  match key with
MARCHE Claude's avatar
MARCHE Claude committed
127
    | "main" :: _ -> List.iter (load_main c) al
128 129
    | "prover" :: id :: _ -> 
        c.provers <- load_prover env id al :: c.provers
MARCHE Claude's avatar
MARCHE Claude committed
130 131 132 133
    | s :: _ -> 
        eprintf "Warning: ignored unknown section [%s] in whyide config file@." s
    | [] -> assert false
        
134
let read_config env =
MARCHE Claude's avatar
MARCHE Claude committed
135 136 137
  try
    let rc = Rc.from_file conf_file in
    let c = default in
138
    List.iter (load env c) rc;
MARCHE Claude's avatar
MARCHE Claude committed
139
    c.provers <- List.rev c.provers;
MARCHE Claude's avatar
MARCHE Claude committed
140 141 142 143 144 145 146 147 148 149
    c
  with
    | Failure "lexing" -> 
        eprintf "Warning: syntax error in whyide config file@.";
        default
    | Not_found ->
        eprintf "Warning: no whyide config file, using default values@.";
        default
    

MARCHE Claude's avatar
MARCHE Claude committed
150 151 152 153 154 155 156
(*

  boomy icons

*)

let image ?size f =
157
  let n = Filename.concat Whyconf.datadir (Filename.concat "images" (f^".png"))
MARCHE Claude's avatar
MARCHE Claude committed
158 159 160 161 162 163 164 165 166 167 168 169 170 171 172 173 174 175 176 177 178 179 180 181 182 183 184 185 186 187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 203 204 205 206 207 208 209 210 211 212 213 214 215 216 217 218 219 220 221 222 223 224 225 226 227 228 229 230 231 232 233 234 235 236 237 238 239 240 241 242 243 244 245 246 247 248 249 250 251 252 253 254 255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272
  in
  match size with
    | None ->
        GdkPixbuf.from_file n
    | Some s ->
        GdkPixbuf.from_file_at_size ~width:s ~height:s n

let iconname_default = "pause32"
let iconname_scheduled = "pause32"
let iconname_running = "play32"
let iconname_valid = "accept32"
let iconname_unknown = "help32"
let iconname_invalid = "delete32"
let iconname_timeout = "clock32"
let iconname_failure = "bug32"
let iconname_yes = "accept32"
let iconname_no = "delete32"
let iconname_directory = "folder32"
let iconname_file = "file32"
let iconname_prover = "wizard32"
let iconname_transf = "cutb32"

let image_default = ref (image ~size:20 iconname_default)
let image_scheduled = ref !image_default
let image_running = ref !image_default
let image_valid = ref !image_default
let image_unknown = ref !image_default
let image_invalid = ref !image_default
let image_timeout = ref !image_default
let image_failure = ref !image_default
let image_yes = ref !image_default
let image_no = ref !image_default
let image_directory = ref !image_default
let image_file = ref !image_default
let image_prover = ref !image_default
let image_transf = ref !image_default

let resize_images size =
  image_default := image ~size iconname_default;
  image_scheduled := image ~size iconname_scheduled;
  image_running := image ~size iconname_running;
  image_valid := image ~size iconname_valid;
  image_unknown := image ~size iconname_unknown;
  image_invalid := image ~size iconname_invalid;
  image_timeout := image ~size iconname_timeout;
  image_failure := image ~size iconname_failure;
  image_yes := image ~size iconname_yes;
  image_no := image ~size iconname_no;
  image_directory := image ~size iconname_directory;
  image_file := image ~size iconname_file;
  image_prover := image ~size iconname_prover;
  image_transf := image ~size iconname_transf;
  ()

let () = resize_images 20



let show_legend_window () =
  let dialog = GWindow.dialog ~title:"Why: legend of icons" () in      
  let vbox = dialog#vbox in
  let text = GText.view ~packing:vbox#add () in
  let b = text#buffer in
  let i s = b#insert ~iter:b#end_iter s in
  let ib i = b#insert_pixbuf ~iter:b#end_iter ~pixbuf:!i in
  i "== icons in the tree view on the left ==\n";
  i "\n";
  ib image_directory;
  i "A theory, containing a set of goals\n";
  ib image_file;
  i "A goal\n";
  ib image_prover;
  i "An external prover\n";
  ib image_transf;
  i "A split transformation\n";
  i "\n";
  i "== icons in the satatus column\n";
  i "\n";
  ib image_scheduled;
  i "external proof scheduled by not started yet\n";
  ib image_running;
  i "external proof is running\n";
  ib image_valid;
  i "goal is proved/theory is fully verified\n";
  ib image_timeout;
  i "external prover reached the time limit\n";
  ib image_unknown;
  i "external prover answer was not conclusive\n";
  ib image_failure;
  i "external prover call failed\n";
  i "\n";
  dialog#add_button "Close" `CLOSE ;
  let ( _ : GWindow.Buttons.about) = dialog#run () in
  dialog#destroy ()


let show_about_window () =
  let about_dialog = 
    GWindow.about_dialog 
      ~name:"Why" 
      ~authors:["Francois Bobot";
                "Jean-Christophe Filliatre";
                "Johannes Kanig";
                "Claude Marche";
                "Andrei Paskevich"
               ]
      ~copyright:"Copyright 2010"
      ~license:"Gnu Lesser General Public License"
      ~website:"http://why.lri.fr"
      ~website_label:"Click here for the web site"
      ~version:"3.0 alpha"
      ()
  in      
  let ( _ : GWindow.Buttons.about) = about_dialog#run () in
  about_dialog#destroy ()
MARCHE Claude's avatar
MARCHE Claude committed
273

274
let preferences c =
MARCHE Claude's avatar
MARCHE Claude committed
275
  let dialog = GWindow.dialog ~title:"Why: preferences" () in      
MARCHE Claude's avatar
MARCHE Claude committed
276 277
  let vbox = dialog#vbox in
  let notebook = GPack.notebook ~packing:vbox#add () in
278
  (** page 1 **)
MARCHE Claude's avatar
MARCHE Claude committed
279
  let label1 = GMisc.label ~text:"General" () in
MARCHE Claude's avatar
MARCHE Claude committed
280 281 282 283
  let page1 =
    GPack.vbox ~homogeneous:false ~packing:
      (fun w -> ignore(notebook#append_page ~tab_label:label1#coerce w)) ()
  in 
284
  (* debug mode ? *)
MARCHE Claude's avatar
MARCHE Claude committed
285
  let debugmode = 
MARCHE Claude's avatar
MARCHE Claude committed
286
    GButton.check_button ~label:"debug" ~packing:page1#add ()
MARCHE Claude's avatar
MARCHE Claude committed
287 288 289 290 291
      ~active:(c.verbose > 0)
  in
  let (_ : GtkSignal.id) = 
    debugmode#connect#toggled ~callback:
      (fun () -> c.verbose <- 1 - c.verbose)
MARCHE Claude's avatar
MARCHE Claude committed
292
  in
293 294 295 296 297 298 299 300 301 302 303
  (* timelimit ? *)
  let hb = GPack.hbox ~homogeneous:false ~packing:page1#add () in
  let _ = GMisc.label ~text:"Time limit" ~packing:hb#add () in
  let timelimit_spin = GEdit.spin_button ~digits:0 ~packing:hb#add () in
  timelimit_spin#adjustment#set_bounds ~lower:2. ~upper:300. ~step_incr:1. ();
  timelimit_spin#adjustment#set_value (float_of_int c.time_limit);
  let (_ : GtkSignal.id) = 
    timelimit_spin#connect#value_changed ~callback:
      (fun () -> c.time_limit <- timelimit_spin#value_as_int)
  in
  (* nb of processes ? *)
MARCHE Claude's avatar
MARCHE Claude committed
304 305 306 307
  let hb = GPack.hbox ~homogeneous:false ~packing:page1#add () in
  let _ = GMisc.label ~text:"Nb of processes" ~packing:hb#add () in
  let nb_processes_spin = GEdit.spin_button ~digits:0 ~packing:hb#add () in
  nb_processes_spin#adjustment#set_bounds ~lower:1. ~upper:16. ~step_incr:1. ();
308
  nb_processes_spin#adjustment#set_value (float_of_int c.max_running_processes);
MARCHE Claude's avatar
MARCHE Claude committed
309 310
  let (_ : GtkSignal.id) = 
    nb_processes_spin#connect#value_changed ~callback:
311
      (fun () -> c.max_running_processes <- nb_processes_spin#value_as_int)
MARCHE Claude's avatar
MARCHE Claude committed
312
  in
313
  (** page 2 **)
MARCHE Claude's avatar
MARCHE Claude committed
314 315
  let label2 = GMisc.label ~text:"Provers" () in
  let _page2 = GMisc.label ~text:"This page should display detected provers" 
MARCHE Claude's avatar
MARCHE Claude committed
316 317
    ~packing:(fun w -> ignore(notebook#append_page ~tab_label:label2#coerce w)) () 
  in
MARCHE Claude's avatar
MARCHE Claude committed
318 319
  dialog#add_button "Close" `CLOSE ;
  let ( _ : GWindow.Buttons.about) = dialog#run () in
MARCHE Claude's avatar
MARCHE Claude committed
320 321
  eprintf "saving IDE config file@.";
  save_config c;
MARCHE Claude's avatar
MARCHE Claude committed
322
  dialog#destroy ()
323 324 325 326 327 328 329 330 331 332 333 334





(* auto-detection of provers *)

type prover_kind = ATP | ITP
type prover_autodetection_data =
    { kind : prover_kind;
      prover_id : string;
      mutable prover_name : string;
335
      mutable execs : string list;
336 337 338 339
      mutable version_switch : string;
      mutable version_regexp : string;
      mutable versions_ok : string list;
      mutable versions_old : string list;
340 341
      mutable command : string;
      mutable driver : string;
MARCHE Claude's avatar
MARCHE Claude committed
342
      mutable editor : string;
343 344 345 346 347 348
    }

let default k id =
  { kind = k;
    prover_id = id;
    prover_name = "";
349
    execs = [];
350 351 352 353
    version_switch = "";
    version_regexp = "";
    versions_ok = [];
    versions_old = [];
354
    command = "";
MARCHE Claude's avatar
MARCHE Claude committed
355 356
    driver = "";
    editor = "";
357 358 359 360 361
    }

let load_prover d (key, value) = 
  match key with
    | "name" -> d.prover_name <- Rc.string value
362
    | "exec" -> d.execs <- Rc.string value :: d.execs
363 364 365 366
    | "version_switch" -> d.version_switch <- Rc.string value
    | "version_regexp" -> d.version_regexp <- Rc.string value
    | "version_ok" -> d.versions_ok <- Rc.string value :: d.versions_ok
    | "version_old" -> d.versions_old <- Rc.string value :: d.versions_old
367 368
    | "command" -> d.command <- Rc.string value 
    | "driver" -> d.driver <- Rc.string value
MARCHE Claude's avatar
MARCHE Claude committed
369
    | "editor" -> d.editor <- Rc.string value
370 371 372 373 374 375 376 377 378 379 380 381 382 383 384 385 386 387
    | s -> 
        eprintf "unknown key [%s] in autodetection data@." s;
        exit 1
        
let load acc (key,l) =
  match key with
    | ["ATP" ; id] -> 
        let d = default ATP id in
        List.iter (load_prover d) l;
        d :: acc
    | ["ITP" ; id] -> 
        let d = default ITP id in
        List.iter (load_prover d) l;
        d :: acc
    | s :: _ ->
        eprintf "unknown section [%s] in auto detection data@." s;
        exit 1
    | [] -> assert false
MARCHE Claude's avatar
MARCHE Claude committed
388
  
389 390 391 392 393 394 395 396 397 398 399 400 401
let read_auto_detection_data () =
  try
    let rc = Rc.from_file "prover-detection-data.conf" in
    List.fold_left load [] rc
  with
    | Failure "lexing" -> 
        eprintf "Syntax error in prover-detection-data.conf@.";
        exit 2
    | Not_found ->
        eprintf "prover-detection-data.conf not found@.";
        exit 2
    

MARCHE Claude's avatar
MARCHE Claude committed
402
let provers_found = ref 0
403

MARCHE Claude's avatar
MARCHE Claude committed
404 405 406
let prover_tips_info = ref false


407 408 409 410 411 412 413 414 415
let make_command exec com =
  let cmd_regexp = Str.regexp "%\\(.\\)" in
  let replace s = match Str.matched_group 1 s with
    | "e" -> exec
    | c -> "%"^c
  in
  Str.global_substitute cmd_regexp replace com

let detect_prover env acc data =
MARCHE Claude's avatar
MARCHE Claude committed
416 417 418 419 420 421 422 423 424 425 426 427 428 429 430 431 432 433 434 435 436 437 438 439 440 441 442 443 444 445 446 447 448 449 450 451 452
  List.fold_left
    (fun acc com ->
	let out = Filename.temp_file "out" "" in
        let cmd = com ^ " " ^ data.version_switch in
	let c = cmd ^ " > " ^ out in
	let ret = Sys.command c in
	if ret <> 0 then
	  begin
	    eprintf "command '%s' failed@." cmd;
	    acc
	  end
	else
	  let s = 
            try 
              let ch = open_in out in
              let s = ref (input_line ch) in
              while !s = "" do s := input_line ch done;
              close_in ch;
	      Sys.remove out;
              !s              
            with Not_found | End_of_file  -> ""
          in
	  let re = Str.regexp data.version_regexp in
	  if Str.string_match re s 0 then            
	    let nam = data.prover_name in
	    let ver = Str.matched_group 1 s in
            if List.mem ver data.versions_ok then 
	      eprintf "Found prover %s version %s, OK.@." nam ver
            else
              begin
                prover_tips_info := true;
                if List.mem ver data.versions_old then 
                  eprintf "Warning: prover %s version %s is quite old, please consider upgrading to a newer version.@." nam ver	    
                else
                  eprintf "Warning: prover %s version %s is not known to be supported, use it at your own risk!@." nam ver
              end;
            incr provers_found;
453 454
            let c = make_command com data.command in
	    get_prover_data env data.prover_id data.prover_name ver 
MARCHE Claude's avatar
MARCHE Claude committed
455
              c data.driver data.editor :: acc
MARCHE Claude's avatar
MARCHE Claude committed
456 457 458 459 460 461 462 463
	  else 
	    begin
              prover_tips_info := true;
	      eprintf "Warning: found prover %s but name/version not recognized by regexp `%s'@." data.prover_name data.version_regexp;
	      eprintf "Answer was `%s'@." s;
	      acc
	    end)
    acc
464
    data.execs
MARCHE Claude's avatar
MARCHE Claude committed
465 466


467
let run_auto_detection env gconfig =
MARCHE Claude's avatar
MARCHE Claude committed
468
  let l = read_auto_detection_data () in
469 470
  let detect = List.fold_left (detect_prover env) [] l in
  eprintf "%d provers detected.@." (List.length detect);
MARCHE Claude's avatar
MARCHE Claude committed
471 472
  gconfig.provers <- detect
    
473

MARCHE Claude's avatar
MARCHE Claude committed
474 475 476 477 478
(*
Local Variables: 
compile-command: "unset LANG; make -C ../.. bin/whyide.opt"
End: 
*)