diff options
author | nobody <nobody@localhost> | 2001-09-10 08:42:32 +0800 |
---|---|---|
committer | nobody <nobody@localhost> | 2001-09-10 08:42:32 +0800 |
commit | 019c19a49fa6a056d407890bd2a4850515073eba (patch) | |
tree | 9b67839e7f45d6cb1705ef363dd8593289d70823 /e-util | |
parent | a9c0f1b944f4983202f4f3b62d83aabd2fd01640 (diff) | |
download | gsoc2013-evolution-019c19a49fa6a056d407890bd2a4850515073eba.tar.gz gsoc2013-evolution-019c19a49fa6a056d407890bd2a4850515073eba.tar.zst gsoc2013-evolution-019c19a49fa6a056d407890bd2a4850515073eba.zip |
This commit was manufactured by cvs2svn to create tag 'guikachu-0_9'.guikachu-0_9
svn path=/tags/guikachu-0_9/; revision=12724
Diffstat (limited to 'e-util')
83 files changed, 0 insertions, 17032 deletions
diff --git a/e-util/.cvsignore b/e-util/.cvsignore deleted file mode 100644 index cb49036068..0000000000 --- a/e-util/.cvsignore +++ /dev/null @@ -1,6 +0,0 @@ -.deps -Makefile -Makefile.in -.libs -*.lo -*.la diff --git a/e-util/ChangeLog b/e-util/ChangeLog deleted file mode 100644 index bb0ebf0a21..0000000000 --- a/e-util/ChangeLog +++ /dev/null @@ -1,1488 +0,0 @@ -2001-09-08 Dan Winship <danw@ximian.com> - - * e-html-utils.c (e_text_to_html_full): Fix some broken calls to - check_size that could result in memory corruption displaying short - replies. - -2001-09-06 Dan Winship <danw@ximian.com> - - * e-html-utils.c (e_text_to_html_full): Add E_TEXT_TO_HTML_CITE, - to prepend "> " to each line. - -2001-09-05 Dan Winship <danw@ximian.com> - - * e-mktemp.c (get_path): Fix the check for the case when mkdir() - returns EEXIST to check S_ISDIR on the right structure component. - Fixes bug #8775. - -2001-08-31 Federico Mena Quintero <federico@ximian.com> - - * e-time-utils.c (e_time_parse_date_and_time): Added format for - "7 PM" and equivalents. Fixes bug #7456. - (e_time_parse_time): Likewise. - -2001-08-28 Not Zed <NotZed@Ximian.com> - - * e-categories-master-list-wombat.c (ecmlw_load): Dont call - g_print with a NULL string. See bug #7396. - -2001-08-24 Jeffrey Stedfast <fejj@ximian.com> - - * e-mktemp.c (get_path): Make more robust. - -2001-08-24 Jeffrey Stedfast <fejj@ximian.com> - - * Makefile.am: Added e-mktemp.[c,h] to the build. - - * e-mktemp.c (e_mktemp): A new wrapper around mktemp so that we - can keep track of temp files for later cleanup. - (e_mkstemp): Same but obviously for the mkstemp call. - (e_mkdtemp): And finally a mkdtemp wrapper. - -2001-08-24 Zbigniew Chyla <cyba@gnome.pl> - - * Makefile.am (libeutil_la_SOURCES): Added e-unicode-i18n.c and - e-unicode-i18n.h. - - * e-unicode-i18n.[ch]: New files with two extra functions - (e_utf8_gettext, e_utf8_dgettext) and U_() macro. - Should be used instead of _() if we need UTF-8 string. - -2001-08-23 Zbigniew Chyla <cyba@gnome.pl> - - * e-request.c (e_request_string): Modified to accept and return - UTF-8 string. It's currently used only in - shell/e-shortcuts-view.c and we need UTF-8 there. - -2001-08-20 Damon Chaplin <damon@ximian.com> - - * e-time-utils.c (e_time_parse_date): added comments to help - translators a bit. - -2001-08-09 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-config.c (e_categories_config_get_icon_for): return - when there's no icon associated with the category - - * e-categories-config.c: reworked to use the - ECategoriesMasterListWombat class. Also, load correctly images - (fixes #6794) - -2001-08-09 Federico Mena Quintero <federico@ximian.com> - - * e-categories-master-list-wombat.c (ecmlw_destroy): Chain to the - destroy handler in the parent class! - - * e-list-iterator.c (e_list_iterator_destroy): Likewise. Sigh. - - * e-list.c (e_list_destroy): Likewise. Double sigh. - -2001-08-08 Ettore Perazzoli <ettore@ximian.com> - - * e-dialog-utils.h: New. - * e-dialog-utils.c: New. - -2001-08-04 Ettore Perazzoli <ettore@ximian.com> - - * e-bonobo-factory-util.c - (e_bonobo_generic_factory_multi_display_new): New function to - create a factory that creates separate component instances for - different displays. - -2001-08-03 Christopher James Lahey <clahey@ximian.com> - - * e-list-iterator.c (e_list_iterator_next): Made it so that - e_list_iterator_next goes to the first element if it's set to - NULL. This makes deleting the first element and then doing - e_list_iterator_next go to the new first element. Did the analogy - for e_list_iterator_prev for completeness and consistency's sakes. - Fixes Ximian bug #6057. - -2001-08-01 Christopher James Lahey <clahey@ximian.com> - - * e-categories-master-list-wombat.c (ecmlw_load): Fixed the load - statement here by just using array_from_string. - (ecmlw_save): Removed the part where we save the icons and colors - since that's handled in the array_to_string function. Fixes - Ximian bug #4451. - -2001-07-27 JP Rosevear <jpr@ximian.com> - - * e-dbhash.c (string_to_dbt): memset everything to 0 - (md5_to_dbt): ditto - -2001-07-20 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-config.c (initialize_categories_config): use the 2 - new category icons (16_category_suppliers.png and - 16_category_time-and-expenses.png) - -2001-07-19 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-config.c (initialize_categories_config): use the 2 - new category icons - - * Makefile.am: s/imagedir/imagesdir - -2001-07-17 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-config.c (initialize_categories_config): generate - default configuration for icons-per-category the first time. And - use a global (for this file) Bonobo_ConfigDatabase - -2001-07-16 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-config.c (e_categories_config_get_icon_for): - (e_categories_config_get_icon_file_for): - (e_categories_config_set_icon_file_for): use GdkPixbuf to load images - -2001-07-16 Federico Mena Quintero <federico@ximian.com> - - * e-time-utils.c (parse_with_strptime): Generalized function for - trying a number of strptime() formats on a string. - (e_time_parse_time): Use parse_with_strptime(). - (e_time_parse_date): New function, analogous to the previous one, - but uses a number of date formats. - -2001-07-12 Federico Mena Quintero <federico@ximian.com> - - * e-time-utils.c (e_time_parse_date_and_time): If the string is - empty, clear the struct tm before returning. - -2001-07-12 Jon Trowbridge <trow@ximian.com> - - * e-html-utils.c: Added is_addr_char_no_pipes macro, which specifically - does not consider '|' ("pipe") to be a legal address character. - (email_address_extract): Use is_addr_char_no_pipes when looking for - e-mail addresses to turn into HTML links. (Bug #3940) - -2001-07-05 Not Zed <NotZed@Ximian.com> - - * e-memory.c: Added some malloc check stuff. - -2001-07-04 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-master-list-wombat.c (ecmlw_load): load all icons - and colors for each category - - (ecmlw_save): save all icons and categories associated with - each category - - * e-categories-config.c: use BonoboConf to store/retrieve settings, - and use ECategoriesMasterListWombat when creating a ECategories - dialog widget - -2001-07-02 Christopher James Lahey <clahey@ximian.com> - - * Makefile.am (libeutil_la_SOURCES): Added - e-categories-master-list-wombat.c and - e-categories-master-list-wombat.h. - (INCLUDES): Added $(BONOBO_CONF_CFLAGS). - - * e-categories-master-list-wombat.c, - e-categories-master-list-wombat.h: New class implementing a master - list that stores its state using bonobo-conf. - -2001-07-02 Rodrigo Moya <rodrigo@ximian.com> - - * e-categories-config.[ch]: new file for a set of functions for - managing category-related (icons, colors) configuration - -2001-07-01 Ettore Perazzoli <ettore@ximian.com> - - * e-request.c: New. - * e-request.h: New. - -2001-06-25 Jeffrey Stedfast <fejj@ximian.com> - - * e-sexp.c (term_eval_and): When ANDing two bools, don't use a - bitwise AND. - -2001-06-18 Dan Winship <danw@ximian.com> - - * Makefile.am: Split e-db3-utils and e-dbhash off into libedb3util - so eutil won't depend on db3. - -2001-06-15 Not Zed <NotZed@Ximian.com> - - * e-sexp.c (parse_values): REmove a silly hardcoded term limit, - oops forgot about that. - -2001-06-11 Damon Chaplin <damon@ximian.com> - - * e-time-utils.c (e_time_parse_date_and_time): skip any non-digits - while looking for dates and times. This should fix some translation - problems. Though there is still a problem with Japanese, where the - am/pm flag comes before the time so we will skip it incorrectly. - -2001-06-10 Damon Chaplin <damon@ximian.com> - - * e-time-utils.c (e_time_parse_date_and_time): - (e_time_parse_time): got rid of '%n' at end of each format string - for strptime. I don't know how I managed to put them in there. - -2001-05-31 Christopher James Lahey <clahey@ximian.com> - - * Makefile.am (INCLUDES): Added db3 cflags. - - * e-dbhash.c: Made this use db3. - - * e-db3-utils.c, e-db3-utils.h: New files with some helper - functions. - -2001-05-27 Dan Winship <danw@ximian.com> - - * e-gui-utils.c: Remove e_pixmaps_update (moved to libeshell) so - libeutil won't depend on bonobo. - -2001-05-19 Ettore Perazzoli <ettore@ximian.com> - - * e-host-utils.c (e_gethostbyname_r) - [HAVE_GETHOSTBYNAME_R && GETHOSTBYNAME_R_FIVE_ARGS]: Set `*herr' - to zero if the function returns a non-NULL pointer to the hostent. - According to the docs, a returned non-NULL hostent always means - "no error" no matter what the returned value of `herr' is. [And - in fact, at least on libc 2.2.3, trying to resolve `localhost' - sets herr to `HOST_NOT_FOUND' even if the name is resolved - correctly and the returned hostent is non-NULL.] - -2001-05-16 Dan Winship <danw@ximian.com> - - * e-html-utils.c (e_text_to_html_full): add - E_TEXT_TO_HTML_ESCAPE_8BIT to turn non-US-ASCII characters into - "?"s. - -2001-05-14 Jon Trowbridge <trow@ximian.com> - - * e-html-utils.c (is_citation): Check for bad utf8. - -2001-05-08 Dan Winship <danw@ximian.com> - - * e-path.c (e_path_find_folders): Walk a hierarchy using the - "/subfolders/" convention and call a callback for each folder - found. - -2001-05-01 Dan Winship <danw@ximian.com> - - * e-msgport.c (e_mutex_assert_locked): Debugging routine. (Only - works for recursive mutexes right now.) - - * e-html-utils.c (e_text_to_html_full): Don't use g_utf8_next_char - on text that isn't valid UTF8, since it won't work (and might even - get into an infinite loop). - -2001-04-29 Dan Winship <danw@ximian.com> - - * e-html-utils.c (email_address_extract): Make this smarter. Now - e_text_to_html_full calls it when it sees a '@', and - email_address_extract deals with scanning both forward and - backward to find the bounds of the email address. It's still - fooled by Message-IDs, but there's not a whole lot we can do - there... - -2001-04-26 Dan Winship <danw@ximian.com> - - * e-host-utils.c (e_gethostbyname_r): Make the Solaris and - no-gethostbyname_r implementations behave more like the Linux one. - Document. - - * Makefile.am (INCLUDES): Remove UNICODE_CFLAGS - (libeutil_la_LIBADD): Change UNICODE_LIBS to GAL_LIBS - -2001-04-26 Not Zed <NotZed@Ximian.com> - - * e-memory.c (e_poolv_get): Modified to match e_strv_get - behaviour. Assert on bad cases, and return "" rather than NULL - for empty/unset strings. - (e_poolv_new): Simplify the mutex cases, only have a single mutex - for mempool and hashtable references. - (e_poolv_set): Simplify mutex code. Fixed a #ifdef orde prob in - profile stuff. Always copy string to our own memory when we add - it to the hash, even if we free it; I think this would have led to - dangling references otherwise. - (e_poolv_destroy): Renamed from poolv_free, for consistency with - the rest of the allocators here. - (e_poolv_set): Add optional refcounting code here, not currently - enabled/used, but should make proper string collection work - easily. - (e_poolv_destroy): Unrefcount the strings here. - (e_poolv_cpy): Add refcounting code here. - - * e-memory.[ch]: Applied Jacob's patches <jacob@ximian.com> for - 'e-poolv' type, added his name to the authors list. - -2001-04-24 Dan Winship <danw@ximian.com> - - * e-html-utils.c (check_size): If the buffer is too small, making - it twice as big does not guarantee it will be big enough. "Duh". - Also, a bunch of the check_size calls don't seem to be taking - trailing NULs into account, so add in a +1 here. - -2001-04-24 Kjartan Maraas <kmaraas@gnome.org> - - * e-gui-utils.c, e-memory, e-msgport.c, e-pilot-map, e-sexp.c: - Added #include <glib.h> and move corresponding local headers - to the top to catch missing includes in them. Tip from clahey. - -2001-04-24 Chris Toshok <toshok@ximian.com> - - * e-host-utils.h: remove prototype for e_gethostbyname_init. - - * e-host-utils.c (e_gethostbyname_r): don't dynamically allocate - anything - store everything in the buffer that's passed in. Also, - stop using EMutex. Switch to a static GMutex (so we can - initialize it without having e_gethostbyname_init). - (e_gethostbyname_init): removed. - -2001-04-23 Jon Trowbridge <trow@ximian.com> - - * e-html-utils.c (e_text_to_html_full): Removed attempts to use - Radek's evil <DATA> hacks, which were just causing me - (and GtkHTML) grief. - -2001-04-23 Jon Trowbridge <trow@ximian.com> - - * e-host-utils.c: Include glib.h, so that the g_warning in - e_gethostbyname_r will be treated as a macro and not as an - unresolved symbol. - -2001-04-22 Chris Toshok <toshok@ximian.com> - - * Makefile.am (libeutil_la_SOURCES): add e-host-utils.[ch] - - * e-host-utils.c: new file, with e_gethostbyname_r. - - * e-host-utils.h: new file. - -2001-04-19 Dan Winship <danw@ximian.com> - - * e-html-utils.c (is_citation): ">From" is not a citation unless - the previous or following line is a citation. - (e_text_to_html_full): Update for is_citation change. Also, when - marking citations, unmangle mbox From-mangling. - -2001-04-15 Federico Mena Quintero <federico@ximian.com> - - * e-sexp.c (e_sexp_parse): Start parsing the sexp with - parse_value(), not parse_list(), because we may have immediate - values (e.g. "#f") as the whole sexp. - -2001-04-08 JP Rosevear <jpr@ximian.com> - - * Makefile.am: Setup up the conduit library building better so the - files get disted - -2001-04-06 Federico Mena Quintero <federico@ximian.com> - - * e-sexp.c (scanner_config): Added a question mark to the set of - valid characters for symbol names. - (parse_value): Fixed parsing of boolean values. - (parse_term_free): Added missing clause for ESEXP_TERM_BOOL. - -2001-04-04 Kjartan Maraas <kmaraas@gnome.org> - - * ename/test-ename-western-gtk.c: Fix headers. - -2001-04-03 Federico Mena Quintero <federico@ximian.com> - - * e-sexp.h (ESExpResultType): Added ESEXP_RES_TIME for time - values. - (ESExpResult): Added a "time_t value.time" field. - (ESExpTermType): Added ESEXP_TERM_TIME. - (ESExpTerm): Added a "time_t value.time" field. - - * e-sexp.c (e_sexp_result_free): Deal with time values. Also, be - more paranoid; added a default clause with g_assert_not_reached(). - (term_eval_lt): Deal with time values. - (term_eval_gt): Likewise. - (term_eval_eq): Likewise. - (term_eval_plus): Likewise. - (term_eval_sub): Likewise. - (e_sexp_term_eval): Likewise. - (eval_dump_result): Likewise. - (parse_dump_term): Likewise. - (parse_term_free): Likewise. - -2001-04-01 Gediminas Paulauskas <menesis@delfi.lt> - - * e-gui-utils.h: new type EPixmap, which is used to cache pixmaps for - bonobo components. use e_pixmaps_update to load icons into ui - component. - * e-gui-utils.c: implementation of EPixmap cache, moved here from - mail/folder-browser-factory.c. - -2001-03-31 Jon Trowbridge <trow@ximian.com> - - * e-url.c (e_url_shroud): Check that first_colon < last_at, - to prevent horrible things from happening. Removed spew. - (e_url_equal): Removed spew. - -2001-03-30 Jon Trowbridge <trow@ximian.com> - - * e-html-utils.c (e_text_to_html_full): Add support for converting - e-mail addresses to links. - (is_email_address): Added. Identifies e-mail addresses. - (email_address_extract): Added. Extracts a copy of the e-mail - address from the text. - - * e-html-utils.h (E_TEXT_TO_HTML_CONVERT_ADDRESSES): Added. - - * e-url.c (e_url_shroud): Added. Copy a url, replacing - any plaintext passwords with a single *. - (e_url_equal): Compare two urls, taking into account that - they may or may not be shrouded. - -2001-03-29 Kjartan Maraas <kmaraas@gnome.org> - - * e-corba-utils.h: Remove #include <glib.h> - * e-dialog-widgets.c: Shuffle some headers. - * e-dialog-widgets.h: Remove #include <libgnomeui/gnome-propertybox.h> - * e-gtk-utils.c: #include <gtk/gtksignal.h> - * e-gtk-utils.h: Replace #include <gtk/gtk.h> - * e-gui-utils.c: Replace #include <gnome.h> - * e-html-utils.c: Shuffle headers. - * e-iterator.c: Replace #include <gtk/gtk.h> - * e-iterator.h: Replace #include <gtk/gtk.h> - * e-list-iterator.c: Remove #include <gtk/gtk.h> - * e-list-iterator.h: Replace #include <gtk/gtk.h> - * e-list.c: Remove #include <gtk/gtk.h> - * e-list.h: Replace #include <gtk/gtk.h> - * e-memory.c: #include <string.h> and <stdlib.h> - * e-msgport.c: Move around some includes. s/%d/%ld/g in a printf() - call to fix a warning. - * e-pilot-map.c: #include <string.h>. Replace #include <gnome.h> - * e-pilot-util.c: Remove #include <gnome.h> - * e-sexp.c: Remove #include <glib.h> - * e-sexp.h: Replace #include <gtk/gtk.h> - * e-time-utils.c: #include <string.h> - * md5-utils.c: Shuffle headers. - * test-ename-western-gtk.c: Replace #include <gnome.h> - * test-ename-western.c: Same here. - -2001-03-20 Radek Doulik <rodo@ximian.com> - - * e-html-utils.c (e_text_to_html_full): new function, extracted - from e_text_to_html, added color parameter - -2001-03-19 Radek Doulik <rodo@ximian.com> - - * e-html-utils.c (e_text_to_html): support mark citation - - * e-html-utils.h (E_TEXT_TO_HTML_MARK_CITATION): added - E_TEXT_TO_HTML_MARK_CITATION - -2001-03-18 Damon Chaplin <damon@ximian.com> - - * e-time-utils.c (e_time_format_time): added function to format just - the time. - -2001-03-16 Dan Winship <danw@ximian.com> - - * e-path.c (e_path_to_physical): Fix a bug noticed by kmaraas - -2001-03-15 Dan Winship <danw@ximian.com> - - * e-html-utils.c (url_extract): Fix a bit: [mailto:foo] shouldn't - grab the ']' - -2001-03-12 JP Rosevear <jpr@ximian.com> - - * Makefile.am: update cflag macros - -2001-03-07 Dan Winship <danw@ximian.com> - - * e-html-utils.c (url_extract): Fix an off-by-one in the "is this - for real?" check so that "http:// " won't get URLified - -2001-03-04 Damon Chaplin <damon@ximian.com> - - * e-time-utils.[hc]: new files to contain functions to parse and - format dates and times for various calendar widgets. - -2001-03-01 Dan Winship <danw@ximian.com> - - * e-path.c (e_path_to_physical): New function to turn foo/bar into - foo/subfolders/bar. The inverse function doesn't exist yet because - I didn't need it. Also, if the shell were going to use this, we'd - need a few more tools... - - * Makefile.am (libeutil_la_SOURCES): Add e-path.[ch] - -2001-03-01 Not Zed <NotZed@Ximian.com> - - * e-sexp.c (e_sexp_encode_string): Make it handle a NULL string as - an empty string. - -2001-02-23 Not Zed <NotZed@Ximian.com> - - * e-msgport.c (e_thread_destroy): Wait a lot lot longer for - threads to finish. - : Turned off some of the debug. - -2001-02-08 Not Zed <NotZed@Ximian.com> - - * e-memory.c (EMemChunk): Changed to allocate raw blocks for the - data, and keep track of them with an array, this is so the native - malloc alignment is not lost at the allocation stage. - -2001-01-30 Not Zed <NotZed@Ximian.com> - - * e-msgport.c (e_thread_destroy): Turn on joining of cancelled threads. - (e_msgport_wait): Put a cleanup handler to clear the mp lock if it - happens in cond_wait, since it will be locked again. - -2001-01-29 Not Zed <NotZed@Ximian.com> - - * e-msgport.c (e_thread_put): If we have waiting threads, then - dont start a new one for the NEW case. - (thread_dispatch): For the NEW case, dont exit, just keep running, - waiting for a new message to come along. - (e_thread_destroy): When cleaning up NEW threads, cancel any - non-busy threads. - -2001-01-24 Not Zed <NotZed@Ximian.com> - - * e-sexp.h (ESExp): Add chunk allocators. - - * e-sexp.c: Removed some redundant debug printfs. - (e_sexp_term_eval): Dont allocate result till we have it. so we - can have a fatal error, and not leak it. - (term_eval_plus): If we have to abort, free our arguments. - (term_eval_sub): Same. - (parse_new_term): Renamed to parse_term_new for consistency. - Fixed callers. - (e_sexp_result_new): Add the esexp as an argument. Ouch, lots of - code to change for this. Allocate blocks from an ememchunk. - Fixed all callers. - (e_sexp_result_free): Same as above, free blocks from the - ememchunk. Fixed all callers. - (parse_term_new): - (parse_term_free): Similarly, add the esexp to the argument, and - alloc/free from memchunks. Fixed all local callers. - (e_sexp_init): Setup the memory chunk allocators. - (e_sexp_finalise): Destroy memchunk allocators. - -2001-01-23 Not Zed <NotZed@Ximian.com> - - * e-sexp.c (e_sexp_parse): Setup error return and return error on - parse error. - (parse_list): Fail if we have a problem. - (parse_value): Here too. - (fatal_error): Fatal error handling function, jumps back to the - top caller. - (term_eval_and): - (e_sexp_term_eval): - (term_eval_sub): - (term_eval_plus): - (term_eval_gt): - (term_eval_lt): - (term_eval_or): Fail on error. - (e_sexp_term_eval): Added a comment about where this can be - called, which is only from inside e_sexp_eval(). - (e_sexp_eval): Setup setjmp error handler. - (e_sexp_error): Error accessor function. - - * e-sexp.h: Added a longjmp environment to the structure, and an - error return to parse. - -2001-01-22 JP Rosevear <jpr@ximian.com> - - * e-dbhash.c (md5_to_dbt): New function, can't use strlen on the md5 - hash because it might have null chars in it. - (e_dbhash_add): use md5_to_dbt - -2001-01-19 JP Rosevear <jpr@ximian.com> - - * e-pilot-map.c (e_pilot_map_remove_by_pid): Remove an item by pid - (e_pilot_map_remove_by_uid): ditto for uid - - * e-pilot-map.h: new protos - -2001-01-17 Jason Leach <jasonleach@usa.net> - - * e-gtk-utils.c (gtk_radio_button_get_nth_selected): New function, - name describes it well. - (gtk_radio_button_select_nth): New function. - -2001-01-17 Federico Mena Quintero <federico@ximian.com> - - * e-dialog-widgets.[ch]: Ximianified. - -2001-01-15 JP Roseveaer <jpr@ximian.com> - - * e-pilot-util.c (e_pilot_utf8_from_pchar): Dup the string passed - in, not the temporary string. d'oh. - -2001-01-04 Dan Winship <danw@helixcode.com> - - * e-msgport.c: #define E_THREAD_NONE as ((pthread_t)~0) and use - that instead of ~0 throughout. (pthread_t is a pointer type on my - system, so there are lots of warnings without the cast.) - -2000-12-24 Not Zed <NotZed@HelixCode.com> - - * Merge from camel-mt-branch. - -2000-12-20 JP Rosevear <jpr@helixcode.com> - - * e-pilot-util.c (e_pilot_utf8_to_pchar): Check for null strings - (e_pilot_utf8_from_pchar): ditto - -2000-12-19 JP Rosevear <jpr@helixcode.com> - - * e-pilot-util.c (e_pilot_utf8_to_pchar): Convert utf8 strings to - pilot character set - (e_pilot_utf8_from_pchar): vice versa - - * Makefile.am: Conditionally build e-pilot-util.[hc] because - they depend on pilot-link stuff - -2000-12-23 Not Zed <NotZed@HelixCode.com> - - * e-msgport.c (e_dlist_length): Util function. - (e_thread_new): Another new thread primitive. This one is a - re-usable 'server thread' thingy. - -2000-12-21 Not Zed <NotZed@HelixCode.com> - - * Makefile.am (libeutil_la_SOURCES): Added msgport stuff. - - * e-msgport.[ch]: Some thread primitives. e_dlist, a - double-linked list (ok, not a thread primitive, but used in ...), - e_msgport - an asynchronous, non-copying message passing - rendesvous port, and e_mutex, a portably configurable mutex. - -2000-12-19 Not Zed <NotZed@HelixCode.com> - - * e-sexp.c: Make the code compile without being a gtk object (the - old code can still be built as a gtk object if required). Also - removed some dead code. - (e_sexp_ref): New function to ref if we're not a gkt object. - (e_sexp_unref): Same for unref. - -2000-12-13 Larry Ewing <lewing@helixcode.com> - - * e-html-utils.c (e_text_to_html): make sure we actually make - enough space for " ". - -2000-12-08 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.c (e_dialog_editable_get): Updated - documentation comment. - -2000-12-04 Ettore Perazzoli <ettore@helixcode.com> - - * e-corba-utils.h: New. - - * e-corba-utils.c: New. - (e_safe_corba_string): New. - -2000-11-30 Not Zed <NotZed@HelixCode.com> - - * e-memory.c (e_strv_new): Fix typename of args (for all funcs). - (e_strv_set_ref): Assert the index is in range. - (e_strv_set_ref_free): " - (e_strv_set): " - (e_strv_get): " - -2000-11-29 Not Zed <NotZed@HelixCode.com> - - * e-sexp.c (term_eval_lt): Plug a memleak, need to free results - from term_eval(). - (term_eval_gt): - (term_eval_eq): - -2000-11-27 Not Zed <NotZed@HelixCode.com> - - * e-memory.c (e_mempool_new): Added some locking to global data. - This should make the interfaces mt-safe, although each object is - only per-thread safe. - -2000-11-22 Not Zed <NotZed@HelixCode.com> - - * e-memory.c (e_mempool_alloc): If we dont get a big enough chunk - in the first node, give up. Otherwise we spend too much time - searching. - (e_mempool_strdup): Doh, and allocate enough for the terminating - NUL at that. - (e_strv_set_ref_free): New function, set a reference to a string - that is then owned/free'd by the strv. - (e_strv_destroy): If there are any strings to destroy, free them - here. - -2000-11-21 Not Zed <NotZed@HelixCode.com> - - * e-memory.c (e_memchunk_alloc0): New function to allocate a - zero'd out chunk. - (e_mempool_strdup): New function to strdup into a mempool. - -2000-11-20 Not Zed <NotZed@HelixCode.com> - - * e-memory.[ch]: New routines for fast memory management and - compact string array storage. - - * Makefile.am (libeutil_la_SOURCES): Added e-memory.[ch]. - -2000-11-09 JP Rosevear <jpr@helixcode.com> - - * e-dbhash.h: oops thats func not *func - - * e-dbhash.c (e_dbhash_foreach_key): Memset the data DBT to 0 - -2000-11-07 JP Rosevear <jpr@helixcode.com> - - * Makefile.am: Build e-dbhash.[hc] - - * e-dbhash.[hc]: New routines to manage a db database on disk that - contains md5 hashed data and indexed by uids. Provides comparison - functions and such so the caller does not have to do the md5 bits. - -200-10-30 Kjartan Maraas <kmaraas@gnome.org> - - * e-dialog-widgets.c: #include <string.h> to quench warning. - * e-sexp.c: #include <stdlib.h> for same reason. - -2000-10-27 <jpr@helixcode.com> - - * Makefile.am: build md5-utils - - * md5-utils.c: Make part of util, get rid of camel stream util - function include string.h - - * md5-utils.h: ditto - -2000-10-27 <jpr@helixcode.com> - - * e-pilot-map.c (e_pilot_map_lookup_uid): Return null if no - pnode was found. - -2000-10-27 JP Rosevear <jpr@helixcode.com> - - * e-pilot-map.c (map_sax_start_element): Get archive field while - parsing - (map_write_foreach): Write out archive field - (e_pilot_map_pid_is_archived): implement - (e_pilot_map_uid_is_archived): ditto - (e_pilot_map_insert): Insert new node structures - (e_pilot_map_lookup_pid): Take into account the list is now - a list of structures - (e_pilot_map_lookup_uid): ditto - -2000-10-26 Michael Meeks <michael@helixcode.com> - - * ename/e-address-western.c (e_address_western_is_postal): - unsigned chars. - - * ename/e-name-western.c (e_name_western_get_one_prefix_at_str): - cast to unsigned char. - -2000-10-25 Dan Winship <danw@helixcode.com> - - * e-html-utils.c (e_text_to_html): Deal properly with URLs at the - end of the buffer. (The old code would append a "�" to the - text.) - -2000-10-23 JP Rosevear <jpr@helixcode.com> - - * e-pilot-map.c (e_pilot_map_lookup_pid): Lookup a pid by uid. - (e_pilot_map_lookup_uid): Lookup a uid by pid. - Now this is wrapped, we can store archive info internally - - * e-pilot-map.h: New accessor prototypes - -2000-10-23 Dan Winship <danw@helixcode.com> - - * ename/Makefile.am (INCLUDES): Remove unused GNOMELOCALEDIR - setting. - -2000-10-23 JP Rosevear <jpr@helixcode.com> - - * e-pilot-map.c: Operate with EPilotMap structure so things are - abstract to the caller - (e_pilot_map_pid_is_archived): Infrastructure for marking records - as archived - (e_pilot_map_uid_is_archived): ditto - - * e-pilot-map.h: Add more to public interface, including EPilotMap - structure - -2000-10-23 JP Rosevear <jpr@helixcode.com> - - * e-pilot-map.c: Pilot map functions grabbed from existing conduits - - * e-pilot-map.h (e_pilot_map_write): Header - -2000-10-18 Dan Winship <danw@helixcode.com> - - * e-html-utils.c (e_text_to_html): If unicode_get_utf8 returns -1, - assume it was actually undeclared iso-8859-1 text. - -2000-10-17 Jesse Pavel <jpavel@helixcode.com> - - * ename/e-address-western.c: made the routines use the stardard - e_strstrcase instead of the included function that existed - earlier. - -2000-10-11 Iain Holmes <iain@helixcode.com> - - * ename/e-address-western.c (e_address_western_parse): g_strconcat - needs to be NULL terminated or it goes funny. - -Tue Sep 26 16:48:49 2000 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added $(EXTRA_GNOME_CFLAGS). - -2000-09-25 Jeffrey Stedfast <fejj@helixcode.com> - - * Makefile.am: add ename as a SUBDIR - -2000-09-18 Christopher James Lahey <clahey@helixcode.com> - - * e-list-iterator.c, e-list.c, e-list.h: Made e_list a bit more - reentrant. If a iterator gets its data pulled out from under it - while in a loop, it goes back one so that loops will be able to - continue. - -2000-09-18 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Removed all the files moved to gal. - - * e-dialog-widgets.c: Fixed the #include lines to deal properly - with gal. - - * e-gui-utils.c, e-gui-utils.h: Removed all of the functionality - that was moved to gal. - - * e-canvas-utils.c, e-canvas-utils.h, e-canvas-vbox.c, - e-canvas-vbox.h, e-canvas.c, e-canvas.h, e-cursors.c, e-cursors.h, - e-font.c, e-font.h, e-popup-menu.c, e-popup-menu.h, e-printable.c, - e-printable.h, e-unicode.c, e-unicode.h, e-util.c, e-util.h, - e-xml-utils.c, e-xml-utils.h: Moved to gal. - -2000-09-13 Christopher James Lahey <clahey@helixcode.com> - - * e-font.c: Fixed an uninitialized variable. - -2000-09-12 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.c (e_utf8_to_gtk_string_sized): Use underscores - for untranslatable characters - (e_utf8_from_gtk_string_sized): Ditto - -2000-09-12 Dan Winship <danw@helixcode.com> - - * e-font.c (e_font_from_gdk_font): Change this a bit so that if - you pass it a bold font, it puts that in font->bold and finds a - lighter font for font->font (if it can). This is for themes like - Metal where the default font is bold. - (find_variants): renamed from find_best_bold - -2000-09-11 Dan Winship <danw@helixcode.com> - - * e-font.c (find_best_bold): Thou shalt leave space for the - trailing \0. - - * e-util.c (e_strstrcase): The return value should not be - const. (Well, unless the input was, but you can't know that.) - -2000-09-11 Christopher James Lahey <clahey@helixcode.com> - - * e-unicode.c, e-unicode.h: Added e_utf8_gtk_editable_get_text and - e_utf8_gtk_editable_set_text. - -2000-09-11 Lauris Kaplinski <lauris@helixcode.com> - - * e-font.c: Try to find real bold variant of X font, fall - to double stroke only if not found - -2000-09-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-gtk-utils.c: New. - (e_gtk_signal_connect_full_while_alive): New. - - * e-gtk-utils.h: New. - -2000-09-08 Lauris Kaplinski <lauris@helixcode.com> - - * e-font.c: Use experimental 16-bit font stuff for EFonts - -2000-09-08 Dan Winship <danw@helixcode.com> - - * e-popup-menu.h: remove consts from the EPopupMenu structure: the - caller may want to modify its own EPopupMenu before calling - e_popup_menu_run. - -2000-09-07 Lauris Kaplinski <lauris@helixcode.com> - - * e-dialog-widgets.c (e_dialog_editable_get): Use UTF-8 - (e_dialog_editable_set): Use UTF-8 - - * e-font.c (translate_encoding): More encodings - (e_gdk_font_encoding): Use experimental stuff - - * e-unicode.* (e_utf8_gtk_editable_insert_text): New wrapper - -2000-09-07 Federico Mena Quintero <federico@helixcode.com> - - * e-canvas.c (emit_event): Remove incorrect optimization. Events - are read-only! - -2000-09-04 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.c: Added new font code, but comment it out now - * e-font.h, e-font.c: Test code for font analyzing - -2000-09-02 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.h, e-unicode.c: New functions - e_utf8_gtk_clist_append, e_utf8_gtk_clist_set_text - e_unicode_init - -2000-08-31 Lauris Kaplinski <lauris@helixcode.com> - - * e-html-utils.c (e_text_to_html): Use UTF-8 - - * e-unicode.h: - * e-unicode.c (g_unichar_to_utf8): glib 1.3 function - (gdk_keyval_to_unicode): gdk 1.3 function - (e_utf8_from_gdk_event_key): Use keyval, not string - -2000-08-30 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.h: #define gnome_font_get_size and - gnome_font_get_width, and gnome_font_lookup_default, - if compiling with gnome-print 0.20 - -2000-08-30 Dan Winship <danw@helixcode.com> - - * Makefile.am (libeutil_la_LIBADD): make e-util depend on - libunicode - - * e-popup-menu.c (make_item): Use GtkMenuItem rather than - GtkPixmapMenuItem for items with no pixmaps, so that if the whole - menu is pixmapless, you don't get a column of blank pixmaps. - -2000-08-24 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.h: - * e-unicode.c (e_utf8_gtk_menu_item_new_with_label): New wrapper - -2000-08-23 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.h: - * e-unicode.c (e_utf8_strstrcase): New function - -2000-08-23 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.c (e_dialog_editable_set): Constify. - -2000-08-22 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.h: - * e-unicode.c: e_utf8_gtk_editable_get_chars - e_utf8_gtk_entry_get_text - e_utf8_gtk_entry_set_text - e_utf8_to_gtk_string: New convenience functions - -2000-08-22 Lauris Kaplinski <lauris@helixcode.com> - - * e-unicode.h: - * e-unicode.c: Some convenience functions to deal with Gtk+ and UTF-8 - - * Makefile.am: Added e-unicode.h, e-unicode.c - -2000-08-21 Lauris Kaplinski <lauris@helixcode.com> - - * e-font.h: - * e-font.c: Changed UTF-8 syntax from char-based to byte-based - -2000-08-21 Peter Williams <peterw@helixcode.com> - - * e-html-utils.c (e_text_to_html): Fix a booboo in the tab - expansion code (didn't use the new value of 'out'). - -2000-08-19 Lauris Kaplinski lauris@helixcode.com - - * e-font.h: #define e_font_height(f) to save some space - -2000-08-19 Lauris Kaplinski lauris@helixcode.com - - * e-font.h: - * e-font.c: Thin wrapper around GdkFont to deal with UTF-8 directly - Also handles bold/italic styling - -2000-08-14 Peter Williams <peterw@helixcode.com> - - * e-sexp.c (scanner_config): Add "-" to be an acceptable - first character for an operation -- yaaay subtraction! - -2000-08-11 Peter Williams <peterw@helixcode.com> - - * e-html-utils.c (e_text_to_html): Fix the tab expansion - for when the length would exceed the ten characters that - we allocated. - -2000-08-10 Dan Winship <danw@helixcode.com> - - * e-setup.[ch]: Remove. The shell tells the components where - the evolution homedir is now. - - * Makefile.am (libeutil_la_SOURCES): Remove e-setup.c - - * e-html-utils.c (e_text_to_html): If converting both spaces and - newlines, then convert tabs too. The joys of pseudo-<PRE>. - -2000-08-09 Christopher James Lahey <clahey@helixcode.com> - - * e-popup-menu.c: Fix the bug where it truncates the last item - -2000-08-09 Christopher James Lahey <clahey@helixcode.com> - - * e-popup-menu.c: Ooops. - -2000-08-09 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added uncompiled e_read_uri function. - -2000-08-09 Christopher James Lahey <clahey@helixcode.com> - - * e-popup-menu.c, e-popup-menu.h: Added a hide_mask argument to - the two popup menu functions. - -2000-08-07 Christopher James Lahey <clahey@helixcode.com> - - * e-gui-utils.c, e-gui-utils.c: Added - e_container_change_tab_order. - -2000-07-27 Peter Williams <peterw@helixcode.com> - - * e-canvas.c (e_canvas_destroy): Chain the - destroy handler. - -2000-07-25 Peter Williams <peterw@helixcode.com> - - * e-canvas.c (emit_event): Don't bother with - dereferencing the event pointer. - (e_canvas_item_set_cursor): Reference our selection - item; print a debug message. Deref when destroying - (e_canvas_item_add_selection): Same. - (e_canvas_item_remove_selection): Same. - -2000-07-25 Peter Williams <peterw@helixcode.com> - - * Makefile.am (libeutil_static_la_LDFLAGS): Build both libraries - (a typo didn't build libeutil.la, only -static.) - -2000-07-25 Seth Alves <alves@hungry.com> - - * Makefile.am (libeutil_static_la_LDFLAGS): build static version - of library for conduit to use - -2000-07-25 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added a bunch of e_marshal functions. - -2000-07-12 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added e_strstrcase function. - -2000-07-11 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas-vbox.c: Removed some debugging printfs. - - * e-canvas.c (e_canvas_unrealize): Call parent unrealize method. - -2000-07-10 Ettore Perazzoli <ettore@helixcode.com> - - * e-sexp.c (eval_dump_result): `#if 0'ed out. - - * e-popup-menu.h (e_popup_menu_create): New prototype. - -2000-07-10 Dan Winship <danw@helixcode.com> - - * e-html-utils.c: Fix warnings. - -2000-07-08 Christopher James Lahey <clahey@helixcode.com> - - * e-list.c, e-list.h: Added e_list_duplicate. - -2000-07-07 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added e_strsplit to work around a bug in - g_strsplit. - -2000-07-07 Christopher James Lahey <clahey@helixcode.com> - - * e-iterator.c, e-iterator.h, e-list-iterator.c, - e-list-iterator.h: Added last and insert functions. - -2000-07-06 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.c: Added docstrings. This file did not have - them at all. EEEEEEK! - -2000-07-05 Dan Winship <danw@helixcode.com> - - * e-sexp.c (e_sexp_parse): Kill debugging message - -2000-07-03 Christopher James Lahey <clahey@helixcode.com> - - * e-iterator.c, e-iterator.h, e-list-iterator.c, - e-list-iterator.h, e-list.c, e-list.h: New list class with - iterators. - - * e-canvas.c: Made it so that you don't get the same selection in - the selection list more than once. - -2000-07-01 Ettore Perazzoli <ettore@helixcode.com> - - * e-gui-utils.h: #include <libgnomeui/gnome-messagebox.h>. It's - needed to be able to pass an appropriate @type arg to - `e_notice()'. - -2000-06-29 Jody Goldberg <jgoldberg@home.com> - - * e-canvas.c (e_canvas_init) : Init the InputContext members - (e_canvas_class_init) : Add a handler for unrealize. - (e_canvas_focus_in) : enable the input context. - (e_canvas_focus_out) : enable the input context. - (e_canvas_realize) : Create an input context. - (e_canvas_unrealize) : New function to release the input context. - -2000-06-28 Dan Winship <danw@helixcode.com> - - * e-html-utils.c (url_extract): add ")" to the set of characters - to back up over at the end of a potential URL. - -2000-06-27 Ettore Perazzoli <ettore@helixcode.com> - - * e-dialog-widgets.c (get_toggle_value): Use `value_var', not - `value'. - -2000-06-27 Ettore Perazzoli <ettore@helixcode.com> - - * Makefile.am (INCLUDES): `-I$(top_srcdir)' to fix compilation - with builddir != srcdir. - -2000-06-26 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added e-canvas-vbox.c and e-canvas-vbox.h. - - * e-canvas-vbox.c, e-canvas-vbox.h: New canvas object to act like - a vbox using the reflow system. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas.c, e-canvas.h: Added a variable to keep track of the - cursor. Set the cursor when selection_add is called. Properly - unset the cursor at the right times. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas.c: Grab the focus when setting the cursor. - -2000-06-20 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas.c, e-canvas.h: Built a system for doing selections - and/or a cursor in canvas. - -2000-06-13 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Changed the needed e_marshal functions. - - * e-printable.c, e-printable.h: Added a quantize parameter to - e_printable_height. Also, added a e_printable_will_fit function. - -2000-06-10 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Added e-printable.c and e-printable.h. - - * e-printable.c, e-printable.h: This new class is a printing - context. Other classes return an EPrintable which represents a - context for printing that object. - - * e-util.c, e-util.h: Added - e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL and - e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c: Fixed e_marshal_INT__INT_INT_POINTER. - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added e_marshal_INT__INT_INT_POINTER. - -2000-06-01 Dan Winship <danw@helixcode.com> - - * e-util.c (g_int_compare): Duh! -1 != 1. :) - -2000-06-01 Christopher James Lahey <clahey@helixcode.com> - - * e-sexp.c (e_sexp_term_eval): g_return_val_if_fail to prevent a crash. - -2000-05-30 Not Zed <NotZed@HelixCode.com> - - * e-sexp.c (e_sexp_encode_bool): Utility function to build a bool - as part of an expression string. - (e_sexp_encode_string): Likewise for strings. - -2000-05-30 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas-utils.c, e-canvas-utils.h: Added - e_canvas_item_show_area which makes sure that a particular area of - a given item is in the scroll area. - -2000-05-30 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.c (hook_radio): Use the exported function to - set the value. - (get_radio_value): Likewise. - (hook_option_menu): Likewise. - (get_option_menu_value): Likewise. - (hook_toggle): Likewise. - (get_toggle_value): Likewise. - (hook_spin_button): Likewise. - (get_spin_button_value): Likewise. - (hook_editable): Likewise. - (get_editable_value): Likewise. - (e_dialog_radio_set): Radio buttons are prepended to their parent - group's list, so we need to flip the index around when - getting/setting the value. - (e_dialog_radio_get): Likewise. - -2000-05-27 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.c (e_dialog_editable_set): Moved over from - event-editor-utils.c. - (e_dialog_editable_get): Likewise. - (e_dialog_toggle_set): Likewise. - (e_dialog_toggle_get): Likewise. - (e_dialog_spin_set): Likewise. - (e_dialog_spin_get_double): Likewise. - (e_dialog_spin_get_int): Likewise. - (e_dialog_option_menu_set): Likewise, and added a value map. - (e_dialog_option_menu_get): Likewise. - (e_dialog_dateedit_set): Likewise. - (e_dialog_dateedit_get): Likewise. - (e_dialog_radio_set): New function. - (e_dialog_radio_get): New function. - -2000-05-24 Christopher James Lahey <clahey@helixcode.com> - - * e-paned.c, e-paned.h: Removed. - -2000-05-23 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.c (get_radio_value): Implemented. Amazing that - one has to go through so much pain to get a stupid value from - GTK+. - (hook_option_menu): Implemented. Same complaint. - (get_toggle_value): Implemented. - (get_spin_button_value): Implemented. - (get_entry_value): Implemented. - (e_dialog_widget_hook_value): Function to hook a widget to the - variable it will modify. - (e_dialog_get_values): Function to feed the variables from a - dialog's widgets. - (e_dialog_xml_widget_hook_value): Function to hook a widget from - a Glade file. - -2000-05-23 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added e_write_file. - -2000-05-19 Federico Mena Quintero <federico@helixcode.com> - - * e-dialog-widgets.[ch]: New files with utilities for hooking up - widgets in Glade-generated dialogs. - - * Makefile.am (libeutil_la_SOURCES): Added e-dialog-widgets.[ch]. - -2000-05-19 Christopher James Lahey <clahey@helixcode.com> - - * e-gui-utils.c, e-gui-utils.h: Added e_container_foreach_leaf. - -2000-05-18 Christopher James Lahey <clahey@helixcode.com> - - * Makefile.am: Add imagesdir support. - - * e-gui-utils.c, e-gui-utils.h: Added e_create_image_widget for - glade use. - -2000-05-16 Christopher James Lahey <clahey@helixcode.com> - - * e-xml-utils.c: xmlGetProp appears to return malloced memory. - Thus we must free it. - -2000-05-15 Ettore Perazzoli <ettore@helixcode.com> - - * e-util.c (e_free_string_list): New function. - -2000-05-14 Christopher James Lahey <clahey@helixcode.com> - - * e-util.c, e-util.h: Added e_strdup_strip which returns a copy of - the string with the leading and trailing spaces removed. - -2000-05-11 NotZed <NotZed@HelixCode.com> - - * e-sexp.c (e_sexp_finalise): Destroy the g_scanner when cleaning up. - (e_sexp_finalise): Free symbol table on finalise. - -2000-05-09 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas.c: Remove reflow idle when being destroyed. - -2000-05-06 Christopher James Lahey <clahey@helixcode.com> - - * e-html-utils.c: Got rid of some warnings. - - * e-util.c, e-util.h: Added e_read_file which takes a filename and - returns a newly allocated string containing the contents of that - file. - -2000-05-03 Ettore Perazzoli <ettore@helixcode.com> - - * e-util.h: #include <glib.h> and <gtk/gtktypeutils.h>. - - * e-util.c (e_free_object_list): New utility function. - -2000-05-02 Damon Chaplin <damon@helixcode.com> - - * e-canvas.c (e_canvas_focus_in): - (e_canvas_focus_out): set and reset the GTK_HAS_FOCUS flag. We now get - focus_out events correctly. - -2000-05-02 NotZed <NotZed@HelixCode.com> - - * e-sexp.c (e_sexp_finalise): Free the parse tree if we have one. - (e_sexp_parse): If we already have a parse tree, free it. - -2000-05-02 Matt Loper <matt@helixcode.com> - - * Makefile.am: set G_LOG_DOMAIN. - -2000-05-01 Ettore Perazzoli <ettore@helixcode.com> - - * e-xml-utils.c, e-xml-utils.h: Constified all the functions. - -2000-04-27 Dan Winship <danw@helixcode.com> - - * e-html-utils.c (e_text_to_html): Moved here from the mailer, - since it's of general use, and the composer needs it too. - -2000-04-24 Miguel de Icaza <miguel@helixcode.com> - - * e-popup-menu.c: New file. Implements easy to use popup menus. - -2000-04-24 Matt Loper <matt@helixcode.com> - - * e-paned.c: New file. Makes a GtkPaned with more than two - children. - * e-paned.h: same. - - * Makefile.am: added e-paned.[ch]. - -2000-04-19 Christopher James Lahey <clahey@helixcode.com> - - * e-xml-utils.c, e-xml-utils.h: Added - e_xml_get_child_by_name_by_lang. - -2000-04-16 Anders Carlsson <andersca@gnu.org> - - * e-canvas.c (e_canvas_class_init): Add realize. - (e_canvas_realize): Set the back pixmap to NULL to reduce flicker. - -2000-04-14 Christopher James Lahey <clahey@helixcode.com> - - * e-xml-utils.c: Fixing a warning. - -2000-04-14 Christopher James Lahey <clahey@helixcode.com> - - * e-xml-utils.c: Add g_return_if_fails. - -2000-04-12 Miguel de Icaza <miguel@gnu.org> - - * e-cursors.c (e_cursor_get): Prevent next hacker to get bitten by this. - -2000-04-10 Christopher James Lahey <clahey@helixcode.com> - - * e-canvas.c: Added proper keyboard focus handling. - -2000-04-06 Matt Loper <matt@helixcode.com> - - * e-setup.c (e_setup_base_dir): Get/set Evolution's base directory - via gnome-config. - (mkdir_if_necessary): New function. - (e_setup_base_dir): Use mkdir_if_necessary(). - -2000-03-22 NotZed <NotZed@HelixCode.com> - - * e-util/e-sexp.h: Formatting cleanup. - -2000-03-07 NotZed <NotZed@HelixCode.com> - - * e-util/Makefile.am (libeutil_la_SOURCES): s-sexp.h -> e-sexp.h. - -2000-03-12 Christopher James Lahey <clahey@helixcode.com> - - * e-util/e-canvas.c, e-util/e-canvas.h: Fixed some bugs here to - speed up reflow and to make it fail less often. - -2000-03-10 Christopher James Lahey <clahey@helixcode.com> - - * e-util/e-canvas.c, e-util/e-canvas.h: Designed a new system for - doing hierarchical displays in the canvas. Adds an extra idle - loop to the canvas system. - -2000-03-05 Christopher James Lahey <clahey@helixcode.com> - - * e-util/e-xml-utils.c: Fixed e_xml_set_integer_prop_by_name. - -2000-03-04 Christopher James Lahey <clahey@helixcode.com> - - * e-util/e-xml-utils.c, e-util/e-xml-utils.h: Added - e_xml_set_integer_prop_by_name. - -2000-02-28 NotZed <NotZed@HelixCode.com> - - * e-util/e-sexp.[ch]: Added. moved from filter-sexp.[ch] - - * e-util/Makefile.am (libeutil_a_SOURCES): Add e-sexp. - (noinst_LTLIBRARIES): Changed to a libtool library. - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * e-util/e-xml-utils.c, e-util/e-xml-utils.h: Added - e_xml_get_integer_prop_by_name. - - * e-util/Makefile.am: Added e-util.c. - - * e-util/e-util.h: Added e-util.c functions. - - * e-util/e-util.c: New file for compare functions - -2000-02-24 Christopher James Lahey <clahey@helixcode.com> - - * e-util/e-canvas-utils.h: Fixed the comment at the top and added - #ifndef __E_CANVAS_UTILS__. - - * e-util/Makefile.am: Added e-xml-utils.c and - e-xml-utils.h. - - * e-util/e-xml-utils.h, e-util/e-xml-utils.c: Added files for some - xml utilities. - - * e-util/e-util.h: Added type EFocus which describes which - direction the focus will be coming from. - -2000-02-23 Dan Winship <danw@helixcode.com> - - * e-util/e-setup.c (e_setup_base_dir): Make ~/evolution mode 700 - rather than mode 600 (and use the symbolic name rather than the - number). - -2000-02-09 Christopher James Lahey <clahey@helixcode.com> - - * e-util/Makefile.am: Add canvas utilities to libeutil. - diff --git a/e-util/Makefile.am b/e-util/Makefile.am deleted file mode 100644 index 3ced0ed128..0000000000 --- a/e-util/Makefile.am +++ /dev/null @@ -1,97 +0,0 @@ -SUBDIRS = . ename - -imagesdir = $(datadir)/images/evolution - -INCLUDES = \ - $(DB3_CFLAGS) \ - -I$(top_srcdir) \ - $(GNOME_INCLUDEDIR) \ - $(EXTRA_GNOME_CFLAGS) \ - $(BONOBO_CONF_CFLAGS) \ - $(PISOCK_CFLAGS) \ - -DEVOLUTION_IMAGES=\""$(imagesdir)"\" \ - -DEVOLUTION_CATEGORY_ICONS=\""$(imagesdir)/categories"\" \ - -DG_LOG_DOMAIN=\"e-utils\" - -noinst_LTLIBRARIES = libeutil.la libeutil-static.la \ - libeconduit.la libeconduit-static.la \ - libedb3util.la - -libeutil_la_SOURCES = \ - e-bonobo-factory-util.c \ - e-bonobo-factory-util.h \ - e-categories-master-list-wombat.c \ - e-categories-master-list-wombat.h \ - e-categories-config.c \ - e-categories-config.h \ - e-corba-utils.c \ - e-corba-utils.h \ - e-dialog-utils.c \ - e-dialog-utils.h \ - e-dialog-widgets.c \ - e-dialog-widgets.h \ - e-gtk-utils.c \ - e-gtk-utils.h \ - e-gui-utils.c \ - e-gui-utils.h \ - e-host-utils.c \ - e-host-utils.h \ - e-html-utils.c \ - e-html-utils.h \ - e-iterator.c \ - e-iterator.h \ - e-list-iterator.c \ - e-list-iterator.h \ - e-list.c \ - e-list.h \ - e-memory.c \ - e-memory.h \ - e-mktemp.c \ - e-mktemp.h \ - e-msgport.c \ - e-msgport.h \ - e-path.c \ - e-path.h \ - e-request.c \ - e-request.h \ - e-sexp.c \ - e-sexp.h \ - e-time-utils.c \ - e-time-utils.h \ - e-unicode-i18n.c \ - e-unicode-i18n.h \ - e-url.c \ - e-url.h \ - md5-utils.c \ - md5-utils.h - -libeutil_la_LIBADD = $(GAL_LIBS) - -libeutil_static_la_SOURCES = $(libeutil_la_SOURCES) -libeutil_static_la_LIBADD = $(libeutil_la_LIBADD) -libeutil_static_la_LDFLAGS = --all-static - -pilot_sources = \ - e-pilot-map.c \ - e-pilot-map.h \ - e-pilot-util.c \ - e-pilot-util.h - -if ENABLE_PILOT_CONDUITS -pilot_compile = $(pilot_sources) -else -pilot_compile = -endif - -libeconduit_la_SOURCES = $(pilot_compile) - -libeconduit_static_la_SOURCES = $(libeconduit_la_SOURCES) -libeconduit_static_la_LDFLAGS = --all-static - -EXTRA_DIST = $(pilot_sources) - -libedb3util_la_SOURCES = \ - e-db3-utils.c \ - e-db3-utils.h \ - e-dbhash.c \ - e-dbhash.h diff --git a/e-util/e-bit-array.c b/e-util/e-bit-array.c deleted file mode 100644 index f79970ad22..0000000000 --- a/e-util/e-bit-array.c +++ /dev/null @@ -1,415 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-selection-model-array.c: a Selection Model - * - * Author: - * Christopher James Lahey <clahey@ximian.com> - * - * (C) 2000, 2001 Ximian, Inc. - */ -#include <config.h> -#include <gtk/gtksignal.h> -#include "e-bit-array.h" -#include "gal/util/e-util.h" - -#define EBA_CLASS(e) ((EBitArrayClass *)((GtkObject *)e)->klass) - -#define PARENT_TYPE (gtk_object_get_type ()) - -#define ONES ((guint32) 0xffffffff) - -#define BOX(n) ((n) / 32) -#define OFFSET(n) (31 - ((n) % 32)) -#define BITMASK(n) ((guint32)(((guint32) 0x1) << OFFSET((n)))) -#define BITMASK_LEFT(n) ((((n) % 32) == 0) ? 0 : (ONES << (32 - ((n) % 32)))) -#define BITMASK_RIGHT(n) ((guint32)(((guint32) ONES) >> ((n) % 32))) - -static GtkObjectClass *parent_class; - -static void -e_bit_array_insert_real(EBitArray *eba, int row) -{ - int box; - int i; - if(eba->bit_count >= 0) { - /* Add another word if needed. */ - if ((eba->bit_count & 0x1f) == 0) { - eba->data = g_renew(gint, eba->data, (eba->bit_count >> 5) + 1); - eba->data[eba->bit_count >> 5] = 0; - } - - /* The box is the word that our row is in. */ - box = BOX(row); - /* Shift all words to the right of our box right one bit. */ - for (i = eba->bit_count >> 5; i > box; i--) { - eba->data[i] = (eba->data[i] >> 1) | (eba->data[i - 1] << 31); - } - - /* Shift right half of box one bit to the right. */ - eba->data[box] = (eba->data[box] & BITMASK_LEFT(row)) | ((eba->data[box] & BITMASK_RIGHT(row)) >> 1); - eba->bit_count ++; - } -} - -static void -e_bit_array_delete_real(EBitArray *eba, int row, gboolean move_selection_mode) -{ - int box; - int i; - int last; - int selected = FALSE; - if(eba->bit_count >= 0) { - guint32 bitmask; - box = row >> 5; - last = eba->bit_count >> 5; - - /* Build bitmasks for the left and right half of the box */ - bitmask = BITMASK_RIGHT(row) >> 1; - if (move_selection_mode) - selected = e_bit_array_value_at(eba, row); - /* Shift right half of box one bit to the left. */ - eba->data[box] = (eba->data[box] & BITMASK_LEFT(row))| ((eba->data[box] & bitmask) << 1); - - /* Shift all words to the right of our box left one bit. */ - if (box < last) { - eba->data[box] &= eba->data[box + 1] >> 31; - - for (i = box + 1; i < last; i++) { - eba->data[i] = (eba->data[i] << 1) | (eba->data[i + 1] >> 31); - } - /* this over-runs our memory! */ - /*eba->data[i] = eba->data[i] << 1; */ - } - eba->bit_count --; - /* Remove the last word if not needed. */ - if ((eba->bit_count & 0x1f) == 0) { - eba->data = g_renew(gint, eba->data, eba->bit_count >> 5); - } - if (move_selection_mode && selected) { - e_bit_array_select_single_row (eba, row > 0 ? row - 1 : 0); - } - } -} - -/* FIXME : Improve efficiency here. */ -void -e_bit_array_delete(EBitArray *eba, int row, int count) -{ - int i; - for (i = 0; i < count; i++) - e_bit_array_delete_real(eba, row, FALSE); -} - -/* FIXME : Improve efficiency here. */ -void -e_bit_array_delete_single_mode(EBitArray *eba, int row, int count) -{ - int i; - for (i = 0; i < count; i++) - e_bit_array_delete_real(eba, row, TRUE); -} - -/* FIXME : Improve efficiency here. */ -void -e_bit_array_insert(EBitArray *eba, int row, int count) -{ - int i; - for (i = 0; i < count; i++) - e_bit_array_insert_real(eba, row); -} - -/* FIXME: Implement this more efficiently. */ -void -e_bit_array_move_row(EBitArray *eba, int old_row, int new_row) -{ - e_bit_array_delete_real(eba, old_row, FALSE); - e_bit_array_insert_real(eba, new_row); -} - -static void -eba_destroy (GtkObject *object) -{ - EBitArray *eba; - - eba = E_BIT_ARRAY (object); - - g_free(eba->data); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -/** - * e_selection_model_is_row_selected - * @selection: #EBitArray to check - * @n: The row to check - * - * This routine calculates whether the given row is selected. - * - * Returns: %TRUE if the given row is selected - */ -gboolean -e_bit_array_value_at (EBitArray *eba, - gint n) -{ - if (eba->bit_count < n || eba->bit_count == 0) - return 0; - else - return (eba->data[BOX(n)] >> OFFSET(n)) & 0x1; -} - -/** - * e_selection_model_foreach - * @selection: #EBitArray to traverse - * @callback: The callback function to call back. - * @closure: The closure - * - * This routine calls the given callback function once for each - * selected row, passing closure as the closure. - */ -void -e_bit_array_foreach (EBitArray *eba, - EForeachFunc callback, - gpointer closure) -{ - int i; - int last = (eba->bit_count + 31) / 32; - for (i = 0; i < last; i++) { - if (eba->data[i]) { - int j; - guint32 value = eba->data[i]; - for (j = 0; j < 32; j++) { - if (value & 0x80000000) { - callback(i * 32 + j, closure); - } - value <<= 1; - } - } - } -} - -/** - * e_selection_model_clear - * @selection: #EBitArray to clear - * - * This routine clears the selection to no rows selected. - */ -void -e_bit_array_clear(EBitArray *eba) -{ - g_free(eba->data); - eba->data = NULL; - eba->bit_count = 0; -} - -#define PART(x,n) (((x) & (0x01010101 << n)) >> n) -#define SECTION(x, n) (((x) >> (n * 8)) & 0xff) - -/** - * e_selection_model_selected_count - * @selection: #EBitArray to count - * - * This routine calculates the number of rows selected. - * - * Returns: The number of rows selected in the given model. - */ -gint -e_bit_array_selected_count (EBitArray *eba) -{ - gint count; - int i; - int last; - - if (!eba->data) - return 0; - - count = 0; - - last = BOX(eba->bit_count - 1); - - for (i = 0; i <= last; i++) { - int j; - guint32 thiscount = 0; - for (j = 0; j < 8; j++) - thiscount += PART(eba->data[i], j); - for (j = 0; j < 4; j++) - count += SECTION(thiscount, j); - } - - return count; -} - -/** - * e_selection_model_select_all - * @selection: #EBitArray to select all - * - * This routine selects all the rows in the given - * #EBitArray. - */ -void -e_bit_array_select_all (EBitArray *eba) -{ - int i; - - if (!eba->data) - eba->data = g_new0 (gint, (eba->bit_count + 31) / 32); - - for (i = 0; i < (eba->bit_count + 31) / 32; i ++) { - eba->data[i] = ONES; - } - - /* need to zero out the bits corresponding to the rows not - selected in the last full 32 bit mask */ - if (eba->bit_count % 32) { - int unselected_mask = 0; - int num_unselected_in_last_byte = 32 - eba->bit_count % 32; - - for (i = 0; i < num_unselected_in_last_byte; i ++) - unselected_mask |= 1 << i; - - eba->data[(eba->bit_count + 31) / 32 - 1] &= ~unselected_mask; - } -} - -/** - * e_selection_model_invert_selection - * @selection: #EBitArray to invert - * - * This routine inverts all the rows in the given - * #EBitArray. - */ -void -e_bit_array_invert_selection (EBitArray *eba) -{ - int i; - - if (!eba->data) - eba->data = g_new0 (gint, (eba->bit_count + 31) / 32); - - for (i = 0; i < (eba->bit_count + 31) / 32; i ++) { - eba->data[i] = ~eba->data[i]; - } -} - -int -e_bit_array_bit_count (EBitArray *eba) -{ - return eba->bit_count; -} - -gboolean -e_bit_array_cross_and (EBitArray *eba) -{ - int i; - for (i = 0; i < eba->bit_count / 32; i++) { - if (eba->data[i] != ONES) - return FALSE; - } - if ((eba->bit_count % 32) && ((eba->data[i] & BITMASK_LEFT(eba->bit_count)) != BITMASK_LEFT(eba->bit_count))) - return FALSE; - return TRUE; -} - -gboolean -e_bit_array_cross_or (EBitArray *eba) -{ - int i; - for (i = 0; i < eba->bit_count / 32; i++) { - if (eba->data[i] != 0) - return TRUE; - } - if ((eba->bit_count % 32) && ((eba->data[i] & BITMASK_LEFT(eba->bit_count)) != 0)) - return TRUE; - return FALSE; -} - -#define OPERATE(object, i,mask,grow) ((grow) ? (((object)->data[(i)]) |= ((guint32) ~(mask))) : (((object)->data[(i)]) &= (mask))) - -void -e_bit_array_change_one_row(EBitArray *eba, int row, gboolean grow) -{ - int i; - i = BOX(row); - - OPERATE(eba, i, ~BITMASK(row), grow); -} - -void -e_bit_array_change_range(EBitArray *eba, int start, int end, gboolean grow) -{ - int i, last; - if (start != end) { - i = BOX(start); - last = BOX(end); - - if (i == last) { - OPERATE(eba, i, BITMASK_LEFT(start) | BITMASK_RIGHT(end), grow); - } else { - OPERATE(eba, i, BITMASK_LEFT(start), grow); - if (grow) - for (i ++; i < last; i++) - eba->data[i] = ONES; - else - for (i ++; i < last; i++) - eba->data[i] = 0; - OPERATE(eba, i, BITMASK_RIGHT(end), grow); - } - } -} - -void -e_bit_array_select_single_row (EBitArray *eba, int row) -{ - int i; - for (i = 0; i < ((eba->bit_count + 31) / 32); i++) { - if (!((i == BOX(row) && eba->data[i] == BITMASK(row)) || - (i != BOX(row) && eba->data[i] == 0))) { - g_free(eba->data); - eba->data = g_new0(gint, (eba->bit_count + 31) / 32); - eba->data[BOX(row)] = BITMASK(row); - - break; - } - } -} - -void -e_bit_array_toggle_single_row (EBitArray *eba, int row) -{ - if (eba->data[BOX(row)] & BITMASK(row)) - eba->data[BOX(row)] &= ~BITMASK(row); - else - eba->data[BOX(row)] |= BITMASK(row); -} - - -static void -e_bit_array_init (EBitArray *eba) -{ - eba->data = NULL; - eba->bit_count = 0; -} - -static void -e_bit_array_class_init (EBitArrayClass *klass) -{ - GtkObjectClass *object_class; - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class = GTK_OBJECT_CLASS(klass); - - object_class->destroy = eba_destroy; -} - -E_MAKE_TYPE(e_bit_array, "EBitArray", EBitArray, - e_bit_array_class_init, e_bit_array_init, PARENT_TYPE); - -EBitArray * -e_bit_array_new (int count) -{ - EBitArray *eba = gtk_type_new (e_bit_array_get_type ()); - eba->bit_count = count; - eba->data = g_new0(gint, (eba->bit_count + 31) / 32); - return eba; -} diff --git a/e-util/e-bit-array.h b/e-util/e-bit-array.h deleted file mode 100644 index 7469413be3..0000000000 --- a/e-util/e-bit-array.h +++ /dev/null @@ -1,82 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_BIT_ARRAY_H_ -#define _E_BIT_ARRAY_H_ - -#include <gtk/gtkobject.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_BIT_ARRAY_TYPE (e_bit_array_get_type ()) -#define E_BIT_ARRAY(o) (GTK_CHECK_CAST ((o), E_BIT_ARRAY_TYPE, EBitArray)) -#define E_BIT_ARRAY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_BIT_ARRAY_TYPE, EBitArrayClass)) -#define E_IS_BIT_ARRAY(o) (GTK_CHECK_TYPE ((o), E_BIT_ARRAY_TYPE)) -#define E_IS_BIT_ARRAY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_BIT_ARRAY_TYPE)) - -#ifndef _E_FOREACH_FUNC_H_ -#define _E_FOREACH_FUNC_H_ -typedef void (*EForeachFunc) (int model_row, - gpointer closure); -#endif - -typedef struct { - GtkObject base; - - gint bit_count; - guint32 *data; -} EBitArray; - -typedef struct { - GtkObjectClass parent_class; -} EBitArrayClass; - - -GtkType e_bit_array_get_type (void); -EBitArray *e_bit_array_new (int count); - -gboolean e_bit_array_value_at (EBitArray *selection, - gint n); -void e_bit_array_foreach (EBitArray *selection, - EForeachFunc callback, - gpointer closure); -void e_bit_array_clear (EBitArray *selection); -gint e_bit_array_selected_count (EBitArray *selection); -void e_bit_array_select_all (EBitArray *selection); -void e_bit_array_invert_selection (EBitArray *selection); -int e_bit_array_bit_count (EBitArray *selection); -void e_bit_array_change_one_row (EBitArray *selection, - int row, - gboolean grow); -void e_bit_array_change_range (EBitArray *selection, - int start, - int end, - gboolean grow); -void e_bit_array_select_single_row (EBitArray *eba, - int row); -void e_bit_array_toggle_single_row (EBitArray *eba, - int row); - -void e_bit_array_insert (EBitArray *esm, - int row, - int count); -void e_bit_array_delete (EBitArray *esm, - int row, - int count); -void e_bit_array_delete_single_mode (EBitArray *esm, - int row, - int count); -void e_bit_array_move_row (EBitArray *esm, - int old_row, - int new_row); -gint e_bit_array_bit_count (EBitArray *esm); - -gboolean e_bit_array_cross_and (EBitArray *esm); -gboolean e_bit_array_cross_or (EBitArray *esm); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* _E_BIT_ARRAY_H_ */ diff --git a/e-util/e-bonobo-factory-util.c b/e-util/e-bonobo-factory-util.c deleted file mode 100644 index 9b67f64fd1..0000000000 --- a/e-util/e-bonobo-factory-util.c +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-bonobo-factory-util.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-bonobo-factory-util.h" - -#include <X11/Xlib.h> -#include <gdk/gdkprivate.h> - - -BonoboGenericFactory * -e_bonobo_generic_factory_multi_display_new (const char *factory_iid, - GnomeFactoryCallback factory_callback, - void *factory_callback_data) -{ - BonoboGenericFactory *factory; - char *registration_id; - char *display_string; - - g_return_val_if_fail (factory_iid != NULL, NULL); - g_return_val_if_fail (factory_callback != NULL, NULL); - - display_string = DisplayString (gdk_display); - registration_id = oaf_make_registration_id (factory_iid, display_string); - factory = bonobo_generic_factory_new_multi (registration_id, factory_callback, factory_callback_data); - - g_free (registration_id); - XFree (display_string); - - return factory; -} diff --git a/e-util/e-bonobo-factory-util.h b/e-util/e-bonobo-factory-util.h deleted file mode 100644 index e4aefd1f42..0000000000 --- a/e-util/e-bonobo-factory-util.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-bonobo-factory-util.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifndef E_BONOBO_FACTORY_UTIL_H -#define E_BONOBO_FACTORY_UTIL_H - -#include <bonobo/bonobo-generic-factory.h> - -BonoboGenericFactory *e_bonobo_generic_factory_multi_display_new (const char *factory_iid, - GnomeFactoryCallback factory_callback, - void *factory_callback_data); - -#endif diff --git a/e-util/e-categories-config.c b/e-util/e-categories-config.c deleted file mode 100644 index 72db8e572c..0000000000 --- a/e-util/e-categories-config.c +++ /dev/null @@ -1,204 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Categories configuration. - * - * Author: - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 2001, Ximian, Inc. - */ - -#include <libgnomeui/gnome-dialog.h> -#include <libgnome/gnome-i18n.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gal/widgets/e-unicode.h> -#include <gal/widgets/e-categories.h> -#include "e-categories-config.h" -#include "e-categories-master-list-wombat.h" - -static gboolean initialized = FALSE; -static ECategoriesMasterListWombat *ecmlw = NULL; -static GHashTable *icons_table = NULL; - -static void -initialize_categories_config (void) -{ - g_return_if_fail (initialized == FALSE); - - ecmlw = E_CATEGORIES_MASTER_LIST_WOMBAT (e_categories_master_list_wombat_new ()); - icons_table = g_hash_table_new (g_str_hash, g_str_equal); - /* FIXME: must free the two objects above when exiting */ - - initialized = TRUE; -} - -/** - * e_categories_config_get_color_for: - * @category: Category to get the color for. - * - * Returns the representation of the color configured for the given - * category - * - * Returns: An X color specification. - */ -const char * -e_categories_config_get_color_for (const char *category) -{ - int n; - - g_return_val_if_fail (category != NULL, NULL); - - if (!initialized) - initialize_categories_config (); - - for (n = 0; - n < e_categories_master_list_count (E_CATEGORIES_MASTER_LIST (ecmlw)); - n++) { - char *tmp_cat; - - tmp_cat = (char *) e_categories_master_list_nth (E_CATEGORIES_MASTER_LIST (ecmlw), n); - if (tmp_cat && !strcmp (tmp_cat, category)) - return e_categories_master_list_nth_color (E_CATEGORIES_MASTER_LIST (ecmlw), n); - } - - return NULL; /* not found */ -} - -/** - * e_categories_config_set_color_for - */ -void -e_categories_config_set_color_for (const char *category, const char *color) -{ - /* FIXME: implement */ -} - -/** - * e_categories_config_get_icon_for: - * @category: Category for which to get the icon. - * @icon: A pointer to where the pixmap will be returned. - * @mask: A pointer to where the mask will be returned. - * - * Returns the icon (and associated mask) configured for the - * given category. - */ -void -e_categories_config_get_icon_for (const char *category, GdkPixmap **pixmap, GdkBitmap **mask) -{ - char *icon_file; - GdkPixbuf *pixbuf; - GdkBitmap *tmp_mask; - - g_return_if_fail (pixmap != NULL); - - icon_file = (char *) e_categories_config_get_icon_file_for (category); - if (!icon_file) { - *pixmap = NULL; - if (mask != NULL) - *mask = NULL; - return; - } - - /* load the icon in our list */ - pixbuf = g_hash_table_lookup (icons_table, icon_file); - if (!pixbuf) { - pixbuf = gdk_pixbuf_new_from_file (icon_file); - if (!pixbuf) { - *pixmap = NULL; - if (mask != NULL) - *mask = NULL; - return; - } - - g_hash_table_insert (icons_table, g_strdup (icon_file), pixbuf); - } - - /* render the pixbuf to the pixmap and mask passed */ - gdk_pixbuf_render_pixmap_and_mask (pixbuf, pixmap, &tmp_mask, 1); - if (mask != NULL) - *mask = tmp_mask; -} - -/** - * e_categories_config_get_icon_file_for - * @category: Category for which to get the icon file - */ -const char * -e_categories_config_get_icon_file_for (const char *category) -{ - int n; - - g_return_val_if_fail (category != NULL, NULL); - - if (!initialized) - initialize_categories_config (); - - for (n = 0; - n < e_categories_master_list_count (E_CATEGORIES_MASTER_LIST (ecmlw)); - n++) { - char *tmp_cat; - - tmp_cat = (char *) e_categories_master_list_nth (E_CATEGORIES_MASTER_LIST (ecmlw), n); - if (tmp_cat && !strcmp (tmp_cat, category)) - return e_categories_master_list_nth_icon (E_CATEGORIES_MASTER_LIST (ecmlw), n); - } - - return NULL; /* not found */ -} - -/** - * e_categories_config_set_icon_for - * @category: Category for which to set the icon. - * @icon_file: Full path of the icon file. - */ -void -e_categories_config_set_icon_for (const char *category, const char *icon_file) -{ -} - -/** - * e_categories_config_open_dialog_for_entry: - * entry: A GtkEntry on which to get/set the categories list. - * - * This is a self-contained function that lets you open a popup dialog for - * the user to select a list of categories. - * - * The @entry parameter is used, at initialization time, as the list of - * initial categories that are selected in the categories selection dialog. - * Then, when the user commits its changes, the list of selected categories - * is put back on the entry widget. - */ -void -e_categories_config_open_dialog_for_entry (GtkEntry *entry) -{ - char *categories; - GnomeDialog *dialog; - int result; - - g_return_if_fail (entry != NULL); - g_return_if_fail (GTK_IS_ENTRY (entry)); - - if (!initialized) - initialize_categories_config (); - - categories = e_utf8_gtk_entry_get_text (GTK_ENTRY (entry)); - dialog = GNOME_DIALOG (e_categories_new (categories)); - - gtk_object_set (GTK_OBJECT (dialog), - "ecml", ecmlw, - NULL); - - /* run the dialog */ - result = gnome_dialog_run (dialog); - g_free (categories); - - if (result == 0) { - gtk_object_get (GTK_OBJECT (dialog), - "categories", &categories, - NULL); - e_utf8_gtk_entry_set_text (GTK_ENTRY (entry), categories); - g_free (categories); - } - - gtk_object_destroy (GTK_OBJECT (dialog)); -} diff --git a/e-util/e-categories-config.h b/e-util/e-categories-config.h deleted file mode 100644 index 0b798e466e..0000000000 --- a/e-util/e-categories-config.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Categories configuration. - * - * Author: - * Rodrigo Moya <rodrigo@ximian.com> - * - * Copyright 2001, Ximian, Inc. - */ - -#ifndef __E_CATEGORIES_CONFIG_H__ -#define __E_CATEGORIES_CONFIG_H__ - -#include <glib.h> -#include <gdk/gdk.h> -#include <gtk/gtkentry.h> -#include <libgnome/gnome-defs.h> - -BEGIN_GNOME_DECLS - -const char *e_categories_config_get_color_for (const char *category); -void e_categories_config_set_color_for (const char *category, const char *color); - -void e_categories_config_get_icon_for (const char *category, - GdkPixmap **icon, - GdkBitmap **mask); -const char *e_categories_config_get_icon_file_for (const char *category); -void e_categories_config_set_icon_for (const char *category, - const char *pixmap_file); - -void e_categories_config_open_dialog_for_entry (GtkEntry *entry); - -END_GNOME_DECLS - -#endif diff --git a/e-util/e-categories-master-list-wombat.c b/e-util/e-categories-master-list-wombat.c deleted file mode 100644 index 8ee2981e8f..0000000000 --- a/e-util/e-categories-master-list-wombat.c +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-categories-master-list.c: the master list of categories. - * - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * (C) 1999, 2000 Ximian, Inc. - */ -#include <config.h> - -#include "e-categories-master-list-wombat.h" -#include "e-categories-config.h" - -#include <tree.h> -#include <parser.h> -#include <gal/util/e-i18n.h> -#include <gal/util/e-xml-utils.h> -#include <bonobo-conf/bonobo-config-database.h> -#include <bonobo/bonobo-moniker-util.h> -#include <bonobo/bonobo-exception.h> -#include <bonobo/bonobo-listener.h> -#include <bonobo/bonobo-event-source.h> - -#define PARENT_TYPE e_categories_master_list_array_get_type () - -#define d(x) - -struct _ECategoriesMasterListWombatPriv { - Bonobo_ConfigDatabase db; - Bonobo_EventSource_ListenerId listener_id; -}; - -static ECategoriesMasterListArrayClass *parent_class; - -static void -ecmlw_load (ECategoriesMasterListWombat *ecmlw) -{ - char *string; - gboolean def; - - string = bonobo_config_get_string_with_default - (ecmlw->priv->db, - "General/CategoryMasterList", - NULL, - &def); - - /* parse the XML string */ - if (!def) { - e_categories_master_list_array_from_string (E_CATEGORIES_MASTER_LIST_ARRAY (ecmlw), - string); - } - - g_print ("load: %s\n", string?string:"(nil)"); - - g_free (string); -} - -static void -ecmlw_save (ECategoriesMasterListWombat *ecmlw) -{ - char *string; - CORBA_Environment ev; - - string = e_categories_master_list_array_to_string (E_CATEGORIES_MASTER_LIST_ARRAY (ecmlw)); - - g_print ("save: %s\n", string); - - CORBA_exception_init (&ev); - - bonobo_config_set_string (ecmlw->priv->db, - "General/CategoryMasterList", - string, - &ev); - - CORBA_exception_free (&ev); - - g_free (string); -} - -/** - * ecmlw_commit: - * @ecml: the master list to remove from. - */ -static void -ecmlw_commit (ECategoriesMasterList *ecml) -{ - ECategoriesMasterListWombat *ecmlw = E_CATEGORIES_MASTER_LIST_WOMBAT (ecml); - - ((ECategoriesMasterListClass *) parent_class)->commit (ecml); - - ecmlw_save (ecmlw); -} - - -/** - * ecmlw_reset: - * @ecml: the master list to reset. - */ -static void -ecmlw_reset (ECategoriesMasterList *ecml) -{ - ECategoriesMasterListWombat *ecmlw = E_CATEGORIES_MASTER_LIST_WOMBAT (ecml); - - ((ECategoriesMasterListClass *) parent_class)->reset (ecml); - - ecmlw_save (ecmlw); -} - -static void -ecmlw_destroy (GtkObject *object) -{ - ECategoriesMasterListWombat *ecmlw = E_CATEGORIES_MASTER_LIST_WOMBAT (object); - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - /* remove the listener */ - - bonobo_event_source_client_remove_listener (ecmlw->priv->db, - ecmlw->priv->listener_id, - &ev); - bonobo_object_release_unref (ecmlw->priv->db, &ev); - - CORBA_exception_free (&ev); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - - -static void -ecmlw_class_init (GtkObjectClass *object_class) -{ - ECategoriesMasterListClass *ecml_class = E_CATEGORIES_MASTER_LIST_CLASS(object_class); - - parent_class = gtk_type_class (PARENT_TYPE); - - ecml_class->commit = ecmlw_commit; - - ecml_class->reset = ecmlw_reset ; - - object_class->destroy = ecmlw_destroy; -} - -static void -property_change_cb (BonoboListener *listener, - char *event_name, - CORBA_any *any, - CORBA_Environment *ev, - gpointer user_data) -{ - ecmlw_load (user_data); -} - -static void -ecmlw_init (ECategoriesMasterListWombat *ecmlw) -{ - CORBA_Environment ev; - - CORBA_exception_init (&ev); - - ecmlw->priv = g_new (ECategoriesMasterListWombatPriv, 1); - ecmlw->priv->db = bonobo_get_object ("wombat:", "Bonobo/ConfigDatabase", &ev); - - /* add a listener */ - ecmlw->priv->listener_id = - bonobo_event_source_client_add_listener (ecmlw->priv->db, property_change_cb, - NULL, &ev, ecmlw); - if (BONOBO_EX (&ev)) { - CORBA_exception_free (&ev); - return; - } - - CORBA_exception_free (&ev); - - ecmlw_load (ecmlw); -} - -guint -e_categories_master_list_wombat_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo info = { - "ECategoriesMasterListWombat", - sizeof (ECategoriesMasterListWombat), - sizeof (ECategoriesMasterListWombatClass), - (GtkClassInitFunc) ecmlw_class_init, - (GtkObjectInitFunc) ecmlw_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -ECategoriesMasterList * -e_categories_master_list_wombat_new (void) -{ - return E_CATEGORIES_MASTER_LIST (gtk_type_new (e_categories_master_list_wombat_get_type ())); -} diff --git a/e-util/e-categories-master-list-wombat.h b/e-util/e-categories-master-list-wombat.h deleted file mode 100644 index a6fe2a04ff..0000000000 --- a/e-util/e-categories-master-list-wombat.h +++ /dev/null @@ -1,35 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_CATEGORIES_MASTER_LIST_WOMBAT_H_ -#define _E_CATEGORIES_MASTER_LIST_WOMBAT_H_ - -#include <gal/widgets/e-categories-master-list-array.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_CATEGORIES_MASTER_LIST_WOMBAT_TYPE (e_categories_master_list_wombat_get_type ()) -#define E_CATEGORIES_MASTER_LIST_WOMBAT(o) (GTK_CHECK_CAST ((o), E_CATEGORIES_MASTER_LIST_WOMBAT_TYPE, ECategoriesMasterListWombat)) -#define E_CATEGORIES_MASTER_LIST_WOMBAT_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_CATEGORIES_MASTER_LIST_WOMBAT_TYPE, ECategoriesMasterListWombatClass)) -#define E_IS_CATEGORIES_MASTER_LIST_WOMBAT(o) (GTK_CHECK_TYPE ((o), E_CATEGORIES_MASTER_LIST_WOMBAT_TYPE)) -#define E_IS_CATEGORIES_MASTER_LIST_WOMBAT_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_CATEGORIES_MASTER_LIST_WOMBAT_TYPE)) - -typedef struct _ECategoriesMasterListWombatPriv ECategoriesMasterListWombatPriv; - -typedef struct { - ECategoriesMasterListArray base; - ECategoriesMasterListWombatPriv *priv; -} ECategoriesMasterListWombat; - -typedef struct { - ECategoriesMasterListArrayClass parent_class; -} ECategoriesMasterListWombatClass; - -GtkType e_categories_master_list_wombat_get_type (void); -ECategoriesMasterList *e_categories_master_list_wombat_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_CATEGORIES_MASTER_LIST_WOMBAT_H_ */ diff --git a/e-util/e-corba-utils.c b/e-util/e-corba-utils.c deleted file mode 100644 index 8245b91986..0000000000 --- a/e-util/e-corba-utils.c +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-html-utils.c -* - * Copyright (C) 2000 Ximian, Inc. - * Author: Ettore Perazzoli <ettore@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-corba-utils.h" - - -const CORBA_char * -e_safe_corba_string (const char *s) -{ - if (s == NULL) - return (CORBA_char *) ""; - - return s; -} diff --git a/e-util/e-corba-utils.h b/e-util/e-corba-utils.h deleted file mode 100644 index 1281f86876..0000000000 --- a/e-util/e-corba-utils.h +++ /dev/null @@ -1,30 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-corba-utils.h - * - * Copyright (C) 2000 Ximian, Inc. - * Author: Ettore Perazzoli <ettore@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef E_CORBA_UTILS_H -#define E_CORBA_UTILS_H - -#include <orb/orbit.h> - -const CORBA_char *e_safe_corba_string (const char *s); - -#endif diff --git a/e-util/e-db3-utils.c b/e-util/e-db3-utils.c deleted file mode 100644 index c1da265453..0000000000 --- a/e-util/e-db3-utils.c +++ /dev/null @@ -1,185 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -#include "config.h" - -#include "e-db3-utils.h" - -#include <db.h> - -#include <errno.h> -#include <sys/stat.h> -#include <fcntl.h> -#include <unistd.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-util.h> - -#if DB_VERSION_MAJOR != 3 || \ - DB_VERSION_MINOR != 1 || \ - DB_VERSION_PATCH != 17 -#error Including wrong DB3. Need libdb 3.1.17. -#endif - -static char * -get_check_filename (const char *filename) -{ - return g_strdup_printf ("%s-upgrading", filename); -} - -static char * -get_copy_filename (const char *filename) -{ - return g_strdup_printf ("%s-copy", filename); -} - -static int -cp_file (const char *src, const char *dest) -{ - int i; - int o; - char buffer[1024]; - int length; - int place; - - i = open (src, O_RDONLY); - if (i == -1) - return -1; - o = creat (dest, S_IREAD | S_IWRITE); - if (o == -1) { - close (i); - return -1; - } - while (1) { - length = read (i, &buffer, sizeof (buffer)); - - if (length == 0) - break; - - if (length == -1) { - if (errno == EINTR) - continue; - else { - close (i); - close (o); - unlink (dest); - return -1; - } - } - - place = 0; - while (length != 0) { - int count; - count = write (o, buffer + place, length); - if (count == -1) { - if (errno == EINTR) - continue; - else { - close (i); - close (o); - unlink (dest); - return -1; - } - } - - length -= count; - place += count; - } - } - if (close (i)) - return -1; - if (close (o)) - return -1; - return 0; -} - -static int -touch_file (const char *file) -{ - int o; - o = creat (file, S_IREAD | S_IWRITE); - if (o == -1) - return -1; - - if (close (o) == -1) - return -1; - - return 0; -} - -static int -resume_upgrade (const char *filename, const char *copy_filename, const char *check_filename) -{ - DB *db; - int ret_val; - - ret_val = db_create (&db, NULL, 0); - - if (ret_val == 0) - ret_val = cp_file (copy_filename, filename); - - if (ret_val == 0) - ret_val = db->upgrade (db, filename, 0); - - if (ret_val == 0) - ret_val = unlink (check_filename); - if (ret_val == 0) - ret_val = unlink (copy_filename); - - db->close (db, 0); - - return ret_val; -} - -int -e_db3_utils_maybe_recover (const char *filename) -{ - int ret_val = 0; - char *copy_filename; - char *check_filename; - - copy_filename = get_copy_filename (filename); - check_filename = get_check_filename (filename); - - if (g_file_exists (check_filename)) { - ret_val = resume_upgrade(filename, copy_filename, check_filename); - } else if (g_file_exists (copy_filename)) { - unlink (copy_filename); - } - - g_free (copy_filename); - g_free (check_filename); - return ret_val; -} - -int -e_db3_utils_upgrade_format (const char *filename) -{ - char *copy_filename; - char *check_filename; - DB *db; - int ret_val; - - ret_val = db_create (&db, NULL, 0); - if (ret_val != 0) - return ret_val; - - copy_filename = get_copy_filename (filename); - check_filename = get_check_filename (filename); - - ret_val = cp_file (filename, copy_filename); - - if (ret_val == 0) - ret_val = touch_file (check_filename); - if (ret_val == 0) - ret_val = db->upgrade (db, filename, 0); - if (ret_val == 0) - ret_val = unlink (check_filename); - - if (ret_val == 0) - ret_val = unlink (copy_filename); - - db->close (db, 0); - - g_free (check_filename); - g_free (copy_filename); - return ret_val; -} diff --git a/e-util/e-db3-utils.h b/e-util/e-db3-utils.h deleted file mode 100644 index a574e59178..0000000000 --- a/e-util/e-db3-utils.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * db3 utils. - * - * Author: - * Chris Lahey <clahey@ximian.com> - * - * Copyright 2001, Ximian, Inc. - */ - -#ifndef __E_DB3_UTILS_H__ -#define __E_DB3_UTILS_H__ - -#include <glib.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -int e_db3_utils_maybe_recover (const char *filename); -int e_db3_utils_upgrade_format (const char *filename); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* ! __E_DB3_UTILS_H__ */ - diff --git a/e-util/e-dbhash.c b/e-util/e-dbhash.c deleted file mode 100644 index 7ac5dd0d8c..0000000000 --- a/e-util/e-dbhash.c +++ /dev/null @@ -1,225 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Author: - * JP Rosevear (jpr@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#include <config.h> - -#include "e-dbhash.h" - -#include <string.h> -#include <fcntl.h> -#include <db.h> -#include "md5-utils.h" - -#if DB_VERSION_MAJOR != 3 || \ - DB_VERSION_MINOR != 1 || \ - DB_VERSION_PATCH != 17 -#error Including wrong DB3. Need libdb 3.1.17. -#endif - -struct _EDbHashPrivate -{ - DB *db; -}; - -EDbHash * -e_dbhash_new (const char *filename) -{ - EDbHash *edbh; - DB *db; - int rv; - - int major, minor, patch; - - db_version (&major, &minor, &patch); - - if (major != 3 || - minor != 1 || - patch != 17) { - g_warning ("Wrong version of libdb."); - return NULL; - } - - /* Attempt to open the database */ - rv = db_create (&db, NULL, 0); - if (rv != 0) { - return NULL; - } - - rv = db->open (db, filename, NULL, DB_HASH, 0, 0666); - if (rv != 0) { - rv = db->open (db, filename, NULL, DB_HASH, DB_CREATE, 0666); - - if (rv != 0) - return NULL; - } - - edbh = g_new (EDbHash, 1); - edbh->priv = g_new (EDbHashPrivate, 1); - edbh->priv->db = db; - - return edbh; -} - -static void -string_to_dbt(const char *str, DBT *dbt) -{ - memset (dbt, 0, sizeof (DBT)); - dbt->data = (void*)str; - dbt->size = strlen (str) + 1; -} - -static void -md5_to_dbt(const char str[16], DBT *dbt) -{ - memset (dbt, 0, sizeof (DBT)); - dbt->data = (void*)str; - dbt->size = 16; -} - -void -e_dbhash_add (EDbHash *edbh, const gchar *key, const gchar *data) -{ - DB *db; - DBT dkey; - DBT ddata; - guchar local_hash[16]; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - g_return_if_fail (edbh->priv->db != NULL); - g_return_if_fail (key != NULL); - g_return_if_fail (data != NULL); - - db = edbh->priv->db; - - /* Key dbt */ - string_to_dbt (key, &dkey); - - /* Data dbt */ - md5_get_digest (data, strlen (data), local_hash); - md5_to_dbt (local_hash, &ddata); - - /* Add to database */ - db->put (db, NULL, &dkey, &ddata, 0); -} - -void -e_dbhash_remove (EDbHash *edbh, const char *key) -{ - DB *db; - DBT dkey; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - g_return_if_fail (key != NULL); - - db = edbh->priv->db; - - /* Key dbt */ - string_to_dbt (key, &dkey); - - /* Remove from database */ - db->del (db, NULL, &dkey, 0); -} - -void -e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data) -{ - DB *db; - DBT dkey; - DBT ddata; - DBC *dbc; - int db_error = 0; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - g_return_if_fail (func != NULL); - - db = edbh->priv->db; - - db_error = db->cursor (db, NULL, &dbc, 0); - - if (db_error != 0) { - return; - } - - db_error = dbc->c_get(dbc, &dkey, &ddata, DB_FIRST); - - while (db_error == 0) { - (*func) ((const char *)dkey.data, user_data); - - db_error = dbc->c_get(dbc, &dkey, &ddata, DB_NEXT); - } - dbc->c_close (dbc); -} - -EDbHashStatus -e_dbhash_compare (EDbHash *edbh, const char *key, const char *compare_data) -{ - DB *db; - DBT dkey; - DBT ddata; - guchar compare_hash[16]; - - g_return_val_if_fail (edbh != NULL, FALSE); - g_return_val_if_fail (edbh->priv != NULL, FALSE); - g_return_val_if_fail (key != NULL, FALSE); - g_return_val_if_fail (compare_hash != NULL, FALSE); - - db = edbh->priv->db; - - /* Key dbt */ - string_to_dbt (key, &dkey); - - /* Lookup in database */ - memset (&ddata, 0, sizeof (DBT)); - db->get (db, NULL, &dkey, &ddata, 0); - - /* Compare */ - if (ddata.data) { - md5_get_digest (compare_data, strlen (compare_data), compare_hash); - - if (memcmp (ddata.data, compare_hash, sizeof (guchar) * 16)) - return E_DBHASH_STATUS_DIFFERENT; - } else { - return E_DBHASH_STATUS_NOT_FOUND; - } - - return E_DBHASH_STATUS_SAME; -} - -void -e_dbhash_write (EDbHash *edbh) -{ - DB *db; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - - db = edbh->priv->db; - - /* Flush database to disk */ - db->sync (db, 0); -} - -void -e_dbhash_destroy (EDbHash *edbh) -{ - DB *db; - - g_return_if_fail (edbh != NULL); - g_return_if_fail (edbh->priv != NULL); - - db = edbh->priv->db; - - /* Close datbase */ - db->close (db, 0); - - g_free (edbh->priv); - g_free (edbh); -} diff --git a/e-util/e-dbhash.h b/e-util/e-dbhash.h deleted file mode 100644 index 9772a60c41..0000000000 --- a/e-util/e-dbhash.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Writes hashes that go to/from disk in db form. Hash keys are strings - * - * Author: - * JP Rosevear (jpr@ximian.com) - * - * Copyright 2000, Ximian, Inc. - */ - -#ifndef __E_DBHASH_H__ -#define __E_DBHASH_H__ - -#include <glib.h> - -typedef enum { - E_DBHASH_STATUS_SAME, - E_DBHASH_STATUS_DIFFERENT, - E_DBHASH_STATUS_NOT_FOUND, -} EDbHashStatus; - -typedef struct _EDbHash EDbHash; -typedef struct _EDbHashPrivate EDbHashPrivate; - -struct _EDbHash -{ - EDbHashPrivate *priv; -}; - -typedef void (*EDbHashFunc) (const char *key, gpointer user_data); - -EDbHash *e_dbhash_new (const char *filename); - -void e_dbhash_add (EDbHash *edbh, const char *key, const char *data); -void e_dbhash_remove (EDbHash *edbh, const char *key); - -EDbHashStatus e_dbhash_compare (EDbHash *edbh, const char *key, const char *compare_data); -void e_dbhash_foreach_key (EDbHash *edbh, EDbHashFunc func, gpointer user_data); - -void e_dbhash_write (EDbHash *edbh); - -void e_dbhash_destroy (EDbHash *edbh); - -#endif /* ! __E_DBHASH_H__ */ - diff --git a/e-util/e-dialog-utils.c b/e-util/e-dialog-utils.c deleted file mode 100644 index 0a6bf13386..0000000000 --- a/e-util/e-dialog-utils.c +++ /dev/null @@ -1,149 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-dialog-utils.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Authors: - * Michael Meeks <michael@ximian.com> - * Ettore Perazzoli <ettore@ximian.com> - */ - -#include "e-dialog-utils.h" - -#include "widgets/misc/e-bonobo-widget.h" - -#include <gdk/gdkx.h> -#include <gdk/gdkprivate.h> -#include <gdk/gdk.h> - -#include <gtk/gtksignal.h> - -#include <bonobo/bonobo-control.h> -#include <bonobo/bonobo-property-bag.h> - - -#define TRANSIENT_DATA_ID "e-dialog:transient" - - -static void -transient_realize_callback (GtkWidget *widget) -{ - GdkWindow *window; - - window = gtk_object_get_data (GTK_OBJECT (widget), TRANSIENT_DATA_ID); - g_assert (window != NULL); - - gdk_window_set_transient_for (GTK_WIDGET (widget)->window, window); -} - -static void -transient_unrealize_callback (GtkWidget *widget) -{ - GdkWindow *window; - - window = gtk_object_get_data (GTK_OBJECT (widget), TRANSIENT_DATA_ID); - g_assert (window != NULL); - - gdk_property_delete (window, gdk_atom_intern ("WM_TRANSIENT_FOR", FALSE)); -} - -static void -transient_destroy_callback (GtkWidget *widget) -{ - GdkWindow *window; - - window = gtk_object_get_data (GTK_OBJECT (widget), "transient"); - if (window != NULL) - gdk_window_unref (window); -} - -static void -set_transient_for_gdk (GtkWindow *window, - GdkWindow *parent) -{ - g_return_if_fail (window != NULL); - g_return_if_fail (gtk_object_get_data (GTK_OBJECT (window), TRANSIENT_DATA_ID) == NULL); - - gdk_window_ref (parent); /* FIXME? */ - - gtk_object_set_data (GTK_OBJECT (window), TRANSIENT_DATA_ID, parent); - - if (GTK_WIDGET_REALIZED (window)) - gdk_window_set_transient_for (GTK_WIDGET (window)->window, parent); - - gtk_signal_connect (GTK_OBJECT (window), "realize", - GTK_SIGNAL_FUNC (transient_realize_callback), NULL); - - gtk_signal_connect (GTK_OBJECT (window), "unrealize", - GTK_SIGNAL_FUNC (transient_unrealize_callback), NULL); - - gtk_signal_connect (GTK_OBJECT (window), "destroy", - GTK_SIGNAL_FUNC (transient_destroy_callback), NULL); -} - - -/** - * e_set_dialog_parent: - * @dialog: - * @parent_widget: - * - * This sets the parent for @dialog to be @parent_widget. Unlike - * gtk_window_set_parent(), this doesn't need @parent_widget to be the actual - * toplevel, and also works if @parent_widget is been embedded as a Bonobo - * control by an out-of-process container. - **/ -void -e_set_dialog_parent (GtkWindow *dialog, - GtkWidget *parent_widget) -{ - Bonobo_PropertyBag property_bag; - GtkWidget *toplevel; - GdkWindow *gdk_window; - CORBA_char *id; - guint32 xid; - - g_return_if_fail (dialog != NULL); - g_return_if_fail (GTK_IS_WINDOW (dialog)); - g_return_if_fail (parent_widget != NULL); - g_return_if_fail (GTK_IS_WIDGET (parent_widget)); - - toplevel = gtk_widget_get_toplevel (parent_widget); - if (toplevel == NULL) - return; - - if (! BONOBO_IS_CONTROL (toplevel)) { - if (GTK_IS_WINDOW (toplevel)) - gtk_window_set_transient_for (dialog, GTK_WINDOW (toplevel)); - return; - } - - property_bag = bonobo_control_get_ambient_properties (BONOBO_CONTROL (toplevel), NULL); - if (property_bag == CORBA_OBJECT_NIL) - return; - - id = bonobo_property_bag_client_get_value_string (property_bag, E_BONOBO_WIDGET_TOPLEVEL_PROPERTY_ID, NULL); - if (id == NULL) - return; - - xid = strtol (id, NULL, 10); - - g_warning ("Got id `%s' -> %x", id, xid); - - gdk_window = gdk_window_foreign_new (xid); - set_transient_for_gdk (dialog, gdk_window); -} diff --git a/e-util/e-dialog-utils.h b/e-util/e-dialog-utils.h deleted file mode 100644 index 578ea0d585..0000000000 --- a/e-util/e-dialog-utils.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-dialog-utils.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli <ettore@ximian.com> - */ - -#ifndef E_DIALOG_UTILS_H -#define E_DIALOG_UTILS_H - -#include <gtk/gtkwindow.h> -#include <gtk/gtkwidget.h> - -void e_set_dialog_parent (GtkWindow *dialog, - GtkWidget *parent_widget); - -#endif diff --git a/e-util/e-dialog-widgets.c b/e-util/e-dialog-widgets.c deleted file mode 100644 index 5bf3d3c844..0000000000 --- a/e-util/e-dialog-widgets.c +++ /dev/null @@ -1,832 +0,0 @@ -/* Evolution internal utilities - Glade dialog widget utilities - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <config.h> - -#include <math.h> -#include <string.h> -#include <time.h> -#include <gtk/gtkmenu.h> -#include <gtk/gtkmenuitem.h> -#include <gtk/gtkoptionmenu.h> -#include <gtk/gtkradiobutton.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkspinbutton.h> -#include <libgnomeui/gnome-dateedit.h> -#include <libgnomeui/gnome-propertybox.h> -#include <gal/widgets/e-unicode.h> - -#include "e-dialog-widgets.h" - - - -/* A widget, a pointer to the variable it will modify, and extra information */ -typedef struct { - GtkWidget *widget; - gpointer value_var; - gpointer info; -} WidgetHook; - -/* Hook information for a complete dialog */ -typedef struct { - GSList *whooks; -} DialogHooks; - - - -/* Destroy handler for the dialog; frees the dialog hooks */ -static void -dialog_destroy_cb (GtkObject *dialog, gpointer data) -{ - DialogHooks *hooks; - - hooks = data; - - g_slist_free (hooks->whooks); - hooks->whooks = NULL; - - g_free (hooks); - gtk_object_set_data (dialog, "dialog-hooks", NULL); -} - -/* Ensures that the dialog has the necessary attached data to store the widget - * hook information. - */ -static DialogHooks * -get_dialog_hooks (GtkWidget *dialog) -{ - DialogHooks *hooks; - - hooks = gtk_object_get_data (GTK_OBJECT (dialog), "dialog-hooks"); - if (!hooks) { - hooks = g_new0 (DialogHooks, 1); - gtk_object_set_data (GTK_OBJECT (dialog), "dialog-hooks", hooks); - gtk_signal_connect (GTK_OBJECT (dialog), "destroy", - GTK_SIGNAL_FUNC (dialog_destroy_cb), hooks); - } - - return hooks; -} - -/* Converts an mapped value to the appropriate index in an item group. The - * values for the items are provided as a -1-terminated array. - */ -static int -value_to_index (const int *value_map, int value) -{ - int i; - - for (i = 0; value_map[i] != -1; i++) - if (value_map[i] == value) - return i; - - return -1; -} - -/* Converts an index in an item group to the appropriate mapped value. See the - * function above. - */ -static int -index_to_value (const int *value_map, int index) -{ - int i; - - /* We do this the hard way, i.e. not as a simple array reference, to - * check for correctness. - */ - - for (i = 0; value_map[i] != -1; i++) - if (i == index) - return value_map[i]; - - return -1; -} - -/* Callback for the "toggled" signal of toggle buttons */ -static void -toggled_cb (GtkToggleButton *toggle, gpointer data) -{ - GnomePropertyBox *pbox; - - pbox = GNOME_PROPERTY_BOX (data); - - /* For radio buttons, we only notify the property box if the button is - * active, because we'll get one call for each of the changed buttons in - * the radio group. - */ - if (!GTK_IS_RADIO_BUTTON (toggle) || toggle->active) - gnome_property_box_changed (pbox); -} - -/* Hooks a radio button group */ -static void -hook_radio (GtkWidget *dialog, GtkRadioButton *radio, gpointer value_var, gpointer info) -{ - GSList *group; - GSList *l; - int *value; - const int *value_map; - - group = gtk_radio_button_group (radio); - - /* Set the value */ - - value = (int *) value_var; - value_map = (const int *) info; - - e_dialog_radio_set (GTK_WIDGET (radio), *value, value_map); - - /* Hook to changed */ - - if (GNOME_IS_PROPERTY_BOX (dialog)) - for (l = group; l; l = l->next) - gtk_signal_connect (GTK_OBJECT (l->data), "toggled", - GTK_SIGNAL_FUNC (toggled_cb), dialog); -} - -/* Gets the value of a radio button group */ -static void -get_radio_value (GtkRadioButton *radio, gpointer value_var, gpointer info) -{ - int *value; - const int *value_map; - - value = (int *) value_var; - value_map = (const int *) info; - - *value = e_dialog_radio_get (GTK_WIDGET (radio), value_map); -} - -/* Callback for the "activate" signal of menu items */ -static void -activate_cb (GtkMenuItem *item, gpointer data) -{ - GnomePropertyBox *pbox; - - pbox = GNOME_PROPERTY_BOX (data); - gnome_property_box_changed (pbox); -} - -/* Hooks an option menu */ -static void -hook_option_menu (GtkWidget *dialog, GtkOptionMenu *omenu, gpointer value_var, gpointer info) -{ - int *value; - const int *value_map; - - /* Set the value */ - - value = (int *) value_var; - value_map = (const int *) info; - - e_dialog_option_menu_set (GTK_WIDGET (omenu), *value, value_map); - - /* Hook to changed */ - - if (GNOME_IS_PROPERTY_BOX (dialog)) { - GtkMenu *menu; - GList *l; - - menu = GTK_MENU (gtk_option_menu_get_menu (omenu)); - - for (l = GTK_MENU_SHELL (menu)->children; l; l = l->next) - gtk_signal_connect (GTK_OBJECT (l->data), "activate", - GTK_SIGNAL_FUNC (activate_cb), dialog); - } -} - -/* Gets the value of an option menu */ -static void -get_option_menu_value (GtkOptionMenu *omenu, gpointer value_var, gpointer info) -{ - int *value; - const int *value_map; - - value = (int *) value_var; - value_map = (const int *) info; - - *value = e_dialog_option_menu_get (GTK_WIDGET (omenu), value_map); -} - -/* Hooks a toggle button */ -static void -hook_toggle (GtkWidget *dialog, GtkToggleButton *toggle, gpointer value_var, gpointer info) -{ - gboolean *value; - - /* Set the value */ - - value = (gboolean *) value_var; - e_dialog_toggle_set (GTK_WIDGET (toggle), *value); - - /* Hook to changed */ - - if (GNOME_IS_PROPERTY_BOX (dialog)) - gtk_signal_connect (GTK_OBJECT (toggle), "toggled", - GTK_SIGNAL_FUNC (toggled_cb), dialog); -} - -/* Gets the value of a toggle button */ -static void -get_toggle_value (GtkToggleButton *toggle, gpointer value_var, gpointer info) -{ - gboolean *value; - - value = (gboolean *) value_var; - *value = e_dialog_toggle_get (GTK_WIDGET (toggle)); -} - -/* Callback for the "value_changed" signal of the adjustment of a spin button */ -static void -value_changed_cb (GtkAdjustment *adj, gpointer data) -{ - GnomePropertyBox *pbox; - - pbox = GNOME_PROPERTY_BOX (data); - gnome_property_box_changed (pbox); -} - -/* Hooks a spin button */ -static void -hook_spin_button (GtkWidget *dialog, GtkSpinButton *spin, gpointer value_var, gpointer info) -{ - double *value; - GtkAdjustment *adj; - - /* Set the value */ - - value = (double *) value_var; - e_dialog_spin_set (GTK_WIDGET (spin), *value); - - /* Hook to changed */ - - adj = gtk_spin_button_get_adjustment (spin); - - if (GNOME_IS_PROPERTY_BOX (dialog)) - gtk_signal_connect (GTK_OBJECT (adj), "value_changed", - GTK_SIGNAL_FUNC (value_changed_cb), dialog); -} - -/* Gets the value of a spin button */ -static void -get_spin_button_value (GtkSpinButton *spin, gpointer value_var, gpointer info) -{ - double *value; - - value = (double *) value_var; - *value = e_dialog_spin_get_double (GTK_WIDGET (spin)); -} - -/* Callback for the "changed" signal of a GtkEditable widget */ -static void -changed_cb (GtkEditable *editable, gpointer data) -{ - GnomePropertyBox *pbox; - - pbox = GNOME_PROPERTY_BOX (data); - gnome_property_box_changed (pbox); -} - -/* Hooks a GtkEditable widget */ -static void -hook_editable (GtkWidget *dialog, GtkEditable *editable, gpointer value_var, gpointer info) -{ - char **value; - - /* Set the value */ - - value = (char **) value_var; - - e_dialog_editable_set (GTK_WIDGET (editable), *value); - - /* Hook to changed */ - - if (GNOME_IS_PROPERTY_BOX (dialog)) - gtk_signal_connect (GTK_OBJECT (editable), "changed", - GTK_SIGNAL_FUNC (changed_cb), dialog); -} - -/* Gets the value of a GtkEditable widget */ -static void -get_editable_value (GtkEditable *editable, gpointer value_var, gpointer data) -{ - char **value; - - value = (char **) value_var; - if (*value) - g_free (*value); - - *value = e_dialog_editable_get (GTK_WIDGET (editable)); -} - -/** - * e_dialog_editable_set: - * @widget: A #GtkEditable widget. - * @value: String value. - * - * Sets the string value inside a #GtkEditable-derived widget. - **/ -void -e_dialog_editable_set (GtkWidget *widget, const char *value) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_EDITABLE (widget)); - - gtk_editable_delete_text (GTK_EDITABLE (widget), 0, -1); - - if (value) { - gint pos; - - pos = 0; - e_utf8_gtk_editable_insert_text (GTK_EDITABLE (widget), value, strlen (value), &pos); - } -} - -/** - * e_dialog_editable_get: - * @widget: A #GtkEditable widget. - * - * Queries the string value inside a #GtkEditable-derived widget. - * - * Return value: String value. You should free it when you are done with it. - * This function can return NULL if the string could not be converted from - * GTK+'s encoding into UTF8. - **/ -char * -e_dialog_editable_get (GtkWidget *widget) -{ - g_return_val_if_fail (widget != NULL, NULL); - g_return_val_if_fail (GTK_IS_EDITABLE (widget), NULL); - - return e_utf8_gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); -} - -/** - * e_dialog_radio_set: - * @widget: A #GtkRadioButton in a radio button group. - * @value: Enumerated value. - * @value_map: Map from enumeration values to array indices. - * - * Sets the selected item in a radio group. The specified @widget can be any of - * the #GtkRadioButtons in the group. Each radio button should correspond to an - * enumeration value; the specified @value will be mapped to an integer from - * zero to the number of items in the group minus 1 by using a mapping table - * specified in @value_map. The last element in this table should be -1. Thus - * a table to map three possible interpolation values to integers could be - * specified as { NEAREST_NEIGHBOR, BILINEAR, HYPERBOLIC, -1 }. - **/ -void -e_dialog_radio_set (GtkWidget *widget, int value, const int *value_map) -{ - GSList *group; - int i; - GSList *l; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_RADIO_BUTTON (widget)); - g_return_if_fail (value_map != NULL); - - group = gtk_radio_button_group (GTK_RADIO_BUTTON (widget)); - - i = value_to_index (value_map, value); - if (i != -1) { - /* Groups are built by prepending items, so the list ends up in reverse - * order; we need to flip the index around. - */ - i = g_slist_length (group) - i - 1; - - l = g_slist_nth (group, i); - if (!l) - g_message ("e_dialog_radio_set(): could not find index %d in radio group!", - i); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l->data), TRUE); - } else - g_message ("e_dialog_radio_set(): could not find value %d in value map!", - value); -} - -/** - * e_dialog_radio_get: - * @widget: A #GtkRadioButton in a radio button group. - * @value_map: Map from enumeration values to array indices. - * - * Queries the selected item in a #GtkRadioButton group. Please read the - * description of e_dialog_radio_set() to see how @value_map maps enumeration - * values to button indices. - * - * Return value: Enumeration value which corresponds to the selected item in the - * radio group. - **/ -int -e_dialog_radio_get (GtkWidget *widget, const int *value_map) -{ - GSList *group; - GSList *l; - int i; - int v; - - g_return_val_if_fail (widget != NULL, -1); - g_return_val_if_fail (GTK_IS_RADIO_BUTTON (widget), -1); - g_return_val_if_fail (value_map != NULL, -1); - - group = gtk_radio_button_group (GTK_RADIO_BUTTON (widget)); - - for (i = 0, l = group; l; l = l->next, i++) { - widget = GTK_WIDGET (l->data); - - if (GTK_TOGGLE_BUTTON (widget)->active) - break; - } - - if (!l) - g_assert_not_reached (); - - /* Groups are built by prepending items, so the list ends up in reverse - * order; we need to flip the index around. - */ - i = g_slist_length (group) - i - 1; - - v = index_to_value (value_map, i); - if (v == -1) { - g_message ("e_dialog_radio_get(): could not find index %d in value map!", i); - return -1; - } - - return v; -} - -/** - * e_dialog_toggle_set: - * @widget: A #GtkToggleButton. - * @value: Toggle value. - * - * Sets the value of a #GtkToggleButton-derived widget. This should not be used - * for radio buttons; it is more convenient to use use e_dialog_radio_set() - * instead. - **/ -void -e_dialog_toggle_set (GtkWidget *widget, gboolean value) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_TOGGLE_BUTTON (widget)); - - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (widget), value); -} - -/** - * e_dialog_toggle_get: - * @widget: A #GtkToggleButton. - * - * Queries the value of a #GtkToggleButton-derived widget. This should not be - * used for radio buttons; it is more convenient to use e_dialog_radio_get() - * instead. - * - * Return value: Toggle value. - **/ -gboolean -e_dialog_toggle_get (GtkWidget *widget) -{ - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GTK_IS_TOGGLE_BUTTON (widget), FALSE); - - return GTK_TOGGLE_BUTTON (widget)->active; -} - -/** - * e_dialog_spin_set: - * @widget: A #GtkSpinButton. - * @value: Numeric value. - * - * Sets the value of a #GtkSpinButton widget. - **/ -void -e_dialog_spin_set (GtkWidget *widget, double value) -{ - GtkAdjustment *adj; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_SPIN_BUTTON (widget)); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)); - - adj->value = value; - gtk_signal_emit_by_name (GTK_OBJECT (adj), "value_changed"); -} - -/** - * e_dialog_spin_get_double: - * @widget: A #GtkSpinButton. - * - * Queries the floating-point value of a #GtkSpinButton widget. - * - * Return value: Numeric value. - **/ -double -e_dialog_spin_get_double (GtkWidget *widget) -{ - GtkAdjustment *adj; - - g_return_val_if_fail (widget != NULL, 0.0); - g_return_val_if_fail (GTK_IS_SPIN_BUTTON (widget), 0.0); - - adj = gtk_spin_button_get_adjustment (GTK_SPIN_BUTTON (widget)); - return adj->value; -} - -/** - * e_dialog_spin_get_int: - * @widget: A #GtkSpinButton. - * - * Queries the integer value of a #GtkSpinButton widget. - * - * Return value: Numeric value. - **/ -int -e_dialog_spin_get_int (GtkWidget *widget) -{ - double value; - - g_return_val_if_fail (widget != NULL, -1); - g_return_val_if_fail (GTK_IS_SPIN_BUTTON (widget), -1); - - value = e_dialog_spin_get_double (widget); - return (int) floor (value); -} - -/** - * e_dialog_option_menu_set: - * @widget: A #GtkOptionMenu. - * @value: Enumerated value. - * @value_map: Map from enumeration values to array indices. - * - * Sets the selected item in a #GtkOptionMenu. Please read the description of - * e_dialog_radio_set() to see how @value_map maps enumeration values to item - * indices. - **/ -void -e_dialog_option_menu_set (GtkWidget *widget, int value, const int *value_map) -{ - int i; - - g_return_if_fail (widget != NULL); - g_return_if_fail (GTK_IS_OPTION_MENU (widget)); - g_return_if_fail (value_map != NULL); - - i = value_to_index (value_map, value); - - if (i != -1) - gtk_option_menu_set_history (GTK_OPTION_MENU (widget), i); - else - g_message ("e_dialog_option_menu_set(): could not find value %d in value map!", - value); -} - -/** - * e_dialog_option_menu_get: - * @widget: A #GtkOptionMenu. - * @value_map: Map from enumeration values to array indices. - * - * Queries the selected item in a #GtkOptionMenu. Please read the description - * of e_dialog_radio_set() to see how @value_map maps enumeration values to item - * indices. - * - * Return value: Enumeration value which corresponds to the selected item in the - * option menu. - **/ -int -e_dialog_option_menu_get (GtkWidget *widget, const int *value_map) -{ - GtkMenu *menu; - GtkWidget *active; - GList *children; - GList *l; - int i; - int v; - - g_return_val_if_fail (widget != NULL, -1); - g_return_val_if_fail (GTK_IS_OPTION_MENU (widget), -1); - g_return_val_if_fail (value_map != NULL, -1); - - menu = GTK_MENU (gtk_option_menu_get_menu (GTK_OPTION_MENU (widget))); - - active = gtk_menu_get_active (menu); - g_assert (active != NULL); - - children = GTK_MENU_SHELL (menu)->children; - - for (i = 0, l = children; l; l = l->next, i++) { - if (GTK_WIDGET (l->data) == active) - break; - } - - if (!l) - g_assert_not_reached (); - - v = index_to_value (value_map, i); - if (v == -1) { - g_message ("e_dialog_option_menu_get(): could not find index %d in value map!", i); - return -1; - } - - return v; -} - -/** - * e_dialog_dateedit_set: - * @widget: A #GnomeDateEdit widget. - * @t: Date/time value. - * - * Sets the value of a #GnomeDateEdit widget. - **/ -void -e_dialog_dateedit_set (GtkWidget *widget, time_t t) -{ - g_return_if_fail (widget != NULL); - g_return_if_fail (GNOME_IS_DATE_EDIT (widget)); - - gnome_date_edit_set_time (GNOME_DATE_EDIT (widget), t); -} - -/** - * e_dialog_dateedit_get: - * @widget: A #GnomeDateEdit widget. - * - * Queries the value of a #GnomeDateEdit widget. - * - * Return value: Date/time value. - **/ -time_t -e_dialog_dateedit_get (GtkWidget *widget) -{ - g_return_val_if_fail (widget != NULL, -1); - g_return_val_if_fail (GNOME_IS_DATE_EDIT (widget), -1); - - return gnome_date_edit_get_date (GNOME_DATE_EDIT (widget)); -} - -/** - * e_dialog_widget_hook_value: - * @dialog: Dialog box in which the @widget lives in. - * @widget: A widget that will control a variable. - * @value_var: Pointer to the variable that the @widget will control. - * @info: NULL for most widgets, or an integer value map array (see - * e_dialog_radio_set() for details). - * - * Hooks a widget from a dialog box to the variable it will modify. Supported - * widgets are: #GtkEditable (char *), #GtkRadioButton (int/value_map pair; see - * e_dialog_radio_set() for more information), #GtkTogglebutton (gboolean), - * #GtkSpinButton (double), #GtkOptionMenu (int/value_map pair), and - * #GnomeDateEdit (time_t). - * - * A pointer to the appropriate variable to modify should be passed in @value_var. - * For values that take a value_map array as well, it should be passed in @info. - * - * The widgets within a dialog that are hooked with this function will set their - * respective variables only when e_dialog_get_values() is called. The typical - * use is to call that function in the handler for the "OK" button of a dialog - * box. - * - * In addition, if the specified @dialog is a #GnomePropertyBox, the widgets wil - * automatically turn on the "Apply" button of the property box when they are - * modified by the user. - * - * Return value: TRUE if the type of the specified @widget is supported, FALSE - * otherwise. - **/ -gboolean -e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget, - gpointer value_var, gpointer info) -{ - DialogHooks *hooks; - WidgetHook *wh; - - g_return_val_if_fail (dialog != NULL, FALSE); - g_return_val_if_fail (widget != NULL, FALSE); - g_return_val_if_fail (GTK_IS_WIDGET (widget), FALSE); - g_return_val_if_fail (value_var != NULL, FALSE); - - hooks = get_dialog_hooks (dialog); - - /* First check if it is a "group" widget, like a radio button or an - * option menu. Then we check for normal ungrouped widgets. - */ - - if (GTK_IS_RADIO_BUTTON (widget)) - hook_radio (dialog, GTK_RADIO_BUTTON (widget), value_var, info); - else if (GTK_IS_OPTION_MENU (widget)) - hook_option_menu (dialog, GTK_OPTION_MENU (widget), value_var, info); - else if (GTK_IS_TOGGLE_BUTTON (widget)) - hook_toggle (dialog, GTK_TOGGLE_BUTTON (widget), value_var, info); - else if (GTK_IS_SPIN_BUTTON (widget)) - hook_spin_button (dialog, GTK_SPIN_BUTTON (widget), value_var, info); - else if (GTK_IS_EDITABLE (widget)) - hook_editable (dialog, GTK_EDITABLE (widget), value_var, info); - else - return FALSE; - - wh = g_new (WidgetHook, 1); - wh->widget = widget; - wh->value_var = value_var; - wh->info = info; - - hooks->whooks = g_slist_prepend (hooks->whooks, wh); - - return TRUE; -} - -/** - * e_dialog_get_values: - * @dialog: A dialog box whose widgets have been hooked to the appropriate - * variables with e_dialog_widget_hook_value(). - * - * Makes every widget in a @dialog that was hooked with - * e_dialog_widget_hook_value() apply its value to its corresponding variable. - * The typical usage is to call this function in the handler for the "OK" button - * of a dialog box. - **/ -void -e_dialog_get_values (GtkWidget *dialog) -{ - DialogHooks *hooks; - GSList *l; - - g_return_if_fail (dialog != NULL); - - hooks = get_dialog_hooks (dialog); - - for (l = hooks->whooks; l; l = l->next) { - WidgetHook *wh; - - wh = l->data; - - if (GTK_IS_RADIO_BUTTON (wh->widget)) - get_radio_value (GTK_RADIO_BUTTON (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_OPTION_MENU (wh->widget)) - get_option_menu_value (GTK_OPTION_MENU (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_TOGGLE_BUTTON (wh->widget)) - get_toggle_value (GTK_TOGGLE_BUTTON (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_SPIN_BUTTON (wh->widget)) - get_spin_button_value (GTK_SPIN_BUTTON (wh->widget), wh->value_var, wh->info); - else if (GTK_IS_EDITABLE (wh->widget)) - get_editable_value (GTK_EDITABLE (wh->widget), wh->value_var, wh->info); - else - g_assert_not_reached (); - } -} - -/** - * e_dialog_xml_widget_hook_value: - * @xml: Glade XML description of a dialog box. - * @dialog: Dialog box in which the widget lives in. - * @widget_name: Name of the widget in the Glade XML data. - * @value_var: Pointer to the variable that the widget will control. - * @info: NULL for most widgets, or an integer value map array (see - * e_dialog_radio_set() for details). - * - * Similar to e_dialog_widget_hook_value(), but uses the widget from a #GladeXML - * data structure. - * - * Return value: TRUE if the type of the specified widget is supported, FALSE - * otherwise. - **/ -gboolean -e_dialog_xml_widget_hook_value (GladeXML *xml, GtkWidget *dialog, const char *widget_name, - gpointer value_var, gpointer info) -{ - GtkWidget *widget; - - g_return_val_if_fail (xml != NULL, FALSE); - g_return_val_if_fail (GLADE_IS_XML (xml), FALSE); - g_return_val_if_fail (dialog != NULL, FALSE); - g_return_val_if_fail (widget_name != NULL, FALSE); - g_return_val_if_fail (value_var != NULL, FALSE); - - widget = glade_xml_get_widget (xml, widget_name); - if (!widget) { - g_message ("e_dialog_xml_widget_hook_value(): could not find widget `%s' in " - "Glade data!", widget_name); - return FALSE; - } - - return e_dialog_widget_hook_value (dialog, widget, value_var, info); -} diff --git a/e-util/e-dialog-widgets.h b/e-util/e-dialog-widgets.h deleted file mode 100644 index 2a27705d3c..0000000000 --- a/e-util/e-dialog-widgets.h +++ /dev/null @@ -1,60 +0,0 @@ -/* Evolution internal utilities - Glade dialog widget utilities - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 2000 Ximian, Inc. - * - * Author: Federico Mena-Quintero <federico@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef E_DIALOG_WIDGETS_H -#define E_DIALOG_WIDGETS_H - -#include <time.h> -#include <glade/glade.h> - - - -void e_dialog_editable_set (GtkWidget *widget, const char *value); -char *e_dialog_editable_get (GtkWidget *widget); - -void e_dialog_radio_set (GtkWidget *widget, int value, const int *value_map); -int e_dialog_radio_get (GtkWidget *widget, const int *value_map); - -void e_dialog_toggle_set (GtkWidget *widget, gboolean value); -gboolean e_dialog_toggle_get (GtkWidget *widget); - -void e_dialog_spin_set (GtkWidget *widget, double value); -double e_dialog_spin_get_double (GtkWidget *widget); -int e_dialog_spin_get_int (GtkWidget *widget); - -void e_dialog_option_menu_set (GtkWidget *widget, int value, const int *value_map); -int e_dialog_option_menu_get (GtkWidget *widget, const int *value_map); - -void e_dialog_dateedit_set (GtkWidget *widget, time_t t); -time_t e_dialog_dateedit_get (GtkWidget *widget); - -gboolean e_dialog_widget_hook_value (GtkWidget *dialog, GtkWidget *widget, - gpointer value_var, gpointer info); - -void e_dialog_get_values (GtkWidget *dialog); - -gboolean e_dialog_xml_widget_hook_value (GladeXML *xml, GtkWidget *dialog, const char *widget_name, - gpointer value_var, gpointer info); - - - -#endif diff --git a/e-util/e-gtk-utils.c b/e-util/e-gtk-utils.c deleted file mode 100644 index a1230ad774..0000000000 --- a/e-util/e-gtk-utils.c +++ /dev/null @@ -1,161 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-gtk-utils.c - * - * Copyright (C) 2000 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <gtk/gtksignal.h> -#include "e-gtk-utils.h" - - -/* (Cut and pasted from Gtk.) */ - -typedef struct DisconnectInfo { - unsigned int signal_handler; - - GtkObject *object1; - unsigned int disconnect_handler1; - - GtkObject *object2; - unsigned int disconnect_handler2; -} DisconnectInfo; - -static unsigned int -alive_disconnecter (GtkObject *object, - DisconnectInfo *info) -{ - g_assert (info != NULL); - - gtk_signal_disconnect (info->object1, info->disconnect_handler1); - gtk_signal_disconnect (info->object1, info->signal_handler); - gtk_signal_disconnect (info->object2, info->disconnect_handler2); - - g_free (info); - - return 0; -} - -/** - * e_gtk_signal_connect_full_while_alive: - * @object: - * @name: - * @func: - * @marshal: - * @data: - * @destroy_func: - * @object_signal: - * @after: - * @alive_object: - * - * Connect a signal like `gtk_signal_connect_while_alive()', but with full - * params like `gtk_signal_connect_full()'. - **/ -void -e_gtk_signal_connect_full_while_alive (GtkObject *object, - const char *name, - GtkSignalFunc func, - GtkCallbackMarshal marshal, - void *data, - GtkDestroyNotify destroy_func, - gboolean object_signal, - gboolean after, - GtkObject *alive_object) -{ - DisconnectInfo *info; - - g_return_if_fail (GTK_IS_OBJECT (object)); - g_return_if_fail (name != NULL); - g_return_if_fail (func != NULL); - g_return_if_fail (GTK_IS_OBJECT (alive_object)); - - info = g_new (DisconnectInfo, 1); - - info->signal_handler = gtk_signal_connect_full (object, name, - func, marshal, data, - destroy_func, - object_signal, after); - - info->object1 = object; - info->disconnect_handler1 = gtk_signal_connect (object, "destroy", - GTK_SIGNAL_FUNC (alive_disconnecter), info); - - info->object2 = alive_object; - info->disconnect_handler2 = gtk_signal_connect (alive_object, "destroy", - GTK_SIGNAL_FUNC (alive_disconnecter), info); -} - -/** - * gtk_radio_button_get_nth_selected: - * @button: A GtkRadioButton - * - * Returns an int indicating which button in the radio group is - * toggled active. NOTE: radio group item numbering starts at zero. - **/ -int -gtk_radio_button_get_nth_selected (GtkRadioButton *button) -{ - GSList *l; - int i, c; - - g_return_val_if_fail (button != NULL, 0); - g_return_val_if_fail (GTK_IS_RADIO_BUTTON (button), 0); - - c = g_slist_length (button->group); - - for (i = 0, l = button->group; l; l = l->next, i++) { - GtkRadioButton *tmp = l->data; - - if (GTK_TOGGLE_BUTTON (tmp)->active) - return c - i - 1; - } - - return 0; -} - -/** - * gtk_radio_button_select_nth: - * @button: A GtkRadioButton - * @n: Which button to select from the group - * - * Select the Nth item of a radio group. NOTE: radio group items - * start numbering from zero - **/ -void -gtk_radio_button_select_nth (GtkRadioButton *button, int n) -{ - GSList *l; - int len; - - g_return_if_fail (button != NULL); - g_return_if_fail (GTK_IS_RADIO_BUTTON (button)); - - len = g_slist_length (button->group); - - if ((n <= len) && (n > 0)) { - l = g_slist_nth (button->group, len - n - 1); - gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON (l->data), TRUE); - } - -} diff --git a/e-util/e-gtk-utils.h b/e-util/e-gtk-utils.h deleted file mode 100644 index cf67b832a6..0000000000 --- a/e-util/e-gtk-utils.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-gtk-utils.c - * - * Copyright (C) 2000 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifndef E_GTK_UTILS_H -#define E_GTK_UTILS_H - -#include <gtk/gtkobject.h> -#include <gtk/gtkradiobutton.h> - -void e_gtk_signal_connect_full_while_alive (GtkObject *object, - const char *name, - GtkSignalFunc func, - GtkCallbackMarshal marshal, - void *data, - GtkDestroyNotify destroy_func, - gboolean object_signal, - gboolean after, - GtkObject *alive_object); - - -/* GtkRadioButton API extensions */ -void gtk_radio_button_select_nth (GtkRadioButton *button, int n); -int gtk_radio_button_get_nth_selected (GtkRadioButton *button); - -#endif diff --git a/e-util/e-gui-utils.c b/e-util/e-gui-utils.c deleted file mode 100644 index 70007cf07a..0000000000 --- a/e-util/e-gui-utils.c +++ /dev/null @@ -1,66 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * GUI utility functions - * - * Author: - * Miguel de Icaza (miguel@ximian.com) - * - * (C) 1999 Miguel de Icaza - * (C) 2000 Ximian, Inc. - */ -#include <config.h> - -#include "e-gui-utils.h" - -#include <glib.h> -#include <gtk/gtksignal.h> -#include <gtk/gtkalignment.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-util.h> -#include <gdk-pixbuf/gdk-pixbuf.h> -#include <gdk-pixbuf/gnome-canvas-pixbuf.h> - -GtkWidget *e_create_image_widget(gchar *name, - gchar *string1, gchar *string2, - gint int1, gint int2) -{ - char *filename; - GdkPixbuf *pixbuf; - double width, height; - GtkWidget *canvas, *alignment; - if (string1) { - if (*string1 == '/') - filename = g_strdup(string1); - else - filename = g_concat_dir_and_file(EVOLUTION_IMAGES, string1); - pixbuf = gdk_pixbuf_new_from_file(filename); - width = gdk_pixbuf_get_width(pixbuf); - height = gdk_pixbuf_get_height(pixbuf); - - canvas = gnome_canvas_new_aa(); - GTK_OBJECT_UNSET_FLAGS(GTK_WIDGET(canvas), GTK_CAN_FOCUS); - gnome_canvas_item_new(gnome_canvas_root(GNOME_CANVAS(canvas)), - gnome_canvas_pixbuf_get_type(), - "pixbuf", pixbuf, - NULL); - - alignment = gtk_widget_new(gtk_alignment_get_type(), - "child", canvas, - "xalign", (double) 0, - "yalign", (double) 0, - "xscale", (double) 0, - "yscale", (double) 0, - NULL); - - gtk_widget_set_usize(canvas, width, height); - - gdk_pixbuf_unref(pixbuf); - - gtk_widget_show(canvas); - gtk_widget_show(alignment); - g_free(filename); - - return alignment; - } else - return NULL; -} diff --git a/e-util/e-gui-utils.h b/e-util/e-gui-utils.h deleted file mode 100644 index 9cbb64fbf6..0000000000 --- a/e-util/e-gui-utils.h +++ /dev/null @@ -1,8 +0,0 @@ -#ifndef E_GUI_UTILS_H -#define E_GUI_UTILS_H - -#include <gtk/gtkwidget.h> - -GtkWidget *e_create_image_widget (gchar *name, gchar *string1, gchar *string2, gint int1, gint int2); - -#endif /* E_GUI_UTILS_H */ diff --git a/e-util/e-host-utils.c b/e-util/e-host-utils.c deleted file mode 100644 index 968063f398..0000000000 --- a/e-util/e-host-utils.c +++ /dev/null @@ -1,155 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-host-utils.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Chris Toshok - */ - -#include <config.h> -#include <glib.h> -#include "e-host-utils.h" -#include <string.h> -#include <stdlib.h> -#include <stdio.h> -#include <errno.h> - -G_LOCK_DEFINE_STATIC (gethost_mutex); - -/** - * e_gethostbyname_r: - * @name: the host to resolve - * @host: a buffer pointing to a struct hostent to use for storage - * @buf: a buffer to use for hostname storage - * @buflen: the size of @buf - * @herr: a pointer to a variable to store an error code in - * - * Resolves the hostname @name, in a hopefully-reentrant fashion. - * - * Return value: 0 on success, ERANGE if @buflen is too small, - * "something else" otherwise (in which case *@herr will be set to - * one of the gethostbyname() error codes). - **/ -int -e_gethostbyname_r (const char *name, struct hostent *host, - char *buf, int buflen, int *herr) -{ -#ifdef HAVE_GETHOSTBYNAME_R -#ifdef GETHOSTBYNAME_R_FIVE_ARGS - if (gethostbyname_r(name, host, buf, buflen, herr)) - return 0; - else - return errno; -#else - struct hostent *hp; - int retval; - - retval = gethostbyname_r(name, host, buf, buflen, &hp, herr); - if (hp != NULL) - *herr = 0; - return retval; -#endif -#else - int i; - char *p; - struct hostent *h; - int req_length; - int num_aliases = 0, num_addrs = 0; - - G_LOCK (gethost_mutex); - - h = gethostbyname (name); - - if (!h) { - *herr = h_errno; - G_UNLOCK (gethost_mutex); - return -1; - } - - /* check to make sure we have enough room in our buffer */ - req_length = 0; - if (h->h_aliases) { - for (i = 0; h->h_aliases[i]; i ++) - req_length += strlen (h->h_aliases[i]) + 1; - num_aliases = i; - } - if (h->h_addr_list) { - for (i = 0; h->h_addr_list[i]; i ++) - req_length += h->h_length; - num_addrs = i; - } - - req_length += sizeof (char*) * (num_aliases + 1); - req_length += sizeof (char*) * (num_addrs + 1); - req_length += strlen (h->h_name) + 1; - - if (buflen < req_length) { - *herr = ERANGE; - G_UNLOCK (gethost_mutex); - return ERANGE; - } - - /* we store the alias/addr pointers in the buffer - figure out - their addresses here. */ - p = buf; - if (num_aliases) { - host->h_aliases = (char**)p; - p += sizeof (char*) * (num_aliases + 1); - } - else - host->h_aliases = NULL; - if (num_addrs) { - host->h_addr_list = (char**)p; - p += sizeof(char*) * (num_addrs + 1); - } - else - host->h_addr_list = NULL; - - /* copy the host name into the buffer */ - host->h_name = p; - strcpy (p, h->h_name); - p += strlen (h->h_name) + 1; - host->h_addrtype = h->h_addrtype; - host->h_length = h->h_length; - - /* copy the aliases/addresses into the buffer, and assign the - pointers into the hostent */ - *p = 0; - if (num_aliases) { - for (i = 0; i < num_aliases; i ++) { - strcpy (p, h->h_aliases[i]); - host->h_aliases[i] = p; - p += strlen (h->h_aliases[i]); - } - host->h_aliases[num_aliases] = NULL; - } - - if (num_addrs) { - for (i = 0; i < num_addrs; i ++) { - memcpy (p, h->h_addr_list[i], h->h_length); - host->h_addr_list[i] = p; - p += h->h_length; - } - host->h_addr_list[num_addrs] = NULL; - } - - G_UNLOCK (gethost_mutex); - - return 0; -#endif -} diff --git a/e-util/e-host-utils.h b/e-util/e-host-utils.h deleted file mode 100644 index 948209f112..0000000000 --- a/e-util/e-host-utils.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-host-utils.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Chris Toshok - */ - -#ifndef E_HOST_UTILS_H -#define E_HOST_UTILS_H - -#include <sys/types.h> -#include <netdb.h> - -/* gethostbyname_r implementation that works for systems without a - native gethostbyname_r. if you use this, you must make sure to - *only* use this - it can't even coexist with naked calls to - gethostbyname (even if they exist in libraries.) yes, this loses - in many ways. blame your local OS developer. */ -int e_gethostbyname_r (const char *name, struct hostent *host, char *buf, int buflen, int *herr); - -#endif /* E_HOST_UTILS_H */ diff --git a/e-util/e-html-utils.c b/e-util/e-html-utils.c deleted file mode 100644 index a2759f91a8..0000000000 --- a/e-util/e-html-utils.c +++ /dev/null @@ -1,417 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-html-utils.c - * Copyright (C) 2000 Ximian, Inc. - * Author: Dan Winship <danw@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <ctype.h> -#include <stdio.h> -#include <string.h> -#include <glib.h> -#include <gal/unicode/gunicode.h> - -#include "e-html-utils.h" - -static char * -check_size (char **buffer, int *buffer_size, char *out, int len) -{ - if (out + len + 1> *buffer + *buffer_size) { - int index = out - *buffer; - - *buffer_size = MAX (index + len + 1, *buffer_size * 2); - *buffer = g_realloc (*buffer, *buffer_size); - out = *buffer + index; - } - return out; -} - -/* 1 = non-email-address chars: ()<>@,;:\"[] */ -/* 2 = trailing garbage: ,.!?;:>)]}`'-_ */ -static int special_chars[] = { - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* nul - 0x0f */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* 0x10 - 0x1f */ - 1, 2, 1, 0, 0, 0, 0, 2, 1, 3, 0, 0, 3, 2, 2, 0, /* sp - / */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 3, 3, 1, 0, 3, 2, /* 0 - ? */ - 1, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* @ - O */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 1, 1, 3, 0, 2, /* P - _ */ - 2, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, /* ` - o */ - 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 2, 0, 0 /* p - del */ -}; - -#define is_addr_char(c) (isprint (c) && !(special_chars[c] & 1)) -#define is_addr_char_no_pipes(c) (is_addr_char(c) && (c) != '|') -#define is_trailing_garbage(c) (!isprint(c) || (special_chars[c] & 2)) - -static char * -url_extract (const unsigned char **text, gboolean check) -{ - const unsigned char *end = *text, *p; - char *out; - - while (*end && !isspace (*end) && (*end != '"') && (*end < 0x80)) - end++; - - /* Back up if we probably went too far. */ - while (end > *text && is_trailing_garbage (*(end - 1))) - end--; - - if (check) { - /* Make sure we weren't fooled. */ - p = memchr (*text, ':', end - *text); - if (!p || end - p < 4) - return NULL; - } - - out = g_strndup (*text, end - *text); - *text = end; - return out; -} - -static char * -email_address_extract (const unsigned char **cur, char **out, const unsigned char *linestart) -{ - const unsigned char *start, *end, *dot; - char *addr; - - /* *cur points to the '@'. Look backward for a valid local-part */ - for (start = *cur; start - 1 >= linestart && is_addr_char_no_pipes (*(start - 1)); start--) - ; - if (start == *cur) - return NULL; - - /* Now look forward for a valid domain part */ - for (end = *cur + 1, dot = NULL; is_addr_char_no_pipes (*end); end++) { - if (*end == '.' && !dot) - dot = end; - } - if (!dot) - return NULL; - - /* Remove trailing garbage */ - while (is_trailing_garbage (*(end - 1))) - end--; - if (dot > end) - return NULL; - - addr = g_strndup (start, end - start); - *out -= *cur - start; - *cur = end; - - return addr; -} - -static gboolean -is_citation (const unsigned char *c, gboolean saw_citation) -{ - gunichar u; - gint i; - - /* A line that starts with a ">" is a citation, unless it's - * just mbox From-mangling... - */ - if (*c == '>') { - const unsigned char *p; - - if (strncmp (c, ">From ", 6) != 0) - return TRUE; - - /* If the previous line was a citation, then say this - * one is too. - */ - if (saw_citation) - return TRUE; - - /* Same if the next line is */ - p = (const unsigned char *)strchr ((const char *)c, '\n'); - if (p && *++p == '>') - return TRUE; - - /* Otherwise, it was just an isolated ">From" line. */ - return FALSE; - } - - /* Check for "Rupert> " and the like... */ - for (i = 0; c && *c && g_unichar_validate (g_utf8_get_char (c)) && *c != '\n' && i < 10; i ++, c = g_utf8_next_char (c)) { - u = g_utf8_get_char (c); - if (u == '>') - return TRUE; - if (!g_unichar_isalnum (u)) - return FALSE; - } - return FALSE; -} - -/** - * e_text_to_html_full: - * @input: a NUL-terminated input buffer - * @flags: some combination of the E_TEXT_TO_HTML_* flags defined - * in e-html-utils.h - * @color: color for citation highlighting - * - * This takes a buffer of text as input and produces a buffer of - * "equivalent" HTML, subject to certain transformation rules. - * - * The set of possible flags is: - * - * - E_TEXT_TO_HTML_PRE: wrap the output HTML in <PRE> and </PRE>. - * Should only be used if @input is the entire buffer to be - * converted. If e_text_to_html is being called with small pieces - * of data, you should wrap the entire result in <PRE> yourself. - * - * - E_TEXT_TO_HTML_CONVERT_NL: convert "\n" to "<BR>\n" on output. - * (should not be used with E_TEXT_TO_HTML_PRE, since that would - * result in double-newlines). - * - * - E_TEXT_TO_HTML_CONVERT_SPACES: convert a block of N spaces - * into N-1 non-breaking spaces and one normal space. A space - * at the start of the buffer is always converted to a - * non-breaking space, regardless of the following character, - * which probably means you don't want to use this flag on - * pieces of data that aren't delimited by at least line breaks. - * - * If E_TEXT_TO_HTML_CONVERT_NL and E_TEXT_TO_HTML_CONVERT_SPACES - * are both defined, then TABs will also be converted to spaces. - * - * - E_TEXT_TO_HTML_CONVERT_URLS: wrap <a href="..."> </a> around - * strings that look like URLs. - * - * - E_TEXT_TO_HTML_CONVERT_ADDRESSES: wrap <a href="mailto:..."> </a> around - * strings that look like mail addresses. - * - * - E_TEXT_TO_HTML_MARK_CITATION: wrap <font color="..."> </font> around - * citations (lines beginning with "> ", etc). - * - * - E_TEXT_TO_HTML_ESCAPE_8BIT: flatten everything to US-ASCII - * - * - E_TEXT_TO_HTML_CITE: quote the text with "> " at the start of each - * line. - **/ -char * -e_text_to_html_full (const char *input, unsigned int flags, guint32 color) -{ - const unsigned char *cur, *next, *linestart; - char *buffer = NULL; - char *out = NULL; - int buffer_size = 0, col; - gboolean colored = FALSE, saw_citation = FALSE; - - /* Allocate a translation buffer. */ - buffer_size = strlen (input) * 2 + 5; - buffer = g_malloc (buffer_size); - - out = buffer; - if (flags & E_TEXT_TO_HTML_PRE) - out += sprintf (out, "<PRE>"); - - col = 0; - - for (cur = linestart = input; cur && *cur; cur = next) { - gunichar u; - - if (flags & E_TEXT_TO_HTML_MARK_CITATION && col == 0) { - saw_citation = is_citation (cur, saw_citation); - if (saw_citation) { - if (!colored) { - gchar font [25]; - - g_snprintf (font, 25, "<FONT COLOR=\"#%06x\">", color); - - out = check_size (&buffer, &buffer_size, out, 25); - out += sprintf (out, "%s", font); - colored = TRUE; - } - } else if (colored) { - gchar *no_font = "</FONT>"; - - out = check_size (&buffer, &buffer_size, out, 9); - out += sprintf (out, "%s", no_font); - colored = FALSE; - } - - /* Display mbox-mangled ">From" as "From" */ - if (*cur == '>' && !saw_citation) - cur++; - } else if (flags & E_TEXT_TO_HTML_CITE && col == 0) { - out = check_size (&buffer, &buffer_size, out, 5); - out += sprintf (out, "> "); - } - - u = g_utf8_get_char (cur); - if (g_unichar_isalpha (u) && - (flags & E_TEXT_TO_HTML_CONVERT_URLS)) { - char *tmpurl = NULL, *refurl = NULL, *dispurl = NULL; - - if (!strncasecmp (cur, "http://", 7) || - !strncasecmp (cur, "https://", 8) || - !strncasecmp (cur, "ftp://", 6) || - !strncasecmp (cur, "nntp://", 7) || - !strncasecmp (cur, "mailto:", 7) || - !strncasecmp (cur, "news:", 5)) { - tmpurl = url_extract (&cur, TRUE); - if (tmpurl) { - refurl = e_text_to_html (tmpurl, 0); - dispurl = g_strdup (refurl); - } - } else if (!strncasecmp (cur, "www.", 4) && - (*(cur + 4) < 0x80) && - g_unichar_isalnum (*(cur + 4))) { - tmpurl = url_extract (&cur, FALSE); - dispurl = e_text_to_html (tmpurl, 0); - refurl = g_strdup_printf ("http://%s", - dispurl); - } - - if (tmpurl) { - out = check_size (&buffer, &buffer_size, out, - strlen (refurl) + - strlen (dispurl) + 15); - out += sprintf (out, - "<a href=\"%s\">%s</a>", - refurl, dispurl); - col += strlen (tmpurl); - g_free (tmpurl); - g_free (refurl); - g_free (dispurl); - } - - if (!*cur) - break; - u = g_utf8_get_char (cur); - } - - if (u == '@' && (flags & E_TEXT_TO_HTML_CONVERT_ADDRESSES)) { - char *addr, *dispaddr, *outaddr; - - addr = email_address_extract (&cur, &out, linestart); - if (addr) { - dispaddr = e_text_to_html (addr, 0); - outaddr = g_strdup_printf ("<a href=\"mailto:%s\">%s</a>", - addr, dispaddr); - out = check_size (&buffer, &buffer_size, out, strlen (outaddr)); - out += sprintf (out, "%s", outaddr); - col += strlen (addr); - g_free (addr); - g_free (dispaddr); - g_free (outaddr); - - u = g_utf8_get_char (cur); - } - } - - if (!g_unichar_validate (u)) { - /* Sigh. Someone sent undeclared 8-bit data. - * Assume it's iso-8859-1. - */ - u = *cur; - next = cur + 1; - } else - next = g_utf8_next_char (cur); - - out = check_size (&buffer, &buffer_size, out, 10); - - switch (u) { - case '<': - strcpy (out, "<"); - out += 4; - col++; - break; - - case '>': - strcpy (out, ">"); - out += 4; - col++; - break; - - case '&': - strcpy (out, "&"); - out += 5; - col++; - break; - - case '"': - strcpy (out, """); - out += 6; - col++; - break; - - case '\n': - if (flags & E_TEXT_TO_HTML_CONVERT_NL) { - strcpy (out, "<br>"); - out += 4; - } - *out++ = *cur; - linestart = cur; - col = 0; - break; - - case '\t': - if (flags & (E_TEXT_TO_HTML_CONVERT_SPACES | - E_TEXT_TO_HTML_CONVERT_NL)) { - do { - out = check_size (&buffer, &buffer_size, - out, 7); - strcpy (out, " "); - out += 6; - col++; - } while (col % 8); - break; - } - /* otherwise, FALL THROUGH */ - - case ' ': - if (flags & E_TEXT_TO_HTML_CONVERT_SPACES) { - if (cur == (const unsigned char *)input || - *(cur + 1) == ' ' || *(cur + 1) == '\t') { - strcpy (out, " "); - out += 6; - col++; - break; - } - } - /* otherwise, FALL THROUGH */ - - default: - if ((u >= 0x20 && u < 0x80) || - (u == '\r' || u == '\t')) { - /* Default case, just copy. */ - *out++ = u; - } else { - if (flags & E_TEXT_TO_HTML_ESCAPE_8BIT) - *out++ = '?'; - else - out += g_snprintf(out, 9, "&#%d;", u); - } - col++; - break; - } - } - - out = check_size (&buffer, &buffer_size, out, 7); - if (flags & E_TEXT_TO_HTML_PRE) - strcpy (out, "</PRE>"); - else - *out = '\0'; - - return buffer; -} - -char * -e_text_to_html (const char *input, unsigned int flags) -{ - return e_text_to_html_full (input, flags, 0); -} diff --git a/e-util/e-html-utils.h b/e-util/e-html-utils.h deleted file mode 100644 index 812fe06d58..0000000000 --- a/e-util/e-html-utils.h +++ /dev/null @@ -1,40 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-html-utils.c */ -/* - * Copyright (C) 2000 Ximian, Inc. - * Author: Dan Winship <danw@ximian.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __E_HTML_UTILS__ -#define __E_HTML_UTILS__ - -#include <glib.h> - -#define E_TEXT_TO_HTML_PRE (1 << 0) -#define E_TEXT_TO_HTML_CONVERT_NL (1 << 1) -#define E_TEXT_TO_HTML_CONVERT_SPACES (1 << 2) -#define E_TEXT_TO_HTML_CONVERT_URLS (1 << 3) -#define E_TEXT_TO_HTML_MARK_CITATION (1 << 4) -#define E_TEXT_TO_HTML_CONVERT_ADDRESSES (1 << 5) -#define E_TEXT_TO_HTML_ESCAPE_8BIT (1 << 6) -#define E_TEXT_TO_HTML_CITE (1 << 7) - -char *e_text_to_html_full (const char *input, unsigned int flags, guint32 color); -char *e_text_to_html (const char *input, unsigned int flags); - -#endif /* __E_HTML_UTILS__ */ diff --git a/e-util/e-i18n.h b/e-util/e-i18n.h deleted file mode 100644 index 58d3420be3..0000000000 --- a/e-util/e-i18n.h +++ /dev/null @@ -1,63 +0,0 @@ -/* - * Copied from gnome-i18nP.h, because this header is typically not installed - * - * This file has to be included before any file from the GNOME libraries - * to have this override the definitions that are pulled from the gnome-i18n.h - * - * the difference is that gnome-i18n.h is used for applications, and this is - * used by libraries (because libraries have to use dcgettext instead of - * gettext and they need to provide the translation domain, unlike apps). - * - * So you can just put this after you include config.h - */ - -#ifndef __E_I18N_H__ -#define __E_I18N_H__ - -#include <glib.h> -#include "libgnome/gnome-defs.h" - -BEGIN_GNOME_DECLS - -#ifdef ENABLE_NLS -# include <libintl.h> -# undef _ -# define _(String) dgettext (PACKAGE, String) -# ifdef gettext_noop -# define N_(String) gettext_noop (String) -# else -# define N_(String) (String) -# endif -#else -/* Stubs that do something close enough. */ -# define textdomain(String) (String) -# define gettext(String) (String) -# define dgettext(Domain,Message) (Message) -# define dcgettext(Domain,Message,Type) (Message) -# define bindtextdomain(Domain,Directory) (Domain) -# define _(String) (String) -# define N_(String) (String) -#endif - -/* - * Do not remove the following define, nor do surround it with ifdefs. - * - * If you get any `redefined' errors, it means that you are including - * -incorrectly- a header file provided by gnome-libs before this file. - * To correctly solve this issue include this file before any libgnome/ - * libgnomeui headers - */ - -#define __GNOME_I18N_H__ 1 - - -/* This is copied staight out of the prototypes for gnome-i18n.h */ -const char *gnome_i18n_get_language(void); -GList *gnome_i18n_get_language_list (const gchar *category_name); -void gnome_i18n_set_preferred_language (const char *val); -const char *gnome_i18n_get_preferred_language (void); -void gnome_i18n_init (void); - -END_GNOME_DECLS - -#endif /* __E_I18N_H__ */ diff --git a/e-util/e-iterator.c b/e-util/e-iterator.c deleted file mode 100644 index 8bd14ee6c8..0000000000 --- a/e-util/e-iterator.c +++ /dev/null @@ -1,186 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Christopher James Lahey <clahey@umich.edu> - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include <config.h> - -#include <gtk/gtksignal.h> -#include "e-iterator.h" - -#define ECI_CLASS(object) (E_ITERATOR_CLASS(GTK_OBJECT((object))->klass)) - -static void e_iterator_init (EIterator *card); -static void e_iterator_class_init (EIteratorClass *klass); - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - -enum { - INVALIDATE, - LAST_SIGNAL -}; - -static guint e_iterator_signals [LAST_SIGNAL] = { 0, }; - -/** - * e_iterator_get_type: - * @void: - * - * Registers the &EIterator class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EIterator class. - **/ -GtkType -e_iterator_get_type (void) -{ - static GtkType type = 0; - - if (!type) { - GtkTypeInfo info = { - "EIterator", - sizeof (EIterator), - sizeof (EIteratorClass), - (GtkClassInitFunc) e_iterator_class_init, - (GtkObjectInitFunc) e_iterator_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -static void -e_iterator_class_init (EIteratorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - e_iterator_signals [INVALIDATE] = - gtk_signal_new ("invalidate", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (EIteratorClass, invalidate), - gtk_marshal_NONE__NONE, - GTK_TYPE_NONE, 0); - - gtk_object_class_add_signals (object_class, e_iterator_signals, LAST_SIGNAL); - - klass->invalidate = NULL; - klass->get = NULL; - klass->reset = NULL; - klass->last = NULL; - klass->next = NULL; - klass->prev = NULL; - klass->delete = NULL; - klass->insert = NULL; - klass->set = NULL; - klass->is_valid = NULL; -} - -/** - * e_iterator_init: - */ -static void -e_iterator_init (EIterator *card) -{ -} - -/* - * Virtual functions: - */ -const void * -e_iterator_get (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->get) - return ECI_CLASS(iterator)->get(iterator); - else - return NULL; -} - -void -e_iterator_reset (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->reset) - ECI_CLASS(iterator)->reset(iterator); -} - -void -e_iterator_last (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->last) - ECI_CLASS(iterator)->last(iterator); -} - -gboolean -e_iterator_next (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->next) - return ECI_CLASS(iterator)->next(iterator); - else - return FALSE; -} - -gboolean -e_iterator_prev (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->prev) - return ECI_CLASS(iterator)->prev(iterator); - else - return FALSE; -} - -void -e_iterator_delete (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->delete) - ECI_CLASS(iterator)->delete(iterator); -} - -void e_iterator_insert (EIterator *iterator, - const void *object, - gboolean before) -{ - if (ECI_CLASS(iterator)->insert) - ECI_CLASS(iterator)->insert(iterator, object, before); -} - -void -e_iterator_set (EIterator *iterator, - const void *object) -{ - if (ECI_CLASS(iterator)->set) - ECI_CLASS(iterator)->set(iterator, object); -} - -gboolean -e_iterator_is_valid (EIterator *iterator) -{ - if (ECI_CLASS(iterator)->is_valid) - return ECI_CLASS(iterator)->is_valid(iterator); - else - return FALSE; -} - -void -e_iterator_invalidate (EIterator *iterator) -{ - g_return_if_fail (iterator != NULL); - g_return_if_fail (E_IS_ITERATOR (iterator)); - - gtk_signal_emit (GTK_OBJECT (iterator), - e_iterator_signals [INVALIDATE]); -} diff --git a/e-util/e-iterator.h b/e-util/e-iterator.h deleted file mode 100644 index a6f0899235..0000000000 --- a/e-util/e-iterator.h +++ /dev/null @@ -1,69 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_ITERATOR_H__ -#define __E_ITERATOR_H__ - -#include <stdio.h> -#include <time.h> -#include <gtk/gtkobject.h> - -#define E_TYPE_ITERATOR (e_iterator_get_type ()) -#define E_ITERATOR(obj) (GTK_CHECK_CAST ((obj), E_TYPE_ITERATOR, EIterator)) -#define E_ITERATOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_ITERATOR, EIteratorClass)) -#define E_IS_ITERATOR(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_ITERATOR)) -#define E_IS_ITERATOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_ITERATOR)) - -typedef struct _EIterator EIterator; -typedef struct _EIteratorClass EIteratorClass; - -struct _EIterator { - GtkObject object; -}; - -struct _EIteratorClass { - GtkObjectClass parent_class; - - /* Signals */ - void (*invalidate) (EIterator *iterator); - - /* Virtual functions */ - const void * (*get) (EIterator *iterator); - void (*reset) (EIterator *iterator); - void (*last) (EIterator *iterator); - gboolean (*next) (EIterator *iterator); - gboolean (*prev) (EIterator *iterator); - void (*delete) (EIterator *iterator); - void (*insert) (EIterator *iterator, - const void *object, - gboolean before); - void (*set) (EIterator *iterator, - const void *object); - gboolean (*is_valid) (EIterator *iterator); -}; - -const void *e_iterator_get (EIterator *iterator); -void e_iterator_reset (EIterator *iterator); -void e_iterator_last (EIterator *iterator); -gboolean e_iterator_next (EIterator *iterator); -gboolean e_iterator_prev (EIterator *iterator); -void e_iterator_delete (EIterator *iterator); -void e_iterator_insert (EIterator *iterator, - const void *object, - gboolean before); -void e_iterator_set (EIterator *iterator, - const void *object); -gboolean e_iterator_is_valid (EIterator *iterator); - -void e_iterator_invalidate (EIterator *iterator); - -/* Standard Gtk function */ -GtkType e_iterator_get_type (void); - -#endif /* ! __E_ITERATOR_H__ */ diff --git a/e-util/e-list-iterator.c b/e-util/e-list-iterator.c deleted file mode 100644 index 7d3d644fc2..0000000000 --- a/e-util/e-list-iterator.c +++ /dev/null @@ -1,249 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Christopher James Lahey <clahey@umich.edu> - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include <config.h> - -#include "e-list-iterator.h" -#include "e-list.h" - - -static void e_list_iterator_init (EListIterator *list); -static void e_list_iterator_class_init (EListIteratorClass *klass); - -static void e_list_iterator_invalidate (EIterator *iterator); -static gboolean e_list_iterator_is_valid (EIterator *iterator); -static void e_list_iterator_set (EIterator *iterator, - const void *object); -static void e_list_iterator_delete (EIterator *iterator); -static void e_list_iterator_insert (EIterator *iterator, - const void *object, - gboolean before); -static gboolean e_list_iterator_prev (EIterator *iterator); -static gboolean e_list_iterator_next (EIterator *iterator); -static void e_list_iterator_reset (EIterator *iterator); -static void e_list_iterator_last (EIterator *iterator); -static const void *e_list_iterator_get (EIterator *iterator); -static void e_list_iterator_destroy (GtkObject *object); - -#define PARENT_TYPE (e_iterator_get_type ()) - -static EIteratorClass *parent_class; -#define PARENT_CLASS (E_ITERATOR_CLASS(parent_class)) - -/** - * e_list_iterator_get_type: - * @void: - * - * Registers the &EListIterator class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EListIterator class. - **/ -GtkType -e_list_iterator_get_type (void) -{ - static GtkType type = 0; - - if (!type) { - GtkTypeInfo info = { - "EListIterator", - sizeof (EListIterator), - sizeof (EListIteratorClass), - (GtkClassInitFunc) e_list_iterator_class_init, - (GtkObjectInitFunc) e_list_iterator_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -static void -e_list_iterator_class_init (EListIteratorClass *klass) -{ - GtkObjectClass *object_class; - EIteratorClass *iterator_class; - - object_class = GTK_OBJECT_CLASS(klass); - iterator_class = E_ITERATOR_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = e_list_iterator_destroy; - - iterator_class->invalidate = e_list_iterator_invalidate; - iterator_class->get = e_list_iterator_get; - iterator_class->reset = e_list_iterator_reset; - iterator_class->last = e_list_iterator_last; - iterator_class->next = e_list_iterator_next; - iterator_class->prev = e_list_iterator_prev; - iterator_class->delete = e_list_iterator_delete; - iterator_class->insert = e_list_iterator_insert; - iterator_class->set = e_list_iterator_set; - iterator_class->is_valid = e_list_iterator_is_valid; -} - - - -/** - * e_list_iterator_init: - */ -static void -e_list_iterator_init (EListIterator *list) -{ -} - -EIterator * -e_list_iterator_new (EList *list) -{ - EListIterator *iterator = gtk_type_new(e_list_iterator_get_type()); - - iterator->list = list; - gtk_object_ref(GTK_OBJECT(list)); - iterator->iterator = list->list; - - return E_ITERATOR(iterator); -} - -/* - * Virtual functions: - */ -static void -e_list_iterator_destroy (GtkObject *object) -{ - EListIterator *iterator = E_LIST_ITERATOR(object); - e_list_remove_iterator(iterator->list, E_ITERATOR(iterator)); - gtk_object_unref(GTK_OBJECT(iterator->list)); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - -static const void * -e_list_iterator_get (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) - return iterator->iterator->data; - else - return NULL; -} - -static void -e_list_iterator_reset (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - iterator->iterator = iterator->list->list; -} - -static void -e_list_iterator_last (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - iterator->iterator = g_list_last(iterator->list->list); -} - -static gboolean -e_list_iterator_next (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) - iterator->iterator = g_list_next(iterator->iterator); - else - iterator->iterator = iterator->list->list; - return (iterator->iterator != NULL); -} - -static gboolean -e_list_iterator_prev (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) - iterator->iterator = g_list_previous(iterator->iterator); - else - iterator->iterator = g_list_last(iterator->list->list); - return (iterator->iterator != NULL); -} - -static void -e_list_iterator_insert (EIterator *_iterator, - const void *object, - gboolean before) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - void *data; - if (iterator->list->copy) - data = iterator->list->copy(object, iterator->list->closure); - else - data = (void *) object; - if (iterator->iterator) { - if (before) { - iterator->list->list = g_list_first(g_list_prepend(iterator->iterator, data)); - iterator->iterator = iterator->iterator->prev; - } else { - if (iterator->iterator->next) - g_list_prepend(iterator->iterator->next, data); - else - g_list_append(iterator->iterator, data); - iterator->iterator = iterator->iterator->next; - } - e_list_invalidate_iterators(iterator->list, E_ITERATOR(iterator)); - } else { - if (before) { - iterator->list->list = g_list_append(iterator->list->list, data); - iterator->iterator = g_list_last(iterator->list->list); - } else { - iterator->list->list = g_list_prepend(iterator->list->list, data); - iterator->iterator = iterator->list->list; - } - e_list_invalidate_iterators(iterator->list, E_ITERATOR(iterator)); - } -} - -static void -e_list_iterator_delete (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) { - e_list_remove_link (iterator->list, iterator->iterator); - } -} - -static void -e_list_iterator_set (EIterator *_iterator, - const void *object) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - if (iterator->iterator) { - if (iterator->list->free) - iterator->list->free(iterator->iterator->data, iterator->list->closure); - if (iterator->list->copy) - iterator->iterator->data = iterator->list->copy(object, iterator->list->closure); - else - iterator->iterator->data = (void *) object; - } -} - -static gboolean -e_list_iterator_is_valid (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - return iterator->iterator != NULL; -} - -static void -e_list_iterator_invalidate (EIterator *_iterator) -{ - EListIterator *iterator = E_LIST_ITERATOR(_iterator); - iterator->iterator = NULL; -} diff --git a/e-util/e-list-iterator.h b/e-util/e-list-iterator.h deleted file mode 100644 index 6903015002..0000000000 --- a/e-util/e-list-iterator.h +++ /dev/null @@ -1,45 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_LIST_ITERATOR_H__ -#define __E_LIST_ITERATOR_H__ - -typedef struct _EListIterator EListIterator; -typedef struct _EListIteratorClass EListIteratorClass; - -#include <stdio.h> -#include <time.h> -#include <gtk/gtkobject.h> - -#include <e-util/e-iterator.h> -#include <e-util/e-list.h> - -#define E_TYPE_LIST_ITERATOR (e_list_iterator_get_type ()) -#define E_LIST_ITERATOR(obj) (GTK_CHECK_CAST ((obj), E_TYPE_LIST_ITERATOR, EListIterator)) -#define E_LIST_ITERATOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_LIST_ITERATOR, EListIteratorClass)) -#define E_IS_LIST_ITERATOR(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_LIST_ITERATOR)) -#define E_IS_LIST_ITERATOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_LIST_ITERATOR)) - -struct _EListIterator { - EIterator parent; - - EList *list; - GList *iterator; -}; - -struct _EListIteratorClass { - EIteratorClass parent_class; -}; - -EIterator *e_list_iterator_new (EList *list); - -/* Standard Gtk function */ -GtkType e_list_iterator_get_type (void); - -#endif /* ! __E_LIST_ITERATOR_H__ */ diff --git a/e-util/e-list.c b/e-util/e-list.c deleted file mode 100644 index 64ccea728c..0000000000 --- a/e-util/e-list.c +++ /dev/null @@ -1,179 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Christopher James Lahey <clahey@umich.edu> - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#include <config.h> - -#include "e-list.h" -#include "e-list-iterator.h" - -#define ECL_CLASS(object) (E_LIST_CLASS(GTK_OBJECT((object))->klass)) - -static void e_list_init (EList *list); -static void e_list_class_init (EListClass *klass); -static void e_list_destroy (GtkObject *object); - -#define PARENT_TYPE (gtk_object_get_type ()) - -static GtkObjectClass *parent_class; - -/** - * e_list_get_type: - * @void: - * - * Registers the &EList class if necessary, and returns the type ID - * associated to it. - * - * Return value: The type ID of the &EList class. - **/ -GtkType -e_list_get_type (void) -{ - static GtkType type = 0; - - if (!type) { - GtkTypeInfo info = { - "EList", - sizeof (EList), - sizeof (EListClass), - (GtkClassInitFunc) e_list_class_init, - (GtkObjectInitFunc) e_list_init, - NULL, /* reserved_1 */ - NULL, /* reserved_2 */ - (GtkClassInitFunc) NULL - }; - - type = gtk_type_unique (PARENT_TYPE, &info); - } - - return type; -} - -static void -e_list_class_init (EListClass *klass) -{ - GtkObjectClass *object_class; - - object_class = GTK_OBJECT_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = e_list_destroy; -} - -/** - * e_list_init: - */ -static void -e_list_init (EList *list) -{ - list->list = NULL; - list->iterators = NULL; -} - -EList * -e_list_new (EListCopyFunc copy, EListFreeFunc free, void *closure) -{ - EList *list = gtk_type_new(e_list_get_type()); - list->copy = copy; - list->free = free; - list->closure = closure; - return list; -} - -EList * -e_list_duplicate (EList *old) -{ - EList *list = gtk_type_new(e_list_get_type()); - - list->copy = old->copy; - list->free = old->free; - list->closure = old->closure; - list->list = g_list_copy(old->list); - if (list->copy) { - GList *listlist; - for (listlist = list->list; listlist; listlist = listlist->next) { - listlist->data = list->copy (listlist->data, list->closure); - } - } - return list; -} - -EIterator * -e_list_get_iterator (EList *list) -{ - EIterator *iterator = e_list_iterator_new(list); - list->iterators = g_list_append(list->iterators, iterator); - return iterator; -} - -int -e_list_length (EList *list) -{ - return g_list_length(list->list); -} - -void -e_list_append (EList *list, const void *data) -{ - e_list_invalidate_iterators(list, NULL); - if (list->copy) - list->list = g_list_append(list->list, list->copy(data, list->closure)); - else - list->list = g_list_append(list->list, (void *) data); -} - -void -e_list_invalidate_iterators (EList *list, EIterator *skip) -{ - GList *iterators = list->iterators; - for (; iterators; iterators = iterators->next) { - if (iterators->data != skip) { - e_iterator_invalidate(E_ITERATOR(iterators->data)); - } - } -} - -/* FIXME: This doesn't work properly if the iterator is the first - iterator in the list. Well, the iterator doesn't continue on after - the next time next is called, at least. */ -void -e_list_remove_link (EList *list, GList *link) -{ - GList *iterators = list->iterators; - for (; iterators; iterators = iterators->next) { - if (((EListIterator *)iterators->data)->iterator == link) { - e_iterator_prev(iterators->data); - } - } - if (list->free) - list->free(link->data, list->closure); - list->list = g_list_remove_link(list->list, link); - g_list_free_1(link); -} - -void -e_list_remove_iterator (EList *list, EIterator *iterator) -{ - list->iterators = g_list_remove(list->iterators, iterator); -} - -/* - * Virtual functions - */ -static void -e_list_destroy (GtkObject *object) -{ - EList *list = E_LIST(object); - g_list_foreach(list->list, (GFunc) list->free, list->closure); - g_list_free(list->list); - - if (GTK_OBJECT_CLASS (parent_class)->destroy) - (* GTK_OBJECT_CLASS (parent_class)->destroy) (object); -} - diff --git a/e-util/e-list.h b/e-util/e-list.h deleted file mode 100644 index da63576996..0000000000 --- a/e-util/e-list.h +++ /dev/null @@ -1,63 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: - * Chris Lahey <clahey@ximian.com> - * - * Copyright (C) 2000 Ximian, Inc. - * Copyright (C) 1999 The Free Software Foundation - */ - -#ifndef __E_LIST_H__ -#define __E_LIST_H__ - -typedef struct _EList EList; -typedef struct _EListClass EListClass; - -#include <stdio.h> -#include <time.h> -#include <gtk/gtkobject.h> -#include <e-util/e-list-iterator.h> - -#define E_TYPE_LIST (e_list_get_type ()) -#define E_LIST(obj) (GTK_CHECK_CAST ((obj), E_TYPE_LIST, EList)) -#define E_LIST_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TYPE_LIST, EListClass)) -#define E_IS_LIST(obj) (GTK_CHECK_TYPE ((obj), E_TYPE_LIST)) -#define E_IS_LIST_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((klass), E_TYPE_LIST)) - -typedef void *(*EListCopyFunc) (const void *data, void *closure); -typedef void (*EListFreeFunc) (void *data, void *closure); - -struct _EList { - GtkObject object; - GList *list; - GList *iterators; - EListCopyFunc copy; - EListFreeFunc free; - void *closure; -}; - -struct _EListClass { - GtkObjectClass parent_class; -}; - -EList *e_list_new (EListCopyFunc copy, - EListFreeFunc free, - void *closure); -EList *e_list_duplicate (EList *list); -EIterator *e_list_get_iterator (EList *list); -void e_list_append (EList *list, - const void *data); -int e_list_length (EList *list); - -/* For iterators to call. */ -void e_list_remove_link (EList *list, - GList *link); -void e_list_remove_iterator (EList *list, - EIterator *iterator); -void e_list_invalidate_iterators (EList *list, - EIterator *skip); - -/* Standard Gtk function */ -GtkType e_list_get_type (void); - -#endif /* ! __E_LIST_H__ */ diff --git a/e-util/e-memory.c b/e-util/e-memory.c deleted file mode 100644 index 4a2764e407..0000000000 --- a/e-util/e-memory.c +++ /dev/null @@ -1,1280 +0,0 @@ -/* - * Copyright (c) 2000, 2001 Ximian Inc. - * - * Authors: Michael Zucchi <notzed@ximian.com> - * Jacob Berkman <jacob@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - -*/ - -#include "e-memory.h" - -#include <string.h> /* memset() */ -#include <stdlib.h> /* alloca() */ -#include <glib.h> - -#define s(x) /* strv debug */ -#define p(x) /* poolv debug */ -#define p2(x) /* poolv assertion checking */ - -/*#define MALLOC_CHECK*/ - -/* #define PROFILE_POOLV */ - -#ifdef PROFILE_POOLV -#include <time.h> -#define pp(x) x -#else -#define pp(x) -#endif - -/*#define TIMEIT*/ - -#ifdef TIMEIT -#include <sys/time.h> -#include <unistd.h> - -struct timeval timeit_start; - -static time_start(const char *desc) -{ - gettimeofday(&timeit_start, NULL); - printf("starting: %s\n", desc); -} - -static time_end(const char *desc) -{ - unsigned long diff; - struct timeval end; - - gettimeofday(&end, NULL); - diff = end.tv_sec * 1000 + end.tv_usec/1000; - diff -= timeit_start.tv_sec * 1000 + timeit_start.tv_usec/1000; - printf("%s took %ld.%03ld seconds\n", - desc, diff / 1000, diff % 1000); -} -#else -#define time_start(x) -#define time_end(x) -#endif - -#ifdef MALLOC_CHECK -#include <mcheck.h> -#include <stdio.h> -static void -checkmem(void *p) -{ - if (p) { - int status = mprobe(p); - - switch (status) { - case MCHECK_HEAD: - printf("Memory underrun at %p\n", p); - abort(); - case MCHECK_TAIL: - printf("Memory overrun at %p\n", p); - abort(); - case MCHECK_FREE: - printf("Double free %p\n", p); - abort(); - } - } -} -#define MPROBE(x) checkmem((void *)(x)) -#else -#define MPROBE(x) -#endif - -/* mempool class */ - -#define STRUCT_ALIGN (4) - -typedef struct _MemChunkFreeNode { - struct _MemChunkFreeNode *next; - unsigned int atoms; -} MemChunkFreeNode; - -typedef struct _EMemChunk { - unsigned int blocksize; /* number of atoms in a block */ - unsigned int atomsize; /* size of each atom */ - GPtrArray *blocks; /* blocks of raw memory */ - struct _MemChunkFreeNode *free; -} MemChunk; - -/** - * e_memchunk_new: - * @atomcount: The number of atoms stored in a single malloc'd block of memory. - * @atomsize: The size of each allocation. - * - * Create a new memchunk header. Memchunks are an efficient way to allocate - * and deallocate identical sized blocks of memory quickly, and space efficiently. - * - * e_memchunks are effectively the same as gmemchunks, only faster (much), and - * they use less memory overhead for housekeeping. - * - * Return value: The new header. - **/ -MemChunk *e_memchunk_new(int atomcount, int atomsize) -{ - MemChunk *m = g_malloc(sizeof(*m)); - - m->blocksize = atomcount; - m->atomsize = MAX(atomsize, sizeof(MemChunkFreeNode)); - m->blocks = g_ptr_array_new(); - m->free = NULL; - - return m; -} - -/** - * memchunk_alloc: - * @m: - * - * Allocate a new atom size block of memory from a memchunk. - **/ -void *e_memchunk_alloc(MemChunk *m) -{ - char *b; - MemChunkFreeNode *f; - void *mem; - - f = m->free; - if (f) { - f->atoms--; - if (f->atoms > 0) { - mem = ((char *)f) + (f->atoms*m->atomsize); - } else { - mem = f; - m->free = m->free->next; - } - return mem; - } else { - b = g_malloc(m->blocksize * m->atomsize); - g_ptr_array_add(m->blocks, b); - f = (MemChunkFreeNode *)&b[m->atomsize]; - f->atoms = m->blocksize-1; - f->next = NULL; - m->free = f; - return b; - } -} - -void *e_memchunk_alloc0(EMemChunk *m) -{ - void *mem; - - mem = e_memchunk_alloc(m); - memset(mem, 0, m->atomsize); - - return mem; -} - -/** - * e_memchunk_free: - * @m: - * @mem: Address of atom to free. - * - * Free a single atom back to the free pool of atoms in the given - * memchunk. - **/ -void -e_memchunk_free(MemChunk *m, void *mem) -{ - MemChunkFreeNode *f; - - /* put the location back in the free list. If we knew if the preceeding or following - cells were free, we could merge the free nodes, but it doesn't really add much */ - f = mem; - f->next = m->free; - m->free = f; - f->atoms = 1; - - /* we could store the free list sorted - we could then do the above, and also - probably improve the locality of reference properties for the allocator */ - /* and it would simplify some other algorithms at that, but slow this one down - significantly */ -} - -/** - * e_memchunk_empty: - * @m: - * - * Clean out the memchunk buffers. Marks all allocated memory as free blocks, - * but does not give it back to the system. Can be used if the memchunk - * is to be used repeatedly. - **/ -void -e_memchunk_empty(MemChunk *m) -{ - int i; - MemChunkFreeNode *f, *h = NULL; - - for (i=0;i<m->blocks->len;i++) { - f = (MemChunkFreeNode *)m->blocks->pdata[i]; - f->atoms = m->blocksize; - f->next = h; - h = f; - } - m->free = h; -} - -struct _cleaninfo { - struct _cleaninfo *next; - char *base; - int count; - int size; /* just so tree_search has it, sigh */ -}; - -static int tree_compare(struct _cleaninfo *a, struct _cleaninfo *b) -{ - if (a->base < b->base) - return -1; - else if (a->base > b->base) - return 1; - return 0; -} - -static int tree_search(struct _cleaninfo *a, char *mem) -{ - if (a->base <= mem) { - if (mem < &a->base[a->size]) - return 0; - return 1; - } - return -1; -} - -/** - * e_memchunk_clean: - * @m: - * - * Scan all empty blocks and check for blocks which can be free'd - * back to the system. - * - * This routine may take a while to run if there are many allocated - * memory blocks (if the total number of allocations is many times - * greater than atomcount). - **/ -void -e_memchunk_clean(MemChunk *m) -{ - GTree *tree; - int i; - MemChunkFreeNode *f; - struct _cleaninfo *ci, *hi = NULL; - - f = m->free; - if (m->blocks->len == 0 || f == NULL) - return; - - /* first, setup the tree/list so we can map free block addresses to block addresses */ - tree = g_tree_new((GCompareFunc)tree_compare); - for (i=0;i<m->blocks->len;i++) { - ci = alloca(sizeof(*ci)); - ci->count = 0; - ci->base = m->blocks->pdata[i]; - ci->size = m->blocksize * m->atomsize; - g_tree_insert(tree, ci, ci); - ci->next = hi; - hi = ci; - } - - /* now, scan all free nodes, and count them in their tree node */ - while (f) { - ci = g_tree_search(tree, (GSearchFunc)tree_search, f); - if (ci) { - ci->count += f->atoms; - } else { - g_warning("error, can't find free node in memory block\n"); - } - f = f->next; - } - - /* if any nodes are all free, free & unlink them */ - ci = hi; - while (ci) { - if (ci->count == m->blocksize) { - g_ptr_array_remove_fast(m->blocks, ci->base); - g_free(ci->base); - } - ci = ci->next; - } - - g_tree_destroy(tree); -} - -/** - * e_memchunk_destroy: - * @m: - * - * Free the memchunk header, and all associated memory. - **/ -void -e_memchunk_destroy(MemChunk *m) -{ - int i; - - if (m == NULL) - return; - - for (i=0;i<m->blocks->len;i++) - g_free(m->blocks->pdata[i]); - g_ptr_array_free(m->blocks, TRUE); - g_free(m); -} - -typedef struct _MemPoolNode { - struct _MemPoolNode *next; - - int free; - char data[1]; -} MemPoolNode; - -typedef struct _MemPoolThresholdNode { - struct _MemPoolThresholdNode *next; - char data[1]; -} MemPoolThresholdNode; - -typedef struct _EMemPool { - int blocksize; - int threshold; - unsigned int align; - struct _MemPoolNode *blocks; - struct _MemPoolThresholdNode *threshold_blocks; -} MemPool; - -/* a pool of mempool header blocks */ -static MemChunk *mempool_memchunk; -#ifdef G_THREADS_ENABLED -static GStaticMutex mempool_mutex = G_STATIC_MUTEX_INIT; -#endif - -/** - * e_mempool_new: - * @blocksize: The base blocksize to use for all system alocations. - * @threshold: If the allocation exceeds the threshold, then it is - * allocated separately and stored in a separate list. - * @flags: Alignment options: E_MEMPOOL_ALIGN_STRUCT uses native - * struct alignment, E_MEMPOOL_ALIGN_WORD aligns to 16 bits (2 bytes), - * and E_MEMPOOL_ALIGN_BYTE aligns to the nearest byte. The default - * is to align to native structures. - * - * Create a new mempool header. Mempools can be used to efficiently - * allocate data which can then be freed as a whole. - * - * Mempools can also be used to efficiently allocate arbitrarily - * aligned data (such as strings) without incurring the space overhead - * of aligning each allocation (which is not required for strings). - * - * However, each allocation cannot be freed individually, only all - * or nothing. - * - * Return value: - **/ -MemPool *e_mempool_new(int blocksize, int threshold, EMemPoolFlags flags) -{ - MemPool *pool; - -#ifdef G_THREADS_ENABLED - g_static_mutex_lock(&mempool_mutex); -#endif - if (mempool_memchunk == NULL) { - mempool_memchunk = e_memchunk_new(8, sizeof(MemPool)); - } - pool = e_memchunk_alloc(mempool_memchunk); -#ifdef G_THREADS_ENABLED - g_static_mutex_unlock(&mempool_mutex); -#endif - if (threshold >= blocksize) - threshold = blocksize * 2 / 3; - pool->blocksize = blocksize; - pool->threshold = threshold; - pool->blocks = NULL; - pool->threshold_blocks = NULL; - - switch (flags & E_MEMPOOL_ALIGN_MASK) { - case E_MEMPOOL_ALIGN_STRUCT: - default: - pool->align = STRUCT_ALIGN-1; - break; - case E_MEMPOOL_ALIGN_WORD: - pool->align = 2-1; - break; - case E_MEMPOOL_ALIGN_BYTE: - pool->align = 1-1; - } - return pool; -} - -/** - * e_mempool_alloc: - * @pool: - * @size: - * - * Allocate a new data block in the mempool. Size will - * be rounded up to the mempool's alignment restrictions - * before being used. - **/ -void *e_mempool_alloc(MemPool *pool, register int size) -{ - size = (size + pool->align) & (~(pool->align)); - if (size>=pool->threshold) { - MemPoolThresholdNode *n; - - n = g_malloc(sizeof(*n) - sizeof(char) + size); - n->next = pool->threshold_blocks; - pool->threshold_blocks = n; - return &n->data[0]; - } else { - register MemPoolNode *n; - - n = pool->blocks; - if (n && n->free >= size) { - n->free -= size; - return &n->data[n->free]; - } - - /* maybe we could do some sort of the free blocks based on size, but - it doubt its worth it at all */ - - n = g_malloc(sizeof(*n) - sizeof(char) + pool->blocksize); - n->next = pool->blocks; - pool->blocks = n; - n->free = pool->blocksize - size; - return &n->data[n->free]; - } -} - -char *e_mempool_strdup(EMemPool *pool, const char *str) -{ - char *out; - - out = e_mempool_alloc(pool, strlen(str)+1); - strcpy(out, str); - - return out; -} - -/** - * e_mempool_flush: - * @pool: - * @freeall: Free all system allocated blocks as well. - * - * Flush used memory and mark allocated blocks as free. - * - * If @freeall is #TRUE, then all allocated blocks are free'd - * as well. Otherwise only blocks above the threshold are - * actually freed, and the others are simply marked as empty. - **/ -void e_mempool_flush(MemPool *pool, int freeall) -{ - MemPoolThresholdNode *tn, *tw; - MemPoolNode *pw, *pn; - - tw = pool->threshold_blocks; - while (tw) { - tn = tw->next; - g_free(tw); - tw = tn; - } - pool->threshold_blocks = NULL; - - if (freeall) { - pw = pool->blocks; - while (pw) { - pn = pw->next; - g_free(pw); - pw = pn; - } - pool->blocks = NULL; - } else { - pw = pool->blocks; - while (pw) { - pw->free = pool->blocksize; - pw = pw->next; - } - } -} - -/** - * e_mempool_destroy: - * @pool: - * - * Free all memory associated with a mempool. - **/ -void e_mempool_destroy(MemPool *pool) -{ - if (pool) { - e_mempool_flush(pool, 1); - e_memchunk_free(mempool_memchunk, pool); - } -} - - -/* - string array classes -*/ - -#define STRV_UNPACKED ((unsigned char)(~0)) - -struct _EStrv { - unsigned char length; /* how many entries we have (or the token STRV_UNPACKED) */ - char data[1]; /* data follows */ -}; - -struct _s_strv_string { - char *string; /* the string to output */ - char *free; /* a string to free, if we referenced it */ -}; - -struct _e_strvunpacked { - unsigned char type; /* we overload last to indicate this is unpacked */ - MemPool *pool; /* pool of memory for strings */ - struct _EStrv *source; /* if we were converted from a packed one, keep the source around for a while */ - unsigned int length; - struct _s_strv_string strings[1]; /* the string array data follows */ -}; - -/** - * e_strv_new: - * @size: The number of elements in the strv. Currently this is limited - * to 254 elements. - * - * Create a new strv (string array) header. strv's can be used to - * create and work with arrays of strings that can then be compressed - * into a space-efficient static structure. This is useful - * where a number of strings are to be stored for lookup, and not - * generally edited afterwards. - * - * The size limit is currently 254 elements. This will probably not - * change as arrays of this size suffer significant performance - * penalties when looking up strings with high indices. - * - * Return value: - **/ -struct _EStrv * -e_strv_new(int size) -{ - struct _e_strvunpacked *s; - - g_assert(size<255); - - s = g_malloc(sizeof(*s) + (size-1)*sizeof(s->strings[0])); - s(printf("new strv=%p, size = %d bytes\n", s, sizeof(*s) + (size-1)*sizeof(char *))); - s->type = STRV_UNPACKED; - s->pool = NULL; - s->length = size; - s->source = NULL; - memset(s->strings, 0, size*sizeof(s->strings[0])); - - return (struct _EStrv *)s; -} - -static struct _e_strvunpacked * -strv_unpack(struct _EStrv *strv) -{ - struct _e_strvunpacked *s; - register char *p; - int i; - - s(printf("unpacking\n")); - - s = (struct _e_strvunpacked *)e_strv_new(strv->length); - p = strv->data; - for (i=0;i<s->length;i++) { - if (i>0) - while (*p++) - ; - s->strings[i].string = p; - } - s->source = strv; - s->type = STRV_UNPACKED; - - return s; -} - -/** - * e_strv_set_ref: - * @strv: - * @index: - * @str: - * - * Set a string array element by reference. The string - * is not copied until the array is packed. - * - * If @strv has been packed, then it is unpacked ready - * for more inserts, and should be packed again once finished with. - * The memory used by the original @strv is not freed until - * the new strv is packed, or freed itself. - * - * Return value: A new EStrv if the strv has already - * been packed, otherwise @strv. - **/ -struct _EStrv * -e_strv_set_ref(struct _EStrv *strv, int index, char *str) -{ - struct _e_strvunpacked *s; - - s(printf("set ref %d '%s'\nawkmeharder: %s\n ", index, str, str)); - - if (strv->length != STRV_UNPACKED) - s = strv_unpack(strv); - else - s = (struct _e_strvunpacked *)strv; - - g_assert(index>=0 && index < s->length); - - s->strings[index].string = str; - - return (struct _EStrv *)s; -} - -/** - * e_strv_set_ref_free: - * @strv: - * @index: - * @str: - * - * Set a string by reference, similar to set_ref, but also - * free the string when finished with it. The string - * is not copied until the strv is packed, and not at - * all if the index is overwritten. - * - * Return value: @strv if already unpacked, otherwise an packed - * EStrv. - **/ -struct _EStrv * -e_strv_set_ref_free(struct _EStrv *strv, int index, char *str) -{ - struct _e_strvunpacked *s; - - s(printf("set ref %d '%s'\nawkmeevenharder: %s\n ", index, str, str)); - - if (strv->length != STRV_UNPACKED) - s = strv_unpack(strv); - else - s = (struct _e_strvunpacked *)strv; - - g_assert(index>=0 && index < s->length); - - s->strings[index].string = str; - if (s->strings[index].free) - g_free(s->strings[index].free); - s->strings[index].free = str; - - return (struct _EStrv *)s; -} - -/** - * e_strv_set: - * @strv: - * @index: - * @str: - * - * Set a string array reference. The string @str is copied - * into the string array at location @index. - * - * If @strv has been packed, then it is unpacked ready - * for more inserts, and should be packed again once finished with. - * - * Return value: A new EStrv if the strv has already - * been packed, otherwise @strv. - **/ -struct _EStrv * -e_strv_set(struct _EStrv *strv, int index, const char *str) -{ - struct _e_strvunpacked *s; - - s(printf("set %d '%s'\n", index, str)); - - if (strv->length != STRV_UNPACKED) - s = strv_unpack(strv); - else - s = (struct _e_strvunpacked *)strv; - - g_assert(index>=0 && index < s->length); - - if (s->pool == NULL) - s->pool = e_mempool_new(1024, 512, E_MEMPOOL_ALIGN_BYTE); - - s->strings[index].string = e_mempool_alloc(s->pool, strlen(str)+1); - strcpy(s->strings[index].string, str); - - return (struct _EStrv *)s; -} - -/** - * e_strv_pack: - * @strv: - * - * Pack the @strv into a space efficient structure for later lookup. - * - * All strings are packed into a single allocated block, separated - * by single \0 characters, together with a count byte. - * - * Return value: - **/ -struct _EStrv * -e_strv_pack(struct _EStrv *strv) -{ - struct _e_strvunpacked *s; - int len, i; - register char *src, *dst; - - if (strv->length == STRV_UNPACKED) { - s = (struct _e_strvunpacked *)strv; - - s(printf("packing string\n")); - - len = 0; - for (i=0;i<s->length;i++) - len += s->strings[i].string?strlen(s->strings[i].string)+1:1; - - strv = g_malloc(sizeof(*strv) + len); - s(printf("allocating strv=%p, size = %d\n", strv, sizeof(*strv)+len)); - strv->length = s->length; - dst = strv->data; - for (i=0;i<s->length;i++) { - if ((src = s->strings[i].string)) { - while ((*dst++ = *src++)) - ; - } else { - *dst++ = 0; - } - } - e_strv_destroy((struct _EStrv *)s); - } - return strv; -} - -/** - * e_strv_get: - * @strv: - * @index: - * - * Retrieve a string by index. This function works - * identically on both packed and unpacked strv's, although - * may be much slower on a packed strv. - * - * Return value: - **/ -char * -e_strv_get(struct _EStrv *strv, int index) -{ - struct _e_strvunpacked *s; - char *p; - - if (strv->length != STRV_UNPACKED) { - g_assert(index>=0 && index < strv->length); - p = strv->data; - while (index > 0) { - while (*p++ != 0) - ; - index--; - } - return p; - } else { - s = (struct _e_strvunpacked *)strv; - g_assert(index>=0 && index < s->length); - return s->strings[index].string?s->strings[index].string:""; - } -} - -/** - * e_strv_destroy: - * @strv: - * - * Free a strv and all associated memory. Works on packed - * or unpacked strv's. - **/ -void -e_strv_destroy(struct _EStrv *strv) -{ - struct _e_strvunpacked *s; - int i; - - s(printf("freeing strv\n")); - - if (strv->length == STRV_UNPACKED) { - s = (struct _e_strvunpacked *)strv; - if (s->pool) - e_mempool_destroy(s->pool); - if (s->source) - e_strv_destroy(s->source); - for (i=0;i<s->length;i++) { - if (s->strings[i].free) - g_free(s->strings[i].free); - } - } - - s(printf("freeing strv=%p\n", strv)); - - g_free(strv); -} - - - -/* string pool stuff */ - -/* TODO: - garbage collection, using the following technique: - Create a memchunk for each possible size of poolv, and allocate every poolv from those - To garbage collect, scan all memchunk internally, ignoring any free areas (or mark each - poolv when freeing it - set length 0?), and find out which strings are not anywhere, - then free them. - - OR: - Just keep a refcount in the hashtable, instead of duplicating the key pointer. - - either would also require a free for the mempool, so ignore it for now */ - -/*#define POOLV_REFCNT*/ /* Define to enable refcounting code that does - automatic garbage collection of unused strings */ - -static GHashTable *poolv_pool = NULL; -static EMemPool *poolv_mempool = NULL; - -#ifdef MALLOC_CHECK -static GPtrArray *poolv_table = NULL; -#endif - -#ifdef PROFILE_POOLV -static gulong poolv_hits = 0; -static gulong poolv_misses = 0; -#endif - -#ifdef G_THREADS_ENABLED -static GStaticMutex poolv_mutex = G_STATIC_MUTEX_INIT; -#endif - -struct _EPoolv { - unsigned char length; - char *s[1]; -}; - -/** - * e_poolv_new: @size: The number of elements in the poolv, maximum of 254 elements. - * - * create a new poolv (string vector which shares a global string - * pool). poolv's can be used to work with arrays of strings which - * save memory by eliminating duplicated allocations of the same - * string. - * - * this is useful when you have a log of read-only strings that do not - * go away and are duplicated a lot (such as email headers). - * - * we should probably in the future ref count the strings contained in - * the hash table, but for now let's not. - * - * Return value: new pooled string vector - **/ -EPoolv * -e_poolv_new(unsigned int size) -{ - EPoolv *poolv; - - g_assert(size < 255); - - poolv = g_malloc0(sizeof (*poolv) + (size - 1) * sizeof (char *)); - poolv->length = size; - -#ifdef G_THREADS_ENABLED - g_static_mutex_lock(&poolv_mutex); -#endif - if (!poolv_pool) - poolv_pool = g_hash_table_new(g_str_hash, g_str_equal); - - if (!poolv_mempool) - poolv_mempool = e_mempool_new(32 * 1024, 512, E_MEMPOOL_ALIGN_BYTE); - -#ifdef MALLOC_CHECK - { - int i; - - if (poolv_table == NULL) - poolv_table = g_ptr_array_new(); - - for (i=0;i<poolv_table->len;i++) - MPROBE(poolv_table->pdata[i]); - - g_ptr_array_add(poolv_table, poolv); - } -#endif - -#ifdef G_THREADS_ENABLED - g_static_mutex_unlock(&poolv_mutex); -#endif - - p(printf("new poolv=%p\tsize=%d\n", poolv, sizeof(*poolv) + (size-1)*sizeof(char *))); - - return poolv; -} - -/** - * e_poolv_cpy: - * @dest: destination pooled string vector - * @src: source pooled string vector - * - * Copy the contents of a pooled string vector - * - * Return value: @dest, which may be re-allocated if the strings - * are different lengths. - **/ -EPoolv * -e_poolv_cpy(EPoolv *dest, const EPoolv *src) -{ -#ifdef POOLV_REFCNT - int i; - unsigned int ref; - char *key; -#endif - - p2(g_return_val_if_fail (dest != NULL, NULL)); - p2(g_return_val_if_fail (src != NULL, NULL)); - - MPROBE(dest); - MPROBE(src); - - if (dest->length != src->length) { - e_poolv_destroy(dest); - dest = e_poolv_new(src->length); - } - -#ifdef POOLV_REFCNT -#ifdef G_THREADS_ENABLED - g_static_mutex_lock(&poolv_mutex); -#endif - /* ref new copies */ - for (i=0;i<src->length;i++) { - if (src->s[i]) { - if (g_hash_table_lookup_extended(poolv_pool, src->s[i], (void **)&key, (void **)&ref)) { - g_hash_table_insert(poolv_pool, key, (void *)(ref+1)); - } else { - g_assert_not_reached(); - } - } - } - - /* unref the old ones */ - for (i=0;i<dest->length;i++) { - if (dest->s[i]) { - if (g_hash_table_lookup_extended(poolv_pool, dest->s[i], (void **)&key, (void **)&ref)) { - /* if ref == 1 free it */ - g_assert(ref > 0); - g_hash_table_insert(poolv_pool, key, (void *)(ref-1)); - } else { - g_assert_not_reached(); - } - } - } -#ifdef G_THREADS_ENABLED - g_static_mutex_unlock(&poolv_mutex); -#endif -#endif - - memcpy(dest->s, src->s, src->length * sizeof (char *)); - - return dest; -} - -#ifdef PROFILE_POOLV -static void -poolv_profile_update (void) -{ - static time_t last_time = 0; - time_t new_time; - - new_time = time (NULL); - if (new_time - last_time < 5) - return; - - printf("poolv profile: %lu hits, %lu misses: %d%% hit rate\n", - poolv_hits, poolv_misses, - (int)(100.0 * ((double) poolv_hits / (double) (poolv_hits + poolv_misses)))); - - last_time = new_time; -} -#endif - -/** - * e_poolv_set: - * @poolv: pooled string vector - * @index: index in vector of string - * @str: string to set - * @freeit: whether the caller is releasing its reference to the - * string - * - * Set a string vector reference. If the caller will no longer be - * referencing the string, freeit should be TRUE. Otherwise, this - * will duplicate the string if it is not found in the pool. - * - * Return value: @poolv - **/ -EPoolv * -e_poolv_set (EPoolv *poolv, int index, char *str, int freeit) -{ -#ifdef POOLV_REFCNT - unsigned int ref; - char *key; -#endif - - p2(g_return_val_if_fail (poolv != NULL, NULL)); - - g_assert(index >=0 && index < poolv->length); - - MPROBE(poolv); - - p(printf("setting %d `%s'\n", index, str)); - - if (!str) { -#ifdef POOLV_REFCNT - if (poolv->s[index]) { - if (g_hash_table_lookup_extended(poolv_pool, poolv->s[index], (void **)&key, (void **)&ref)) { - g_assert(ref > 0); - g_hash_table_insert(poolv_pool, key, (void *)(ref-1)); - } else { - g_assert_not_reached(); - } - } -#endif - poolv->s[index] = NULL; - return poolv; - } - -#ifdef G_THREADS_ENABLED - g_static_mutex_lock(&poolv_mutex); -#endif - -#ifdef POOLV_REFCNT - if (g_hash_table_lookup_extended(poolv_pool, str, (void **)&key, (void **)&ref)) { - g_hash_table_insert(poolv_pool, key, (void *)(ref+1)); - poolv->s[index] = key; -# ifdef PROFILE_POOLV - poolv_hits++; - poolv_profile_update (); -# endif - } else { -# ifdef PROFILE_POOLV - poolv_misses++; - poolv_profile_update (); -# endif - poolv->s[index] = e_mempool_strdup(poolv_mempool, str); - g_hash_table_insert(poolv_pool, poolv->s[index], (void *)1); - } - -#else /* !POOLV_REFCNT */ - if ((poolv->s[index] = g_hash_table_lookup(poolv_pool, str)) != NULL) { -# ifdef PROFILE_POOLV - poolv_hits++; - poolv_profile_update (); -# endif - } else { -# ifdef PROFILE_POOLV - poolv_misses++; - poolv_profile_update (); -# endif - poolv->s[index] = e_mempool_strdup(poolv_mempool, str); - g_hash_table_insert(poolv_pool, poolv->s[index], poolv->s[index]); - } -#endif /* !POOLV_REFCNT */ - -#ifdef G_THREADS_ENABLED - g_static_mutex_unlock(&poolv_mutex); -#endif - - if (freeit) - g_free(str); - - return poolv; -} - -/** - * e_poolv_get: - * @poolv: pooled string vector - * @index: index in vector of string - * - * Retrieve a string by index. This could possibly just be a macro. - * - * Since the pool is never freed, this string does not need to be - * duplicated, but should not be modified. - * - * Return value: string at that index. - **/ -const char * -e_poolv_get(EPoolv *poolv, int index) -{ - g_assert(poolv != NULL); - g_assert(index>= 0 && index < poolv->length); - - MPROBE(poolv); - - p(printf("get %d = `%s'\n", index, poolv->s[index])); - - return poolv->s[index]?poolv->s[index]:""; -} - -/** - * e_poolv_destroy: - * @poolv: pooled string vector to free - * - * Free a pooled string vector. This doesn't free the strings from - * the vector, however. - **/ -void -e_poolv_destroy(EPoolv *poolv) -{ -#ifdef POOLV_REFCNT - int i; - unsigned int ref; - char *key; - - MPROBE(poolv); - -#ifdef G_THREADS_ENABLED - g_static_mutex_lock(&poolv_mutex); -#endif - -#ifdef MALLOC_CHECK - for (i=0;i<poolv_table->len;i++) - MPROBE(poolv_table->pdata[i]); - - g_ptr_array_remove_fast(poolv_table, poolv); -#endif - - for (i=0;i<poolv->length;i++) { - if (poolv->s[i]) { - if (g_hash_table_lookup_extended(poolv_pool, poolv->s[i], (void **)&key, (void **)&ref)) { - /* if ref == 1 free it */ - g_assert(ref > 0); - g_hash_table_insert(poolv_pool, key, (void *)(ref-1)); - } else { - g_assert_not_reached(); - } - } - } -#ifdef G_THREADS_ENABLED - g_static_mutex_unlock(&poolv_mutex); -#endif -#endif - - g_free(poolv); -} - -#if 0 - -#define CHUNK_SIZE (20) -#define CHUNK_COUNT (32) - -#define s(x) - -main() -{ - int i; - MemChunk *mc; - void *mem, *last; - GMemChunk *gmc; - struct _EStrv *s; - - s = strv_new(8); - s = strv_set(s, 1, "Testing 1"); - s = strv_set(s, 2, "Testing 2"); - s = strv_set(s, 3, "Testing 3"); - s = strv_set(s, 4, "Testing 4"); - s = strv_set(s, 5, "Testing 5"); - s = strv_set(s, 6, "Testing 7"); - - for (i=0;i<8;i++) { - printf("s[%d] = %s\n", i, strv_get(s, i)); - } - - s(sleep(5)); - - printf("packing ...\n"); - s = strv_pack(s); - - for (i=0;i<8;i++) { - printf("s[%d] = %s\n", i, strv_get(s, i)); - } - - printf("setting ...\n"); - - s = strv_set_ref(s, 1, "Testing 1 x"); - - for (i=0;i<8;i++) { - printf("s[%d] = %s\n", i, strv_get(s, i)); - } - - printf("packing ...\n"); - s = strv_pack(s); - - for (i=0;i<8;i++) { - printf("s[%d] = %s\n", i, strv_get(s, i)); - } - - strv_free(s); - -#if 0 - time_start("Using memchunks"); - mc = memchunk_new(CHUNK_COUNT, CHUNK_SIZE); - for (i=0;i<1000000;i++) { - mem = memchunk_alloc(mc); - if ((i & 1) == 0) - memchunk_free(mc, mem); - } - s(sleep(10)); - memchunk_destroy(mc); - time_end("allocating 1000000 memchunks, freeing 500k"); - - time_start("Using gmemchunks"); - gmc = g_mem_chunk_new("memchunk", CHUNK_SIZE, CHUNK_SIZE*CHUNK_COUNT, G_ALLOC_AND_FREE); - for (i=0;i<1000000;i++) { - mem = g_mem_chunk_alloc(gmc); - if ((i & 1) == 0) - g_mem_chunk_free(gmc, mem); - } - s(sleep(10)); - g_mem_chunk_destroy(gmc); - time_end("allocating 1000000 gmemchunks, freeing 500k"); - - time_start("Using memchunks"); - mc = memchunk_new(CHUNK_COUNT, CHUNK_SIZE); - for (i=0;i<1000000;i++) { - mem = memchunk_alloc(mc); - } - s(sleep(10)); - memchunk_destroy(mc); - time_end("allocating 1000000 memchunks"); - - time_start("Using gmemchunks"); - gmc = g_mem_chunk_new("memchunk", CHUNK_SIZE, CHUNK_COUNT*CHUNK_SIZE, G_ALLOC_ONLY); - for (i=0;i<1000000;i++) { - mem = g_mem_chunk_alloc(gmc); - } - s(sleep(10)); - g_mem_chunk_destroy(gmc); - time_end("allocating 1000000 gmemchunks"); - - time_start("Using malloc"); - for (i=0;i<1000000;i++) { - malloc(CHUNK_SIZE); - } - time_end("allocating 1000000 malloc"); -#endif - -} - -#endif diff --git a/e-util/e-memory.h b/e-util/e-memory.h deleted file mode 100644 index c609a896be..0000000000 --- a/e-util/e-memory.h +++ /dev/null @@ -1,75 +0,0 @@ -/* - * Copyright (C) 2001, Ximian Inc. - * - * Authors: Michael Zucchi <notzed@ximian.com> - * Jacob Berkman <jacob@ximian.com> - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -#ifndef _E_MEMORY_H -#define _E_MEMORY_H - -/* memchunks - allocate/free fixed-size blocks of memory */ -/* this is like gmemchunk, only faster and less overhead (only 4 bytes for every atomcount allocations) */ -typedef struct _EMemChunk EMemChunk; - -EMemChunk *e_memchunk_new(int atomcount, int atomsize); -void *e_memchunk_alloc(EMemChunk *m); -void *e_memchunk_alloc0(EMemChunk *m); -void e_memchunk_free(EMemChunk *m, void *mem); -void e_memchunk_empty(EMemChunk *m); -void e_memchunk_clean(EMemChunk *m); -void e_memchunk_destroy(EMemChunk *m); - -/* mempools - allocate variable sized blocks of memory, and free as one */ -/* allocation is very fast, but cannot be freed individually */ -typedef struct _EMemPool EMemPool; -typedef enum { - E_MEMPOOL_ALIGN_STRUCT = 0, /* allocate to native structure alignment */ - E_MEMPOOL_ALIGN_WORD = 1, /* allocate to words - 16 bit alignment */ - E_MEMPOOL_ALIGN_BYTE = 2, /* allocate to bytes - 8 bit alignment */ - E_MEMPOOL_ALIGN_MASK = 3, /* which bits determine the alignment information */ -} EMemPoolFlags; - -EMemPool *e_mempool_new(int blocksize, int threshold, EMemPoolFlags flags); -void *e_mempool_alloc(EMemPool *pool, int size); -char *e_mempool_strdup(EMemPool *pool, const char *str); -void e_mempool_flush(EMemPool *pool, int freeall); -void e_mempool_destroy(EMemPool *pool); - -/* strv's string arrays that can be efficiently modified and then compressed mainly for retrival */ -/* building is relatively fast, once compressed it takes the minimum amount of memory possible to store */ -typedef struct _EStrv EStrv; - -EStrv *e_strv_new(int size); -EStrv *e_strv_set_ref(EStrv *strv, int index, char *str); -EStrv *e_strv_set_ref_free(EStrv *strv, int index, char *str); -EStrv *e_strv_set(EStrv *strv, int index, const char *str); -EStrv *e_strv_pack(EStrv *strv); -char *e_strv_get(EStrv *strv, int index); -void e_strv_destroy(EStrv *strv); - -/* poolv's are similar to strv's, but they store common strings */ -typedef struct _EPoolv EPoolv; - -EPoolv *e_poolv_new(unsigned int size); -EPoolv *e_poolv_cpy(EPoolv *dest, const EPoolv *src); -EPoolv *e_poolv_set(EPoolv *poolv, int index, char *str, int freeit); -const char *e_poolv_get(EPoolv *poolv, int index); -void e_poolv_destroy(EPoolv *poolv); - -#endif /* ! _E_MEMORY_H */ diff --git a/e-util/e-mktemp.c b/e-util/e-mktemp.c deleted file mode 100644 index e532498c1d..0000000000 --- a/e-util/e-mktemp.c +++ /dev/null @@ -1,265 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: Jeffrey Stedfast <fejj@ximian.com> - * - * Copyright 2001 Ximian, Inc. (www.ximian.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. - * - */ - - -#include "e-mktemp.h" - -#include <config.h> - -#include <glib.h> -#include <sys/stat.h> -#include <sys/types.h> -#include <stdlib.h> -#include <fcntl.h> -#include <unistd.h> -#include <dirent.h> -#include <errno.h> - -#ifdef ENABLE_THREADS -#include <pthread.h> -#endif - - -static gboolean initialized = FALSE; -static GSList *temp_files = NULL; -static GSList *temp_dirs = NULL; -#ifdef ENABLE_THREADS -static pthread_mutex_t temp_files_lock = PTHREAD_MUTEX_INITIALIZER; -static pthread_mutex_t temp_dirs_lock = PTHREAD_MUTEX_INITIALIZER; -#define TEMP_FILES_LOCK() pthread_mutex_lock (&temp_files_lock) -#define TEMP_FILES_UNLOCK() pthread_mutex_unlock (&temp_files_lock) -#define TEMP_DIRS_LOCK() pthread_mutex_lock (&temp_dirs_lock) -#define TEMP_DIRS_UNLOCK() pthread_mutex_unlock (&temp_dirs_lock) -#else -#define TEMP_FILES_LOCK() -#define TEMP_FILES_UNLOCK() -#define TEMP_DIRS_LOCK() -#define TEMP_DIRS_UNLOCK() -#endif /* ENABLE_THREADS */ - - -static GString * -get_path (gboolean make) -{ - GString *path; - - path = g_string_new ("/tmp/evolution-"); - g_string_sprintfa (path, "%d-%d", (int) getuid (), (int) getpid ()); - - if (make) { - int ret; - - /* shoot now, ask questions later */ - ret = mkdir (path->str, S_IRWXU); - if (ret == -1) { - if (errno == EEXIST) { - struct stat st; - - if (stat (path->str, &st) == -1) { - /* reset errno */ - errno = EEXIST; - g_string_free (path, TRUE); - return NULL; - } - - /* make sure this is a directory and belongs to us... */ - if (!S_ISDIR (st.st_mode) || st.st_uid != getuid ()) { - /* eek! this is bad... */ - g_string_free (path, TRUE); - return NULL; - } - } else { - /* some other error...do not pass go, do not collect $200 */ - g_string_free (path, TRUE); - return NULL; - } - } - } - - return path; -} - -static void -e_mktemp_cleanup (void) -{ - GString *path; - GSList *node; - - TEMP_FILES_LOCK (); - if (temp_files) { - node = temp_files; - while (node) { - unlink (node->data); - g_free (node->data); - node = node->next; - } - g_slist_free (temp_files); - temp_files = NULL; - } - TEMP_FILES_UNLOCK (); - - TEMP_DIRS_LOCK (); - if (temp_dirs) { - node = temp_dirs; - while (node) { - /* perform the equivalent of a rm -rf */ - struct dirent *dent; - DIR *dir; - - /* first empty out this directory of it's files... */ - dir = opendir (node->data); - while ((dent = readdir (dir)) != NULL) { - /* yea...so if we contain - subdirectories this won't work, but - it shouldn't so we won't - bother caring... */ - if (strcmp (dent->d_name, ".") && strcmp (dent->d_name, "..")) - unlink (dent->d_name); - } - closedir (dir); - - /* ...then rmdir the directory */ - rmdir (node->data); - g_free (node->data); - node = node->next; - } - g_slist_free (temp_dirs); - temp_dirs = NULL; - } - TEMP_DIRS_UNLOCK (); - - path = get_path (FALSE); - rmdir (path->str); - - g_string_free (path, TRUE); -} - - -const char * -e_mktemp (const char *template) -{ - GString *path; - char *ret; - - path = get_path (TRUE); - if (!path) - return NULL; - - g_string_append_c (path, '/'); - if (template) - g_string_append (path, template); - else - g_string_append (path, "unknown-XXXXXX"); - - ret = mktemp (path->str); - if (ret) { - TEMP_FILES_LOCK (); - if (!initialized) { - g_atexit (e_mktemp_cleanup); - initialized = TRUE; - } - temp_files = g_slist_prepend (temp_files, ret); - g_string_free (path, FALSE); - TEMP_FILES_UNLOCK (); - } else { - g_string_free (path, TRUE); - } - - return ret; -} - - -int -e_mkstemp (const char *template) -{ - GString *path; - int fd; - - path = get_path (TRUE); - if (!path) - return -1; - - g_string_append_c (path, '/'); - if (template) - g_string_append (path, template); - else - g_string_append (path, "unknown-XXXXXX"); - - fd = mkstemp (path->str); - if (fd != -1) { - TEMP_FILES_LOCK (); - if (!initialized) { - g_atexit (e_mktemp_cleanup); - initialized = TRUE; - } - temp_files = g_slist_prepend (temp_files, path->str); - g_string_free (path, FALSE); - TEMP_FILES_UNLOCK (); - } else { - g_string_free (path, TRUE); - } - - return fd; -} - - -const char * -e_mkdtemp (const char *template) -{ - GString *path; - char *tmpdir; - - path = get_path (TRUE); - if (!path) - return NULL; - - g_string_append_c (path, '/'); - if (template) - g_string_append (path, template); - else - g_string_append (path, "unknown-XXXXXX"); - -#ifdef HAVE_MKDTEMP - tmpdir = mkdtemp (path->str); -#else - tmpdir = mktemp (path->str); - if (tmpdir) { - if (mkdir (tmpdir, S_IRWXU) == -1) - tmpdir = NULL; - } -#endif - - if (tmpdir) { - TEMP_DIRS_LOCK (); - if (!initialized) { - g_atexit (e_mktemp_cleanup); - initialized = TRUE; - } - temp_dirs = g_slist_prepend (temp_dirs, tmpdir); - g_string_free (path, FALSE); - TEMP_DIRS_UNLOCK (); - } else { - g_string_free (path, TRUE); - } - - return tmpdir; -} diff --git a/e-util/e-mktemp.h b/e-util/e-mktemp.h deleted file mode 100644 index 9f7831d7b5..0000000000 --- a/e-util/e-mktemp.h +++ /dev/null @@ -1,33 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Authors: Jeffrey Stedfast <fejj@ximian.com> - * - * Copyright 2001 Ximian, Inc. (www.ximian.com) - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Street #330, Boston, MA 02111-1307, USA. - * - */ - - -#ifndef __E_MKTEMP_H__ -#define __E_MKTEMP_H__ - -const char *e_mktemp (const char *template); - -int e_mkstemp (const char *template); - -const char *e_mkdtemp (const char *template); - -#endif /* __E_MKTEMP_H__ */ diff --git a/e-util/e-msgport.c b/e-util/e-msgport.c deleted file mode 100644 index d034f0deaf..0000000000 --- a/e-util/e-msgport.c +++ /dev/null @@ -1,876 +0,0 @@ - -#include "e-msgport.h" - -#include <sys/time.h> -#include <sys/types.h> -#include <unistd.h> -#include <errno.h> -#include <string.h> -#include <stdio.h> - -#include <pthread.h> - -#include <glib.h> - -#define m(x) /* msgport debug */ -#define t(x) /* thread debug */ - -void e_dlist_init(EDList *v) -{ - v->head = (EDListNode *)&v->tail; - v->tail = 0; - v->tailpred = (EDListNode *)&v->head; -} - -EDListNode *e_dlist_addhead(EDList *l, EDListNode *n) -{ - n->next = l->head; - n->prev = (EDListNode *)&l->head; - l->head->prev = n; - l->head = n; - return n; -} - -EDListNode *e_dlist_addtail(EDList *l, EDListNode *n) -{ - n->next = (EDListNode *)&l->tail; - n->prev = l->tailpred; - l->tailpred->next = n; - l->tailpred = n; - return n; -} - -EDListNode *e_dlist_remove(EDListNode *n) -{ - n->next->prev = n->prev; - n->prev->next = n->next; - return n; -} - -EDListNode *e_dlist_remhead(EDList *l) -{ - EDListNode *n, *nn; - - n = l->head; - nn = n->next; - if (nn) { - nn->prev = n->prev; - l->head = nn; - return n; - } - return NULL; -} - -EDListNode *e_dlist_remtail(EDList *l) -{ - EDListNode *n, *np; - - n = l->tailpred; - np = n->prev; - if (np) { - np->next = n->next; - l->tailpred = np; - return n; - } - return NULL; -} - -int e_dlist_empty(EDList *l) -{ - return (l->head == (EDListNode *)&l->tail); -} - -int e_dlist_length(EDList *l) -{ - EDListNode *n, *nn; - int count = 0; - - n = l->head; - nn = n->next; - while (nn) { - count++; - n = nn; - nn = n->next; - } - - return 0; -} - -struct _EMsgPort { - EDList queue; - int condwait; /* how many waiting in condwait */ - union { - int pipe[2]; - struct { - int read; - int write; - } fd; - } pipe; - /* @#@$#$ glib stuff */ - GCond *cond; - GMutex *lock; -}; - -EMsgPort *e_msgport_new(void) -{ - EMsgPort *mp; - - mp = g_malloc(sizeof(*mp)); - e_dlist_init(&mp->queue); - mp->lock = g_mutex_new(); - mp->cond = g_cond_new(); - mp->pipe.fd.read = -1; - mp->pipe.fd.write = -1; - mp->condwait = 0; - - return mp; -} - -void e_msgport_destroy(EMsgPort *mp) -{ - g_mutex_free(mp->lock); - g_cond_free(mp->cond); - if (mp->pipe.fd.read != -1) { - close(mp->pipe.fd.read); - close(mp->pipe.fd.write); - } - g_free(mp); -} - -/* get a fd that can be used to wait on the port asynchronously */ -int e_msgport_fd(EMsgPort *mp) -{ - int fd; - - g_mutex_lock(mp->lock); - fd = mp->pipe.fd.read; - if (fd == -1) { - pipe(mp->pipe.pipe); - fd = mp->pipe.fd.read; - } - g_mutex_unlock(mp->lock); - - return fd; -} - -void e_msgport_put(EMsgPort *mp, EMsg *msg) -{ - m(printf("put:\n")); - g_mutex_lock(mp->lock); - e_dlist_addtail(&mp->queue, &msg->ln); - if (mp->condwait > 0) { - m(printf("put: condwait > 0, waking up\n")); - g_cond_signal(mp->cond); - } - if (mp->pipe.fd.write != -1) { - m(printf("put: have pipe, writing notification to it\n")); - write(mp->pipe.fd.write, "", 1); - } - g_mutex_unlock(mp->lock); - m(printf("put: done\n")); -} - -static void -msgport_cleanlock(void *data) -{ - EMsgPort *mp = data; - - g_mutex_unlock(mp->lock); -} - -EMsg *e_msgport_wait(EMsgPort *mp) -{ - EMsg *msg; - - m(printf("wait:\n")); - g_mutex_lock(mp->lock); - while (e_dlist_empty(&mp->queue)) { - if (mp->pipe.fd.read == -1) { - m(printf("wait: waiting on condition\n")); - mp->condwait++; - /* if we are cancelled in the cond-wait, then we need to unlock our lock when we cleanup */ - pthread_cleanup_push(msgport_cleanlock, mp); - g_cond_wait(mp->cond, mp->lock); - pthread_cleanup_pop(0); - m(printf("wait: got condition\n")); - mp->condwait--; - } else { - fd_set rfds; - - m(printf("wait: waitng on pipe\n")); - FD_ZERO(&rfds); - FD_SET(mp->pipe.fd.read, &rfds); - g_mutex_unlock(mp->lock); - select(mp->pipe.fd.read+1, &rfds, NULL, NULL, NULL); - pthread_testcancel(); - g_mutex_lock(mp->lock); - m(printf("wait: got pipe\n")); - } - } - msg = (EMsg *)mp->queue.head; - m(printf("wait: message = %p\n", msg)); - g_mutex_unlock(mp->lock); - m(printf("wait: done\n")); - return msg; -} - -EMsg *e_msgport_get(EMsgPort *mp) -{ - EMsg *msg; - char dummy[1]; - - g_mutex_lock(mp->lock); - msg = (EMsg *)e_dlist_remhead(&mp->queue); - if (msg && mp->pipe.fd.read != -1) - read(mp->pipe.fd.read, dummy, 1); - m(printf("get: message = %p\n", msg)); - g_mutex_unlock(mp->lock); - - return msg; -} - -void e_msgport_reply(EMsg *msg) -{ - if (msg->reply_port) { - e_msgport_put(msg->reply_port, msg); - } - /* else lost? */ -} - -struct _thread_info { - pthread_t id; - int busy; -}; - -struct _EThread { - EMsgPort *server_port; - EMsgPort *reply_port; - pthread_mutex_t mutex; - e_thread_t type; - int queue_limit; - - int waiting; /* if we are waiting for a new message, count of waiting processes */ - pthread_t id; /* id of our running child thread */ - GList *id_list; /* if THREAD_NEW, then a list of our child threads in thread_info structs */ - - EThreadFunc destroy; - void *destroy_data; - - EThreadFunc received; - void *received_data; - - EThreadFunc lost; - void *lost_data; -}; - -#define E_THREAD_NONE ((pthread_t)~0) - -static void thread_destroy_msg(EThread *e, EMsg *m); - -static struct _thread_info *thread_find(EThread *e, pthread_t id) -{ - GList *node; - struct _thread_info *info; - - node = e->id_list; - while (node) { - info = node->data; - if (info->id == id) - return info; - node = node->next; - } - return NULL; -} - -#if 0 -static void thread_remove(EThread *e, pthread_t id) -{ - GList *node; - struct _thread_info *info; - - node = e->id_list; - while (node) { - info = node->data; - if (info->id == id) { - e->id_list = g_list_remove(e->id_list, info); - g_free(info); - } - node = node->next; - } -} -#endif - -EThread *e_thread_new(e_thread_t type) -{ - EThread *e; - - e = g_malloc0(sizeof(*e)); - pthread_mutex_init(&e->mutex, 0); - e->type = type; - e->server_port = e_msgport_new(); - e->id = E_THREAD_NONE; - e->queue_limit = INT_MAX; - - return e; -} - -/* close down the threads & resources etc */ -void e_thread_destroy(EThread *e) -{ - int tries = 0; - int busy = FALSE; - EMsg *msg; - struct _thread_info *info; - - /* make sure we soak up all the messages first */ - while ( (msg = e_msgport_get(e->server_port)) ) { - thread_destroy_msg(e, msg); - } - - pthread_mutex_lock(&e->mutex); - - switch(e->type) { - case E_THREAD_QUEUE: - case E_THREAD_DROP: - /* if we have a thread, 'kill' it */ - while (e->id != E_THREAD_NONE && tries < 500) { - if (e->waiting > 0) { - pthread_t id = e->id; - e->id = E_THREAD_NONE; - pthread_mutex_unlock(&e->mutex); - if (pthread_cancel(id) == 0) - pthread_join(id, 0); - pthread_mutex_lock(&e->mutex); - } else { - (printf("thread still active, waiting for it to finish\n")); - pthread_mutex_unlock(&e->mutex); - sleep(1); - pthread_mutex_lock(&e->mutex); - } - tries++; - } - busy = e->id != E_THREAD_NONE; - break; - case E_THREAD_NEW: - while (e->id_list && tries < 500) { - info = e->id_list->data; - if (!info->busy) { - e->id_list = g_list_remove(e->id_list, info); - printf("cleaning up pool thread %ld\n", info->id); - pthread_mutex_unlock(&e->mutex); - if (pthread_cancel(info->id) == 0) - pthread_join(info->id, 0); - pthread_mutex_lock(&e->mutex); - printf("cleaned up ok\n"); - g_free(info); - } else { - (printf("thread(s) still active, waiting for it to finish\n")); - tries++; - pthread_mutex_unlock(&e->mutex); - sleep(1); - pthread_mutex_lock(&e->mutex); - } - } -#if 0 - while (g_list_length(e->id_list) && tries < 5) { - (printf("thread(s) still active, waiting for them to finish\n")); - pthread_mutex_unlock(&e->mutex); - sleep(1); - pthread_mutex_lock(&e->mutex); - } -#endif - busy = g_list_length(e->id_list) != 0; - break; - } - - pthread_mutex_unlock(&e->mutex); - - /* and clean up, if we can */ - if (busy) { - g_warning("threads were busy, leaked EThread"); - return; - } - - e_msgport_destroy(e->server_port); - g_free(e); -} - -/* set the queue maximum depth, what happens when the queue - fills up depends on the queue type */ -void e_thread_set_queue_limit(EThread *e, int limit) -{ - e->queue_limit = limit; -} - -/* set a msg destroy callback, this can not call any e_thread functions on @e */ -void e_thread_set_msg_destroy(EThread *e, EThreadFunc destroy, void *data) -{ - pthread_mutex_lock(&e->mutex); - e->destroy = destroy; - e->destroy_data = data; - pthread_mutex_unlock(&e->mutex); -} - -/* set a message lost callback, called if any message is discarded */ -void e_thread_set_msg_lost(EThread *e, EThreadFunc lost, void *data) -{ - pthread_mutex_lock(&e->mutex); - e->lost = lost; - e->lost_data = lost; - pthread_mutex_unlock(&e->mutex); -} - -/* set a reply port, if set, then send messages back once finished */ -void e_thread_set_reply_port(EThread *e, EMsgPort *reply_port) -{ - e->reply_port = reply_port; -} - -/* set a received data callback */ -void e_thread_set_msg_received(EThread *e, EThreadFunc received, void *data) -{ - pthread_mutex_lock(&e->mutex); - e->received = received; - e->received_data = data; - pthread_mutex_unlock(&e->mutex); -} - -static void -thread_destroy_msg(EThread *e, EMsg *m) -{ - EThreadFunc func; - void *func_data; - - /* we do this so we never get an incomplete/unmatched callback + data */ - pthread_mutex_lock(&e->mutex); - func = e->destroy; - func_data = e->destroy_data; - pthread_mutex_unlock(&e->mutex); - - if (func) - func(e, m, func_data); -} - -static void -thread_received_msg(EThread *e, EMsg *m) -{ - EThreadFunc func; - void *func_data; - - /* we do this so we never get an incomplete/unmatched callback + data */ - pthread_mutex_lock(&e->mutex); - func = e->received; - func_data = e->received_data; - pthread_mutex_unlock(&e->mutex); - - if (func) - func(e, m, func_data); - else - g_warning("No processing callback for EThread, message unprocessed"); -} - -static void -thread_lost_msg(EThread *e, EMsg *m) -{ - EThreadFunc func; - void *func_data; - - /* we do this so we never get an incomplete/unmatched callback + data */ - pthread_mutex_lock(&e->mutex); - func = e->lost; - func_data = e->lost_data; - pthread_mutex_unlock(&e->mutex); - - if (func) - func(e, m, func_data); -} - -/* the actual thread dispatcher */ -static void * -thread_dispatch(void *din) -{ - EThread *e = din; - EMsg *m; - struct _thread_info *info; - - t(printf("dispatch thread started: %ld\n", pthread_self())); - - while (1) { - pthread_mutex_lock(&e->mutex); - m = e_msgport_get(e->server_port); - if (m == NULL) { - /* nothing to do? If we are a 'new' type thread, just quit. - Otherwise, go into waiting (can be cancelled here) */ - info = NULL; - switch (e->type) { - case E_THREAD_NEW: - case E_THREAD_QUEUE: - case E_THREAD_DROP: - info = thread_find(e, pthread_self()); - if (info) - info->busy = FALSE; - e->waiting++; - pthread_mutex_unlock(&e->mutex); - e_msgport_wait(e->server_port); - pthread_mutex_lock(&e->mutex); - e->waiting--; - pthread_mutex_unlock(&e->mutex); - break; -#if 0 - case E_THREAD_NEW: - e->id_list = g_list_remove(e->id_list, (void *)pthread_self()); - pthread_mutex_unlock(&e->mutex); - return 0; -#endif - } - - continue; - } else { - info = thread_find(e, pthread_self()); - if (info) - info->busy = TRUE; - } - pthread_mutex_unlock(&e->mutex); - - t(printf("got message in dispatch thread\n")); - - /* process it */ - thread_received_msg(e, m); - - /* if we have a reply port, send it back, otherwise, lose it */ - if (m->reply_port) { - e_msgport_reply(m); - } else { - thread_destroy_msg(e, m); - } - } - - /* if we run out of things to process we could conceivably 'hang around' for a bit, - but to do this we need to use the fd interface of the msgport, and its utility - is probably debatable anyway */ - -#if 0 - /* signify we are no longer running */ - /* This code isn't used yet, but would be if we ever had a 'quit now' message implemented */ - pthread_mutex_lock(&e->mutex); - switch (e->type) { - case E_THREAD_QUEUE: - case E_THREAD_DROP: - e->id = E_THREAD_NONE; - break; - case E_THREAD_NEW: - e->id_list = g_list_remove(e->id_list, (void *)pthread_self()); - break; - } - pthread_mutex_unlock(&e->mutex); -#endif - - return 0; -} - -/* send a message to the thread, start thread if necessary */ -void e_thread_put(EThread *e, EMsg *msg) -{ - pthread_t id; - EMsg *dmsg = NULL; - - pthread_mutex_lock(&e->mutex); - - /* the caller forgot to tell us what to do, well, we can't do anything can we */ - if (e->received == NULL) { - pthread_mutex_unlock(&e->mutex); - g_warning("EThread called with no receiver function, no work to do!"); - thread_destroy_msg(e, msg); - return; - } - - msg->reply_port = e->reply_port; - - switch(e->type) { - case E_THREAD_QUEUE: - /* if the queue is full, lose this new addition */ - if (e_dlist_length(&e->server_port->queue) < e->queue_limit) { - e_msgport_put(e->server_port, msg); - } else { - printf("queue limit reached, dropping new message\n"); - dmsg = msg; - } - break; - case E_THREAD_DROP: - /* if the queue is full, lose the oldest (unprocessed) message */ - if (e_dlist_length(&e->server_port->queue) < e->queue_limit) { - e_msgport_put(e->server_port, msg); - } else { - printf("queue limit reached, dropping old message\n"); - e_msgport_put(e->server_port, msg); - dmsg = e_msgport_get(e->server_port); - } - break; - case E_THREAD_NEW: - /* it is possible that an existing thread can catch this message, so - we might create a thread with no work to do. - but that doesn't matter, the other alternative that it be lost is worse */ - e_msgport_put(e->server_port, msg); - if (e->waiting == 0 - && g_list_length(e->id_list) < e->queue_limit - && pthread_create(&id, NULL, thread_dispatch, e) == 0) { - struct _thread_info *info = g_malloc0(sizeof(*info)); - t(printf("created NEW thread %ld\n", id)); - info->id = id; - info->busy = TRUE; - e->id_list = g_list_append(e->id_list, info); - } - pthread_mutex_unlock(&e->mutex); - return; - } - - /* create the thread, if there is none to receive it yet */ - if (e->id == E_THREAD_NONE) { - if (pthread_create(&e->id, NULL, thread_dispatch, e) == -1) { - g_warning("Could not create dispatcher thread, message queued?: %s", strerror(errno)); - e->id = E_THREAD_NONE; - } - } - - pthread_mutex_unlock(&e->mutex); - - if (dmsg) { - thread_lost_msg(e, dmsg); - thread_destroy_msg(e, dmsg); - } -} - -/* yet-another-mutex interface */ -struct _EMutex { - int type; - pthread_t owner; - short waiters; - short depth; - pthread_mutex_t mutex; - pthread_cond_t cond; -}; - -/* sigh, this is just painful to have to need, but recursive - read/write, etc mutexes just aren't very common in thread - implementations */ -/* TODO: Just make it use recursive mutexes if they are available */ -EMutex *e_mutex_new(e_mutex_t type) -{ - struct _EMutex *m; - - m = g_malloc(sizeof(*m)); - m->type = type; - m->waiters = 0; - m->depth = 0; - m->owner = E_THREAD_NONE; - - switch (type) { - case E_MUTEX_SIMPLE: - pthread_mutex_init(&m->mutex, 0); - break; - case E_MUTEX_REC: - pthread_mutex_init(&m->mutex, 0); - pthread_cond_init(&m->cond, 0); - break; - /* read / write ? flags for same? */ - } - - return m; -} - -int e_mutex_destroy(EMutex *m) -{ - int ret = 0; - - switch (m->type) { - case E_MUTEX_SIMPLE: - ret = pthread_mutex_destroy(&m->mutex); - if (ret == -1) - g_warning("EMutex destroy failed: %s", strerror(errno)); - g_free(m); - break; - case E_MUTEX_REC: - ret = pthread_mutex_destroy(&m->mutex); - if (ret == -1) - g_warning("EMutex destroy failed: %s", strerror(errno)); - ret = pthread_cond_destroy(&m->cond); - if (ret == -1) - g_warning("EMutex destroy failed: %s", strerror(errno)); - g_free(m); - - } - return ret; -} - -int e_mutex_lock(EMutex *m) -{ - pthread_t id; - - switch (m->type) { - case E_MUTEX_SIMPLE: - return pthread_mutex_lock(&m->mutex); - case E_MUTEX_REC: - id = pthread_self(); - if (pthread_mutex_lock(&m->mutex) == -1) - return -1; - while (1) { - if (m->owner == E_THREAD_NONE) { - m->owner = id; - m->depth = 1; - break; - } else if (id == m->owner) { - m->depth++; - break; - } else { - m->waiters++; - if (pthread_cond_wait(&m->cond, &m->mutex) == -1) - return -1; - m->waiters--; - } - } - return pthread_mutex_unlock(&m->mutex); - } - - errno = EINVAL; - return -1; -} - -int e_mutex_unlock(EMutex *m) -{ - switch (m->type) { - case E_MUTEX_SIMPLE: - return pthread_mutex_unlock(&m->mutex); - case E_MUTEX_REC: - if (pthread_mutex_lock(&m->mutex) == -1) - return -1; - g_assert(m->owner == pthread_self()); - - m->depth--; - if (m->depth == 0) { - m->owner = E_THREAD_NONE; - if (m->waiters > 0) - pthread_cond_signal(&m->cond); - } - return pthread_mutex_unlock(&m->mutex); - } - - errno = EINVAL; - return -1; -} - -void e_mutex_assert_locked(EMutex *m) -{ - g_return_if_fail (m->type == E_MUTEX_REC); - pthread_mutex_lock(&m->mutex); - g_assert(m->owner == pthread_self()); - pthread_mutex_unlock(&m->mutex); -} - -#ifdef STANDALONE -EMsgPort *server_port; - - -void *fdserver(void *data) -{ - int fd; - EMsg *msg; - int id = (int)data; - fd_set rfds; - - fd = e_msgport_fd(server_port); - - while (1) { - int count = 0; - - printf("server %d: waiting on fd %d\n", id, fd); - FD_ZERO(&rfds); - FD_SET(fd, &rfds); - select(fd+1, &rfds, NULL, NULL, NULL); - printf("server %d: Got async notification, checking for messages\n", id); - while ((msg = e_msgport_get(server_port))) { - printf("server %d: got message\n", id); - sleep(1); - printf("server %d: replying\n", id); - e_msgport_reply(msg); - count++; - } - printf("server %d: got %d messages\n", id, count); - } -} - -void *server(void *data) -{ - EMsg *msg; - int id = (int)data; - - while (1) { - printf("server %d: waiting\n", id); - msg = e_msgport_wait(server_port); - msg = e_msgport_get(server_port); - if (msg) { - printf("server %d: got message\n", id); - sleep(1); - printf("server %d: replying\n", id); - e_msgport_reply(msg); - } else { - printf("server %d: didn't get message\n", id); - } - } -} - -void *client(void *data) -{ - EMsg *msg; - EMsgPort *replyport; - int i; - - replyport = e_msgport_new(); - msg = g_malloc0(sizeof(*msg)); - msg->reply_port = replyport; - for (i=0;i<10;i++) { - /* synchronous operation */ - printf("client: sending\n"); - e_msgport_put(server_port, msg); - printf("client: waiting for reply\n"); - e_msgport_wait(replyport); - e_msgport_get(replyport); - printf("client: got reply\n"); - } - - printf("client: sleeping ...\n"); - sleep(2); - printf("client: sending multiple\n"); - - for (i=0;i<10;i++) { - msg = g_malloc0(sizeof(*msg)); - msg->reply_port = replyport; - e_msgport_put(server_port, msg); - } - - printf("client: receiving multiple\n"); - for (i=0;i<10;i++) { - e_msgport_wait(replyport); - msg = e_msgport_get(replyport); - g_free(msg); - } - - printf("client: done\n"); -} - -int main(int argc, char **argv) -{ - pthread_t serverid, clientid; - - g_thread_init(NULL); - - server_port = e_msgport_new(); - - /*pthread_create(&serverid, NULL, server, (void *)1);*/ - pthread_create(&serverid, NULL, fdserver, (void *)1); - pthread_create(&clientid, NULL, client, NULL); - - sleep(60); - - return 0; -} -#endif diff --git a/e-util/e-msgport.h b/e-util/e-msgport.h deleted file mode 100644 index d181ac7fb7..0000000000 --- a/e-util/e-msgport.h +++ /dev/null @@ -1,82 +0,0 @@ - -#ifndef _E_MSGPORT_H -#define _E_MSGPORT_H - -/* double-linked list yeah another one, deal */ -typedef struct _EDListNode { - struct _EDListNode *next; - struct _EDListNode *prev; -} EDListNode; - -typedef struct _EDList { - struct _EDListNode *head; - struct _EDListNode *tail; - struct _EDListNode *tailpred; -} EDList; - -#define E_DLIST_INITIALISER(l) { (EDListNode *)&l.tail, 0, (EDListNode *)&l.head } - -void e_dlist_init(EDList *v); -EDListNode *e_dlist_addhead(EDList *l, EDListNode *n); -EDListNode *e_dlist_addtail(EDList *l, EDListNode *n); -EDListNode *e_dlist_remove(EDListNode *n); -EDListNode *e_dlist_remhead(EDList *l); -EDListNode *e_dlist_remtail(EDList *l); -int e_dlist_empty(EDList *l); -int e_dlist_length(EDList *l); - -/* message ports - a simple inter-thread 'ipc' primitive */ -/* opaque handle */ -typedef struct _EMsgPort EMsgPort; - -/* header for any message */ -typedef struct _EMsg { - EDListNode ln; - EMsgPort *reply_port; -} EMsg; - -EMsgPort *e_msgport_new(void); -void e_msgport_destroy(EMsgPort *mp); -/* get a fd that can be used to wait on the port asynchronously */ -int e_msgport_fd(EMsgPort *mp); -void e_msgport_put(EMsgPort *mp, EMsg *msg); -EMsg *e_msgport_wait(EMsgPort *mp); -EMsg *e_msgport_get(EMsgPort *mp); -void e_msgport_reply(EMsg *msg); - -/* e threads, a server thread with a message based request-response, and flexible queuing */ -typedef struct _EThread EThread; - -typedef enum { - E_THREAD_QUEUE = 0, /* run one by one, until done, if the queue_limit is reached, discard new request */ - E_THREAD_DROP, /* run one by one, until done, if the queue_limit is reached, discard oldest requests */ - E_THREAD_NEW, /* always run in a new thread, if the queue limit is reached, new requests are - stored in the queue until a thread becomes available for it, creating a thread pool */ -} e_thread_t; - -typedef void (*EThreadFunc)(EThread *, EMsg *, void *data); - -EThread *e_thread_new(e_thread_t type); -void e_thread_destroy(EThread *e); -void e_thread_set_queue_limit(EThread *e, int limit); -void e_thread_set_msg_lost(EThread *e, EThreadFunc destroy, void *data); -void e_thread_set_msg_destroy(EThread *e, EThreadFunc destroy, void *data); -void e_thread_set_reply_port(EThread *e, EMsgPort *reply_port); -void e_thread_set_msg_received(EThread *e, EThreadFunc received, void *data); -void e_thread_put(EThread *e, EMsg *msg); - -/* sigh, another mutex interface, this one allows different mutex types, portably */ -typedef struct _EMutex EMutex; - -typedef enum _e_mutex_t { - E_MUTEX_SIMPLE, /* == pthread_mutex */ - E_MUTEX_REC, /* recursive mutex */ -} e_mutex_t; - -EMutex *e_mutex_new(e_mutex_t type); -int e_mutex_destroy(EMutex *m); -int e_mutex_lock(EMutex *m); -int e_mutex_unlock(EMutex *m); -void e_mutex_assert_locked(EMutex *m); - -#endif diff --git a/e-util/e-path.c b/e-util/e-path.c deleted file mode 100644 index 22b370b436..0000000000 --- a/e-util/e-path.c +++ /dev/null @@ -1,207 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-path.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> - -#include <dirent.h> -#include <string.h> -#include <sys/stat.h> -#include <glib.h> - -#include "e-path.h" - -#define SUBFOLDER_DIR_NAME "subfolders" -#define SUBFOLDER_DIR_NAME_LEN 10 - -/** - * e_path_to_physical: - * @prefix: a prefix to prepend to the path, or %NULL - * @path: the virtual path to convert to a filesystem path. - * - * This converts the "virtual" path @path into an expanded form that - * allows a given name to refer to both a file and a directory. The - * expanded path will have a "subfolders" directory inserted between - * each path component. If the path ends with "/", the returned - * physical path will end with "/subfolders" - * - * If @prefix is non-%NULL, it will be prepended to the returned path. - * - * Return value: the expanded path - **/ -char * -e_path_to_physical (const char *prefix, const char *vpath) -{ - const char *p, *newp; - char *dp; - char *ppath; - int ppath_len; - int prefix_len; - - while (*vpath == '/') - vpath++; - if (!prefix) - prefix = ""; - - /* Calculate the length of the real path. */ - ppath_len = strlen (vpath); - ppath_len++; /* For the ending zero. */ - - prefix_len = strlen (prefix); - ppath_len += prefix_len; - ppath_len++; /* For the separating slash. */ - - /* Take account of the fact that we need to translate every - * separator into `subfolders/'. - */ - p = vpath; - while (1) { - newp = strchr (p, '/'); - if (newp == NULL) - break; - - ppath_len += SUBFOLDER_DIR_NAME_LEN; - ppath_len++; /* For the separating slash. */ - - /* Skip consecutive slashes. */ - while (*newp == '/') - newp++; - - p = newp; - }; - - ppath = g_malloc (ppath_len); - dp = ppath; - - memcpy (dp, prefix, prefix_len); - dp += prefix_len; - *(dp++) = '/'; - - /* Copy the mangled path. */ - p = vpath; - while (1) { - newp = strchr (p, '/'); - if (newp == NULL) { - strcpy (dp, p); - break; - } - - memcpy (dp, p, newp - p + 1); /* `+ 1' to copy the slash too. */ - dp += newp - p + 1; - - memcpy (dp, SUBFOLDER_DIR_NAME, SUBFOLDER_DIR_NAME_LEN); - dp += SUBFOLDER_DIR_NAME_LEN; - - *(dp++) = '/'; - - /* Skip consecutive slashes. */ - while (*newp == '/') - newp++; - - p = newp; - } - - return ppath; -} - - -static gboolean -find_folders_recursive (const char *physical_path, const char *path, - EPathFindFoldersCallback callback, gpointer data) -{ - DIR *dir; - char *subfolder_directory_path; - gboolean ok; - - if (*path) { - if (!callback (physical_path, path, data)) - return FALSE; - - subfolder_directory_path = g_strdup_printf ("%s/%s", physical_path, SUBFOLDER_DIR_NAME); - } else { - /* On the top level, we have no folders and, - * consequently, no subfolder directory. - */ - - subfolder_directory_path = g_strdup (physical_path); - } - - /* Now scan the subfolders and load them. */ - dir = opendir (subfolder_directory_path); - if (dir == NULL) { - g_free (subfolder_directory_path); - return TRUE; - } - - ok = TRUE; - while (ok) { - struct stat file_stat; - struct dirent *dirent; - char *file_path; - char *new_path; - - dirent = readdir (dir); - if (dirent == NULL) - break; - - if (strcmp (dirent->d_name, ".") == 0 || strcmp (dirent->d_name, "..") == 0) - continue; - - file_path = g_strdup_printf ("%s/%s", subfolder_directory_path, - dirent->d_name); - - if (stat (file_path, &file_stat) < 0 || - ! S_ISDIR (file_stat.st_mode)) { - g_free (file_path); - continue; - } - - new_path = g_strdup_printf ("%s/%s", path, dirent->d_name); - - ok = find_folders_recursive (file_path, new_path, callback, data); - - g_free (file_path); - g_free (new_path); - } - - closedir (dir); - g_free (subfolder_directory_path); - - return ok; -} - -/** - * e_path_find_folders: - * @prefix: directory to start from - * @callback: Callback to invoke on each folder - * @data: Data for @callback - * - * Walks the folder tree starting at @prefix and calls @callback - * on each folder. - * - * Return value: %TRUE on success, %FALSE if an error occurs at any point - **/ -gboolean -e_path_find_folders (const char *prefix, - EPathFindFoldersCallback callback, - gpointer data) -{ - return find_folders_recursive (prefix, "", callback, data); -} diff --git a/e-util/e-path.h b/e-util/e-path.h deleted file mode 100644 index 50a3507363..0000000000 --- a/e-util/e-path.h +++ /dev/null @@ -1,36 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Copyright (C) 2001 Ximian, Inc. - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __E_PATH__ -#define __E_PATH__ - -#include <glib.h> - -typedef gboolean (*EPathFindFoldersCallback) (const char *physical_path, - const char *path, - gpointer user_data); - -char * e_path_to_physical (const char *prefix, const char *vpath); - -gboolean e_path_find_folders (const char *prefix, - EPathFindFoldersCallback callback, - gpointer data); - -#endif /* __E_PATH__ */ diff --git a/e-util/e-pilot-map.c b/e-util/e-pilot-map.c deleted file mode 100644 index 54552b4dca..0000000000 --- a/e-util/e-pilot-map.c +++ /dev/null @@ -1,305 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution Conduits - Pilot Map routines - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include "e-pilot-map.h" - -#include <string.h> /* memset(), strcmp() */ -#include <stdlib.h> -#include <glib.h> -#include <gnome-xml/parser.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-util.h> - -typedef struct -{ - char *uid; - gboolean archived; -} EPilotMapPidNode; - -typedef struct -{ - guint32 pid; - gboolean archived; -} EPilotMapUidNode; - - -static void -map_set_node_timet (xmlNodePtr node, const char *name, time_t t) -{ - char *tstring; - - tstring = g_strdup_printf ("%ld", t); - xmlSetProp (node, name, tstring); -} - -static void -map_sax_start_element (void *data, const xmlChar *name, - const xmlChar **attrs) -{ - EPilotMap *map = (EPilotMap *)data; - - if (!strcmp (name, "PilotMap")) { - while (attrs && *attrs != NULL) { - const xmlChar **val = attrs; - - val++; - if (!strcmp (*attrs, "timestamp")) - map->since = (time_t)strtoul (*val, NULL, 0); - - attrs = ++val; - } - } - - if (!strcmp (name, "map")) { - const char *uid = NULL; - guint32 pid = 0; - gboolean archived = FALSE; - - while (attrs && *attrs != NULL) { - const xmlChar **val = attrs; - - val++; - if (!strcmp (*attrs, "uid")) - uid = *val; - - if (!strcmp (*attrs, "pilot_id")) - pid = strtoul (*val, NULL, 0); - - if (!strcmp (*attrs, "archived")) - archived = strtoul (*val, NULL, 0)== 1 ? TRUE : FALSE; - - attrs = ++val; - } - - if (uid && pid != 0) - e_pilot_map_insert (map, pid, uid, archived); - } -} - -static void -map_write_foreach (gpointer key, gpointer value, gpointer data) -{ - xmlNodePtr root = data; - xmlNodePtr mnode; - unsigned long *pid = key; - EPilotMapPidNode *pnode = value; - char *pidstr; - - mnode = xmlNewChild (root, NULL, "map", NULL); - - pidstr = g_strdup_printf ("%lu", *pid); - xmlSetProp (mnode, "pilot_id", pidstr); - g_free (pidstr); - - xmlSetProp (mnode, "uid", pnode->uid); - - if (pnode->archived) - xmlSetProp (mnode, "archived", "1"); - else - xmlSetProp (mnode, "archived", "0"); -} - -gboolean -e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pid) -{ - EPilotMapPidNode *pnode; - - pnode = g_hash_table_lookup (map->pid_map, &pid); - - if (pnode == NULL) - return FALSE; - - return pnode->archived; -} - -gboolean -e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid) -{ - EPilotMapUidNode *unode; - - unode = g_hash_table_lookup (map->uid_map, uid); - - if (unode == NULL) - return FALSE; - - return unode->archived; -} - -void -e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived) -{ - char *new_uid; - guint32 *new_pid = g_new (guint32, 1); - EPilotMapPidNode *pnode = g_new0 (EPilotMapPidNode, 1); - EPilotMapUidNode *unode = g_new0 (EPilotMapUidNode, 1); - - *new_pid = pid; - new_uid = g_strdup (uid); - - pnode->uid = new_uid; - pnode->archived = archived; - - unode->pid = pid; - unode->archived = archived; - - g_hash_table_insert (map->pid_map, new_pid, pnode); - g_hash_table_insert (map->uid_map, new_uid, unode); -} - -void -e_pilot_map_remove_by_pid (EPilotMap *map, guint32 pid) -{ - EPilotMapPidNode *pnode; - EPilotMapUidNode *unode; - - pnode = g_hash_table_lookup (map->pid_map, &pid); - if (!pnode) - return; - - unode = g_hash_table_lookup (map->uid_map, pnode->uid); - - g_hash_table_remove (map->pid_map, &pid); - g_hash_table_remove (map->uid_map, pnode->uid); - - g_free (pnode); - g_free (unode); -} - -void -e_pilot_map_remove_by_uid (EPilotMap *map, const char *uid) -{ - EPilotMapPidNode *pnode; - EPilotMapUidNode *unode; - - unode = g_hash_table_lookup (map->uid_map, uid); - if (!unode) - return; - - pnode = g_hash_table_lookup (map->pid_map, &unode->pid); - - g_hash_table_remove (map->uid_map, uid); - g_hash_table_remove (map->pid_map, &unode->pid); - - g_free (unode); - g_free (pnode); -} - - -guint32 -e_pilot_map_lookup_pid (EPilotMap *map, const char *uid) -{ - EPilotMapUidNode *unode = NULL; - - unode = g_hash_table_lookup (map->uid_map, uid); - - if (unode == NULL) - return 0; - - return unode->pid; -} - -const char * -e_pilot_map_lookup_uid (EPilotMap *map, guint32 pid) -{ - EPilotMapPidNode *pnode = NULL; - - pnode = g_hash_table_lookup (map->pid_map, &pid); - - if (pnode == NULL) - return NULL; - - return pnode->uid; -} - -int -e_pilot_map_read (const char *filename, EPilotMap **map) -{ - xmlSAXHandler handler; - EPilotMap *new_map = g_new0 (EPilotMap, 1); - - *map = NULL; - - memset (&handler, 0, sizeof (xmlSAXHandler)); - handler.startElement = map_sax_start_element; - - new_map->pid_map = g_hash_table_new (g_int_hash, g_int_equal); - new_map->uid_map = g_hash_table_new (g_str_hash, g_str_equal); - - if (g_file_exists (filename)) { - if (xmlSAXUserParseFile (&handler, new_map, filename) < 0) { - g_free (new_map); - return -1; - } - } - - *map = new_map; - - return 0; -} - -int -e_pilot_map_write (const char *filename, EPilotMap *map) -{ - xmlDocPtr doc; - int ret; - - g_return_val_if_fail (map != NULL, -1); - - doc = xmlNewDoc ("1.0"); - if (doc == NULL) { - g_warning ("Pilot map file could not be created\n"); - return -1; - } - doc->root = xmlNewDocNode(doc, NULL, "PilotMap", NULL); - map->since = time (NULL); - map_set_node_timet (doc->root, "timestamp", map->since); - - g_hash_table_foreach (map->pid_map, map_write_foreach, doc->root); - - /* Write the file */ - xmlSetDocCompressMode (doc, 0); - ret = xmlSaveFile (filename, doc); - if (ret < 0) { - g_warning ("Pilot map file '%s' could not be saved\n", filename); - return -1; - } - - xmlFreeDoc (doc); - - return 0; -} - -void -e_pilot_map_destroy (EPilotMap *map) -{ - g_hash_table_destroy (map->pid_map); - g_hash_table_destroy (map->uid_map); - g_free (map); -} - - - - - - - - diff --git a/e-util/e-pilot-map.h b/e-util/e-pilot-map.h deleted file mode 100644 index 51039e3ca0..0000000000 --- a/e-util/e-pilot-map.h +++ /dev/null @@ -1,54 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution Conduits - Pilot Map routines - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef E_PILOT_MAP_H -#define E_PILOT_MAP_H - -#include <glib.h> -#include <time.h> - -typedef struct _EPilotMap EPilotMap; - -struct _EPilotMap -{ - GHashTable *pid_map; - GHashTable *uid_map; - - time_t since; -}; - -gboolean e_pilot_map_pid_is_archived (EPilotMap *map, guint32 pid); -gboolean e_pilot_map_uid_is_archived (EPilotMap *map, const char *uid); - -void e_pilot_map_insert (EPilotMap *map, guint32 pid, const char *uid, gboolean archived); -void e_pilot_map_remove_by_pid (EPilotMap *map, guint32 pid); -void e_pilot_map_remove_by_uid (EPilotMap *map, const char *uid); - -guint32 e_pilot_map_lookup_pid (EPilotMap *map, const char *uid); -const char * e_pilot_map_lookup_uid (EPilotMap *map, guint32 pid); - -int e_pilot_map_read (const char *filename, EPilotMap **map); -int e_pilot_map_write (const char *filename, EPilotMap *map); - -void e_pilot_map_destroy (EPilotMap *map); - -#endif /* E_PILOT_MAP_H */ diff --git a/e-util/e-pilot-util.c b/e-util/e-pilot-util.c deleted file mode 100644 index 780336a62f..0000000000 --- a/e-util/e-pilot-util.c +++ /dev/null @@ -1,62 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution Conduits - Pilot Map routines - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#include <stdlib.h> -#include <time.h> -#include <gnome-xml/parser.h> -#include <pi-util.h> - -#include "e-pilot-util.h" - -char * -e_pilot_utf8_to_pchar (const char *string) -{ - char *pstring = NULL; - int res; - - if (!string) - return NULL; - - res = convert_ToPilotChar ("UTF8", string, strlen (string), &pstring); - - if (res != 0) - pstring = strdup (string); - - return pstring; -} - -char * -e_pilot_utf8_from_pchar (const char *string) -{ - char *ustring = NULL; - int res; - - if (!string) - return NULL; - - res = convert_FromPilotChar ("UTF8", string, strlen (string), &ustring); - - if (res != 0) - ustring = strdup (string); - - return ustring; -} diff --git a/e-util/e-pilot-util.h b/e-util/e-pilot-util.h deleted file mode 100644 index 811a1d77ef..0000000000 --- a/e-util/e-pilot-util.h +++ /dev/null @@ -1,29 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* Evolution Conduits - Pilot Map routines - * - * Copyright (C) 2000 Ximian, Inc. - * - * Authors: JP Rosevear <jpr@ximian.com> - * - * This program is free software; you can redistribute it and/or modify - * it under the terms of the GNU General Public License as published by - * the Free Software Foundation; either version 2 of the License, or - * (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307, USA. - */ - -#ifndef E_PILOT_UTIL_H -#define E_PILOT_UTIL_H - -char *e_pilot_utf8_to_pchar (const char *string); -char *e_pilot_utf8_from_pchar (const char *string); - -#endif /* E_PILOT_UTIL_H */ diff --git a/e-util/e-request.c b/e-util/e-request.c deleted file mode 100644 index 09634eb32b..0000000000 --- a/e-util/e-request.c +++ /dev/null @@ -1,105 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-request.c - * - * Copyright (C) 2000, 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include "e-request.h" - -#include <libgnomeui/gnome-dialog.h> -#include <libgnomeui/gnome-stock.h> -#include <gal/widgets/e-unicode.h> - -#include <gtk/gtklabel.h> -#include <gtk/gtkentry.h> - - -/** - * e_request_string: - * @parent: - * @title: - * @prompt: - * @default: - * - * Requst a string to the user. - * - * Return value: NULL if the user cancelled the dialog, the inserted string - * otherwise. The string must be freed by the caller. - **/ -char * -e_request_string (GtkWindow *parent, - const char *title, - const char *prompt, - const char *default_string) -{ - GtkWidget *dialog; - GtkWidget *prompt_label; - GtkWidget *entry; - GtkWidget *vbox; - char *retval; - - g_return_val_if_fail (title != NULL, NULL); - g_return_val_if_fail (prompt != NULL, NULL); - - dialog = gnome_dialog_new (title, GNOME_STOCK_BUTTON_OK, GNOME_STOCK_BUTTON_CANCEL, NULL); - gnome_dialog_set_parent (GNOME_DIALOG (dialog), parent); - gnome_dialog_set_default (GNOME_DIALOG (dialog), 0); - gnome_dialog_close_hides (GNOME_DIALOG (dialog), TRUE); - - vbox = GNOME_DIALOG (dialog)->vbox; - - prompt_label = gtk_label_new (prompt); - gtk_box_pack_start (GTK_BOX (vbox), prompt_label, TRUE, TRUE, 0); - - entry = gtk_entry_new (); - e_utf8_gtk_entry_set_text (GTK_ENTRY (entry), default_string); - gtk_entry_select_region (GTK_ENTRY (entry), 0, -1); - gtk_box_pack_start (GTK_BOX (vbox), entry, TRUE, TRUE, 0); - - gtk_widget_grab_focus (entry); - gnome_dialog_editable_enters (GNOME_DIALOG (dialog), GTK_EDITABLE (entry)); - - gtk_widget_show (prompt_label); - gtk_widget_show (entry); - gtk_widget_show (dialog); - - switch (gnome_dialog_run (GNOME_DIALOG (dialog))) { - case 0: - /* OK. */ - retval = e_utf8_gtk_entry_get_text (GTK_ENTRY (entry)); - break; - case -1: - case 1: - /* Cancel. */ - retval = NULL; - break; - default: - g_assert_not_reached (); - retval = NULL; - } - - gtk_widget_destroy (dialog); - - return retval; -} diff --git a/e-util/e-request.h b/e-util/e-request.h deleted file mode 100644 index f4404b83d5..0000000000 --- a/e-util/e-request.h +++ /dev/null @@ -1,34 +0,0 @@ -/* -*- Mode: C; indent-tabs-mode: t; c-basic-offset: 8; tab-width: 8 -*- */ -/* e-request.c - * - * Copyright (C) 2000, 2001 Ximian, Inc. - * - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this program; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - * - * Author: Ettore Perazzoli - */ - -#ifndef E_REQUEST_H -#define E_REQUEST_H - -#include <gtk/gtkwindow.h> - -char *e_request_string (GtkWindow *parent, - const char *title, - const char *prompt, - const char *default_string); - -#endif diff --git a/e-util/e-sexp.c b/e-util/e-sexp.c deleted file mode 100644 index e8b100808f..0000000000 --- a/e-util/e-sexp.c +++ /dev/null @@ -1,1292 +0,0 @@ -/* - * Copyright 2000 Ximian (www.ximian.com). - * - * A simple, extensible s-exp evaluation engine. - * - * Author : - * Michael Zucchi <notzed@ximian.com> - - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA - */ - -/* - The following built-in s-exp's are supported: - - list = (and list*) - perform an intersection of a number of lists, and return that. - - bool = (and bool*) - perform a boolean AND of boolean values. - - list = (or list*) - perform a union of a number of lists, returning the new list. - - bool = (or bool*) - perform a boolean OR of boolean values. - - int = (+ int*) - Add integers. - - string = (+ string*) - Concat strings. - - time_t = (+ time_t*) - Add time_t values. - - int = (- int int*) - Subtract integers from the first. - - time_t = (- time_t*) - Subtract time_t values from the first. - - Comparison operators: - - bool = (< int int) - bool = (> int int) - bool = (= int int) - - bool = (< string string) - bool = (> string string) - bool = (= string string) - - bool = (< time_t time_t) - bool = (> time_t time_t) - bool = (= time_t time_t) - Perform a comparision of 2 integers, 2 string values, or 2 time values. - - Function flow: - - type = (if bool function) - type = (if bool function function) - Choose a flow path based on a boolean value - - type = (begin func func func) - Execute a sequence. The last function return is the return type. -*/ - -#include "e-sexp.h" - -#include <stdio.h> -#include <stdlib.h> -#include <time.h> -#include <string.h> - -#include <glib.h> -#include "e-memory.h" -#define p(x) /* parse debug */ -#define r(x) /* run debug */ -#define d(x) /* general debug */ - - -static struct _ESExpTerm * parse_list(ESExp *f, int gotbrace); -static struct _ESExpTerm * parse_value(ESExp *f); - -static void parse_dump_term(struct _ESExpTerm *t, int depth); - -#ifdef E_SEXP_IS_GTK_OBJECT -static GtkObjectClass *parent_class; -#endif - -static GScannerConfig scanner_config = -{ - ( " \t\r\n") /* cset_skip_characters */, - ( G_CSET_a_2_z - "_+-<=>?" - G_CSET_A_2_Z) /* cset_identifier_first */, - ( G_CSET_a_2_z - "_0123456789-<>?" - G_CSET_A_2_Z - G_CSET_LATINS - G_CSET_LATINC ) /* cset_identifier_nth */, - ( ";\n" ) /* cpair_comment_single */, - - FALSE /* case_sensitive */, - - TRUE /* skip_comment_multi */, - TRUE /* skip_comment_single */, - TRUE /* scan_comment_multi */, - TRUE /* scan_identifier */, - TRUE /* scan_identifier_1char */, - FALSE /* scan_identifier_NULL */, - TRUE /* scan_symbols */, - FALSE /* scan_binary */, - TRUE /* scan_octal */, - TRUE /* scan_float */, - TRUE /* scan_hex */, - FALSE /* scan_hex_dollar */, - TRUE /* scan_string_sq */, - TRUE /* scan_string_dq */, - TRUE /* numbers_2_int */, - FALSE /* int_2_float */, - FALSE /* identifier_2_string */, - TRUE /* char_2_token */, - FALSE /* symbol_2_token */, - FALSE /* scope_0_fallback */, -}; - -/* jumps back to the caller of f->failenv, only to be called from inside a callback */ -void -e_sexp_fatal_error(struct _ESExp *f, char *why, ...) -{ - va_list args; - - if (f->error) - g_free(f->error); - - va_start(args, why); - f->error = g_strdup_vprintf(why, args); - va_end(args); - - longjmp(f->failenv, 1); -} - -const char * -e_sexp_error(struct _ESExp *f) -{ - return f->error; -} - -struct _ESExpResult * -e_sexp_result_new(struct _ESExp *f, int type) -{ - struct _ESExpResult *r = e_memchunk_alloc0(f->result_chunks); - r->type = type; - return r; -} - -void -e_sexp_result_free(struct _ESExp *f, struct _ESExpResult *t) -{ - if (t == NULL) - return; - - switch(t->type) { - case ESEXP_RES_ARRAY_PTR: - g_ptr_array_free(t->value.ptrarray, TRUE); - break; - case ESEXP_RES_BOOL: - case ESEXP_RES_INT: - case ESEXP_RES_TIME: - break; - case ESEXP_RES_STRING: - g_free(t->value.string); - break; - case ESEXP_RES_UNDEFINED: - break; - default: - g_assert_not_reached(); - } - e_memchunk_free(f->result_chunks, t); -} - -/* used in normal functions if they have to abort, and free their arguments */ -void -e_sexp_resultv_free(struct _ESExp *f, int argc, struct _ESExpResult **argv) -{ - int i; - - for (i=0;i<argc;i++) { - e_sexp_result_free(f, argv[i]); - } -} - -/* implementations for the builtin functions */ - -/* can you tell, i dont like glib? */ -/* we can only itereate a hashtable from a called function */ -struct _glib_sux_donkeys { - int count; - GPtrArray *uids; -}; - -/* ok, store any values that are in all sets */ -static void -g_lib_sux_htand(char *key, int value, struct _glib_sux_donkeys *fuckup) -{ - if (value == fuckup->count) { - g_ptr_array_add(fuckup->uids, key); - } -} - -/* or, store all unique values */ -static void -g_lib_sux_htor(char *key, int value, struct _glib_sux_donkeys *fuckup) -{ - g_ptr_array_add(fuckup->uids, key); -} - -static ESExpResult * -term_eval_and(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r, *r1; - GHashTable *ht = g_hash_table_new(g_str_hash, g_str_equal); - struct _glib_sux_donkeys lambdafoo; - int type=-1; - int bool = TRUE; - int i; - - r(printf("( and\n")); - - r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED); - - for (i=0;bool && i<argc;i++) { - r1 = e_sexp_term_eval(f, argv[i]); - if (type == -1) - type = r1->type; - if (type != r1->type) { - e_sexp_result_free(f, r); - e_sexp_result_free(f, r1); - g_hash_table_destroy(ht); - e_sexp_fatal_error(f, "Invalid types in AND"); - } else if (r1->type == ESEXP_RES_ARRAY_PTR) { - char **a1; - int l1, j; - - a1 = (char **)r1->value.ptrarray->pdata; - l1 = r1->value.ptrarray->len; - for (j=0;j<l1;j++) { - int n; - n = (int)g_hash_table_lookup(ht, a1[j]); - g_hash_table_insert(ht, a1[j], (void *)n+1); - } - } else if (r1->type == ESEXP_RES_BOOL) { - bool = bool && r1->value.bool; - } - e_sexp_result_free(f, r1); - } - - if (type == ESEXP_RES_ARRAY_PTR) { - lambdafoo.count = argc; - lambdafoo.uids = g_ptr_array_new(); - g_hash_table_foreach(ht, (GHFunc)g_lib_sux_htand, &lambdafoo); - r->type = ESEXP_RES_ARRAY_PTR; - r->value.ptrarray = lambdafoo.uids; - } else if (type == ESEXP_RES_BOOL) { - r->type = ESEXP_RES_BOOL; - r->value.bool = bool; - } - - g_hash_table_destroy(ht); - - return r; -} - -static ESExpResult * -term_eval_or(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r, *r1; - GHashTable *ht = g_hash_table_new(g_str_hash, g_str_equal); - struct _glib_sux_donkeys lambdafoo; - int type = -1; - int bool = FALSE; - int i; - - r(printf("(or \n")); - - r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED); - - for (i=0;!bool && i<argc;i++) { - r1 = e_sexp_term_eval(f, argv[i]); - if (type == -1) - type = r1->type; - if (r1->type != type) { - e_sexp_result_free(f, r); - e_sexp_result_free(f, r1); - g_hash_table_destroy(ht); - e_sexp_fatal_error(f, "Invalid types in OR"); - } else if (r1->type == ESEXP_RES_ARRAY_PTR) { - char **a1; - int l1, j; - - a1 = (char **)r1->value.ptrarray->pdata; - l1 = r1->value.ptrarray->len; - for (j=0;j<l1;j++) { - g_hash_table_insert(ht, a1[j], (void *)1); - } - } else if (r1->type == ESEXP_RES_BOOL) { - bool |= r1->value.bool; - } - e_sexp_result_free(f, r1); - } - - if (type == ESEXP_RES_ARRAY_PTR) { - lambdafoo.count = argc; - lambdafoo.uids = g_ptr_array_new(); - g_hash_table_foreach(ht, (GHFunc)g_lib_sux_htor, &lambdafoo); - r->type = ESEXP_RES_ARRAY_PTR; - r->value.ptrarray = lambdafoo.uids; - } else if (type == ESEXP_RES_BOOL) { - r->type = ESEXP_RES_BOOL; - r->value.bool = bool; - } - g_hash_table_destroy(ht); - - return r; -} - -static ESExpResult * -term_eval_not(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - int res = TRUE; - ESExpResult *r; - - if (argc>0) { - if (argv[0]->type == ESEXP_RES_BOOL - && argv[0]->value.bool) - res = FALSE; - } - r = e_sexp_result_new(f, ESEXP_RES_BOOL); - r->value.bool = res; - return r; -} - -/* this should support all arguments ...? */ -static ESExpResult * -term_eval_lt(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r, *r1, *r2; - - r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED); - - if (argc == 2) { - r1 = e_sexp_term_eval(f, argv[0]); - r2 = e_sexp_term_eval(f, argv[1]); - if (r1->type != r2->type) { - e_sexp_result_free(f, r1); - e_sexp_result_free(f, r2); - e_sexp_result_free(f, r); - e_sexp_fatal_error(f, "Incompatible types in compare <"); - } else if (r1->type == ESEXP_RES_INT) { - r->type = ESEXP_RES_BOOL; - r->value.bool = r1->value.number < r2->value.number; - } else if (r1->type == ESEXP_RES_TIME) { - r->type = ESEXP_RES_BOOL; - r->value.bool = r1->value.time < r2->value.time; - } else if (r1->type == ESEXP_RES_STRING) { - r->type = ESEXP_RES_BOOL; - r->value.bool = strcmp(r1->value.string, r2->value.string) < 0; - } - e_sexp_result_free(f, r1); - e_sexp_result_free(f, r2); - } - return r; -} - -/* this should support all arguments ...? */ -static ESExpResult * -term_eval_gt(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r, *r1, *r2; - - r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED); - - if (argc == 2) { - r1 = e_sexp_term_eval(f, argv[0]); - r2 = e_sexp_term_eval(f, argv[1]); - if (r1->type != r2->type) { - e_sexp_result_free(f, r1); - e_sexp_result_free(f, r2); - e_sexp_result_free(f, r); - e_sexp_fatal_error(f, "Incompatible types in compare >"); - } else if (r1->type == ESEXP_RES_INT) { - r->type = ESEXP_RES_BOOL; - r->value.bool = r1->value.number > r2->value.number; - } else if (r1->type == ESEXP_RES_TIME) { - r->type = ESEXP_RES_BOOL; - r->value.bool = r1->value.time > r2->value.time; - } else if (r1->type == ESEXP_RES_STRING) { - r->type = ESEXP_RES_BOOL; - r->value.bool = strcmp(r1->value.string, r2->value.string) > 0; - } - e_sexp_result_free(f, r1); - e_sexp_result_free(f, r2); - } - return r; -} - -/* this should support all arguments ...? */ -static ESExpResult * -term_eval_eq(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r, *r1, *r2; - - r = e_sexp_result_new(f, ESEXP_RES_BOOL); - - if (argc == 2) { - r1 = e_sexp_term_eval(f, argv[0]); - r2 = e_sexp_term_eval(f, argv[1]); - if (r1->type != r2->type) { - r->value.bool = FALSE; - } else if (r1->type == ESEXP_RES_INT) { - r->value.bool = r1->value.number == r2->value.number; - } else if (r1->type == ESEXP_RES_BOOL) { - r->value.bool = r1->value.bool == r2->value.bool; - } else if (r1->type == ESEXP_RES_TIME) { - r->value.bool = r1->value.time == r2->value.time; - } else if (r1->type == ESEXP_RES_STRING) { - r->value.bool = strcmp(r1->value.string, r2->value.string) == 0; - } - e_sexp_result_free(f, r1); - e_sexp_result_free(f, r2); - } - return r; -} - -static ESExpResult * -term_eval_plus(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - struct _ESExpResult *r=NULL; - int type; - int i; - - if (argc>0) { - type = argv[0]->type; - switch(type) { - case ESEXP_RES_INT: { - int total = argv[0]->value.number; - for (i=1;i<argc && argv[i]->type == ESEXP_RES_INT;i++) { - total += argv[i]->value.number; - } - if (i<argc) { - e_sexp_resultv_free(f, argc, argv); - e_sexp_fatal_error(f, "Invalid types in (+ ints)"); - } - r = e_sexp_result_new(f, ESEXP_RES_INT); - r->value.number = total; - break; } - case ESEXP_RES_STRING: { - GString *s = g_string_new(argv[0]->value.string); - for (i=1;i<argc && argv[i]->type == ESEXP_RES_STRING;i++) { - g_string_append(s, argv[i]->value.string); - } - if (i<argc) { - e_sexp_resultv_free(f, argc, argv); - e_sexp_fatal_error(f, "Invalid types in (+ strings)"); - } - r = e_sexp_result_new(f, ESEXP_RES_STRING); - r->value.string = s->str; - g_string_free(s, FALSE); - break; } - case ESEXP_RES_TIME: { - time_t total; - - total = argv[0]->value.time; - - for (i = 1; i < argc && argv[i]->type == ESEXP_RES_TIME; i++) - total += argv[i]->value.time; - - if (i < argc) { - e_sexp_resultv_free (f, argc, argv); - e_sexp_fatal_error (f, "Invalid types in (+ time_t)"); - } - - r = e_sexp_result_new (f, ESEXP_RES_TIME); - r->value.time = total; - break; } - } - } - - if (!r) { - r = e_sexp_result_new(f, ESEXP_RES_INT); - r->value.number = 0; - } - return r; -} - -static ESExpResult * -term_eval_sub(struct _ESExp *f, int argc, struct _ESExpResult **argv, void *data) -{ - struct _ESExpResult *r=NULL; - int type; - int i; - - if (argc>0) { - type = argv[0]->type; - switch(type) { - case ESEXP_RES_INT: { - int total = argv[0]->value.number; - for (i=1;i<argc && argv[i]->type == ESEXP_RES_INT;i++) { - total -= argv[i]->value.number; - } - if (i<argc) { - e_sexp_resultv_free(f, argc, argv); - e_sexp_fatal_error(f, "Invalid types in -"); - } - r = e_sexp_result_new(f, ESEXP_RES_INT); - r->value.number = total; - break; } - case ESEXP_RES_TIME: { - time_t total; - - total = argv[0]->value.time; - - for (i = 1; i < argc && argv[i]->type == ESEXP_RES_TIME; i++) - total -= argv[i]->value.time; - - if (i < argc) { - e_sexp_resultv_free (f, argc, argv); - e_sexp_fatal_error (f, "Invalid types in (- time_t)"); - } - - r = e_sexp_result_new (f, ESEXP_RES_TIME); - r->value.time = total; - break; } - } - } - - if (!r) { - r = e_sexp_result_new(f, ESEXP_RES_INT); - r->value.number = 0; - } - return r; -} - -/* implements 'if' function */ -static ESExpResult * -term_eval_if(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r; - int doit; - - if (argc >=2 && argc<=3) { - r = e_sexp_term_eval(f, argv[0]); - doit = (r->type == ESEXP_RES_BOOL && r->value.bool); - e_sexp_result_free(f, r); - if (doit) { - return e_sexp_term_eval(f, argv[1]); - } else if (argc>2) { - return e_sexp_term_eval(f, argv[2]); - } - } - return e_sexp_result_new(f, ESEXP_RES_UNDEFINED); -} - -/* implements 'begin' statement */ -static ESExpResult * -term_eval_begin(struct _ESExp *f, int argc, struct _ESExpTerm **argv, void *data) -{ - struct _ESExpResult *r=NULL; - int i; - - for (i=0;i<argc;i++) { - if (r) - e_sexp_result_free(f, r); - r = e_sexp_term_eval(f, argv[i]); - } - if (r) - return r; - else - return e_sexp_result_new(f, ESEXP_RES_UNDEFINED); -} - - -/* this must only be called from inside term evaluation callbacks! */ -struct _ESExpResult * -e_sexp_term_eval(struct _ESExp *f, struct _ESExpTerm *t) -{ - struct _ESExpResult *r = NULL; - int i; - struct _ESExpResult **argv; - - g_return_val_if_fail(t != NULL, NULL); - - r(printf("eval term :\n")); - r(parse_dump_term(t, 0)); - - switch (t->type) { - case ESEXP_TERM_STRING: - r(printf(" (string \"%s\")\n", t->value.string)); - r = e_sexp_result_new(f, ESEXP_RES_STRING); - /* erk, this shoul;dn't need to strdup this ... */ - r->value.string = g_strdup(t->value.string); - break; - case ESEXP_TERM_INT: - r(printf(" (int %d)\n", t->value.number)); - r = e_sexp_result_new(f, ESEXP_RES_INT); - r->value.number = t->value.number; - break; - case ESEXP_TERM_BOOL: - r(printf(" (int %d)\n", t->value.number)); - r = e_sexp_result_new(f, ESEXP_RES_BOOL); - r->value.bool = t->value.bool; - break; - case ESEXP_TERM_TIME: - r(printf(" (time_t %d)\n", t->value.time)); - r = e_sexp_result_new (f, ESEXP_RES_TIME); - r->value.time = t->value.time; - break; - case ESEXP_TERM_IFUNC: - if (t->value.func.sym->f.ifunc) - r = t->value.func.sym->f.ifunc(f, t->value.func.termcount, t->value.func.terms, t->value.func.sym->data); - break; - case ESEXP_TERM_FUNC: - /* first evaluate all arguments to result types */ - argv = alloca(sizeof(argv[0]) * t->value.func.termcount); - for (i=0;i<t->value.func.termcount;i++) { - argv[i] = e_sexp_term_eval(f, t->value.func.terms[i]); - } - /* call the function */ - if (t->value.func.sym->f.func) - r = t->value.func.sym->f.func(f, t->value.func.termcount, argv, t->value.func.sym->data); - - e_sexp_resultv_free(f, t->value.func.termcount, argv); - break; - default: - e_sexp_fatal_error(f, "Unknown type in parse tree: %d", t->type); - } - - if (r==NULL) - r = e_sexp_result_new(f, ESEXP_RES_UNDEFINED); - - return r; -} - -#ifdef TESTER -static void -eval_dump_result(ESExpResult *r, int depth) -{ - int i; - - if (r==NULL) { - printf("null result???\n"); - return; - } - - for (i=0;i<depth;i++) - printf(" "); - - switch (r->type) { - case ESEXP_RES_ARRAY_PTR: - printf("array pointers\n"); - break; - case ESEXP_RES_INT: - printf("int: %d\n", r->value.number); - break; - case ESEXP_RES_STRING: - printf("string: '%s'\n", r->value.string); - break; - case ESEXP_RES_BOOL: - printf("bool: %c\n", r->value.bool?'t':'f'); - break; - case ESEXP_RES_TIME: - printf("time_t: %ld\n", (long) r->value.time); - break; - case ESEXP_RES_UNDEFINED: - printf(" <undefined>\n"); - break; - } - printf("\n"); -} -#endif - -static void -parse_dump_term(struct _ESExpTerm *t, int depth) -{ - int i; - - if (t==NULL) { - printf("null term??\n"); - return; - } - - for (i=0;i<depth;i++) - printf(" "); - - switch (t->type) { - case ESEXP_TERM_STRING: - printf(" \"%s\"", t->value.string); - break; - case ESEXP_TERM_INT: - printf(" %d", t->value.number); - break; - case ESEXP_TERM_BOOL: - printf(" #%c", t->value.bool?'t':'f'); - break; - case ESEXP_TERM_TIME: - printf(" %ld", (long) t->value.time); - break; - case ESEXP_TERM_IFUNC: - case ESEXP_TERM_FUNC: - printf(" (function %s\n", t->value.func.sym->name); - /*printf(" [%d] ", t->value.func.termcount);*/ - for (i=0;i<t->value.func.termcount;i++) { - parse_dump_term(t->value.func.terms[i], depth+1); - } - for (i=0;i<depth;i++) - printf(" "); - printf(" )"); - break; - case ESEXP_TERM_VAR: - printf(" (variable %s )\n", t->value.var->name); - break; - default: - printf("unknown type: %d\n", t->type); - } - - printf("\n"); -} - -/* - PARSER -*/ - -static struct _ESExpTerm * -parse_term_new(struct _ESExp *f, int type) -{ - struct _ESExpTerm *s = e_memchunk_alloc0(f->term_chunks); - s->type = type; - return s; -} - -static void -parse_term_free(struct _ESExp *f, struct _ESExpTerm *t) -{ - int i; - - if (t==NULL) { - return; - } - - switch (t->type) { - case ESEXP_TERM_INT: - case ESEXP_TERM_BOOL: - case ESEXP_TERM_TIME: - case ESEXP_TERM_VAR: - break; - - case ESEXP_TERM_STRING: - g_free(t->value.string); - break; - - case ESEXP_TERM_FUNC: - case ESEXP_TERM_IFUNC: - for (i=0;i<t->value.func.termcount;i++) { - parse_term_free(f, t->value.func.terms[i]); - } - g_free(t->value.func.terms); - break; - - default: - printf("parse_term_free: unknown type: %d\n", t->type); - } - e_memchunk_free(f->term_chunks, t); -} - -static struct _ESExpTerm ** -parse_values(ESExp *f, int *len) -{ - int token; - struct _ESExpTerm **terms; - int i, size = 0; - GScanner *gs = f->scanner; - GSList *list = NULL, *l; - - p(printf("parsing values\n")); - - while ( (token = g_scanner_peek_next_token(gs)) != G_TOKEN_EOF - && token != ')') { - list = g_slist_prepend(list, parse_value(f)); - size++; - } - - /* go over the list, and put them backwards into the term array */ - terms = g_malloc(size * sizeof(*terms)); - l = list; - for (i=size-1;i>=0;i--) { - g_assert(l); - g_assert(l->data); - terms[i] = l->data; - l = g_slist_next(l); - } - g_slist_free(list); - - p(printf("found %d subterms\n", size)); - *len = size; - - p(printf("done parsing values\n")); - return terms; -} - -static struct _ESExpTerm * -parse_value(ESExp *f) -{ - int token; - struct _ESExpTerm *t = NULL; - GScanner *gs = f->scanner; - struct _ESExpSymbol *s; - - p(printf("parsing value\n")); - - token = g_scanner_get_next_token(gs); - switch(token) { - case G_TOKEN_LEFT_PAREN: - p(printf("got brace, its a list!\n")); - return parse_list(f, TRUE); - case G_TOKEN_STRING: - p(printf("got string\n")); - t = parse_term_new(f, ESEXP_TERM_STRING); - t->value.string = g_strdup(g_scanner_cur_value(gs).v_string); - break; - case G_TOKEN_INT: - t = parse_term_new(f, ESEXP_TERM_INT); - t->value.number = g_scanner_cur_value(gs).v_int; - p(printf("got int\n")); - break; - case '#': { - char *str; - - p(printf("got bool?\n")); - token = g_scanner_get_next_token(gs); - if (token != G_TOKEN_IDENTIFIER) { - e_sexp_fatal_error (f, "Invalid format for a boolean value"); - return NULL; - } - - str = g_scanner_cur_value (gs).v_identifier; - - g_assert (str != NULL); - if (!(strlen (str) == 1 && (str[0] == 't' || str[0] == 'f'))) { - e_sexp_fatal_error (f, "Invalid format for a boolean value"); - return NULL; - } - - t = parse_term_new(f, ESEXP_TERM_BOOL); - t->value.bool = (str[0] == 't'); - break; } - case G_TOKEN_SYMBOL: - s = g_scanner_cur_value(gs).v_symbol; - switch (s->type) { - case ESEXP_TERM_FUNC: - case ESEXP_TERM_IFUNC: - /* this is basically invalid, since we can't use function - pointers, but let the runtime catch it ... */ - t = parse_term_new(f, s->type); - t->value.func.sym = s; - t->value.func.terms = parse_values(f, &t->value.func.termcount); - break; - case ESEXP_TERM_VAR: - t = parse_term_new(f, s->type); - t->value.var = s; - break; - default: - e_sexp_fatal_error(f, "Invalid symbol type: %s: %d", s->name, s->type); - } - break; - case G_TOKEN_IDENTIFIER: - e_sexp_fatal_error(f, "Unknown identifier: %s", g_scanner_cur_value(gs).v_identifier); - break; - default: - e_sexp_fatal_error(f, "Unexpected token encountered: %d", token); - } - p(printf("done parsing value\n")); - return t; -} - -/* FIXME: this needs some robustification */ -static struct _ESExpTerm * -parse_list(ESExp *f, int gotbrace) -{ - int token; - struct _ESExpTerm *t = NULL; - GScanner *gs = f->scanner; - - p(printf("parsing list\n")); - if (gotbrace) - token = '('; - else - token = g_scanner_get_next_token(gs); - if (token =='(') { - token = g_scanner_get_next_token(gs); - switch(token) { - case G_TOKEN_SYMBOL: { - struct _ESExpSymbol *s; - - s = g_scanner_cur_value(gs).v_symbol; - p(printf("got funciton: %s\n", s->name)); - t = parse_term_new(f, s->type); - p(printf("created new list %p\n", t)); - /* if we have a variable, find out its base type */ - while (s->type == ESEXP_TERM_VAR) { - s = ((ESExpTerm *)(s->data))->value.var; - } - if (s->type == ESEXP_TERM_FUNC - || s->type == ESEXP_TERM_IFUNC) { - t->value.func.sym = s; - t->value.func.terms = parse_values(f, &t->value.func.termcount); - } else { - parse_term_free(f, t); - e_sexp_fatal_error(f, "Trying to call variable as function: %s", s->name); - } - break; } - case G_TOKEN_IDENTIFIER: - e_sexp_fatal_error(f, "Unknown identifier: %s", g_scanner_cur_value(gs).v_identifier); - break; - default: - e_sexp_fatal_error(f, "Unexpected token encountered: %d", token); - } - token = g_scanner_get_next_token(gs); - if (token != ')') { - e_sexp_fatal_error(f, "Missing ')'"); - } - } else { - e_sexp_fatal_error(f, "Missing '('"); - } - - p(printf("returning list %p\n", t)); - return t; -} - -static void e_sexp_finalise(void *); - -#ifdef E_SEXP_IS_GTK_OBJECT -static void -e_sexp_class_init (ESExpClass *class) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass *) class; - - object_class->finalize = e_sexp_finalise; - - parent_class = gtk_type_class (gtk_object_get_type ()); -} -#endif - -/* 'builtin' functions */ -static struct { - char *name; - ESExpFunc *func; - int type; /* set to 1 if a function can perform shortcut evaluation, or - doesn't execute everything, 0 otherwise */ -} symbols[] = { - { "and", (ESExpFunc *)term_eval_and, 1 }, - { "or", (ESExpFunc *)term_eval_or, 1 }, - { "not", (ESExpFunc *)term_eval_not, 0 }, - { "<", (ESExpFunc *)term_eval_lt, 1 }, - { ">", (ESExpFunc *)term_eval_gt, 1 }, - { "=", (ESExpFunc *)term_eval_eq, 1 }, - { "+", (ESExpFunc *)term_eval_plus, 0 }, - { "-", (ESExpFunc *)term_eval_sub, 0 }, - { "if", (ESExpFunc *)term_eval_if, 1 }, - { "begin", (ESExpFunc *)term_eval_begin, 1 }, -}; - -static void -free_symbol(void *key, void *value, void *data) -{ - struct _ESExpSymbol *s = value; - - g_free(s->name); - g_free(s); -} - -static void -e_sexp_finalise(void *o) -{ - ESExp *s = (ESExp *)o; - - if (s->tree) { - parse_term_free(s, s->tree); - s->tree = NULL; - } - - e_memchunk_destroy(s->term_chunks); - e_memchunk_destroy(s->result_chunks); - - g_scanner_scope_foreach_symbol(s->scanner, 0, free_symbol, 0); - g_scanner_destroy(s->scanner); - -#ifdef E_SEXP_IS_GTK_OBJECT - ((GtkObjectClass *)(parent_class))->finalize((GtkObject *)o); -#endif -} - -static void -e_sexp_init (ESExp *s) -{ - int i; - - s->scanner = g_scanner_new(&scanner_config); - s->term_chunks = e_memchunk_new(16, sizeof(struct _ESExpTerm)); - s->result_chunks = e_memchunk_new(16, sizeof(struct _ESExpResult)); - - /* load in builtin symbols? */ - for(i=0;i<sizeof(symbols)/sizeof(symbols[0]);i++) { - if (symbols[i].type == 1) { - e_sexp_add_ifunction(s, 0, symbols[i].name, (ESExpIFunc *)symbols[i].func, &symbols[i]); - } else { - e_sexp_add_function(s, 0, symbols[i].name, symbols[i].func, &symbols[i]); - } - } - -#ifndef E_SEXP_IS_GTK_OBJECT - s->refcount = 1; -#endif -} - -#ifdef E_SEXP_IS_GTK_OBJECT -guint -e_sexp_get_type (void) -{ - static guint type = 0; - - if (!type) { - GtkTypeInfo type_info = { - "ESExp", - sizeof (ESExp), - sizeof (ESExpClass), - (GtkClassInitFunc) e_sexp_class_init, - (GtkObjectInitFunc) e_sexp_init, - (GtkArgSetFunc) NULL, - (GtkArgGetFunc) NULL - }; - - type = gtk_type_unique (gtk_object_get_type (), &type_info); - } - - return type; -} -#endif - -ESExp * -e_sexp_new (void) -{ -#ifdef E_SEXP_IS_GTK_OBJECT - ESExp *f = E_SEXP ( gtk_type_new (e_sexp_get_type ())); -#else - ESExp *f = g_malloc0(sizeof(*f)); - e_sexp_init(f); -#endif - - return f; -} - -#ifndef E_SEXP_IS_GTK_OBJECT -void e_sexp_ref (ESExp *f) -{ - f->refcount++; -} - -void e_sexp_unref (ESExp *f) -{ - f->refcount--; - if (f->refcount == 0) { - e_sexp_finalise(f); - g_free(f); - } -} -#endif - -void -e_sexp_add_function(ESExp *f, int scope, char *name, ESExpFunc *func, void *data) -{ - struct _ESExpSymbol *s; - - g_return_if_fail(FILTER_IS_SEXP(f)); - g_return_if_fail(name != NULL); - - s = g_malloc0(sizeof(*s)); - s->name = g_strdup(name); - s->f.func = func; - s->type = ESEXP_TERM_FUNC; - s->data = data; - g_scanner_scope_add_symbol(f->scanner, scope, s->name, s); -} - -void -e_sexp_add_ifunction(ESExp *f, int scope, char *name, ESExpIFunc *ifunc, void *data) -{ - struct _ESExpSymbol *s; - - g_return_if_fail(FILTER_IS_SEXP(f)); - g_return_if_fail(name != NULL); - - s = g_malloc0(sizeof(*s)); - s->name = g_strdup(name); - s->f.ifunc = ifunc; - s->type = ESEXP_TERM_IFUNC; - s->data = data; - g_scanner_scope_add_symbol(f->scanner, scope, s->name, s); -} - -void -e_sexp_add_variable(ESExp *f, int scope, char *name, ESExpTerm *value) -{ - struct _ESExpSymbol *s; - - g_return_if_fail(FILTER_IS_SEXP(f)); - g_return_if_fail(name != NULL); - - s = g_malloc0(sizeof(*s)); - s->name = g_strdup(name); - s->type = ESEXP_TERM_VAR; - s->data = value; - g_scanner_scope_add_symbol(f->scanner, scope, s->name, s); -} - -void -e_sexp_remove_symbol(ESExp *f, int scope, char *name) -{ - int oldscope; - struct _ESExpSymbol *s; - - g_return_if_fail(FILTER_IS_SEXP(f)); - g_return_if_fail(name != NULL); - - oldscope = g_scanner_set_scope(f->scanner, scope); - s = g_scanner_lookup_symbol(f->scanner, name); - g_scanner_scope_remove_symbol(f->scanner, scope, name); - g_scanner_set_scope(f->scanner, oldscope); - if (s) { - g_free(s->name); - g_free(s); - } -} - -int -e_sexp_set_scope(ESExp *f, int scope) -{ - g_return_val_if_fail(FILTER_IS_SEXP(f), 0); - - return g_scanner_set_scope(f->scanner, scope); -} - -void -e_sexp_input_text(ESExp *f, const char *text, int len) -{ - g_return_if_fail(FILTER_IS_SEXP(f)); - g_return_if_fail(text != NULL); - - g_scanner_input_text(f->scanner, text, len); -} - -void -e_sexp_input_file (ESExp *f, int fd) -{ - g_return_if_fail(FILTER_IS_SEXP(f)); - - g_scanner_input_file(f->scanner, fd); -} - -/* returns -1 on error */ -int -e_sexp_parse(ESExp *f) -{ - g_return_val_if_fail(FILTER_IS_SEXP(f), -1); - - if (setjmp(f->failenv)) { - g_warning("Error in parsing: %s", f->error); - return -1; - } - - if (f->tree) - parse_term_free(f, f->tree); - - f->tree = parse_value (f); - - return 0; -} - -/* returns NULL on error */ -struct _ESExpResult * -e_sexp_eval(ESExp *f) -{ - g_return_val_if_fail(FILTER_IS_SEXP(f), NULL); - g_return_val_if_fail(f->tree != NULL, NULL); - - if (setjmp(f->failenv)) { - g_warning("Error in execution: %s", f->error); - return NULL; - } - - return e_sexp_term_eval(f, f->tree); -} - -/** - * e_sexp_encode_bool: - * @s: - * @state: - * - * Encode a bool into an s-expression @s. Bools are - * encoded using #t #f syntax. - **/ -void -e_sexp_encode_bool(GString *s, gboolean state) -{ - if (state) - g_string_append(s, " #t"); - else - g_string_append(s, " #f"); -} - -/** - * e_sexp_encode_string: - * @s: Destination string. - * @string: String expression. - * - * Add a c string @string to the s-expression stored in - * the gstring @s. Quotes are added, and special characters - * are escaped appropriately. - **/ -void -e_sexp_encode_string(GString *s, const char *string) -{ - char c; - const char *p; - - if (string == NULL) - p = ""; - else - p = string; - g_string_append(s, " \""); - while ( (c = *p++) ) { - if (c=='\\' || c=='\"' || c=='\'') - g_string_append_c(s, '\\'); - g_string_append_c(s, c); - } - g_string_append(s, "\""); -} - -#ifdef TESTER -int main(int argc, char **argv) -{ - ESExp *f; - char *t = "(+ \"foo\" \"\\\"\" \"bar\" \"\\\\ blah \\x \")"; - ESExpResult *r; - - gtk_init(&argc, &argv); - - f = e_sexp_new(); - - e_sexp_add_variable(f, 0, "test", NULL); - - e_sexp_input_text(f, t, strlen(t)); - e_sexp_parse(f); - - if (f->tree) { - parse_dump_term(f->tree, 0); - } - - r = e_sexp_eval(f); - if (r) { - eval_dump_result(r, 0); - } else { - printf("no result?|\n"); - } - - return 0; -} -#endif diff --git a/e-util/e-sexp.h b/e-util/e-sexp.h deleted file mode 100644 index d4b8795c3e..0000000000 --- a/e-util/e-sexp.h +++ /dev/null @@ -1,162 +0,0 @@ -/* - generic s-exp evaluator class -*/ -#ifndef _E_SEXP_H -#define _E_SEXP_H - -#include <setjmp.h> -#include <time.h> -#include <glib.h> - -#ifdef E_SEXP_IS_GTK_OBJECT -#include <gtk/gtkobject.h> -#endif - -#ifdef E_SEXP_IS_GTK_OBJECT -#define E_SEXP(obj) GTK_CHECK_CAST (obj, e_sexp_get_type (), ESExp) -#define E_SEXP_CLASS(klass) GTK_CHECK_CLASS_CAST (klass, e_sexp_get_type (), ESExpClass) -#define FILTER_IS_SEXP(obj) GTK_CHECK_TYPE (obj, e_sexp_get_type ()) -#else -#define E_SEXP(obj) ((struct _ESExp *)(obj)) -#define E_SEXP_CLASS(klass) ((struct _ESExpClass *)(klass)) -#define FILTER_IS_SEXP(obj) (1) -#endif - -typedef struct _ESExp ESExp; -typedef struct _ESExpClass ESExpClass; - -typedef struct _ESExpSymbol ESExpSymbol; -typedef struct _ESExpResult ESExpResult; -typedef struct _ESExpTerm ESExpTerm; - -typedef struct _ESExpResult *(ESExpFunc)(struct _ESExp *sexp, - int argc, - struct _ESExpResult **argv, - void *data); - -typedef struct _ESExpResult *(ESExpIFunc)(struct _ESExp *sexp, - int argc, - struct _ESExpTerm **argv, - void *data); -enum _ESExpResultType { - ESEXP_RES_ARRAY_PTR=0, /* type is a ptrarray, what it points to is implementation dependant */ - ESEXP_RES_INT, /* type is a number */ - ESEXP_RES_STRING, /* type is a pointer to a single string */ - ESEXP_RES_BOOL, /* boolean type */ - ESEXP_RES_TIME, /* time_t type */ - ESEXP_RES_UNDEFINED /* unknown type */ -}; - -struct _ESExpResult { - enum _ESExpResultType type; - union { - GPtrArray *ptrarray; - int number; - char *string; - int bool; - time_t time; - } value; -}; - -enum _ESExpTermType { - ESEXP_TERM_INT = 0, /* integer literal */ - ESEXP_TERM_BOOL, /* boolean literal */ - ESEXP_TERM_STRING, /* string literal */ - ESEXP_TERM_TIME, /* time_t literal (number of seconds past the epoch) */ - ESEXP_TERM_FUNC, /* normal function, arguments are evaluated before calling */ - ESEXP_TERM_IFUNC, /* immediate function, raw terms are arguments */ - ESEXP_TERM_VAR, /* variable reference */ -}; - -struct _ESExpSymbol { - int type; /* ESEXP_TERM_FUNC or ESEXP_TERM_VAR */ - char *name; - void *data; - union { - ESExpFunc *func; - ESExpIFunc *ifunc; - } f; -}; - -struct _ESExpTerm { - enum _ESExpTermType type; - union { - char *string; - int number; - int bool; - time_t time; - struct { - struct _ESExpSymbol *sym; - struct _ESExpTerm **terms; - int termcount; - } func; - struct _ESExpSymbol *var; - } value; -}; - - - -struct _ESExp { -#ifdef E_SEXP_IS_GTK_OBJECT - GtkObject object; -#else - int refcount; -#endif - GScanner *scanner; /* for parsing text version */ - ESExpTerm *tree; /* root of expression tree */ - - /* private stuff */ - jmp_buf failenv; - char *error; - - /* TODO: may also need a pool allocator for term strings, so we dont lose them - in error conditions? */ - struct _EMemChunk *term_chunks; - struct _EMemChunk *result_chunks; -}; - -struct _ESExpClass { -#ifdef E_SEXP_IS_GTK_OBJECT - GtkObjectClass parent_class; -#endif -}; - -#ifdef E_SEXP_IS_GTK_OBJECT -guint e_sexp_get_type (void); -#endif -ESExp *e_sexp_new (void); -#ifndef E_SEXP_IS_GTK_OBJECT -void e_sexp_ref (ESExp *f); -void e_sexp_unref (ESExp *f); -#endif -void e_sexp_add_function (ESExp *f, int scope, char *name, ESExpFunc *func, void *data); -void e_sexp_add_ifunction (ESExp *f, int scope, char *name, ESExpIFunc *func, void *data); -void e_sexp_add_variable (ESExp *f, int scope, char *name, ESExpTerm *value); -void e_sexp_remove_symbol (ESExp *f, int scope, char *name); -int e_sexp_set_scope (ESExp *f, int scope); - -void e_sexp_input_text (ESExp *f, const char *text, int len); -void e_sexp_input_file (ESExp *f, int fd); - - -int e_sexp_parse (ESExp *f); -ESExpResult *e_sexp_eval (ESExp *f); - -ESExpResult *e_sexp_term_eval (struct _ESExp *f, struct _ESExpTerm *t); -ESExpResult *e_sexp_result_new (struct _ESExp *f, int type); -void e_sexp_result_free (struct _ESExp *f, struct _ESExpResult *t); - -/* used in normal functions if they have to abort, to free their arguments */ -void e_sexp_resultv_free (struct _ESExp *f, int argc, struct _ESExpResult **argv); - -/* utility functions for creating s-exp strings. */ -void e_sexp_encode_bool (GString *s, gboolean state); -void e_sexp_encode_string (GString *s, const char *string); - -/* only to be called from inside a callback to signal a fatal execution error */ -void e_sexp_fatal_error (struct _ESExp *f, char *why, ...); - -/* return the error string */ -const char *e_sexp_error (struct _ESExp *f); - -#endif /* _E_SEXP_H */ diff --git a/e-util/e-sorter-array.c b/e-util/e-sorter-array.c deleted file mode 100644 index ecbdb23198..0000000000 --- a/e-util/e-sorter-array.c +++ /dev/null @@ -1,278 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-sorter-array.c: - * - * Author: - * Christopher James Lahey <clahey@ximian.com> - * - * (C) 2001 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <string.h> -#include <gtk/gtksignal.h> -#include "gal/util/e-util.h" -#include "e-sorter-array.h" - -#define d(x) - -/* The arguments we take */ -enum { - ARG_0, -}; - -#define PARENT_TYPE e_sorter_get_type() - -#define INCREMENT_AMOUNT 100 - -static ESorterClass *parent_class; - -static void esa_sort (ESorterArray *esa); -static void esa_backsort (ESorterArray *esa); - -static gint esa_model_to_sorted (ESorter *sorter, int row); -static gint esa_sorted_to_model (ESorter *sorter, int row); -static void esa_get_model_to_sorted_array (ESorter *sorter, int **array, int *count); -static void esa_get_sorted_to_model_array (ESorter *sorter, int **array, int *count); -static gboolean esa_needs_sorting (ESorter *esa); - -#define ESA_NEEDS_SORTING(esa) (((ESorterArray *) (esa))->compare != NULL) - -static int -esort_callback(const void *data1, const void *data2, gpointer user_data) -{ - ESorterArray *esa = user_data; - int ret_val; - int int1, int2; - - int1 = *(int *)data1; - int2 = *(int *)data2; - - ret_val = esa->compare (int1, int2, esa->closure); - if (ret_val != 0) - return ret_val; - - if (int1 < int2) - return -1; - if (int1 > int2) - return 1; - return 0; -} - -static void -esa_sort(ESorterArray *esa) -{ - int rows; - int i; - - if (esa->sorted) - return; - - rows = esa->rows; - - esa->sorted = g_new(int, rows); - for (i = 0; i < rows; i++) - esa->sorted[i] = i; - - if (esa->compare) - e_sort (esa->sorted, rows, sizeof(int), esort_callback, esa); -} - -static void -esa_backsort(ESorterArray *esa) -{ - int i, rows; - - if (esa->backsorted) - return; - - esa_sort(esa); - - rows = esa->rows; - - esa->backsorted = g_new0(int, rows); - - for (i = 0; i < rows; i++) { - esa->backsorted[esa->sorted[i]] = i; - } -} - - -static gint -esa_model_to_sorted (ESorter *es, int row) -{ - ESorterArray *esa = E_SORTER_ARRAY(es); - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < esa->rows, -1); - - if (ESA_NEEDS_SORTING(es)) - esa_backsort(esa); - - if (esa->backsorted) - return esa->backsorted[row]; - else - return row; -} - -static gint -esa_sorted_to_model (ESorter *es, int row) -{ - ESorterArray *esa = (ESorterArray *) es; - - g_return_val_if_fail(row >= 0, -1); - g_return_val_if_fail(row < esa->rows, -1); - - if (ESA_NEEDS_SORTING(es)) - esa_sort(esa); - - if (esa->sorted) - return esa->sorted[row]; - else - return row; -} - -static void -esa_get_model_to_sorted_array (ESorter *es, int **array, int *count) -{ - ESorterArray *esa = E_SORTER_ARRAY(es); - if (array || count) { - esa_backsort(esa); - - if (array) - *array = esa->backsorted; - if (count) - *count = esa->rows; - } -} - -static void -esa_get_sorted_to_model_array (ESorter *es, int **array, int *count) -{ - ESorterArray *esa = E_SORTER_ARRAY(es); - if (array || count) { - esa_sort(esa); - - if (array) - *array = esa->sorted; - if (count) - *count = esa->rows; - } -} - -static gboolean -esa_needs_sorting(ESorter *es) -{ - ESorterArray *esa = E_SORTER_ARRAY(es); - return esa->compare != NULL; -} - -void -e_sorter_array_clean(ESorterArray *esa) -{ - g_free(esa->sorted); - esa->sorted = NULL; - - g_free(esa->backsorted); - esa->backsorted = NULL; -} - -void -e_sorter_array_set_count (ESorterArray *esa, int count) -{ - e_sorter_array_clean (esa); - esa->rows = count; -} - -void -e_sorter_array_append (ESorterArray *esa, int count) -{ - int i; - g_free(esa->backsorted); - esa->backsorted = NULL; - - if (esa->sorted) { - esa->sorted = g_renew(int, esa->sorted, esa->rows + count); - for (i = 0; i < count; i++) { - int value = esa->rows; - size_t pos; - e_bsearch (&value, esa->sorted, esa->rows, sizeof (int), esort_callback, esa, &pos, NULL); - memmove (esa->sorted + pos + 1, esa->sorted + pos, sizeof (int) * (esa->rows - pos)); - esa->sorted[pos] = value; - esa->rows ++; - } - } else { - esa->rows = count; - } -} - -ESorterArray * -e_sorter_array_construct (ESorterArray *esa, - ECompareRowsFunc compare, - gpointer closure) -{ - esa->compare = compare; - esa->closure = closure; - return esa; -} - -ESorterArray * -e_sorter_array_new (ECompareRowsFunc compare, gpointer closure) -{ - ESorterArray *esa = gtk_type_new (E_SORTER_ARRAY_TYPE); - - return e_sorter_array_construct (esa, compare, closure); -} - -static void -esa_destroy (GtkObject *object) -{ - GTK_OBJECT_CLASS (parent_class)->destroy (object); -} - -static void -esa_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - switch (arg_id) { - default: - break; - } -} - -static void -esa_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - switch (arg_id) { - } -} - -static void -esa_class_init (ESorterArrayClass *klass) -{ - GtkObjectClass *object_class = GTK_OBJECT_CLASS(klass); - ESorterClass *sorter_class = E_SORTER_CLASS(klass); - - parent_class = gtk_type_class (PARENT_TYPE); - - object_class->destroy = esa_destroy; - object_class->set_arg = esa_set_arg; - object_class->get_arg = esa_get_arg; - - sorter_class->model_to_sorted = esa_model_to_sorted ; - sorter_class->sorted_to_model = esa_sorted_to_model ; - sorter_class->get_model_to_sorted_array = esa_get_model_to_sorted_array ; - sorter_class->get_sorted_to_model_array = esa_get_sorted_to_model_array ; - sorter_class->needs_sorting = esa_needs_sorting ; -} - -static void -esa_init (ESorterArray *esa) -{ - esa->rows = 0; - esa->compare = NULL; - esa->closure = NULL; - esa->sorted = NULL; - esa->backsorted = NULL; -} - -E_MAKE_TYPE(e_sorter_array, "ESorterArray", ESorterArray, esa_class_init, esa_init, PARENT_TYPE); diff --git a/e-util/e-sorter-array.h b/e-util/e-sorter-array.h deleted file mode 100644 index 7f876e4148..0000000000 --- a/e-util/e-sorter-array.h +++ /dev/null @@ -1,56 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_SORTER_ARRAY_H_ -#define _E_SORTER_ARRAY_H_ - -#include <gtk/gtkobject.h> -#include <gal/util/e-sorter.h> -#include <glib.h> -#include <libgnome/gnome-defs.h> - -BEGIN_GNOME_DECLS - -#define E_SORTER_ARRAY_TYPE (e_sorter_array_get_type ()) -#define E_SORTER_ARRAY(o) (GTK_CHECK_CAST ((o), E_SORTER_ARRAY_TYPE, ESorterArray)) -#define E_SORTER_ARRAY_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_SORTER_ARRAY_TYPE, ESorterArrayClass)) -#define E_IS_SORTER_ARRAY(o) (GTK_CHECK_TYPE ((o), E_SORTER_ARRAY_TYPE)) -#define E_IS_SORTER_ARRAY_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SORTER_ARRAY_TYPE)) - -#ifndef _E_COMPARE_ROWS_FUNC_H_ -#define _E_COMPARE_ROWS_FUNC_H_ -typedef int (*ECompareRowsFunc) (int row1, - int row2, - gpointer closure); -#endif - -typedef struct { - ESorter base; - - ECompareRowsFunc compare; - gpointer closure; - - /* If needs_sorting is 0, then model_to_sorted and sorted_to_model are no-ops. */ - int *sorted; - int *backsorted; - - int rows; -} ESorterArray; - -typedef struct { - ESorterClass parent_class; -} ESorterArrayClass; - -GtkType e_sorter_array_get_type (void); -ESorterArray *e_sorter_array_construct (ESorterArray *sorter, - ECompareRowsFunc compare, - gpointer closure); -ESorterArray *e_sorter_array_new (ECompareRowsFunc compare, - gpointer closure); -void e_sorter_array_clean (ESorterArray *esa); -void e_sorter_array_set_count (ESorterArray *esa, - int count); -void e_sorter_array_append (ESorterArray *esa, - int count); - -END_GNOME_DECLS - -#endif /* _E_SORTER_ARRAY_H_ */ diff --git a/e-util/e-sorter.c b/e-util/e-sorter.c deleted file mode 100644 index b6e0c000fc..0000000000 --- a/e-util/e-sorter.c +++ /dev/null @@ -1,142 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * E-sorted.c: Virtual sorter class - * - * Author: - * Chris Lahey <clahey@ximian.com> - * - * (C) 2000,2001 Ximian, Inc. - */ -#include <config.h> -#include <stdlib.h> -#include <gtk/gtksignal.h> -#include <string.h> -#include "gal/util/e-util.h" -#include "e-sorter.h" - -#define d(x) - -#define PARENT_TYPE gtk_object_get_type() - -static GtkObjectClass *parent_class; - -#define ES_CLASS(es) ((ESorterClass *)((GtkObject *)(es))->klass) - -static gint es_model_to_sorted (ESorter *es, int row); -static gint es_sorted_to_model (ESorter *es, int row); -static void es_get_model_to_sorted_array (ESorter *es, int **array, int *count); -static void es_get_sorted_to_model_array (ESorter *es, int **array, int *count); -static gboolean es_needs_sorting(ESorter *es); - -static void -es_class_init (ESorterClass *klass) -{ - parent_class = gtk_type_class (PARENT_TYPE); - - klass->model_to_sorted = es_model_to_sorted; - klass->sorted_to_model = es_sorted_to_model; - klass->get_model_to_sorted_array = es_get_model_to_sorted_array; - klass->get_sorted_to_model_array = es_get_sorted_to_model_array; - klass->needs_sorting = es_needs_sorting; -} - -static void -es_init (ESorter *es) -{ -} - -E_MAKE_TYPE(e_sorter, "ESorter", ESorter, es_class_init, es_init, PARENT_TYPE); - -ESorter * -e_sorter_new (void) -{ - ESorter *es = gtk_type_new (E_SORTER_TYPE); - - return es; -} - - -static gint -es_model_to_sorted (ESorter *es, int row) -{ - return row; -} - -static gint -es_sorted_to_model (ESorter *es, int row) -{ - return row; -} - - -static void -es_get_model_to_sorted_array (ESorter *es, int **array, int *count) -{ -} - -static void -es_get_sorted_to_model_array (ESorter *es, int **array, int *count) -{ -} - - -static gboolean -es_needs_sorting(ESorter *es) -{ - return FALSE; -} - -gint -e_sorter_model_to_sorted (ESorter *es, int row) -{ - g_return_val_if_fail(es != NULL, -1); - g_return_val_if_fail(row >= 0, -1); - - if (ES_CLASS(es)->model_to_sorted) - return ES_CLASS(es)->model_to_sorted (es, row); - else - return -1; -} - -gint -e_sorter_sorted_to_model (ESorter *es, int row) -{ - g_return_val_if_fail(es != NULL, -1); - g_return_val_if_fail(row >= 0, -1); - - if (ES_CLASS(es)->sorted_to_model) - return ES_CLASS(es)->sorted_to_model (es, row); - else - return -1; -} - - -void -e_sorter_get_model_to_sorted_array (ESorter *es, int **array, int *count) -{ - g_return_if_fail(es != NULL); - - if (ES_CLASS(es)->get_model_to_sorted_array) - ES_CLASS(es)->get_model_to_sorted_array (es, array, count); -} - -void -e_sorter_get_sorted_to_model_array (ESorter *es, int **array, int *count) -{ - g_return_if_fail(es != NULL); - - if (ES_CLASS(es)->get_sorted_to_model_array) - ES_CLASS(es)->get_sorted_to_model_array (es, array, count); -} - - -gboolean -e_sorter_needs_sorting(ESorter *es) -{ - g_return_val_if_fail (es != NULL, FALSE); - - if (ES_CLASS(es)->needs_sorting) - return ES_CLASS(es)->needs_sorting (es); - else - return FALSE; -} diff --git a/e-util/e-sorter.h b/e-util/e-sorter.h deleted file mode 100644 index fa6c5bbc60..0000000000 --- a/e-util/e-sorter.h +++ /dev/null @@ -1,59 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -#ifndef _E_SORTER_H_ -#define _E_SORTER_H_ - -#include <gtk/gtkobject.h> - -#ifdef __cplusplus -extern "C" { -#endif /* __cplusplus */ - -#define E_SORTER_TYPE (e_sorter_get_type ()) -#define E_SORTER(o) (GTK_CHECK_CAST ((o), E_SORTER_TYPE, ESorter)) -#define E_SORTER_CLASS(k) (GTK_CHECK_CLASS_CAST((k), E_SORTER_TYPE, ESorterClass)) -#define E_IS_SORTER(o) (GTK_CHECK_TYPE ((o), E_SORTER_TYPE)) -#define E_IS_SORTER_CLASS(k) (GTK_CHECK_CLASS_TYPE ((k), E_SORTER_TYPE)) - -typedef struct { - GtkObject base; -} ESorter; - -typedef struct { - GtkObjectClass parent_class; - gint (*model_to_sorted) (ESorter *sorter, - int row); - gint (*sorted_to_model) (ESorter *sorter, - int row); - - void (*get_model_to_sorted_array) (ESorter *sorter, - int **array, - int *count); - void (*get_sorted_to_model_array) (ESorter *sorter, - int **array, - int *count); - - gboolean (*needs_sorting) (ESorter *sorter); -} ESorterClass; - -GtkType e_sorter_get_type (void); -ESorter *e_sorter_new (void); - -gint e_sorter_model_to_sorted (ESorter *sorter, - int row); -gint e_sorter_sorted_to_model (ESorter *sorter, - int row); - -void e_sorter_get_model_to_sorted_array (ESorter *sorter, - int **array, - int *count); -void e_sorter_get_sorted_to_model_array (ESorter *sorter, - int **array, - int *count); - -gboolean e_sorter_needs_sorting (ESorter *sorter); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_SORTER_H_ */ diff --git a/e-util/e-text-event-processor-emacs-like.c b/e-util/e-text-event-processor-emacs-like.c deleted file mode 100644 index f3077ae42f..0000000000 --- a/e-util/e-text-event-processor-emacs-like.c +++ /dev/null @@ -1,499 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <string.h> -#include <gdk/gdkkeysyms.h> -#include <gtk/gtksignal.h> -#include "e-text-event-processor-emacs-like.h" - -static void e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *card); -static void e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass); -static gint e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -static ETextEventProcessorClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0 -}; - -static const ETextEventProcessorCommand control_keys[26] = -{ - { E_TEP_START_OF_LINE, E_TEP_MOVE, 0, "" }, /* a */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_COPY, 0, "" }, /* c */ - { E_TEP_FORWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_END_OF_LINE, E_TEP_MOVE, 0, "" }, /* e */ - { E_TEP_FORWARD_CHARACTER, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_BACKWARD_CHARACTER, E_TEP_DELETE, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_END_OF_LINE, E_TEP_DELETE, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_FORWARD_LINE, E_TEP_MOVE, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_BACKWARD_LINE, E_TEP_MOVE, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_START_OF_LINE, E_TEP_DELETE, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_DELETE, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_PASTE, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ -}; - -static const ETextEventProcessorCommand alt_keys[26] = -{ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* a */ - { E_TEP_BACKWARD_WORD, E_TEP_MOVE, 0, "" }, /* b */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* c */ - { E_TEP_FORWARD_WORD, E_TEP_DELETE, 0, "" }, /* d */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* e */ - { E_TEP_FORWARD_WORD, E_TEP_MOVE, 0, "" }, /* f */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* g */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* h */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* i */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* j */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* k */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* l */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* m */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* n */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* o */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* p */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* q */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* r */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* s */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* t */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* u */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* v */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* w */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* x */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" }, /* y */ - { E_TEP_SELECTION, E_TEP_NOP, 0, "" } /* z */ - -}; - -GtkType -e_text_event_processor_emacs_like_get_type (void) -{ - static GtkType text_event_processor_emacs_like_type = 0; - - if (!text_event_processor_emacs_like_type) - { - static const GtkTypeInfo text_event_processor_emacs_like_info = - { - "ETextEventProcessorEmacsLike", - sizeof (ETextEventProcessorEmacsLike), - sizeof (ETextEventProcessorEmacsLikeClass), - (GtkClassInitFunc) e_text_event_processor_emacs_like_class_init, - (GtkObjectInitFunc) e_text_event_processor_emacs_like_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_emacs_like_type = gtk_type_unique (e_text_event_processor_get_type (), &text_event_processor_emacs_like_info); - } - - return text_event_processor_emacs_like_type; -} - -static void -e_text_event_processor_emacs_like_class_init (ETextEventProcessorEmacsLikeClass *klass) -{ - GtkObjectClass *object_class; - ETextEventProcessorClass *processor_class; - - object_class = (GtkObjectClass*) klass; - processor_class = (ETextEventProcessorClass*) klass; - - parent_class = gtk_type_class (e_text_event_processor_get_type ()); - - processor_class->event = e_text_event_processor_emacs_like_event; -} - -static void -e_text_event_processor_emacs_like_init (ETextEventProcessorEmacsLike *tep) -{ -} - -static gint -e_text_event_processor_emacs_like_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - ETextEventProcessorCommand command; - ETextEventProcessorEmacsLike *tep_el = E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(tep); - command.action = E_TEP_NOP; - switch (event->type) { - case GDK_BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_GRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - if (event->button.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - tep_el->mouse_down = TRUE; - } - break; - case GDK_2BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_WORD; - command.time = event->button.time; - } - break; - case GDK_3BUTTON_PRESS: - if (event->button.button == 1) { - command.action = E_TEP_SELECT; - command.position = E_TEP_SELECT_ALL; - command.time = event->button.time; - } - break; - case GDK_BUTTON_RELEASE: - if (event->button.button == 1) { - command.action = E_TEP_UNGRAB; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - command.time = event->button.time; - tep_el->mouse_down = FALSE; - command.action = E_TEP_NOP; - } else if (event->button.button == 2) { - command.action = E_TEP_MOVE; - command.position = E_TEP_VALUE; - command.value = event->button.position; - command.time = event->button.time; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_GET_SELECTION; - command.position = E_TEP_SELECTION; - command.value = 0; - command.time = event->button.time; - } - break; - case GDK_MOTION_NOTIFY: - if (tep_el->mouse_down) { - command.action = E_TEP_SELECT; - command.position = E_TEP_VALUE; - command.time = event->motion.time; - command.value = event->motion.position; - } - break; - case GDK_KEY_PRESS: - { - ETextEventProcessorEventKey key = event->key; - command.time = event->key.time; - if (key.state & GDK_SHIFT_MASK) - command.action = E_TEP_SELECT; - else - command.action = E_TEP_MOVE; - switch(key.keyval) { - case GDK_Home: - case GDK_KP_Home: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_START_OF_BUFFER; - else - command.position = E_TEP_START_OF_LINE; - break; - case GDK_End: - case GDK_KP_End: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_END_OF_BUFFER; - else - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Page_Up: - case GDK_KP_Page_Up: command.position = E_TEP_BACKWARD_PAGE; break; - - case GDK_Page_Down: - case GDK_KP_Page_Down: command.position = E_TEP_FORWARD_PAGE; break; - /* CUA has Ctrl-Up/Ctrl-Down as paragraph up down */ - case GDK_Up: - case GDK_KP_Up: command.position = E_TEP_BACKWARD_LINE; break; - - case GDK_Down: - case GDK_KP_Down: command.position = E_TEP_FORWARD_LINE; break; - - case GDK_Left: - case GDK_KP_Left: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Right: - case GDK_KP_Right: - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_FORWARD_WORD; - else - command.position = E_TEP_FORWARD_CHARACTER; - break; - - case GDK_BackSpace: - command.action = E_TEP_DELETE; - if (key.state & GDK_CONTROL_MASK) - command.position = E_TEP_BACKWARD_WORD; - else - command.position = E_TEP_BACKWARD_CHARACTER; - break; - case GDK_Clear: - command.action = E_TEP_DELETE; - command.position = E_TEP_END_OF_LINE; - break; - case GDK_Insert: - case GDK_KP_Insert: - if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_PASTE; - command.position = E_TEP_SELECTION; - } else if (key.state & GDK_CONTROL_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - } else { - /* gtk_toggle_insert(text) -- IMPLEMENT -- FIXME */ - } - break; - case GDK_Delete: - case GDK_KP_Delete: - if (key.state & GDK_CONTROL_MASK){ - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_WORD; - } else if (key.state & GDK_SHIFT_MASK) { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } else { - command.action = E_TEP_DELETE; - command.position = E_TEP_FORWARD_CHARACTER; - } - break; - case GDK_Tab: - case GDK_KP_Tab: - case GDK_ISO_Left_Tab: - case GDK_3270_BackTab: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - case GDK_Return: - case GDK_KP_Enter: - if (tep->allow_newlines) { - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "\n"; - } else { - command.action = E_TEP_ACTIVATE; - command.position = E_TEP_SELECTION; - } - break; - case GDK_Escape: - /* Don't insert literally */ - command.action = E_TEP_NOP; - command.position = E_TEP_SELECTION; - break; - - case GDK_KP_Space: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = " "; - break; - case GDK_KP_Equal: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "="; - break; - case GDK_KP_Multiply: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "*"; - break; - case GDK_KP_Add: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "+"; - break; - case GDK_KP_Subtract: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "-"; - break; - case GDK_KP_Decimal: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "."; - break; - case GDK_KP_Divide: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "/"; - break; - case GDK_KP_0: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "0"; - break; - case GDK_KP_1: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "1"; - break; - case GDK_KP_2: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "2"; - break; - case GDK_KP_3: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "3"; - break; - case GDK_KP_4: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "4"; - break; - case GDK_KP_5: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "5"; - break; - case GDK_KP_6: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "6"; - break; - case GDK_KP_7: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "7"; - break; - case GDK_KP_8: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "8"; - break; - case GDK_KP_9: - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = 1; - command.string = "9"; - break; - - default: - if (key.state & GDK_CONTROL_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = control_keys[(int) (key.keyval - 'a')].position; - if (control_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = control_keys[(int) (key.keyval - 'a')].action; - command.value = control_keys[(int) (key.keyval - 'a')].value; - command.string = control_keys[(int) (key.keyval - 'a')].string; - } - - if (key.keyval == 'x' || key.keyval == 'w') { - command.action = E_TEP_COPY; - command.position = E_TEP_SELECTION; - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - - command.action = E_TEP_DELETE; - command.position = E_TEP_SELECTION; - } - - break; - } else if (key.state & GDK_MOD1_MASK) { - if ((key.keyval >= 'A') && (key.keyval <= 'Z')) - key.keyval -= 'A' - 'a'; - - if ((key.keyval >= 'a') && (key.keyval <= 'z')) { - command.position = alt_keys[(int) (key.keyval - 'a')].position; - if (alt_keys[(int) (key.keyval - 'a')].action != E_TEP_MOVE) - command.action = alt_keys[(int) (key.keyval - 'a')].action; - command.value = alt_keys[(int) (key.keyval - 'a')].value; - command.string = alt_keys[(int) (key.keyval - 'a')].string; - } - } else if (key.length > 0) { - if (key.keyval >= GDK_KP_0 && key.keyval <= GDK_KP_9) { - key.keyval = '0'; - key.string = "0"; - } - command.action = E_TEP_INSERT; - command.position = E_TEP_SELECTION; - command.value = strlen(key.string); - command.string = key.string; - - } else { - command.action = E_TEP_NOP; - } - } - break; - case GDK_KEY_RELEASE: - command.time = event->key.time; - command.action = E_TEP_NOP; - break; - default: - command.action = E_TEP_NOP; - break; - } - } - if (command.action != E_TEP_NOP) { - gtk_signal_emit_by_name (GTK_OBJECT (tep), "command", &command); - return 1; - } - else - return 0; -} - -ETextEventProcessor * -e_text_event_processor_emacs_like_new (void) -{ - ETextEventProcessorEmacsLike *retval = gtk_type_new (e_text_event_processor_emacs_like_get_type ()); - return E_TEXT_EVENT_PROCESSOR (retval); -} - diff --git a/e-util/e-text-event-processor-emacs-like.h b/e-util/e-text-event-processor-emacs-like.h deleted file mode 100644 index 7d1f0e68d2..0000000000 --- a/e-util/e-text-event-processor-emacs-like.h +++ /dev/null @@ -1,67 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor-emacs-like.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ -#define __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ - -#include <gal/util/e-text-event-processor.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessorEmacsLike - Turns events on a text widget into commands. Uses an emacs-ish interface. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE (e_text_event_processor_emacs_like_get_type ()) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLike)) -#define E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE, ETextEventProcessorEmacsLikeClass)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_EMACS_LIKE_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_TYPE)) - - -typedef struct _ETextEventProcessorEmacsLike ETextEventProcessorEmacsLike; -typedef struct _ETextEventProcessorEmacsLikeClass ETextEventProcessorEmacsLikeClass; - -struct _ETextEventProcessorEmacsLike -{ - ETextEventProcessor parent; - - /* object specific fields */ - guint mouse_down : 1; -}; - -struct _ETextEventProcessorEmacsLikeClass -{ - ETextEventProcessorClass parent_class; -}; - - -GtkType e_text_event_processor_emacs_like_get_type (void); -ETextEventProcessor *e_text_event_processor_emacs_like_new (void); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_EMACS_LIKE_H__ */ diff --git a/e-util/e-text-event-processor-types.h b/e-util/e-text-event-processor-types.h deleted file mode 100644 index 1e012cdf1a..0000000000 --- a/e-util/e-text-event-processor-types.h +++ /dev/null @@ -1,133 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -/* - * Modified by the GTK+ Team and others 1997-1999. See the AUTHORS - * file for a list of people on the GTK+ Team. See the ChangeLog - * files for a list of changes. These files are distributed with - * GTK+ at ftp://ftp.gtk.org/pub/gtk/. - */ - -#ifndef __E_TEXT_EVENT_PROCESSOR_TYPES_H__ -#define __E_TEXT_EVENT_PROCESSOR_TYPES_H__ - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#include <gdk/gdktypes.h> - -typedef union _ETextEventProcessorEvent ETextEventProcessorEvent; - -typedef enum { - E_TEP_VALUE, - E_TEP_SELECTION, - - E_TEP_START_OF_BUFFER, - E_TEP_END_OF_BUFFER, - - E_TEP_START_OF_LINE, - E_TEP_END_OF_LINE, - - E_TEP_FORWARD_CHARACTER, - E_TEP_BACKWARD_CHARACTER, - - E_TEP_FORWARD_WORD, - E_TEP_BACKWARD_WORD, - - E_TEP_FORWARD_LINE, - E_TEP_BACKWARD_LINE, - - E_TEP_FORWARD_PARAGRAPH, - E_TEP_BACKWARD_PARAGRAPH, - - E_TEP_FORWARD_PAGE, - E_TEP_BACKWARD_PAGE, - - E_TEP_SELECT_WORD, - E_TEP_SELECT_ALL - -} ETextEventProcessorCommandPosition; - -typedef enum { - E_TEP_MOVE, - E_TEP_SELECT, - E_TEP_DELETE, - E_TEP_INSERT, - - E_TEP_COPY, - E_TEP_PASTE, - E_TEP_GET_SELECTION, - E_TEP_SET_SELECT_BY_WORD, - E_TEP_ACTIVATE, - - E_TEP_GRAB, - E_TEP_UNGRAB, - - E_TEP_NOP -} ETextEventProcessorCommandAction; - -typedef struct { - ETextEventProcessorCommandPosition position; - ETextEventProcessorCommandAction action; - int value; - char *string; - guint32 time; -} ETextEventProcessorCommand; - -typedef struct { - GdkEventType type; - guint32 time; - guint state; - guint button; - gint position; -} ETextEventProcessorEventButton; - -typedef struct { - GdkEventType type; - guint32 time; - guint state; - guint keyval; - gint length; - gchar *string; -} ETextEventProcessorEventKey; - -typedef struct { - GdkEventType type; - guint32 time; - guint state; - gint position; -} ETextEventProcessorEventMotion; - -union _ETextEventProcessorEvent { - GdkEventType type; - ETextEventProcessorEventButton button; - ETextEventProcessorEventKey key; - ETextEventProcessorEventMotion motion; -}; - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_TYPES_H__ */ diff --git a/e-util/e-text-event-processor.c b/e-util/e-text-event-processor.c deleted file mode 100644 index 6449b23463..0000000000 --- a/e-util/e-text-event-processor.c +++ /dev/null @@ -1,146 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include "e-text-event-processor.h" -#include <gtk/gtksignal.h> - -static void e_text_event_processor_init (ETextEventProcessor *card); -static void e_text_event_processor_class_init (ETextEventProcessorClass *klass); - -static void e_text_event_processor_set_arg (GtkObject *object, GtkArg *arg, guint arg_id); -static void e_text_event_processor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id); - -static GtkObjectClass *parent_class = NULL; - -/* The arguments we take */ -enum { - ARG_0, - ARG_ALLOW_NEWLINES, -}; - -enum { - E_TEP_EVENT, - E_TEP_LAST_SIGNAL -}; - -static guint e_tep_signals[E_TEP_LAST_SIGNAL] = { 0 }; - -GtkType -e_text_event_processor_get_type (void) -{ - static GtkType text_event_processor_type = 0; - - if (!text_event_processor_type) - { - static const GtkTypeInfo text_event_processor_info = - { - "ETextEventProcessor", - sizeof (ETextEventProcessor), - sizeof (ETextEventProcessorClass), - (GtkClassInitFunc) e_text_event_processor_class_init, - (GtkObjectInitFunc) e_text_event_processor_init, - /* reserved_1 */ NULL, - /* reserved_2 */ NULL, - (GtkClassInitFunc) NULL, - }; - - text_event_processor_type = gtk_type_unique (gtk_object_get_type (), &text_event_processor_info); - } - - return text_event_processor_type; -} - -static void -e_text_event_processor_class_init (ETextEventProcessorClass *klass) -{ - GtkObjectClass *object_class; - - object_class = (GtkObjectClass*) klass; - - parent_class = gtk_type_class (gtk_object_get_type ()); - - e_tep_signals[E_TEP_EVENT] = - gtk_signal_new ("command", - GTK_RUN_LAST, - object_class->type, - GTK_SIGNAL_OFFSET (ETextEventProcessorClass, command), - gtk_marshal_NONE__POINTER, - GTK_TYPE_NONE, 1, - GTK_TYPE_POINTER); - - gtk_object_class_add_signals (object_class, e_tep_signals, E_TEP_LAST_SIGNAL); - - gtk_object_add_arg_type ("ETextEventProcessor::allow_newlines", GTK_TYPE_BOOL, - GTK_ARG_READWRITE, ARG_ALLOW_NEWLINES); - - klass->event = NULL; - klass->command = NULL; - - object_class->set_arg = e_text_event_processor_set_arg; - object_class->get_arg = e_text_event_processor_get_arg; -} - -static void -e_text_event_processor_init (ETextEventProcessor *tep) -{ - tep->allow_newlines = TRUE; -} - -gint -e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event) -{ - if (E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event) { - return E_TEXT_EVENT_PROCESSOR_CLASS(GTK_OBJECT(tep)->klass)->event(tep, event); - } else { - return 0; - } -} - -/* Set_arg handler for the text item */ -static void -e_text_event_processor_set_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETextEventProcessor *tep = E_TEXT_EVENT_PROCESSOR (object); - - switch (arg_id) { - case ARG_ALLOW_NEWLINES: - tep->allow_newlines = GTK_VALUE_BOOL (*arg); - break; - default: - return; - } -} - -/* Get_arg handler for the text item */ -static void -e_text_event_processor_get_arg (GtkObject *object, GtkArg *arg, guint arg_id) -{ - ETextEventProcessor *tep = E_TEXT_EVENT_PROCESSOR (object); - - switch (arg_id) { - case ARG_ALLOW_NEWLINES: - GTK_VALUE_BOOL (*arg) = tep->allow_newlines; - break; - default: - arg->type = GTK_TYPE_INVALID; - break; - } -} diff --git a/e-util/e-text-event-processor.h b/e-util/e-text-event-processor.h deleted file mode 100644 index 00785db757..0000000000 --- a/e-util/e-text-event-processor.h +++ /dev/null @@ -1,75 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* e-text-event-processor.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ -#ifndef __E_TEXT_EVENT_PROCESSOR_H__ -#define __E_TEXT_EVENT_PROCESSOR_H__ - -#include <glib.h> -#include <gtk/gtkobject.h> -#include <gal/util/e-text-event-processor-types.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -/* ETextEventProcessor - Turns events on a text widget into commands. - * - */ - -#define E_TEXT_EVENT_PROCESSOR_TYPE (e_text_event_processor_get_type ()) -#define E_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_CAST ((obj), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessor)) -#define E_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_CAST ((klass), E_TEXT_EVENT_PROCESSOR_TYPE, ETextEventProcessorClass)) -#define E_IS_TEXT_EVENT_PROCESSOR(obj) (GTK_CHECK_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) -#define E_IS_TEXT_EVENT_PROCESSOR_CLASS(klass) (GTK_CHECK_CLASS_TYPE ((obj), E_TEXT_EVENT_PROCESSOR_TYPE)) - - -typedef struct _ETextEventProcessor ETextEventProcessor; -typedef struct _ETextEventProcessorClass ETextEventProcessorClass; - -struct _ETextEventProcessor -{ - GtkObject parent; - - /* object specific fields */ - guint allow_newlines : 1; -}; - -struct _ETextEventProcessorClass -{ - GtkObjectClass parent_class; - - /* signals */ - void (* command) (ETextEventProcessor *tep, ETextEventProcessorCommand *command); - - /* virtual functions */ - gint (* event) (ETextEventProcessor *tep, ETextEventProcessorEvent *event); -}; - - -GtkType e_text_event_processor_get_type (void); -gint e_text_event_processor_handle_event (ETextEventProcessor *tep, ETextEventProcessorEvent *event); - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - - -#endif /* __E_TEXT_EVENT_PROCESSOR_H__ */ diff --git a/e-util/e-time-utils.c b/e-util/e-time-utils.c deleted file mode 100644 index 59650a31d3..0000000000 --- a/e-util/e-time-utils.c +++ /dev/null @@ -1,375 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Time utility functions - * - * Author: - * Damon Chaplin (damon@ximian.com) - * - * (C) 2001 Ximian, Inc. - */ - -#include <config.h> - -/* We need this for strptime. */ -#define _XOPEN_SOURCE 500 -#define __USE_XOPEN -#include <time.h> -#include <sys/time.h> -#undef _XOPEN_SOURCE -#undef __USE_XOPEN - -#include <string.h> -#include <ctype.h> -#include <glib.h> -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> -#include "e-time-utils.h" - - -/* Returns whether a string is NULL, empty, or full of whitespace */ -static gboolean -string_is_empty (const char *value) -{ - const char *p; - gboolean empty = TRUE; - - if (value) { - p = value; - while (*p) { - if (!isspace (*p)) { - empty = FALSE; - break; - } - p++; - } - } - return empty; -} - - -/* - * Parses a string containing a date and a time. The date is expected to be - * in a format something like "Wed 3/13/00 14:20:00", though we use gettext - * to support the appropriate local formats and we try to accept slightly - * different formats, e.g. the weekday can be skipped and we can accept 12-hour - * formats with an am/pm string. - * - * Returns E_TIME_PARSE_OK if it could not be parsed, E_TIME_PARSE_NONE if it - * was empty, or E_TIME_PARSE_INVALID if it couldn't be parsed. - */ -ETimeParseStatus -e_time_parse_date_and_time (const char *value, - struct tm *result) -{ - struct tm time_tm; - struct tm *today_tm; - time_t t; - const char *pos, *parse_end; - char *format[5]; - gboolean parsed_date = FALSE, parsed_time = FALSE; - gint i; - - if (string_is_empty (value)) { - memset (result, 0, sizeof (*result)); - result->tm_isdst = -1; - return E_TIME_PARSE_NONE; - } - - pos = value; - - /* Skip everything up to the first digit. */ - while (!isdigit (*pos)) - pos++; - - memset (result, 0, sizeof (*result)); - /* strptime format for a date. */ - parse_end = strptime (pos, _("%m/%d/%Y"), result); - if (parse_end) { - pos = parse_end; - parsed_date = TRUE; - } - - /* FIXME: Skip everything up to the first digit. I hope the am/pm flag - never gets entered first - it does in Japanese, so fix this. */ - while (!isdigit (*pos)) - pos++; - - - /* strptime format for a time of day, in 12-hour format. */ - format[0] = _("%I:%M:%S %p"); - - /* strptime format for a time of day, in 24-hour format. */ - format[1] = _("%H:%M:%S"); - - /* strptime format for time of day, without seconds, 12-hour format. */ - format[2] = _("%I:%M %p"); - - /* strptime format for hour and AM/PM */ - format[3] = _("%I %p"); - - /* strptime format for time of day, without seconds 24-hour format. */ - format[4] = _("%H:%M"); - - for (i = 0; i < sizeof (format) / sizeof (format[0]); i++) { - memset (&time_tm, 0, sizeof (time_tm)); - parse_end = strptime (pos, format[i], &time_tm); - if (parse_end) { - pos = parse_end; - parsed_time = TRUE; - break; - } - } - - /* Skip any whitespace. */ - while (isspace (*pos)) - pos++; - - /* If we haven't already parsed a date, try again. */ - if (!parsed_date) { - memset (result, 0, sizeof (*result)); - /* strptime format for a date. */ - parse_end = strptime (pos, _("%m/%d/%Y"), result); - if (parse_end) { - pos = parse_end; - parsed_date = TRUE; - } - } - - /* If we don't have a date or a time it must be invalid. */ - if (!parsed_date && !parsed_time) - return E_TIME_PARSE_INVALID; - - if (parsed_date) { - /* If a 2-digit year was used we use the current century. */ - if (result->tm_year < 0) { - t = time (NULL); - today_tm = localtime (&t); - - /* This should convert it into a value from 0 to 99. */ - result->tm_year += 1900; - - /* Now add on the century. */ - result->tm_year += today_tm->tm_year - - (today_tm->tm_year % 100); - } - } else { - /* If we didn't get a date we use the current day. */ - t = time (NULL); - today_tm = localtime (&t); - result->tm_mday = today_tm->tm_mday; - result->tm_mon = today_tm->tm_mon; - result->tm_year = today_tm->tm_year; - } - - if (parsed_time) { - result->tm_hour = time_tm.tm_hour; - result->tm_min = time_tm.tm_min; - result->tm_sec = time_tm.tm_sec; - } else { - result->tm_hour = 0; - result->tm_min = 0; - result->tm_sec = 0; - } - - result->tm_isdst = -1; - - return E_TIME_PARSE_OK; -} - -/* Takes a number of format strings for strptime() and attempts to parse a - * string with them. - */ -static ETimeParseStatus -parse_with_strptime (const char *value, struct tm *result, const char **formats, int n_formats) -{ - const char *pos, *parse_end; - gboolean parsed; - int i; - - if (string_is_empty (value)) { - memset (result, 0, sizeof (*result)); - result->tm_isdst = -1; - return E_TIME_PARSE_NONE; - } - - pos = value; - - /* Skip whitespace */ - while (isspace (*pos)) - pos++; - - /* Try each of the formats in turn */ - - for (i = 0; i < n_formats; i++) { - memset (result, 0, sizeof (*result)); - parse_end = strptime (pos, formats[i], result); - if (parse_end) { - pos = parse_end; - parsed = TRUE; - break; - } - } - - result->tm_isdst = -1; - - /* If we could not parse it it must be invalid. */ - if (!parsed) - return E_TIME_PARSE_INVALID; - - return E_TIME_PARSE_OK; -} - - -/** - * e_time_parse_date: - * @value: A date string. - * @result: Return value for the parsed date. - * - * Takes in a date string entered by the user and tries to convert it to - * a struct tm. - * - * Return value: Result code indicating whether the @value was an empty - * string, a valid date, or an invalid date. - **/ -ETimeParseStatus -e_time_parse_date (const char *value, struct tm *result) -{ - const char *format[4]; - - g_return_val_if_fail (value != NULL, E_TIME_PARSE_INVALID); - g_return_val_if_fail (result != NULL, E_TIME_PARSE_INVALID); - - /* This is the preferred date format for the locale. */ - format[0] = _("%m/%d/%Y"); - - /* This is the second-choice date format for the locale, which we use - if previous attempts to parse the date string failed. */ - format[1] = _("%d/%m/%Y"); - - /* This is the third-choice date format for the locale, which we use - if previous attempts to parse the date string failed. */ - format[2] = _("%Y/%m/%d"); - - /* This is the final-choice date format for the locale, which we use - if previous attempts to parse the date string failed. */ - format[3] = _("%x"); /* catch-all give-up strptime()-sucks format */ - - return parse_with_strptime (value, result, format, sizeof (format) / sizeof (format[0])); -} - - -/* - * Parses a string containing a time. It is expected to be in a format - * something like "14:20:00", though we use gettext to support the appropriate - * local formats and we try to accept slightly different formats, e.g. we can - * accept 12-hour formats with an am/pm string. - * - * Returns E_TIME_PARSE_OK if it could not be parsed, E_TIME_PARSE_NONE if it - * was empty, or E_TIME_PARSE_INVALID if it couldn't be parsed. - */ -ETimeParseStatus -e_time_parse_time (const char *value, struct tm *result) -{ - const char *format[5]; - - /* strptime format for a time of day, in 12-hour format. - If it is not appropriate in the locale set to an empty string. */ - format[0] = _("%I:%M:%S %p"); - - /* strptime format for a time of day, in 24-hour format. */ - format[1] = _("%H:%M:%S"); - - /* strptime format for time of day, without seconds, 12-hour format. - If it is is not appropriate in the locale set to an empty string. */ - format[2] = _("%I:%M %p"); - - /* strptime format for hour and AM/PM */ - format[3] = _("%I %p"); - - /* strptime format for time of day, without seconds 24-hour format. */ - format[4] = _("%H:%M"); - - return parse_with_strptime (value, result, format, sizeof (format) / sizeof (format[0])); -} - - -/* Creates a string representation of a time value and stores it in buffer. - buffer_size should be about 64 to be safe. If show_midnight is FALSE, and - the time is midnight, then we just show the date. If show_zero_seconds - is FALSE, then if the time has zero seconds only the hour and minute are - shown. */ -void -e_time_format_date_and_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_midnight, - gboolean show_zero_seconds, - char *buffer, - int buffer_size) -{ - char *format; - - if (!show_midnight && date_tm->tm_hour == 0 - && date_tm->tm_min == 0 && date_tm->tm_sec == 0) { - /* strftime format of a weekday and a date. */ - format = _("%a %m/%d/%Y"); - } else if (use_24_hour_format) { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a weekday, a date and a - time, in 24-hour format, without seconds. */ - format = _("%a %m/%d/%Y %H:%M"); - else - /* strftime format of a weekday, a date and a - time, in 24-hour format. */ - format = _("%a %m/%d/%Y %H:%M:%S"); - } else { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a weekday, a date and a - time, in 12-hour format, without seconds. */ - format = _("%a %m/%d/%Y %I:%M %p"); - else - /* strftime format of a weekday, a date and a - time, in 12-hour format. */ - format = _("%a %m/%d/%Y %I:%M:%S %p"); - } - - /* strftime returns 0 if the string doesn't fit, and leaves the buffer - undefined, so we set it to the empty string in that case. */ - if (strftime (buffer, buffer_size, format, date_tm) == 0) - buffer[0] = '\0'; -} - - -/* Creates a string representation of a time value and stores it in buffer. - buffer_size should be about 64 to be safe. */ -void -e_time_format_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_zero_seconds, - char *buffer, - int buffer_size) -{ - char *format; - - if (use_24_hour_format) { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a time in 24-hour format, - without seconds. */ - format = _("%H:%M"); - else - /* strftime format of a time in 24-hour format. */ - format = _("%H:%M:%S"); - } else { - if (!show_zero_seconds && date_tm->tm_sec == 0) - /* strftime format of a time in 12-hour format, - without seconds. */ - format = _("%I:%M %p"); - else - /* strftime format of a time in 12-hour format. */ - format = _("%I:%M:%S %p"); - } - - /* strftime returns 0 if the string doesn't fit, and leaves the buffer - undefined, so we set it to the empty string in that case. */ - if (strftime (buffer, buffer_size, format, date_tm) == 0) - buffer[0] = '\0'; -} diff --git a/e-util/e-time-utils.h b/e-util/e-time-utils.h deleted file mode 100644 index f6d85df5ac..0000000000 --- a/e-util/e-time-utils.h +++ /dev/null @@ -1,53 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * Time utility functions - * - * Author: - * Damon Chaplin (damon@ximian.com) - * - * (C) 2001 Ximian, Inc. - */ - -#ifndef E_TIME_UTILS -#define E_TIME_UTILS - -#include <time.h> -#include <glib.h> - -typedef enum { - E_TIME_PARSE_OK, - E_TIME_PARSE_NONE, - E_TIME_PARSE_INVALID -} ETimeParseStatus; - -/* Tries to parse a string containing a date and time. */ -ETimeParseStatus e_time_parse_date_and_time (const char *value, - struct tm *result); - -/* Tries to parse a string containing a date. */ -ETimeParseStatus e_time_parse_date (const char *value, - struct tm *result); - -/* Tries to parse a string containing a time. */ -ETimeParseStatus e_time_parse_time (const char *value, - struct tm *result); - -/* Turns a struct tm into a string like "Wed 3/12/00 12:00:00 AM". */ -void e_time_format_date_and_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_midnight, - gboolean show_zero_seconds, - char *buffer, - int buffer_size); - -/* Formats a time from a struct tm, e.g. "01:59 PM". */ -void e_time_format_time (struct tm *date_tm, - gboolean use_24_hour_format, - gboolean show_zero_seconds, - char *buffer, - int buffer_size); - - - - -#endif /* E_TIME_UTILS */ diff --git a/e-util/e-unicode-i18n.c b/e-util/e-unicode-i18n.c deleted file mode 100644 index 94cf05ecd9..0000000000 --- a/e-util/e-unicode-i18n.c +++ /dev/null @@ -1,59 +0,0 @@ -/* - * e-unicode-i18n.c - * - * Author: Zbigniew Chyla <cyba@gnome.pl> - * - * Copyright (C) 2001 Ximian, Inc. - */ - -#ifdef HAVE_CONFIG_H -#include <config.h> -#endif - -#include <glib.h> -#include <gal/widgets/e-unicode.h> -#include "e-unicode-i18n.h" - -static GHashTable *locale_to_utf8_hash = NULL; - -static const char * -locale_to_utf8 (const char *string) -{ - char *utf; - - if (locale_to_utf8_hash == NULL) { - locale_to_utf8_hash = g_hash_table_new (&g_str_hash, &g_str_equal); - } - - utf = g_hash_table_lookup (locale_to_utf8_hash, string); - if (utf == NULL) { - utf = e_utf8_from_locale_string (string); - g_hash_table_insert (locale_to_utf8_hash, g_strdup (string), utf); - } - - return utf; -} - -const char * -e_utf8_gettext (const char *string) -{ - if (string == NULL) { - return NULL; - } else if (string[0] == '\0') { - return ""; - } else { - return locale_to_utf8 (gettext (string)); - } -} - -const char * -e_utf8_dgettext (const char *domain, const char *string) -{ - if (string == NULL) { - return NULL; - } else if (string[0] == '\0') { - return ""; - } else { - return locale_to_utf8 (dgettext (domain, string)); - } -} diff --git a/e-util/e-unicode-i18n.h b/e-util/e-unicode-i18n.h deleted file mode 100644 index e8281891bc..0000000000 --- a/e-util/e-unicode-i18n.h +++ /dev/null @@ -1,17 +0,0 @@ -#ifndef _E_UNICODE_I18N_H -#define _E_UNICODE_I18N_H - -#include <libgnome/gnome-defs.h> -#include <libgnome/gnome-i18n.h> - -const char *e_utf8_gettext (const char *string); -const char *e_utf8_dgettext (const char *domain, const char *string); - -#undef U_ -#ifdef GNOME_EXPLICIT_TRANSLATION_DOMAIN -# define U_(domain,string) e_utf8_dgettext (domain, string) -#else -# define U_(string) e_utf8_gettext (string) -#endif - -#endif /* _E_UNICODE_I18N_H */ diff --git a/e-util/e-url.c b/e-util/e-url.c deleted file mode 100644 index 8b54a81d16..0000000000 --- a/e-util/e-url.c +++ /dev/null @@ -1,86 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-url.c - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#include <config.h> -#include <string.h> -#include "e-url.h" - -char * -e_url_shroud (const char *url) -{ - const char *first_colon = NULL; - const char *last_at = NULL; - const char *p; - char *shrouded; - - if (url == NULL) - return NULL; - - /* Skip past the moniker */ - for (p = url; *p && *p != ':'; ++p); - if (*p) - ++p; - - while (*p) { - if (first_colon == NULL && *p == ':') - first_colon = p; - if (*p == '@') - last_at = p; - ++p; - } - - if (first_colon && last_at && first_colon < last_at) { - shrouded = g_strdup_printf ("%.*s%s", first_colon - url, url, last_at); - } else { - shrouded = g_strdup (url); - } - - return shrouded; -} - -gboolean -e_url_equal (const char *url1, const char *url2) -{ - char *shroud1 = e_url_shroud (url1); - char *shroud2 = e_url_shroud (url2); - gint len1, len2; - gboolean rv; - - if (shroud1 == NULL || shroud2 == NULL) { - rv = (shroud1 == shroud2); - } else { - len1 = strlen (shroud1); - len2 = strlen (shroud2); - - rv = !strncmp (shroud1, shroud2, MIN (len1, len2)); - } - - g_free (shroud1); - g_free (shroud2); - - return rv; -} diff --git a/e-util/e-url.h b/e-util/e-url.h deleted file mode 100644 index 5250963dba..0000000000 --- a/e-util/e-url.h +++ /dev/null @@ -1,37 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ - -/* - * e-url.h - * - * Copyright (C) 2001 Ximian, Inc. - * - * Developed by Jon Trowbridge <trow@ximian.com> - */ - -/* - * This program is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the - * GNU General Public License for more details. - * - * You should have received a copy of the GNU General Public License - * along with this program; if not, write to the Free Software - * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 - * USA. - */ - -#ifndef __E_URL_H__ -#define __E_URL_H__ - -#include <gtk/gtk.h> - -char *e_url_shroud (const char *url); -gboolean e_url_equal (const char *url1, const char *url2); - -#endif /* __E_URL_H__ */ - diff --git a/e-util/e-util.c b/e-util/e-util.c deleted file mode 100644 index fb18db91ca..0000000000 --- a/e-util/e-util.c +++ /dev/null @@ -1,1117 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-xml-utils.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <glib.h> -#include <gtk/gtkobject.h> -#include <errno.h> -#include <fcntl.h> -#include <unistd.h> -#include <ctype.h> -#include <sys/stat.h> -#include <string.h> -#include <locale.h> -#include <stdio.h> -#include <stdlib.h> - -#include "e-util.h" -#if 0 -#include <libgnomevfs/gnome-vfs.h> -#endif - -int -g_str_compare(const void *x, const void *y) -{ - if (x == NULL || y == NULL) { - if (x == y) - return 0; - else - return x ? -1 : 1; - } - - return strcmp(x, y); -} - -int -g_int_compare(const void *x, const void *y) -{ - if ( GPOINTER_TO_INT(x) < GPOINTER_TO_INT(y) ) - return -1; - else if ( GPOINTER_TO_INT(x) == GPOINTER_TO_INT(y) ) - return 0; - else - return 1; -} - -char * -e_strdup_strip(const char *string) -{ - int i; - int length = 0; - int initial = 0; - for ( i = 0; string[i]; i++ ) { - if (initial == i && isspace((unsigned char) string[i])) { - initial ++; - } - if (!isspace((unsigned char) string[i])) { - length = i - initial + 1; - } - } - return g_strndup(string + initial, length); -} - -void -e_free_object_list (GList *list) -{ - GList *p; - - for (p = list; p != NULL; p = p->next) - gtk_object_unref (GTK_OBJECT (p->data)); - - g_list_free (list); -} - -void -e_free_object_slist (GSList *list) -{ - GSList *p; - - for (p = list; p != NULL; p = p->next) - gtk_object_unref (GTK_OBJECT (p->data)); - - g_slist_free (list); -} - -void -e_free_string_list (GList *list) -{ - GList *p; - - for (p = list; p != NULL; p = p->next) - g_free (p->data); - - g_list_free (list); -} - -void -e_free_string_slist (GSList *list) -{ - GSList *p; - - for (p = list; p != NULL; p = p->next) - g_free (p->data); - g_slist_free (list); -} - -#define BUFF_SIZE 1024 - -char * -e_read_file(const char *filename) -{ - int fd; - char buffer[BUFF_SIZE]; - GList *list = NULL, *list_iterator; - GList *lengths = NULL, *lengths_iterator; - int length = 0; - int bytes; - char *ret_val; - - fd = open(filename, O_RDONLY); - if (fd == -1) - return NULL; - bytes = read(fd, buffer, BUFF_SIZE); - while (bytes) { - if (bytes > 0) { - char *temp = g_malloc(bytes); - memcpy (temp, buffer, bytes); - list = g_list_prepend(list, temp); - lengths = g_list_prepend(lengths, GINT_TO_POINTER(bytes)); - length += bytes; - } else { - if (errno != EINTR) { - close(fd); - g_list_foreach(list, (GFunc) g_free, NULL); - g_list_free(list); - g_list_free(lengths); - return NULL; - } - } - bytes = read(fd, buffer, BUFF_SIZE); - } - ret_val = g_new(char, length + 1); - ret_val[length] = 0; - lengths_iterator = lengths; - list_iterator = list; - for ( ; list_iterator; list_iterator = list_iterator->next, lengths_iterator = lengths_iterator->next) { - int this_length = GPOINTER_TO_INT(lengths_iterator->data); - length -= this_length; - memcpy(ret_val + length, list_iterator->data, this_length); - } - close(fd); - g_list_foreach(list, (GFunc) g_free, NULL); - g_list_free(list); - g_list_free(lengths); - return ret_val; -} - -gint -e_write_file(const char *filename, const char *data, int flags) -{ - int fd; - int length = strlen(data); - int bytes; - fd = open(filename, flags, 0666); - if (fd == -1) - return errno; - while (length > 0) { - bytes = write(fd, data, length); - if (bytes > 0) { - length -= bytes; - data += bytes; - } else { - if (errno != EINTR && errno != EAGAIN) { - int save_errno = errno; - close(fd); - return save_errno; - } - } - } - close(fd); - 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; - - p = copy = g_strdup (path); - do { - p = strchr (p + 1, '/'); - if (p) - *p = '\0'; - if (access (copy, F_OK) == -1) { - if (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) -{ - GnomeVFSHandle *handle; - GList *list = NULL, *list_iterator; - GList *lengths = NULL, *lengths_iterator; - gchar buffer[1025]; - gchar *ret_val; - int length = 0; - GnomeVFSFileSize bytes; - - gnome_vfs_open(&handle, uri, GNOME_VFS_OPEN_READ); - - gnome_vfs_read(handle, buffer, 1024, &bytes); - while (bytes) { - if (bytes) { - char *temp = g_malloc(bytes); - memcpy (temp, buffer, bytes); - list = g_list_prepend(list, temp); - lengths = g_list_prepend(lengths, GINT_TO_POINTER((gint) bytes)); - length += bytes; - } - gnome_vfs_read(handle, buffer, 1024, &bytes); - } - - ret_val = g_new(char, length + 1); - ret_val[length] = 0; - lengths_iterator = lengths; - list_iterator = list; - for ( ; list_iterator; list_iterator = list_iterator->next, lengths_iterator = lengths_iterator->next) { - int this_length = GPOINTER_TO_INT(lengths_iterator->data); - length -= this_length; - memcpy(ret_val + length, list_iterator->data, this_length); - } - gnome_vfs_close(handle); - g_list_foreach(list, (GFunc) g_free, NULL); - g_list_free(list); - g_list_free(lengths); - return ret_val; -} -#endif - -typedef gint (*GtkSignal_INT__INT_INT_POINTER) (GtkObject * object, - gint arg1, - gint arg2, - gpointer arg3, - gpointer user_data); - -void -e_marshal_INT__INT_INT_POINTER (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_INT__INT_INT_POINTER rfunc; - gint *return_val; - return_val = GTK_RETLOC_INT (args[3]); - rfunc = (GtkSignal_INT__INT_INT_POINTER) func; - *return_val = (*rfunc) (object, - GTK_VALUE_INT (args[0]), - GTK_VALUE_INT (args[1]), - GTK_VALUE_POINTER (args[2]), - func_data); -} - -typedef gint (*GtkSignal_INT__INT_POINTER_INT_POINTER) (GtkObject * object, - gint arg1, - gpointer arg2, - gint arg3, - gpointer arg4, - gpointer user_data); - -void -e_marshal_INT__INT_POINTER_INT_POINTER (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_INT__INT_POINTER_INT_POINTER rfunc; - gint *return_val; - return_val = GTK_RETLOC_INT (args[4]); - rfunc = (GtkSignal_INT__INT_POINTER_INT_POINTER) func; - *return_val = (*rfunc) (object, - GTK_VALUE_INT (args[0]), - GTK_VALUE_POINTER (args[1]), - GTK_VALUE_INT (args[2]), - GTK_VALUE_POINTER (args[3]), - func_data); -} - -typedef void (*GtkSignal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL) (GtkObject * object, - GtkObject *arg1, - gdouble arg2, - gdouble arg3, - gboolean arg4, - gpointer user_data); - -void -e_marshal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL rfunc; - rfunc = (GtkSignal_NONE__OBJECT_DOUBLE_DOUBLE_BOOL) func; - (*rfunc) (object, - GTK_VALUE_OBJECT (args[0]), - GTK_VALUE_DOUBLE (args[1]), - GTK_VALUE_DOUBLE (args[2]), - GTK_VALUE_BOOL (args[3]), - func_data); -} - -typedef gdouble (*GtkSignal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL) (GtkObject * object, - GtkObject *arg1, - gdouble arg2, - gdouble arg3, - gboolean arg4, - gpointer user_data); - -void -e_marshal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL rfunc; - gdouble *return_val; - return_val = GTK_RETLOC_DOUBLE (args[4]); - rfunc = (GtkSignal_DOUBLE__OBJECT_DOUBLE_DOUBLE_BOOL) func; - *return_val = (*rfunc) (object, - GTK_VALUE_OBJECT (args[0]), - GTK_VALUE_DOUBLE (args[1]), - GTK_VALUE_DOUBLE (args[2]), - GTK_VALUE_BOOL (args[3]), - func_data); -} - -typedef gdouble (*GtkSignal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL) (GtkObject * object, - GtkObject *arg1, - gdouble arg2, - gdouble arg3, - gboolean arg4, - gpointer user_data); - -void -e_marshal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL rfunc; - gboolean *return_val; - return_val = GTK_RETLOC_BOOL (args[4]); - rfunc = (GtkSignal_BOOL__OBJECT_DOUBLE_DOUBLE_BOOL) func; - *return_val = (*rfunc) (object, - GTK_VALUE_OBJECT (args[0]), - GTK_VALUE_DOUBLE (args[1]), - GTK_VALUE_DOUBLE (args[2]), - GTK_VALUE_BOOL (args[3]), - func_data); -} - -typedef void (*GtkSignal_NONE__INT_INT_POINTER_POINTER_INT_INT) (GtkObject * object, - gint arg1, - gint arg2, - gpointer arg3, - gpointer arg4, - gint arg5, - gint arg6, - gpointer user_data); -void -e_marshal_NONE__INT_INT_POINTER_POINTER_INT_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__INT_INT_POINTER_POINTER_INT_INT rfunc; - rfunc = (GtkSignal_NONE__INT_INT_POINTER_POINTER_INT_INT) func; - (*rfunc) (object, - GTK_VALUE_INT (args[0]), GTK_VALUE_INT (args[1]), - GTK_VALUE_POINTER (args[2]), - GTK_VALUE_POINTER (args[3]), - GTK_VALUE_INT (args[4]), GTK_VALUE_INT (args[5]), func_data); -} - -typedef void (*GtkSignal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT) (GtkObject * object, - gint arg1, - gpointer arg2, - gint arg3, - gpointer arg4, - gpointer arg5, - gint arg6, - gint arg7, - gpointer user_data); -void -e_marshal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT rfunc; - rfunc = (GtkSignal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT) func; - (*rfunc) (object, - GTK_VALUE_INT (args[0]), GTK_VALUE_POINTER (args[1]), GTK_VALUE_INT (args[2]), - GTK_VALUE_POINTER (args[3]), - GTK_VALUE_POINTER (args[4]), - GTK_VALUE_INT (args[5]), GTK_VALUE_INT (args[6]), func_data); -} - -typedef void (*GtkSignal_NONE__INT_INT_POINTER_INT) (GtkObject * object, - gint arg1, - gint arg2, - gpointer arg3, - gint arg4, gpointer user_data); -void -e_marshal_NONE__INT_INT_POINTER_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__INT_INT_POINTER_INT rfunc; - rfunc = (GtkSignal_NONE__INT_INT_POINTER_INT) func; - (*rfunc) (object, - GTK_VALUE_INT (args[0]), GTK_VALUE_INT (args[1]), - GTK_VALUE_POINTER (args[2]), GTK_VALUE_INT (args[3]), func_data); -} - -typedef void (*GtkSignal_NONE__INT_POINTER_INT_POINTER_INT) (GtkObject * object, - gint arg1, - gpointer arg2, - gint arg3, - gpointer arg4, - gint arg5, gpointer user_data); -void -e_marshal_NONE__INT_POINTER_INT_POINTER_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__INT_POINTER_INT_POINTER_INT rfunc; - rfunc = (GtkSignal_NONE__INT_POINTER_INT_POINTER_INT) func; - (*rfunc) (object, - GTK_VALUE_INT (args[0]), GTK_VALUE_POINTER (args[1]), GTK_VALUE_INT (args[2]), - GTK_VALUE_POINTER (args[3]), GTK_VALUE_INT (args[4]), func_data); -} - -typedef gboolean (*GtkSignal_BOOL__INT_INT_POINTER_INT_INT_INT) (GtkObject * object, - gint arg1, - gint arg2, - gpointer arg3, - gint arg4, - gint arg5, - gint arg6, - gpointer user_data); -void -e_marshal_BOOL__INT_INT_POINTER_INT_INT_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_BOOL__INT_INT_POINTER_INT_INT_INT rfunc; - gboolean *return_val; - return_val = GTK_RETLOC_BOOL (args[6]); - rfunc = (GtkSignal_BOOL__INT_INT_POINTER_INT_INT_INT) func; - *return_val = (*rfunc) (object, - GTK_VALUE_INT (args[0]), - GTK_VALUE_INT (args[1]), - GTK_VALUE_POINTER (args[2]), - GTK_VALUE_INT (args[3]), - GTK_VALUE_INT (args[4]), - GTK_VALUE_INT (args[5]), func_data); -} - -typedef gboolean (*GtkSignal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT) (GtkObject * object, - gint arg1, - gpointer arg2, - gint arg3, - gpointer arg4, - gint arg5, - gint arg6, - gint arg7, - gpointer user_data); -void -e_marshal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT rfunc; - gboolean *return_val; - return_val = GTK_RETLOC_BOOL (args[7]); - rfunc = (GtkSignal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT) func; - *return_val = (*rfunc) (object, - GTK_VALUE_INT (args[0]), - GTK_VALUE_POINTER (args[1]), - GTK_VALUE_INT (args[2]), - GTK_VALUE_POINTER (args[3]), - GTK_VALUE_INT (args[4]), - GTK_VALUE_INT (args[5]), - GTK_VALUE_INT (args[6]), func_data); -} - -typedef void (*GtkSignal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT) (GtkObject * - object, - gint arg1, - gint arg2, - gpointer - arg3, - gint arg4, - gint arg5, - gpointer - arg6, - gint arg7, - gint arg8, - gpointer - user_data); - -void -e_marshal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, - GtkArg * args) -{ - GtkSignal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT rfunc; - rfunc = (GtkSignal_NONE__INT_INT_POINTER_INT_INT_POINTER_INT_INT) func; - (*rfunc) (object, - GTK_VALUE_INT (args[0]), GTK_VALUE_INT (args[1]), - GTK_VALUE_POINTER (args[2]), - GTK_VALUE_INT (args[3]), - GTK_VALUE_INT (args[4]), - GTK_VALUE_POINTER (args[5]), - GTK_VALUE_INT (args[6]), GTK_VALUE_INT (args[7]), func_data); -} - -typedef void (*GtkSignal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT) (GtkObject * - object, - gint arg1, - gpointer arg2, - gint arg3, - gpointer arg4, - gint arg5, - gint arg6, - gpointer arg7, - gint arg8, - gint arg9, - gpointer user_data); - -void -e_marshal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT (GtkObject * object, - GtkSignalFunc func, - gpointer func_data, - GtkArg * args) -{ - GtkSignal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT rfunc; - rfunc = (GtkSignal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT) func; - (*rfunc) (object, - GTK_VALUE_INT (args[0]), - GTK_VALUE_POINTER (args[1]), - GTK_VALUE_INT (args[2]), - GTK_VALUE_POINTER (args[3]), - GTK_VALUE_INT (args[4]), - GTK_VALUE_INT (args[5]), - GTK_VALUE_POINTER (args[6]), - GTK_VALUE_INT (args[7]), GTK_VALUE_INT (args[8]), func_data); -} - -typedef void (*GtkSignal_NONE__POINTER_POINTER_INT) (GtkObject *, gpointer, - gpointer, gint, gpointer); - -void -e_marshal_NONE__POINTER_POINTER_INT (GtkObject * object, GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__POINTER_POINTER_INT rfunc; - rfunc = (GtkSignal_NONE__POINTER_POINTER_INT) func; - (*rfunc) (object, GTK_VALUE_POINTER (args[0]), GTK_VALUE_POINTER (args[1]), - GTK_VALUE_INT (args[2]), func_data); -} - -typedef void (*GtkSignal_NONE__INT_POINTER_INT_POINTER) (GtkObject *, gint, gpointer, - gint, gpointer, gpointer); - -void -e_marshal_NONE__INT_POINTER_INT_POINTER (GtkObject * object, GtkSignalFunc func, - gpointer func_data, GtkArg * args) -{ - GtkSignal_NONE__INT_POINTER_INT_POINTER rfunc; - rfunc = (GtkSignal_NONE__INT_POINTER_INT_POINTER) func; - (*rfunc) (object, GTK_VALUE_INT (args[0]), GTK_VALUE_POINTER (args[1]), - GTK_VALUE_INT (args[2]), GTK_VALUE_POINTER (args[3]), func_data); -} - -typedef int (*GtkSignal_INT__POINTER_POINTER) (GtkObject *, - gpointer, gpointer, - gpointer user_data); -void -e_marshal_INT__POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - GtkSignal_INT__POINTER_POINTER rfunc; - int *return_val; - - rfunc = (GtkSignal_INT__POINTER_POINTER) func; - return_val = GTK_RETLOC_INT (args[2]); - - *return_val = (*rfunc) (object, - GTK_VALUE_POINTER (args[0]), - GTK_VALUE_POINTER (args[1]), - func_data); -} - -typedef int (*GtkSignal_INT__POINTER_POINTER_POINTER) (GtkObject *, - gpointer, gpointer, gpointer, - gpointer user_data); -void -e_marshal_INT__POINTER_POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - GtkSignal_INT__POINTER_POINTER_POINTER rfunc; - int *return_val; - - rfunc = (GtkSignal_INT__POINTER_POINTER_POINTER) func; - return_val = GTK_RETLOC_INT (args[3]); - - *return_val = (*rfunc) (object, - GTK_VALUE_POINTER (args[0]), - GTK_VALUE_POINTER (args[1]), - GTK_VALUE_POINTER (args[2]), - func_data); -} - -typedef int (*GtkSignal_INT__POINTER_POINTER_POINTER_POINTER) (GtkObject *, - gpointer, gpointer, gpointer, gpointer, - gpointer user_data); -void -e_marshal_INT__POINTER_POINTER_POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - GtkSignal_INT__POINTER_POINTER_POINTER_POINTER rfunc; - int *return_val; - - rfunc = (GtkSignal_INT__POINTER_POINTER_POINTER_POINTER) func; - return_val = GTK_RETLOC_INT (args[4]); - - *return_val = (*rfunc) (object, - GTK_VALUE_POINTER (args[0]), - GTK_VALUE_POINTER (args[1]), - GTK_VALUE_POINTER (args[2]), - GTK_VALUE_POINTER (args[3]), - func_data); -} - - -typedef int (*GtkSignal_INT__POINTER_POINTER_POINTER_POINTER_POINTER) (GtkObject *, - gpointer, gpointer, gpointer, gpointer, gpointer, - gpointer user_data); -void -e_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - GtkSignal_INT__POINTER_POINTER_POINTER_POINTER_POINTER rfunc; - int *return_val; - - rfunc = (GtkSignal_INT__POINTER_POINTER_POINTER_POINTER_POINTER) func; - return_val = GTK_RETLOC_INT (args[4]); - - *return_val = (*rfunc) (object, - GTK_VALUE_POINTER (args[0]), - GTK_VALUE_POINTER (args[1]), - GTK_VALUE_POINTER (args[2]), - GTK_VALUE_POINTER (args[3]), - GTK_VALUE_POINTER (args[3]), - func_data); -} - - -void -e_marshal_NONE__POINTER_INT_INT_INT (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - (* (void (*)(GtkObject *, gpointer, int, int, int, gpointer)) func) - (object, - GTK_VALUE_POINTER (args[0]), - GTK_VALUE_INT (args[1]), - GTK_VALUE_INT (args[2]), - - GTK_VALUE_INT (args[3]), - func_data); -} - -typedef int (*GtkSignal_INT__OBJECT_POINTER) (GtkObject *, - GtkObject *, gpointer, - gpointer user_data); -void -e_marshal_INT__OBJECT_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args) -{ - GtkSignal_INT__OBJECT_POINTER rfunc; - int *return_val; - - rfunc = (GtkSignal_INT__OBJECT_POINTER) func; - return_val = GTK_RETLOC_INT (args[2]); - - *return_val = (*rfunc) (object, - GTK_VALUE_OBJECT (args[0]), - GTK_VALUE_POINTER (args[1]), - func_data); -} - -gchar** -e_strsplit (const gchar *string, - const gchar *delimiter, - gint max_tokens) -{ - GSList *string_list = NULL, *slist; - gchar **str_array, *s; - guint i, n = 1; - - g_return_val_if_fail (string != NULL, NULL); - g_return_val_if_fail (delimiter != NULL, NULL); - - if (max_tokens < 1) - max_tokens = G_MAXINT; - - s = strstr (string, delimiter); - if (s) - { - guint delimiter_len = strlen (delimiter); - - do - { - guint len; - gchar *new_string; - - len = s - string; - new_string = g_new (gchar, len + 1); - strncpy (new_string, string, len); - new_string[len] = 0; - string_list = g_slist_prepend (string_list, new_string); - n++; - string = s + delimiter_len; - s = strstr (string, delimiter); - } - while (--max_tokens && s); - } - - n++; - string_list = g_slist_prepend (string_list, g_strdup (string)); - - str_array = g_new (gchar*, n); - - i = n - 1; - - str_array[i--] = NULL; - for (slist = string_list; slist; slist = slist->next) - str_array[i--] = slist->data; - - g_slist_free (string_list); - - 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_strncasecmp (ptr, needle, len)) - return (gchar *) ptr; - - return NULL; -} - -void -e_filename_make_safe (gchar *string) -{ - gchar *p; - - g_return_if_fail (string != NULL); - - for (p = string; *p; p++) { - if (!isprint ((unsigned char)*p) || strchr (" /'\"`&();|<>${}!", *p)) - *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; - int initial_grouping; - - locality = localeconv(); - grouping = locality->grouping; - initial_grouping = *grouping; - while (number) { - char *group; - switch (*grouping) { - default: - last_count = *grouping; - grouping++; - case 0: - divider = epow10(last_count); - if((!list && (number/divider) > 0) || number > divider) { - group = g_strdup_printf("%0*d", initial_grouping, number % divider); - } else { - 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, 1 + 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"); - } -} - -gchar * -e_format_number_float (gfloat number) -{ - gint int_part; - gint fraction; - struct lconv *locality; - gchar *str_intpart; - gchar *decimal_point; - gchar *str_fraction; - gchar *value; - - locality = localeconv(); - - int_part = (int) number; - str_intpart = e_format_number (int_part); - - if (!strcmp(locality->mon_decimal_point, "")) { - decimal_point = "."; - } - else { - decimal_point = locality->mon_decimal_point; - } - - fraction = (int) ((number - int_part) * 100); - - if (fraction == 0) { - str_fraction = g_strdup ("00"); - } - else { - str_fraction = g_strdup_printf ("%02d", fraction); - } - - value = g_strconcat (str_intpart, decimal_point, str_fraction, NULL); - - g_free (str_intpart); - g_free (str_fraction); - - return value; -} - -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); -} - - -/* Perform a binary search for key in base which has nmemb elements - of size bytes each. The comparisons are done by (*compare)(). */ -void e_bsearch (const void *key, - const void *base, - size_t nmemb, - size_t size, - ESortCompareFunc compare, - gpointer closure, - size_t *start, - size_t *end) -{ - size_t l, u, idx; - const void *p; - int comparison; - if (!(start || end)) - return; - - l = 0; - u = nmemb; - while (l < u) { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compare) (key, p, closure); - if (comparison < 0) - u = idx; - else if (comparison > 0) - l = idx + 1; - else { - size_t lsave, usave; - lsave = l; - usave = u; - if (start) { - while (l < u) { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compare) (key, p, closure); - if (comparison <= 0) - u = idx; - else - l = idx + 1; - } - *start = l; - - l = lsave; - u = usave; - } - if (end) { - while (l < u) { - idx = (l + u) / 2; - p = (void *) (((const char *) base) + (idx * size)); - comparison = (*compare) (key, p, closure); - if (comparison < 0) - u = idx; - else - l = idx + 1; - } - *end = l; - } - return; - } - } - - if (start) - *start = l; - if (end) - *end = l; -} - -static gpointer closure_closure; -static ESortCompareFunc compare_closure; - -static int -qsort_callback(const void *data1, const void *data2) -{ - return (*compare_closure) (data1, data2, closure_closure); -} - -/* Forget it. We're just going to use qsort. I lost the need for a stable sort. */ -void -e_sort (void *base, - size_t nmemb, - size_t size, - ESortCompareFunc compare, - gpointer closure) -{ - closure_closure = closure; - compare_closure = compare; - qsort(base, nmemb, size, qsort_callback); -#if 0 - void *base_copy; - int i; - base_copy = g_malloc(nmemb * size); - - for (i = 0; i < nmemb; i++) { - int position; - e_bsearch(base + (i * size), base_copy, i, size, compare, closure, NULL, &position); - memmove(base_copy + (position + 1) * size, base_copy + position * size, (i - position) * size); - memcpy(base_copy + position * size, base + i * size, size); - } - memcpy(base, base_copy, nmemb * size); - g_free(base_copy); -#endif -} diff --git a/e-util/e-util.h b/e-util/e-util.h deleted file mode 100644 index 8f99e0f8d5..0000000000 --- a/e-util/e-util.h +++ /dev/null @@ -1,212 +0,0 @@ -#ifndef _E_UTIL_H_ -#define _E_UTIL_H_ - -#include <sys/types.h> -#include <gtk/gtktypeutils.h> - -#ifdef __cplusplus -extern "C" { -#pragma } -#endif /* __cplusplus */ - -#define E_MAKE_TYPE(l,str,t,ci,i,parent) \ -GtkType l##_get_type(void)\ -{\ - static GtkType type = 0;\ - if (!type){\ - GtkTypeInfo info = {\ - str,\ - sizeof (t),\ - sizeof (t##Class),\ - (GtkClassInitFunc) ci,\ - (GtkObjectInitFunc) i,\ - NULL, /* reserved 1 */\ - NULL, /* reserved 2 */\ - (GtkClassInitFunc) NULL\ - };\ - type = gtk_type_unique (parent, &info);\ - }\ - return type;\ -} - - -#define E_MAKE_X_TYPE(l,str,t,ci,i,parent,poa_init,offset) \ -GtkType l##_get_type(void)\ -{\ - static GtkType type = 0;\ - if (!type){\ - GtkTypeInfo info = {\ - str,\ - sizeof (t),\ - sizeof (t##Class),\ - (GtkClassInitFunc) ci,\ - (GtkObjectInitFunc) i,\ - NULL, /* reserved 1 */\ - NULL, /* reserved 2 */\ - (GtkClassInitFunc) NULL\ - };\ - type = bonobo_x_type_unique (\ - parent, poa_init, NULL,\ - offset, &info);\ - }\ - return type;\ -} - -typedef enum { - E_FOCUS_NONE, - E_FOCUS_CURRENT, - 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_object_slist (GSList *list); -void e_free_string_list (GList *list); -void e_free_string_slist (GSList *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); -gchar *e_format_number (gint number); -gchar *e_format_number_float (gfloat number); -gboolean e_create_directory (gchar *directory); - - -typedef int (*ESortCompareFunc) (const void *first, - const void *second, - gpointer closure); -void e_sort (void *base, - size_t nmemb, - size_t size, - ESortCompareFunc compare, - gpointer closure); -void e_bsearch (const void *key, - const void *base, - size_t nmemb, - size_t size, - ESortCompareFunc compare, - gpointer closure, - size_t *start, - size_t *end); -void e_marshal_INT__INT_INT_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_INT__INT_POINTER_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); - -#define e_marshal_NONE__INT_POINTER_INT_POINTER_POINTER_UINT_UINT e_marshal_NONE__INT_POINTER_INT_POINTER_POINTER_INT_INT -void e_marshal_NONE__INT_POINTER_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); - -#define e_marshal_NONE__INT_POINTER_INT_POINTER_UINT e_marshal_NONE__INT_POINTER_INT_POINTER_INT -void e_marshal_NONE__INT_POINTER_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); - -#define e_marshal_BOOL__INT_POINTER_INT_POINTER_INT_INT_UINT e_marshal_BOOL__INT_POINTER_INT_POINTER_INT_INT_INT -void e_marshal_BOOL__INT_POINTER_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); - -#define e_marshal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_UINT_UINT e_marshal_NONE__INT_POINTER_INT_POINTER_INT_INT_POINTER_INT_INT -void e_marshal_NONE__INT_POINTER_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_POINTER_INT_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_INT__POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_INT__POINTER_POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_INT__POINTER_POINTER_POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_INT__POINTER_POINTER_POINTER_POINTER_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_NONE__POINTER_INT_INT_INT (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); -void e_marshal_INT__OBJECT_POINTER (GtkObject *object, - GtkSignalFunc func, - gpointer func_data, - GtkArg *args); - - -#ifdef __cplusplus -} -#endif /* __cplusplus */ - -#endif /* _E_UTIL_H_ */ diff --git a/e-util/e-xml-utils.c b/e-util/e-xml-utils.c deleted file mode 100644 index 3754d42ba2..0000000000 --- a/e-util/e-xml-utils.c +++ /dev/null @@ -1,420 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-xml-utils.c - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#include <config.h> - -#include "e-xml-utils.h" - -#include <locale.h> -#include <math.h> -#include <string.h> -#include <gnome-xml/parser.h> -#include <gnome-xml/xmlmemory.h> -#include "gal/util/e-i18n.h" - -xmlNode * -e_xml_get_child_by_name (const xmlNode *parent, const xmlChar *child_name) -{ - xmlNode *child; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (child_name != NULL, NULL); - - for (child = parent->childs; child != NULL; child = child->next) { - if (xmlStrcmp (child->name, child_name) == 0) { - return child; - } - } - return NULL; -} - -/* Returns the first child with the name child_name and the "lang" - * attribute that matches the current LC_MESSAGES, or else, the first - * child with the name child_name and no "lang" attribute. - */ -xmlNode * -e_xml_get_child_by_name_by_lang (const xmlNode *parent, - const xmlChar *child_name, - const gchar *lang) -{ - xmlNode *child; - /* This is the default version of the string. */ - xmlNode *C = NULL; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (child_name != NULL, NULL); - - if (lang == NULL) { -#ifdef HAVE_LC_MESSAGES - lang = setlocale (LC_MESSAGES, NULL); -#else - lang = setlocale (LC_CTYPE, NULL); -#endif - } - for (child = parent->childs; child != NULL; child = child->next) { - if (xmlStrcmp (child->name, child_name) == 0) { - xmlChar *this_lang = xmlGetProp (child, "lang"); - if (this_lang == NULL) { - C = child; - } else if (xmlStrcmp(this_lang, "lang") == 0) { - return child; - } - } - } - return C; -} - -static xmlNode * -e_xml_get_child_by_name_by_lang_list_with_score (const xmlNode *parent, - const gchar *name, - GList *lang_list, - gint *best_lang_score) -{ - xmlNodePtr best_node = NULL, node; - - for (node = parent->childs; node != NULL; node = node->next) { - xmlChar *lang; - - if (node->name == NULL || strcmp (node->name, name) != 0) { - continue; - } - lang = xmlGetProp (node, "xml:lang"); - if (lang != NULL) { - GList *l; - gint i; - - for (l = lang_list, i = 0; - l != NULL && i < *best_lang_score; - l = l->next, i++) { - if (strcmp ((gchar *) l->data, lang) == 0) { - best_node = node; - *best_lang_score = i; - } - } - } else { - if (best_node == NULL) { - best_node = node; - } - } - xmlFree (lang); - if (*best_lang_score == 0) { - return best_node; - } - } - - return best_node; -} - -/* - * e_xml_get_child_by_name_by_lang_list: - * - */ -xmlNode * -e_xml_get_child_by_name_by_lang_list (const xmlNode *parent, - const gchar *name, - GList *lang_list) -{ - gint best_lang_score = INT_MAX; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - if (lang_list == NULL) { - lang_list = gnome_i18n_get_language_list ("LC_MESSAGES"); - } - return e_xml_get_child_by_name_by_lang_list_with_score - (parent,name, - lang_list, - &best_lang_score); -} - -/* - * e_xml_get_child_by_name_no_lang - * - */ -xmlNode * -e_xml_get_child_by_name_no_lang (const xmlNode *parent, const gchar *name) -{ - xmlNodePtr node; - - g_return_val_if_fail (parent != NULL, NULL); - g_return_val_if_fail (name != NULL, NULL); - - for (node = parent->childs; node != NULL; node = node->next) { - xmlChar *lang; - - if (node->name == NULL || strcmp (node->name, name) != 0) { - continue; - } - lang = xmlGetProp (node, "xml:lang"); - if (lang == NULL) { - return node; - } - xmlFree (lang); - } - - return NULL; -} - -gint -e_xml_get_integer_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) -{ - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - return e_xml_get_integer_prop_by_name_with_default (parent, prop_name, 0); -} - -gint -e_xml_get_integer_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - gint def) -{ - xmlChar *prop; - gint ret_val = def; - - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - prop = xmlGetProp ((xmlNode *) parent, prop_name); - if (prop != NULL) { - (void) sscanf (prop, "%d", &ret_val); - xmlFree (prop); - } - return ret_val; -} - -void -e_xml_set_integer_prop_by_name (xmlNode *parent, - const xmlChar *prop_name, - gint value) -{ - gchar *valuestr; - - g_return_if_fail (parent != NULL); - g_return_if_fail (prop_name != NULL); - - valuestr = g_strdup_printf ("%d", value); - xmlSetProp (parent, prop_name, valuestr); - g_free (valuestr); -} - -guint -e_xml_get_uint_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) -{ - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - return e_xml_get_uint_prop_by_name_with_default (parent, prop_name, 0); -} - -guint -e_xml_get_uint_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - guint def) -{ - xmlChar *prop; - guint ret_val = def; - - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - prop = xmlGetProp ((xmlNode *) parent, prop_name); - if (prop != NULL) { - (void) sscanf (prop, "%u", &ret_val); - xmlFree (prop); - } - return ret_val; -} - -void -e_xml_set_uint_prop_by_name (xmlNode *parent, - const xmlChar *prop_name, - guint value) -{ - gchar *valuestr; - - g_return_if_fail (parent != NULL); - g_return_if_fail (prop_name != NULL); - - valuestr = g_strdup_printf ("%u", value); - xmlSetProp (parent, prop_name, valuestr); - g_free (valuestr); -} - -gboolean -e_xml_get_bool_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name) -{ - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - return e_xml_get_bool_prop_by_name_with_default (parent, - prop_name, - FALSE); -} - -gboolean -e_xml_get_bool_prop_by_name_with_default(const xmlNode *parent, - const xmlChar *prop_name, - gboolean def) -{ - xmlChar *prop; - gboolean ret_val = def; - - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - prop = xmlGetProp ((xmlNode *) parent, prop_name); - if (prop != NULL) { - if (g_strcasecmp (prop, "true") == 0) { - ret_val = TRUE; - } else if (g_strcasecmp (prop, "false") == 0) { - ret_val = FALSE; - } - xmlFree(prop); - } - return ret_val; -} - -void -e_xml_set_bool_prop_by_name (xmlNode *parent, const xmlChar *prop_name, gboolean value) -{ - g_return_if_fail (parent != NULL); - g_return_if_fail (prop_name != NULL); - - if (value) { - xmlSetProp (parent, prop_name, "true"); - } else { - xmlSetProp (parent, prop_name, "false"); - } -} - -gdouble -e_xml_get_double_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) -{ - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - return e_xml_get_double_prop_by_name_with_default (parent, prop_name, 0.0); -} - -gdouble -e_xml_get_double_prop_by_name_with_default (const xmlNode *parent, const xmlChar *prop_name, gdouble def) -{ - xmlChar *prop; - gdouble ret_val = def; - - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - prop = xmlGetProp ((xmlNode *) parent, prop_name); - if (prop != NULL) { - (void) sscanf (prop, "%lf", &ret_val); - xmlFree (prop); - } - return ret_val; -} - -void -e_xml_set_double_prop_by_name(xmlNode *parent, const xmlChar *prop_name, gdouble value) -{ - gchar *valuestr; - - g_return_if_fail (parent != NULL); - g_return_if_fail (prop_name != NULL); - - if (fabs (value) < 1e9 && fabs (value) > 1e-5) { - valuestr = g_strdup_printf ("%f", value); - } else { - valuestr = g_strdup_printf ("%.*g", DBL_DIG, value); - } - xmlSetProp (parent, prop_name, valuestr); - g_free (valuestr); -} - -gchar * -e_xml_get_string_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) -{ - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - return e_xml_get_string_prop_by_name_with_default (parent, prop_name, NULL); -} - -gchar * -e_xml_get_string_prop_by_name_with_default (const xmlNode *parent, const xmlChar *prop_name, const gchar *def) -{ - xmlChar *prop; - gchar *ret_val; - - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - prop = xmlGetProp ((xmlNode *) parent, prop_name); - if (prop != NULL) { - ret_val = g_strdup (prop); - xmlFree (prop); - } else { - ret_val = g_strdup (def); - } - return ret_val; -} - -void -e_xml_set_string_prop_by_name (xmlNode *parent, const xmlChar *prop_name, const gchar *value) -{ - g_return_if_fail (parent != NULL); - g_return_if_fail (prop_name != NULL); - - if (value != NULL) { - xmlSetProp (parent, prop_name, value); - } -} - -gchar * -e_xml_get_translated_string_prop_by_name (const xmlNode *parent, const xmlChar *prop_name) -{ - xmlChar *prop; - gchar *ret_val = NULL; - gchar *combined_name; - - g_return_val_if_fail (parent != NULL, 0); - g_return_val_if_fail (prop_name != NULL, 0); - - prop = xmlGetProp ((xmlNode *) parent, prop_name); - if (prop != NULL) { - ret_val = g_strdup (prop); - xmlFree (prop); - return ret_val; - } - - combined_name = g_strdup_printf("_%s", prop_name); - prop = xmlGetProp ((xmlNode *) parent, combined_name); - if (prop != NULL) { - ret_val = g_strdup (gettext(prop)); - xmlFree (prop); - } - g_free(combined_name); - - return ret_val; -} diff --git a/e-util/e-xml-utils.h b/e-util/e-xml-utils.h deleted file mode 100644 index ba102c1c3d..0000000000 --- a/e-util/e-xml-utils.h +++ /dev/null @@ -1,99 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * e-xml-utils.h - * Copyright (C) 2000 Helix Code, Inc. - * Author: Chris Lahey <clahey@helixcode.com> - * - * This library is free software; you can redistribute it and/or - * modify it under the terms of the GNU General Public License as - * published by the Free Software Foundation; either version 2 of the - * License, or (at your option) any later version. - * - * This program is distributed in the hope that it will be useful, - * but WITHOUT ANY WARRANTY; without even the implied warranty of - * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU - * General Public License for more details. - * - * You should have received a copy of the GNU General Public - * License along with this library; if not, write to the - * Free Software Foundation, Inc., 59 Temple Place - Suite 330, - * Boston, MA 02111-1307, USA. - */ - -#ifndef __E_XML_UTILS__ -#define __E_XML_UTILS__ - -#include <libgnome/gnome-defs.h> -#include <glib.h> -#include <gnome-xml/tree.h> - -BEGIN_GNOME_DECLS - -xmlNode *e_xml_get_child_by_name (const xmlNode *parent, - const xmlChar *child_name); -/* lang set to NULL means use the current locale. */ -xmlNode *e_xml_get_child_by_name_by_lang (const xmlNode *parent, - const xmlChar *child_name, - const gchar *lang); -/* lang_list set to NULL means use the current locale. */ -xmlNode *e_xml_get_child_by_name_by_lang_list (const xmlNode *parent, - const gchar *name, - GList *lang_list); -xmlNode *e_xml_get_child_by_name_no_lang (const xmlNode *parent, - const gchar *name); - - -gint e_xml_get_integer_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name); -gint e_xml_get_integer_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - gint def); -void e_xml_set_integer_prop_by_name (xmlNode *parent, - const xmlChar *prop_name, - gint value); - - -guint e_xml_get_uint_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name); -guint e_xml_get_uint_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - guint def); -void e_xml_set_uint_prop_by_name (xmlNode *parent, - const xmlChar *prop_name, - guint value); - - -gboolean e_xml_get_bool_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name); -gboolean e_xml_get_bool_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - gboolean def); -void e_xml_set_bool_prop_by_name (xmlNode *parent, - const xmlChar *prop_name, - gboolean value); - -gdouble e_xml_get_double_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name); -gdouble e_xml_get_double_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - gdouble def); -void e_xml_set_double_prop_by_name ( xmlNode *parent, - const xmlChar *prop_name, - gdouble value); - - -gchar *e_xml_get_string_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name); -gchar *e_xml_get_string_prop_by_name_with_default (const xmlNode *parent, - const xmlChar *prop_name, - const gchar *def); -void e_xml_set_string_prop_by_name (xmlNode *parent, - const xmlChar *prop_name, - const gchar *value); - -gchar *e_xml_get_translated_string_prop_by_name (const xmlNode *parent, - const xmlChar *prop_name); - -END_GNOME_DECLS - -#endif /* __E_XML_UTILS__ */ diff --git a/e-util/ename/.cvsignore b/e-util/ename/.cvsignore deleted file mode 100644 index 4f8c173841..0000000000 --- a/e-util/ename/.cvsignore +++ /dev/null @@ -1,8 +0,0 @@ -.deps -.libs -Makefile -Makefile.in -*.lo -*.la -test-ename-western -test-ename-western-gtk diff --git a/e-util/ename/Makefile.am b/e-util/ename/Makefile.am deleted file mode 100644 index b3abe633df..0000000000 --- a/e-util/ename/Makefile.am +++ /dev/null @@ -1,57 +0,0 @@ -INCLUDES = \ - -DG_LOG_DOMAIN=\"EName\" \ - -I$(srcdir) \ - -I$(srcdir)/.. \ - -I$(top_srcdir) \ - -I. \ - -I.. \ - -I$(top_builddir) \ - -I$(includedir) \ - $(GNOME_INCLUDEDIR) \ - $(EXTRA_GNOME_CFLAGS) - -gnome_libs = \ - $(BONOBO_GNOME_LIBS) \ - $(INTLLIBS) \ - $(EXTRA_GNOME_LIBS) - -ename_libs = \ - libename.la \ - $(gnome_libs) - -lib_LTLIBRARIES = libename.la - -libename_la_SOURCES = \ - e-address-western.c \ - e-name-western.c - -libenameincludedir = $(includedir)/ename - -libenameinclude_HEADERS = \ - e-address-western.h \ - e-name-western-tables.h \ - e-name-western.h - - -noinst_LTLIBRARIES = libename-static.la -libename_static_la_SOURCES = $(libename_la_SOURCES) -libename_static_la_LDFLAGS = --all-static - - -noinst_PROGRAMS = \ - test-ename-western \ - test-ename-western-gtk - -test_ename_western_SOURCES = \ - test-ename-western.c - -test_ename_western_LDADD = $(ename_libs) \ - $(EXTRA_GNOME_LIBS) - -test_ename_western_gtk_SOURCES = \ - test-ename-western-gtk.c - -test_ename_western_gtk_LDADD = \ - $(ename_libs) \ - $(top_builddir)/e-util/libeutil.la \ - $(gnome_libs) diff --git a/e-util/ename/TODO b/e-util/ename/TODO deleted file mode 100644 index 669661eea7..0000000000 --- a/e-util/ename/TODO +++ /dev/null @@ -1,2 +0,0 @@ -* Support other naming systems. -* Handle misspelled suffixes better. diff --git a/e-util/ename/e-address-western.c b/e-util/ename/e-address-western.c deleted file mode 100644 index 88b501497e..0000000000 --- a/e-util/ename/e-address-western.c +++ /dev/null @@ -1,446 +0,0 @@ -/* -------------------------------------------------- - - An address parser, yielding fields as per RFC 2426. - - Author: - Jesse Pavel (jpavel@ximian.com) - - Copyright 2000, Ximian, Inc. - -------------------------------------------------- -*/ - -#include <ctype.h> -#include <string.h> -#include <glib.h> - -#ifdef E_ADDRESS_WESTERN_TEST - -#include "e-address-western.h" - -#else - -#include <ename/e-address-western.h> -#include <gal/util/e-util.h> - -#endif - -/* These are the keywords that will distinguish the start of an extended - address. */ - -static char *extended_keywords[] = { - "apt", "apartment", "suite", NULL -}; - - - -static gboolean -e_address_western_is_line_blank (gchar *line) -{ - gboolean blank = TRUE; - gint cntr; - - /* A blank line consists of whitespace only, or a NULL line. */ - for (cntr = 0; line[cntr] != '\0'; cntr++ ) { - if (!isspace(line[cntr])) { - blank = FALSE; - break; - } - } - - return blank; -} - - - -/* In the array of lines, `lines', we will erase the line at line_num, and - shift the remaining lines, up to line number num_lines, up one position. */ - -static void -e_address_western_shift_line (gchar *lines[], gint line_num, gint num_lines) -{ - gint cntr; - - if (line_num >= (num_lines - 1)) { - /* It is the last line, so simply shift in a NULL. */ - lines[line_num] = NULL; - } - else { - for (cntr = line_num; cntr < num_lines; cntr++) - lines[cntr] = lines[cntr + 1]; - } -} - - -static void -e_address_western_remove_blank_lines (gchar *lines[], gint *linecntr) -{ - gint cntr; - - for (cntr = 0; cntr < *linecntr; cntr++) { - if (e_address_western_is_line_blank (lines[cntr])) { - /* Delete the blank line, and shift all subsequent lines up - one spot to fill its old spot. */ - e_address_western_shift_line (lines, cntr, *linecntr); - - /* Since we must check the newly shifted line, let's - not advance the counter on this next pass. */ - cntr--; - - /* There is now one less line, total. */ - *linecntr -= 1; - } - } -} - - -static gboolean -e_address_western_is_po_box (gchar *line) -{ - gboolean retval = FALSE; - - /* In which phase of processing are we? */ - enum State { FIRSTCHAR, SECONDCHAR, WHITESPACE } state; - - - /* If the first two letters of the line are `p' and `o', and these - are in turn followed by whitespace before another letter, then I - will deem the line a representation of a PO Box address. */ - - gint cntr; - - state = FIRSTCHAR; - for (cntr = 0; line[cntr] != '\0'; cntr++) { - if (state == FIRSTCHAR) { - if (isalnum(line[cntr])) { - if (tolower(line[cntr]) == 'p') - state = SECONDCHAR; - else { - retval = FALSE; - break; - } - } - } - else if (state == SECONDCHAR) { - if (isalnum (line[cntr])) { - if (tolower(line[cntr]) == 'o') - state = WHITESPACE; - else { - retval = FALSE; - break; - } - } - } - else if (state == WHITESPACE) { - if (isspace (line[cntr])) { - retval = TRUE; - break; - } - else if (isalnum (line[cntr])) { - retval = FALSE; - break; - } - } - } - - return retval; -} - -/* A line that contains a comma followed eventually by a number is - deemed to be the line in the form of <town, region postal-code>. */ - -static gboolean -e_address_western_is_postal (guchar *line) -{ - gboolean retval; - int cntr; - - if (strchr (line, ',') == NULL) - retval = FALSE; /* No comma. */ - else { - int index; - - /* Ensure that the first character after the comma is - a letter. */ - index = strcspn (line, ","); - index++; - while (isspace(line[index])) - index++; - - if (!isalpha (line[index])) - return FALSE; /* FIXME: ugly control flow. */ - - cntr = strlen(line) - 1; - - /* Go to the character immediately following the last - whitespace character. */ - while (cntr >= 0 && isspace(line[cntr])) - cntr--; - - while (cntr >= 0 && !isspace(line[cntr])) - cntr--; - - if (cntr == 0) - retval = FALSE; - else { - if (isdigit (line[cntr+1])) - retval = TRUE; - else - retval = FALSE; - } - } - - return retval; -} - -static gchar * -e_address_western_extract_po_box (gchar *line) -{ - /* Return everything from the beginning of the line to - the end of the first word that contains a number. */ - - int index; - - index = 0; - while (!isdigit(line[index])) - index++; - - while (isgraph(line[index])) - index++; - - return g_strndup (line, index); -} - -static gchar * -e_address_western_extract_locality (gchar *line) -{ - gint index; - - /* Everything before the comma is the locality. */ - index = strcspn(line, ","); - - if (index == 0) - return NULL; - else - return g_strndup (line, index); -} - - -/* Whatever resides between the comma and the start of the - postal code is deemed to be the region. */ - -static gchar * -e_address_western_extract_region (gchar *line) -{ - gint start, end; - - start = strcspn (line, ","); - start++; - while (isspace(line[start])) - start++; - - end = strlen(line) - 1; - while (isspace (line[end])) - end--; - - while (!isspace (line[end])) - end--; - - while (isspace (line[end])) - end--; - end++; - - /* Between start and end lie the string. */ - return g_strndup ( (line+start), end-start); -} - -static gchar * -e_address_western_extract_postal_code (gchar *line) -{ - int start, end; - - end = strlen (line) - 1; - while (isspace(line[end])) - end--; - - start = end; - end++; - - while (!isspace(line[start])) - start--; - start++; - - /* Between start and end lie the string. */ - return g_strndup ( (line+start), end-start); -} - - - -static void -e_address_western_extract_street (gchar *line, gchar **street, gchar **extended) -{ - const gchar *split = NULL; - gint cntr; - - for (cntr = 0; extended_keywords[cntr] != NULL; cntr++) { - split = e_strstrcase (line, extended_keywords[cntr]); - if (split != NULL) - break; - } - - if (split != NULL) { - *street = g_strndup (line, (split - line)); - *extended = g_strdup (split); - } - else { - *street = g_strdup (line); - *extended = NULL; - } - -} - - - -EAddressWestern * -e_address_western_parse (const gchar *in_address) -{ - gchar **lines; - gint linecntr, lineindex; - gchar *address; - gint cntr; - gboolean found_po_box, found_postal; - - EAddressWestern *eaw; -#if 0 - gint start, end; /* To be used to classify address lines. */ -#endif - - if (in_address == NULL) - return NULL; - - eaw = (EAddressWestern *)g_malloc (sizeof(EAddressWestern)); - eaw->po_box = NULL; - eaw->extended = NULL; - eaw->street = NULL; - eaw->locality = NULL; - eaw->region = NULL; - eaw->postal_code = NULL; - eaw->country = NULL; - - address = g_strdup (in_address); - - /* The first thing I'll do is divide the multiline input string - into lines. */ - - /* ... count the lines. */ - linecntr = 1; - lineindex = 0; - while (address[lineindex] != '\0') { - if (address[lineindex] == '\n') - linecntr++; - - lineindex++; - } - - /* ... tally them. */ - lines = (gchar **)g_malloc (sizeof(gchar *) * (linecntr+3)); - lineindex = 0; - lines[0] = &address[0]; - linecntr = 1; - while (address[lineindex] != '\0') { - if (address[lineindex] == '\n') { - lines[linecntr] = &address[lineindex + 1]; - linecntr++; - } - - lineindex++; - } - - /* Convert the newlines at the end of each line (except the last, - because it is already NULL terminated) to NULLs. */ - for (cntr = 0; cntr < (linecntr - 1); cntr++) { - *(strchr (lines[cntr], '\n')) = '\0'; - } - - e_address_western_remove_blank_lines (lines, &linecntr); - - /* Let's just test these functions. */ - found_po_box = FALSE; - found_postal = FALSE; - - for (cntr = 0; cntr < linecntr; cntr++) { - if (e_address_western_is_po_box (lines[cntr])) { - if (eaw->po_box == NULL) - eaw->po_box = e_address_western_extract_po_box (lines[cntr]); - found_po_box = TRUE; - } - else if (e_address_western_is_postal (lines[cntr])) { - if (eaw->locality == NULL) - eaw->locality = e_address_western_extract_locality (lines[cntr]); - if (eaw->region == NULL) - eaw->region = e_address_western_extract_region (lines[cntr]); - if (eaw->postal_code == NULL) - eaw->postal_code = e_address_western_extract_postal_code (lines[cntr]); - found_postal = TRUE; - } - else { - if (found_postal) { - if (eaw->country == NULL) - eaw->country = g_strdup (lines[cntr]); - else { - gchar *temp; - temp = g_strconcat (eaw->country, "\n", lines[cntr], NULL); - g_free (eaw->country); - eaw->country = temp; - } - } - else { - if (eaw->street == NULL) { - e_address_western_extract_street (lines[cntr], &eaw->street, - &eaw->extended ); - } - else { - if (eaw->extended == NULL) { - eaw->extended = g_strdup (lines[cntr]); - } - else { - gchar *temp; - temp = g_strconcat (eaw->extended, "\n", lines[cntr], NULL); - g_free (eaw->extended); - eaw->extended = temp; - } - } - } - } - } - - g_free (lines); - g_free (address); - - return eaw; -} - - -void -e_address_western_free (EAddressWestern *eaw) -{ - if (eaw == NULL) - return; - - if (eaw->po_box != NULL) - g_free(eaw->po_box); - if (eaw->extended != NULL) - g_free(eaw->extended); - if (eaw->street != NULL) - g_free(eaw->street); - if (eaw->locality != NULL) - g_free(eaw->locality); - if (eaw->region != NULL) - g_free(eaw->region); - if (eaw->postal_code != NULL) - g_free(eaw->postal_code); - if (eaw->country != NULL) - g_free(eaw->country); - - g_free (eaw); -} - diff --git a/e-util/ename/e-address-western.h b/e-util/ename/e-address-western.h deleted file mode 100644 index e6417f88c4..0000000000 --- a/e-util/ename/e-address-western.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __E_ADDRESS_WESTERN_H__ -#define __E_ADDRESS_WESTERN_H__ - -typedef struct { - - /* Public */ - char *po_box; - char *extended; /* I'm not sure what this is. */ - char *street; - char *locality; /* For example, the city or town. */ - char *region; /* The state or province. */ - char *postal_code; - char *country; -} EAddressWestern; - -EAddressWestern *e_address_western_parse (const char *address); -void e_address_western_free (EAddressWestern *eaw); - -#endif /* ! __E_ADDRESS_WESTERN_H__ */ - - diff --git a/e-util/ename/e-name-western-tables.h b/e-util/ename/e-name-western-tables.h deleted file mode 100644 index 2e94a94845..0000000000 --- a/e-util/ename/e-name-western-tables.h +++ /dev/null @@ -1,74 +0,0 @@ -#ifndef __E_NAME_WESTERN_TABLES_H__ -#define __E_NAME_WESTERN_TABLES_H__ - -char *e_name_western_pfx_table[] = { - - /* - * English. - */ - "mister", "miss.", "mr.", "mrs.", "ms.", - "miss", "mr", "mrs", "ms", "sir", - "professor", "prof.", "dr", "dr.", "doctor", - "judge", "justice", "chief justice", - "congressman", "congresswoman", "commander", - "lieutenant", "lt.", "colonel", "col.", "major", "maj.", - "general", "gen.", "admiral", "admr.", "sergeant", "sgt.", - "lord", "lady", "baron", "baroness", "duke", "duchess", - "king", "queen", "prince", "princess", - - "the most honorable", "the honorable", - "the reverend", "his holiness", - "his eminence", "his majesty", "her majesty", - "his grace", "her grace", - - "president", "vice president", "secretary", "undersecretary", - "consul", "ambassador", - - "senator", "saint", "st.", "pastor", "deacon", - "father", "bishop", "archbishop", "cardinal", "pope", - "reverend", "rev.", "rabbi", - - /* - * French. - */ - "monsieur", "m.", "mademoiselle", "melle", - "madame", "mme", "professeur", "dauphin", "dauphine", - - /* - * German - */ - "herr", "frau", "fraulein", "herr doktor", "doktor frau", "doktor frau doktor", - "frau doktor", - - - /* - * Spanish. - */ - "senor", "senora", "sra.", "senorita", "srita.", - - NULL}; - -char *e_name_western_sfx_table[] = { - - /* - * English. - */ - "junior", "senior", "jr", "sr", "I", "II", "III", "IV", "V", - "VI", "VII", "VIII", "IX", "X", "XI", "XII", "XIII", "XIV", - "XV", "XVI", "XVII", "XVIII", "XIX", "XX", "XXI", "XXII", - "phd", "ms", "md", "esq", "esq.", "esquire", - - NULL}; - -char *e_name_western_twopart_sfx_table[] = { - - /* - * English. - */ - "the first", "the second", "the third", - - NULL}; - -char *e_name_western_complex_last_table[] = {"van", "von", "de", NULL}; - -#endif /* ! __E_NAME_WESTERN_TABLES_H__ */ diff --git a/e-util/ename/e-name-western.c b/e-util/ename/e-name-western.c deleted file mode 100644 index f3fe719023..0000000000 --- a/e-util/ename/e-name-western.c +++ /dev/null @@ -1,870 +0,0 @@ -/* - * A simple Western name parser. - * - * <Nat> Jamie, do you know anything about name parsing? - * <jwz> Are you going down that rat hole? Bring a flashlight. - * - * Author: - * Nat Friedman (nat@ximian.com) - * - * Copyright 1999, Ximian, Inc. - */ - -#include <ctype.h> -#include <string.h> -#include <glib.h> - -#include <ename/e-name-western.h> -#include <ename/e-name-western-tables.h> - -typedef struct { - int prefix_idx; - int first_idx; - int middle_idx; - int nick_idx; - int last_idx; - int suffix_idx; -} ENameWesternIdxs; - -static int -e_name_western_str_count_words (char *str) -{ - int word_count; - char *p; - - word_count = 0; - - for (p = str; p != NULL; p = strchr (p, ' ')) { - word_count ++; - p ++; - } - - return word_count; -} - -static void -e_name_western_cleanup_string (char **str) -{ - char *newstr; - char *p; - - if (*str == NULL) - return; - - /* skip any spaces and commas at the start of the string */ - p = *str; - while (isspace (*p) || *p == ',') - p ++; - - /* make the copy we're going to return */ - newstr = g_strdup (p); - - if ( strlen(newstr) > 0) { - /* now search from the back, skipping over any spaces and commas */ - p = newstr + strlen (newstr) - 1; - while (isspace (*p) || *p == ',') - p --; - /* advance p to after the character that caused us to exit the - previous loop, and end the string. */ - if ((! isspace (*p)) && *p != ',') - p ++; - *p = '\0'; - } - - g_free (*str); - *str = newstr; -} - -static char * -e_name_western_get_words_at_idx (char *str, int idx, int num_words) -{ - char *words; - char *p; - int word_count; - int words_len; - - /* - * Walk to the end of the words. - */ - word_count = 0; - p = str + idx; - while (word_count < num_words && *p != '\0') { - while (! isspace (*p) && *p != '\0') - p ++; - - while (isspace (*p) && *p != '\0') - p ++; - - word_count ++; - } - - words_len = p - str - idx - 1; - - if (*p == '\0') - words_len ++; - - words = g_malloc0 (1 + words_len); - strncpy (words, str + idx, words_len); - - return words; -} - -/* - * What the fuck is wrong with glib's MAX macro. - */ -static int -e_name_western_max (const int a, const int b) -{ - if (a > b) - return a; - - return b; -} - -static gboolean -e_name_western_word_is_suffix (char *word) -{ - int i; - - for (i = 0; e_name_western_sfx_table [i] != NULL; i ++) { - if (g_strcasecmp (word, e_name_western_sfx_table [i])) - continue; - - return TRUE; - } - - return FALSE; -} - -static char * -e_name_western_get_one_prefix_at_str (char *str) -{ - char *word; - int i; - - /* - * Check for prefixes from our table. - */ - for (i = 0; e_name_western_pfx_table [i] != NULL; i ++) { - int pfx_words; - char *words; - - pfx_words = e_name_western_str_count_words (e_name_western_pfx_table [i]); - words = e_name_western_get_words_at_idx (str, 0, pfx_words); - - if (! g_strcasecmp (words, e_name_western_pfx_table [i])) - return words; - - g_free (words); - } - - /* - * Check for prefixes we don't know about. These are always a - * sequence of more than one letters followed by a period. - */ - word = e_name_western_get_words_at_idx (str, 0, 1); - - if (strlen (word) > 2 && - isalpha ((unsigned char) word [0]) && - isalpha ((unsigned char) word [1]) && - word [strlen (word) - 1] == '.') - return word; - - g_free (word); - - return NULL; -} - -static char * -e_name_western_get_prefix_at_str (char *str) -{ - char *pfx; - char *pfx1; - char *pfx2; - char *p; - - /* Get the first prefix. */ - pfx1 = e_name_western_get_one_prefix_at_str (str); - - if (pfx1 == NULL) - return NULL; - - /* Check for a second prefix. */ - p = str + strlen (pfx1); - while (isspace (*p) && *p != '\0') - p ++; - - pfx2 = e_name_western_get_one_prefix_at_str (p); - - if (pfx2 != NULL) { - int pfx_len; - - pfx_len = (p + strlen (pfx2)) - str; - pfx = g_malloc0 (pfx_len + 1); - strncpy (pfx, str, pfx_len); - } else { - pfx = g_strdup (pfx1); - } - - g_free (pfx1); - g_free (pfx2); - - return pfx; -} - -static void -e_name_western_extract_prefix (ENameWestern *name, ENameWesternIdxs *idxs) -{ - char *pfx; - - pfx = e_name_western_get_prefix_at_str (name->full); - - if (pfx == NULL) - return; - - idxs->prefix_idx = 0; - name->prefix = pfx; -} - -static gboolean -e_name_western_is_complex_last_beginning (char *word) -{ - int i; - - for (i = 0; e_name_western_complex_last_table [i] != NULL; i ++) { - - if (! g_strcasecmp ( - word, e_name_western_complex_last_table [i])) - return TRUE; - } - - return FALSE; -} - -static void -e_name_western_extract_first (ENameWestern *name, ENameWesternIdxs *idxs) -{ - /* - * If there's a prefix, then the first name is right after it. - */ - if (idxs->prefix_idx != -1) { - int first_idx; - char *p; - - first_idx = idxs->prefix_idx + strlen (name->prefix); - - /* Skip past white space. */ - p = name->full + first_idx; - while (isspace (*p) && *p != '\0') - p++; - - if (*p == '\0') - return; - - idxs->first_idx = p - name->full; - name->first = e_name_western_get_words_at_idx ( - name->full, idxs->first_idx, 1); - - } else { - - /* - * Otherwise, the first name is probably the first string. - */ - idxs->first_idx = 0; - name->first = e_name_western_get_words_at_idx ( - name->full, idxs->first_idx, 1); - } - - /* - * Check that we didn't just assign the beginning of a - * compound last name to the first name. - */ - if (name->first != NULL) { - if (e_name_western_is_complex_last_beginning (name->first)) { - g_free (name->first); - name->first = NULL; - idxs->first_idx = -1; - } - } -} - -static void -e_name_western_extract_middle (ENameWestern *name, ENameWesternIdxs *idxs) -{ - char *word; - int middle_idx; - - /* - * Middle names can only exist if you have a first name. - */ - if (idxs->first_idx == -1) - return; - - middle_idx = idxs->first_idx + strlen (name->first) + 1; - - if (middle_idx > strlen (name->full)) - return; - - /* - * Search for the first space (or the terminating \0) - */ - while (isspace (name->full [middle_idx]) && - name->full [middle_idx] != '\0') - middle_idx ++; - - if (name->full [middle_idx] == '\0') - return; - - /* - * Skip past the nickname, if it's there. - */ - if (name->full [middle_idx] == '\"') { - if (idxs->nick_idx == -1) - return; - - middle_idx = idxs->nick_idx + strlen (name->nick) + 1; - - while (isspace (name->full [middle_idx]) && - name->full [middle_idx] != '\0') - middle_idx ++; - - if (name->full [middle_idx] == '\0') - return; - } - - /* - * Make sure this isn't the beginning of a complex last name. - */ - word = e_name_western_get_words_at_idx (name->full, middle_idx, 1); - if (e_name_western_is_complex_last_beginning (word)) { - g_free (word); - return; - } - - /* - * Make sure this isn't a suffix. - */ - e_name_western_cleanup_string (& word); - if (e_name_western_word_is_suffix (word)) { - g_free (word); - return; - } - - /* - * Make sure we didn't just grab a cute nickname. - */ - if (word [0] == '\"') { - g_free (word); - return; - } - - idxs->middle_idx = middle_idx; - name->middle = word; -} - -static void -e_name_western_extract_nickname (ENameWestern *name, ENameWesternIdxs *idxs) -{ - int idx; - int start_idx; - char *str; - - if (idxs->first_idx == -1) - return; - - if (idxs->middle_idx > idxs->first_idx) - idx = idxs->middle_idx + strlen (name->middle); - else - idx = idxs->first_idx + strlen (name->first); - - while (name->full [idx] != '\"' && name->full [idx] != '\0') - idx ++; - - if (name->full [idx] != '\"') - return; - - start_idx = idx; - - /* - * Advance to the next double quote. - */ - idx ++; - - while (name->full [idx] != '\"' && name->full [idx] != '\0') - idx ++; - - if (name->full [idx] == '\0') - return; - - str = g_malloc0 (idx - start_idx + 2); - strncpy (str, name->full + start_idx, idx - start_idx + 1); - - name->nick = str; - idxs->nick_idx = start_idx; -} - -static int -e_name_western_last_get_max_idx (ENameWestern *name, ENameWesternIdxs *idxs) -{ - int max_idx = -1; - - if (name->prefix != NULL) - max_idx = e_name_western_max ( - max_idx, idxs->prefix_idx + strlen (name->prefix)); - - if (name->first != NULL) - max_idx = e_name_western_max ( - max_idx, idxs->first_idx + strlen (name->first)); - - if (name->middle != NULL) - max_idx = e_name_western_max ( - max_idx, idxs->middle_idx + strlen (name->middle)); - - if (name->nick != NULL) - max_idx = e_name_western_max ( - max_idx, idxs->nick_idx + strlen (name->nick)); - - return max_idx; -} - -static void -e_name_western_extract_last (ENameWestern *name, ENameWesternIdxs *idxs) -{ - char *word; - int idx = -1; - - idx = e_name_western_last_get_max_idx (name, idxs); - - /* - * In the case where there is no preceding name element, the - * name is either just a first name ("Nat", "John"), is a - * single-element name ("Cher", which we treat as a first - * name), or is just a last name. The only time we can - * differentiate a last name alone from a single-element name - * or a first name alone is if it's a complex last name ("de - * Icaza", "van Josephsen"). So if there is no preceding name - * element, we check to see whether or not the first part of - * the name is the beginning of a complex name. If it is, - * we subsume the entire string. If we accidentally subsume - * the suffix, this will get fixed in the fixup routine. - */ - if (idx == -1) { - word = e_name_western_get_words_at_idx (name->full, 0, 1); - if (! e_name_western_is_complex_last_beginning (word)) { - g_free (word); - return; - } - - name->last = g_strdup (name->full); - idxs->last_idx = 0; - return; - } - - /* Skip past the white space. */ - while (isspace (name->full [idx]) && name->full [idx] != '\0') - idx ++; - - if (name->full [idx] == '\0') - return; - - word = e_name_western_get_words_at_idx (name->full, idx, 1); - e_name_western_cleanup_string (& word); - if (e_name_western_word_is_suffix (word)) { - g_free (word); - return; - } - g_free (word); - - /* - * Subsume the rest of the string into the last name. If we - * accidentally include the prefix, it will get fixed later. - * This is the only way to handle things like "Miguel de Icaza - * Amozorrutia" without dropping data and forcing the user - * to retype it. - */ - name->last = g_strdup (name->full + idx); - idxs->last_idx = idx; -} - -static char * -e_name_western_get_preceding_word (char *str, int idx) -{ - int word_len; - char *word; - char *p; - - p = str + idx; - - while (isspace (*p) && p > str) - p --; - - while (! isspace (*p) && p > str) - p --; - - if (isspace (*p)) - p ++; - - word_len = (str + idx) - p; - word = g_malloc0 (word_len + 1); - if (word_len > 0) - strncpy (word, p, word_len); - - return word; -} - -static char * -e_name_western_get_suffix_at_str_end (char *str) -{ - char *suffix; - char *p; - - /* - * Walk backwards till we reach the beginning of the - * (potentially-comma-separated) list of suffixes. - */ - p = str + strlen (str); - while (1) { - char *nextp; - char *word; - - word = e_name_western_get_preceding_word (str, p - str); - nextp = p - strlen (word) - 1; - - e_name_western_cleanup_string (& word); - - if (e_name_western_word_is_suffix (word)) { - p = nextp; - g_free (word); - } else { - g_free (word); - break; - } - } - - if (p == (str + strlen (str))) - return NULL; - - suffix = g_strdup (p); - e_name_western_cleanup_string (& suffix); - - if (strlen (suffix) == 0) { - g_free (suffix); - return NULL; - } - - return suffix; -} - -static void -e_name_western_extract_suffix (ENameWestern *name, ENameWesternIdxs *idxs) -{ - - name->suffix = e_name_western_get_suffix_at_str_end (name->full); - - if (name->suffix == NULL) - return; - - idxs->suffix_idx = strlen (name->full) - strlen (name->suffix); -} - -static gboolean -e_name_western_detect_backwards (ENameWestern *name, ENameWesternIdxs *idxs) -{ - char *comma; - char *word; - - comma = strchr (name->full, ','); - - if (comma == NULL) - return FALSE; - - /* - * If there's a comma, we need to detect whether it's - * separating the last name from the first or just separating - * suffixes. So we grab the word which comes before the - * comma and check if it's a suffix. - */ - word = e_name_western_get_preceding_word (name->full, comma - name->full); - - if (e_name_western_word_is_suffix (word)) { - g_free (word); - return FALSE; - } - - g_free (word); - return TRUE; -} - -static void -e_name_western_reorder_asshole (ENameWestern *name, ENameWesternIdxs *idxs) -{ - char *prefix; - char *last; - char *suffix; - char *firstmidnick; - char *newfull; - - char *comma; - char *p; - - if (! e_name_western_detect_backwards (name, idxs)) - return; - - /* - * Convert - * <Prefix> <Last name>, <First name> <Middle[+nick] name> <Suffix> - * to - * <Prefix> <First name> <Middle[+nick] name> <Last name> <Suffix> - */ - - /* - * Grab the prefix from the beginning. - */ - prefix = e_name_western_get_prefix_at_str (name->full); - - /* - * Everything from the end of the prefix to the comma is the - * last name. - */ - comma = strchr (name->full, ','); - if (comma == NULL) - return; - - p = name->full + (prefix == NULL ? 0 : strlen (prefix)); - - while (isspace (*p) && *p != '\0') - p ++; - - last = g_malloc0 (comma - p + 1); - strncpy (last, p, comma - p); - - /* - * Get the suffix off the end. - */ - suffix = e_name_western_get_suffix_at_str_end (name->full); - - /* - * Firstmidnick is everything from the comma to the beginning - * of the suffix. - */ - p = comma + 1; - - while (isspace (*p) && *p != '\0') - p ++; - - if (suffix != NULL) { - char *q; - - /* - * Point q at the beginning of the suffix. - */ - q = name->full + strlen (name->full) - strlen (suffix) - 1; - - /* - * Walk backwards until we hit the space which - * separates the suffix from firstmidnick. - */ - while (! isspace (*q) && q > comma) - q --; - - if ((q - p + 1) > 0) { - firstmidnick = g_malloc0 (q - p + 1); - strncpy (firstmidnick, p, q - p); - } else - firstmidnick = NULL; - } else { - firstmidnick = g_strdup (p); - } - - /* - * Create our new reordered version of the name. - */ -#define NULLSTR(a) ((a) == NULL ? "" : (a)) - newfull = g_strdup_printf ("%s %s %s %s", NULLSTR (prefix), NULLSTR (firstmidnick), - NULLSTR (last), NULLSTR (suffix)); - g_strstrip (newfull); - g_free (name->full); - name->full = newfull; - - - g_free (prefix); - g_free (firstmidnick); - g_free (last); - g_free (suffix); -} - -static void -e_name_western_zap_nil (char **str, int *idx) -{ - if (*str == NULL) - return; - - if (strlen (*str) != 0) - return; - - *idx = -1; - g_free (*str); - *str = NULL; -} - -static void -e_name_western_fixup (ENameWestern *name, ENameWesternIdxs *idxs) -{ - /* - * The middle and last names cannot be the same. - */ - if (idxs->middle_idx != -1 && idxs->middle_idx == idxs->last_idx) { - idxs->middle_idx = -1; - g_free (name->middle); - name->middle = NULL; - } - - /* - * If we have a middle name and no last name, then we mistook - * the last name for the middle name. - */ - if (idxs->last_idx == -1 && idxs->middle_idx != -1) { - idxs->last_idx = idxs->middle_idx; - name->last = name->middle; - name->middle = NULL; - idxs->middle_idx = -1; - } - - /* - * Check to see if we accidentally included the suffix in the - * last name. - */ - if (idxs->suffix_idx != -1 && idxs->last_idx != -1 && - idxs->suffix_idx < (idxs->last_idx + strlen (name->last))) { - char *sfx; - - sfx = name->last + (idxs->suffix_idx - idxs->last_idx); - if (sfx != NULL) { - char *newlast; - char *p; - - p = sfx - 1; - while (isspace (*p) && p > name->last) - p --; - p ++; - - newlast = g_malloc0 (p - name->last + 1); - strncpy (newlast, name->last, p - name->last); - g_free (name->last); - name->last = newlast; - } - } - - /* - * If we have a prefix and a first name, but no last name, - * then we need to assign the first name to the last name. - * This way we get things like "Mr Friedman" correctly. - */ - if (idxs->first_idx != -1 && idxs->prefix_idx != -1 && - idxs->last_idx == -1) { - name->last = name->first; - idxs->last_idx = idxs->first_idx; - idxs->first_idx = -1; - name->first = NULL; - } - - /* - * Remove stray spaces and commas (although there don't seem - * to be any in the test cases, they might show up later). - */ - e_name_western_cleanup_string (& name->prefix); - e_name_western_cleanup_string (& name->first); - e_name_western_cleanup_string (& name->middle); - e_name_western_cleanup_string (& name->nick); - e_name_western_cleanup_string (& name->last); - e_name_western_cleanup_string (& name->suffix); - - /* - * Make zero-length strings just NULL. - */ - e_name_western_zap_nil (& name->prefix, & idxs->prefix_idx); - e_name_western_zap_nil (& name->first, & idxs->first_idx); - e_name_western_zap_nil (& name->middle, & idxs->middle_idx); - e_name_western_zap_nil (& name->nick, & idxs->nick_idx); - e_name_western_zap_nil (& name->last, & idxs->last_idx); - e_name_western_zap_nil (& name->suffix, & idxs->suffix_idx); -} - -/** - * e_name_western_western_parse_fullname: - * @full_name: A string containing a Western name. - * - * Parses @full_name and returns an #ENameWestern object filled with - * the component parts of the name. - */ -ENameWestern * -e_name_western_parse (const char *full_name) -{ - ENameWesternIdxs *idxs; - ENameWestern *wname; - - wname = g_new0 (ENameWestern, 1); - - wname->full = g_strdup (full_name); - - idxs = g_new0 (ENameWesternIdxs, 1); - - idxs->prefix_idx = -1; - idxs->first_idx = -1; - idxs->middle_idx = -1; - idxs->nick_idx = -1; - idxs->last_idx = -1; - idxs->suffix_idx = -1; - - /* - * An extremely simple algorithm. - * - * The goal here is to get it right 95% of the time for - * Western names. - * - * First we check to see if this is an ass-backwards name - * ("Prefix Last, First Middle Suffix"). These names really - * suck (imagine "Dr von Johnson, Albert Roderick Jr"), so - * we reorder them first and then parse them. - * - * Next, we grab the most obvious assignments for the various - * parts of the name. Once this is done, we check for stupid - * errors and fix them up. - */ - e_name_western_reorder_asshole (wname, idxs); - - e_name_western_extract_prefix (wname, idxs); - e_name_western_extract_first (wname, idxs); - e_name_western_extract_nickname (wname, idxs); - e_name_western_extract_middle (wname, idxs); - e_name_western_extract_last (wname, idxs); - e_name_western_extract_suffix (wname, idxs); - - e_name_western_fixup (wname, idxs); - - g_free (idxs); - - return wname; -} - -/** - * e_name_western_free: - * @name: An ENameWestern object which needs to be freed. - * - * Deep-frees @name - */ -void -e_name_western_free (ENameWestern *w) -{ - - g_free (w->prefix); - g_free (w->first); - g_free (w->middle); - g_free (w->nick); - g_free (w->last); - g_free (w->suffix); - - g_free (w->full); - - g_free (w); -} diff --git a/e-util/ename/e-name-western.h b/e-util/ename/e-name-western.h deleted file mode 100644 index fa5bac494c..0000000000 --- a/e-util/ename/e-name-western.h +++ /dev/null @@ -1,21 +0,0 @@ -#ifndef __E_NAME_WESTERN_H__ -#define __E_NAME_WESTERN_H__ - -typedef struct { - - /* Public */ - char *prefix; - char *first; - char *middle; - char *nick; - char *last; - char *suffix; - - /* Private */ - char *full; -} ENameWestern; - -ENameWestern *e_name_western_parse (const char *full_name); -void e_name_western_free (ENameWestern *w); - -#endif /* ! __E_NAME_WESTERN_H__ */ diff --git a/e-util/ename/test-ename-western-gtk.c b/e-util/ename/test-ename-western-gtk.c deleted file mode 100644 index 8ae0ef8770..0000000000 --- a/e-util/ename/test-ename-western-gtk.c +++ /dev/null @@ -1,157 +0,0 @@ -#include <gtk/gtkmain.h> -#include <gtk/gtktable.h> -#include <libgnomeui/gnome-app.h> -#include <libgnomeui/gnome-init.h> -#include <gal/widgets/e-unicode.h> -#include "e-name-western.h" - -ENameWestern *name; -GtkWidget *full; -GtkWidget *prefix; -GtkWidget *first; -GtkWidget *middle; -GtkWidget *nick; -GtkWidget *last; -GtkWidget *suffix; - -static void -fill_entries (void) -{ - -#define SET(a,b) (e_utf8_gtk_entry_set_text (GTK_ENTRY (a), (b) == NULL ? "" : (b))) - SET(prefix, name->prefix); - SET(first, name->first); - SET(middle, name->middle); - SET(nick, name->nick); - SET(last, name->last); - SET(suffix, name->suffix); -} - -static void -full_changed_cb (GtkEntry *fulle) -{ - gchar *str; - - e_name_western_free (name); - str = e_utf8_gtk_entry_get_text (fulle); - name = e_name_western_parse (str); - fill_entries (); - - g_free (str); -} - -static void -create_window (void) -{ - GtkWidget *app; - GtkTable *table; - - GtkWidget *prefix_label; - GtkWidget *first_label; - GtkWidget *middle_label; - GtkWidget *nick_label; - GtkWidget *last_label; - GtkWidget *suffix_label; - - app = gnome_app_new ("test", "Evolution Western Name Parser"); - - table = GTK_TABLE (gtk_table_new (3, 6, FALSE)); - - full = gtk_entry_new (); - prefix = gtk_entry_new (); - first = gtk_entry_new (); - middle = gtk_entry_new (); - nick = gtk_entry_new (); - last = gtk_entry_new (); - suffix = gtk_entry_new (); - - gtk_widget_set_usize (prefix, 100, 0); - gtk_widget_set_usize (first, 100, 0); - gtk_widget_set_usize (middle, 100, 0); - gtk_widget_set_usize (nick, 100, 0); - gtk_widget_set_usize (last, 100, 0); - gtk_widget_set_usize (suffix, 100, 0); - - gtk_table_attach (table, full, 0, 6, 0, 1, - GTK_EXPAND | GTK_FILL, 0, - 0, 0); - - gtk_table_attach (table, prefix, 0, 1, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, first, 1, 2, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, middle, 2, 3, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, nick, 3, 4, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, last, 4, 5, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, suffix, 5, 6, 1, 2, - GTK_EXPAND | GTK_FILL | GTK_SHRINK, 0, - 0, 0); - - prefix_label = gtk_label_new ("Prefix"); - first_label = gtk_label_new ("First"); - middle_label = gtk_label_new ("Middle"); - nick_label = gtk_label_new ("Nick"); - last_label = gtk_label_new ("Last"); - suffix_label = gtk_label_new ("Suffix"); - - gtk_table_attach (table, prefix_label, 0, 1, 2, 3, - GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, first_label, 1, 2, 2, 3, - GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, middle_label, 2, 3, 2, 3, - GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, nick_label, 3, 4, 2, 3, - GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, last_label, 4, 5, 2, 3, - GTK_SHRINK, 0, - 0, 0); - - gtk_table_attach (table, suffix_label, 5, 6, 2, 3, - GTK_SHRINK, 0, - 0, 0); - - gnome_app_set_contents (GNOME_APP (app), GTK_WIDGET (table)); - - gtk_widget_show_all (app); - - gtk_entry_set_text (GTK_ENTRY (full), - "The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire"); - - name = e_name_western_parse ("The Honorable Doctor van Jacobsen, Albert Roderick \"The Clenched Fist\" Jr, MD, PhD, Esquire"); - fill_entries (); - - gtk_signal_connect (GTK_OBJECT (full), "changed", full_changed_cb, NULL); -} - -int -main (int argc, char **argv) -{ - gnome_init ("Test EName", "Test EName", argc, argv); - - create_window (); - - gtk_main (); - - return 0; -} diff --git a/e-util/ename/test-ename-western.c b/e-util/ename/test-ename-western.c deleted file mode 100644 index 09847b5b4b..0000000000 --- a/e-util/ename/test-ename-western.c +++ /dev/null @@ -1,71 +0,0 @@ -#include <ctype.h> -#include <stdio.h> -#include <glib.h> -#include <gtk/gtkmain.h> -#include <ename/e-name-western.h> - -static void -do_name (char *n) -{ - ENameWestern *wname; - - wname = e_name_western_parse (n); - - printf ("Full Name: [%s]\n", n); - - printf ("Prefix: [%s]\n", wname->prefix); - printf ("First: [%s]\n", wname->first); - printf ("Middle: [%s]\n", wname->middle); - printf ("Nick: [%s]\n", wname->nick); - printf ("Last: [%s]\n", wname->last); - printf ("Suffix: [%s]\n", wname->suffix); - - printf ("\n"); - - e_name_western_free (wname); -} - -int -main (int argc, char **argv) -{ - if (argc == 2) { - while (! feof (stdin)) { - char s[256]; - - if (fgets (s, sizeof (s), stdin) == NULL) - return 0; - - g_strstrip (s); - - do_name (s); - } - - return 0; - } - - do_name ("Nat"); - do_name ("Karl Anders Carlsson"); - do_name ("Miguel de Icaza Amozorrutia"); - do_name ("The Honorable Doctor de Icaza, Miguel \"Sparky\" Junior, PhD, MD"); - do_name ("Nat Friedman MD, Phd"); - do_name ("Nat Friedman PhD"); - do_name ("Friedman, Nat"); - do_name ("Miguel de Icaza Esquire"); - do_name ("Dr Miguel \"Sparky\" de Icaza"); - do_name ("Robert H.B. Netzer"); - do_name ("W. Richard Stevens"); - do_name ("Nat Friedman"); - do_name ("N. Friedman"); - do_name ("Miguel de Icaza"); - do_name ("Drew Johnson"); - do_name ("President Bill \"Slick Willy\" Clinton"); - do_name ("The Honorable Mark J. Einstein Jr"); - do_name ("Friedman, Nat"); - do_name ("de Icaza, Miguel"); - do_name ("Mr de Icaza, Miguel"); - do_name ("Smith, John Jr"); - do_name ("Nick Glennie-Smith"); - do_name ("Dr von Johnson, Albert Roderick Jr"); - - return 0; -} diff --git a/e-util/md5-utils.c b/e-util/md5-utils.c deleted file mode 100644 index 368a3c1828..0000000000 --- a/e-util/md5-utils.c +++ /dev/null @@ -1,362 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to md5_init, call md5_update as - * needed on buffers full of bytes, and then call md5_Final, which - * will fill a supplied 16-byte array with the digest. - */ - -/* parts of this file are : - * Written March 1993 by Branko Lankester - * Modified June 1993 by Colin Plumb for altered md5.c. - * Modified October 1995 by Erik Troan for RPM - */ - - -#include <stdio.h> -#include <string.h> -#include "md5-utils.h" - -static void md5_transform (guint32 buf[4], const guint32 in[16]); - -static gint _ie = 0x44332211; -static union _endian { gint i; gchar b[4]; } *_endian = (union _endian *)&_ie; -#define IS_BIG_ENDIAN() (_endian->b[0] == '\x44') -#define IS_LITTLE_ENDIAN() (_endian->b[0] == '\x11') - - -/* - * Note: this code is harmless on little-endian machines. - */ -static void -_byte_reverse (guchar *buf, guint32 longs) -{ - guint32 t; - do { - t = (guint32) ((guint32) buf[3] << 8 | buf[2]) << 16 | - ((guint32) buf[1] << 8 | buf[0]); - *(guint32 *) buf = t; - buf += 4; - } while (--longs); -} - -/** - * md5_init: Initialise an md5 context object - * @ctx: md5 context - * - * Initialise an md5 buffer. - * - **/ -void -md5_init (MD5Context *ctx) -{ - ctx->buf[0] = 0x67452301; - ctx->buf[1] = 0xefcdab89; - ctx->buf[2] = 0x98badcfe; - ctx->buf[3] = 0x10325476; - - ctx->bits[0] = 0; - ctx->bits[1] = 0; - - if (IS_BIG_ENDIAN()) - ctx->doByteReverse = 1; - else - ctx->doByteReverse = 0; -} - - - -/** - * md5_update: add a buffer to md5 hash computation - * @ctx: conetxt object used for md5 computaion - * @buf: buffer to add - * @len: buffer length - * - * Update context to reflect the concatenation of another buffer full - * of bytes. Use this to progressively construct an md5 hash. - **/ -void -md5_update (MD5Context *ctx, const guchar *buf, guint32 len) -{ - guint32 t; - - /* Update bitcount */ - - t = ctx->bits[0]; - if ((ctx->bits[0] = t + ((guint32) len << 3)) < t) - ctx->bits[1]++; /* Carry from low to high */ - ctx->bits[1] += len >> 29; - - t = (t >> 3) & 0x3f; /* Bytes already in shsInfo->data */ - - /* Handle any leading odd-sized chunks */ - - if (t) { - guchar *p = (guchar *) ctx->in + t; - - t = 64 - t; - if (len < t) { - memcpy (p, buf, len); - return; - } - memcpy (p, buf, t); - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 16); - md5_transform (ctx->buf, (guint32 *) ctx->in); - buf += t; - len -= t; - } - /* Process data in 64-byte chunks */ - - while (len >= 64) { - memcpy (ctx->in, buf, 64); - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 16); - md5_transform (ctx->buf, (guint32 *) ctx->in); - buf += 64; - len -= 64; - } - - /* Handle any remaining bytes of data. */ - - memcpy (ctx->in, buf, len); -} - - - - - -/* - * Final wrapup - pad to 64-byte boundary with the bit pattern - * 1 0* (64-bit count of bits processed, MSB-first) - */ -/** - * md5_final: copy the final md5 hash to a bufer - * @digest: 16 bytes buffer - * @ctx: context containing the calculated md5 - * - * copy the final md5 hash to a bufer - **/ -void -md5_final (MD5Context *ctx, guchar digest[16]) -{ - guint32 count; - guchar *p; - - /* Compute number of bytes mod 64 */ - count = (ctx->bits[0] >> 3) & 0x3F; - - /* Set the first char of padding to 0x80. This is safe since there is - always at least one byte free */ - p = ctx->in + count; - *p++ = 0x80; - - /* Bytes of padding needed to make 64 bytes */ - count = 64 - 1 - count; - - /* Pad out to 56 mod 64 */ - if (count < 8) { - /* Two lots of padding: Pad the first block to 64 bytes */ - memset (p, 0, count); - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 16); - md5_transform (ctx->buf, (guint32 *) ctx->in); - - /* Now fill the next block with 56 bytes */ - memset (ctx->in, 0, 56); - } else { - /* Pad block to 56 bytes */ - memset (p, 0, count - 8); - } - if (ctx->doByteReverse) - _byte_reverse (ctx->in, 14); - - /* Append length in bits and transform */ - ((guint32 *) ctx->in)[14] = ctx->bits[0]; - ((guint32 *) ctx->in)[15] = ctx->bits[1]; - - md5_transform (ctx->buf, (guint32 *) ctx->in); - if (ctx->doByteReverse) - _byte_reverse ((guchar *) ctx->buf, 4); - memcpy (digest, ctx->buf, 16); -} - - - - -/* The four core functions - F1 is optimized somewhat */ - -/* #define F1(x, y, z) (x & y | ~x & z) */ -#define F1(x, y, z) (z ^ (x & (y ^ z))) -#define F2(x, y, z) F1(z, x, y) -#define F3(x, y, z) (x ^ y ^ z) -#define F4(x, y, z) (y ^ (x | ~z)) - -/* This is the central step in the MD5 algorithm. */ -#define MD5STEP(f, w, x, y, z, data, s) \ - ( w += f(x, y, z) + data, w = w<<s | w>>(32-s), w += x ) - -/* - * The core of the MD5 algorithm, this alters an existing MD5 hash to - * reflect the addition of 16 longwords of new data. md5_Update blocks - * the data and converts bytes into longwords for this routine. - */ -static void -md5_transform (guint32 buf[4], const guint32 in[16]) -{ - register guint32 a, b, c, d; - - a = buf[0]; - b = buf[1]; - c = buf[2]; - d = buf[3]; - - MD5STEP (F1, a, b, c, d, in[0] + 0xd76aa478, 7); - MD5STEP (F1, d, a, b, c, in[1] + 0xe8c7b756, 12); - MD5STEP (F1, c, d, a, b, in[2] + 0x242070db, 17); - MD5STEP (F1, b, c, d, a, in[3] + 0xc1bdceee, 22); - MD5STEP (F1, a, b, c, d, in[4] + 0xf57c0faf, 7); - MD5STEP (F1, d, a, b, c, in[5] + 0x4787c62a, 12); - MD5STEP (F1, c, d, a, b, in[6] + 0xa8304613, 17); - MD5STEP (F1, b, c, d, a, in[7] + 0xfd469501, 22); - MD5STEP (F1, a, b, c, d, in[8] + 0x698098d8, 7); - MD5STEP (F1, d, a, b, c, in[9] + 0x8b44f7af, 12); - MD5STEP (F1, c, d, a, b, in[10] + 0xffff5bb1, 17); - MD5STEP (F1, b, c, d, a, in[11] + 0x895cd7be, 22); - MD5STEP (F1, a, b, c, d, in[12] + 0x6b901122, 7); - MD5STEP (F1, d, a, b, c, in[13] + 0xfd987193, 12); - MD5STEP (F1, c, d, a, b, in[14] + 0xa679438e, 17); - MD5STEP (F1, b, c, d, a, in[15] + 0x49b40821, 22); - - MD5STEP (F2, a, b, c, d, in[1] + 0xf61e2562, 5); - MD5STEP (F2, d, a, b, c, in[6] + 0xc040b340, 9); - MD5STEP (F2, c, d, a, b, in[11] + 0x265e5a51, 14); - MD5STEP (F2, b, c, d, a, in[0] + 0xe9b6c7aa, 20); - MD5STEP (F2, a, b, c, d, in[5] + 0xd62f105d, 5); - MD5STEP (F2, d, a, b, c, in[10] + 0x02441453, 9); - MD5STEP (F2, c, d, a, b, in[15] + 0xd8a1e681, 14); - MD5STEP (F2, b, c, d, a, in[4] + 0xe7d3fbc8, 20); - MD5STEP (F2, a, b, c, d, in[9] + 0x21e1cde6, 5); - MD5STEP (F2, d, a, b, c, in[14] + 0xc33707d6, 9); - MD5STEP (F2, c, d, a, b, in[3] + 0xf4d50d87, 14); - MD5STEP (F2, b, c, d, a, in[8] + 0x455a14ed, 20); - MD5STEP (F2, a, b, c, d, in[13] + 0xa9e3e905, 5); - MD5STEP (F2, d, a, b, c, in[2] + 0xfcefa3f8, 9); - MD5STEP (F2, c, d, a, b, in[7] + 0x676f02d9, 14); - MD5STEP (F2, b, c, d, a, in[12] + 0x8d2a4c8a, 20); - - MD5STEP (F3, a, b, c, d, in[5] + 0xfffa3942, 4); - MD5STEP (F3, d, a, b, c, in[8] + 0x8771f681, 11); - MD5STEP (F3, c, d, a, b, in[11] + 0x6d9d6122, 16); - MD5STEP (F3, b, c, d, a, in[14] + 0xfde5380c, 23); - MD5STEP (F3, a, b, c, d, in[1] + 0xa4beea44, 4); - MD5STEP (F3, d, a, b, c, in[4] + 0x4bdecfa9, 11); - MD5STEP (F3, c, d, a, b, in[7] + 0xf6bb4b60, 16); - MD5STEP (F3, b, c, d, a, in[10] + 0xbebfbc70, 23); - MD5STEP (F3, a, b, c, d, in[13] + 0x289b7ec6, 4); - MD5STEP (F3, d, a, b, c, in[0] + 0xeaa127fa, 11); - MD5STEP (F3, c, d, a, b, in[3] + 0xd4ef3085, 16); - MD5STEP (F3, b, c, d, a, in[6] + 0x04881d05, 23); - MD5STEP (F3, a, b, c, d, in[9] + 0xd9d4d039, 4); - MD5STEP (F3, d, a, b, c, in[12] + 0xe6db99e5, 11); - MD5STEP (F3, c, d, a, b, in[15] + 0x1fa27cf8, 16); - MD5STEP (F3, b, c, d, a, in[2] + 0xc4ac5665, 23); - - MD5STEP (F4, a, b, c, d, in[0] + 0xf4292244, 6); - MD5STEP (F4, d, a, b, c, in[7] + 0x432aff97, 10); - MD5STEP (F4, c, d, a, b, in[14] + 0xab9423a7, 15); - MD5STEP (F4, b, c, d, a, in[5] + 0xfc93a039, 21); - MD5STEP (F4, a, b, c, d, in[12] + 0x655b59c3, 6); - MD5STEP (F4, d, a, b, c, in[3] + 0x8f0ccc92, 10); - MD5STEP (F4, c, d, a, b, in[10] + 0xffeff47d, 15); - MD5STEP (F4, b, c, d, a, in[1] + 0x85845dd1, 21); - MD5STEP (F4, a, b, c, d, in[8] + 0x6fa87e4f, 6); - MD5STEP (F4, d, a, b, c, in[15] + 0xfe2ce6e0, 10); - MD5STEP (F4, c, d, a, b, in[6] + 0xa3014314, 15); - MD5STEP (F4, b, c, d, a, in[13] + 0x4e0811a1, 21); - MD5STEP (F4, a, b, c, d, in[4] + 0xf7537e82, 6); - MD5STEP (F4, d, a, b, c, in[11] + 0xbd3af235, 10); - MD5STEP (F4, c, d, a, b, in[2] + 0x2ad7d2bb, 15); - MD5STEP (F4, b, c, d, a, in[9] + 0xeb86d391, 21); - - buf[0] += a; - buf[1] += b; - buf[2] += c; - buf[3] += d; -} - - - - -/** - * md5_get_digest: get the md5 hash of a buffer - * @buffer: byte buffer - * @buffer_size: buffer size (in bytes) - * @digest: 16 bytes buffer receiving the hash code. - * - * Get the md5 hash of a buffer. The result is put in - * the 16 bytes buffer @digest . - **/ -void -md5_get_digest (const gchar *buffer, gint buffer_size, guchar digest[16]) -{ - MD5Context ctx; - - md5_init (&ctx); - md5_update (&ctx, buffer, buffer_size); - md5_final (&ctx, digest); - -} - - -/** - * md5_get_digest_from_file: get the md5 hash of a file - * @filename: file name - * @digest: 16 bytes buffer receiving the hash code. - * - * Get the md5 hash of a file. The result is put in - * the 16 bytes buffer @digest . - **/ -void -md5_get_digest_from_file (const gchar *filename, guchar digest[16]) -{ - MD5Context ctx; - guchar tmp_buf[1024]; - gint nb_bytes_read; - FILE *fp; - - printf("generating checksum\n"); - - md5_init (&ctx); - fp = fopen(filename, "r"); - if (!fp) { - return; - } - - while ((nb_bytes_read = fread (tmp_buf, sizeof (guchar), 1024, fp)) > 0) - md5_update (&ctx, tmp_buf, nb_bytes_read); - - if (ferror(fp)) { - fclose(fp); - return; - } - - - md5_final (&ctx, digest); - - printf("checksum done\n"); -} - - - - diff --git a/e-util/md5-utils.h b/e-util/md5-utils.h deleted file mode 100644 index 08e014e86e..0000000000 --- a/e-util/md5-utils.h +++ /dev/null @@ -1,52 +0,0 @@ -/* -*- Mode: C; tab-width: 8; indent-tabs-mode: t; c-basic-offset: 8 -*- */ -/* - * This code implements the MD5 message-digest algorithm. - * The algorithm is due to Ron Rivest. This code was - * written by Colin Plumb in 1993, no copyright is claimed. - * This code is in the public domain; do with it what you wish. - * - * Equivalent code is available from RSA Data Security, Inc. - * This code has been tested against that, and is equivalent, - * except that you don't need to include two pages of legalese - * with every copy. - * - * To compute the message digest of a chunk of bytes, declare an - * MD5Context structure, pass it to rpmMD5Init, call rpmMD5Update as - * needed on buffers full of bytes, and then call rpmMD5Final, which - * will fill a supplied 16-byte array with the digest. - */ - -/* parts of this file are : - * Written March 1993 by Branko Lankester - * Modified June 1993 by Colin Plumb for altered md5.c. - * Modified October 1995 by Erik Troan for RPM - */ - - -#ifndef MD5_UTILS_H -#define MD5_UTILS_H - -#include <glib.h> - -typedef struct { - guint32 buf[4]; - guint32 bits[2]; - guchar in[64]; - gint doByteReverse; - -} MD5Context ; - - -void md5_get_digest (const gchar *buffer, gint buffer_size, guchar digest[16]); - -/* use this one when speed is needed */ -/* for use in provider code only */ -void md5_get_digest_from_file (const gchar *filename, guchar digest[16]); - -/* raw routines */ -void md5_init (MD5Context *ctx); -void md5_update (MD5Context *ctx, const guchar *buf, guint32 len); -void md5_final (MD5Context *ctx, guchar digest[16]); - - -#endif /* MD5_UTILS_H */ |