Ticket #3972: aliases.patch
File aliases.patch, 7.0 KB (added by zaytsev, 2 months ago) |
---|
-
lib/charsets.c
diff --git a/lib/charsets.c b/lib/charsets.c index 0df5ecb21..5b1e3f386 100644
a b 33 33 #include <stdlib.h> 34 34 #include <string.h> 35 35 36 #include <gio/gio.h> 37 36 38 #include "lib/global.h" 37 39 #include "lib/strutil.h" /* utf-8 functions */ 38 40 #include "lib/fileloc.h" … … free_codepage_desc (gpointer data) 96 98 static void 97 99 load_codepages_list_from_file (GPtrArray **list, const char *fname) 98 100 { 99 FILE *f; 100 char buf[BUF_MEDIUM]; 101 char *default_codepage = NULL; 101 GFile *fp = g_file_new_for_path (fname); // never fails 102 GFileInputStream *input_stream = g_file_read (fp, NULL, NULL); 103 GDataInputStream *data_input_stream = NULL; 104 105 if (input_stream == NULL) 106 goto cleanup; 102 107 103 f = fopen (fname, "r");104 if ( f== NULL)105 return;108 data_input_stream = g_data_input_stream_new (G_INPUT_STREAM (input_stream)); 109 if (data_input_stream == NULL) 110 goto cleanup; 106 111 107 while ( fgets (buf, sizeof buf, f) != NULL)112 while (TRUE) 108 113 { 109 /* split string into id and cpname */ 110 char *p = buf; 111 size_t buflen; 112 113 if (*p == '\n' || *p == '\0' || *p == '#') 114 continue; 115 116 buflen = strlen (buf); 117 118 if (buflen != 0 && buf[buflen - 1] == '\n') 119 buf[buflen - 1] = '\0'; 120 while (*p != '\0' && !whitespace (*p)) 121 ++p; 122 if (*p == '\0') 123 goto fail; 124 125 *p++ = '\0'; 126 g_strstrip (p); 127 if (*p == '\0') 128 goto fail; 129 130 if (strcmp (buf, "default") == 0) 131 default_codepage = g_strdup (p); 132 else 114 gchar **key_value = NULL; 115 gchar **keys = NULL; 116 GPtrArray *encodings = NULL; 117 gsize j = 0, i = 0, size; 118 GError *error = NULL; 119 gchar *line = g_data_input_stream_read_line (data_input_stream, &size, NULL, &error); 120 121 if (line == NULL) 133 122 { 134 const char *id = buf; 123 // error handling - error->message 124 if (error != NULL) 125 g_error_free (error); 126 break; 127 } 135 128 136 if (*list == NULL) 137 { 138 *list = g_ptr_array_new_full (16, free_codepage_desc); 139 g_ptr_array_add (*list, new_codepage_desc (id, p)); 140 } 141 else 129 if (*line == '\n' || *line == '\0' || *line == '#') 130 goto next_line; 131 132 key_value = g_strsplit_set (line, " \t", 2); 133 if (key_value == NULL || g_strv_length (key_value) != 2) 134 goto next_line; 135 136 keys = g_strsplit (key_value[0], ",", -1); 137 if (keys == NULL || g_strv_length (keys) < 1) 138 goto next_line; 139 140 encodings = g_ptr_array_new_full (1, g_free); 141 for (i = 0; i < g_strv_length (keys); i++) 142 { 143 char *id = g_strstrip (g_strdup (keys[i])); 144 if (*id != '\0') 145 g_ptr_array_add (encodings, id); 146 } 147 148 if (encodings->len < 1) 149 goto next_line; 150 151 if (*list == NULL) 152 *list = g_ptr_array_new_full (16, free_codepage_desc); 153 154 155 for (i = 0; i < encodings->len; i++) 156 { 157 gchar *id = g_strdup (g_ptr_array_index (encodings, i)); 158 gchar *description = 159 g_strdup_printf ("%s (%s)", g_strstrip (g_strdup (key_value[1])), id); 160 161 /* whether id is already present in list */ 162 /* if yes, overwrite description */ 163 for (j = 0; j < (*list)->len; j++) 142 164 { 143 unsigned int i;165 codepage_desc *desc = g_ptr_array_index (*list, j); 144 166 145 /* whether id is already present in list */ 146 /* if yes, overwrite description */ 147 for (i = 0; i < (*list)->len; i++) 167 /* found */ 168 if (strcmp (id, desc->id) == 0) 148 169 { 149 codepage_desc *desc; 170 g_free (desc->name); 171 desc->name = g_strdup (description); 172 break; 173 } 174 } 150 175 151 desc = (codepage_desc *) g_ptr_array_index (*list, i); 176 /* not found */ 177 if (j == (*list)->len) 178 g_ptr_array_add (*list, new_codepage_desc (id, description)); 152 179 153 if (strcmp (id, desc->id) == 0) 154 { 155 /* found */ 156 g_free (desc->name); 157 desc->name = g_strdup (p); 158 break; 159 } 160 } 180 g_free (id); 181 g_free (description); 161 182 162 /* not found */ 163 if (i == (*list)->len) 164 g_ptr_array_add (*list, new_codepage_desc (id, p)); 165 } 183 184 next_line: 185 g_strfreev (keys); 186 g_strfreev (key_value); 187 g_free (line); 166 188 } 167 }168 189 169 if (default_codepage != NULL)170 {171 mc_global.display_codepage = get_codepage_index (default_codepage);172 g_free (default_codepage);173 190 } 174 191 175 fail: 176 fclose (f); 192 193 cleanup: 194 #define g_object_unref_maybe_null(ptr) if (ptr != NULL) g_object_unref(ptr); 195 g_object_unref_maybe_null (data_input_stream); 196 g_object_unref_maybe_null (input_stream); 197 g_object_unref_maybe_null (fp); 198 #undef g_object_unref_maybe_null 199 177 200 } 178 201 179 202 /* --------------------------------------------------------------------------------------------- */ -
m4.include/mc-glib.m4
diff --git a/m4.include/mc-glib.m4 b/m4.include/mc-glib.m4 index f93962f0e..2830ec573 100644
a b AC_DEFUN([mc_G_MODULE_SUPPORTED], [ 8 8 g_module_supported="" 9 9 10 10 found_gmodule=no 11 PKG_CHECK_MODULES(GMODULE, [gmodule-no-export-2.0 >= 2.32 ], [found_gmodule=yes], [:])11 PKG_CHECK_MODULES(GMODULE, [gmodule-no-export-2.0 >= 2.32 gio-2.0], [found_gmodule=yes], [:]) 12 12 if test x"$found_gmodule" = xyes; then 13 13 g_module_supported="gmodule-no-export-2.0" 14 14 else 15 15 dnl try fallback to the generic gmodule 16 PKG_CHECK_MODULES(GMODULE, [gmodule-2.0 >= 2.32 ], [found_gmodule=yes], [:])16 PKG_CHECK_MODULES(GMODULE, [gmodule-2.0 >= 2.32 gio-2.0], [found_gmodule=yes], [:]) 17 17 if test x"$found_gmodule" = xyes; then 18 18 g_module_supported="gmodule-2.0" 19 19 fi … … AC_DEFUN([mc_G_MODULE_SUPPORTED], [ 43 43 lib=glib ;; 44 44 x-lgmodule*) 45 45 lib=gmodule ;; 46 x-lgio*) 47 lib=gio ;; 46 48 *) 47 49 lib= 48 50 add="$i" ;; … … AC_DEFUN([mc_CHECK_GLIB], [ 78 80 AS_HELP_STRING([--with-glib-static], [Link glib statically @<:@no@:>@])) 79 81 80 82 glib_found=no 81 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.32 ], [glib_found=yes], [:])83 PKG_CHECK_MODULES(GLIB, [glib-2.0 >= 2.32 gio-2.0], [glib_found=yes], [:]) 82 84 if test x"$glib_found" = xno; then 83 85 AC_MSG_ERROR([glib-2.0 not found or version too old (must be >= 2.32)]) 84 86 fi