From 0f599670735f6ad7b8a5ddffc51a6fea8cacafbc Mon Sep 17 00:00:00 2001 From: =?utf8?q?Am=C3=A9lia=20Coutard-Sander?= Date: Sat, 4 Jan 2025 23:09:29 +0100 Subject: [PATCH] Ajout du nom de l'automate aux fichiers de sauvegarde --- bin/modes.ml | 21 +++++++++++++++++---- 1 file changed, 17 insertions(+), 4 deletions(-) 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 ())))) -- 2.46.0