Commit d7af0c9e authored by POTTIER Francois's avatar POTTIER Francois

A more complex (safer) magic string.

parent cc179b1f
......@@ -8,12 +8,13 @@ open Cmly_api
exception Error of string
let read (ic : in_channel) : grammar =
(* .cmly file format: version string ++ grammar *)
(* .cmly file format: CMLY ++ version string ++ grammar *)
let magic = "CMLY" ^ Version.version in
try
let m = really_input_string ic (String.length Version.version) in
if m <> Version.version then
raise (Error (Printf.sprintf "Invalid magic number in .cmly file.\n\
Expecting %S, but got %S." Version.version m))
let m = really_input_string ic (String.length magic) in
if m <> magic then
raise (Error (Printf.sprintf "Invalid magic string in .cmly file.\n\
Expecting %S, but got %S." magic m))
else
(input_value ic : grammar)
with
......
......@@ -149,8 +149,9 @@ let encode () : grammar =
}
let write oc t =
(* .cmly file format: version string ++ grammar *)
output_string oc Version.version;
(* .cmly file format: CMLY ++ version string ++ grammar *)
let magic = "CMLY" ^ Version.version in
output_string oc magic;
output_value oc (t : grammar)
let write filename =
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment