123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127(**************************************************************************)(* *)(* This file is part of Frama-C. *)(* *)(* Copyright (C) 2007-2025 *)(* 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). *)(* *)(**************************************************************************)(** {1 Auxiliary definitions and functions for pretty-printing } *)(** Partially applied format-like function missing a "%a" argument *)typepoly_format_quote_a={pf:'a.(Format.formatter->'a->unit)->'a->unit}(** Partially applied Log.pretty_printer value, missing its entire formatter
(and the arguments) *)typepoly_pretty_printer={ppp:'a.('a,Format.formatter,unit)format->'a}letcompare_tag(v1:'a)(v2:'a)=leto1=Obj.reprv1ando2=Obj.reprv2inmatchObj.is_into1,Obj.is_into2with|true,true->Stdlib.compareo1o2|false,false->Stdlib.compare(Obj.tago1)(Obj.tago2)|true,false->1|false,true->-1letcompf1v11v12f2v21v22=letr=f1v11v12inifr=0thenf2v21v22elser(* -------------------------------------------------------------------------- *)(* --- Misc --- *)(* -------------------------------------------------------------------------- *)type'aconversion_with_warning=[|`Successof'a|`WithWarningof(Format.formatter->unit)*'a]type'aconversion=[|'aconversion_with_warning|`Failureof(Format.formatter->unit)]exceptionFoundofintletutf8_char_lengthc=ifc<0x80then1elsetryletmask=ref0b10000000infori=1to8domask:=!masklor(1lsl(8-i));if(cland!mask)=!maskthenraise(Found(i+1))done;failwith(Format.sprintf"incorrect utf-8 start %d"c)withFoundi->i(*if c < 0b11100000 then 2
else if c < 0b11110000 then 3
else if c < 0b11111000 then 4
else if c < 0b11111100 then 5
else 6
*)exceptionEscape_non_utf8ofstring*int*intletescape_charc=ifc='"'then"\\\""elseChar.escapedcletescape_non_utf8s=lets'=Buffer.create(String.lengths)inletrecauxi=ifi<String.lengthsthenletc=s.[i]inletutf8=utf8_char_length(Char.codec)inifutf8<>1thentryletsub=String.subsiutf8inBuffer.add_strings'sub;aux(i+utf8)with_->raise(Escape_non_utf8(s,i,utf8))else(Buffer.add_strings'(escape_charc);aux(i+1))inaux0;Buffer.contentss'letclear_value_results()=Project.clear~selection:(State_selection.with_dependenciesAnalysis.self)();;;letmthread_h()=Mt_options.MThread.Share.get_file"mthread.h";;letsanitize_filename?(char='_')s=letis_invalidc=matchcwith|'&'|'+'|'['|']'|'.'->true|_->falseinString.map(func->ifis_invalidcthencharelsec)s