aboutsummaryrefslogtreecommitdiffstats
path: root/prefs.c
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2004-05-24 02:25:21 +0000
committerGuy Harris <guy@alum.mit.edu>2004-05-24 02:25:21 +0000
commit911bad80f01e1a526cb5db6a1c8b67224a0eb6fd (patch)
treeea0dc09abb3bad519585a3c81e2c1592383a9bc7 /prefs.c
parent9cccb951f0afece3eb83d45275d903852298839c (diff)
Have two strings in an enum_val_t - one that's a short string that is
convenient to put into a command line (no capital letters, no spaces to require quotes), and one that's a detailed description for use in the UI. Allow either of them in the preferences file or "-o" option; use the detailed description in the UI, and also use it when writing the preferences out, so that the preference will be readable by older versions of Ethereal (assuming the preference existed in that version). Update "README.developer" to give more detail about an enum_val_t (and to put the _t in), and to give a more detailed description of the "radio_buttons" argument to "prefs_register_enum_preference()". svn path=/trunk/; revision=10982
Diffstat (limited to 'prefs.c')
-rw-r--r--prefs.c43
1 files changed, 32 insertions, 11 deletions
diff --git a/prefs.c b/prefs.c
index cc2d00c632..132becac13 100644
--- a/prefs.c
+++ b/prefs.c
@@ -1,7 +1,7 @@
/* prefs.c
* Routines for handling preferences
*
- * $Id: prefs.c,v 1.132 2004/05/13 15:28:01 ulfl Exp $
+ * $Id: prefs.c,v 1.133 2004/05/24 02:25:20 guy Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@ethereal.com>
@@ -804,21 +804,35 @@ clear_string_list(GList *sl)
* Takes a string, a pointer to an array of "enum_val_t"s, and a default gint
* value.
* The array must be terminated by an entry with a null "name" string.
- * If the string matches a "name" strings in an entry, the value from that
- * entry is returned. Otherwise, the default value that was passed as the
- * third argument is returned.
+ *
+ * If the string matches a "name" string in an entry, the value from that
+ * entry is returned.
+ *
+ * Otherwise, if a string matches a "desctiption" string in an entry, the
+ * value from that entry is returned; we do that for backwards compatibility,
+ * as we used to have only a "name" string that was used both for command-line
+ * and configuration-file values and in the GUI (which meant either that
+ * the GUI had what might be somewhat cryptic values to select from or that
+ * the "-o" flag took long strings, often with spaces in them).
+ *
+ * Otherwise, the default value that was passed as the third argument is
+ * returned.
*/
gint
find_val_for_string(const char *needle, const enum_val_t *haystack,
gint default_value)
{
- int i = 0;
+ int i;
- while (haystack[i].name != NULL) {
+ for (i = 0; haystack[i].name != NULL; i++) {
if (strcasecmp(needle, haystack[i].name) == 0) {
return haystack[i].value;
}
- i++;
+ }
+ for (i = 0; haystack[i].name != NULL; i++) {
+ if (strcasecmp(needle, haystack[i].description) == 0) {
+ return haystack[i].value;
+ }
}
return default_value;
}
@@ -2006,13 +2020,20 @@ write_pref(gpointer data, gpointer user_data)
break;
case PREF_ENUM:
+ /*
+ * For now, we save the "description" value, so that if we
+ * save the preferences older versions of Ethereal can at
+ * least read preferences that they supported; we support
+ * either the short name or the description when reading
+ * the preferences file or a "-o" option.
+ */
fprintf(arg->pf, "# One of: ");
enum_valp = pref->info.enum_info.enumvals;
val_string = NULL;
while (enum_valp->name != NULL) {
if (enum_valp->value == *pref->varp.enump)
- val_string = enum_valp->name;
- fprintf(arg->pf, "%s", enum_valp->name);
+ val_string = enum_valp->description;
+ fprintf(arg->pf, "%s", enum_valp->description);
enum_valp++;
if (enum_valp->name == NULL)
fprintf(arg->pf, "\n");
@@ -2020,8 +2041,8 @@ write_pref(gpointer data, gpointer user_data)
fprintf(arg->pf, ", ");
}
fprintf(arg->pf, "# (case-insensitive).\n");
- fprintf(arg->pf, "%s.%s: %s\n", arg->module->name, pref->name,
- val_string);
+ fprintf(arg->pf, "%s.%s: %s\n", arg->module->name,
+ pref->name, val_string);
break;
case PREF_STRING: