aboutsummaryrefslogtreecommitdiffstats
path: root/lib/Responsefile.mll
diff options
context:
space:
mode:
authorBernhard Schommer <bernhardschommer@gmail.com>2016-08-16 10:35:17 +0200
committerBernhard Schommer <bernhardschommer@gmail.com>2016-08-16 10:35:17 +0200
commit5309f16159e4decd81330622dcdd6eb4b25819a1 (patch)
treeb40df6edcd7826e7d83885253508ccf49377479d /lib/Responsefile.mll
parenteb2844b87fa0e176bd65466d7ab7d16666344406 (diff)
downloadcompcert-kvx-5309f16159e4decd81330622dcdd6eb4b25819a1.tar.gz
compcert-kvx-5309f16159e4decd81330622dcdd6eb4b25819a1.zip
Moved quoting functions in Responsefile
Also corrected some typos and corrected exception handling for expandargv. Bug 18308
Diffstat (limited to 'lib/Responsefile.mll')
-rw-r--r--lib/Responsefile.mll27
1 files changed, 25 insertions, 2 deletions
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
}