SF.net SVN: geany: [1456] trunk
eht16 at users.sourceforge.net
eht16 at xxxxx
Mon Apr 16 15:58:36 UTC 2007
Revision: 1456
http://svn.sourceforge.net/geany/?rev=1456&view=rev
Author: eht16
Date: 2007-04-16 08:58:34 -0700 (Mon, 16 Apr 2007)
Log Message:
-----------
Use g_stat() instead of stat() to prevent file read errors on Win32.
Prevent unnecessary filename encoding conversions on Win32.
Modified Paths:
--------------
trunk/ChangeLog
trunk/src/build.c
trunk/src/dialogs.c
trunk/src/document.c
trunk/src/utils.c
Modified: trunk/ChangeLog
===================================================================
--- trunk/ChangeLog 2007-04-16 11:10:22 UTC (rev 1455)
+++ trunk/ChangeLog 2007-04-16 15:58:34 UTC (rev 1456)
@@ -1,3 +1,10 @@
+2007-04-16 Enrico Tröger <enrico.troeger at uvena.de>
+
+ * src/build.c, src/dialogs.c, src/document.c, src/utils.c:
+ Use g_stat() instead of stat() to prevent file read errors on Win32.
+ Prevent unnecessary filename encoding conversions on Win32.
+
+
2007-04-16 Nick Treleaven <nick.treleaven at btinternet.com>
* src/filetypes.c:
Modified: trunk/src/build.c
===================================================================
--- trunk/src/build.c 2007-04-16 11:10:22 UTC (rev 1455)
+++ trunk/src/build.c 2007-04-16 15:58:34 UTC (rev 1456)
@@ -33,6 +33,7 @@
#include <sys/stat.h>
#include <unistd.h>
#include <errno.h>
+#include <glib/gstdio.h>
#ifdef G_OS_UNIX
# include <sys/types.h>
@@ -153,7 +154,7 @@
locale_filename = utils_get_locale_from_utf8(view_file);
// check wether view_file exists
- if (stat(locale_filename, &st) != 0)
+ if (g_stat(locale_filename, &st) != 0)
{
msgwin_status_add(_("Failed to view %s (make sure it is already compiled)"), view_file);
utils_free_pointers(executable, view_file, locale_filename, NULL);
@@ -354,9 +355,9 @@
object_file = g_strdup_printf("%s.o", executable);
// check wether object file (file.o) exists
- if (stat(object_file, &st) == 0)
+ if (g_stat(object_file, &st) == 0)
{ // check wether src is newer than object file
- if (stat(locale_filename, &st2) == 0)
+ if (g_stat(locale_filename, &st2) == 0)
{
if (st2.st_mtime > st.st_mtime)
{
@@ -546,7 +547,7 @@
}
// check whether executable exists
- if (stat(check_executable, &st) != 0)
+ if (g_stat(check_executable, &st) != 0)
{
utf8_check_executable = utils_get_utf8_from_locale(check_executable);
msgwin_status_add(_("Failed to execute %s (make sure it is already built)"),
Modified: trunk/src/dialogs.c
===================================================================
--- trunk/src/dialogs.c 2007-04-16 11:10:22 UTC (rev 1455)
+++ trunk/src/dialogs.c 2007-04-16 15:58:34 UTC (rev 1456)
@@ -39,6 +39,7 @@
#ifdef HAVE_SYS_TYPES_H
# include <sys/types.h>
#endif
+#include <glib/gstdio.h>
#include "dialogs.h"
@@ -674,8 +675,13 @@
#if defined(HAVE_SYS_STAT_H) && defined(TIME_WITH_SYS_TIME) && defined(HAVE_SYS_TYPES_H)
+#ifdef G_OS_WIN32
+ // don't try to convert the filename on Windows, it should be already in UTF8
+ locale_filename = g_strdup(doc_list[idx].file_name);
+#else
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
- if (stat(locale_filename, &st) == 0)
+#endif
+ if (g_stat(locale_filename, &st) == 0)
{
// first copy the returned string and the trim it, to not modify the static glibc string
// g_strchomp() is used to remove trailing EOL chars, which are there for whatever reason
Modified: trunk/src/document.c
===================================================================
--- trunk/src/document.c 2007-04-16 11:10:22 UTC (rev 1455)
+++ trunk/src/document.c 2007-04-16 15:58:34 UTC (rev 1456)
@@ -48,6 +48,8 @@
#include <ctype.h>
#include <stdlib.h>
+#include <glib/gstdio.h>
+
#include "document.h"
#include "support.h"
#include "sciwrappers.h"
@@ -609,19 +611,16 @@
filedata->bom = FALSE;
filedata->readonly = FALSE;
- if (stat(locale_filename, &st) != 0)
+ if (g_stat(locale_filename, &st) != 0)
{
msgwin_status_add(_("Could not open file %s (%s)"), utf8_filename, g_strerror(errno));
+ dialogs_show_msgbox(0, "%s %s", utf8_filename, locale_filename);
return FALSE;
}
filedata->mtime = st.st_mtime;
-#ifdef G_OS_WIN32
- if (! g_file_get_contents(utf8_filename, &filedata->data, NULL, &err))
-#else
if (! g_file_get_contents(locale_filename, &filedata->data, NULL, &err))
-#endif
{
msgwin_status_add(err->message);
g_error_free(err);
@@ -742,7 +741,11 @@
// try to get the UTF-8 equivalent for the filename, fallback to filename if error
locale_filename = g_strdup(filename);
+#ifdef G_OS_WIN32 // on Win32 we only use locale_filename because it is already UTF8. I hope
+ utf8_filename = g_strdup(locale_filename);
+#else
utf8_filename = utils_get_utf8_from_locale(locale_filename);
+#endif
// if file is already open, switch to it and go
idx = document_find_by_filename(utf8_filename, FALSE);
@@ -913,9 +916,13 @@
g_return_val_if_fail(DOC_IDX_VALID(idx), FALSE);
+#ifdef G_OS_WIN32
+ // don't try to convert the filename on Windows, it should be already in UTF8
+ locale_filename = g_strdup(doc_list[idx].file_name);
+#else
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
-
- if (stat(locale_filename, &st) != 0)
+#endif
+ if (g_stat(locale_filename, &st) != 0)
{
msgwin_status_add(_("Could not open file %s (%s)"), doc_list[idx].file_name,
g_strerror(errno));
Modified: trunk/src/utils.c
===================================================================
--- trunk/src/utils.c 2007-04-16 11:10:22 UTC (rev 1455)
+++ trunk/src/utils.c 2007-04-16 15:58:34 UTC (rev 1456)
@@ -332,8 +332,13 @@
if (! force && doc_list[idx].last_check > (t - GEANY_CHECK_FILE_DELAY)) return FALSE;
+#ifdef G_OS_WIN32
+ // don't try to convert the filename on Windows, it should be already in UTF8
+ locale_filename = g_strdup(doc_list[idx].file_name);
+#else
locale_filename = utils_get_locale_from_utf8(doc_list[idx].file_name);
- if (stat(locale_filename, &st) != 0)
+#endif
+ if (g_stat(locale_filename, &st) != 0)
{
// TODO: warn user file on disk is missing
}
@@ -1432,17 +1437,29 @@
gchar *utils_get_locale_from_utf8(const gchar *utf8_text)
{
+#ifdef G_OS_WIN32
+ // just do nothing on Windows platforms, this ifdef is just to prevent unwanted conversions
+ // which would result in wrongly converted strings
+ return g_strdup(utf8_text);
+#else
gchar *locale_text = g_locale_from_utf8(utf8_text, -1, NULL, NULL, NULL);
if (locale_text == NULL) locale_text = g_strdup(utf8_text);
return locale_text;
+#endif
}
gchar *utils_get_utf8_from_locale(const gchar *locale_text)
{
+#ifdef G_OS_WIN32
+ // just do nothing on Windows platforms, this ifdef is just to prevent unwanted conversions
+ // which would result in wrongly converted strings
+ return g_strdup(locale_text);
+#else
gchar *utf8_text = g_locale_to_utf8(locale_text, -1, NULL, NULL, NULL);
if (utf8_text == NULL) utf8_text = g_strdup(locale_text);
return utf8_text;
+#endif
}
This was sent by the SourceForge.net collaborative development platform, the world's largest Open Source development site.
More information about the Commits
mailing list