Skip to content

Commit

Permalink
Add debug versions of path_to_utf8() and path_from_utf8() which allow…
Browse files Browse the repository at this point in the history
…s to report the caller file and line, this is enabled with --enable-debug-flags (and developer mode too).
  • Loading branch information
Laurent Monin committed Mar 6, 2009
1 parent 7b8e46a commit 4da2979
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
2 changes: 1 addition & 1 deletion configure.in
Original file line number Diff line number Diff line change
Expand Up @@ -73,7 +73,7 @@ then
CXXFLAGS="${CXXFLAGS} -Wall"
CFLAGS="${CFLAGS} -Wstrict-prototypes -Wall"
fi
__COMMONFLAGS="-g -O0 -Wextra -Wunused-value -Wunused-variable -Wunused-function -Wunused-label -Wcomment -Wmissing-braces -Wparentheses -Wreturn-type -Wswitch -Wstrict-aliasing -Wno-unused-parameter -Wformat -Wformat-security"
__COMMONFLAGS="-g -O0 -Wextra -Wunused-value -Wunused-variable -Wunused-function -Wunused-label -Wcomment -Wmissing-braces -Wparentheses -Wreturn-type -Wswitch -Wstrict-aliasing -Wno-unused-parameter -Wformat -Wformat-security -DGQ_DEBUG_PATH_UTF8=1"
CXXFLAGS="${CXXFLAGS} ${__COMMONFLAGS}"
CFLAGS="${CFLAGS} ${__COMMONFLAGS} -Wimplicit-int -Werror-implicit-function-declaration"
__IS_DEBUG_FLAGS=yes
Expand Down
16 changes: 16 additions & 0 deletions src/ui_fileops.c
Original file line number Diff line number Diff line change
Expand Up @@ -127,7 +127,11 @@ static void encoding_dialog(const gchar *path)
g_string_free(string, TRUE);
}

#if GQ_DEBUG_PATH_UTF8
gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line)
#else
gchar *path_to_utf8(const gchar *path)
#endif
{
gchar *utf8;
GError *error = NULL;
Expand All @@ -137,7 +141,11 @@ gchar *path_to_utf8(const gchar *path)
utf8 = g_filename_to_utf8(path, -1, NULL, NULL, &error);
if (error)
{
#if GQ_DEBUG_PATH_UTF8
log_printf("%s:%d: Unable to convert filename to UTF-8:\n%s\n%s\n", file, line, path, error->message);
#else
log_printf("Unable to convert filename to UTF-8:\n%s\n%s\n", path, error->message);
#endif
g_error_free(error);
encoding_dialog(path);
}
Expand All @@ -150,7 +158,11 @@ gchar *path_to_utf8(const gchar *path)
return utf8;
}

#if GQ_DEBUG_PATH_UTF8
gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line)
#else
gchar *path_from_utf8(const gchar *utf8)
#endif
{
gchar *path;
GError *error = NULL;
Expand All @@ -160,7 +172,11 @@ gchar *path_from_utf8(const gchar *utf8)
path = g_filename_from_utf8(utf8, -1, NULL, NULL, &error);
if (error)
{
#if GQ_DEBUG_PATH_UTF8
log_printf("%s:%d: Unable to convert filename to locale from UTF-8:\n%s\n%s\n", file, line, utf8, error->message);
#else
log_printf("Unable to convert filename to locale from UTF-8:\n%s\n%s\n", utf8, error->message);
#endif
g_error_free(error);
}
if (!path)
Expand Down
9 changes: 8 additions & 1 deletion src/ui_fileops.h
Original file line number Diff line number Diff line change
Expand Up @@ -31,8 +31,15 @@ void print_term(const gchar *text_utf8);
g_free(msg); \
} while (0)

#if GQ_DEBUG_PATH_UTF8
#define path_to_utf8(path) path_to_utf8_debug(path, __FILE__, __LINE__)
#define path_from_utf8(utf8) path_from_utf8_debug(utf8, __FILE__, __LINE__)
gchar *path_to_utf8_debug(const gchar *path, const gchar *file, gint line);
gchar *path_from_utf8_debug(const gchar *utf8, const gchar *file, gint line);
#else
gchar *path_to_utf8(const gchar *path);
gchar *path_from_utf8(const gchar *path);
gchar *path_from_utf8(const gchar *utf8);
#endif

const gchar *xdg_data_home_get(void);
const gchar *xdg_config_home_get(void);
Expand Down

0 comments on commit 4da2979

Please sign in to comment.