diff options
-rw-r--r-- | e-util/ChangeLog | 23 | ||||
-rw-r--r-- | e-util/e-mktemp.c | 3 | ||||
-rw-r--r-- | e-util/e-plugin.c | 2 | ||||
-rw-r--r-- | e-util/e-util.c | 186 | ||||
-rw-r--r-- | e-util/e-util.h | 14 |
5 files changed, 28 insertions, 200 deletions
diff --git a/e-util/ChangeLog b/e-util/ChangeLog index 73b26ece84..8d01621562 100644 --- a/e-util/ChangeLog +++ b/e-util/ChangeLog @@ -1,3 +1,26 @@ +2006-01-10 Simon Zheng <simon.zheng@sun.com> + + * e-mktemp.c (get_dir): + * e-plugin.c: + * e-util.[ch] (e_create_directory): + (e_sort): + Delete e_mkdir_hier(), and use e_util_mkdir_hier() + instead of it. + + Delete e_strstrcasea(), and use e_util_strstrcase() + instead of it. + + Delete e_strftime(), use the copy in evolution-data-server/ + libedataserver/e-data-server-util.c instead of it. + + Delete e_filename_make_safe(), and use the copy in + evolution-data-server/libedataserver/e-data-server-util.c + instead of it. + + Detelte e_utf8_strftime(), and use the copy in + evolution-data-server/libedataserver/e-data-server-util.c + instead of it. + 2006-01-06 Simon Zheng <simon.zheng@sun.com> * e-account.[ch], e-account-list.[ch]: removed. diff --git a/e-util/e-mktemp.c b/e-util/e-mktemp.c index 9a65e0daa2..dbd163dfdc 100644 --- a/e-util/e-mktemp.c +++ b/e-util/e-mktemp.c @@ -36,6 +36,7 @@ #include <stdio.h> #include <time.h> +#include <libedataserver/e-data-server-util.h> #include "e-util.h" #include "e-mktemp.h" @@ -110,7 +111,7 @@ get_dir (gboolean make) #ifdef TEMP_HOME path = g_string_new (g_get_home_dir()); g_string_append_printf(path, "/.evolution/cache/tmp"); - if (make && e_mkdir_hier(path->str, 0777) == -1) { + if (make && e_util_mkdir_hier(path->str, 0777) == -1) { g_string_free(path, TRUE); path = NULL; } diff --git a/e-util/e-plugin.c b/e-util/e-plugin.c index 762ab51afe..d1911abbea 100644 --- a/e-util/e-plugin.c +++ b/e-util/e-plugin.c @@ -26,7 +26,7 @@ #include <gconf/gconf-client.h> #include <libedataserver/e-msgport.h> -#include <libedataserver/e-util.h> +#include <libedataserver/e-data-server-util.h> #include <libedataserver/e-xml-utils.h> #include "e-plugin.h" diff --git a/e-util/e-util.c b/e-util/e-util.c index b2efe75f95..d364a06ec9 100644 --- a/e-util/e-util.c +++ b/e-util/e-util.c @@ -44,6 +44,7 @@ #include <windows.h> #endif +#include <libedataserver/e-data-server-util.h> #include "e-i18n.h" #include "e-util.h" #include "e-util-private.h" @@ -265,59 +266,6 @@ e_write_file_mkstemp(char *filename, const char *data) return 0; } -/** - * e_mkdir_hier: - * @path: a directory path - * @mode: a mode, as for mkdir(2) - * - * This creates the named directory with the given @mode, creating - * any necessary intermediate directories (with the same @mode). - * - * Return value: 0 on success, -1 on error, in which case errno will - * be set as for mkdir(2). - **/ -int -e_mkdir_hier(const char *path, mode_t mode) -{ - char *copy, *p; - - if (g_path_is_absolute (path)) { - p = copy = g_strdup (path); - } else { - gchar *current_dir = g_get_current_dir(); - p = copy = g_build_filename (current_dir, path, NULL); - g_free (current_dir); - } - - p = (char *)g_path_skip_root (p); - do { - char *p1 = strchr (p, '/'); -#ifdef G_OS_WIN32 - { - char *p2 = strchr (p, '\\'); - if (p1 == NULL || - (p2 != NULL && p2 < p1)) - p1 = p2; - } -#endif - p = p1; - if (p) - *p = '\0'; - if (!g_file_test (copy, G_FILE_TEST_IS_DIR)) { - if (g_mkdir (copy, mode) == -1) { - g_free (copy); - return -1; - } - } - if (p) { - *p++ = '/'; - } - } while (p); - - g_free (copy); - return 0; -} - #if 0 char * e_read_uri(const char *uri) @@ -418,72 +366,6 @@ e_strsplit (const gchar *string, return str_array; } -gchar * -e_strstrcase (const gchar *haystack, const gchar *needle) -{ - /* find the needle in the haystack neglecting case */ - const gchar *ptr; - guint len; - - g_return_val_if_fail (haystack != NULL, NULL); - g_return_val_if_fail (needle != NULL, NULL); - - len = strlen(needle); - if (len > strlen(haystack)) - return NULL; - - if (len == 0) - return (gchar *) haystack; - - for (ptr = haystack; *(ptr + len - 1) != '\0'; ptr++) - if (!g_ascii_strncasecmp (ptr, needle, len)) - return (gchar *) ptr; - - return NULL; -} - -/* This only makes a filename safe for usage as a filename. It still may have shell meta-characters in it. */ - -/* This code is rather misguided and mostly pointless, but can't be - * changed because of backward compatibility, I guess. - * - * It replaces some perfectly safe characters like '%' with an - * underscore. (Recall that on Unix, the only bytes not allowed in a - * file name component are '\0' and '/'.) On the other hand, the UTF-8 - * for a printable non-ASCII Unicode character (that thus consists of - * several very nonprintable non-ASCII bytes) is let through as - * such. But those bytes are of course also allowed in filenames, so - * it doesn't matter as such... - */ -void -e_filename_make_safe (gchar *string) -{ - gchar *p, *ts; - gunichar c; -#ifdef G_OS_WIN32 - const char *unsafe_chars = " /'\"`&();|<>$%{}!\\:*?"; -#else - const char *unsafe_chars = " /'\"`&();|<>$%{}!"; -#endif - - g_return_if_fail (string != NULL); - p = string; - - while(p && *p) { - c = g_utf8_get_char (p); - ts = p; - p = g_utf8_next_char (p); - /* I wonder what this code is supposed to actually - * achieve, and whether it does that as currently - * written? - */ - if (!g_unichar_isprint(c) || ( c < 0xff && strchr (unsafe_chars, c&0xff ))) { - while (ts<p) - *ts++ = '_'; - } - } -} - static gint epow10 (gint number) { gint value; @@ -685,7 +567,7 @@ e_format_number_float (gfloat number) gboolean e_create_directory (gchar *directory) { - gint ret_val = e_mkdir_hier (directory, 0777); + gint ret_val = e_util_mkdir_hier (directory, 0777); if (ret_val == -1) return FALSE; else @@ -797,70 +679,6 @@ e_sort (void *base, #endif } -size_t e_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) -{ -#ifdef HAVE_LKSTRFTIME - return strftime(s, max, fmt, tm); -#else - char *c, *ffmt, *ff; - size_t ret; - - ffmt = g_strdup(fmt); - ff = ffmt; - while ((c = strstr(ff, "%l")) != NULL) { - c[1] = 'I'; - ff = c; - } - - ff = ffmt; - while ((c = strstr(ff, "%k")) != NULL) { - c[1] = 'H'; - ff = c; - } - - ret = strftime(s, max, ffmt, tm); - g_free(ffmt); - return ret; -#endif -} - -size_t -e_utf8_strftime(char *s, size_t max, const char *fmt, const struct tm *tm) -{ - size_t sz, ret; - char *locale_fmt, *buf; - - locale_fmt = g_locale_from_utf8(fmt, -1, NULL, &sz, NULL); - if (!locale_fmt) - return 0; - - ret = e_strftime(s, max, locale_fmt, tm); - if (!ret) { - g_free (locale_fmt); - return 0; - } - - buf = g_locale_to_utf8(s, ret, NULL, &sz, NULL); - if (!buf) { - g_free (locale_fmt); - return 0; - } - - if (sz >= max) { - char *tmp = buf + max - 1; - tmp = g_utf8_find_prev_char(buf, tmp); - if (tmp) - sz = tmp - buf; - else - sz = 0; - } - memcpy(s, buf, sz); - s[sz] = '\0'; - g_free(locale_fmt); - g_free(buf); - return sz; -} - /** * Function to do a last minute fixup of the AM/PM stuff if the locale * and gettext haven't done it right. Most English speaking countries diff --git a/e-util/e-util.h b/e-util/e-util.h index cc0043c7df..b80915f8f0 100644 --- a/e-util/e-util.h +++ b/e-util/e-util.h @@ -156,16 +156,11 @@ int e_write_file (cons int flags); int e_write_file_mkstemp (char *filename, const char *data); -int e_mkdir_hier (const char *path, - mode_t mode); gchar **e_strsplit (const gchar *string, const gchar *delimiter, gint max_tokens); -gchar *e_strstrcase (const gchar *haystack, - const gchar *needle); /* This only makes a filename safe for usage as a filename. It still may have shell meta-characters in it. */ -void e_filename_make_safe (gchar *string); gchar *e_format_number (gint number); gchar *e_format_number_float (gfloat number); gboolean e_create_directory (gchar *directory); @@ -193,20 +188,11 @@ size_t e_strftime_fix_am_pm (char *s, const char *fmt, const struct tm *tm); -size_t e_strftime (char *s, - size_t max, - const char *fmt, - const struct tm *tm); - size_t e_utf8_strftime_fix_am_pm (char *s, size_t max, const char *fmt, const struct tm *tm); -size_t e_utf8_strftime (char *s, - size_t max, - const char *fmt, - const struct tm *tm); /* String to/from double conversion functions */ gdouble e_flexible_strtod (const gchar *nptr, |