diff --git a/.gitignore b/.gitignore index ebba842a7fe2aaac5df6d5b5400e80dd4d74b097..cb2bdbdfb9740ffd81853e6294b477ee066c4b99 100644 --- a/.gitignore +++ b/.gitignore @@ -61,8 +61,6 @@ autom4te.cache /devel_tools/fc-time /devel_tools/fc-memuse /bin/ocamldep_transitive_closure -/bin/isutf8 -/bin/isutf8.exe #share /share/Makefile.config diff --git a/bin/isutf8.ml b/bin/isutf8.ml deleted file mode 100644 index 0e775f13502710afea395fa9aadb2686ca72b40d..0000000000000000000000000000000000000000 --- a/bin/isutf8.ml +++ /dev/null @@ -1,97 +0,0 @@ -(**************************************************************************) -(* *) -(* This file is part of Frama-C. *) -(* *) -(* Copyright (C) 2007-2022 *) -(* CEA (Commissariat à l'énergie atomique et aux énergies *) -(* alternatives) *) -(* *) -(* you can redistribute it and/or modify it under the terms of the GNU *) -(* Lesser General Public License as published by the Free Software *) -(* Foundation, version 2.1. *) -(* *) -(* It is distributed in the hope that it will be useful, *) -(* but WITHOUT ANY WARRANTY; without even the implied warranty of *) -(* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the *) -(* GNU Lesser General Public License for more details. *) -(* *) -(* See the GNU Lesser General Public License version 2.1 *) -(* for more details (enclosed in the file licenses/LGPLv2.1). *) -(* *) -(**************************************************************************) - -module StringSet = Set.Make(String) - -exception False - -let is_valid_utf8 filename = - let buf = Bytes.create 1024 in - try - let ic = open_in_bin filename in - let extra = ref 0 in - try - while true do - let n_bytes_read = input ic buf 0 1024 in - if n_bytes_read = 0 then raise End_of_file; - for i = 0 to n_bytes_read - 1 do - let c = Bytes.get_uint8 buf i in - (*Format.printf "extra: %d, read byte: %d (0x%x, char %c)@." - !extra c c (Char.chr c);*) - if !extra > 0 then begin - decr extra; - if c lsr 6 <> 2 then raise False - end - else - if c > 127 then begin - if c lsr 5 = 6 then extra := 1 - else if c lsr 4 = 14 then extra := 2 - else if c lsr 3 = 30 then extra := 3 - else raise False - end; - done; - done; - close_in ic; - !extra = 0 - with - | End_of_file -> - close_in ic; - !extra = 0 - | False -> - close_in ic; - false - with - | Sys_error msg -> - (* possibly a non-existing file (e.g. with spaces); ignoring *) - Format.printf "isutf8: cannot open, ignoring file: %s (%s)@." - filename msg; - true - -(* usage: first argument is a file name containing a list of files - (one per line) to be checked; the remaining arguments are filenames - to be ignored during checking. *) -let () = - if Array.length Sys.argv < 2 then begin - Format.printf "usage: %s file_list.txt [ignore1 ignore2 ...]@." Sys.argv.(0); - exit 0 - end; - let errors = ref 0 in - let file_list_ic = open_in Sys.argv.(1) in - let to_ignore = StringSet.of_list (List.tl (Array.to_list Sys.argv)) in - begin - try - while true; do - let filename = input_line file_list_ic in - if not (StringSet.mem filename to_ignore) - && not (is_valid_utf8 filename) then begin - incr errors; - Format.printf "error: invalid UTF-8 in file: %s@." filename - end - done - with End_of_file -> - close_in file_list_ic - end; - if !errors > 0 then begin - Format.printf "Found %d file(s) with errors.@." !errors; - exit 1 - end else - exit 0