Better error handling for file size specs

This commit is contained in:
John Whitington 2024-02-14 21:27:04 +00:00
parent 501f83a71a
commit 88ffc089e7
1 changed files with 4 additions and 1 deletions

View File

@ -1137,7 +1137,10 @@ let displaydoctitle b =
_ -> failwith "DisplayDocTitle: must use true or false" _ -> failwith "DisplayDocTitle: must use true or false"
let read_file_size s = let read_file_size s =
let read_int s = int_of_string (implode (rev s)) in let read_int s' =
try int_of_string (implode (rev s')) with
_ -> error (Printf.sprintf "Could not read file size specification %s" s)
in
match rev (explode (String.uppercase_ascii s)) with match rev (explode (String.uppercase_ascii s)) with
| 'B'::'I'::'G'::s -> 1024 * 1024 * 1024 * read_int s | 'B'::'I'::'G'::s -> 1024 * 1024 * 1024 * read_int s
| 'B'::'G'::s -> 1000 * 1000 * 1000 * read_int s | 'B'::'G'::s -> 1000 * 1000 * 1000 * read_int s