Mercurial > gftp.yaz
diff lib/config_file.c @ 227:a85a097bbb02
2003-7-20 Brian Masney <masneyb@gftp.org>
* lib/config_file.c lib/gftp.h - added compare_function to
gftp_config_vars structure. (gftp_set_global_option) use the compare
function to see if the value was actually changed, and if so set the
gftp_configuration_changed variable
* lib/misc.c lib/gftp.h - For glib 1.2, added my version of
g_build_path() since it's not there
* lib/misc.c - GLIB/GTK+ 1.2 fixes
* lib/protocols.c (gftp_fd_open) - cleaned up some
* lib/rfc959.c (rfc959_init) - if the email address is blank, get the
users address here instead of in register_module. It was being blanked
out when the config file was being read
* lib/options.h lib/rfc2068.c lib/rfc959.c lib/sshv2.c - mark the
config variables that can show up in the bookmarks editor
* src/text/gftp-text.c src/gtk/options_dialog.c - use
gftp_set_global_option() to set the new configuration values
* src/gtk/bookmarks.c - fixed crash in bookmarks dialog. Added notebook
widget to the dialog as well. The options that can be edited for this
site will show up in other tabs
* src/gtk/gftp-gtk.c - fixes to the calls to gftp_set_global_option()
* src/gtk/options_dialog.c - added gftp_gtk_setup_bookmark_options()
to display all the editable options for this bookmark
author | masneyb |
---|---|
date | Mon, 21 Jul 2003 00:26:43 +0000 |
parents | de6a2e8e51cb |
children | 35ae2e80962e |
line wrap: on
line diff
--- a/lib/config_file.c Mon Jul 21 00:22:46 2003 +0000 +++ b/lib/config_file.c Mon Jul 21 00:26:43 2003 +0000 @@ -935,6 +935,25 @@ } +static int +gftp_config_file_compare_text (gftp_config_vars * cv1, gftp_config_vars * cv2) +{ + char *str1, *str2; + + str1 = cv1->value; + str2 = cv2->value; + + if (cv1->value == NULL && cv2->value == NULL) + return (0); + + if ((cv1->value == NULL && cv2->value != NULL) || + (cv1->value != NULL && cv2->value == NULL)) + return (-1); + + return (strcmp (str1, str2)); +} + + static void gftp_config_file_copy_ptr_contents (gftp_config_vars * cv, gftp_config_vars * dest_cv) { @@ -958,6 +977,13 @@ static int +gftp_config_file_compare_int (gftp_config_vars * cv1, gftp_config_vars * cv2) +{ + return (GPOINTER_TO_INT(cv1->value) == GPOINTER_TO_INT(cv2->value) ? 0 : -1); +} + + +static int gftp_config_file_read_checkbox (char *str, gftp_config_vars * cv, int line) { cv->value = GINT_TO_POINTER(strtol (str, NULL, 10) ? 1 : 0); @@ -988,6 +1014,17 @@ static int +gftp_config_file_compare_float (gftp_config_vars * cv1, gftp_config_vars * cv2) +{ + float f1, f2; + + memcpy (&f1, &cv1->value, sizeof (f1)); + memcpy (&f2, &cv2->value, sizeof (f2)); + return (f1 == f2 ? 0 : -1); +} + + +static int gftp_config_file_read_color (char *str, gftp_config_vars * cv, int line) { char *red, *green, *blue; @@ -1037,6 +1074,19 @@ static int +gftp_config_file_compare_color (gftp_config_vars * cv1, gftp_config_vars * cv2) +{ + gftp_color * color1, * color2; + + color1 = cv1->value; + color2 = cv2->value; + + return (color1->red == color2->red && color1->green == color2->green && + color1->blue == color2->blue ? 0 : -1); +} + + +static int gftp_config_file_read_intcombo (char *str, gftp_config_vars * cv, int line) { char **clist; @@ -1102,17 +1152,31 @@ /* Note, the index numbers of this array must match up to the numbers in gftp_option_type_enum in gftp.h */ gftp_option_type_var gftp_option_types[] = { - {gftp_config_file_read_text, gftp_config_file_write_text, gftp_config_file_copy_text, NULL, NULL, NULL}, - {gftp_config_file_read_textcombo, gftp_config_file_write_text, gftp_config_file_copy_text, NULL, NULL, NULL}, - {gftp_config_file_read_text, gftp_config_file_write_text, gftp_config_file_copy_text, NULL, NULL, NULL}, - {gftp_config_file_read_text, gftp_config_file_write_hidetext, gftp_config_file_copy_text, NULL, NULL, NULL}, - {gftp_config_file_read_int, gftp_config_file_write_int, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL}, - {gftp_config_file_read_checkbox, gftp_config_file_write_int, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL}, - {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL}, - {gftp_config_file_read_float, gftp_config_file_write_float, gftp_config_file_copy_ptr_contents, NULL, NULL, NULL}, - {gftp_config_file_read_color, gftp_config_file_write_color, gftp_config_file_copy_color, NULL, NULL, NULL}, - {NULL, NULL, NULL, NULL, NULL}, - {NULL, NULL, NULL, NULL, NULL} + {gftp_config_file_read_text, gftp_config_file_write_text, + gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL}, + {gftp_config_file_read_textcombo, gftp_config_file_write_text, + gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL}, + {gftp_config_file_read_text, gftp_config_file_write_text, + gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL}, + {gftp_config_file_read_text, gftp_config_file_write_hidetext, + gftp_config_file_copy_text, gftp_config_file_compare_text, NULL, NULL, NULL}, + {gftp_config_file_read_int, gftp_config_file_write_int, + gftp_config_file_copy_ptr_contents, gftp_config_file_compare_int, + NULL, NULL, NULL}, + {gftp_config_file_read_checkbox, gftp_config_file_write_int, + gftp_config_file_copy_ptr_contents, gftp_config_file_compare_int, + NULL, NULL, NULL}, + {gftp_config_file_read_intcombo, gftp_config_file_write_intcombo, + gftp_config_file_copy_ptr_contents, gftp_config_file_compare_int, + NULL, NULL, NULL}, + {gftp_config_file_read_float, gftp_config_file_write_float, + gftp_config_file_copy_ptr_contents, gftp_config_file_compare_float, + NULL, NULL, NULL}, + {gftp_config_file_read_color, gftp_config_file_write_color, + gftp_config_file_copy_color, gftp_config_file_compare_color, + NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL}, + {NULL, NULL, NULL, NULL, NULL, NULL} }; @@ -1152,18 +1216,29 @@ void -gftp_set_global_option (char * key, void *value) +gftp_set_global_option (char * key, const void *value) { - gftp_config_vars * tmpconfigvar; + gftp_config_vars * tmpconfigvar, newconfigvar; + void *nc_ptr; + int ret; if (gftp_global_options_htable != NULL && (tmpconfigvar = g_hash_table_lookup (gftp_global_options_htable, key)) != NULL) { - memcpy (&tmpconfigvar->value, value, sizeof (tmpconfigvar->value)); + memcpy (&newconfigvar, tmpconfigvar, sizeof (newconfigvar)); + + /* Cheap warning fix for const pointer... */ + memcpy (&nc_ptr, &value, sizeof (nc_ptr)); + newconfigvar.value = nc_ptr; + newconfigvar.flags &= ~GFTP_CVARS_FLAGS_DYNMEM; - /* FIXME - only set this variable if the value has changed */ - gftp_configuration_changed = 1; + ret = gftp_option_types[newconfigvar.otype].compare_function (&newconfigvar, tmpconfigvar); + if (ret != 0) + { + gftp_option_types[newconfigvar.otype].copy_function (&newconfigvar, tmpconfigvar); + gftp_configuration_changed = 1; + } } else { @@ -1307,7 +1382,9 @@ while (tempentry != NULL) { gftp_free_bookmark (tempentry); - g_free (tempentry->path); + + if (tempentry->path != NULL) + g_free (tempentry->path); if (tempentry->children != NULL) { @@ -1326,8 +1403,6 @@ tempentry = tempentry->next; g_free (delentry); } - - g_free (bookmarks); }