[m-rev.] for review: quote windows paths with spaces

Ian MacLarty maclarty at cs.mu.OZ.AU
Sun Nov 20 18:12:35 AEDT 2005


For review by anyone.

Estimated hours taken: 3
Branches: main and 0.12

compiler/compile_target_code.m:
	Quote include directories passed to gcc, in case they contain
	spaces.

compiler/options.m:
	Change the way arguments are quoted on Windows.  Using `\' to escape
	whitespace doesn't work because `\' is a directory separator on
	Windows, instead enclose the argument in quotation marks if it
	contains whitespace.

library/io.m:
	Fix a comment that had the wrong predicate name.

Index: compiler/compile_target_code.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/compile_target_code.m,v
retrieving revision 1.75
diff -u -r1.75 compile_target_code.m
--- compiler/compile_target_code.m	17 Nov 2005 15:57:04 -0000	1.75
+++ compiler/compile_target_code.m	19 Nov 2005 09:32:51 -0000
@@ -431,7 +431,7 @@
     globals__io_lookup_accumulating_option(c_include_directory,
         C_Incl_Dirs, !IO),
     InclOpt = string__append_list(list__condense(list__map(
-        (func(C_INCL) = ["-I", C_INCL, " "]), C_Incl_Dirs))),
+        (func(C_INCL) = ["-I", quote_arg(C_INCL), " "] ), C_Incl_Dirs))),
     globals__io_lookup_bool_option(split_c_files, Split_C_Files, !IO),
     (
         Split_C_Files = yes,
Index: compiler/options.m
===================================================================
RCS file: /home/mercury1/repository/mercury/compiler/options.m,v
retrieving revision 1.477
diff -u -r1.477 options.m
--- compiler/options.m	17 Nov 2005 15:57:26 -0000	1.477
+++ compiler/options.m	19 Nov 2005 09:32:52 -0000
@@ -2630,13 +2630,10 @@
     % XXX Instead of using dir__use_windows_paths, this should really
     % test whether we are using a Unix or Windows shell.
     ( dir__use_windows_paths ->
-        ArgList = quote_arg_windows(string__to_char_list(Arg0)),
-        (
-            ArgList = [],
-            Arg = """"""
+        ( ( string_contains_whitespace(Arg0) ; Arg0 = "" ) ->
+            Arg = """" ++ Arg0 ++ """"
         ;
-            ArgList = [_ | _],
-            Arg = string__from_char_list(ArgList)
+            Arg = Arg0
         )
     ;
         ArgList = quote_arg_unix(string__to_char_list(Arg0)),
@@ -2660,30 +2657,15 @@
         )
     ).
 
-:- func quote_arg_windows(list(char)) = list(char).
+:- pred string_contains_whitespace(string::in) is semidet.
 
-quote_arg_windows([]) = [].
-quote_arg_windows([Char | Chars0]) = Chars :-
-    Chars1 = quote_arg_windows(Chars0),
-    ( quote_char_windows(Char) ->
-        % We want whitespace characters within an argument to not be
-        % treated as whitespace when splitting the command line into words.
-        % Newlines and tabs within a word don't really make sense, so just
-        % convert them to spaces.
-        QuoteChar = ( char__is_whitespace(Char) -> ' ' ; Char ),
-        Chars = [('\\'), QuoteChar | Chars1]
-    ;
-        Chars = [Char | Chars1]
+string_contains_whitespace(Str) :-
+    Chars = string.to_char_list(Str),
+    some [Char] (
+        list.member(Char, Chars),
+        char.is_whitespace(Char)
     ).
 
-:- pred quote_char_windows(char::in) is semidet.
-
-quote_char_windows(' ').
-quote_char_windows('\n').
-quote_char_windows('\t').
-quote_char_windows('"').
-quote_char_windows('%').
-
 :- func quote_arg_unix(list(char)) = list(char).
 
 quote_arg_unix([]) = [].
Index: library/io.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/io.m,v
retrieving revision 1.339
diff -u -r1.339 io.m
--- library/io.m	15 Nov 2005 04:59:22 -0000	1.339
+++ library/io.m	19 Nov 2005 09:30:41 -0000
@@ -1138,8 +1138,8 @@
     %
 :- pred io__make_temp(string::out, io::di, io::uo) is det.
 
-    % io__mktemp(Dir, Prefix, Name, IO0, IO) creates an empty file whose name
-    % is different to the name of any existing file. The file will reside
+    % io__make_temp(Dir, Prefix, Name, IO0, IO) creates an empty file whose
+    % name is different to the name of any existing file. The file will reside
     % in the directory specified by `Dir' and will have a prefix using up to
     % the first 5 characters of `Prefix'. Name is bound to the name of the
     % file. It is the responsibility of the program to delete the file
--------------------------------------------------------------------------
mercury-reviews mailing list
post:  mercury-reviews at cs.mu.oz.au
administrative address: owner-mercury-reviews at cs.mu.oz.au
unsubscribe: Address: mercury-reviews-request at cs.mu.oz.au Message: unsubscribe
subscribe:   Address: mercury-reviews-request at cs.mu.oz.au Message: subscribe
--------------------------------------------------------------------------



More information about the reviews mailing list