[m-dev.] diff: dir__make_path_name

Zoltan Somogyi zs at cs.mu.OZ.AU
Mon Aug 21 10:51:23 AEST 2000


library/dir.m:
	Add a function for constructing a pathname from a directory name
	and a filename within that directory.

Zoltan.

cvs diff: Diffing .
Index: dir.m
===================================================================
RCS file: /home/mercury1/repository/mercury/library/dir.m,v
retrieving revision 1.11
diff -u -r1.11 dir.m
--- dir.m	1999/07/07 15:19:37	1.11
+++ dir.m	2000/08/21 00:50:44
@@ -34,10 +34,14 @@
 :- pred dir__basename(string::in, string::out) is det.
 :- pred dir__dirname(string::in, string::out) is det.
 
+	% Given a directory name and a filename, return the pathname of that
+	% file in that directory.
+:- func dir__make_path_name(string, string) = string.
+
 %-----------------------------------------------------------------------------%
 
 :- implementation.
-:- import_module int, require, string.
+:- import_module int, list, require, string.
 
 dir__directory_separator('/').
 
@@ -47,7 +51,8 @@
 	string__length(FileName, Length),
 	dir__split_name_2(FileName, Length, DirName, BaseName).
 
-:- pred dir__split_name_2(string::in, int::in, string::out, string::out) is det.
+:- pred dir__split_name_2(string::in, int::in, string::out, string::out)
+	is det.
 
 dir__split_name_2(FileName, N, DirName, BaseName) :-
 	N1 is N - 1,
@@ -76,6 +81,16 @@
 dir__dirname(FileName, DirName) :-
 	dir__split_name(FileName, DirName, _).
 
+dir__make_path_name(DirName, FileName) = PathName :-
+		% Using string__append_list has a fixed overhead of six
+		% words, whereas using two string__appends back to back
+		% would have a memory overhead proportional to the size
+		% of the string copied twice. We prefer the former because
+		% it is bounded.
+	string__append_list([DirName,
+		string__char_to_string(dir__directory_separator),
+		FileName], PathName).
+
 %-----------------------------------------------------------------------------%
 %-----------------------------------------------------------------------------%
 % Ralph Becket <rwab1 at cl.cam.ac.uk> 27/04/99
--------------------------------------------------------------------------
mercury-developers mailing list
Post messages to:       mercury-developers at cs.mu.oz.au
Administrative Queries: owner-mercury-developers at cs.mu.oz.au
Subscriptions:          mercury-developers-request at cs.mu.oz.au
--------------------------------------------------------------------------



More information about the developers mailing list