aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristopher James Lahey <clahey@ximian.com>2001-02-07 11:28:54 +0800
committerChris Lahey <clahey@src.gnome.org>2001-02-07 11:28:54 +0800
commit758b87ad3702f4c0b55c0b3174b521f365ff5896 (patch)
treedd377d7e7de58e38dfc6026df854918a36e73603
parent71c965734eb20a39456ecc7c6f87052059cd23d4 (diff)
downloadgsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.tar
gsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.tar.gz
gsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.tar.bz2
gsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.tar.lz
gsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.tar.xz
gsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.tar.zst
gsoc2013-evolution-758b87ad3702f4c0b55c0b3174b521f365ff5896.zip
Added e_format_number and e_create_directory.
2001-02-06 Christopher James Lahey <clahey@ximian.com> * gal/util/e-util.c, gal/util/e-util.h (e_format_number, e_create_directory): Added e_format_number and e_create_directory. svn path=/trunk/; revision=8042
-rw-r--r--e-util/e-util.c132
-rw-r--r--e-util/e-util.h112
2 files changed, 189 insertions, 55 deletions
diff --git a/e-util/e-util.c b/e-util/e-util.c
index 5bffc9e4a9..4840bf0ffd 100644
--- a/e-util/e-util.c
+++ b/e-util/e-util.c
@@ -28,6 +28,8 @@
#include <ctype.h>
#include <sys/stat.h>
#include <string.h>
+#include <locale.h>
+#include <stdio.h>
#include "e-util.h"
#if 0
@@ -536,3 +538,133 @@ e_filename_make_safe (gchar *string)
*p = '_';
}
}
+
+static gint
+epow10 (gint number) {
+ gint value;
+
+ for (value = 1; number > 0; number --) {
+ value *= 10;
+ }
+ return value;
+}
+
+gchar *
+e_format_number (gint number)
+{
+ GList *iterator, *list = NULL;
+ struct lconv *locality;
+ gint char_length = 0;
+ gint group_count = 0;
+ guchar *grouping;
+ int last_count = 3;
+ int divider;
+ char *value;
+ char *value_iterator;
+
+ locality = localeconv();
+ grouping = locality->grouping;
+ while (number) {
+ char *group;
+ switch (*grouping) {
+ default:
+ last_count = *grouping;
+ grouping++;
+ case 0:
+ divider = epow10(last_count);
+ group = g_strdup_printf("%d", number % divider);
+ number /= divider;
+ break;
+ case CHAR_MAX:
+ group = g_strdup_printf("%d", number);
+ number = 0;
+ break;
+ }
+ char_length += strlen(group);
+ list = g_list_prepend(list, group);
+ group_count ++;
+ }
+
+ if (list) {
+ value = g_new(char, char_length + (group_count - 1) * strlen(locality->thousands_sep));
+
+ iterator = list;
+ value_iterator = value;
+
+ strcpy(value_iterator, iterator->data);
+ value_iterator += strlen(iterator->data);
+ for (iterator = iterator->next; iterator; iterator = iterator->next) {
+ strcpy(value_iterator, locality->thousands_sep);
+ value_iterator += strlen(locality->thousands_sep);
+
+ strcpy(value_iterator, iterator->data);
+ value_iterator += strlen(iterator->data);
+ }
+ e_free_string_list (list);
+ return value;
+ } else {
+ return g_strdup("0");
+ }
+}
+
+gboolean
+e_create_directory (gchar *directory)
+{
+ gchar *full_name;
+ gchar *position;
+ gchar *current_dir = g_get_current_dir();
+ struct stat info;
+ gboolean return_value = TRUE;
+
+ if (directory[0] == '/') {
+ full_name = g_malloc0 (strlen (directory) + 1);
+ strcpy (full_name, directory);
+ } else {
+ full_name = g_malloc0 (strlen (directory) + strlen (current_dir) + 2);
+ sprintf (full_name, "%s/%s", current_dir, directory);
+ }
+
+ if ((position = strrchr (full_name, '/')) == full_name) {
+ if (stat (full_name, &info)) {
+ switch (errno) {
+ case ENOENT:
+ if (mkdir (full_name, 0777)) {
+ switch (errno) {
+ default:
+ return_value = FALSE;
+ break;
+ }
+ }
+ break;
+ default:
+ return_value = FALSE;
+ break;
+ }
+ }
+ } else {
+ *position = 0;
+ e_create_directory (full_name);
+ *position = '/';
+ if (stat (full_name, &info)) {
+ switch (errno) {
+ case ENOENT:
+ if (mkdir (full_name, 0777)) {
+ switch (errno) {
+ default:
+ return_value = FALSE;
+ break;
+ }
+ }
+ break;
+ default:
+ return_value = FALSE;
+ break;
+ }
+ }
+ }
+
+ g_free (current_dir);
+ g_free (full_name);
+
+ return (return_value);
+}
diff --git a/e-util/e-util.h b/e-util/e-util.h
index 1e1f4b322d..1f11635096 100644
--- a/e-util/e-util.h
+++ b/e-util/e-util.h
@@ -31,69 +31,71 @@ typedef enum {
E_FOCUS_START,
E_FOCUS_END
} EFocus;
-int g_str_compare (const void *x,
- const void *y);
-int g_int_compare (const void *x,
- const void *y);
-char *e_strdup_strip (const char *string);
-void e_free_object_list (GList *list);
-void e_free_string_list (GList *list);
-char *e_read_file (const char *filename);
-int e_write_file (const char *filename,
- const char *data,
- int flags);
-int e_mkdir_hier (const char *path,
- mode_t mode);
+int g_str_compare (const void *x,
+ const void *y);
+int g_int_compare (const void *x,
+ const void *y);
+char *e_strdup_strip (const char *string);
+void e_free_object_list (GList *list);
+void e_free_string_list (GList *list);
+char *e_read_file (const char *filename);
+int e_write_file (const char *filename,
+ const char *data,
+ int flags);
+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);
-void e_filename_make_safe (gchar *string);
-void e_marshal_INT__INT_INT_POINTER (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
-void e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
-void e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
-void e_marshal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
+gchar **e_strsplit (const gchar *string,
+ const gchar *delimiter,
+ gint max_tokens);
+gchar *e_strstrcase (const gchar *haystack,
+ const gchar *needle);
+void e_filename_make_safe (gchar *string);
+gchar *e_format_number (gint number);
+gboolean e_create_directory (gchar *directory);
+void e_marshal_INT__INT_INT_POINTER (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
+void e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
+void e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
+void e_marshal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
#define e_marshal_NONE__INT_INT_POINTER_POINTER_UINT_UINT e_marshal_NONE__INT_INT_POINTER_POINTER_INT_INT
-void e_marshal_NONE__INT_INT_POINTER_POINTER_INT_INT (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
+void e_marshal_NONE__INT_INT_POINTER_POINTER_INT_INT (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
#define e_marshal_NONE__INT_INT_POINTER_UINT e_marshal_NONE__INT_INT_POINTER_INT
-void e_marshal_NONE__INT_INT_POINTER_INT (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
+void e_marshal_NONE__INT_INT_POINTER_INT (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
#define e_marshal_BOOL__INT_INT_POINTER_INT_INT_UINT e_marshal_BOOL__INT_INT_POINTER_INT_INT_INT
-void e_marshal_BOOL__INT_INT_POINTER_INT_INT_INT (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
+void e_marshal_BOOL__INT_INT_POINTER_INT_INT_INT (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
#define e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_UINT_UINT e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT
-void e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
-void e_marshal_NONE__POINTER_POINTER_INT (GtkObject *object,
- GtkSignalFunc func,
- gpointer func_data,
- GtkArg *args);
+void e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
+void e_marshal_NONE__POINTER_POINTER_INT (GtkObject *object,
+ GtkSignalFunc func,
+ gpointer func_data,
+ GtkArg *args);
#endif /* _E_UTIL_H_ */