From: Amélia Coutard-Sander Date: Sat, 4 Jan 2025 22:09:29 +0000 (+0100) Subject: Ajout du nom de l'automate aux fichiers de sauvegarde X-Git-Url: https://git.ameliathe1st.gay/?a=commitdiff_plain;h=0f599670735f6ad7b8a5ddffc51a6fea8cacafbc;p=cells.git Ajout du nom de l'automate aux fichiers de sauvegarde --- diff --git a/bin/modes.ml b/bin/modes.ml index a36dda5..f5f7c29 100644 --- a/bin/modes.ml +++ b/bin/modes.ml @@ -148,14 +148,27 @@ module rec Command : (Mode with type initer = string) = struct Printf.fprintf stderr "Automate inconnu: `%s' !\n%!" auto; (estate, Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())))) | ["write"; f] -> - (try Out_channel.with_open_text f (Automata.serialise (module M) st.board) + (try + Out_channel.with_open_text f (fun f -> + Printf.fprintf f "%s\n" M.name; + Automata.serialise (module M) st.board f) with Sys_error _ -> Printf.fprintf stderr "Failed to write file `%s' !\n%!" f); (EditorState (m, st), Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ()))) | ["read"; f] -> ( try - ( EditorState - (m, { st with board = In_channel.with_open_text f (Automata.deserialise (module M)) }), - Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())) ) + In_channel.with_open_text f (fun f -> + let name = Option.get (In_channel.input_line f) in + let auto = List.find (fun m -> get_name m = name) Automata.automata in + let module M = (val auto) in + ( EditorState + ( (module M), + { + board = Automata.deserialise (module M) f; + pos = st.pos; + current = M.default; + size = st.size; + } ), + Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ())) )) with Sys_error _ -> Printf.fprintf stderr "Failed to write file `%s' !\n%!" f; (estate, Either.right (ModeAux.ModeAndState ((module Normal), Normal.initial ()))))