vala r1082 - in trunk: . compiler vapi



Author: juergbi
Date: Sun Mar  2 10:55:25 2008
New Revision: 1082
URL: http://svn.gnome.org/viewvc/vala?rev=1082&view=rev

Log:
2008-03-02  Juerg Billeter  <j bitron ch>

	* vapi/glib-2.0.vapi: add dir separator bindings,
	  fix g_regex_escape_string binding

	* compiler/valacompiler.vala: port realpath to Windows,
	  fixes bug 515210


Modified:
   trunk/ChangeLog
   trunk/compiler/valacompiler.vala
   trunk/vapi/glib-2.0.vapi

Modified: trunk/compiler/valacompiler.vala
==============================================================================
--- trunk/compiler/valacompiler.vala	(original)
+++ trunk/compiler/valacompiler.vala	Sun Mar  2 10:55:25 2008
@@ -281,29 +281,43 @@
 		return quit ();
 	}
 
+	private static bool ends_with_dir_separator (string s) {
+		return Path.is_dir_separator (s.offset (s.len () - 1).get_char ());
+	}
+
 	/* ported from glibc */
-	private string! realpath (string! name) {
+	private static string! realpath (string! name) {
 		string rpath;
 
-		if (name.get_char () != '/') {
+		// start of path component
+		weak string start;
+		// end of path component
+		weak string end;
+
+		if (!Path.is_absolute (name)) {
 			// relative path
 			rpath = Environment.get_current_dir ();
+
+			start = end = name;
 		} else {
-			rpath = "/";
+			// set start after root
+			start = end = Path.skip_root (name);
+
+			// extract root
+			rpath = name.substring (0, name.pointer_to_offset (start));
 		}
 
-		weak string start;
-		weak string end;
+		long root_len = rpath.pointer_to_offset (Path.skip_root (rpath));
 
-		for (start = end = name; start.get_char () != 0; start = end) {
+		for (; start.get_char () != 0; start = end) {
 			// skip sequence of multiple path-separators
-			while (start.get_char () == '/') {
+			while (Path.is_dir_separator (start.get_char ())) {
 				start = start.next_char ();
 			}
 
 			// find end of path component
 			long len = 0;
-			for (end = start; end.get_char () != 0 && end.get_char () != '/'; end = end.next_char ()) {
+			for (end = start; end.get_char () != 0 && !Path.is_dir_separator (end.get_char ()); end = end.next_char ()) {
 				len++;
 			}
 
@@ -313,24 +327,37 @@
 				// do nothing
 			} else if (len == 2 && start.has_prefix ("..")) {
 				// back up to previous component, ignore if at root already
-				if (rpath.len () > 1) {
+				if (rpath.len () > root_len) {
 					do {
 						rpath = rpath.substring (0, rpath.len () - 1);
-					} while (!rpath.has_suffix ("/"));
+					} while (!ends_with_dir_separator (rpath));
 				}
 			} else {
-				if (!rpath.has_suffix ("/")) {
-					rpath += "/";
+				if (!ends_with_dir_separator (rpath)) {
+					rpath += Path.DIR_SEPARATOR_S;
 				}
 
 				rpath += start.substring (0, len);
 			}
 		}
 
-		if (rpath.len () > 1 && rpath.has_suffix ("/")) {
+		if (rpath.len () > root_len && ends_with_dir_separator (rpath)) {
 			rpath = rpath.substring (0, rpath.len () - 1);
 		}
 
+		if (Path.DIR_SEPARATOR != '/') {
+			// don't use backslashes internally,
+			// to avoid problems in #include directives
+			try {
+				var regex = new Regex (Regex.escape_string (Path.DIR_SEPARATOR_S));
+				string new_rpath = regex.replace_literal (rpath, -1, 0, "/");
+				rpath = new_rpath;
+			} catch (RegexError e) {
+				// should never happen
+				assert_not_reached ();
+			}
+		}
+
 		return rpath;
 	}
 

Modified: trunk/vapi/glib-2.0.vapi
==============================================================================
--- trunk/vapi/glib-2.0.vapi	(original)
+++ trunk/vapi/glib-2.0.vapi	Sun Mar  2 10:55:25 2008
@@ -1689,6 +1689,13 @@
 		public static string get_dirname (string file_name);
 		[CCode (cname = "g_build_filename")]
 		public static string build_filename (string first_element, ...);
+
+		[CCode (cname = "G_DIR_SEPARATOR")]
+		public const char DIR_SEPARATOR;
+		[CCode (cname = "G_DIR_SEPARATOR_S")]
+		public const string DIR_SEPARATOR_S;
+		[CCode (cname = "G_IS_DIR_SEPARATOR")]
+		public static bool is_dir_separator (unichar c);
 	}
 
 	public static class Bit {
@@ -2223,7 +2230,7 @@
 		public int get_max_backref ();
 		public int get_capture_count ();
 		public int get_string_number (string! name);
-		public string! escape_string (string! str, int length = -1);
+		public static string! escape_string (string! str, int length = -1);
 		public static bool match_simple (string! pattern, string! str, RegexCompileFlags compile_options = 0, RegexMatchFlags match_options = 0);
 		public bool match (string! str, RegexMatchFlags match_options = 0, out MatchInfo match_info = null);
 		public bool match_full (string! str, long string_len = -1, int start_position = 0, RegexMatchFlags match_options = 0, out MatchInfo match_info = null) throws RegexError;



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]