1 /* Bluefish HTML Editor 2 * bf_lib.h - non-GUI general functions 3 * 4 * Copyright (C) 2000-2004 Olivier Sessink 5 * 6 * This program is free software; you can redistribute it and/or modify 7 * it under the terms of the GNU General Public License as published by 8 * the Free Software Foundation; either version 3 of the License, or 9 * (at your option) any later version. 10 * 11 * This program is distributed in the hope that it will be useful, 12 * but WITHOUT ANY WARRANTY; without even the implied warranty of 13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the 14 * GNU General Public License for more details. 15 * 16 * You should have received a copy of the GNU General Public License 17 * along with this program. If not, see <http://www.gnu.org/licenses/>. 18 */ 19 20 #ifndef __BF_LIB_H_ 21 #define __BF_LIB_H_ 22 23 #include <time.h> /* for time_t */ 24 25 typedef struct { 26 gint my_int; 27 gchar *my_char; 28 } Tconvert_table; 29 30 typedef enum { 31 tcc2i_full_match = 0, 32 tcc2i_firstchar, 33 tcc2i_mycharlen, 34 tcc2i_full_match_gettext 35 } Ttcc2i_mode; 36 37 typedef struct { 38 gpointer data; 39 gint count; 40 } Trefcpointer; 41 42 /* #define REFP_DEBUG */ 43 Trefcpointer *refcpointer_new(gpointer data); 44 #ifdef REFP_DEBUG 45 void refcpointer_ref(Trefcpointer *rp); 46 #else 47 #define refcpointer_ref(rp) rp->count++ 48 #endif 49 void refcpointer_unref(Trefcpointer *rp); 50 51 /*GFile *add_suffix_to_uri(GFile *file, const char *suffix);*/ 52 /*const gchar *full_path_utf8_from_uri(GFile *uri);*/ 53 /*gchar *filename_utf8_from_uri(GFile *uri);*/ 54 /*gchar *get_utf8filename_from_on_disk_encoding(const gchar *encodedname);*/ 55 56 gchar *mime_with_extension(const gchar *mimetype, const gchar *filename); 57 58 GList *urilist_to_stringlist(GList *urilist); 59 void free_urilist(GList *urilist); 60 #if GTK_CHECK_VERSION(2,14,0) 61 #else 62 GFile *gtk_file_chooser_get_file(GtkFileChooser *chooser); 63 #endif 64 /*#define user_bfdir(file) g_strconcat(g_get_home_dir(), "/."PACKAGE"/", file, NULL)*/ 65 GFile *user_bfdir(const gchar *filename); 66 67 gchar *filename_utf8_from_full_path_utf8(const gchar *full_path_utf8); 68 69 gchar *get_filename_on_disk_encoding(const gchar *utf8filename); 70 71 gboolean string_is_color(const gchar *color); 72 73 #include <sys/types.h> 74 #include <sys/stat.h> 75 #include <unistd.h> 76 gchar *filemode_to_string(mode_t statmode); 77 /*gchar *return_root_with_protocol(const gchar *url);*/ 78 void pointer_switch_addresses(gpointer *a, gpointer *b); 79 void list_switch_order(GList *first, GList *second); 80 gboolean file_copy(gchar *source, gchar *dest); 81 /*gint find_common_prefixlen_in_stringlist(GList *stringlist);*/ 82 /*guint countchars(const gchar *string, const gchar *chars);*/ 83 gint table_convert_char2int(Tconvert_table *table, const gchar *my_char, Ttcc2i_mode mode); 84 gchar *table_convert_int2char(Tconvert_table *table, gint my_int); 85 gchar *expand_string(const gchar *string, const char specialchar, Tconvert_table *table); 86 gchar *unexpand_string(const gchar *original, const char specialchar, Tconvert_table *table); 87 gchar *replace_string_printflike(const gchar *string, Tconvert_table *table); 88 gchar *unescape_string(const gchar *original, gboolean escape_colon); 89 gchar *escape_string(const gchar *original, gboolean escape_colon); 90 Tconvert_table *new_convert_table(gint size, gboolean fill_standardescape); 91 void free_convert_table(Tconvert_table *tct); 92 93 #define utf8_byteoffset_to_charsoffset(string,byteoffset) g_utf8_pointer_to_offset(string, string+byteoffset) 94 /*glong utf8_byteoffset_to_charsoffset(gchar *string, glong byteoffset);*/ 95 void utf8_offset_cache_reset(); 96 guint utf8_charoffset_to_byteoffset_cached(const gchar *string, guint charoffset); 97 guint utf8_byteoffset_to_charsoffset_cached(const gchar *string, glong byteoffset); 98 99 gchar *strip_any_whitespace(gchar *string); 100 gchar *trunc_on_char(gchar * string, gchar which_char); 101 /*gchar *strip_common_path(char *to_filename, char *from_filename);*/ 102 gchar *most_efficient_filename(gchar *filename); 103 gchar *create_relative_link_to(const gchar * current_filepath, const gchar * link_to_filepath); 104 105 gchar *strip_trailing_slash(gchar *input); 106 gchar *ending_slash(const gchar *dirname); 107 /*gchar *path_get_dirname_with_ending_slash(const gchar *filename);*/ 108 /*gboolean full_path_exists(const gchar *full_path);*/ 109 /*gboolean file_exists_and_readable(const gchar * filename);*/ 110 GFile *return_first_existing_filename(const gchar * filename, ...); 111 /*gboolean filename_test_extensions(gchar **extensions, const gchar *filename);*/ 112 gchar *bf_str_repeat(const gchar * str, gint number_of); 113 gint get_int_from_string(const gchar *string); 114 gchar *unique_path(const gchar *basedir, const gchar *prefix, GHashTable *excludehash); 115 gchar *create_secure_dir_return_filename(void); 116 /*void remove_secure_dir_and_filename(gchar *filename);*/ 117 /*gchar *buf_replace_char(gchar *buf, gint len, gchar srcchar, gchar destchar);*/ 118 void wordcount(gchar *text, guint *chars, guint *lines, guint *words); 119 /*GSList *gslist_from_glist_reversed(GList *src);*/ 120 GList *glist_from_gslist(GSList *src); 121 gchar *bf_portable_time(const time_t *timep); 122 123 gboolean arr3_equal (gconstpointer v1,gconstpointer v2); 124 guint arr3_hash(gconstpointer v); 125 gchar *gfile_display_name(GFile *uri,GFileInfo *finfo); 126 gboolean gfile_uri_is_parent(GFile *parent, GFile *child, gboolean recursive); 127 gchar *get_hostname_from_uri(GFile *uri); 128 GList *scan_dir_for_files(const gchar * dir, const gchar *patspec); 129 typedef struct { 130 void (*func)(); 131 gpointer data; 132 } Tcallback; 133 void callback_register(GSList **slist, void (*func)(), gpointer data); 134 void callback_remove_by_data(GSList **slist, gpointer data); 135 void callback_remove_all(GSList **slist); 136 137 #define BF_ELIST_HEAD gpointer next, prev 138 typedef struct { 139 BF_ELIST_HEAD; 140 } Telist; 141 #define BF_ELIST(var) ((Telist *)var) 142 #define bf_elist_next(var) (var)->next 143 #define bf_elist_prev(var) (var)->prev 144 145 Telist * bf_elist_prepend(gpointer cur, gpointer new); 146 Telist * bf_elist_append(gpointer cur, gpointer new); 147 Telist * bf_elist_first(gpointer cur); 148 Telist * bf_elist_last(gpointer cur); 149 Telist * bf_elist_remove(gpointer toremove); 150 151 void print_character_escaped(gunichar uc); 152 153 #endif /* __BF_LIB_H_ */ 154 155