diff options
author | Bernhard Schommer <bernhardschommer@gmail.com> | 2016-08-16 10:35:17 +0200 |
---|---|---|
committer | Bernhard Schommer <bernhardschommer@gmail.com> | 2016-08-16 10:35:17 +0200 |
commit | 5309f16159e4decd81330622dcdd6eb4b25819a1 (patch) | |
tree | b40df6edcd7826e7d83885253508ccf49377479d /lib | |
parent | eb2844b87fa0e176bd65466d7ab7d16666344406 (diff) | |
download | compcert-5309f16159e4decd81330622dcdd6eb4b25819a1.tar.gz compcert-5309f16159e4decd81330622dcdd6eb4b25819a1.zip |
Moved quoting functions in Responsefile
Also corrected some typos and corrected exception handling for
expandargv.
Bug 18308
Diffstat (limited to 'lib')
-rw-r--r-- | lib/Responsefile.mli | 11 | ||||
-rw-r--r-- | lib/Responsefile.mll | 27 |
2 files changed, 36 insertions, 2 deletions
diff --git a/lib/Responsefile.mli b/lib/Responsefile.mli index ec82c32e..ada5a15d 100644 --- a/lib/Responsefile.mli +++ b/lib/Responsefile.mli @@ -18,3 +18,14 @@ val expandargv: string array -> string array (** Expand responsefile arguments contained in the array and return the full set of arguments. *) + +exception Error of string + (** Raised by [expandargv] in case of an error *) + +val gnu_quote : string -> string + (** [gnu_quote arg] returns [arg] quoted compatible with the gnu tool chain + quoting conventions. *) + +val diab_quote : string -> string + (** [diab_quote arg] returns [arg] quoted compatible with the diab tool chain + quoting conventions. *) diff --git a/lib/Responsefile.mll b/lib/Responsefile.mll index bb29fd75..35a2dbdb 100644 --- a/lib/Responsefile.mll +++ b/lib/Responsefile.mll @@ -15,8 +15,6 @@ (* *********************************************************************) -(* Parsing response files with various quoting styles *) - { (* To accumulate the characters in a word or quoted string *) let buf = Buffer.create 32 @@ -94,4 +92,29 @@ let expandargv argv = let args = Array.to_list argv in Array.of_list (List.rev (expand_args [] args [])) +(* This function reimplements quoting of writeargv from libiberty *) +let gnu_quote arg = + let len = String.length arg in + let buf = Buffer.create len in + String.iter (fun c -> begin match c with + | ' ' | '\t' | '\r' | '\n' | '\\' | '\'' | '"' -> + Buffer.add_char buf '\\' + | _ -> () end; + Buffer.add_char buf c) arg; + Buffer.contents buf + +let re_quote = Str.regexp ".*[ \t\n\r\"]" + +let diab_quote arg = + let buf = Buffer.create ((String.length arg) + 8) in + let doublequote = Str.string_match re_quote arg 0 in + if doublequote then begin + Buffer.add_char buf '"'; + String.iter (fun c -> + if c = '"' then Buffer.add_char buf '\\'; + Buffer.add_char buf c) arg; + if doublequote then Buffer.add_char buf '"'; + Buffer.contents buf + end else + arg } |