GTK: Wrap static preference labels.
[metze/wireshark/wip.git] / epan / prefs.c
index beff049a02407ff63712f3ab117a139e3a6db16d..ed7bea648a324556ccd2d3cae4716dedbc040290 100644 (file)
 
 #include <stdlib.h>
 #include <string.h>
-#include <ctype.h>
 #include <errno.h>
 
-#ifdef HAVE_UNISTD_H
-#include <unistd.h>
-#endif
-
 #include <glib.h>
 
 #include <stdio.h>
 #include <epan/proto.h>
 #include <epan/strutil.h>
 #include <epan/column.h>
+#include <epan/decode_as.h>
 #include "print.h"
 #include <wsutil/file_util.h>
+#include <wsutil/ws_printf.h> /* ws_g_warning */
 
 #include <epan/prefs-int.h>
 #include <epan/uat-int.h>
@@ -62,20 +59,22 @@ static module_t *find_subtree(module_t *parent, const char *tilte);
 static module_t *prefs_register_module_or_subtree(module_t *parent,
     const char *name, const char *title, const char *description, gboolean is_subtree,
     void (*apply_cb)(void), gboolean use_gui);
+static void prefs_register_modules(void);
 static prefs_set_pref_e set_pref(gchar*, const gchar*, void *, gboolean);
-static char * join_string_list(GList *);
 static void free_col_info(GList *);
 static void pre_init_prefs(void);
 static gboolean prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt);
 static gboolean parse_column_format(fmt_data *cfmt, const char *fmt);
 static void try_convert_to_custom_column(gpointer *el_data);
 
+#define IS_PREF_OBSOLETE(p) ((p) & PREF_OBSOLETE)
+#define SET_PREF_OBSOLETE(p) ((p) |= PREF_OBSOLETE)
+#define RESET_PREF_OBSOLETE(p) ((p) &= ~PREF_OBSOLETE)
 
 #define PF_NAME         "preferences"
 #define OLD_GPF_NAME    "wireshark.conf" /* old name for global preferences file */
 
 static gboolean prefs_initialized = FALSE;
-static gboolean prefs_pre_initialized = FALSE;
 static gchar *gpf_path = NULL;
 static gchar *cols_hidden_list = NULL;
 
@@ -170,7 +169,7 @@ static const gchar *capture_cols[7] = {
 };
 #define CAPTURE_COL_TYPE_DESCRIPTION \
     "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, MONITOR, BUFFER, FILTER\n"
-#elif defined(_WIN32) && !defined (HAVE_PCAP_CREATE)
+#elif defined(CAN_SET_CAPTURE_BUFFER_SIZE)
 /* Can set buffer size but not monitor mode. */
 static gint num_capture_cols = 6;
 static const gchar *capture_cols[6] = {
@@ -197,6 +196,110 @@ static const gchar *capture_cols[5] = {
     "Possible values: INTERFACE, LINK, PMODE, SNAPLEN, FILTER\n"
 #endif
 
+static const enum_val_t gui_packet_list_elide_mode[] = {
+    {"LEFT", "LEFT", ELIDE_LEFT},
+    {"RIGHT", "RIGHT", ELIDE_RIGHT},
+    {"MIDDLE", "MIDDLE", ELIDE_MIDDLE},
+    {"NONE", "NONE", ELIDE_NONE},
+    {NULL, NULL, -1}
+};
+
+/** Struct to hold preference data */
+struct preference {
+    const char *name;                /**< name of preference */
+    const char *title;               /**< title to use in GUI */
+    const char *description;         /**< human-readable description of preference */
+    int ordinal;                     /**< ordinal number of this preference */
+    int type;                        /**< type of that preference */
+    gui_type_t gui;                  /**< type of the GUI (QT, GTK or both) the preference is registered for */
+    union {                          /* The Qt preference code assumes that these will all be pointers (and unique) */
+        guint *uint;
+        gboolean *boolp;
+        gint *enump;
+        char **string;
+        range_t **range;
+        struct epan_uat* uat;
+        color_t *colorp;
+        GList** list;
+    } varp;                          /**< pointer to variable storing the value */
+    union {
+        guint uint;
+        gboolean boolval;
+        gint enumval;
+        char *string;
+        range_t *range;
+        color_t color;
+        GList* list;
+    } stashed_val;                     /**< original value, when editing from the GUI */
+    union {
+        guint uint;
+        gboolean boolval;
+        gint enumval;
+        char *string;
+        range_t *range;
+        color_t color;
+        GList* list;
+    } default_val;                   /**< the default value of the preference */
+    union {
+      guint base;                    /**< input/output base, for PREF_UINT */
+      guint32 max_value;             /**< maximum value of a range */
+      struct {
+        const enum_val_t *enumvals;  /**< list of name & values */
+        gboolean radio_buttons;      /**< TRUE if it should be shown as
+                                          radio buttons rather than as an
+                                          option menu or combo box in
+                                          the preferences tab */
+      } enum_info;                   /**< for PREF_ENUM */
+    } info;                          /**< display/text file information */
+    struct pref_custom_cbs custom_cbs;   /**< for PREF_CUSTOM */
+    void    *control;                /**< handle for GUI control for this preference. GTK+ only? */
+};
+
+const char* prefs_get_description(pref_t *pref)
+{
+    return pref->description;
+}
+
+const char* prefs_get_title(pref_t *pref)
+{
+    return pref->title;
+}
+
+int prefs_get_type(pref_t *pref)
+{
+    return pref->type;
+}
+
+gui_type_t prefs_get_gui_type(pref_t *pref)
+{
+    return pref->gui;
+}
+
+const char* prefs_get_name(pref_t *pref)
+{
+    return pref->name;
+}
+
+guint32 prefs_get_max_value(pref_t *pref)
+{
+    return pref->info.max_value;
+}
+
+void* prefs_get_control(pref_t *pref)
+{
+    return pref->control;
+}
+
+void prefs_set_control(pref_t *pref, void* control)
+{
+    pref->control = control;
+}
+
+int prefs_get_ordinal(pref_t *pref)
+{
+    return pref->ordinal;
+}
+
 /*
  * List of all modules with preference settings.
  */
@@ -212,20 +315,37 @@ static wmem_tree_t *prefs_top_level_modules = NULL;
 void
 prefs_init(void)
 {
+    memset(&prefs, 0, sizeof(prefs));
     prefs_modules = wmem_tree_new(wmem_epan_scope());
     prefs_top_level_modules = wmem_tree_new(wmem_epan_scope());
 }
 
+/*
+ * Free the strings for a string-like preference.
+ */
+static void
+free_string_like_preference(pref_t *pref)
+{
+    g_free(*pref->varp.string);
+    *pref->varp.string = NULL;
+    g_free(pref->default_val.string);
+    pref->default_val.string = NULL;
+}
+
 static void
 free_pref(gpointer data, gpointer user_data _U_)
 {
     pref_t *pref = (pref_t *)data;
+    int type = pref->type;
 
-    switch (pref->type) {
-    case PREF_OBSOLETE:
+    /* we reset the PREF_OBSOLETE bit in order to allow the original preference to be freed */
+    RESET_PREF_OBSOLETE(type);
+
+    switch (type) {
     case PREF_BOOL:
     case PREF_ENUM:
     case PREF_UINT:
+    case PREF_DECODE_AS_UINT:
     case PREF_STATIC_TEXT:
     case PREF_UAT:
     case PREF_COLOR:
@@ -233,15 +353,16 @@ free_pref(gpointer data, gpointer user_data _U_)
     case PREF_STRING:
     case PREF_FILENAME:
     case PREF_DIRNAME:
-        g_free((char *)*pref->varp.string);
+        g_free(*pref->varp.string);
         *pref->varp.string = NULL;
         g_free(pref->default_val.string);
         pref->default_val.string = NULL;
         break;
     case PREF_RANGE:
-        g_free(*pref->varp.range);
+    case PREF_DECODE_AS_RANGE:
+        wmem_free(wmem_epan_scope(), *pref->varp.range);
         *pref->varp.range = NULL;
-        g_free(pref->default_val.range);
+        wmem_free(wmem_epan_scope(), pref->default_val.range);
         pref->default_val.range = NULL;
         break;
     case PREF_CUSTOM:
@@ -281,6 +402,9 @@ prefs_cleanup(void)
      *  do what clean up we can.
      */
     prefs_modules_foreach(free_module_prefs, NULL);
+
+    /* Clean the uats */
+    uat_cleanup();
 }
 
 /*
@@ -299,6 +423,27 @@ prefs_register_module(module_t *parent, const char *name, const char *title,
                                             FALSE, apply_cb, use_gui);
 }
 
+static void
+prefs_deregister_module(module_t *parent, const char *name, const char *title)
+{
+    /* Remove this module from the list of all modules */
+    module_t *module = (module_t *)wmem_tree_remove_string(prefs_modules, name, WMEM_TREE_STRING_NOCASE);
+
+    if (!module)
+        return;
+
+    if (parent == NULL) {
+        /* Remove from top */
+        wmem_tree_remove_string(prefs_top_level_modules, title, WMEM_TREE_STRING_NOCASE);
+    } else if (parent->submodules) {
+        /* Remove from parent */
+        wmem_tree_remove_string(parent->submodules, title, WMEM_TREE_STRING_NOCASE);
+    }
+
+    free_module_prefs(module, NULL);
+    wmem_free(wmem_epan_scope(), module);
+}
+
 /*
  * Register a subtree that will have modules under it.
  * Specify the module under which to register it or NULL to register it
@@ -368,9 +513,8 @@ prefs_register_module_or_subtree(module_t *parent, const char *name,
          * shifting, etc.
          */
         for (p = name; (c = *p) != '\0'; p++)
-            g_assert(isascii(c) &&
-                (islower(c) || isdigit(c) || c == '_' ||
-                 c == '-' || c == '.'));
+            g_assert(g_ascii_islower(c) || g_ascii_isdigit(c) || c == '_' ||
+                 c == '-' || c == '.');
 
         /*
          * Make sure there's not already a module with that
@@ -439,6 +583,7 @@ prefs_register_protocol(int id, void (*apply_cb)(void))
          * No.  Register Protocols subtree as well as any preferences
          * for non-dissector modules.
          */
+        pre_init_prefs();
         prefs_register_modules();
     }
     protocol = find_protocol_by_id(id);
@@ -448,6 +593,15 @@ prefs_register_protocol(int id, void (*apply_cb)(void))
                                  proto_get_protocol_name(id), apply_cb, TRUE);
 }
 
+void
+prefs_deregister_protocol (int id)
+{
+    protocol_t *protocol = find_protocol_by_id(id);
+    prefs_deregister_module (protocols_module,
+                             proto_get_protocol_filter_name(id),
+                             proto_get_protocol_short_name(protocol));
+}
+
 module_t *
 prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(void))
 {
@@ -466,6 +620,7 @@ prefs_register_protocol_subtree(const char *subtree, int id, void (*apply_cb)(vo
          * No.  Register Protocols subtree as well as any preferences
          * for non-dissector modules.
          */
+        pre_init_prefs();
         prefs_register_modules();
     }
 
@@ -525,6 +680,7 @@ prefs_register_protocol_obsolete(int id)
          * No.  Register Protocols subtree as well as any preferences
          * for non-dissector modules.
          */
+        pre_init_prefs();
         prefs_register_modules();
     }
     protocol = find_protocol_by_id(id);
@@ -560,7 +716,8 @@ prefs_register_stat(const char *name, const char *title,
          * No.  Register Statistics subtree as well as any preferences
          * for non-dissector modules.
          */
-         prefs_register_modules();
+        pre_init_prefs();
+        prefs_register_modules();
     }
 
     return prefs_register_module(stats_module, name, title, description,
@@ -599,7 +756,7 @@ typedef struct {
 } call_foreach_t;
 
 static gboolean
-call_foreach_cb(void *value, void *data)
+call_foreach_cb(const void *key _U_, void *value, void *data)
 {
     module_t *module = (module_t*)value;
     call_foreach_t *call_data = (call_foreach_t*)data;
@@ -675,7 +832,7 @@ prefs_modules_foreach_submodules(module_t *module, module_cb callback,
 }
 
 static gboolean
-call_apply_cb(void *value, void *data _U_)
+call_apply_cb(const void *key _U_, void *value, void *data _U_)
 {
     module_t *module = (module_t *)value;
 
@@ -686,6 +843,8 @@ call_apply_cb(void *value, void *data _U_)
             (*module->apply_cb)();
         module->prefs_changed = FALSE;
     }
+    if (module->submodules)
+        wmem_tree_foreach(module->submodules, call_apply_cb, NULL);
     return FALSE;
 }
 
@@ -711,7 +870,7 @@ void
 prefs_apply(module_t *module)
 {
     if (module && module->prefs_changed)
-        call_apply_cb(module, NULL);
+        call_apply_cb(NULL, module, NULL);
 }
 
 /*
@@ -723,10 +882,11 @@ prefs_apply(module_t *module)
  */
 static pref_t *
 register_preference(module_t *module, const char *name, const char *title,
-                    const char *description, pref_type_t type)
+                    const char *description, int type)
 {
     pref_t *preference;
     const gchar *p;
+    const char *name_prefix = (module->name != NULL) ? module->name : module->parent->name;
 
     preference = g_new(pref_t,1);
     preference->name = name;
@@ -750,8 +910,7 @@ register_preference(module_t *module, const char *name, const char *title,
      * and shouldn't require quoting, shifting, etc.
      */
     for (p = name; *p != '\0'; p++)
-        if (!(isascii((guchar)*p) &&
-            (islower((guchar)*p) || isdigit((guchar)*p) || *p == '_' || *p == '.')))
+        if (!(g_ascii_islower(*p) || g_ascii_isdigit(*p) || *p == '_' || *p == '.'))
             g_error("Preference %s.%s contains invalid characters", module->name, name);
 
     /*
@@ -763,7 +922,7 @@ register_preference(module_t *module, const char *name, const char *title,
     if (prefs_find_preference(module, name) != NULL)
         g_error("Preference %s has already been registered", name);
 
-    if ((type != PREF_OBSOLETE) &&
+    if ((!IS_PREF_OBSOLETE(type)) &&
         /* Don't compare if it's a subtree */
         (module->name != NULL)) {
         /*
@@ -775,9 +934,32 @@ register_preference(module_t *module, const char *name, const char *title,
             g_error("Preference %s begins with the module name", name);
     }
 
+    /* The title shows up in the preferences dialog. Make sure it's UI-friendly. */
+    if (preference->title) {
+        const char *cur_char;
+        if (preference->type != PREF_STATIC_TEXT && g_utf8_strlen(preference->title, -1) > 80) { // Arbitrary.
+            g_error("Title for preference %s.%s is too long: %s", name_prefix, preference->name, preference->title);
+        }
+
+        if (!g_utf8_validate(preference->title, -1, NULL)) {
+            g_error("Title for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name);
+        }
+
+        for (cur_char = preference->title; *cur_char; cur_char = g_utf8_next_char(cur_char)) {
+            if (!g_unichar_isprint(g_utf8_get_char(cur_char))) {
+                g_error("Title for preference %s.%s isn't printable UTF-8.", name_prefix, preference->name);
+            }
+        }
+    }
+
+    if (preference->description) {
+        if (!g_utf8_validate(preference->description, -1, NULL)) {
+            g_error("Description for preference %s.%s isn't valid UTF-8.", name_prefix, preference->name);
+        }
+    }
+
     /*
-     * There isn't already one with that name, so add the
-     * preference.
+     * We passed all of our checks. Add the preference.
      */
     module->prefs = g_list_append(module->prefs, preference);
     if (title != NULL)
@@ -793,6 +975,7 @@ register_preference(module_t *module, const char *name, const char *title,
 typedef struct {
     GList *list_entry;
     const char *name;
+    module_t *submodule;
 } find_pref_arg_t;
 
 static gint
@@ -805,7 +988,7 @@ preference_match(gconstpointer a, gconstpointer b)
 }
 
 static gboolean
-module_find_pref_cb(void *value, void *data)
+module_find_pref_cb(const void *key _U_, void *value, void *data)
 {
     find_pref_arg_t* arg = (find_pref_arg_t*)data;
     GList *list_entry;
@@ -821,11 +1004,15 @@ module_find_pref_cb(void *value, void *data)
         return FALSE;
 
     arg->list_entry = list_entry;
+    arg->submodule = module;
     return TRUE;
 }
 
-struct preference *
-prefs_find_preference(module_t *module, const char *name)
+/* Tries to find a preference, setting containing_module to the (sub)module
+ * holding this preference. */
+static struct preference *
+prefs_find_preference_with_submodule(module_t *module, const char *name,
+        module_t **containing_module)
 {
     find_pref_arg_t arg;
     GList *list_entry;
@@ -835,6 +1022,7 @@ prefs_find_preference(module_t *module, const char *name)
 
     list_entry = g_list_find_custom(module->prefs, name,
         preference_match);
+    arg.submodule = NULL;
 
     if (list_entry == NULL)
     {
@@ -851,9 +1039,18 @@ prefs_find_preference(module_t *module, const char *name)
     if (list_entry == NULL)
         return NULL;    /* no such preference */
 
+    if (containing_module)
+        *containing_module = arg.submodule ? arg.submodule : module;
+
     return (struct preference *) list_entry->data;
 }
 
+struct preference *
+prefs_find_preference(module_t *module, const char *name)
+{
+    return prefs_find_preference_with_submodule(module, name, NULL);
+}
+
 /*
  * Returns TRUE if the given protocol has registered preferences
  */
@@ -935,9 +1132,85 @@ prefs_register_bool_preference(module_t *module, const char *name,
     preference->default_val.boolval = *var;
 }
 
+gboolean prefs_set_bool_value(pref_t *pref, gboolean value, pref_source_t source)
+{
+    gboolean changed = FALSE;
+
+    switch (source)
+    {
+    case pref_default:
+        if (pref->default_val.boolval != value) {
+            pref->default_val.boolval = value;
+            changed = TRUE;
+        }
+        break;
+    case pref_stashed:
+        if (pref->stashed_val.boolval != value) {
+            pref->stashed_val.boolval = value;
+            changed = TRUE;
+        }
+        break;
+    case pref_current:
+        if (*pref->varp.boolp != value) {
+            *pref->varp.boolp = value;
+            changed = TRUE;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return changed;
+}
+
+void prefs_invert_bool_value(pref_t *pref, pref_source_t source)
+{
+    switch (source)
+    {
+    case pref_default:
+        pref->default_val.boolval = !pref->default_val.boolval;
+        break;
+    case pref_stashed:
+        pref->stashed_val.boolval = !pref->stashed_val.boolval;
+        break;
+    case pref_current:
+        *pref->varp.boolp = !(*pref->varp.boolp);
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+}
+
+gboolean prefs_get_bool_value(pref_t *pref, pref_source_t source)
+{
+    switch (source)
+    {
+    case pref_default:
+        return pref->default_val.boolval;
+        break;
+    case pref_stashed:
+        return pref->stashed_val.boolval;
+        break;
+    case pref_current:
+        return *pref->varp.boolp;
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return FALSE;
+}
+
 /*
  * Register a preference with an enumerated value.
  */
+/*
+ * XXX Should we get rid of the radio_buttons parameter and make that
+ * behavior automatic depending on the number of items?
+ */
 void
 prefs_register_enum_preference(module_t *module, const char *name,
                                const char *title, const char *description,
@@ -954,16 +1227,80 @@ prefs_register_enum_preference(module_t *module, const char *name,
     preference->info.enum_info.radio_buttons = radio_buttons;
 }
 
-static pref_t*
+gboolean prefs_set_enum_value(pref_t *pref, gint value, pref_source_t source)
+{
+    gboolean changed = FALSE;
+
+    switch (source)
+    {
+    case pref_default:
+        if (pref->default_val.enumval != value) {
+            pref->default_val.enumval = value;
+            changed = TRUE;
+        }
+        break;
+    case pref_stashed:
+        if (pref->stashed_val.enumval != value) {
+            pref->stashed_val.enumval = value;
+            changed = TRUE;
+        }
+        break;
+    case pref_current:
+        if (*pref->varp.enump != value) {
+            *pref->varp.enump = value;
+            changed = TRUE;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return changed;
+}
+
+gint prefs_get_enum_value(pref_t *pref, pref_source_t source)
+{
+    switch (source)
+    {
+    case pref_default:
+        return pref->default_val.enumval;
+        break;
+    case pref_stashed:
+        return pref->stashed_val.enumval;
+        break;
+    case pref_current:
+        return *pref->varp.enump;
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return 0;
+}
+
+const enum_val_t* prefs_get_enumvals(pref_t *pref)
+{
+    return pref->info.enum_info.enumvals;
+}
+
+gboolean prefs_get_enum_radiobuttons(pref_t *pref)
+{
+    return pref->info.enum_info.radio_buttons;
+}
+
+static void
 register_string_like_preference(module_t *module, const char *name,
                                 const char *title, const char *description,
-                                const char **var, pref_type_t type)
+                                char **var, int type,
+                                struct pref_custom_cbs* custom_cbs,
+                                gboolean free_tmp)
 {
-    pref_t *preference;
-    char *varcopy;
+    pref_t *pref;
+    gchar *tmp;
 
-    preference = register_preference(module, name, title, description,
-                                     type);
+    pref = register_preference(module, name, title, description, type);
 
     /*
      * String preference values should be non-null (as you can't
@@ -974,50 +1311,116 @@ register_string_like_preference(module_t *module, const char *name,
      * If the value is a null pointer, make it a copy of a null
      * string, otherwise make it a copy of the value.
      */
+    tmp = *var;
     if (*var == NULL) {
         *var = g_strdup("");
-        varcopy = g_strdup("");
     } else {
         *var = g_strdup(*var);
-        varcopy = g_strdup(*var);
     }
-    preference->varp.string = var;
-    preference->default_val.string = varcopy;
-    preference->stashed_val.string = NULL;
-
-    return preference;
+    if (free_tmp) {
+        g_free(tmp);
+    }
+    pref->varp.string = var;
+    pref->default_val.string = g_strdup(*var);
+    pref->stashed_val.string = NULL;
+    if (type == PREF_CUSTOM) {
+        g_assert(custom_cbs);
+        pref->custom_cbs = *custom_cbs;
+    }
 }
 
 /*
- * Register a preference with a character-string value.
+ * For use by UI code that sets preferences.
  */
-void
-prefs_register_string_preference(module_t *module, const char *name,
-                                 const char *title, const char *description,
-                                 const char **var)
+gboolean
+prefs_set_string_value(pref_t *pref, const char* value, pref_source_t source)
+{
+    gboolean changed = FALSE;
+
+    switch (source)
+    {
+    case pref_default:
+        if (*pref->default_val.string) {
+            if (strcmp(pref->default_val.string, value) != 0) {
+                changed = TRUE;
+                g_free(pref->default_val.string);
+                pref->default_val.string = g_strdup(value);
+            }
+        } else if (value) {
+            pref->default_val.string = g_strdup(value);
+        }
+        break;
+    case pref_stashed:
+        if (pref->stashed_val.string) {
+            if (strcmp(pref->stashed_val.string, value) != 0) {
+                changed = TRUE;
+                g_free(pref->stashed_val.string);
+                pref->stashed_val.string = g_strdup(value);
+            }
+        } else if (value) {
+            pref->stashed_val.string = g_strdup(value);
+        }
+        break;
+    case pref_current:
+        if (*pref->varp.string) {
+            if (strcmp(*pref->varp.string, value) != 0) {
+                changed = TRUE;
+                g_free(*pref->varp.string);
+                *pref->varp.string = g_strdup(value);
+            }
+        } else if (value) {
+            *pref->varp.string = g_strdup(value);
+        }
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return changed;
+}
+
+char* prefs_get_string_value(pref_t *pref, pref_source_t source)
 {
-    register_string_like_preference(module, name, title, description, var,
-                                    PREF_STRING);
+    switch (source)
+    {
+    case pref_default:
+        return pref->default_val.string;
+    case pref_stashed:
+        return pref->stashed_val.string;
+    case pref_current:
+        return *pref->varp.string;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return NULL;
 }
 
 /*
- * Register a "custom" preference with a character-string value.
- * XXX - This should be temporary until we can find a better way
- * to do "custom" preferences
+ * Reset the value of a string-like preference.
  */
 static void
-prefs_register_string_custom_preference(module_t *module, const char *name,
-                                 const char *title, const char *description,
-                                 struct pref_custom_cbs* custom_cbs, const char **var)
+reset_string_like_preference(pref_t *pref)
 {
-    pref_t *preference;
-
-    preference = register_string_like_preference(module, name, title, description, var,
-                                    PREF_CUSTOM);
-
-    preference->custom_cbs = *custom_cbs;
+    g_free(*pref->varp.string);
+    *pref->varp.string = g_strdup(pref->default_val.string);
 }
 
+/*
+ * Register a preference with a character-string value.
+ */
+void
+prefs_register_string_preference(module_t *module, const char *name,
+                                 const char *title, const char *description,
+                                 const char **var)
+{
+DIAG_OFF(cast-qual)
+    register_string_like_preference(module, name, title, description,
+                                    (char **)var, PREF_STRING, NULL, FALSE);
+DIAG_ON(cast-qual)
+}
 
 /*
  * Register a preference with a file name (string) value.
@@ -1027,8 +1430,10 @@ prefs_register_filename_preference(module_t *module, const char *name,
                                    const char *title, const char *description,
                                    const char **var)
 {
-    register_string_like_preference(module, name, title, description, var,
-                                    PREF_FILENAME);
+DIAG_OFF(cast-qual)
+    register_string_like_preference(module, name, title, description,
+                                    (char **)var, PREF_FILENAME, NULL, FALSE);
+DIAG_ON(cast-qual)
 }
 
 /*
@@ -1039,25 +1444,23 @@ prefs_register_directory_preference(module_t *module, const char *name,
                                    const char *title, const char *description,
                                    const char **var)
 {
-    register_string_like_preference(module, name, title, description, var,
-                                    PREF_DIRNAME);
+DIAG_OFF(cast-qual)
+    register_string_like_preference(module, name, title, description,
+                                    (char **)var, PREF_DIRNAME, NULL, FALSE);
+DIAG_ON(cast-qual)
 }
 
-/*
- * Register a preference with a ranged value.
- */
-void
-prefs_register_range_preference(module_t *module, const char *name,
+/* Refactoring to handle both PREF_RANGE and PREF_DECODE_AS_RANGE */
+static void
+prefs_register_range_preference_common(module_t *module, const char *name,
                                 const char *title, const char *description,
-                                range_t **var, guint32 max_value)
+                                range_t **var, guint32 max_value, int type)
 {
     pref_t *preference;
 
-    preference = register_preference(module, name, title, description,
-                                     PREF_RANGE);
+    preference = register_preference(module, name, title, description, type);
     preference->info.max_value = max_value;
 
-
     /*
      * Range preference values should be non-null (as you can't
      * keep them null after using the preferences GUI, you can at best
@@ -1067,57 +1470,190 @@ prefs_register_range_preference(module_t *module, const char *name,
      * If the value is a null pointer, make it an empty range.
      */
     if (*var == NULL)
-        *var = range_empty();
+        *var = range_empty(wmem_epan_scope());
     preference->varp.range = var;
-    preference->default_val.range = range_copy(*var);
+    preference->default_val.range = range_copy(wmem_epan_scope(), *var);
     preference->stashed_val.range = NULL;
 }
 
 /*
- * Register a static text 'preference'.  It can be used to add explanatory
- * text inline with other preferences in the GUI.
- * Note: Static preferences are not saved to the preferences file.
+ * Register a preference with a ranged value.
  */
 void
-prefs_register_static_text_preference(module_t *module, const char *name,
-                                      const char *title,
-                                      const char *description)
+prefs_register_range_preference(module_t *module, const char *name,
+                                const char *title, const char *description,
+                                range_t **var, guint32 max_value)
 {
-    register_preference(module, name, title, description, PREF_STATIC_TEXT);
+    prefs_register_range_preference_common(module, name, title,
+                description, var, max_value, PREF_RANGE);
 }
 
-/*
- * Register a uat 'preference'. It adds a button that opens the uat's window in the
- * preferences tab of the module.
- */
-extern void
-prefs_register_uat_preference(module_t *module, const char *name,
-                              const char *title, const char *description,
-                              uat_t* uat)
+gboolean
+prefs_set_range_value_work(pref_t *pref, const gchar *value,
+                           gboolean return_range_errors, gboolean *changed)
 {
+    range_t *newrange;
 
-    pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+    if (range_convert_str_work(wmem_epan_scope(), &newrange, value, pref->info.max_value,
+                               return_range_errors) != CVT_NO_ERROR) {
+        return FALSE;        /* number was bad */
+    }
 
-    preference->varp.uat = uat;
+    if (!ranges_are_equal(*pref->varp.range, newrange)) {
+        *changed = TRUE;
+        wmem_free(wmem_epan_scope(), *pref->varp.range);
+        *pref->varp.range = newrange;
+    } else {
+        wmem_free(wmem_epan_scope(), newrange);
+    }
+    return TRUE;
 }
 
 /*
- * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
- * preferences tab of the module.
+ * For use by UI code that sets preferences.
  */
-extern void
-prefs_register_uat_preference_qt(module_t *module, const char *name,
-                              const char *title, const char *description,
-                              uat_t* uat)
+gboolean
+prefs_set_stashed_range_value(pref_t *pref, const gchar *value)
 {
+    range_t *newrange;
 
-    pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+    if (range_convert_str_work(wmem_epan_scope(), &newrange, value, pref->info.max_value,
+                               TRUE) != CVT_NO_ERROR) {
+        return FALSE;        /* number was bad */
+    }
 
-    preference->varp.uat = uat;
+    if (!ranges_are_equal(pref->stashed_val.range, newrange)) {
+        wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+        pref->stashed_val.range = newrange;
+    } else {
+        wmem_free(wmem_epan_scope(), newrange);
+    }
+    return TRUE;
+
+}
+
+gboolean prefs_set_range_value(pref_t *pref, range_t *value, pref_source_t source)
+{
+    gboolean changed = FALSE;
+
+    switch (source)
+    {
+    case pref_default:
+        if (!ranges_are_equal(pref->default_val.range, value)) {
+            wmem_free(wmem_epan_scope(), pref->default_val.range);
+            pref->default_val.range = range_copy(wmem_epan_scope(), value);
+            changed = TRUE;
+        }
+        break;
+    case pref_stashed:
+        if (!ranges_are_equal(pref->stashed_val.range, value)) {
+            wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+            pref->stashed_val.range = range_copy(wmem_epan_scope(), value);
+            changed = TRUE;
+        }
+        break;
+    case pref_current:
+        if (!ranges_are_equal(*pref->varp.range, value)) {
+            wmem_free(wmem_epan_scope(), *pref->varp.range);
+            *pref->varp.range = range_copy(wmem_epan_scope(), value);
+            changed = TRUE;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return changed;
+}
+
+range_t* prefs_get_range_value_real(pref_t *pref, pref_source_t source)
+{
+    switch (source)
+    {
+    case pref_default:
+        return pref->default_val.range;
+    case pref_stashed:
+        return pref->stashed_val.range;
+        break;
+    case pref_current:
+        return *pref->varp.range;
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return NULL;
+}
+
+range_t* prefs_get_range_value(const char *module_name, const char* pref_name)
+{
+    return prefs_get_range_value_real(prefs_find_preference(prefs_find_module(module_name), pref_name), pref_current);
+}
+
+void
+prefs_range_add_value(pref_t *pref, guint32 val)
+{
+    range_add_value(wmem_epan_scope(), pref->varp.range, val);
+}
+
+void
+prefs_range_remove_value(pref_t *pref, guint32 val)
+{
+    range_remove_value(wmem_epan_scope(), pref->varp.range, val);
+}
+
+/*
+ * Register a static text 'preference'.  It can be used to add explanatory
+ * text inline with other preferences in the GUI.
+ * Note: Static preferences are not saved to the preferences file.
+ */
+void
+prefs_register_static_text_preference(module_t *module, const char *name,
+                                      const char *title,
+                                      const char *description)
+{
+    register_preference(module, name, title, description, PREF_STATIC_TEXT);
+}
+
+/*
+ * Register a uat 'preference'. It adds a button that opens the uat's window in the
+ * preferences tab of the module.
+ */
+extern void
+prefs_register_uat_preference(module_t *module, const char *name,
+                              const char *title, const char *description,
+                              uat_t* uat)
+{
+
+    pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+
+    preference->varp.uat = uat;
+}
+
+/*
+ * Register a uat 'preference' for QT only. It adds a button that opens the uat's window in the
+ * preferences tab of the module.
+ */
+extern void
+prefs_register_uat_preference_qt(module_t *module, const char *name,
+                              const char *title, const char *description,
+                              uat_t* uat)
+{
+
+    pref_t* preference = register_preference(module, name, title, description, PREF_UAT);
+
+    preference->varp.uat = uat;
 
     preference->gui = GUI_QT;
 }
 
+struct epan_uat* prefs_get_uat_value(pref_t *pref)
+{
+    return pref->varp.uat;
+}
+
 /*
  * Register a color preference.
  */
@@ -1132,6 +1668,64 @@ prefs_register_color_preference(module_t *module, const char *name,
     preference->default_val.color = *color;
 }
 
+gboolean prefs_set_color_value(pref_t *pref, color_t value, pref_source_t source)
+{
+    gboolean changed = FALSE;
+
+    switch (source)
+    {
+    case pref_default:
+        if ((pref->default_val.color.red != value.red) &&
+            (pref->default_val.color.green != value.green) &&
+            (pref->default_val.color.blue != value.blue)) {
+            changed = TRUE;
+            pref->default_val.color = value;
+        }
+        break;
+    case pref_stashed:
+        if ((pref->stashed_val.color.red != value.red) &&
+            (pref->stashed_val.color.green != value.green) &&
+            (pref->stashed_val.color.blue != value.blue)) {
+            changed = TRUE;
+            pref->stashed_val.color = value;
+        }
+        break;
+    case pref_current:
+        if ((pref->varp.colorp->red != value.red) &&
+            (pref->varp.colorp->green != value.green) &&
+            (pref->varp.colorp->blue != value.blue)) {
+            changed = TRUE;
+            *pref->varp.colorp = value;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return changed;
+}
+
+color_t* prefs_get_color_value(pref_t *pref, pref_source_t source)
+{
+    switch (source)
+    {
+    case pref_default:
+        return &pref->default_val.color;
+    case pref_stashed:
+        return &pref->stashed_val.color;
+        break;
+    case pref_current:
+        return pref->varp.colorp;
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return NULL;
+}
+
 /*
  * Register a "custom" preference with a list.
  * XXX - This should be temporary until we can find a better way
@@ -1169,6 +1763,86 @@ prefs_register_custom_preference(module_t *module, const char *name,
     */
 }
 
+/*
+ * Register a (internal) "Decode As" preference with a ranged value.
+ */
+void prefs_register_decode_as_range_preference(module_t *module, const char *name,
+    const char *title, const char *description, range_t **var,
+    guint32 max_value)
+{
+    prefs_register_range_preference_common(module, name, title,
+                description, var, max_value, PREF_DECODE_AS_RANGE);
+}
+
+/*
+ * Register a (internal) "Decode As" preference with an unsigned integral value
+ * for a dissector table.
+ */
+void prefs_register_decode_as_preference(module_t *module, const char *name,
+    const char *title, const char *description, guint *var)
+{
+    pref_t *preference;
+
+    preference = register_preference(module, name, title, description,
+                                     PREF_DECODE_AS_UINT);
+    preference->varp.uint = var;
+    preference->default_val.uint = *var;
+    /* XXX - Presume base 10 for now */
+    preference->info.base = 10;
+}
+
+gboolean prefs_add_decode_as_value(pref_t *pref, guint value, gboolean replace)
+{
+    switch(pref->type)
+    {
+    case PREF_DECODE_AS_UINT:
+        /* This doesn't support multiple values for a dissector in Decode As because the
+            preference only supports a single value. This leads to a "last port for
+            dissector in Decode As wins" */
+        *pref->varp.uint = value;
+        break;
+    case PREF_DECODE_AS_RANGE:
+        if (replace)
+        {
+            /* If range has single value, replace it */
+            if (((*pref->varp.range)->nranges == 1) &&
+                ((*pref->varp.range)->ranges[0].low == (*pref->varp.range)->ranges[0].high)) {
+                wmem_free(wmem_epan_scope(), *pref->varp.range);
+                *pref->varp.range = range_empty(wmem_epan_scope());
+            }
+        }
+
+        prefs_range_add_value(pref, value);
+        break;
+    default:
+        /* XXX - Worth asserting over? */
+        break;
+    }
+
+    return TRUE;
+}
+
+gboolean prefs_remove_decode_as_value(pref_t *pref, guint value, gboolean set_default)
+{
+    switch(pref->type)
+    {
+    case PREF_DECODE_AS_UINT:
+        if (set_default) {
+            *pref->varp.uint = pref->default_val.uint;
+        } else {
+            *pref->varp.uint = 0;
+        }
+        break;
+    case PREF_DECODE_AS_RANGE:
+        prefs_range_remove_value(pref, value);
+        break;
+    default:
+        break;
+    }
+
+    return TRUE;
+}
+
 /*
  * Register a preference that used to be supported but no longer is.
  */
@@ -1185,7 +1859,7 @@ extern gboolean
 prefs_get_preference_obsolete(pref_t *pref)
 {
     if (pref)
-        return pref->type == PREF_OBSOLETE ? TRUE : FALSE;
+        return (IS_PREF_OBSOLETE(pref->type) ? TRUE : FALSE);
 
     return TRUE;
 }
@@ -1197,12 +1871,291 @@ extern prefs_set_pref_e
 prefs_set_preference_obsolete(pref_t *pref)
 {
     if (pref) {
-        pref->type = PREF_OBSOLETE;
+        SET_PREF_OBSOLETE(pref->type);
         return PREFS_SET_OK;
     }
     return PREFS_SET_NO_SUCH_PREF;
 }
 
+guint
+pref_stash(pref_t *pref, gpointer unused _U_)
+{
+    switch (pref->type) {
+
+    case PREF_DECODE_AS_UINT:
+        pref->stashed_val.uint = *pref->varp.uint;
+        break;
+
+    case PREF_UINT:
+        pref->stashed_val.uint = *pref->varp.uint;
+        break;
+
+    case PREF_BOOL:
+        pref->stashed_val.boolval = *pref->varp.boolp;
+        break;
+
+    case PREF_ENUM:
+        pref->stashed_val.enumval = *pref->varp.enump;
+        break;
+
+    case PREF_STRING:
+    case PREF_FILENAME:
+    case PREF_DIRNAME:
+        g_free(pref->stashed_val.string);
+        pref->stashed_val.string = g_strdup(*pref->varp.string);
+        break;
+
+    case PREF_DECODE_AS_RANGE:
+    case PREF_RANGE:
+        wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+        pref->stashed_val.range = range_copy(wmem_epan_scope(), *pref->varp.range);
+        break;
+
+    case PREF_COLOR:
+        pref->stashed_val.color = *pref->varp.colorp;
+        break;
+
+    case PREF_STATIC_TEXT:
+    case PREF_UAT:
+    case PREF_CUSTOM:
+        break;
+
+    case PREF_OBSOLETE:
+        g_assert_not_reached();
+        break;
+    }
+    return 0;
+}
+
+guint
+pref_unstash(pref_t *pref, gpointer unstash_data_p)
+{
+    pref_unstash_data_t *unstash_data = (pref_unstash_data_t *)unstash_data_p;
+    dissector_table_t sub_dissectors = NULL;
+    dissector_handle_t handle = NULL;
+
+    /* Revert the preference to its saved value. */
+    switch (pref->type) {
+
+    case PREF_DECODE_AS_UINT:
+        if (*pref->varp.uint != pref->stashed_val.uint) {
+            unstash_data->module->prefs_changed = TRUE;
+
+            if (unstash_data->handle_decode_as) {
+                if (*pref->varp.uint != pref->default_val.uint) {
+                    dissector_reset_uint(pref->name, *pref->varp.uint);
+                }
+            }
+
+            *pref->varp.uint = pref->stashed_val.uint;
+
+            if (unstash_data->handle_decode_as) {
+                sub_dissectors = find_dissector_table(pref->name);
+                if (sub_dissectors != NULL) {
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)unstash_data->module->title);
+                    if (handle != NULL) {
+                        dissector_change_uint(pref->name, *pref->varp.uint, handle);
+                    }
+                }
+            }
+        }
+        break;
+
+    case PREF_UINT:
+        if (*pref->varp.uint != pref->stashed_val.uint) {
+            unstash_data->module->prefs_changed = TRUE;
+            *pref->varp.uint = pref->stashed_val.uint;
+        }
+        break;
+
+    case PREF_BOOL:
+        if (*pref->varp.boolp != pref->stashed_val.boolval) {
+            unstash_data->module->prefs_changed = TRUE;
+            *pref->varp.boolp = pref->stashed_val.boolval;
+        }
+        break;
+
+    case PREF_ENUM:
+        if (*pref->varp.enump != pref->stashed_val.enumval) {
+            unstash_data->module->prefs_changed = TRUE;
+            *pref->varp.enump = pref->stashed_val.enumval;
+        }
+        break;
+
+    case PREF_STRING:
+    case PREF_FILENAME:
+    case PREF_DIRNAME:
+        if (strcmp(*pref->varp.string, pref->stashed_val.string) != 0) {
+            unstash_data->module->prefs_changed = TRUE;
+            g_free(*pref->varp.string);
+            *pref->varp.string = g_strdup(pref->stashed_val.string);
+        }
+        break;
+
+    case PREF_DECODE_AS_RANGE:
+        if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
+            guint32 i, j;
+            unstash_data->module->prefs_changed = TRUE;
+
+            if (unstash_data->handle_decode_as) {
+                sub_dissectors = find_dissector_table(pref->name);
+                if (sub_dissectors != NULL) {
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)unstash_data->module->title);
+                    if (handle != NULL) {
+                        /* Delete all of the old values from the dissector table */
+                        for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+                            for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+                                dissector_delete_uint(pref->name, j, handle);
+                                decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+                            }
+
+                            dissector_delete_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+                            decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+                        }
+                    }
+                }
+            }
+
+            wmem_free(wmem_epan_scope(), *pref->varp.range);
+            *pref->varp.range = range_copy(wmem_epan_scope(), pref->stashed_val.range);
+
+            if (unstash_data->handle_decode_as) {
+                if ((sub_dissectors != NULL) && (handle != NULL)) {
+
+                    /* Add new values to the dissector table */
+                    for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+
+                        for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+                            dissector_change_uint(pref->name, j, handle);
+                            decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+                        }
+
+                        dissector_change_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+                        decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+                    }
+                }
+            }
+        }
+        break;
+
+    case PREF_RANGE:
+        if (!ranges_are_equal(*pref->varp.range, pref->stashed_val.range)) {
+            unstash_data->module->prefs_changed = TRUE;
+            wmem_free(wmem_epan_scope(), *pref->varp.range);
+            *pref->varp.range = range_copy(wmem_epan_scope(), pref->stashed_val.range);
+        }
+    break;
+
+    case PREF_COLOR:
+        *pref->varp.colorp = pref->stashed_val.color;
+        break;
+
+    case PREF_STATIC_TEXT:
+    case PREF_UAT:
+    case PREF_CUSTOM:
+        break;
+
+    case PREF_OBSOLETE:
+        g_assert_not_reached();
+        break;
+    }
+    return 0;
+}
+
+void
+reset_stashed_pref(pref_t *pref) {
+    switch (pref->type) {
+
+    case PREF_DECODE_AS_UINT:
+        pref->stashed_val.uint = pref->default_val.uint;
+        break;
+
+    case PREF_UINT:
+        pref->stashed_val.uint = pref->default_val.uint;
+        break;
+
+    case PREF_BOOL:
+        pref->stashed_val.boolval = pref->default_val.boolval;
+        break;
+
+    case PREF_ENUM:
+        pref->stashed_val.enumval = pref->default_val.enumval;
+        break;
+
+    case PREF_STRING:
+    case PREF_FILENAME:
+    case PREF_DIRNAME:
+        g_free(pref->stashed_val.string);
+        pref->stashed_val.string = g_strdup(pref->default_val.string);
+        break;
+
+    case PREF_DECODE_AS_RANGE:
+    case PREF_RANGE:
+        wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+        pref->stashed_val.range = range_copy(wmem_epan_scope(), pref->default_val.range);
+        break;
+
+    case PREF_COLOR:
+        memcpy(&pref->stashed_val.color, &pref->default_val.color, sizeof(color_t));
+        break;
+
+    case PREF_STATIC_TEXT:
+    case PREF_UAT:
+    case PREF_CUSTOM:
+        break;
+
+    case PREF_OBSOLETE:
+        g_assert_not_reached();
+        break;
+    }
+}
+
+guint
+pref_clean_stash(pref_t *pref, gpointer unused _U_)
+{
+    switch (pref->type) {
+
+    case PREF_UINT:
+    case PREF_DECODE_AS_UINT:
+        break;
+
+    case PREF_BOOL:
+        break;
+
+    case PREF_ENUM:
+        break;
+
+    case PREF_STRING:
+    case PREF_FILENAME:
+    case PREF_DIRNAME:
+        if (pref->stashed_val.string != NULL) {
+            g_free(pref->stashed_val.string);
+            pref->stashed_val.string = NULL;
+        }
+        break;
+
+    case PREF_DECODE_AS_RANGE:
+    case PREF_RANGE:
+        if (pref->stashed_val.range != NULL) {
+            wmem_free(wmem_epan_scope(), pref->stashed_val.range);
+            pref->stashed_val.range = NULL;
+        }
+        break;
+
+    case PREF_STATIC_TEXT:
+    case PREF_UAT:
+    case PREF_COLOR:
+    case PREF_CUSTOM:
+        break;
+
+    case PREF_OBSOLETE:
+        g_assert_not_reached();
+        break;
+    }
+    return 0;
+}
+
+#if 0
 /* Return the value assigned to the given uint preference. */
 guint
 prefs_get_uint_preference(pref_t *pref)
@@ -1211,6 +2164,7 @@ prefs_get_uint_preference(pref_t *pref)
         return *pref->varp.uint;
     return 0;
 }
+#endif
 
 /*
  * Call a callback function, with a specified argument, for each preference
@@ -1228,7 +2182,7 @@ prefs_pref_foreach(module_t *module, pref_cb callback, gpointer user_data)
 
     for (elem = g_list_first(module->prefs); elem != NULL; elem = g_list_next(elem)) {
         pref = (pref_t *)elem->data;
-        if (pref->type == PREF_OBSOLETE) {
+        if (IS_PREF_OBSOLETE(pref->type)) {
             /*
              * This preference is no longer supported; it's
              * not a real preference, so we don't call the
@@ -1263,15 +2217,6 @@ static const enum_val_t print_dest_vals[] = {
     { NULL,      NULL,      0 }
 };
 
-static const enum_val_t gui_qt_language[] = {
-    {"Auto-Detect", "auto", 0},
-    {"English", "en", 1},
-    {"French", "fr", 2},
-    {"German", "de", 3},
-    {"Chinese", "zh_CN", 4},
-    {NULL, NULL, -1}
-};
-
 static const enum_val_t st_sort_col_vals[] = {
     { "name",    "Node name (topic/item)", ST_SORT_COL_NAME },
     { "count",   "Item count", ST_SORT_COL_COUNT },
@@ -1406,22 +2351,6 @@ static char * console_log_level_to_str_cb(pref_t* pref, gboolean default_val) {
 #define PRS_COL_NUM                      "column.number"
 static module_t *gui_column_module = NULL;
 
-static void
-column_hidden_free_cb(pref_t* pref)
-{
-    g_free((char *)*pref->varp.string);
-    *pref->varp.string = NULL;
-    g_free(pref->default_val.string);
-    pref->default_val.string = NULL;
-}
-
-static void
-column_hidden_reset_cb(pref_t* pref)
-{
-    g_free((void *)*pref->varp.string);
-    *pref->varp.string = g_strdup(pref->default_val.string);
-}
-
 static prefs_set_pref_e
 column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
 {
@@ -1429,15 +2358,7 @@ column_hidden_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
     fmt_data    *cfmt;
     pref_t  *format_pref;
 
-    if (*pref->varp.string) {
-        if (strcmp(*pref->varp.string, value) != 0) {
-            *changed = TRUE;
-            g_free((void *)*pref->varp.string);
-            *pref->varp.string = g_strdup(value);
-        }
-    } else if (value) {
-        *pref->varp.string = g_strdup(value);
-    }
+    (*changed) |= prefs_set_string_value(pref, value, pref_current);
 
     /*
      * Set the "visible" flag for the existing columns; we need to
@@ -1482,10 +2403,10 @@ column_hidden_to_str_cb(pref_t* pref, gboolean default_val)
     while (clp) {
         gchar *prefs_fmt;
         cfmt = (fmt_data *) clp->data;
-        if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
+        if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
             prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
                     col_format_to_string(cfmt->fmt),
-                    cfmt->custom_field,
+                    cfmt->custom_fields,
                     cfmt->custom_occurrence,
                     cfmt->resolved ? 'R' : 'U');
         } else {
@@ -1496,6 +2417,7 @@ column_hidden_to_str_cb(pref_t* pref, gboolean default_val)
                 g_string_append (cols_hidden, ",");
             g_string_append (cols_hidden, prefs_fmt);
         }
+        g_free(prefs_fmt);
         clp = clp->next;
     }
 
@@ -1570,11 +2492,11 @@ column_format_init_cb(pref_t* pref, GList** value)
         dest_cfmt = g_new(fmt_data,1);
         dest_cfmt->title = g_strdup(src_cfmt->title);
         dest_cfmt->fmt = src_cfmt->fmt;
-        if (src_cfmt->custom_field) {
-            dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
+        if (src_cfmt->custom_fields) {
+            dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
             dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
         } else {
-            dest_cfmt->custom_field = NULL;
+            dest_cfmt->custom_fields = NULL;
             dest_cfmt->custom_occurrence = 0;
         }
         dest_cfmt->visible = src_cfmt->visible;
@@ -1605,11 +2527,11 @@ column_format_reset_cb(pref_t* pref)
         dest_cfmt = g_new(fmt_data,1);
         dest_cfmt->title = g_strdup(src_cfmt->title);
         dest_cfmt->fmt = src_cfmt->fmt;
-        if (src_cfmt->custom_field) {
-            dest_cfmt->custom_field = g_strdup(src_cfmt->custom_field);
+        if (src_cfmt->custom_fields) {
+            dest_cfmt->custom_fields = g_strdup(src_cfmt->custom_fields);
             dest_cfmt->custom_occurrence = src_cfmt->custom_occurrence;
         } else {
-            dest_cfmt->custom_field = NULL;
+            dest_cfmt->custom_fields = NULL;
             dest_cfmt->custom_occurrence = 0;
         }
         dest_cfmt->visible = src_cfmt->visible;
@@ -1658,7 +2580,7 @@ column_format_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
         try_convert_to_custom_column(&col_l_elt->data);
       } else {
         /* We don't need the custom column field on this pass. */
-        g_free(cfmt_check.custom_field);
+        g_free(cfmt_check.custom_fields);
       }
 
       /* Go past the format.  */
@@ -1686,7 +2608,7 @@ column_format_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
     }
 
     prefs_clear_string_list(col_l);
-    column_hidden_free_cb(hidden_pref);
+    free_string_like_preference(hidden_pref);
     return PREFS_SET_OK;
 }
 
@@ -1723,8 +2645,8 @@ column_format_is_default_cb(pref_t* pref)
             def_cfmt = (fmt_data *) def_col->data;
             if ((g_strcmp0(cfmt->title, def_cfmt->title) != 0) ||
                     (cfmt->fmt != def_cfmt->fmt) ||
-                    (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) &&
-                     ((g_strcmp0(cfmt->custom_field, def_cfmt->custom_field) != 0) ||
+                    (((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) &&
+                     ((g_strcmp0(cfmt->custom_fields, def_cfmt->custom_fields) != 0) ||
                       (cfmt->resolved != def_cfmt->resolved)))) {
                 is_default = FALSE;
                 break;
@@ -1752,10 +2674,10 @@ column_format_to_str_cb(pref_t* pref, gboolean default_val)
     while (clp) {
         cfmt = (fmt_data *) clp->data;
         col_l = g_list_append(col_l, g_strdup(cfmt->title));
-        if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_field)) {
+        if ((cfmt->fmt == COL_CUSTOM) && (cfmt->custom_fields)) {
             prefs_fmt = g_strdup_printf("%s:%s:%d:%c",
                     col_format_to_string(cfmt->fmt),
-                    cfmt->custom_field,
+                    cfmt->custom_fields,
                     cfmt->custom_occurrence,
                     cfmt->resolved ? 'R' : 'U');
         } else {
@@ -1766,10 +2688,7 @@ column_format_to_str_cb(pref_t* pref, gboolean default_val)
     }
 
     column_format_str = join_string_list(col_l);
-
-    /* This frees the list of strings, but not the strings to which it
-       refers; they are free'ed in join_string_list(). */
-    g_list_free(col_l);
+    prefs_clear_string_list(col_l);
     return column_format_str;
 }
 
@@ -1804,29 +2723,12 @@ capture_column_init_cb(pref_t* pref, GList** capture_cols_values)
 static void
 capture_column_free_cb(pref_t* pref)
 {
-    GList    *clist = prefs.capture_columns;
-    gchar    *col_name;
-
-    while (clist) {
-        col_name = (gchar *)clist->data;
-        g_free(col_name);
-        clist = g_list_remove_link(clist, clist);
-    }
-    g_list_free(clist);
+    prefs_clear_string_list(prefs.capture_columns);
     prefs.capture_columns = NULL;
 
     if (pref->stashed_val.boolval == TRUE) {
-      GList *dlist;
-      gchar *col;
-
-      dlist = pref->default_val.list;
-      while (dlist != NULL) {
-        col = (gchar *)dlist->data;
-        g_free(col);
-        dlist = g_list_remove_link(dlist, dlist);
-      }
-      g_list_free(dlist);
-      dlist = NULL;
+      prefs_clear_string_list(pref->default_val.list);
+      pref->default_val.list = NULL;
     }
 }
 
@@ -1835,18 +2737,10 @@ capture_column_free_cb(pref_t* pref)
 static void
 capture_column_reset_cb(pref_t* pref)
 {
-    GList *vlist, *dlist;
-    gchar *vcol;
+    GList *vlist = NULL, *dlist;
 
     /* Free the column name strings and remove the links from *pref->varp.list */
-    vlist = *pref->varp.list;
-    while (vlist != NULL) {
-      vcol = (gchar *)vlist->data;
-      g_free(vcol);
-      vlist = g_list_remove_link(vlist, vlist);
-    }
-    g_list_free(vlist);
-    vlist = NULL;
+    prefs_clear_string_list(*pref->varp.list);
 
     for (dlist = pref->default_val.list; dlist != NULL; dlist = g_list_next(dlist)) {
       vlist = g_list_append(vlist, g_strdup((gchar *)dlist->data));
@@ -1857,9 +2751,9 @@ capture_column_reset_cb(pref_t* pref)
 static prefs_set_pref_e
 capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
 {
-    GList   *col_l  = prefs_get_string_list(value);
-    GList    *col_l_elt;
-    gchar   *col_name;
+    GList *col_l  = prefs_get_string_list(value);
+    GList *col_l_elt;
+    gchar *col_name;
     int i;
 
     if (col_l == NULL)
@@ -1896,6 +2790,7 @@ capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
           prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
         }
         pref->varp.list = &prefs.capture_columns;
+        prefs_clear_string_list(col_l);
         return PREFS_SET_SYNTAX_ERR;
       }
       col_l_elt = col_l_elt->next;
@@ -1908,6 +2803,7 @@ capture_column_set_cb(pref_t* pref, const gchar* value, gboolean* changed _U_)
       col_l_elt = col_l_elt->next;
     }
     pref->varp.list = &prefs.capture_columns;
+    g_list_free(col_l);
     return PREFS_SET_OK;
 }
 
@@ -1958,7 +2854,8 @@ capture_column_to_str_cb(pref_t* pref, gboolean default_val)
     GList       *pref_l = default_val ? pref->default_val.list : prefs.capture_columns;
     GList       *clp = g_list_first(pref_l);
     GList       *col_l = NULL;
-    gchar       *col, *capture_column_str;
+    gchar       *col;
+    char        *capture_column_str;
 
     while (clp) {
         col = (gchar *) clp->data;
@@ -1967,39 +2864,14 @@ capture_column_to_str_cb(pref_t* pref, gboolean default_val)
     }
 
     capture_column_str = join_string_list(col_l);
-    /* This frees the list of strings, but not the strings to which it
-       refers; they are free'ed in write_string_list(). */
-    g_list_free(col_l);
+    prefs_clear_string_list(col_l);
     return capture_column_str;
 }
 
-
-static void
-colorized_frame_free_cb(pref_t* pref)
-{
-    g_free((char *)*pref->varp.string);
-    *pref->varp.string = NULL;
-    g_free(pref->default_val.string);
-    pref->default_val.string = NULL;
-
-}
-
-static void
-colorized_frame_reset_cb(pref_t* pref)
-{
-    g_free((void *)*pref->varp.string);
-    *pref->varp.string = g_strdup(pref->default_val.string);
-}
-
 static prefs_set_pref_e
 colorized_frame_set_cb(pref_t* pref, const gchar* value, gboolean* changed)
 {
-    if (strcmp(*pref->varp.string, value) != 0) {
-        *changed = TRUE;
-        g_free((void *)*pref->varp.string);
-        *pref->varp.string = g_strdup(value);
-    }
-
+    (*changed) |= prefs_set_string_value(pref, value, pref_current);
     return PREFS_SET_OK;
 }
 
@@ -2043,11 +2915,15 @@ static module_t *gui_module = NULL;
 static module_t *gui_color_module = NULL;
 static module_t *nameres_module = NULL;
 
-void
+static void
 prefs_register_modules(void)
 {
     module_t *printing, *capture_module, *console_module,
         *gui_layout_module, *gui_font_module;
+#ifdef HAVE_EXTCAP
+    module_t *extcap_module;
+#endif
+
     struct pref_custom_cbs custom_cbs;
 
     if (protocols_module != NULL) {
@@ -2055,10 +2931,23 @@ prefs_register_modules(void)
         return;
     }
 
-    /* Ensure the "global" preferences have been initialized so the
-     * preference API has the proper default values to work from
+#ifdef HAVE_EXTCAP
+    /* GUI
+     * These are "simple" GUI preferences that can be read/written using the
+     * preference module API.  These preferences still use their own
+     * configuration screens for access, but this cuts down on the
+     * preference "string compare list" in set_pref()
      */
-    pre_init_prefs();
+    extcap_module = prefs_register_module(NULL, "extcap", "Extcap Utilities",
+        "Extcap Utilities", NULL, FALSE);
+
+    /* Setting default value to true */
+    prefs.extcap_save_on_start = TRUE;
+    prefs_register_bool_preference(extcap_module, "gui_save_on_start",
+                                   "Save arguments on start of capture",
+                                   "Save arguments on start of capture",
+                                   &prefs.extcap_save_on_start);
+#endif
 
     /* GUI
      * These are "simple" GUI preferences that can be read/written using the
@@ -2074,7 +2963,7 @@ prefs_register_modules(void)
      */
     prefs_register_enum_preference(gui_module, "console_open",
                        "Open a console window",
-                       "Open a console window (WIN32 only)",
+                       "Open a console window (Windows only)",
                        (gint*)(void*)(&prefs.gui_console_open), gui_console_open_type, FALSE);
 
     prefs_register_obsolete_preference(gui_module, "scrollbar_on_right");
@@ -2113,15 +3002,16 @@ prefs_register_modules(void)
 
     gui_column_module = prefs_register_subtree(gui_module, "Columns", "Columns", NULL);
 
-    custom_cbs.free_cb = column_hidden_free_cb;
-    custom_cbs.reset_cb = column_hidden_reset_cb;
+    custom_cbs.free_cb = free_string_like_preference;
+    custom_cbs.reset_cb = reset_string_like_preference;
     custom_cbs.set_cb = column_hidden_set_cb;
     custom_cbs.type_name_cb = column_hidden_type_name_cb;
     custom_cbs.type_description_cb = column_hidden_type_description_cb;
     custom_cbs.is_default_cb = column_hidden_is_default_cb;
     custom_cbs.to_str_cb = column_hidden_to_str_cb;
-    prefs_register_string_custom_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
-        "List all columns to hide in the packet list", &custom_cbs, (const char **)&cols_hidden_list);
+    register_string_like_preference(gui_column_module, PRS_COL_HIDDEN, "Packet list hidden columns",
+        "List all columns to hide in the packet list",
+        &cols_hidden_list, PREF_CUSTOM, &custom_cbs, FALSE);
 
     custom_cbs.free_cb = column_format_free_cb;
     custom_cbs.reset_cb = column_format_reset_cb;
@@ -2153,11 +3043,13 @@ prefs_register_modules(void)
 
     prefs_register_obsolete_preference(gui_font_module, "font_name");
 
-    prefs_register_string_preference(gui_font_module, "gtk2.font_name", "Font name",
-        "Font name for packet list, protocol tree, and hex dump panes. (GTK+)", (const char **)&prefs.gui_gtk2_font_name);
+    register_string_like_preference(gui_font_module, "gtk2.font_name", "Font name",
+        "Font name for packet list, protocol tree, and hex dump panes. (GTK+)",
+        &prefs.gui_gtk2_font_name, PREF_STRING, NULL, TRUE);
 
-    prefs_register_string_preference(gui_font_module, "qt.font_name", "Font name",
-        "Font name for packet list, protocol tree, and hex dump panes. (Qt)", (const char **)&prefs.gui_qt_font_name);
+    register_string_like_preference(gui_font_module, "qt.font_name", "Font name",
+        "Font name for packet list, protocol tree, and hex dump panes. (Qt)",
+        &prefs.gui_qt_font_name, PREF_STRING, NULL, TRUE);
 
     /* User Interface : Colors */
     gui_color_module = prefs_register_subtree(gui_module, "Colors", "Colors", NULL);
@@ -2186,25 +3078,27 @@ prefs_register_modules(void)
     prefs_register_color_preference(gui_color_module, "stream.server.bg", "TCP stream window color preference",
         "TCP stream window color preference", &prefs.st_server_bg);
 
-    custom_cbs.free_cb = colorized_frame_free_cb;
-    custom_cbs.reset_cb = colorized_frame_reset_cb;
+    custom_cbs.free_cb = free_string_like_preference;
+    custom_cbs.reset_cb = reset_string_like_preference;
     custom_cbs.set_cb = colorized_frame_set_cb;
     custom_cbs.type_name_cb = colorized_frame_type_name_cb;
     custom_cbs.type_description_cb = colorized_frame_type_description_cb;
     custom_cbs.is_default_cb = colorized_frame_is_default_cb;
     custom_cbs.to_str_cb = colorized_frame_to_str_cb;
-    prefs_register_string_custom_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
-        "Filter Colorized Foreground", &custom_cbs, (const char **)&prefs.gui_colorized_fg);
+    register_string_like_preference(gui_column_module, "colorized_frame.fg", "Colorized Foreground",
+        "Filter Colorized Foreground",
+        &prefs.gui_colorized_fg, PREF_CUSTOM, &custom_cbs, TRUE);
 
-    custom_cbs.free_cb = colorized_frame_free_cb;
-    custom_cbs.reset_cb = colorized_frame_reset_cb;
+    custom_cbs.free_cb = free_string_like_preference;
+    custom_cbs.reset_cb = reset_string_like_preference;
     custom_cbs.set_cb = colorized_frame_set_cb;
     custom_cbs.type_name_cb = colorized_frame_type_name_cb;
     custom_cbs.type_description_cb = colorized_frame_type_description_cb;
     custom_cbs.is_default_cb = colorized_frame_is_default_cb;
     custom_cbs.to_str_cb = colorized_frame_to_str_cb;
-    prefs_register_string_custom_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
-        "Filter Colorized Background", &custom_cbs, (const char **)&prefs.gui_colorized_bg);
+    register_string_like_preference(gui_column_module, "colorized_frame.bg", "Colorized Background",
+        "Filter Colorized Background",
+        &prefs.gui_colorized_bg, PREF_CUSTOM, &custom_cbs, TRUE);
 
     prefs_register_color_preference(gui_color_module, "color_filter_bg.valid", "Valid color filter background",
         "Valid color filter background", &prefs.gui_text_valid);
@@ -2232,8 +3126,9 @@ prefs_register_modules(void)
                                    10,
                                    &prefs.gui_recent_df_entries_max);
 
-    prefs_register_directory_preference(gui_module, "fileopen.dir", "Start Directory",
-        "Directory to start in when opening File Open dialog.", (const char **)&prefs.gui_fileopen_dir);
+    register_string_like_preference(gui_module, "fileopen.dir", "Start Directory",
+        "Directory to start in when opening File Open dialog.",
+        &prefs.gui_fileopen_dir, PREF_DIRNAME, NULL, TRUE);
 
     prefs_register_obsolete_preference(gui_module, "fileopen.remembered_dir");
 
@@ -2273,9 +3168,10 @@ prefs_register_modules(void)
                                    "Save window maximized state at exit?",
                                    &prefs.gui_geometry_save_maximized);
 
+    /* GTK+ only */
     prefs_register_bool_preference(gui_module, "macosx_style",
-                                   "Use Mac OS X style",
-                                   "Use Mac OS X style (Mac OS X with native GTK only)?",
+                                   "Use OS X style",
+                                   "Use OS X style (OS X with native GTK only)?",
                                    &prefs.gui_macosx_style);
 
     prefs_register_obsolete_preference(gui_module, "geometry.main.x");
@@ -2294,8 +3190,9 @@ prefs_register_modules(void)
                        "Filter Toolbar style",
                        &prefs.gui_toolbar_filter_style, gui_toolbar_style, FALSE);
 
-    prefs_register_string_preference(gui_module, "webbrowser", "The path to the webbrowser",
-        "The path to the webbrowser (Ex: mozilla)", (const char **)&prefs.gui_webbrowser);
+    register_string_like_preference(gui_module, "webbrowser", "The path to the webbrowser",
+        "The path to the webbrowser (Ex: mozilla)",
+        &prefs.gui_webbrowser, PREF_STRING, NULL, TRUE);
 
     prefs_register_bool_preference(gui_module, "update.enabled",
                                    "Check for updates",
@@ -2313,11 +3210,17 @@ prefs_register_modules(void)
                                    10,
                                    &prefs.gui_update_interval);
 
-    prefs_register_string_preference(gui_module, "window_title", "Custom window title",
-        "Custom window title. (Appended to existing titles.)", (const char **)&prefs.gui_window_title);
+    register_string_like_preference(gui_module, "window_title", "Custom window title",
+        "Custom window title to be appended to the existing title\n%P = profile name\n%V = version info",
+        &prefs.gui_window_title, PREF_STRING, NULL, TRUE);
 
-    prefs_register_string_preference(gui_module, "start_title", "Custom start page title",
-        "Custom start page title", (const char**)(&prefs.gui_start_title));
+    register_string_like_preference(gui_module, "prepend_window_title", "Custom window title prefix",
+        "Custom window title to be prepended to the existing title\n%P = profile name\n%V = version info",
+        &prefs.gui_prepend_window_title, PREF_STRING, NULL, TRUE);
+
+    register_string_like_preference(gui_module, "start_title", "Custom start page title",
+        "Custom start page title",
+        &prefs.gui_start_title, PREF_STRING, NULL, TRUE);
 
     prefs_register_enum_preference(gui_module, "version_placement",
                        "Show version in the start page and/or main screen's title bar",
@@ -2325,21 +3228,18 @@ prefs_register_modules(void)
                        (gint*)(void*)(&prefs.gui_version_placement), gui_version_placement_type, FALSE);
 
     prefs_register_bool_preference(gui_module, "auto_scroll_on_expand",
-                                   "Automatically scroll the recently expanded item",
-                                   "Automatically scroll the recently expanded item",
+                                   "Automatically scroll packet details",
+                                   "When selecting a new packet, automatically scroll"
+                                   "to the packet detail item that matches the most"
+                                   "recently selected item",
                                    &prefs.gui_auto_scroll_on_expand);
 
     prefs_register_uint_preference(gui_module, "auto_scroll_percentage",
-                                   "The percentage down the view the recently expanded item should be scrolled",
-                                   "The percentage down the view the recently expanded item should be scrolled",
+                                   "Packet detail scroll percentage",
+                                   "The percentage down the view the recently expanded detail item should be scrolled",
                                    10,
                                    &prefs.gui_auto_scroll_percentage);
 
-    prefs_register_enum_preference(gui_module, "qt_language",
-                       "Qt Language",
-                       "Qt Language",
-                       &prefs.gui_qt_language, gui_qt_language, FALSE);
-
     /* User Interface : Layout */
     gui_layout_module = prefs_register_subtree(gui_module, "Layout", "Layout", gui_layout_callback);
 
@@ -2364,10 +3264,48 @@ prefs_register_modules(void)
                        "Layout content of the pane 3",
                        (gint*)(void*)(&prefs.gui_layout_content_3), gui_layout_content, FALSE);
 
+    prefs_register_bool_preference(gui_layout_module, "packet_list_separator.enabled",
+                                   "Enable Packet List Separator",
+                                   "Enable Packet List Separator",
+                                   &prefs.gui_qt_packet_list_separator);
+
     prefs_register_bool_preference(gui_module, "packet_editor.enabled",
                                    "Enable Packet Editor",
                                    "Enable Packet Editor (Experimental)",
                                    &prefs.gui_packet_editor);
+
+    prefs_register_enum_preference(gui_module, "packet_list_elide_mode",
+                       "Elide mode",
+                       "The position of \"...\" in packet list text.",
+                       (gint*)(void*)(&prefs.gui_packet_list_elide_mode), gui_packet_list_elide_mode, FALSE);
+
+    prefs_register_bool_preference(gui_layout_module, "packet_list_show_related",
+                                   "Show Related Packets",
+                                   "Show related packet indicators in the first column",
+                                   &prefs.gui_packet_list_show_related);
+
+    prefs_register_bool_preference(gui_layout_module, "packet_list_show_minimap",
+                                   "Enable Intelligent Scroll Bar",
+                                   "Show the intelligent scroll bar (a minimap of packet list colors in the scrollbar)",
+                                   &prefs.gui_packet_list_show_minimap);
+
+
+    prefs_register_bool_preference(gui_module, "interfaces_show_hidden",
+                                   "Show hidden interfaces",
+                                   "Show all interfaces, including interfaces marked as hidden",
+                                   &prefs.gui_interfaces_show_hidden);
+
+#ifdef HAVE_PCAP_REMOTE
+    prefs_register_bool_preference(gui_module, "interfaces_remote_display",
+                                   "Show Remote interfaces",
+                                   "Show remote interfaces in the interface selection",
+                                   &prefs.gui_interfaces_remote_display);
+#endif
+
+    register_string_like_preference(gui_module, "interfaces_hidden_types", "Hide interface types in list",
+        "Hide the given interface types in the startup list",
+        &prefs.gui_interfaces_hide_types, PREF_STRING, NULL, TRUE);
+
     /* Console
      * These are preferences that can be read/written using the
      * preference module API.  These preferences still use their own
@@ -2375,7 +3313,7 @@ prefs_register_modules(void)
      * preference "string compare list" in set_pref()
      */
     console_module = prefs_register_module(NULL, "console", "Console",
-        "CONSOLE", NULL, FALSE);
+        "Console logging and debugging output", NULL, FALSE);
 
     custom_cbs.free_cb = custom_pref_no_cb;
     custom_cbs.reset_cb = console_log_level_reset_cb;
@@ -2385,7 +3323,12 @@ prefs_register_modules(void)
     custom_cbs.is_default_cb = console_log_level_is_default_cb;
     custom_cbs.to_str_cb = console_log_level_to_str_cb;
     prefs_register_uint_custom_preference(console_module, "log.level", "logging level",
-        "A bitmask of glib log levels", &custom_cbs, &prefs.console_log_level);
+        "A bitmask of GLib log levels", &custom_cbs, &prefs.console_log_level);
+
+    prefs_register_bool_preference(console_module, "incomplete_dissectors_check_debug",
+                                   "Print debug line for incomplete dissectors",
+                                   "Look for dissectors that left some bytes undecoded (debug)",
+                                   &prefs.incomplete_dissectors_check_debug);
 
     /* Capture
      * These are preferences that can be read/written using the
@@ -2394,52 +3337,60 @@ prefs_register_modules(void)
      * preference "string compare list" in set_pref()
      */
     capture_module = prefs_register_module(NULL, "capture", "Capture",
-        "CAPTURE", NULL, FALSE);
+        "Capture preferences", NULL, FALSE);
 
-    prefs_register_string_preference(capture_module, "device", "Default capture device",
-        "Default capture device", (const char **)&prefs.capture_device);
+    register_string_like_preference(capture_module, "device", "Default capture device",
+        "Default capture device",
+        &prefs.capture_device, PREF_STRING, NULL, FALSE);
 
-    prefs_register_string_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
+    register_string_like_preference(capture_module, "devices_linktypes", "Interface link-layer header type",
         "Interface link-layer header types (Ex: en0(1),en1(143),...)",
-        (const char **)&prefs.capture_devices_linktypes);
+        &prefs.capture_devices_linktypes, PREF_STRING, NULL, FALSE);
 
-    prefs_register_string_preference(capture_module, "devices_descr", "Interface descriptions",
+    register_string_like_preference(capture_module, "devices_descr", "Interface descriptions",
         "Interface descriptions (Ex: eth0(eth0 descr),eth1(eth1 descr),...)",
-        (const char **)&prefs.capture_devices_descr);
+        &prefs.capture_devices_descr, PREF_STRING, NULL, FALSE);
 
-    prefs_register_string_preference(capture_module, "devices_hide", "Hide interface",
-        "Hide interface? (Ex: eth0,eth3,...)", (const char **)&prefs.capture_devices_hide);
+    register_string_like_preference(capture_module, "devices_hide", "Hide interface",
+        "Hide interface? (Ex: eth0,eth3,...)",
+        &prefs.capture_devices_hide, PREF_STRING, NULL, FALSE);
 
-    prefs_register_string_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
+    register_string_like_preference(capture_module, "devices_monitor_mode", "Capture in monitor mode",
         "By default, capture in monitor mode on interface? (Ex: eth0,eth3,...)",
-        (const char **)&prefs.capture_devices_monitor_mode);
+        &prefs.capture_devices_monitor_mode, PREF_STRING, NULL, FALSE);
 
-#if defined(_WIN32) || defined(HAVE_PCAP_CREATE)
-    prefs_register_string_preference(capture_module, "devices_buffersize", "Interface buffer size",
+#ifdef CAN_SET_CAPTURE_BUFFER_SIZE
+    register_string_like_preference(capture_module, "devices_buffersize", "Interface buffer size",
         "Interface buffer size (Ex: en0(1),en1(143),...)",
-        ((const char **)&prefs.capture_devices_buffersize));
+        &prefs.capture_devices_buffersize, PREF_STRING, NULL, FALSE);
 #endif
 
-    prefs_register_string_preference(capture_module, "devices_snaplen", "Interface snap length",
+    register_string_like_preference(capture_module, "devices_snaplen", "Interface snap length",
         "Interface snap length (Ex: en0(65535),en1(1430),...)",
-        (const char **)&prefs.capture_devices_snaplen);
+        &prefs.capture_devices_snaplen, PREF_STRING, NULL, FALSE);
 
-    prefs_register_string_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
+    register_string_like_preference(capture_module, "devices_pmode", "Interface promiscuous mode",
         "Interface promiscuous mode (Ex: en0(0),en1(1),...)",
-        (const char **)&prefs.capture_devices_pmode);
+        &prefs.capture_devices_pmode, PREF_STRING, NULL, FALSE);
 
     prefs_register_bool_preference(capture_module, "prom_mode", "Capture in promiscuous mode",
         "Capture in promiscuous mode?", &prefs.capture_prom_mode);
 
+    register_string_like_preference(capture_module, "devices_filter", "Interface capture filter",
+        "Interface capture filter (Ex: en0(tcp),en1(udp),...)",
+        &prefs.capture_devices_filter, PREF_STRING, NULL, FALSE);
+
     prefs_register_bool_preference(capture_module, "pcap_ng", "Capture in Pcap-NG format",
         "Capture in Pcap-NG format?", &prefs.capture_pcap_ng);
 
     prefs_register_bool_preference(capture_module, "real_time_update", "Update packet list in real time during capture",
         "Update packet list in real time during capture?", &prefs.capture_real_time);
 
+    /* We might want to make this a "recent" setting. */
     prefs_register_bool_preference(capture_module, "auto_scroll", "Scroll packet list during capture",
         "Scroll packet list during capture?", &prefs.capture_auto_scroll);
 
+    /* GTK+ only */
     prefs_register_bool_preference(capture_module, "show_info", "Show capture info dialog while capturing",
         "Show capture info dialog while capturing?", &prefs.capture_show_info);
 
@@ -2477,13 +3428,14 @@ prefs_register_modules(void)
                                    &prefs.pr_dest, print_dest_vals, TRUE);
 
 #ifndef _WIN32
-    prefs_register_string_preference(printing, "command", "Command",
-        "Output gets piped to this command when the destination is set to \"command\"", (const char**)(&prefs.pr_cmd));
+    register_string_like_preference(printing, "command", "Command",
+        "Output gets piped to this command when the destination is set to \"command\"",
+        &prefs.pr_cmd, PREF_STRING, NULL, TRUE);
 #endif
 
-    prefs_register_filename_preference(printing, "file", "File",
-        "This is the file that gets written to when the destination is set to \"file\"", (const char**)(&prefs.pr_file));
-
+    register_string_like_preference(printing, "file", "File",
+        "This is the file that gets written to when the destination is set to \"file\"",
+        &prefs.pr_file, PREF_FILENAME, NULL, TRUE);
 
     /* Statistics */
     stats_module = prefs_register_module(NULL, "statistics", "Statistics",
@@ -2580,6 +3532,16 @@ prefs_register_modules(void)
                                    "Display all hidden protocol items in the packet list.",
                                    &prefs.display_hidden_proto_items);
 
+    prefs_register_bool_preference(protocols_module, "display_byte_fields_with_spaces",
+                                   "Display byte fields with a space character between bytes",
+                                   "Display all byte fields with a space character between each byte in the packet list.",
+                                   &prefs.display_byte_fields_with_spaces);
+
+    prefs_register_bool_preference(protocols_module, "enable_incomplete_dissectors_check",
+                                   "Look for incomplete dissectors",
+                                   "Look for dissectors that left some bytes undecoded.",
+                                   &prefs.enable_incomplete_dissectors_check);
+
     /* Obsolete preferences
      * These "modules" were reorganized/renamed to correspond to their GUI
      * configuration screen within the preferences dialog
@@ -2599,100 +3561,98 @@ prefs_register_modules(void)
 GList *
 prefs_get_string_list(const gchar *str)
 {
-  enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
-
-  gint      state = PRE_STRING, i = 0, j = 0;
-  gboolean  backslash = FALSE;
-  guchar    cur_c;
-  gchar    *slstr = NULL;
-  GList    *sl = NULL;
-
-  /* Allocate a buffer for the first string.   */
-  slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
-  j = 0;
-
-  for (;;) {
-    cur_c = str[i];
-    if (cur_c == '\0') {
-      /* It's the end of the input, so it's the end of the string we
-         were working on, and there's no more input. */
-      if (state == IN_QUOT || backslash) {
-        /* We were in the middle of a quoted string or backslash escape,
-           and ran out of characters; that's an error.  */
-        g_free(slstr);
-        prefs_clear_string_list(sl);
-        return NULL;
-      }
-      slstr[j] = '\0';
-      sl = g_list_append(sl, slstr);
-      break;
-    }
-    if (cur_c == '"' && ! backslash) {
-      switch (state) {
-        case PRE_STRING:
-          /* We hadn't yet started processing a string; this starts the
-             string, and we're now quoting.  */
-          state = IN_QUOT;
-          break;
-        case IN_QUOT:
-          /* We're in the middle of a quoted string, and we saw a quotation
-             mark; we're no longer quoting.   */
-          state = NOT_IN_QUOT;
-          break;
-        case NOT_IN_QUOT:
-          /* We're working on a string, but haven't seen a quote; we're
-             now quoting.  */
-          state = IN_QUOT;
-          break;
-        default:
-          break;
-      }
-    } else if (cur_c == '\\' && ! backslash) {
-      /* We saw a backslash, and the previous character wasn't a
-         backslash; escape the next character.
-
-         This also means we've started a new string. */
-      backslash = TRUE;
-      if (state == PRE_STRING)
-        state = NOT_IN_QUOT;
-    } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
-      /* We saw a comma, and we're not in the middle of a quoted string
-         and it wasn't preceded by a backslash; it's the end of
-         the string we were working on...  */
-      slstr[j] = '\0';
-      sl = g_list_append(sl, slstr);
-
-      /* ...and the beginning of a new string.  */
-      state = PRE_STRING;
-      slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
-      j = 0;
-    } else if (!isspace(cur_c) || state != PRE_STRING) {
-      /* Either this isn't a white-space character, or we've started a
-         string (i.e., already seen a non-white-space character for that
-         string and put it into the string).
-
-         The character is to be put into the string; do so if there's
-         room.  */
-      if (j < COL_MAX_LEN) {
-        slstr[j] = cur_c;
-        j++;
-      }
+    enum { PRE_STRING, IN_QUOT, NOT_IN_QUOT };
+
+    gint      state = PRE_STRING, i = 0, j = 0;
+    gboolean  backslash = FALSE;
+    guchar    cur_c;
+    gchar    *slstr = NULL;
+    GList    *sl = NULL;
+
+    /* Allocate a buffer for the first string.   */
+    slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
+    j = 0;
+
+    for (;;) {
+        cur_c = str[i];
+        if (cur_c == '\0') {
+            /* It's the end of the input, so it's the end of the string we
+               were working on, and there's no more input. */
+            if (state == IN_QUOT || backslash) {
+                /* We were in the middle of a quoted string or backslash escape,
+                   and ran out of characters; that's an error.  */
+                g_free(slstr);
+                prefs_clear_string_list(sl);
+                return NULL;
+            }
+            slstr[j] = '\0';
+            sl = g_list_append(sl, slstr);
+            break;
+        }
+        if (cur_c == '"' && ! backslash) {
+            switch (state) {
+            case PRE_STRING:
+                /* We hadn't yet started processing a string; this starts the
+                   string, and we're now quoting.  */
+                state = IN_QUOT;
+                break;
+            case IN_QUOT:
+                /* We're in the middle of a quoted string, and we saw a quotation
+                   mark; we're no longer quoting.   */
+                state = NOT_IN_QUOT;
+                break;
+            case NOT_IN_QUOT:
+                /* We're working on a string, but haven't seen a quote; we're
+                   now quoting.  */
+                state = IN_QUOT;
+                break;
+            default:
+                break;
+            }
+        } else if (cur_c == '\\' && ! backslash) {
+            /* We saw a backslash, and the previous character wasn't a
+               backslash; escape the next character.
+
+               This also means we've started a new string. */
+            backslash = TRUE;
+            if (state == PRE_STRING)
+                state = NOT_IN_QUOT;
+        } else if (cur_c == ',' && state != IN_QUOT && ! backslash) {
+            /* We saw a comma, and we're not in the middle of a quoted string
+               and it wasn't preceded by a backslash; it's the end of
+               the string we were working on...  */
+            slstr[j] = '\0';
+            sl = g_list_append(sl, slstr);
+
+            /* ...and the beginning of a new string.  */
+            state = PRE_STRING;
+            slstr = (gchar *) g_malloc(sizeof(gchar) * COL_MAX_LEN);
+            j = 0;
+        } else if (!g_ascii_isspace(cur_c) || state != PRE_STRING) {
+            /* Either this isn't a white-space character, or we've started a
+               string (i.e., already seen a non-white-space character for that
+               string and put it into the string).
+
+               The character is to be put into the string; do so if there's
+               room.  */
+            if (j < COL_MAX_LEN) {
+                slstr[j] = cur_c;
+                j++;
+            }
 
-      /* If it was backslash-escaped, we're done with the backslash escape.  */
-      backslash = FALSE;
+            /* If it was backslash-escaped, we're done with the backslash escape.  */
+            backslash = FALSE;
+        }
+        i++;
     }
-    i++;
-  }
-  return(sl);
+    return(sl);
 }
 
-static char *
-join_string_list(GList *sl)
+char *join_string_list(GList *sl)
 {
     GString      *joined_str = g_string_new("");
     GList        *cur, *first;
     gchar        *str;
-    gchar        *quoted_str;
     guint         item_count = 0;
 
     cur = first = g_list_first(sl);
@@ -2709,9 +3669,20 @@ join_string_list(GList *sl)
         } else
             g_string_append_c(joined_str, ' ');
 
-        quoted_str = g_strescape(str, "");
-        g_string_append_printf(joined_str, "\"%s\"", quoted_str);
-        g_free(quoted_str);
+        g_string_append_c(joined_str, '"');
+        while (*str) {
+            gunichar uc = g_utf8_get_char (str);
+
+            if (uc == '"' || uc == '\\')
+                g_string_append_c(joined_str, '\\');
+
+            if (g_unichar_isprint(uc))
+                g_string_append_unichar (joined_str, uc);
+
+            str = g_utf8_next_char (str);
+        }
+
+        g_string_append_c(joined_str, '"');
 
         cur = cur->next;
     }
@@ -2721,12 +3692,9 @@ join_string_list(GList *sl)
 void
 prefs_clear_string_list(GList *sl)
 {
-  GList *l = sl;
-
-  while (l) {
-    g_free(l->data);
-    l = g_list_remove_link(l, l);
-  }
+    /* g_list_free_full() only exists since 2.28. */
+    g_list_foreach(sl, (GFunc)g_free, NULL);
+    g_list_free(sl);
 }
 
 /*
@@ -2737,7 +3705,7 @@ prefs_clear_string_list(GList *sl)
  * 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
+ * Otherwise, if a string matches a "description" 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
@@ -2766,6 +3734,45 @@ find_val_for_string(const char *needle, const enum_val_t *haystack,
     return default_value;
 }
 
+
+/* Array of columns that have been migrated to custom columns */
+struct deprecated_columns {
+    const gchar *col_fmt;
+    const gchar *col_expr;
+};
+static struct deprecated_columns migrated_columns[] = {
+    { /* COL_COS_VALUE */ "%U", "vlan.priority" },
+    { /* COL_CIRCUIT_ID */ "%c", "iax2.call" },
+    { /* COL_BSSGP_TLLI */ "%l", "bssgp.tlli" },
+    { /* COL_HPUX_SUBSYS */ "%H", "nettl.subsys" },
+    { /* COL_HPUX_DEVID */ "%P", "nettl.devid" },
+    { /* COL_FR_DLCI */ "%C", "fr.dlci" },
+    { /* COL_REL_CONV_TIME */ "%rct", "tcp.time_relative" },
+    { /* COL_DELTA_CONV_TIME */ "%dct", "tcp.time_delta" },
+    { /* COL_OXID */ "%XO", "fc.ox_id" },
+    { /* COL_RXID */ "%XR", "fc.rx_id" },
+    { /* COL_SRCIDX */ "%Xd", "mdshdr.srcidx" },
+    { /* COL_DSTIDX */ "%Xs", "mdshdr.dstidx" },
+    { /* COL_DCE_CTX */ "%z", "dcerpc.cn_ctx_id" }
+};
+
+static gboolean
+is_deprecated_column_format(const gchar* fmt)
+{
+    guint haystack_idx;
+
+    for (haystack_idx = 0;
+         haystack_idx < G_N_ELEMENTS(migrated_columns);
+         ++haystack_idx) {
+
+        if (strcmp(migrated_columns[haystack_idx].col_fmt, fmt) == 0) {
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
 /* Preferences file format:
  * - Configuration directives start at the beginning of the line, and
  *   are terminated with a colon.
@@ -2789,259 +3796,284 @@ print.file: /a/very/long/path/
 static gboolean
 parse_column_format(fmt_data *cfmt, const char *fmt)
 {
-  const gchar *cust_format = col_format_to_string(COL_CUSTOM);
-  size_t cust_format_len = strlen(cust_format);
-  gchar **cust_format_info;
-  char *p;
-  int col_fmt;
-  gchar *col_custom_field;
-  long col_custom_occurrence;
-  gboolean col_resolved;
-
-  /*
-   * Is this a custom column?
-   */
-  if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
-      strncmp(fmt, cust_format, cust_format_len) == 0) {
-    /* Yes. */
-    col_fmt = COL_CUSTOM;
-    cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
-    col_custom_field = g_strdup(cust_format_info[0]);
-    if (col_custom_field && cust_format_info[1]) {
-      col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
-      if (p == cust_format_info[1] || *p != '\0') {
-        /* Not a valid number. */
-        g_free(col_custom_field);
+    const gchar *cust_format = col_format_to_string(COL_CUSTOM);
+    size_t cust_format_len = strlen(cust_format);
+    gchar **cust_format_info;
+    char *p;
+    int col_fmt;
+    gchar *col_custom_fields = NULL;
+    long col_custom_occurrence = 0;
+    gboolean col_resolved = TRUE;
+
+    /*
+     * Is this a custom column?
+     */
+    if ((strlen(fmt) > cust_format_len) && (fmt[cust_format_len] == ':') &&
+        strncmp(fmt, cust_format, cust_format_len) == 0) {
+        /* Yes. */
+        col_fmt = COL_CUSTOM;
+        cust_format_info = g_strsplit(&fmt[cust_format_len+1],":",3); /* add 1 for ':' */
+        col_custom_fields = g_strdup(cust_format_info[0]);
+        if (col_custom_fields && cust_format_info[1]) {
+            col_custom_occurrence = strtol(cust_format_info[1], &p, 10);
+            if (p == cust_format_info[1] || *p != '\0') {
+                /* Not a valid number. */
+                g_free(col_custom_fields);
+                g_strfreev(cust_format_info);
+                return FALSE;
+            }
+        }
+        if (col_custom_fields && cust_format_info[1] && cust_format_info[2]) {
+            col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
+        }
         g_strfreev(cust_format_info);
-        return FALSE;
-      }
     } else {
-      col_custom_occurrence = 0;
+        col_fmt = get_column_format_from_str(fmt);
+        if ((col_fmt == -1) && (!is_deprecated_column_format(fmt)))
+            return FALSE;
     }
-    if (col_custom_field && cust_format_info[1] && cust_format_info[2]) {
-      col_resolved = (cust_format_info[2][0] == 'U') ? FALSE : TRUE;
-    } else {
-      col_resolved = TRUE;
-    }
-    g_strfreev(cust_format_info);
-  } else {
-    col_fmt = get_column_format_from_str(fmt);
-    if (col_fmt == -1)
-      return FALSE;
-    col_custom_field = NULL;
-    col_custom_occurrence = 0;
-    col_resolved = TRUE;
-  }
-
-  cfmt->fmt = col_fmt;
-  cfmt->custom_field = col_custom_field;
-  cfmt->custom_occurrence = (int)col_custom_occurrence;
-  cfmt->resolved = col_resolved;
-  return TRUE;
-}
-
-/* Initialize non-dissector preferences to wired-in default values.
- * (The dissector preferences are assumed to be set to those values
- * by the dissectors.)
- * They may be overridden by the global preferences file or the
- *  user's preferences file.
+
+    cfmt->fmt = col_fmt;
+    cfmt->custom_fields = col_custom_fields;
+    cfmt->custom_occurrence = (int)col_custom_occurrence;
+    cfmt->resolved = col_resolved;
+    return TRUE;
+}
+
+/* Initialize non-dissector preferences to wired-in default values Called
+ * at program startup and any time the profile changes. (The dissector
+ * preferences are assumed to be set to those values by the dissectors.)
+ * They may be overridden by the global preferences file or the user's
+ * preferences file.
  */
 static void
 init_prefs(void)
 {
-  if (prefs_initialized)
-    return;
+    if (prefs_initialized)
+        return;
 
-  uat_load_all();
+    uat_load_all();
 
-  prefs_register_modules();
+    /*
+     * Ensure the "global" preferences have been initialized so the
+     * preference API has the proper default values to work from
+     */
+    pre_init_prefs();
+
+    prefs_register_modules();
 
-  filter_expression_init(TRUE);
+    filter_expression_init();
 
-  prefs_initialized = TRUE;
+    prefs_initialized = TRUE;
 }
 
-/* Initialize non-dissector preferences used by the "register preference" API
- * to default values so the default values can be used when registered
+/*
+ * Initialize non-dissector preferences used by the "register preference" API
+ * to default values so the default values can be used when registered.
+ *
+ * String, filename, and directory preferences will be g_freed so they must
+ * be g_mallocated.
  */
 static void
 pre_init_prefs(void)
 {
-  int         i;
-  gchar       *col_name;
-  fmt_data    *cfmt;
-  static const gchar *col_fmt[DEF_NUM_COLS*2] = {
-                            "No.",      "%m", "Time",        "%t",
-                            "Source",   "%s", "Destination", "%d",
-                            "Protocol", "%p", "Length",      "%L",
-                            "Info",     "%i"};
-
-  if (prefs_pre_initialized)
-     return;
-
-  prefs.pr_format  = PR_FMT_TEXT;
-  prefs.pr_dest    = PR_DEST_CMD;
-  prefs.pr_file    = "wireshark.out";
-  prefs.pr_cmd     = "lpr";
-
-  prefs.gui_altern_colors = FALSE;
-  prefs.gui_expert_composite_eyecandy = FALSE;
-  prefs.gui_ptree_line_style = 0;
-  prefs.gui_ptree_expander_style = 1;
-  prefs.gui_hex_dump_highlight_style = 1;
-  prefs.filter_toolbar_show_in_statusbar = FALSE;
-  prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
-  prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
-  /* These string prefs will be strduped shortly, so we can safely cast away
-   * their constness in these assignments */
+    int         i;
+    gchar       *col_name;
+    fmt_data    *cfmt;
+    static const gchar *col_fmt[DEF_NUM_COLS*2] = {
+        "No.",      "%m", "Time",        "%t",
+        "Source",   "%s", "Destination", "%d",
+        "Protocol", "%p", "Length",      "%L",
+        "Info",     "%i"};
+
+    prefs.pr_format  = PR_FMT_TEXT;
+    prefs.pr_dest    = PR_DEST_CMD;
+    if (prefs.pr_file) g_free(prefs.pr_file);
+    prefs.pr_file    = g_strdup("wireshark.out");
+    if (prefs.pr_cmd) g_free(prefs.pr_cmd);
+    prefs.pr_cmd     = g_strdup("lpr");
+
+    prefs.gui_altern_colors = FALSE;
+    prefs.gui_expert_composite_eyecandy = FALSE;
+    prefs.gui_ptree_line_style = 0;
+    prefs.gui_ptree_expander_style = 1;
+    prefs.gui_hex_dump_highlight_style = 1;
+    prefs.filter_toolbar_show_in_statusbar = FALSE;
+    prefs.gui_toolbar_main_style = TB_STYLE_ICONS;
+    prefs.gui_toolbar_filter_style = TB_STYLE_TEXT;
+    /* These will be g_freed, so they must be g_mallocated. */
+    if (prefs.gui_gtk2_font_name) g_free(prefs.gui_gtk2_font_name);
 #ifdef _WIN32
-  prefs.gui_gtk2_font_name         = (char *) "Lucida Console 10";
+    prefs.gui_gtk2_font_name         = g_strdup("Lucida Console 10");
 #else
-  prefs.gui_gtk2_font_name         = (char *) "Monospace 10";
+    prefs.gui_gtk2_font_name         = g_strdup("Monospace 10");
 #endif
-  /* We try to find the best font in the Qt code */
-  prefs.gui_qt_font_name           = (char *) "";
-  prefs.gui_marked_fg.pixel        =     65535;
-  prefs.gui_marked_fg.red          =     65535;
-  prefs.gui_marked_fg.green        =     65535;
-  prefs.gui_marked_fg.blue         =     65535;
-  prefs.gui_marked_bg.pixel        =         0;
-  prefs.gui_marked_bg.red          =         0;
-  prefs.gui_marked_bg.green        =      8224;
-  prefs.gui_marked_bg.blue         =     10794;
-  prefs.gui_ignored_fg.pixel       =     32767;
-  prefs.gui_ignored_fg.red         =     32767;
-  prefs.gui_ignored_fg.green       =     32767;
-  prefs.gui_ignored_fg.blue        =     32767;
-  prefs.gui_ignored_bg.pixel       =     65535;
-  prefs.gui_ignored_bg.red         =     65535;
-  prefs.gui_ignored_bg.green       =     65535;
-  prefs.gui_ignored_bg.blue        =     65535;
-  prefs.gui_colorized_fg           = "000000,000000,000000,000000,000000,000000,000000,000000,000000,000000";
-  prefs.gui_colorized_bg           = "ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0";
-  prefs.st_client_fg.pixel         =     0;
-  prefs.st_client_fg.red           = 32767;
-  prefs.st_client_fg.green         =     0;
-  prefs.st_client_fg.blue          =     0;
-  prefs.st_client_bg.pixel         =     0;
-  prefs.st_client_bg.red           = 64507;
-  prefs.st_client_bg.green         = 60909;
-  prefs.st_client_bg.blue          = 60909;
-  prefs.st_server_fg.pixel         =     0;
-  prefs.st_server_fg.red           =     0;
-  prefs.st_server_fg.green         =     0;
-  prefs.st_server_fg.blue          = 32767;
-  prefs.st_server_bg.pixel         =     0;
-  prefs.st_server_bg.red           = 60909;
-  prefs.st_server_bg.green         = 60909;
-  prefs.st_server_bg.blue          = 64507;
-  prefs.gui_text_valid.pixel         =     0; /* light green */
-  prefs.gui_text_valid.red           = 0xAFFF;
-  prefs.gui_text_valid.green         = 0xFFFF;
-  prefs.gui_text_valid.blue          = 0xAFFF;
-  prefs.gui_text_invalid.pixel     =     0;  /* light red */
-  prefs.gui_text_invalid.red       = 0xFFFF;
-  prefs.gui_text_invalid.green     = 0xAFFF;
-  prefs.gui_text_invalid.blue      = 0xAFFF;
-  prefs.gui_text_deprecated.pixel  =     0; /* light yellow */
-  prefs.gui_text_deprecated.red    = 0xFFFF;
-  prefs.gui_text_deprecated.green  = 0xFFFF;
-  prefs.gui_text_deprecated.blue   = 0xAFFF;
-  prefs.gui_geometry_save_position = TRUE;
-  prefs.gui_geometry_save_size     = TRUE;
-  prefs.gui_geometry_save_maximized= TRUE;
-  prefs.gui_macosx_style           = TRUE;
-  prefs.gui_console_open           = console_open_never;
-  prefs.gui_fileopen_style         = FO_STYLE_LAST_OPENED;
-  prefs.gui_recent_df_entries_max  = 10;
-  prefs.gui_recent_files_count_max = 10;
-  prefs.gui_fileopen_dir           = (char *) get_persdatafile_dir();
-  prefs.gui_fileopen_preview       = 3;
-  prefs.gui_ask_unsaved            = TRUE;
-  prefs.gui_find_wrap              = TRUE;
-  prefs.gui_use_pref_save          = FALSE;
-  prefs.gui_update_enabled         = TRUE;
-  prefs.gui_update_channel         = UPDATE_CHANNEL_STABLE;
-  prefs.gui_update_interval        = 60*60*24; /* Seconds */
-#ifdef HTML_VIEWER
-  prefs.gui_webbrowser             = (char *) HTML_VIEWER " %s";
-#else
-  prefs.gui_webbrowser             = (char *) "";
+    /* We try to find the best font in the Qt code */
+    if (prefs.gui_qt_font_name) g_free(prefs.gui_qt_font_name);
+    prefs.gui_qt_font_name           = g_strdup("");
+    prefs.gui_marked_fg.red          =     65535;
+    prefs.gui_marked_fg.green        =     65535;
+    prefs.gui_marked_fg.blue         =     65535;
+    prefs.gui_marked_bg.red          =         0;
+    prefs.gui_marked_bg.green        =      8224;
+    prefs.gui_marked_bg.blue         =     10794;
+    prefs.gui_ignored_fg.red         =     32767;
+    prefs.gui_ignored_fg.green       =     32767;
+    prefs.gui_ignored_fg.blue        =     32767;
+    prefs.gui_ignored_bg.red         =     65535;
+    prefs.gui_ignored_bg.green       =     65535;
+    prefs.gui_ignored_bg.blue        =     65535;
+    if (prefs.gui_colorized_fg) g_free(prefs.gui_colorized_fg);
+    prefs.gui_colorized_fg           = g_strdup("000000,000000,000000,000000,000000,000000,000000,000000,000000,000000");
+    if (prefs.gui_colorized_bg) g_free(prefs.gui_colorized_bg);
+    prefs.gui_colorized_bg           = g_strdup("ffc0c0,ffc0ff,e0c0e0,c0c0ff,c0e0e0,c0ffff,c0ffc0,ffffc0,e0e0c0,e0e0e0");
+    prefs.st_client_fg.red           = 32767;
+    prefs.st_client_fg.green         =     0;
+    prefs.st_client_fg.blue          =     0;
+    prefs.st_client_bg.red           = 64507;
+    prefs.st_client_bg.green         = 60909;
+    prefs.st_client_bg.blue          = 60909;
+    prefs.st_server_fg.red           =     0;
+    prefs.st_server_fg.green         =     0;
+    prefs.st_server_fg.blue          = 32767;
+    prefs.st_server_bg.red           = 60909;
+    prefs.st_server_bg.green         = 60909;
+    prefs.st_server_bg.blue          = 64507;
+    prefs.gui_text_valid.red         = 0xAFFF; /* light green */
+    prefs.gui_text_valid.green       = 0xFFFF;
+    prefs.gui_text_valid.blue        = 0xAFFF;
+    prefs.gui_text_invalid.red       = 0xFFFF; /* light red */
+    prefs.gui_text_invalid.green     = 0xAFFF;
+    prefs.gui_text_invalid.blue      = 0xAFFF;
+    prefs.gui_text_deprecated.red    = 0xFFFF; /* light yellow */
+    prefs.gui_text_deprecated.green  = 0xFFFF;
+    prefs.gui_text_deprecated.blue   = 0xAFFF;
+    prefs.gui_geometry_save_position = TRUE;
+    prefs.gui_geometry_save_size     = TRUE;
+    prefs.gui_geometry_save_maximized= TRUE;
+    prefs.gui_macosx_style           = TRUE;
+    prefs.gui_console_open           = console_open_never;
+    prefs.gui_fileopen_style         = FO_STYLE_LAST_OPENED;
+    prefs.gui_recent_df_entries_max  = 10;
+    prefs.gui_recent_files_count_max = 10;
+    if (prefs.gui_fileopen_dir) g_free(prefs.gui_fileopen_dir);
+    prefs.gui_fileopen_dir           = g_strdup(get_persdatafile_dir());
+    prefs.gui_fileopen_preview       = 3;
+    prefs.gui_ask_unsaved            = TRUE;
+    prefs.gui_find_wrap              = TRUE;
+    prefs.gui_use_pref_save          = FALSE;
+    prefs.gui_update_enabled         = TRUE;
+    prefs.gui_update_channel         = UPDATE_CHANNEL_STABLE;
+    prefs.gui_update_interval        = 60*60*24; /* Seconds */
+    if (prefs.gui_webbrowser) g_free(prefs.gui_webbrowser);
+    prefs.gui_webbrowser             = g_strdup("");
+    if (prefs.gui_window_title) g_free(prefs.gui_window_title);
+    prefs.gui_window_title           = g_strdup("");
+    if (prefs.gui_prepend_window_title) g_free(prefs.gui_prepend_window_title);
+    prefs.gui_prepend_window_title   = g_strdup("");
+    if (prefs.gui_start_title) g_free(prefs.gui_start_title);
+    prefs.gui_start_title            = g_strdup("The World's Most Popular Network Protocol Analyzer");
+    prefs.gui_version_placement      = version_both;
+    prefs.gui_auto_scroll_on_expand  = FALSE;
+    prefs.gui_auto_scroll_percentage = 0;
+    prefs.gui_layout_type            = layout_type_5;
+    prefs.gui_layout_content_1       = layout_pane_content_plist;
+    prefs.gui_layout_content_2       = layout_pane_content_pdetails;
+    prefs.gui_layout_content_3       = layout_pane_content_pbytes;
+    prefs.gui_packet_editor          = FALSE;
+    prefs.gui_packet_list_elide_mode = ELIDE_RIGHT;
+    prefs.gui_packet_list_show_related = TRUE;
+    prefs.gui_packet_list_show_minimap = TRUE;
+    if (prefs.gui_interfaces_hide_types) g_free (prefs.gui_interfaces_hide_types);
+    prefs.gui_interfaces_hide_types = g_strdup("");
+    prefs.gui_interfaces_show_hidden = FALSE;
+#ifdef HAVE_PCAP_REMOTE
+    prefs.gui_interfaces_remote_display = TRUE;
 #endif
-  prefs.gui_window_title           = (char *) "";
-  prefs.gui_start_title            = "The World's Most Popular Network Protocol Analyzer";
-  prefs.gui_version_placement      = version_both;
-  prefs.gui_auto_scroll_on_expand  = FALSE;
-  prefs.gui_auto_scroll_percentage = 0;
-  prefs.gui_layout_type            = layout_type_5;
-  prefs.gui_layout_content_1       = layout_pane_content_plist;
-  prefs.gui_layout_content_2       = layout_pane_content_pdetails;
-  prefs.gui_layout_content_3       = layout_pane_content_pbytes;
-  prefs.gui_qt_language            = 0; /* (Auto-Detect) */
-  prefs.gui_packet_editor          = FALSE;
-
-  prefs.col_list = NULL;
-  for (i = 0; i < DEF_NUM_COLS; i++) {
-    cfmt = g_new(fmt_data,1);
-    cfmt->title = g_strdup(col_fmt[i * 2]);
-    parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
-    cfmt->visible = TRUE;
-    cfmt->resolved = TRUE;
-    cfmt->custom_field = NULL;
-    cfmt->custom_occurrence = 0;
-    prefs.col_list = g_list_append(prefs.col_list, cfmt);
-  }
-  prefs.num_cols  = DEF_NUM_COLS;
+
+    prefs.gui_qt_packet_list_separator = FALSE;
+
+    if (prefs.col_list) {
+        free_col_info(prefs.col_list);
+        prefs.col_list = NULL;
+    }
+    for (i = 0; i < DEF_NUM_COLS; i++) {
+        cfmt = g_new(fmt_data,1);
+        cfmt->title = g_strdup(col_fmt[i * 2]);
+        parse_column_format(cfmt, col_fmt[(i * 2) + 1]);
+        cfmt->visible = TRUE;
+        cfmt->resolved = TRUE;
+        cfmt->custom_fields = NULL;
+        cfmt->custom_occurrence = 0;
+        prefs.col_list = g_list_append(prefs.col_list, cfmt);
+    }
+    prefs.num_cols  = DEF_NUM_COLS;
 
 /* set the default values for the capture dialog box */
-  prefs.capture_prom_mode             = TRUE;
+    prefs.capture_prom_mode             = TRUE;
 #ifdef PCAP_NG_DEFAULT
-  prefs.capture_pcap_ng               = TRUE;
+    prefs.capture_pcap_ng               = TRUE;
 #else
-  prefs.capture_pcap_ng               = FALSE;
+    prefs.capture_pcap_ng               = FALSE;
 #endif
-  prefs.capture_real_time             = TRUE;
-  prefs.capture_auto_scroll           = TRUE;
-  prefs.capture_show_info             = FALSE;
+    prefs.capture_real_time             = TRUE;
+    prefs.capture_auto_scroll           = TRUE;
+    prefs.capture_show_info             = FALSE;
 
-  prefs.capture_columns               = NULL;
-  for (i = 0; i < num_capture_cols; i++) {
-    col_name = g_strdup(capture_cols[i]);
-    prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
-  }
+    if (!prefs.capture_columns) {
+        /* First time through */
+        for (i = 0; i < num_capture_cols; i++) {
+            col_name = g_strdup(capture_cols[i]);
+            prefs.capture_columns = g_list_append(prefs.capture_columns, col_name);
+        }
+    }
 
-  prefs.console_log_level          =
-      G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
+    prefs.console_log_level          =
+        G_LOG_LEVEL_WARNING | G_LOG_LEVEL_CRITICAL | G_LOG_LEVEL_ERROR;
 
 /* set the default values for the tap/statistics dialog box */
-  prefs.tap_update_interval    = TAP_UPDATE_DEFAULT_INTERVAL;
-  prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
-  prefs.st_enable_burstinfo = TRUE;
-  prefs.st_burst_showcount = FALSE;
-  prefs.st_burst_resolution = ST_DEF_BURSTRES;
-  prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
-  prefs.st_sort_casesensitve = TRUE;
-  prefs.st_sort_rng_fixorder = TRUE;
-  prefs.st_sort_rng_nameonly = TRUE;
-  prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
-  prefs.st_sort_defdescending = TRUE;
-  prefs.st_sort_showfullname = FALSE;
-  prefs.display_hidden_proto_items = FALSE;
-
-  prefs_pre_initialized = TRUE;
+    prefs.tap_update_interval    = TAP_UPDATE_DEFAULT_INTERVAL;
+    prefs.rtp_player_max_visible = RTP_PLAYER_DEFAULT_VISIBLE;
+    prefs.st_enable_burstinfo = TRUE;
+    prefs.st_burst_showcount = FALSE;
+    prefs.st_burst_resolution = ST_DEF_BURSTRES;
+    prefs.st_burst_windowlen = ST_DEF_BURSTLEN;
+    prefs.st_sort_casesensitve = TRUE;
+    prefs.st_sort_rng_fixorder = TRUE;
+    prefs.st_sort_rng_nameonly = TRUE;
+    prefs.st_sort_defcolflag = ST_SORT_COL_COUNT;
+    prefs.st_sort_defdescending = TRUE;
+    prefs.st_sort_showfullname = FALSE;
+    prefs.display_hidden_proto_items = FALSE;
+    prefs.display_byte_fields_with_spaces = FALSE;
 }
 
 /*
  * Reset a single dissector preference.
  */
-static void
+void
 reset_pref(pref_t *pref)
 {
+    int type;
     if (!pref) return;
 
-    switch (pref->type) {
+    type = pref->type;
+
+    /*
+     * This preference is no longer supported; it's not a
+     * real preference, so we don't reset it (i.e., we
+     * treat it as if it weren't found in the list of
+     * preferences, and we weren't called in the first place).
+     */
+    if (IS_PREF_OBSOLETE(type))
+        return;
+    else
+        RESET_PREF_OBSOLETE(type);
+
+    switch (type) {
 
     case PREF_UINT:
+    case PREF_DECODE_AS_UINT:
         *pref->varp.uint = pref->default_val.uint;
         break;
 
@@ -3063,13 +4095,13 @@ reset_pref(pref_t *pref)
     case PREF_STRING:
     case PREF_FILENAME:
     case PREF_DIRNAME:
-        g_free((void *)*pref->varp.string);
-        *pref->varp.string = g_strdup(pref->default_val.string);
+        reset_string_like_preference(pref);
         break;
 
     case PREF_RANGE:
-        g_free(*pref->varp.range);
-        *pref->varp.range = range_copy(pref->default_val.range);
+    case PREF_DECODE_AS_RANGE:
+        wmem_free(wmem_epan_scope(), *pref->varp.range);
+        *pref->varp.range = range_copy(wmem_epan_scope(), pref->default_val.range);
         break;
 
     case PREF_STATIC_TEXT:
@@ -3077,21 +4109,12 @@ reset_pref(pref_t *pref)
         /* Nothing to do */
         break;
 
-    case PREF_COLOR:
-        *pref->varp.colorp = pref->default_val.color;
-        break;
-
-    case PREF_CUSTOM:
-        pref->custom_cbs.reset_cb(pref);
-        break;
-
-    case PREF_OBSOLETE:
-        /*
-         * This preference is no longer supported; it's not a
-         * real preference, so we don't reset it (i.e., we
-         * treat it as if it weren't found in the list of
-         * preferences, and we weren't called in the first place).
-         */
+    case PREF_COLOR:
+        *pref->varp.colorp = pref->default_val.color;
+        break;
+
+    case PREF_CUSTOM:
+        pref->custom_cbs.reset_cb(pref);
         break;
     }
 }
@@ -3111,7 +4134,7 @@ typedef struct {
  * Reset all preferences for a module.
  */
 static gboolean
-reset_module_prefs(void *value, void *data _U_)
+reset_module_prefs(const void *key _U_, void *value, void *data _U_)
 {
     reset_pref_arg_t arg;
 
@@ -3124,27 +4147,35 @@ reset_module_prefs(void *value, void *data _U_)
 void
 prefs_reset(void)
 {
-  prefs_initialized = FALSE;
-  g_free(prefs.saved_at_version);
-  /*
-   * Unload all UAT preferences.
-   */
-  uat_unload_all();
+    prefs_initialized = FALSE;
+    g_free(prefs.saved_at_version);
+    prefs.saved_at_version = NULL;
+
+    /*
+     * Unload all UAT preferences.
+     */
+    uat_unload_all();
+
+    /*
+     * Unload any loaded MIBs.
+     */
+    oids_cleanup();
 
-  /*
-   * Unload any loaded MIBs.
-   */
-  oids_cleanup();
+    /*
+     * Free the filter expression list.
+     */
+    filter_expression_free(*pfilter_expression_head);
+    *pfilter_expression_head = NULL;
 
-  /*
-   * Reset the non-dissector preferences.
-   */
-  init_prefs();
+    /*
+     * Reset the non-dissector preferences.
+     */
+    init_prefs();
 
-  /*
-   * Reset the non-UAT dissector preferences.
-   */
-  wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
+    /*
+     * Reset the non-UAT dissector preferences.
+     */
+    wmem_tree_foreach(prefs_modules, reset_module_prefs, NULL);
 }
 
 /* Read the preferences file, fill in "prefs", and return a pointer to it.
@@ -3159,292 +4190,314 @@ prefs_reset(void)
    and a pointer to the path of the file into "*pf_path_return", and
    return NULL. */
 e_prefs *
-
 read_prefs(int *gpf_errno_return, int *gpf_read_errno_return,
            char **gpf_path_return, int *pf_errno_return,
            int *pf_read_errno_return, char **pf_path_return)
 {
-  int         err;
-  char        *pf_path;
-  FILE        *pf;
+    int         err;
+    char        *pf_path;
+    FILE        *pf;
 
-  /* clean up libsmi structures before reading prefs */
-  oids_cleanup();
+    /* clean up libsmi structures before reading prefs */
+    oids_cleanup();
 
-  init_prefs();
+    init_prefs();
 
-  /*
-   * If we don't already have the pathname of the global preferences
-   * file, construct it.  Then, in either case, try to open the file.
-   */
-  if (gpf_path == NULL) {
     /*
-     * We don't have the path; try the new path first, and, if that
-     * file doesn't exist, try the old path.
+     * If we don't already have the pathname of the global preferences
+     * file, construct it.  Then, in either case, try to open the file.
      */
-    gpf_path = get_datafile_path(PF_NAME);
-    if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
-      /*
-       * It doesn't exist by the new name; try the old name.
-       */
-      g_free(gpf_path);
-      gpf_path = get_datafile_path(OLD_GPF_NAME);
-      pf = ws_fopen(gpf_path, "r");
+    if (gpf_path == NULL) {
+        /*
+         * We don't have the path; try the new path first, and, if that
+         * file doesn't exist, try the old path.
+         */
+        gpf_path = get_datafile_path(PF_NAME);
+        if ((pf = ws_fopen(gpf_path, "r")) == NULL && errno == ENOENT) {
+            /*
+             * It doesn't exist by the new name; try the old name.
+             */
+            g_free(gpf_path);
+            gpf_path = get_datafile_path(OLD_GPF_NAME);
+            pf = ws_fopen(gpf_path, "r");
+        }
+    } else {
+        /*
+         * We have the path; try it.
+         */
+        pf = ws_fopen(gpf_path, "r");
     }
-  } else {
-    /*
-     * We have the path; try it.
-     */
-    pf = ws_fopen(gpf_path, "r");
-  }
-
-  /*
-   * If we were able to open the file, read it.
-   * XXX - if it failed for a reason other than "it doesn't exist",
-   * report the error.
-   */
-  *gpf_path_return = NULL;
-  if (pf != NULL) {
+
     /*
-     * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
-     * seen.
+     * If we were able to open the file, read it.
+     * XXX - if it failed for a reason other than "it doesn't exist",
+     * report the error.
      */
-    mgcp_tcp_port_count = 0;
-    mgcp_udp_port_count = 0;
-
-    /* We succeeded in opening it; read it. */
-    err = read_prefs_file(gpf_path, pf, set_pref, NULL);
-    if (err != 0) {
-      /* We had an error reading the file; return the errno and the
-         pathname, so our caller can report the error. */
-      *gpf_errno_return = 0;
-      *gpf_read_errno_return = err;
-      *gpf_path_return = gpf_path;
+    *gpf_path_return = NULL;
+    if (pf != NULL) {
+        /*
+         * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
+         * seen.
+         */
+        mgcp_tcp_port_count = 0;
+        mgcp_udp_port_count = 0;
+
+        /* We succeeded in opening it; read it. */
+        err = read_prefs_file(gpf_path, pf, set_pref, NULL);
+        if (err != 0) {
+            /* We had an error reading the file; return the errno and the
+               pathname, so our caller can report the error. */
+            *gpf_errno_return = 0;
+            *gpf_read_errno_return = err;
+            *gpf_path_return = gpf_path;
+        }
+        fclose(pf);
+    } else {
+        /* We failed to open it.  If we failed for some reason other than
+           "it doesn't exist", return the errno and the pathname, so our
+           caller can report the error. */
+        if (errno != ENOENT) {
+            *gpf_errno_return = errno;
+            *gpf_read_errno_return = 0;
+            *gpf_path_return = gpf_path;
+        }
+    }
+
+    /* Construct the pathname of the user's preferences file. */
+    pf_path = get_persconffile_path(PF_NAME, TRUE);
+
+    /* Read the user's preferences file, if it exists. */
+    *pf_path_return = NULL;
+    if ((pf = ws_fopen(pf_path, "r")) != NULL) {
+        /*
+         * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
+         * seen.
+         */
+        mgcp_tcp_port_count = 0;
+        mgcp_udp_port_count = 0;
+
+        /* We succeeded in opening it; read it. */
+        err = read_prefs_file(pf_path, pf, set_pref, NULL);
+        if (err != 0) {
+            /* We had an error reading the file; return the errno and the
+               pathname, so our caller can report the error. */
+            *pf_errno_return = 0;
+            *pf_read_errno_return = err;
+            *pf_path_return = pf_path;
+        } else
+            g_free(pf_path);
+        fclose(pf);
+    } else {
+        /* We failed to open it.  If we failed for some reason other than
+           "it doesn't exist", return the errno and the pathname, so our
+           caller can report the error. */
+        if (errno != ENOENT) {
+            *pf_errno_return = errno;
+            *pf_read_errno_return = 0;
+            *pf_path_return = pf_path;
+        } else
+            g_free(pf_path);
     }
-    fclose(pf);
-  } else {
-    /* We failed to open it.  If we failed for some reason other than
-       "it doesn't exist", return the errno and the pathname, so our
-       caller can report the error. */
-    if (errno != ENOENT) {
-      *gpf_errno_return = errno;
-      *gpf_read_errno_return = 0;
-      *gpf_path_return = gpf_path;
-    }
-  }
-
-  /* Construct the pathname of the user's preferences file. */
-  pf_path = get_persconffile_path(PF_NAME, TRUE);
-
-  /* Read the user's preferences file, if it exists. */
-  *pf_path_return = NULL;
-  if ((pf = ws_fopen(pf_path, "r")) != NULL) {
-    /*
-     * Start out the counters of "mgcp.{tcp,udp}.port" entries we've
-     * seen.
-     */
-    mgcp_tcp_port_count = 0;
-    mgcp_udp_port_count = 0;
-
-    /* We succeeded in opening it; read it. */
-    err = read_prefs_file(pf_path, pf, set_pref, NULL);
-    if (err != 0) {
-      /* We had an error reading the file; return the errno and the
-         pathname, so our caller can report the error. */
-      *pf_errno_return = 0;
-      *pf_read_errno_return = err;
-      *pf_path_return = pf_path;
-    } else
-      g_free(pf_path);
-    fclose(pf);
-  } else {
-    /* We failed to open it.  If we failed for some reason other than
-       "it doesn't exist", return the errno and the pathname, so our
-       caller can report the error. */
-    if (errno != ENOENT) {
-      *pf_errno_return = errno;
-      *pf_read_errno_return = 0;
-      *pf_path_return = pf_path;
-    } else
-      g_free(pf_path);
-  }
 
-  /* load SMI modules if needed */
-  oids_init();
+    /* load SMI modules if needed */
+    oids_init();
 
-  return &prefs;
+    return &prefs;
 }
 
-/* read the preferences file (or similiar) and call the callback
+/* read the preferences file (or similar) and call the callback
  * function to set each key/value pair found */
 int
 read_prefs_file(const char *pf_path, FILE *pf,
                 pref_set_pair_cb pref_set_pair_fct, void *private_data)
 {
-  enum { START, IN_VAR, PRE_VAL, IN_VAL, IN_SKIP };
-  int       got_c, state = START;
-  GString  *cur_val;
-  GString  *cur_var;
-  gboolean  got_val = FALSE;
-  gint      fline = 1, pline = 1;
-  gchar     hint[] = "(save preferences to remove this warning)";
-
-  cur_val = g_string_new("");
-  cur_var = g_string_new("");
-
-  /* Try to read in the profile name in the first line of the preferences file. */
-  got_c = getc(pf);
-  if (got_c) {
-    char firstl[100];
-
-    if (fgets(firstl, 100, pf) != NULL) {
-      if (strncmp((const char *)firstl, " Configuration file for ", 24) == 0) {
-        const gchar *ver = (gchar *)&firstl[24];
-        /* Eliminate the period and LF the end of the string */
-        prefs.saved_at_version = g_strndup(ver, strlen(ver) - 2);
-      }
+    enum {
+        START,    /* beginning of a line */
+        IN_VAR,   /* processing key name */
+        PRE_VAL,  /* finished processing key name, skipping white space befor evalue */
+        IN_VAL,   /* processing value */
+        IN_SKIP   /* skipping to the end of the line */
+    } state = START;
+    int       got_c;
+    GString  *cur_val;
+    GString  *cur_var;
+    gboolean  got_val = FALSE;
+    gint      fline = 1, pline = 1;
+    gchar     hint[] = "(save preferences to remove this warning)";
+    gchar     ver[128];
+
+    cur_val = g_string_new("");
+    cur_var = g_string_new("");
+
+    /* Try to read in the profile name in the first line of the preferences file. */
+    if (fscanf(pf, "# Configuration file for %127[^\r\n]", ver) == 1) {
+        /* Assume trailing period and remove it */
+        g_free(prefs.saved_at_version);
+        prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
     }
-  }
-  rewind(pf);
-
-  while ((got_c = getc(pf)) != EOF) {
-    if (got_c == '\n') {
-      state = START;
-      fline++;
-      continue;
-    }
-
-    switch (state) {
-      case START:
-        if (isalnum(got_c)) {
-          if (cur_var->len > 0) {
-            if (got_val) {
-              if (cur_val->len > 0) {
-                if (cur_val->str[cur_val->len-1] == ',') {
-                  /*
-                   * If the pref has a trailing comma, eliminate it.
-                   */
-                  cur_val->str[cur_val->len-1] = '\0';
-                  g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
-                }
-              }
-              /* Call the routine to set the preference; it will parse
-                 the value as appropriate. */
-              switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
+    rewind(pf);
+
+    while ((got_c = ws_getc_unlocked(pf)) != EOF) {
+        if (got_c == '\r') {
+            /* Treat CR-LF at the end of a line like LF, so that if we're reading
+             * a Windows-format file on UN*X, we handle it the same way we'd handle
+             * a UN*X-format file. */
+            got_c = ws_getc_unlocked(pf);
+            if (got_c == EOF)
+                break;
+            if (got_c != '\n') {
+                /* Put back the character after the CR, and process the CR normally. */
+                ungetc(got_c, pf);
+                got_c = '\r';
+            }
+        }
+        if (got_c == '\n') {
+            state = START;
+            fline++;
+            continue;
+        }
 
-              case PREFS_SET_OK:
+        switch (state) {
+        case START:
+            if (g_ascii_isalnum(got_c)) {
+                if (cur_var->len > 0) {
+                    if (got_val) {
+                        if (cur_val->len > 0) {
+                            if (cur_val->str[cur_val->len-1] == ',') {
+                                /*
+                                 * If the pref has a trailing comma, eliminate it.
+                                 */
+                                cur_val->str[cur_val->len-1] = '\0';
+                                ws_g_warning ("%s line %d: trailing comma in \"%s\" %s", pf_path, pline, cur_var->str, hint);
+                            }
+                        }
+                        /* Call the routine to set the preference; it will parse
+                           the value as appropriate.
+
+                           Since we're reading a file, rather than processing
+                           explicit user input, for range preferences, silently
+                           lower values in excess of the range's maximum, rather
+                           than reporting errors and failing. */
+                        switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
+
+                        case PREFS_SET_OK:
+                            break;
+
+                        case PREFS_SET_SYNTAX_ERR:
+                            ws_g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
+                                       cur_var->str, pline, pf_path, hint);
+                            break;
+
+                        case PREFS_SET_NO_SUCH_PREF:
+                            /*
+                             * If "print.command" silently ignore it because it's valid
+                             * on non-Win32 platforms.
+                             */
+                            if (strcmp(cur_var->str, "print.command") != 0)
+                                ws_g_warning ("No such preference \"%s\" at line %d of\n%s %s",
+                                           cur_var->str, pline, pf_path, hint);
+                            prefs.unknown_prefs = TRUE;
+                            break;
+
+                        case PREFS_SET_OBSOLETE:
+                            if (strcmp(cur_var->str, "print.command") != 0)
+                                /* If an attempt is made to save the preferences, a popup warning will be
+                                   displayed stating that obsolete prefs have been detected and the user will
+                                   be given the opportunity to save these prefs under a different profile name.
+                                   The prefs in question need to be listed in the console window so that the
+                                   user can make an informed choice.
+                                */
+                                ws_g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
+                                           cur_var->str, pline, pf_path, hint);
+                            prefs.unknown_prefs = TRUE;
+                            break;
+                        }
+                    } else {
+                        ws_g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
+                    }
+                }
+                state      = IN_VAR;
+                got_val    = FALSE;
+                g_string_truncate(cur_var, 0);
+                g_string_append_c(cur_var, (gchar) got_c);
+                pline = fline;
+            } else if (g_ascii_isspace(got_c) && cur_var->len > 0 && got_val) {
+                state = PRE_VAL;
+            } else if (got_c == '#') {
+                state = IN_SKIP;
+            } else {
+                ws_g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
+            }
+            break;
+        case IN_VAR:
+            if (got_c != ':') {
+                g_string_append_c(cur_var, (gchar) got_c);
+            } else {
+                /* This is a colon (':') */
+                state   = PRE_VAL;
+                g_string_truncate(cur_val, 0);
+                /*
+                 * Set got_val to TRUE to accommodate prefs such as
+                 * "gui.fileopen.dir" that do not require a value.
+                 */
+                got_val = TRUE;
+            }
+            break;
+        case PRE_VAL:
+            if (!g_ascii_isspace(got_c)) {
+                state = IN_VAL;
+                g_string_append_c(cur_val, (gchar) got_c);
+            }
+            break;
+        case IN_VAL:
+            g_string_append_c(cur_val, (gchar) got_c);
+            break;
+        case IN_SKIP:
+            break;
+        }
+    }
+    if (cur_var->len > 0) {
+        if (got_val) {
+            /* Call the routine to set the preference; it will parse
+               the value as appropriate.
+
+               Since we're reading a file, rather than processing
+               explicit user input, for range preferences, silently
+               lower values in excess of the range's maximum, rather
+               than reporting errors and failing. */
+            switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
+
+            case PREFS_SET_OK:
                 break;
 
-              case PREFS_SET_SYNTAX_ERR:
-                g_warning ("Syntax error in preference \"%s\" at line %d of\n%s %s",
-                  cur_var->str, pline, pf_path, hint);
+            case PREFS_SET_SYNTAX_ERR:
+                ws_g_warning ("Syntax error in preference %s at line %d of\n%s %s",
+                           cur_var->str, pline, pf_path, hint);
                 break;
 
-              case PREFS_SET_NO_SUCH_PREF:
-                /*
-                 * If "print.command" silently ignore it because it's valid
-                 * on non-Win32 platforms.
-                 */
-                if (strcmp(cur_var->str, "print.command") != 0)
-                    g_warning ("No such preference \"%s\" at line %d of\n%s %s",
-                      cur_var->str, pline, pf_path, hint);
+            case PREFS_SET_NO_SUCH_PREF:
+                ws_g_warning ("No such preference \"%s\" at line %d of\n%s %s",
+                           cur_var->str, pline, pf_path, hint);
                 prefs.unknown_prefs = TRUE;
                 break;
 
-              case PREFS_SET_OBSOLETE:
-                if (strcmp(cur_var->str, "print.command") != 0)
-                  /* If an attempt is made to save the preferences, a popup warning will be
-                     displayed stating that obsolete prefs have been detected and the user will
-                     be given the opportunity to save these prefs under a different profile name.
-                     The prefs in question need to be listed in the console window so that the
-                     user can make an informed choice.
-                   */
-                  g_warning ("Obsolete preference \"%s\" at line %d of\n%s %s",
-                    cur_var->str, pline, pf_path, hint);
+            case PREFS_SET_OBSOLETE:
                 prefs.unknown_prefs = TRUE;
                 break;
-              }
-            } else {
-              g_warning ("Incomplete preference at line %d: of\n%s %s", pline, pf_path, hint);
             }
-          }
-          state      = IN_VAR;
-          got_val    = FALSE;
-          g_string_truncate(cur_var, 0);
-          g_string_append_c(cur_var, (gchar) got_c);
-          pline = fline;
-        } else if (isspace(got_c) && cur_var->len > 0 && got_val) {
-          state = PRE_VAL;
-        } else if (got_c == '#') {
-          state = IN_SKIP;
         } else {
-          g_warning ("Malformed preference at line %d of\n%s %s", fline, pf_path, hint);
-        }
-        break;
-      case IN_VAR:
-        if (got_c != ':') {
-          g_string_append_c(cur_var, (gchar) got_c);
-        } else {
-          /* This is a colon (':') */
-          state   = PRE_VAL;
-          g_string_truncate(cur_val, 0);
-          /*
-           * Set got_val to TRUE to accommodate prefs such as
-           * "gui.fileopen.dir" that do not require a value.
-           */
-          got_val = TRUE;
-        }
-        break;
-      case PRE_VAL:
-        if (!isspace(got_c)) {
-          state = IN_VAL;
-          g_string_append_c(cur_val, (gchar) got_c);
+            ws_g_warning("Incomplete preference at line %d of\n%s %s",
+                       pline, pf_path, hint);
         }
-        break;
-      case IN_VAL:
-        g_string_append_c(cur_val, (gchar) got_c);
-        break;
-    }
-  }
-  if (cur_var->len > 0) {
-    if (got_val) {
-      /*  Convert the string to a range.  Since we're reading the
-       *  preferences file, silently lower values in excess of the
-       *  range's maximum.
-       */
-      switch (pref_set_pair_fct(cur_var->str, cur_val->str, private_data, FALSE)) {
-
-      case PREFS_SET_OK:
-        break;
-
-      case PREFS_SET_SYNTAX_ERR:
-        g_warning ("Syntax error in preference %s at line %d of\n%s %s",
-          cur_var->str, pline, pf_path, hint);
-        break;
-
-      case PREFS_SET_NO_SUCH_PREF:
-        g_warning ("No such preference \"%s\" at line %d of\n%s %s",
-            cur_var->str, pline, pf_path, hint);
-        prefs.unknown_prefs = TRUE;
-        break;
-
-      case PREFS_SET_OBSOLETE:
-        prefs.unknown_prefs = TRUE;
-        break;
-      }
-    } else {
-      g_warning ("Incomplete preference at line %d of\n%s %s",
-        pline, pf_path, hint);
     }
-  }
 
-  g_string_free(cur_val, TRUE);
-  g_string_free(cur_var, TRUE);
+    g_string_free(cur_val, TRUE);
+    g_string_free(cur_var, TRUE);
 
-  if (ferror(pf))
-    return errno;
-  else
-    return 0;
+    if (ferror(pf))
+        return errno;
+    else
+        return 0;
 }
 
 /*
@@ -3455,7 +4508,8 @@ static gboolean
 prefs_set_uat_pref(char *uat_entry) {
     gchar *p, *colonp;
     uat_t *uat;
-    gchar *err;
+    gchar *err = NULL;
+    gboolean ret;
 
     colonp = strchr(uat_entry, ':');
     if (colonp == NULL)
@@ -3469,7 +4523,7 @@ prefs_set_uat_pref(char *uat_entry) {
      * as we allow it in the preferences file, we might as well
      * allow it here).
      */
-    while (isspace((guchar)*p))
+    while (g_ascii_isspace(*p))
         p++;
     if (*p == '\0') {
         /*
@@ -3487,10 +4541,9 @@ prefs_set_uat_pref(char *uat_entry) {
         return FALSE;
     }
 
-    if (uat_load_str(uat, p, &err)) {
-        return TRUE;
-    }
-    return FALSE;
+    ret = uat_load_str(uat, p, &err);
+    g_free(err);
+    return ret;
 }
 
 /*
@@ -3507,7 +4560,7 @@ prefs_set_pref(char *prefarg)
 
     /*
      * Set the counters of "mgcp.{tcp,udp}.port" entries we've
-     * seen to values that keep us from trying to interpret tham
+     * seen to values that keep us from trying to interpret them
      * as "mgcp.{tcp,udp}.gateway_port" or "mgcp.{tcp,udp}.callagent_port",
      * as, from the command line, we have no way of guessing which
      * the user had in mind.
@@ -3527,7 +4580,7 @@ prefs_set_pref(char *prefarg)
      * as we allow it in the preferences file, we might as well
      * allow it here).
      */
-    while (isspace((guchar)*p))
+    while (g_ascii_isspace(*p))
         p++;
     if (*p == '\0') {
         /*
@@ -3547,6 +4600,68 @@ prefs_set_pref(char *prefarg)
     return ret;
 }
 
+guint prefs_get_uint_value_real(pref_t *pref, pref_source_t source)
+{
+    switch (source)
+    {
+    case pref_default:
+        return pref->default_val.uint;
+        break;
+    case pref_stashed:
+        return pref->stashed_val.uint;
+        break;
+    case pref_current:
+        return *pref->varp.uint;
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return 0;
+}
+
+guint prefs_get_uint_value(const char *module_name, const char* pref_name)
+{
+    return prefs_get_uint_value_real(prefs_find_preference(prefs_find_module(module_name), pref_name), pref_current);
+}
+
+gboolean prefs_set_uint_value(pref_t *pref, guint value, pref_source_t source)
+{
+    gboolean changed = FALSE;
+    switch (source)
+    {
+    case pref_default:
+        if (pref->default_val.uint != value) {
+            pref->default_val.uint = value;
+            changed = TRUE;
+        }
+        break;
+    case pref_stashed:
+        if (pref->stashed_val.uint != value) {
+            pref->stashed_val.uint = value;
+            changed = TRUE;
+        }
+        break;
+    case pref_current:
+        if (*pref->varp.uint != value) {
+            *pref->varp.uint = value;
+            changed = TRUE;
+        }
+        break;
+    default:
+        g_assert_not_reached();
+        break;
+    }
+
+    return changed;
+}
+
+guint prefs_get_uint_base(pref_t *pref)
+{
+    return pref->info.base;
+}
+
 /*
  * Returns TRUE if the given device is hidden
  */
@@ -3607,8 +4722,8 @@ prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
              */
             if (cfmt->fmt != cfmt_hidden.fmt) {
                 /* No. */
-                g_free(cfmt_hidden.custom_field);
-                cfmt_hidden.custom_field = NULL;
+                g_free(cfmt_hidden.custom_fields);
+                cfmt_hidden.custom_fields = NULL;
                 continue;
             }
             if (cfmt->fmt == COL_CUSTOM) {
@@ -3616,18 +4731,18 @@ prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
                  * A custom column has to have the
                  * same custom field and occurrence.
                  */
-                if (cfmt_hidden.custom_field && cfmt->custom_field) {
-                    if (strcmp(cfmt->custom_field,
-                               cfmt_hidden.custom_field) != 0) {
+                if (cfmt_hidden.custom_fields && cfmt->custom_fields) {
+                    if (strcmp(cfmt->custom_fields,
+                               cfmt_hidden.custom_fields) != 0) {
                         /* Different fields. */
-                        g_free(cfmt_hidden.custom_field);
-                        cfmt_hidden.custom_field = NULL;
+                        g_free(cfmt_hidden.custom_fields);
+                        cfmt_hidden.custom_fields = NULL;
                         continue;
                     }
                     if (cfmt->custom_occurrence != cfmt_hidden.custom_occurrence) {
                         /* Different occurrences. */
-                        g_free(cfmt_hidden.custom_field);
-                        cfmt_hidden.custom_field = NULL;
+                        g_free(cfmt_hidden.custom_fields);
+                        cfmt_hidden.custom_fields = NULL;
                         continue;
                     }
                 }
@@ -3637,7 +4752,7 @@ prefs_is_column_visible(const gchar *cols_hidden, fmt_data *cfmt)
              * OK, they match, so it's one of the hidden fields,
              * hence not visible.
              */
-            g_free(cfmt_hidden.custom_field);
+            g_free(cfmt_hidden.custom_fields);
             g_free(cols);
             return FALSE;
         }
@@ -3684,607 +4799,1045 @@ prefs_capture_options_dialog_column_is_visible(const gchar *column)
     GList *curr;
     gchar *col;
 
-    for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
-        col = (gchar *)curr->data;
-        if (col && (g_ascii_strcasecmp(col, column) == 0)) {
+    for (curr = g_list_first(prefs.capture_columns); curr; curr = g_list_next(curr)) {
+        col = (gchar *)curr->data;
+        if (col && (g_ascii_strcasecmp(col, column) == 0)) {
+            return TRUE;
+        }
+    }
+    return FALSE;
+}
+
+#define PRS_GUI_FILTER_LABEL             "gui.filter_expressions.label"
+#define PRS_GUI_FILTER_EXPR              "gui.filter_expressions.expr"
+#define PRS_GUI_FILTER_ENABLED           "gui.filter_expressions.enabled"
+
+/*
+ * Extract the red, green, and blue components of a 24-bit RGB value
+ * and convert them from [0,255] to [0,65535].
+ */
+#define RED_COMPONENT(x)   (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
+#define GREEN_COMPONENT(x) (guint16) (((((x) >>  8) & 0xff) * 65535 / 255))
+#define BLUE_COMPONENT(x)  (guint16) ( (((x)        & 0xff) * 65535 / 255))
+
+char
+string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
+{
+    char c;
+
+    memset(name_resolve, 0, sizeof(e_addr_resolve));
+    while ((c = *string++) != '\0') {
+        switch (c) {
+        case 'm':
+            name_resolve->mac_name = TRUE;
+            break;
+        case 'n':
+            name_resolve->network_name = TRUE;
+            break;
+        case 'N':
+            name_resolve->use_external_net_name_resolver = TRUE;
+            break;
+        case 't':
+            name_resolve->transport_name = TRUE;
+            break;
+        case 'C':
+            /* DEPRECATED */
+            /* name_resolve->concurrent_dns */
+            break;
+        case 'd':
+            name_resolve->dns_pkt_addr_resolution = TRUE;
+            break;
+        case 'v':
+            name_resolve->vlan_name = TRUE;
+            break;
+        default:
+            /*
+             * Unrecognized letter.
+             */
+            return c;
+        }
+    }
+    return '\0';
+}
+
+static void
+try_convert_to_custom_column(gpointer *el_data)
+{
+    guint haystack_idx;
+
+    gchar **fmt = (gchar **) el_data;
+
+    for (haystack_idx = 0;
+         haystack_idx < G_N_ELEMENTS(migrated_columns);
+         ++haystack_idx) {
+
+        if (strcmp(migrated_columns[haystack_idx].col_fmt, *fmt) == 0) {
+            gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
+                                migrated_columns[haystack_idx].col_expr);
+
+            g_free(*fmt);
+            *fmt = cust_col;
+        }
+    }
+}
+
+static gboolean
+deprecated_heur_dissector_pref(gchar *pref_name, const gchar *value)
+{
+    struct heur_pref_name
+    {
+        const char* pref_name;
+        const char* short_name;
+        gboolean  more_dissectors; /* For multiple dissectors controlled by the same preference */
+    };
+
+    struct heur_pref_name heur_prefs[] = {
+        {"acn.heuristic_acn", "acn_udp", 0},
+        {"bfcp.enable", "bfcp_tcp", 1},
+        {"bfcp.enable", "bfcp_udp", 0},
+        {"bt-dht.enable", "bittorrent_dht_udp", 0},
+        {"bt-utp.enable", "bt_utp_udp", 0},
+        {"cattp.enable", "cattp_udp", 0},
+        {"cfp.enable", "fp_eth", 0},
+        {"dicom.heuristic", "dicom_tcp", 0},
+        {"dnp3.heuristics", "dnp3_tcp", 1},
+        {"dnp3.heuristics", "dnp3_udp", 0},
+        {"dvb-s2_modeadapt.enable", "dvb_s2_udp", 0},
+        {"esl.enable", "esl_eth", 0},
+        {"fp.udp_heur", "fp_udp", 0},
+        {"gvsp.enable_heuristic", "gvsp_udp", 0},
+        {"hdcp2.enable", "hdcp2_tcp", 0},
+        {"hislip.enable_heuristic", "hislip_tcp", 0},
+        {"infiniband.dissect_eoib", "mellanox_eoib", 1},
+        {"infiniband.identify_payload", "eth_over_ib", 0},
+        {"jxta.udp.heuristic", "jxta_udp", 0},
+        {"jxta.tcp.heuristic", "jxta_tcp", 0},
+        {"jxta.sctp.heuristic", "jxta_sctp", 0},
+        {"mac-lte.heuristic_mac_lte_over_udp", "mac_lte_udp", 0},
+        {"mbim.bulk_heuristic", "mbim_usb_bulk", 0},
+        {"norm.heuristic_norm", "rmt_norm_udp", 0},
+        {"openflow.heuristic", "openflow_tcp", 0},
+        {"pdcp-lte.heuristic_pdcp_lte_over_udp", "pdcp_lte_udp", 0},
+        {"rlc.heuristic_rlc_over_udp", "rlc_udp", 0},
+        {"rlc-lte.heuristic_rlc_lte_over_udp", "rlc_lte_udp", 0},
+        {"rtcp.heuristic_rtcp", "rtcp_udp", 1},
+        {"rtcp.heuristic_rtcp", "rtcp_stun", 0},
+        {"rtp.heuristic_rtp", "rtp_udp", 1},
+        {"rtp.heuristic_rtp", "rtp_stun", 0},
+        {"teredo.heuristic_teredo", "teredo_udp", 0},
+        {"vssmonitoring.use_heuristics", "vssmonitoring_eth", 0},
+        {"xml.heuristic", "xml_http", 1},
+        {"xml.heuristic", "xml_sip", 1},
+        {"xml.heuristic", "xml_media", 0},
+        {"xml.heuristic_tcp", "xml_tcp", 0},
+        {"xml.heuristic_udp", "xml_udp", 0},
+    };
+
+    unsigned int i;
+    heur_dtbl_entry_t* heuristic;
+
+
+    for (i = 0; i < sizeof(heur_prefs)/sizeof(struct heur_pref_name); i++)
+    {
+        if (strcmp(pref_name, heur_prefs[i].pref_name) == 0)
+        {
+            heuristic = find_heur_dissector_by_unique_short_name(heur_prefs[i].short_name);
+            if (heuristic != NULL) {
+                heuristic->enabled = ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE);
+            }
+
+            if (!heur_prefs[i].more_dissectors)
+                return TRUE;
+        }
+    }
+
+
+    return FALSE;
+}
+
+static gboolean
+deprecated_enable_dissector_pref(gchar *pref_name, const gchar *value)
+{
+    struct dissector_pref_name
+    {
+        const char* pref_name;
+        const char* short_name;
+    };
+
+    struct dissector_pref_name dissector_prefs[] = {
+        {"transum.tsumenabled", "TRANSUM"},
+        {"snort.enable_snort_dissector", "Snort"},
+        {"prp.enable", "PRP"},
+    };
+
+    unsigned int i;
+    int proto_id;
+
+    for (i = 0; i < sizeof(dissector_prefs)/sizeof(struct dissector_pref_name); i++)
+    {
+        if (strcmp(pref_name, dissector_prefs[i].pref_name) == 0)
+        {
+            proto_id = proto_get_id_by_short_name(dissector_prefs[i].short_name);
+            if (proto_id >= 0)
+                proto_set_decoding(proto_id, ((g_ascii_strcasecmp(value, "true") == 0) ? TRUE : FALSE));
+            return TRUE;
+        }
+    }
+
+    return FALSE;
+}
+
+static gboolean
+deprecated_port_pref(gchar *pref_name, const gchar *value)
+{
+    struct port_pref_name
+    {
+        const char* pref_name;
+        const char* module_name;
+        const char* table_name;
+        guint base;
+    };
+
+    struct obsolete_pref_name
+    {
+        const char* pref_name;
+    };
+
+    /* For now this is only supporting TCP/UDP port dissector preferences
+       which are assumed to be decimal */
+    struct port_pref_name port_prefs[] = {
+        /* TCP */
+        {"cmp.tcp_alternate_port", "CMP", "tcp.port", 10},
+        {"h248.tcp_port", "H248", "tcp.port", 10},
+        {"cops.tcp.cops_port", "COPS", "tcp.port", 10},
+        {"dhcpfo.tcp_port", "DHCPFO", "tcp.port", 10},
+        {"enttec.tcp_port", "ENTTEC", "tcp.port", 10},
+        {"forces.tcp_alternate_port", "ForCES", "tcp.port", 10},
+        {"ged125.tcp_port", "GED125", "tcp.port", 10},
+        {"hpfeeds.dissector_port", "HPFEEDS", "tcp.port", 10},
+        {"lsc.port", "LSC", "tcp.port", 10},
+        {"megaco.tcp.txt_port", "MEGACO", "tcp.port", 10},
+        {"netsync.tcp_port", "Netsync", "tcp.port", 10},
+        {"osi.tpkt_port", "OSI", "tcp.port", 10},
+        {"rsync.tcp_port", "RSYNC", "tcp.port", 10},
+        {"sametime.tcp_port", "SAMETIME", "tcp.port", 10},
+        {"sigcomp.tcp.port2", "SIGCOMP", "tcp.port", 10},
+        {"synphasor.tcp_port", "SYNCHROPHASOR", "tcp.port", 10},
+        {"tipc.alternate_port", "TIPC", "tcp.port", 10},
+        {"vnc.alternate_port", "VNC", "tcp.port", 10},
+        {"scop.port", "SCoP", "tcp.port", 10},
+        {"scop.port_secure", "SCoP", "tcp.port", 10},
+        /* UDP */
+        {"h248.udp_port", "H248", "udp.port", 10},
+        {"actrace.udp_port", "ACtrace", "udp.port", 10},
+        {"brp.port", "BRP", "udp.port", 10},
+        {"bvlc.additional_udp_port", "BVLC", "udp.port", 10},
+        {"capwap.udp.port.control", "CAPWAP-CONTROL", "udp.port", 10},
+        {"capwap.udp.port.data", "CAPWAP-CONTROL", "udp.port", 10},
+        {"coap.udp_port", "CoAP", "udp.port", 10},
+        {"enttec.udp_port", "ENTTEC", "udp.port", 10},
+        {"forces.udp_alternate_port", "ForCES", "udp.port", 10},
+        {"ldss.udp_port", "LDSS", "udp.port", 10},
+        {"lmp.udp_port", "LMP", "udp.port", 10},
+        {"ltp.port", "LTP", "udp.port", 10},
+        {"lwres.udp.lwres_port", "LWRES", "udp.port", 10},
+        {"megaco.udp.txt_port", "MEGACO", "udp.port", 10},
+        {"pgm.udp.encap_ucast_port", "PGM", "udp.port", 10},
+        {"pgm.udp.encap_mcast_port", "PGM", "udp.port", 10},
+        {"quic.udp.quic.port", "QUIC", "udp.port", 10},
+        {"quic.udp.quics.port", "QUIC", "udp.port", 10},
+        {"radius.alternate_port", "RADIUS", "udp.port", 10},
+        {"rdt.default_udp_port", "RDT", "udp.port", 10},
+        {"alc.default.udp_port", "ALC", "udp.port", 10},
+        {"sigcomp.udp.port2", "SIGCOMP", "udp.port", 10},
+        {"synphasor.udp_port", "SYNCHROPHASOR", "udp.port", 10},
+        {"tdmop.udpport", "TDMoP", "udp.port", 10},
+        {"uaudp.port1", "UAUDP", "udp.port", 10},
+        {"uaudp.port2", "UAUDP", "udp.port", 10},
+        {"uaudp.port3", "UAUDP", "udp.port", 10},
+        {"uaudp.port4", "UAUDP", "udp.port", 10},
+        {"uhd.dissector_port", "UHD", "udp.port", 10},
+        {"vrt.dissector_port", "VITA 49", "udp.port", 10},
+        {"vuze-dht.udp_port", "Vuze-DHT", "udp.port", 10},
+        {"wimaxasncp.udp.wimax_port", "WiMAX ASN CP", "udp.port", 10},
+    };
+
+    struct port_pref_name port_range_prefs[] = {
+        /* TCP */
+        {"couchbase.tcp.ports", "Couchbase", "tcp.port", 10},
+        {"gsm_ipa.tcp_ports", "GSM over IP", "tcp.port", 10},
+        {"kafka.tcp.ports", "Kafka", "tcp.port", 10},
+        {"kt.tcp.ports", "Kyoto Tycoon", "tcp.port", 10},
+        {"memcache.tcp.ports", "MEMCACHE", "tcp.port", 10},
+        {"mrcpv2.tcp.port_range", "MRCPv2", "tcp.port", 10},
+        {"rtsp.tcp.port_range", "RTSP", "tcp.port", 10},
+        {"sip.tcp.ports", "SIP", "tcp.port", 10},
+        {"tds.tcp_ports", "TDS", "tcp.port", 10},
+        {"uma.tcp.ports", "UMA", "tcp.port", 10},
+        /* UDP */
+        {"aruba_erm.udp.ports", "ARUBA_ERM", "udp.port", 10},
+        {"diameter.udp.ports", "DIAMETER", "udp.port", 10},
+        {"dmp.udp_ports", "DMP", "udp.port", 10},
+        {"dns.udp.ports", "DNS", "udp.port", 10},
+        {"gsm_ipa.udp_ports", "GSM over IP", "udp.port", 10},
+        {"hcrt.dissector_udp_port", "HCrt", "udp.port", 10},
+        {"memcache.udp.ports", "MEMCACHE", "udp.port", 10},
+        {"nb_rtpmux.udp_ports", "NB_RTPMUX", "udp.port", 10},
+        {"gprs-ns.udp.ports", "GPRS-NS", "udp.port", 10},
+        {"p_mul.udp_ports", "P_MUL", "udp.port", 10},
+        {"radius.ports", "RADIUS", "udp.port", 10},
+        {"sflow.ports", "sFlow", "udp.port", 10},
+        {"sscop.udp.ports", "SSCOP", "udp.port", 10},
+        {"tftp.udp_ports", "TFTP", "udp.port", 10},
+        {"tipc.udp.ports", "TIPC", "udp.port", 10},
+    };
+
+    /* These are subdissectors of TPKT/OSITP that used to have a
+       TCP port preference even though they were never
+       directly on TCP.  Convert them to use Decode As
+       with the TPKT dissector handle */
+    struct port_pref_name tpkt_subdissector_port_prefs[] = {
+        {"dap.tcp.port", "DAP", "tcp.port", 10},
+        {"disp.tcp.port", "DISP", "tcp.port", 10},
+        {"dop.tcp.port", "DOP", "tcp.port", 10},
+        {"dsp.tcp.port", "DSP", "tcp.port", 10},
+        {"p1.tcp.port", "P1", "tcp.port", 10},
+        {"p7.tcp.port", "P7", "tcp.port", 10},
+        {"rdp.tcp.port", "RDP", "tcp.port", 10},
+    };
+
+    /* These are obsolete preferences from the dissectors' view,
+       (typically because of a switch from a single value to a
+       range value) but the name of the preference conflicts
+       with the generated preference name from the dissector table.
+       Don't allow the obsolete preference through to be handled */
+    struct obsolete_pref_name obsolete_prefs[] = {
+        {"diameter.tcp.port"},
+        {"kafka.tcp.port"},
+        {"mrcpv2.tcp.port"},
+        {"rtsp.tcp.port"},
+        {"sip.tcp.port"},
+        {"t38.tcp.port"},
+    };
+
+    unsigned int i;
+    char     *p;
+    guint    uval;
+    dissector_table_t sub_dissectors;
+    dissector_handle_t handle, tpkt_handle;
+    module_t *module;
+    pref_t *pref;
+
+    for (i = 0; i < sizeof(port_prefs)/sizeof(struct port_pref_name); i++)
+    {
+        if (strcmp(pref_name, port_prefs[i].pref_name) == 0)
+        {
+            /* XXX - give an error if it doesn't fit in a guint? */
+            uval = (guint)strtoul(value, &p, port_prefs[i].base);
+            if (p == value || *p != '\0')
+                return FALSE;        /* number was bad */
+
+            module = prefs_find_module((gchar*)port_prefs[i].module_name);
+            pref = prefs_find_preference(module, port_prefs[i].table_name);
+            if (pref != NULL)
+            {
+                module->prefs_changed = TRUE;
+                *pref->varp.uint = uval;
+            }
+
+            /* If the value is zero, it wouldn't add to the Decode As tables */
+            if (uval != 0)
+            {
+                sub_dissectors = find_dissector_table(port_prefs[i].table_name);
+                if (sub_dissectors != NULL) {
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_prefs[i].module_name);
+                    if (handle != NULL) {
+                        dissector_change_uint(port_prefs[i].table_name, uval, handle);
+                        decode_build_reset_list(port_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
+                    }
+                }
+            }
+
             return TRUE;
         }
     }
-    return FALSE;
-}
-
-#define PRS_GUI_FILTER_LABEL             "gui.filter_expressions.label"
-#define PRS_GUI_FILTER_EXPR              "gui.filter_expressions.expr"
-#define PRS_GUI_FILTER_ENABLED           "gui.filter_expressions.enabled"
-
-#define RED_COMPONENT(x)   (guint16) (((((x) >> 16) & 0xff) * 65535 / 255))
-#define GREEN_COMPONENT(x) (guint16) (((((x) >>  8) & 0xff) * 65535 / 255))
-#define BLUE_COMPONENT(x)  (guint16) ( (((x)        & 0xff) * 65535 / 255))
 
-char
-string_to_name_resolve(const char *string, e_addr_resolve *name_resolve)
-{
-  char c;
+    for (i = 0; i < sizeof(port_range_prefs)/sizeof(struct port_pref_name); i++)
+    {
+        if (strcmp(pref_name, port_range_prefs[i].pref_name) == 0)
+        {
+            guint32 range_i, range_j;
+
+            sub_dissectors = find_dissector_table(port_range_prefs[i].table_name);
+            if (sub_dissectors != NULL) {
+                switch (dissector_table_get_type(sub_dissectors)) {
+                case FT_UINT8:
+                case FT_UINT16:
+                case FT_UINT24:
+                case FT_UINT32:
+                    break;
+
+                default:
+                    g_error("The dissector table %s (%s) is not an integer type - are you using a buggy plugin?", port_range_prefs[i].table_name, get_dissector_table_ui_name(port_range_prefs[i].table_name));
+                    g_assert_not_reached();
+                }
 
-  memset(name_resolve, 0, sizeof(e_addr_resolve));
-  while ((c = *string++) != '\0') {
-      switch (c) {
-      case 'm':
-          name_resolve->mac_name = TRUE;
-          break;
-      case 'n':
-          name_resolve->network_name = TRUE;
-          break;
-      case 'N':
-          name_resolve->use_external_net_name_resolver = TRUE;
-          break;
-      case 't':
-          name_resolve->transport_name = TRUE;
-          break;
-      case 'C':
-          name_resolve->concurrent_dns = TRUE;
-          break;
-      default:
-          /*
-           * Unrecognized letter.
-           */
-          return c;
-      }
-  }
-  return '\0';
-}
+                module = prefs_find_module((gchar*)port_range_prefs[i].module_name);
+                pref = prefs_find_preference(module, port_range_prefs[i].table_name);
+                if (pref != NULL)
+                {
+                    if (!prefs_set_range_value_work(pref, value, TRUE, &module->prefs_changed))
+                    {
+                        return FALSE;        /* number was bad */
+                    }
 
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)port_range_prefs[i].module_name);
+                    if (handle != NULL) {
 
-static void
-try_convert_to_custom_column(gpointer *el_data)
-{
-    /* Array of columns that have been migrated to custom columns */
-    struct {
-        gint el;
-        const gchar *col_expr;
-    } migrated_columns[] = {
-        { COL_COS_VALUE, "vlan.priority" },
-        { COL_CIRCUIT_ID, "iax2.call" },
-        { COL_BSSGP_TLLI, "bssgp.tlli" },
-        { COL_HPUX_SUBSYS, "nettl.subsys" },
-        { COL_HPUX_DEVID, "nettl.devid" },
-        { COL_FR_DLCI, "fr.dlci" },
-        { COL_REL_CONV_TIME, "tcp.time_relative" },
-        { COL_DELTA_CONV_TIME, "tcp.time_delta" },
-        { COL_OXID, "fc.ox_id" },
-        { COL_RXID, "fc.rx_id" },
-        { COL_SRCIDX, "mdshdr.srcidx" },
-        { COL_DSTIDX, "mdshdr.dstidx" },
-        { COL_DCE_CTX, "dcerpc.cn_ctx_id" }
-    };
+                        for (range_i = 0; range_i < (*pref->varp.range)->nranges; range_i++) {
+                            for (range_j = (*pref->varp.range)->ranges[range_i].low; range_j < (*pref->varp.range)->ranges[range_i].high; range_j++) {
+                                dissector_change_uint(port_range_prefs[i].table_name, range_j, handle);
+                                decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(range_j), NULL, NULL);
+                            }
 
-    guint haystack_idx;
-    const gchar *haystack_fmt;
+                            dissector_change_uint(port_range_prefs[i].table_name, (*pref->varp.range)->ranges[range_i].high, handle);
+                            decode_build_reset_list(port_range_prefs[i].table_name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[range_i].high), NULL, NULL);
+                        }
+                    }
+                }
+            }
 
-    gchar **fmt = (gchar **) el_data;
+            return TRUE;
+        }
+    }
 
-    for (haystack_idx = 0;
-         haystack_idx < G_N_ELEMENTS(migrated_columns);
-         ++haystack_idx) {
+    for (i = 0; i < sizeof(tpkt_subdissector_port_prefs)/sizeof(struct port_pref_name); i++)
+    {
+        if (strcmp(pref_name, tpkt_subdissector_port_prefs[i].pref_name) == 0)
+        {
+            /* XXX - give an error if it doesn't fit in a guint? */
+            uval = (guint)strtoul(value, &p, tpkt_subdissector_port_prefs[i].base);
+            if (p == value || *p != '\0')
+                return FALSE;        /* number was bad */
+
+            /* If the value is 0 or 102 (default TPKT port), don't add to the Decode As tables */
+            if ((uval != 0) && (uval != 102))
+            {
+                tpkt_handle = find_dissector("tpkt");
+                if (tpkt_handle != NULL) {
+                    dissector_change_uint(tpkt_subdissector_port_prefs[i].table_name, uval, tpkt_handle);
+                }
+            }
 
-        haystack_fmt = col_format_to_string(migrated_columns[haystack_idx].el);
-        if (strcmp(haystack_fmt, *fmt) == 0) {
-            gchar *cust_col = g_strdup_printf("%%Cus:%s:0",
-                                migrated_columns[haystack_idx].col_expr);
+            return TRUE;
+        }
+    }
 
-            g_free(*fmt);
-            *fmt = cust_col;
+    for (i = 0; i < sizeof(obsolete_prefs)/sizeof(struct obsolete_pref_name); i++)
+    {
+        if (strcmp(pref_name, obsolete_prefs[i].pref_name) == 0)
+        {
+            /* Just ignore the preference */
+            return TRUE;
         }
     }
+    return FALSE;
 }
 
 static prefs_set_pref_e
 set_pref(gchar *pref_name, const gchar *value, void *private_data _U_,
          gboolean return_range_errors)
 {
-  unsigned long int cval;
-  guint    uval;
-  gboolean bval;
-  gint     enum_val;
-  char     *p;
-  gchar    *dotp, *last_dotp;
-  static gchar *filter_label = NULL;
-  static gboolean filter_enabled = FALSE;
-  gchar    *filter_expr = NULL;
-  module_t *module;
-  pref_t   *pref;
-
-  if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
-    filter_label = g_strdup(value);
-  } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
-    filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
-  } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
-    filter_expr = g_strdup(value);
-    filter_expression_new(filter_label, filter_expr, filter_enabled);
-    g_free(filter_label);
-    g_free(filter_expr);
-  } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
-    /* Convert deprecated value to closest current equivalent */
-    if (g_ascii_strcasecmp(value, "true") == 0) {
-        prefs.gui_version_placement = version_both;
-    } else {
-        prefs.gui_version_placement = version_neither;
-    }
-  } else if (strcmp(pref_name, "name_resolve") == 0 ||
-             strcmp(pref_name, "capture.name_resolve") == 0) {
-    /*
-     * Handle the deprecated name resolution options.
-     *
-     * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
-     * RESOLV_ALL and RESOLV_NONE.
-     *
-     * Otherwise, we treat it as a list of name types we want to resolve.
-     */
-     if (g_ascii_strcasecmp(value, "true") == 0) {
-        gbl_resolv_flags.mac_name = TRUE;
-        gbl_resolv_flags.network_name = TRUE;
-        gbl_resolv_flags.transport_name = TRUE;
-        gbl_resolv_flags.concurrent_dns = TRUE;
-     }
-     else if (g_ascii_strcasecmp(value, "false") == 0) {
-        gbl_resolv_flags.mac_name = FALSE;
-        gbl_resolv_flags.network_name = FALSE;
-        gbl_resolv_flags.transport_name = FALSE;
-        gbl_resolv_flags.concurrent_dns = FALSE;
-     }
-     else {
-        /* start out with none set */
-        gbl_resolv_flags.mac_name = FALSE;
-        gbl_resolv_flags.network_name = FALSE;
-        gbl_resolv_flags.transport_name = FALSE;
-        gbl_resolv_flags.concurrent_dns = FALSE;
-        if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
-           return PREFS_SET_SYNTAX_ERR;
-     }
-  } else {
-    /* Handle deprecated "global" options that don't have a module
-     * associated with them
-     */
-    if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
-        (strcmp(pref_name, "name_resolve_load_smi_modules") == 0)  ||
-        (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
-        module = nameres_module;
-        dotp = pref_name;
-    } else {
-      /* To which module does this preference belong? */
-      module = NULL;
-      last_dotp = pref_name;
-      while (!module) {
-        dotp = strchr(last_dotp, '.');
-        if (dotp == NULL) {
-            /* Either there's no such module, or no module was specified.
-               In either case, that means there's no such preference. */
-            return PREFS_SET_NO_SUCH_PREF;
+    unsigned long int cval;
+    guint    uval;
+    gboolean bval;
+    gint     enum_val;
+    char     *p;
+    gchar    *dotp, *last_dotp;
+    static gchar *filter_label = NULL;
+    static gboolean filter_enabled = FALSE;
+    gchar    *filter_expr = NULL;
+    module_t *module, *containing_module;
+    pref_t   *pref;
+    int type;
+
+    if (strcmp(pref_name, PRS_GUI_FILTER_LABEL) == 0) {
+        filter_label = g_strdup(value);
+    } else if (strcmp(pref_name, PRS_GUI_FILTER_ENABLED) == 0) {
+        filter_enabled = (strcmp(value, "TRUE") == 0) ? TRUE : FALSE;
+    } else if (strcmp(pref_name, PRS_GUI_FILTER_EXPR) == 0) {
+        filter_expr = g_strdup(value);
+        filter_expression_new(filter_label, filter_expr, filter_enabled);
+        g_free(filter_label);
+        g_free(filter_expr);
+    } else if (strcmp(pref_name, "gui.version_in_start_page") == 0) {
+        /* Convert deprecated value to closest current equivalent */
+        if (g_ascii_strcasecmp(value, "true") == 0) {
+            prefs.gui_version_placement = version_both;
+        } else {
+            prefs.gui_version_placement = version_neither;
         }
-        *dotp = '\0'; /* separate module and preference name */
-        module = prefs_find_module(pref_name);
-
+    } else if (strcmp(pref_name, "name_resolve") == 0 ||
+               strcmp(pref_name, "capture.name_resolve") == 0) {
         /*
-         * XXX - "Diameter" rather than "diameter" was used in earlier
-         * versions of Wireshark; if we didn't find the module, and its name
-         * was "Diameter", look for "diameter" instead.
-         *
-         * In addition, the BEEP protocol used to be the BXXP protocol,
-         * so if we didn't find the module, and its name was "bxxp",
-         * look for "beep" instead.
-         *
-         * Also, the preferences for GTP v0 and v1 were combined under
-         * a single "gtp" heading, and the preferences for SMPP were
-         * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
-         * However, SMPP now has its own preferences, so we just map
-         * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
-         *
-         * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
-         * and "nsip" to "gprs_ns".
+         * Handle the deprecated name resolution options.
          *
-         * The SynOptics Network Management Protocol (SONMP) is now known by
-         * its modern name, the Nortel Discovery Protocol (NDP).
-         */
-        if (module == NULL) {
-          if (strcmp(pref_name, "column") == 0)
-            module = gui_column_module;
-          else if (strcmp(pref_name, "Diameter") == 0)
-            module = prefs_find_module("diameter");
-          else if (strcmp(pref_name, "bxxp") == 0)
-            module = prefs_find_module("beep");
-          else if (strcmp(pref_name, "gtpv0") == 0 ||
-                   strcmp(pref_name, "gtpv1") == 0)
-            module = prefs_find_module("gtp");
-          else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
-            module = prefs_find_module("gsm-sms-ud");
-          else if (strcmp(pref_name, "dcp") == 0)
-            module = prefs_find_module("dccp");
-          else if (strcmp(pref_name, "x.25") == 0)
-            module = prefs_find_module("x25");
-          else if (strcmp(pref_name, "x411") == 0)
-            module = prefs_find_module("p1");
-          else if (strcmp(pref_name, "nsip") == 0)
-            module = prefs_find_module("gprs-ns");
-          else if (strcmp(pref_name, "sonmp") == 0)
-            module = prefs_find_module("ndp");
-          else if (strcmp(pref_name, "etheric") == 0 ||
-                   strcmp(pref_name, "isup_thin") == 0) {
-            /* This protocol was removed 7. July 2009 */
-            return PREFS_SET_OBSOLETE;
-          }
-          if (module) {
-            g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
-              "Save your preferences to make this change permanent.",
-              pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
-            prefs.unknown_prefs = TRUE;
-          }
-        }
-        *dotp = '.';                /* put the preference string back */
-        dotp++;                     /* skip past separator to preference name */
-        last_dotp = dotp;
-      }
-    }
-
-    pref = prefs_find_preference(module, dotp);
-
-    if (pref == NULL) {
-      prefs.unknown_prefs = TRUE;
-
-      /* "gui" prefix was added to column preferences for better organization
-       * within the preferences file
-       */
-      if ((strcmp(pref_name, PRS_COL_HIDDEN) == 0) ||
-          (strcmp(pref_name, PRS_COL_FMT) == 0)) {
-         pref = prefs_find_preference(module, pref_name);
-      }
-      else if (strcmp(module->name, "mgcp") == 0) {
-        /*
-         * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
-         * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
-         * were used in earlier versions of Wireshark; if we didn't find the
-         * preference, it was an MGCP preference, and its name was
-         * "display raw text toggle" or "display dissect tree", look for
-         * "display_raw_text" or "display_dissect_tree" instead.
+         * "TRUE" and "FALSE", for backwards compatibility, are synonyms for
+         * RESOLV_ALL and RESOLV_NONE.
          *
-         * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
-         * the gateway and callagent ports were given those names; we interpret
-         * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
-         * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
-         * they were registered by the MCCP dissector and thus that's the
-         * order in which they were written to the preferences file.  (If
-         * we're not reading the preferences file, but are handling stuff
-         * from a "-o" command-line option, we have no clue which the user
-         * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
-         * or "mgcp.{tcp,udp}.callagent_port" instead.)
+         * Otherwise, we treat it as a list of name types we want to resolve.
          */
-        if (strcmp(dotp, "display raw text toggle") == 0)
-          pref = prefs_find_preference(module, "display_raw_text");
-        else if (strcmp(dotp, "display dissect tree") == 0)
-          pref = prefs_find_preference(module, "display_dissect_tree");
-        else if (strcmp(dotp, "tcp.port") == 0) {
-          mgcp_tcp_port_count++;
-          if (mgcp_tcp_port_count == 1) {
-            /* It's the first one */
-            pref = prefs_find_preference(module, "tcp.gateway_port");
-          } else if (mgcp_tcp_port_count == 2) {
-            /* It's the second one */
-            pref = prefs_find_preference(module, "tcp.callagent_port");
-          }
-          /* Otherwise it's from the command line, and we don't bother
-             mapping it. */
-        } else if (strcmp(dotp, "udp.port") == 0) {
-          mgcp_udp_port_count++;
-          if (mgcp_udp_port_count == 1) {
-            /* It's the first one */
-            pref = prefs_find_preference(module, "udp.gateway_port");
-          } else if (mgcp_udp_port_count == 2) {
-            /* It's the second one */
-            pref = prefs_find_preference(module, "udp.callagent_port");
-          }
-          /* Otherwise it's from the command line, and we don't bother
-             mapping it. */
+        if (g_ascii_strcasecmp(value, "true") == 0) {
+            gbl_resolv_flags.mac_name = TRUE;
+            gbl_resolv_flags.network_name = TRUE;
+            gbl_resolv_flags.transport_name = TRUE;
         }
-      } else if (strcmp(module->name, "smb") == 0) {
-        /* Handle old names for SMB preferences. */
-        if (strcmp(dotp, "smb.trans.reassembly") == 0)
-          pref = prefs_find_preference(module, "trans_reassembly");
-        else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
-          pref = prefs_find_preference(module, "dcerpc_reassembly");
-      } else if (strcmp(module->name, "ndmp") == 0) {
-        /* Handle old names for NDMP preferences. */
-        if (strcmp(dotp, "ndmp.desegment") == 0)
-          pref = prefs_find_preference(module, "desegment");
-      } else if (strcmp(module->name, "diameter") == 0) {
-        /* Handle old names for Diameter preferences. */
-        if (strcmp(dotp, "diameter.desegment") == 0)
-          pref = prefs_find_preference(module, "desegment");
-      } else if (strcmp(module->name, "pcli") == 0) {
-        /* Handle old names for PCLI preferences. */
-        if (strcmp(dotp, "pcli.udp_port") == 0)
-          pref = prefs_find_preference(module, "udp_port");
-      } else if (strcmp(module->name, "artnet") == 0) {
-        /* Handle old names for ARTNET preferences. */
-        if (strcmp(dotp, "artnet.udp_port") == 0)
-          pref = prefs_find_preference(module, "udp_port");
-      } else if (strcmp(module->name, "mapi") == 0) {
-        /* Handle old names for MAPI preferences. */
-        if (strcmp(dotp, "mapi_decrypt") == 0)
-          pref = prefs_find_preference(module, "decrypt");
-      } else if (strcmp(module->name, "fc") == 0) {
-        /* Handle old names for Fibre Channel preferences. */
-        if (strcmp(dotp, "reassemble_fc") == 0)
-          pref = prefs_find_preference(module, "reassemble");
-        else if (strcmp(dotp, "fc_max_frame_size") == 0)
-          pref = prefs_find_preference(module, "max_frame_size");
-      } else if (strcmp(module->name, "fcip") == 0) {
-        /* Handle old names for Fibre Channel-over-IP preferences. */
-        if (strcmp(dotp, "desegment_fcip_messages") == 0)
-          pref = prefs_find_preference(module, "desegment");
-        else if (strcmp(dotp, "fcip_port") == 0)
-          pref = prefs_find_preference(module, "target_port");
-      } else if (strcmp(module->name, "gtp") == 0) {
-        /* Handle old names for GTP preferences. */
-        if (strcmp(dotp, "gtpv0_port") == 0)
-          pref = prefs_find_preference(module, "v0_port");
-        else if (strcmp(dotp, "gtpv1c_port") == 0)
-          pref = prefs_find_preference(module, "v1c_port");
-        else if (strcmp(dotp, "gtpv1u_port") == 0)
-          pref = prefs_find_preference(module, "v1u_port");
-        else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
-          pref = prefs_find_preference(module, "dissect_tpdu");
-        else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
-          pref = prefs_find_preference(module, "v0_dissect_cdr_as");
-        else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
-          pref = prefs_find_preference(module, "v0_check_etsi");
-        else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
-          pref = prefs_find_preference(module, "v1_check_etsi");
-      } else if (strcmp(module->name, "ip") == 0) {
-        /* Handle old names for IP preferences. */
-        if (strcmp(dotp, "ip_summary_in_tree") == 0)
-          pref = prefs_find_preference(module, "summary_in_tree");
-      } else if (strcmp(module->name, "iscsi") == 0) {
-        /* Handle old names for iSCSI preferences. */
-        if (strcmp(dotp, "iscsi_port") == 0)
-          pref = prefs_find_preference(module, "target_port");
-      } else if (strcmp(module->name, "lmp") == 0) {
-        /* Handle old names for LMP preferences. */
-        if (strcmp(dotp, "lmp_version") == 0)
-          pref = prefs_find_preference(module, "version");
-      } else if (strcmp(module->name, "mtp3") == 0) {
-        /* Handle old names for MTP3 preferences. */
-        if (strcmp(dotp, "mtp3_standard") == 0)
-          pref = prefs_find_preference(module, "standard");
-        else if (strcmp(dotp, "net_addr_format") == 0)
-          pref = prefs_find_preference(module, "addr_format");
-      } else if (strcmp(module->name, "nlm") == 0) {
-        /* Handle old names for NLM preferences. */
-        if (strcmp(dotp, "nlm_msg_res_matching") == 0)
-          pref = prefs_find_preference(module, "msg_res_matching");
-      } else if (strcmp(module->name, "ppp") == 0) {
-        /* Handle old names for PPP preferences. */
-        if (strcmp(dotp, "ppp_fcs") == 0)
-          pref = prefs_find_preference(module, "fcs_type");
-        else if (strcmp(dotp, "ppp_vj") == 0)
-          pref = prefs_find_preference(module, "decompress_vj");
-      } else if (strcmp(module->name, "rsvp") == 0) {
-        /* Handle old names for RSVP preferences. */
-        if (strcmp(dotp, "rsvp_process_bundle") == 0)
-          pref = prefs_find_preference(module, "process_bundle");
-      } else if (strcmp(module->name, "tcp") == 0) {
-        /* Handle old names for TCP preferences. */
-        if (strcmp(dotp, "tcp_summary_in_tree") == 0)
-          pref = prefs_find_preference(module, "summary_in_tree");
-        else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
-          pref = prefs_find_preference(module, "analyze_sequence_numbers");
-        else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
-          pref = prefs_find_preference(module, "relative_sequence_numbers");
-      } else if (strcmp(module->name, "udp") == 0) {
-        /* Handle old names for UDP preferences. */
-        if (strcmp(dotp, "udp_summary_in_tree") == 0)
-          pref = prefs_find_preference(module, "summary_in_tree");
-      } else if (strcmp(module->name, "ndps") == 0) {
-        /* Handle old names for NDPS preferences. */
-        if (strcmp(dotp, "desegment_ndps") == 0)
-          pref = prefs_find_preference(module, "desegment_tcp");
-      } else if (strcmp(module->name, "http") == 0) {
-        /* Handle old names for HTTP preferences. */
-        if (strcmp(dotp, "desegment_http_headers") == 0)
-          pref = prefs_find_preference(module, "desegment_headers");
-        else if (strcmp(dotp, "desegment_http_body") == 0)
-          pref = prefs_find_preference(module, "desegment_body");
-      } else if (strcmp(module->name, "smpp") == 0) {
-        /* Handle preferences that moved from SMPP. */
-        module_t *new_module = prefs_find_module("gsm-sms-ud");
-        if (new_module){
-          if (strcmp(dotp, "port_number_udh_means_wsp") == 0)
-            pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
-          else if (strcmp(dotp, "try_dissect_1st_fragment") == 0)
-            pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
+        else if (g_ascii_strcasecmp(value, "false") == 0) {
+            disable_name_resolution();
         }
-      } else if (strcmp(module->name, "asn1") == 0) {
-        /* Handle old generic ASN.1 preferences (it's not really a
-           rename, as the new preferences support multiple ports,
-           but we might as well copy them over). */
-        if (strcmp(dotp, "tcp_port") == 0)
-          pref = prefs_find_preference(module, "tcp_ports");
-        else if (strcmp(dotp, "udp_port") == 0)
-          pref = prefs_find_preference(module, "udp_ports");
-        else if (strcmp(dotp, "sctp_port") == 0)
-          pref = prefs_find_preference(module, "sctp_ports");
-      } else if (strcmp(module->name, "llcgprs") == 0) {
-        if (strcmp(dotp, "ignore_cipher_bit") == 0)
-          pref = prefs_find_preference(module, "autodetect_cipher_bit");
-      } else if (strcmp(module->name, "erf") == 0) {
-        if (strcmp(dotp, "erfeth") == 0) {
-          /* Handle the old "erfeth" preference; map it to the new
-             "ethfcs" preference, and map the values to those for
-             the new preference. */
-          pref = prefs_find_preference(module, "ethfcs");
-          if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
-            value = "TRUE";
-          else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
-            value = "FALSE";
-          else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
-            value = "TRUE";
-        } else if (strcmp(dotp, "erfatm") == 0) {
-          /* Handle the old "erfatm" preference; map it to the new
-             "aal5_type" preference, and map the values to those for
-             the new preference. */
-          pref = prefs_find_preference(module, "aal5_type");
-          if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
-            value = "guess";
-          else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
-            value = "llc";
-          else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
-            value = "guess";
-        } else if (strcmp(dotp, "erfhdlc") == 0) {
-          /* Handle the old "erfhdlc" preference; map it to the new
-             "hdlc_type" preference, and map the values to those for
-             the new preference. */
-          pref = prefs_find_preference(module, "hdlc_type");
-          if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
-            value = "chdlc";
-          else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
-            value = "ppp";
-          else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
-            value = "frelay";
-          else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
-            value = "mtp2";
-          else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
-            value = "guess";
+        else {
+            /* start out with none set */
+            disable_name_resolution();
+            if (string_to_name_resolve(value, &gbl_resolv_flags) != '\0')
+                return PREFS_SET_SYNTAX_ERR;
         }
-      } else if (strcmp(module->name, "eth") == 0) {
-        /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
-        if (strcmp(dotp, "qinq_ethertype") == 0) {
-          module_t *new_module = prefs_find_module("vlan");
-          if (new_module) {
-            pref = prefs_find_preference(new_module, "qinq_ethertype");
-            module = new_module;
-          }
+    } else if (deprecated_heur_dissector_pref(pref_name, value)) {
+         /* Handled within deprecated_heur_dissector_pref() if found */
+    } else if (deprecated_enable_dissector_pref(pref_name, value)) {
+         /* Handled within deprecated_enable_dissector_pref() if found */
+    } else if (deprecated_port_pref(pref_name, value)) {
+         /* Handled within deprecated_port_pref() if found */
+    } else {
+        /* Handle deprecated "global" options that don't have a module
+         * associated with them
+         */
+        if ((strcmp(pref_name, "name_resolve_concurrency") == 0) ||
+            (strcmp(pref_name, "name_resolve_load_smi_modules") == 0)  ||
+            (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0)) {
+            module = nameres_module;
+            dotp = pref_name;
+        } else {
+            /* To which module does this preference belong? */
+            module = NULL;
+            last_dotp = pref_name;
+            while (!module) {
+                dotp = strchr(last_dotp, '.');
+                if (dotp == NULL) {
+                    /* Either there's no such module, or no module was specified.
+                       In either case, that means there's no such preference. */
+                    return PREFS_SET_NO_SUCH_PREF;
+                }
+                *dotp = '\0'; /* separate module and preference name */
+                module = prefs_find_module(pref_name);
+
+                /*
+                 * XXX - "Diameter" rather than "diameter" was used in earlier
+                 * versions of Wireshark; if we didn't find the module, and its name
+                 * was "Diameter", look for "diameter" instead.
+                 *
+                 * In addition, the BEEP protocol used to be the BXXP protocol,
+                 * so if we didn't find the module, and its name was "bxxp",
+                 * look for "beep" instead.
+                 *
+                 * Also, the preferences for GTP v0 and v1 were combined under
+                 * a single "gtp" heading, and the preferences for SMPP were
+                 * moved to "smpp-gsm-sms" and then moved to "gsm-sms-ud".
+                 * However, SMPP now has its own preferences, so we just map
+                 * "smpp-gsm-sms" to "gsm-sms-ud", and then handle SMPP below.
+                 *
+                 * We also renamed "dcp" to "dccp", "x.25" to "x25", "x411" to "p1"
+                 * and "nsip" to "gprs_ns".
+                 *
+                 * The SynOptics Network Management Protocol (SONMP) is now known by
+                 * its modern name, the Nortel Discovery Protocol (NDP).
+                 */
+                if (module == NULL) {
+                    if (strcmp(pref_name, "column") == 0)
+                        module = gui_column_module;
+                    else if (strcmp(pref_name, "Diameter") == 0)
+                        module = prefs_find_module("diameter");
+                    else if (strcmp(pref_name, "bxxp") == 0)
+                        module = prefs_find_module("beep");
+                    else if (strcmp(pref_name, "gtpv0") == 0 ||
+                             strcmp(pref_name, "gtpv1") == 0)
+                        module = prefs_find_module("gtp");
+                    else if (strcmp(pref_name, "smpp-gsm-sms") == 0)
+                        module = prefs_find_module("gsm-sms-ud");
+                    else if (strcmp(pref_name, "dcp") == 0)
+                        module = prefs_find_module("dccp");
+                    else if (strcmp(pref_name, "x.25") == 0)
+                        module = prefs_find_module("x25");
+                    else if (strcmp(pref_name, "x411") == 0)
+                        module = prefs_find_module("p1");
+                    else if (strcmp(pref_name, "nsip") == 0)
+                        module = prefs_find_module("gprs-ns");
+                    else if (strcmp(pref_name, "sonmp") == 0)
+                        module = prefs_find_module("ndp");
+                    else if (strcmp(pref_name, "etheric") == 0 ||
+                             strcmp(pref_name, "isup_thin") == 0) {
+                        /* This protocol was removed 7. July 2009 */
+                        return PREFS_SET_OBSOLETE;
+                    }
+                    if (module) {
+                        ws_g_warning ("Preference \"%s.%s\" has been converted to \"%s.%s.%s\"\n"
+                                   "Save your preferences to make this change permanent.",
+                                   pref_name, dotp+1, module->parent->name, pref_name, dotp+1);
+                        prefs.unknown_prefs = TRUE;
+                    }
+                }
+                *dotp = '.';                /* put the preference string back */
+                dotp++;                     /* skip past separator to preference name */
+                last_dotp = dotp;
+            }
         }
-      } else if (strcmp(module->name, "taps") == 0) {
-          /* taps preferences moved to "statistics" module */
-          if (strcmp(dotp, "update_interval") == 0 ||
-              strcmp(dotp, "rtp_player_max_visible") == 0)
-            pref = prefs_find_preference(stats_module, dotp);
-      } else if (strcmp(module->name, "packet_list") == 0) {
-          /* packet_list preferences moved to protocol module */
-          if (strcmp(dotp, "display_hidden_proto_items") == 0)
-            pref = prefs_find_preference(protocols_module, dotp);
-      } else if (strcmp(module->name, "stream") == 0) {
-          /* stream preferences moved to gui color module */
-          if ((strcmp(dotp, "client.fg") == 0) ||
-              (strcmp(dotp, "client.bg") == 0) ||
-              (strcmp(dotp, "server.fg") == 0) ||
-              (strcmp(dotp, "server.bg") == 0))
-            pref = prefs_find_preference(gui_color_module, pref_name);
-      } else if (strcmp(module->name, "nameres") == 0) {
-          if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
-            pref = prefs_find_preference(nameres_module, pref_name);
-          } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
-            pref = prefs_find_preference(nameres_module, "load_smi_modules");
-          } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
-            pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
-          }
-      }
-    }
-    if (pref == NULL)
-      return PREFS_SET_NO_SUCH_PREF;        /* no such preference */
 
-    switch (pref->type) {
+        /* The pref is located in the module or a submodule.
+         * Assume module, then search for a submodule holding the pref. */
+        containing_module = module;
+        pref = prefs_find_preference_with_submodule(module, dotp, &containing_module);
 
-    case PREF_UINT:
-      /* XXX - give an error if it doesn't fit in a guint? */
-      uval = (guint)strtoul(value, &p, pref->info.base);
-      if (p == value || *p != '\0')
-        return PREFS_SET_SYNTAX_ERR;        /* number was bad */
-      if (*pref->varp.uint != uval) {
-        module->prefs_changed = TRUE;
-        *pref->varp.uint = uval;
-      }
-      break;
+        if (pref == NULL) {
+            prefs.unknown_prefs = TRUE;
 
-    case PREF_BOOL:
-      /* XXX - give an error if it's neither "true" nor "false"? */
-      if (g_ascii_strcasecmp(value, "true") == 0)
-        bval = TRUE;
-      else
-        bval = FALSE;
-      if (*pref->varp.boolp != bval) {
-        module->prefs_changed = TRUE;
-        *pref->varp.boolp = bval;
-      }
-      break;
+            /* "gui" prefix was added to column preferences for better organization
+             * within the preferences file
+             */
+            if (module == gui_column_module) {
+                /* While this has a subtree, there is no apply callback, so no
+                 * need to use prefs_find_preference_with_submodule to update
+                 * containing_module. It would not be useful. */
+                pref = prefs_find_preference(module, pref_name);
+            }
+            else if (strcmp(module->name, "mgcp") == 0) {
+                /*
+                 * XXX - "mgcp.display raw text toggle" and "mgcp.display dissect tree"
+                 * rather than "mgcp.display_raw_text" and "mgcp.display_dissect_tree"
+                 * were used in earlier versions of Wireshark; if we didn't find the
+                 * preference, it was an MGCP preference, and its name was
+                 * "display raw text toggle" or "display dissect tree", look for
+                 * "display_raw_text" or "display_dissect_tree" instead.
+                 *
+                 * "mgcp.tcp.port" and "mgcp.udp.port" are harder to handle, as both
+                 * the gateway and callagent ports were given those names; we interpret
+                 * the first as "mgcp.{tcp,udp}.gateway_port" and the second as
+                 * "mgcp.{tcp,udp}.callagent_port", as that's the order in which
+                 * they were registered by the MCCP dissector and thus that's the
+                 * order in which they were written to the preferences file.  (If
+                 * we're not reading the preferences file, but are handling stuff
+                 * from a "-o" command-line option, we have no clue which the user
+                 * had in mind - they should have used "mgcp.{tcp,udp}.gateway_port"
+                 * or "mgcp.{tcp,udp}.callagent_port" instead.)
+                 */
+                if (strcmp(dotp, "display raw text toggle") == 0)
+                    pref = prefs_find_preference(module, "display_raw_text");
+                else if (strcmp(dotp, "display dissect tree") == 0)
+                    pref = prefs_find_preference(module, "display_dissect_tree");
+                else if (strcmp(dotp, "tcp.port") == 0) {
+                    mgcp_tcp_port_count++;
+                    if (mgcp_tcp_port_count == 1) {
+                        /* It's the first one */
+                        pref = prefs_find_preference(module, "tcp.gateway_port");
+                    } else if (mgcp_tcp_port_count == 2) {
+                        /* It's the second one */
+                        pref = prefs_find_preference(module, "tcp.callagent_port");
+                    }
+                    /* Otherwise it's from the command line, and we don't bother
+                       mapping it. */
+                } else if (strcmp(dotp, "udp.port") == 0) {
+                    mgcp_udp_port_count++;
+                    if (mgcp_udp_port_count == 1) {
+                        /* It's the first one */
+                        pref = prefs_find_preference(module, "udp.gateway_port");
+                    } else if (mgcp_udp_port_count == 2) {
+                        /* It's the second one */
+                        pref = prefs_find_preference(module, "udp.callagent_port");
+                    }
+                    /* Otherwise it's from the command line, and we don't bother
+                       mapping it. */
+                }
+            } else if (strcmp(module->name, "smb") == 0) {
+                /* Handle old names for SMB preferences. */
+                if (strcmp(dotp, "smb.trans.reassembly") == 0)
+                    pref = prefs_find_preference(module, "trans_reassembly");
+                else if (strcmp(dotp, "smb.dcerpc.reassembly") == 0)
+                    pref = prefs_find_preference(module, "dcerpc_reassembly");
+            } else if (strcmp(module->name, "ndmp") == 0) {
+                /* Handle old names for NDMP preferences. */
+                if (strcmp(dotp, "ndmp.desegment") == 0)
+                    pref = prefs_find_preference(module, "desegment");
+            } else if (strcmp(module->name, "diameter") == 0) {
+                /* Handle old names for Diameter preferences. */
+                if (strcmp(dotp, "diameter.desegment") == 0)
+                    pref = prefs_find_preference(module, "desegment");
+            } else if (strcmp(module->name, "pcli") == 0) {
+                /* Handle old names for PCLI preferences. */
+                if (strcmp(dotp, "pcli.udp_port") == 0)
+                    pref = prefs_find_preference(module, "udp_port");
+            } else if (strcmp(module->name, "artnet") == 0) {
+                /* Handle old names for ARTNET preferences. */
+                if (strcmp(dotp, "artnet.udp_port") == 0)
+                    pref = prefs_find_preference(module, "udp_port");
+            } else if (strcmp(module->name, "mapi") == 0) {
+                /* Handle old names for MAPI preferences. */
+                if (strcmp(dotp, "mapi_decrypt") == 0)
+                    pref = prefs_find_preference(module, "decrypt");
+            } else if (strcmp(module->name, "fc") == 0) {
+                /* Handle old names for Fibre Channel preferences. */
+                if (strcmp(dotp, "reassemble_fc") == 0)
+                    pref = prefs_find_preference(module, "reassemble");
+                else if (strcmp(dotp, "fc_max_frame_size") == 0)
+                    pref = prefs_find_preference(module, "max_frame_size");
+            } else if (strcmp(module->name, "fcip") == 0) {
+                /* Handle old names for Fibre Channel-over-IP preferences. */
+                if (strcmp(dotp, "desegment_fcip_messages") == 0)
+                    pref = prefs_find_preference(module, "desegment");
+                else if (strcmp(dotp, "fcip_port") == 0)
+                    pref = prefs_find_preference(module, "target_port");
+            } else if (strcmp(module->name, "gtp") == 0) {
+                /* Handle old names for GTP preferences. */
+                if (strcmp(dotp, "gtpv0_port") == 0)
+                    pref = prefs_find_preference(module, "v0_port");
+                else if (strcmp(dotp, "gtpv1c_port") == 0)
+                    pref = prefs_find_preference(module, "v1c_port");
+                else if (strcmp(dotp, "gtpv1u_port") == 0)
+                    pref = prefs_find_preference(module, "v1u_port");
+                else if (strcmp(dotp, "gtp_dissect_tpdu") == 0)
+                    pref = prefs_find_preference(module, "dissect_tpdu");
+                else if (strcmp(dotp, "gtpv0_dissect_cdr_as") == 0)
+                    pref = prefs_find_preference(module, "v0_dissect_cdr_as");
+                else if (strcmp(dotp, "gtpv0_check_etsi") == 0)
+                    pref = prefs_find_preference(module, "v0_check_etsi");
+                else if (strcmp(dotp, "gtpv1_check_etsi") == 0)
+                    pref = prefs_find_preference(module, "v1_check_etsi");
+            } else if (strcmp(module->name, "ip") == 0) {
+                /* Handle old names for IP preferences. */
+                if (strcmp(dotp, "ip_summary_in_tree") == 0)
+                    pref = prefs_find_preference(module, "summary_in_tree");
+            } else if (strcmp(module->name, "iscsi") == 0) {
+                /* Handle old names for iSCSI preferences. */
+                if (strcmp(dotp, "iscsi_port") == 0)
+                    pref = prefs_find_preference(module, "target_port");
+            } else if (strcmp(module->name, "lmp") == 0) {
+                /* Handle old names for LMP preferences. */
+                if (strcmp(dotp, "lmp_version") == 0)
+                    pref = prefs_find_preference(module, "version");
+            } else if (strcmp(module->name, "mtp3") == 0) {
+                /* Handle old names for MTP3 preferences. */
+                if (strcmp(dotp, "mtp3_standard") == 0)
+                    pref = prefs_find_preference(module, "standard");
+                else if (strcmp(dotp, "net_addr_format") == 0)
+                    pref = prefs_find_preference(module, "addr_format");
+            } else if (strcmp(module->name, "nlm") == 0) {
+                /* Handle old names for NLM preferences. */
+                if (strcmp(dotp, "nlm_msg_res_matching") == 0)
+                    pref = prefs_find_preference(module, "msg_res_matching");
+            } else if (strcmp(module->name, "ppp") == 0) {
+                /* Handle old names for PPP preferences. */
+                if (strcmp(dotp, "ppp_fcs") == 0)
+                    pref = prefs_find_preference(module, "fcs_type");
+                else if (strcmp(dotp, "ppp_vj") == 0)
+                    pref = prefs_find_preference(module, "decompress_vj");
+            } else if (strcmp(module->name, "rsvp") == 0) {
+                /* Handle old names for RSVP preferences. */
+                if (strcmp(dotp, "rsvp_process_bundle") == 0)
+                    pref = prefs_find_preference(module, "process_bundle");
+            } else if (strcmp(module->name, "tcp") == 0) {
+                /* Handle old names for TCP preferences. */
+                if (strcmp(dotp, "tcp_summary_in_tree") == 0)
+                    pref = prefs_find_preference(module, "summary_in_tree");
+                else if (strcmp(dotp, "tcp_analyze_sequence_numbers") == 0)
+                    pref = prefs_find_preference(module, "analyze_sequence_numbers");
+                else if (strcmp(dotp, "tcp_relative_sequence_numbers") == 0)
+                    pref = prefs_find_preference(module, "relative_sequence_numbers");
+            } else if (strcmp(module->name, "udp") == 0) {
+                /* Handle old names for UDP preferences. */
+                if (strcmp(dotp, "udp_summary_in_tree") == 0)
+                    pref = prefs_find_preference(module, "summary_in_tree");
+            } else if (strcmp(module->name, "ndps") == 0) {
+                /* Handle old names for NDPS preferences. */
+                if (strcmp(dotp, "desegment_ndps") == 0)
+                    pref = prefs_find_preference(module, "desegment_tcp");
+            } else if (strcmp(module->name, "http") == 0) {
+                /* Handle old names for HTTP preferences. */
+                if (strcmp(dotp, "desegment_http_headers") == 0)
+                    pref = prefs_find_preference(module, "desegment_headers");
+                else if (strcmp(dotp, "desegment_http_body") == 0)
+                    pref = prefs_find_preference(module, "desegment_body");
+            } else if (strcmp(module->name, "smpp") == 0) {
+                /* Handle preferences that moved from SMPP. */
+                module_t *new_module = prefs_find_module("gsm-sms-ud");
+                if (new_module) {
+                    if (strcmp(dotp, "port_number_udh_means_wsp") == 0) {
+                        pref = prefs_find_preference(new_module, "port_number_udh_means_wsp");
+                        containing_module = new_module;
+                    } else if (strcmp(dotp, "try_dissect_1st_fragment") == 0) {
+                        pref = prefs_find_preference(new_module, "try_dissect_1st_fragment");
+                        containing_module = new_module;
+                    }
+                }
+            } else if (strcmp(module->name, "asn1") == 0) {
+                /* Handle old generic ASN.1 preferences (it's not really a
+                   rename, as the new preferences support multiple ports,
+                   but we might as well copy them over). */
+                if (strcmp(dotp, "tcp_port") == 0)
+                    pref = prefs_find_preference(module, "tcp_ports");
+                else if (strcmp(dotp, "udp_port") == 0)
+                    pref = prefs_find_preference(module, "udp_ports");
+                else if (strcmp(dotp, "sctp_port") == 0)
+                    pref = prefs_find_preference(module, "sctp_ports");
+            } else if (strcmp(module->name, "llcgprs") == 0) {
+                if (strcmp(dotp, "ignore_cipher_bit") == 0)
+                    pref = prefs_find_preference(module, "autodetect_cipher_bit");
+            } else if (strcmp(module->name, "erf") == 0) {
+                if (strcmp(dotp, "erfeth") == 0) {
+                    /* Handle the old "erfeth" preference; map it to the new
+                       "ethfcs" preference, and map the values to those for
+                       the new preference. */
+                    pref = prefs_find_preference(module, "ethfcs");
+                    if (strcmp(value, "ethfcs") == 0 || strcmp(value, "Ethernet with FCS") == 0)
+                        value = "TRUE";
+                    else if (strcmp(value, "eth") == 0 || strcmp(value, "Ethernet") == 0)
+                        value = "FALSE";
+                    else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
+                        value = "TRUE";
+                } else if (strcmp(dotp, "erfatm") == 0) {
+                    /* Handle the old "erfatm" preference; map it to the new
+                       "aal5_type" preference, and map the values to those for
+                       the new preference. */
+                    pref = prefs_find_preference(module, "aal5_type");
+                    if (strcmp(value, "atm") == 0 || strcmp(value, "ATM") == 0)
+                        value = "guess";
+                    else if (strcmp(value, "llc") == 0 || strcmp(value, "LLC") == 0)
+                        value = "llc";
+                    else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
+                        value = "guess";
+                } else if (strcmp(dotp, "erfhdlc") == 0) {
+                    /* Handle the old "erfhdlc" preference; map it to the new
+                       "hdlc_type" preference, and map the values to those for
+                       the new preference. */
+                    pref = prefs_find_preference(module, "hdlc_type");
+                    if (strcmp(value, "chdlc") == 0 || strcmp(value, "Cisco HDLC") == 0)
+                        value = "chdlc";
+                    else if (strcmp(value, "ppp") == 0 || strcmp(value, "PPP serial") == 0)
+                        value = "ppp";
+                    else if (strcmp(value, "fr") == 0 || strcmp(value, "Frame Relay") == 0)
+                        value = "frelay";
+                    else if (strcmp(value, "mtp2") == 0 || strcmp(value, "SS7 MTP2") == 0)
+                        value = "mtp2";
+                    else if (strcmp(value, "raw") == 0 || strcmp(value, "Raw data") == 0)
+                        value = "guess";
+                }
+            } else if (strcmp(module->name, "eth") == 0) {
+                /* "eth.qinq_ethertype" has been changed(restored) to "vlan.qinq.ethertype" */
+                if (strcmp(dotp, "qinq_ethertype") == 0) {
+                    module_t *new_module = prefs_find_module("vlan");
+                    if (new_module) {
+                        pref = prefs_find_preference(new_module, "qinq_ethertype");
+                        containing_module = new_module;
+                    }
+                }
+            } else if (strcmp(module->name, "taps") == 0) {
+                /* taps preferences moved to "statistics" module */
+                if (strcmp(dotp, "update_interval") == 0 ||
+                    strcmp(dotp, "rtp_player_max_visible") == 0)
+                    pref = prefs_find_preference(stats_module, dotp);
+            } else if (strcmp(module->name, "packet_list") == 0) {
+                /* packet_list preferences moved to protocol module */
+                if (strcmp(dotp, "display_hidden_proto_items") == 0)
+                    pref = prefs_find_preference(protocols_module, dotp);
+            } else if (strcmp(module->name, "stream") == 0) {
+                /* stream preferences moved to gui color module */
+                if ((strcmp(dotp, "client.fg") == 0) ||
+                    (strcmp(dotp, "client.bg") == 0) ||
+                    (strcmp(dotp, "server.fg") == 0) ||
+                    (strcmp(dotp, "server.bg") == 0))
+                    pref = prefs_find_preference(gui_color_module, pref_name);
+            } else if (strcmp(module->name, "nameres") == 0) {
+                if (strcmp(pref_name, "name_resolve_concurrency") == 0) {
+                    pref = prefs_find_preference(nameres_module, pref_name);
+                } else if (strcmp(pref_name, "name_resolve_load_smi_modules") == 0) {
+                    pref = prefs_find_preference(nameres_module, "load_smi_modules");
+                } else if (strcmp(pref_name, "name_resolve_suppress_smi_errors") == 0) {
+                    pref = prefs_find_preference(nameres_module, "suppress_smi_errors");
+                }
+            }
+        }
+        if (pref == NULL)
+            return PREFS_SET_NO_SUCH_PREF;        /* no such preference */
 
-    case PREF_ENUM:
-      /* XXX - give an error if it doesn't match? */
-      enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
-                                     *pref->varp.enump);
-      if (*pref->varp.enump != enum_val) {
-        module->prefs_changed = TRUE;
-        *pref->varp.enump = enum_val;
-      }
-      break;
+        type = pref->type;
+        if (IS_PREF_OBSOLETE(type)) {
+            return PREFS_SET_OBSOLETE;        /* no such preference any more */
+        } else {
+            RESET_PREF_OBSOLETE(type);
+        }
 
-    case PREF_STRING:
-    case PREF_FILENAME:
-    case PREF_DIRNAME:
-      if (strcmp(*pref->varp.string, value) != 0) {
-        module->prefs_changed = TRUE;
-        g_free((void *)*pref->varp.string);
-        *pref->varp.string = g_strdup(value);
-      }
-      break;
+        switch (type) {
 
-    case PREF_RANGE:
-    {
-      range_t *newrange;
+        case PREF_UINT:
+            /* XXX - give an error if it doesn't fit in a guint? */
+            uval = (guint)strtoul(value, &p, pref->info.base);
+            if (p == value || *p != '\0')
+                return PREFS_SET_SYNTAX_ERR;        /* number was bad */
+            if (*pref->varp.uint != uval) {
+                containing_module->prefs_changed = TRUE;
+                *pref->varp.uint = uval;
+            }
+            break;
+        case PREF_DECODE_AS_UINT:
+        {
+            /* This is for backwards compatibility in case any of the preferences
+               that shared the "Decode As" preference name and used to be PREF_UINT
+               are now applied directly to the Decode As funtionality */
+
+            dissector_table_t sub_dissectors;
+            dissector_handle_t handle;
+
+            /* XXX - give an error if it doesn't fit in a guint? */
+            uval = (guint)strtoul(value, &p, pref->info.base);
+            if (p == value || *p != '\0')
+                return PREFS_SET_SYNTAX_ERR;        /* number was bad */
+
+            if (*pref->varp.uint != uval) {
+                containing_module->prefs_changed = TRUE;
+                *pref->varp.uint = uval;
+
+                /* Name of preference is the dissector table */
+                sub_dissectors = find_dissector_table(pref->name);
+                if (sub_dissectors != NULL) {
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+                    if (handle != NULL) {
+                        if (uval != 0) {
+                            dissector_change_uint(pref->name, uval, handle);
+                            decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(uval), NULL, NULL);
+                        } else {
+                            dissector_delete_uint(pref->name, *pref->varp.uint, handle);
+                            decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), pref->varp.uint, NULL, NULL);
+                        }
+
+                        /* XXX - Do we save the decode_as_entries file here? */
+                    }
+                }
+            }
+            break;
+        }
+        case PREF_BOOL:
+            /* XXX - give an error if it's neither "true" nor "false"? */
+            if (g_ascii_strcasecmp(value, "true") == 0)
+                bval = TRUE;
+            else
+                bval = FALSE;
+            if (*pref->varp.boolp != bval) {
+                containing_module->prefs_changed = TRUE;
+                *pref->varp.boolp = bval;
+            }
+            break;
 
-      if (range_convert_str_work(&newrange, value, pref->info.max_value,
-                                 return_range_errors) != CVT_NO_ERROR) {
-        return PREFS_SET_SYNTAX_ERR;        /* number was bad */
-      }
+        case PREF_ENUM:
+            /* XXX - give an error if it doesn't match? */
+            enum_val = find_val_for_string(value, pref->info.enum_info.enumvals,
+                                           *pref->varp.enump);
+            if (*pref->varp.enump != enum_val) {
+                containing_module->prefs_changed = TRUE;
+                *pref->varp.enump = enum_val;
+            }
+            break;
 
-      if (!ranges_are_equal(*pref->varp.range, newrange)) {
-        module->prefs_changed = TRUE;
-        g_free(*pref->varp.range);
-        *pref->varp.range = newrange;
-      } else {
-        g_free (newrange);
-      }
-      break;
-    }
+        case PREF_STRING:
+        case PREF_FILENAME:
+        case PREF_DIRNAME:
+            containing_module->prefs_changed |= prefs_set_string_value(pref, value, pref_current);
+            break;
 
-    case PREF_COLOR:
-    {
-      cval = strtoul(value, NULL, 16);
-      pref->varp.colorp->pixel = 0;
-      if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
-          (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
-          (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
-          module->prefs_changed = TRUE;
-          pref->varp.colorp->red   = RED_COMPONENT(cval);
-          pref->varp.colorp->green = GREEN_COMPONENT(cval);
-          pref->varp.colorp->blue  = BLUE_COMPONENT(cval);
-      }
-      break;
-    }
+        case PREF_RANGE:
+        {
+            if (!prefs_set_range_value_work(pref, value, return_range_errors,
+                                            &containing_module->prefs_changed))
+                return PREFS_SET_SYNTAX_ERR;        /* number was bad */
+            break;
+        }
+        case PREF_DECODE_AS_RANGE:
+        {
+            /* This is for backwards compatibility in case any of the preferences
+               that shared the "Decode As" preference name and used to be PREF_RANGE
+               are now applied directly to the Decode As funtionality */
+            range_t *newrange;
+            dissector_table_t sub_dissectors;
+            dissector_handle_t handle;
+            guint32 i, j;
+
+            if (range_convert_str_work(wmem_epan_scope(), &newrange, value, pref->info.max_value,
+                                       return_range_errors) != CVT_NO_ERROR) {
+                return PREFS_SET_SYNTAX_ERR;        /* number was bad */
+            }
 
-    case PREF_CUSTOM:
-        return pref->custom_cbs.set_cb(pref, value, &module->prefs_changed);
+            if (!ranges_are_equal(*pref->varp.range, newrange)) {
+                wmem_free(wmem_epan_scope(), *pref->varp.range);
+                *pref->varp.range = newrange;
+                containing_module->prefs_changed = TRUE;
+
+                /* Name of preference is the dissector table */
+                sub_dissectors = find_dissector_table(pref->name);
+                if (sub_dissectors != NULL) {
+                    handle = dissector_table_get_dissector_handle(sub_dissectors, (gchar*)module->title);
+                    if (handle != NULL) {
+                        /* Delete all of the old values from the dissector table */
+                               for (i = 0; i < (*pref->varp.range)->nranges; i++) {
+                                       for (j = (*pref->varp.range)->ranges[i].low; j < (*pref->varp.range)->ranges[i].high; j++) {
+                                dissector_delete_uint(pref->name, j, handle);
+                                decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+                            }
+
+                            dissector_delete_uint(pref->name, (*pref->varp.range)->ranges[i].high, handle);
+                            decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER((*pref->varp.range)->ranges[i].high), NULL, NULL);
+                               }
+
+                        /* Add new values to the dissector table */
+                               for (i = 0; i < newrange->nranges; i++) {
+                                       for (j = newrange->ranges[i].low; j < newrange->ranges[i].high; j++) {
+                                dissector_change_uint(pref->name, j, handle);
+                                decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(j), NULL, NULL);
+                            }
+
+                            dissector_change_uint(pref->name, newrange->ranges[i].high, handle);
+                            decode_build_reset_list(pref->name, dissector_table_get_type(sub_dissectors), GUINT_TO_POINTER(newrange->ranges[i].high), NULL, NULL);
+                               }
+
+                        /* XXX - Do we save the decode_as_entries file here? */
+                    }
+                }
+            } else {
+                wmem_free(wmem_epan_scope(), newrange);
+            }
+            break;
+        }
 
-    case PREF_STATIC_TEXT:
-    case PREF_UAT:
-    {
-      break;
-    }
+        case PREF_COLOR:
+        {
+            cval = strtoul(value, NULL, 16);
+            if ((pref->varp.colorp->red != RED_COMPONENT(cval)) ||
+                (pref->varp.colorp->green != GREEN_COMPONENT(cval)) ||
+                (pref->varp.colorp->blue != BLUE_COMPONENT(cval))) {
+                containing_module->prefs_changed = TRUE;
+                pref->varp.colorp->red   = RED_COMPONENT(cval);
+                pref->varp.colorp->green = GREEN_COMPONENT(cval);
+                pref->varp.colorp->blue  = BLUE_COMPONENT(cval);
+            }
+            break;
+        }
 
-    case PREF_OBSOLETE:
-      return PREFS_SET_OBSOLETE;        /* no such preference any more */
+        case PREF_CUSTOM:
+            return pref->custom_cbs.set_cb(pref, value, &containing_module->prefs_changed);
+
+        case PREF_STATIC_TEXT:
+        case PREF_UAT:
+        {
+            break;
+        }
+        }
     }
-  }
 
-  return PREFS_SET_OK;
+    return PREFS_SET_OK;
 }
 
 typedef struct {
@@ -4296,12 +5849,21 @@ const char *
 prefs_pref_type_name(pref_t *pref)
 {
     const char *type_name = "[Unknown]";
+    int type;
 
     if (!pref) {
         return type_name; /* ...or maybe assert? */
     }
 
-    switch (pref->type) {
+    type = pref->type;
+
+    if (IS_PREF_OBSOLETE(type)) {
+        type_name = "Obsolete";
+    } else {
+        RESET_PREF_OBSOLETE(type);
+    }
+
+    switch (type) {
 
     case PREF_UINT:
         switch (pref->info.base) {
@@ -4354,8 +5916,12 @@ prefs_pref_type_name(pref_t *pref)
         type_name = "Custom";
         break;
 
-    case PREF_OBSOLETE:
-        type_name = "Obsolete";
+    case PREF_DECODE_AS_UINT:
+        type_name = "Decode As value";
+        break;
+
+    case PREF_DECODE_AS_RANGE:
+        type_name = "Range (for Decode As)";
         break;
 
     case PREF_STATIC_TEXT:
@@ -4372,13 +5938,22 @@ prefs_pref_type_name(pref_t *pref)
 char *
 prefs_pref_type_description(pref_t *pref)
 {
-    const char *type_desc = "An unkown preference type";
+    const char *type_desc = "An unknown preference type";
+    int type;
 
     if (!pref) {
         return g_strdup_printf("%s.", type_desc); /* ...or maybe assert? */
     }
 
-    switch (pref->type) {
+    type = pref->type;
+
+    if (IS_PREF_OBSOLETE(type)) {
+        type_desc = "An obsolete preference";
+    } else {
+        RESET_PREF_OBSOLETE(type);
+    }
+
+    switch (type) {
 
     case PREF_UINT:
         switch (pref->info.base) {
@@ -4446,8 +6021,12 @@ prefs_pref_type_description(pref_t *pref)
         type_desc = "A custom value";
         break;
 
-    case PREF_OBSOLETE:
-        type_desc = "An obsolete preference";
+    case PREF_DECODE_AS_UINT:
+        type_desc = "An integer value used in Decode As";
+        break;
+
+    case PREF_DECODE_AS_RANGE:
+        type_desc = "A string denoting an positive integer range for Decode As";
         break;
 
     case PREF_STATIC_TEXT:
@@ -4464,11 +6043,25 @@ prefs_pref_type_description(pref_t *pref)
     return g_strdup(type_desc);
 }
 
-static gboolean
-prefs_pref_is_default(pref_t *pref) {
+gboolean
+prefs_pref_is_default(pref_t *pref)
+{
+    int type;
     if (!pref) return FALSE;
 
-    switch (pref->type) {
+    type = pref->type;
+    if (IS_PREF_OBSOLETE(type)) {
+        return FALSE;
+    } else {
+        RESET_PREF_OBSOLETE(type);
+    }
+
+    switch (type) {
+
+    case PREF_DECODE_AS_UINT:
+        if (pref->default_val.uint == *pref->varp.uint)
+            return TRUE;
+        break;
 
     case PREF_UINT:
         if (pref->default_val.uint == *pref->varp.uint)
@@ -4492,6 +6085,7 @@ prefs_pref_is_default(pref_t *pref) {
             return TRUE;
         break;
 
+    case PREF_DECODE_AS_RANGE:
     case PREF_RANGE:
     {
         if ((ranges_are_equal(pref->default_val.range, *pref->varp.range)))
@@ -4511,7 +6105,6 @@ prefs_pref_is_default(pref_t *pref) {
     case PREF_CUSTOM:
         return pref->custom_cbs.is_default_cb(pref);
 
-    case PREF_OBSOLETE:
     case PREF_STATIC_TEXT:
     case PREF_UAT:
         return FALSE;
@@ -4524,12 +6117,10 @@ prefs_pref_is_default(pref_t *pref) {
 char *
 prefs_pref_to_str(pref_t *pref, pref_source_t source) {
     const char *pref_text = "[Unknown]";
-    guint pref_uint;
-    gboolean pref_boolval;
-    gint pref_enumval;
-    const char *pref_string;
-    range_t *pref_range;
+    void *valp; /* pointer to preference value */
     color_t *pref_color;
+    gchar *tmp_value, *ret_value;
+    int type;
 
     if (!pref) {
         return g_strdup(pref_text);
@@ -4537,58 +6128,57 @@ prefs_pref_to_str(pref_t *pref, pref_source_t source) {
 
     switch (source) {
         case pref_default:
-            pref_uint = pref->default_val.uint;
-            pref_boolval = pref->default_val.boolval;
-            pref_enumval = pref->default_val.enumval;
-            pref_string = pref->default_val.string;
-            pref_range = pref->default_val.range;
+            valp = &pref->default_val;
+            /* valp = &boolval, &enumval, etc. are implied by union property */
             pref_color = &pref->default_val.color;
             break;
         case pref_stashed:
-            pref_uint = pref->stashed_val.uint;
-            pref_boolval = pref->stashed_val.boolval;
-            pref_enumval = pref->stashed_val.enumval;
-            pref_string = pref->stashed_val.string;
-            pref_range = pref->stashed_val.range;
+            valp = &pref->stashed_val;
+            /* valp = &boolval, &enumval, etc. are implied by union property */
             pref_color = &pref->stashed_val.color;
             break;
         case pref_current:
-            pref_uint = *pref->varp.uint;
-            pref_boolval = *pref->varp.boolp;
-            pref_enumval = *pref->varp.enump;
-            pref_string = *pref->varp.string;
-            pref_range = *pref->varp.range;
+            valp = pref->varp.uint;
+            /* valp = boolval, enumval, etc. are implied by union property */
             pref_color = pref->varp.colorp;
             break;
         default:
             return g_strdup(pref_text);
     }
 
-    switch (pref->type) {
+    type = pref->type;
+    if (IS_PREF_OBSOLETE(type)) {
+        pref_text = "[Obsolete]";
+    } else {
+        RESET_PREF_OBSOLETE(type);
+    }
 
+    switch (type) {
+
+    case PREF_DECODE_AS_UINT:
     case PREF_UINT:
+    {
+        guint pref_uint = *(guint *) valp;
         switch (pref->info.base) {
 
         case 10:
             return g_strdup_printf("%u", pref_uint);
-            break;
 
         case 8:
             return g_strdup_printf("%#o", pref_uint);
-            break;
 
         case 16:
             return g_strdup_printf("%#x", pref_uint);
-            break;
         }
         break;
+    }
 
     case PREF_BOOL:
-        return g_strdup_printf("%s", pref_boolval ? "TRUE" : "FALSE");
-        break;
+        return g_strdup((*(gboolean *) valp) ? "TRUE" : "FALSE");
 
     case PREF_ENUM:
     {
+        gint pref_enumval = *(gint *) valp;
         /*
          * For now, we return the "description" value, so that if we
          * save the preferences older versions of Wireshark can at
@@ -4608,19 +6198,21 @@ prefs_pref_to_str(pref_t *pref, pref_source_t source) {
     case PREF_STRING:
     case PREF_FILENAME:
     case PREF_DIRNAME:
-        return g_strdup(pref_string);
-        break;
+        return g_strdup(*(const char **) valp);
 
+    case PREF_DECODE_AS_RANGE:
     case PREF_RANGE:
-        pref_text = range_convert_range(pref_range);
-        break;
+        /* Convert wmem to g_alloc memory */
+        tmp_value = range_convert_range(NULL, *(range_t **) valp);
+        ret_value = g_strdup(tmp_value);
+        wmem_free(NULL, tmp_value);
+        return ret_value;
 
     case PREF_COLOR:
         return g_strdup_printf("%02x%02x%02x",
                    (pref_color->red * 255 / 65535),
                    (pref_color->green * 255 / 65535),
                    (pref_color->blue * 255 / 65535));
-        break;
 
     case PREF_CUSTOM:
         if (pref->custom_cbs.to_str_cb)
@@ -4628,10 +6220,6 @@ prefs_pref_to_str(pref_t *pref, pref_source_t source) {
         pref_text = "[Custom]";
         break;
 
-    case PREF_OBSOLETE:
-        pref_text = "[Obsolete]";
-        break;
-
     case PREF_STATIC_TEXT:
         pref_text = "[Static text]";
         break;
@@ -4662,9 +6250,11 @@ write_pref(gpointer data, gpointer user_data)
     write_pref_arg_t *arg = (write_pref_arg_t *)user_data;
     gchar **desc_lines;
     int i;
+    int type;
 
-    switch (pref->type) {
-    case PREF_OBSOLETE:
+    type = pref->type;
+
+    if (IS_PREF_OBSOLETE(type)) {
         /*
          * This preference is no longer supported; it's not a
          * real preference, so we don't write it out (i.e., we
@@ -4672,11 +6262,20 @@ write_pref(gpointer data, gpointer user_data)
          * preferences, and we weren't called in the first place).
          */
         return;
+    } else {
+        RESET_PREF_OBSOLETE(type);
+    }
+
+    switch (type) {
 
     case PREF_STATIC_TEXT:
     case PREF_UAT:
         /* Nothing to do; don't bother printing the description */
         return;
+    case PREF_DECODE_AS_UINT:
+    case PREF_DECODE_AS_RANGE:
+        /* Data is saved through Decode As mechanism and not part of preferences file */
+        return;
     default:
         break;
     }
@@ -4773,74 +6372,75 @@ write_module_prefs(module_t *module, gpointer user_data)
 int
 write_prefs(char **pf_path_return)
 {
-  char        *pf_path;
-  FILE        *pf;
-  write_gui_pref_arg_t write_gui_pref_info;
+    char        *pf_path;
+    FILE        *pf;
+    write_gui_pref_arg_t write_gui_pref_info;
 
-  /* Needed for "-G defaultprefs" */
-  init_prefs();
+    /* Needed for "-G defaultprefs" */
+    init_prefs();
 
-  /* To do:
-   * - Split output lines longer than MAX_VAL_LEN
-   * - Create a function for the preference directory check/creation
-   *   so that duplication can be avoided with filter.c
-   */
+    /* To do:
+     * - Split output lines longer than MAX_VAL_LEN
+     * - Create a function for the preference directory check/creation
+     *   so that duplication can be avoided with filter.c
+     */
 
-  if (pf_path_return != NULL) {
-    pf_path = get_persconffile_path(PF_NAME, TRUE);
-    if ((pf = ws_fopen(pf_path, "w")) == NULL) {
-      *pf_path_return = pf_path;
-      return errno;
-    }
-  } else {
-    pf = stdout;
-  }
-
-  fputs("# Configuration file for Wireshark " VERSION ".\n"
-        "#\n"
-        "# This file is regenerated each time preferences are saved within\n"
-        "# Wireshark. Making manual changes should be safe, however.\n"
-        "# Preferences that have been commented out have not been\n"
-        "# changed from their default value.\n", pf);
-
-  /*
-   * For "backwards compatibility" the GUI module is written first as it's
-   * at the top of the file.  This is followed by all modules that can't
-   * fit into the preferences read/write API.  Finally the remaining modules
-   * are written in alphabetical order (including of course the protocol preferences)
-   */
-  write_gui_pref_info.pf = pf;
-  write_gui_pref_info.is_gui_module = TRUE;
-
-  write_module_prefs(gui_module, &write_gui_pref_info);
-
-  {
-    struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
-
-    if (fe != NULL)
-      fprintf(pf, "\n####### Filter Expressions ########\n");
-
-    while (fe != NULL) {
-      if (fe->deleted == FALSE) {
-        fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
-        fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
-        fe->enabled == TRUE ? "TRUE" : "FALSE");
-        fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
-      }
-      fe = fe->next;
+    if (pf_path_return != NULL) {
+        pf_path = get_persconffile_path(PF_NAME, TRUE);
+        if ((pf = ws_fopen(pf_path, "w")) == NULL) {
+            *pf_path_return = pf_path;
+            return errno;
+        }
+        g_free(pf_path);
+    } else {
+        pf = stdout;
     }
-  }
 
-  write_gui_pref_info.is_gui_module = FALSE;
-  prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
+    fputs("# Configuration file for Wireshark " VERSION ".\n"
+          "#\n"
+          "# This file is regenerated each time preferences are saved within\n"
+          "# Wireshark. Making manual changes should be safe, however.\n"
+          "# Preferences that have been commented out have not been\n"
+          "# changed from their default value.\n", pf);
 
-  fclose(pf);
+    /*
+     * For "backwards compatibility" the GUI module is written first as it's
+     * at the top of the file.  This is followed by all modules that can't
+     * fit into the preferences read/write API.  Finally the remaining modules
+     * are written in alphabetical order (including of course the protocol preferences)
+     */
+    write_gui_pref_info.pf = pf;
+    write_gui_pref_info.is_gui_module = TRUE;
+
+    write_module_prefs(gui_module, &write_gui_pref_info);
+
+    {
+        struct filter_expression *fe = *(struct filter_expression **)prefs.filter_expressions;
+
+        if (fe != NULL)
+            fprintf(pf, "\n####### Filter Expressions ########\n\n");
+
+        while (fe != NULL) {
+            if (fe->deleted == FALSE) {
+                fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_LABEL, fe->label);
+                fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_ENABLED,
+                        fe->enabled == TRUE ? "TRUE" : "FALSE");
+                fprintf(pf, "%s: %s\n", PRS_GUI_FILTER_EXPR, fe->expression);
+            }
+            fe = fe->next;
+        }
+    }
+
+    write_gui_pref_info.is_gui_module = FALSE;
+    prefs_modules_foreach_submodules(NULL, write_module_prefs, &write_gui_pref_info);
+
+    fclose(pf);
 
-  /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
-     an error indication, or maybe write to a new preferences file and
-     rename that file on top of the old one only if there are not I/O
-     errors. */
-  return 0;
+    /* XXX - catch I/O errors (e.g. "ran out of disk space") and return
+       an error indication, or maybe write to a new preferences file and
+       rename that file on top of the old one only if there are not I/O
+       errors. */
+    return 0;
 }
 
 /** The col_list is only partly managed by the custom preference API
@@ -4848,20 +6448,20 @@ write_prefs(char **pf_path_return)
  * it's freed here
  */
 static void
-free_col_info(GList * list)
+free_col_info(GList *list)
 {
-  fmt_data *cfmt;
+    fmt_data *cfmt;
+    GList *list_head = list;
 
-  while (list != NULL) {
-    cfmt = (fmt_data *)list->data;
+    while (list != NULL) {
+        cfmt = (fmt_data *)list->data;
 
-    g_free(cfmt->title);
-    g_free(cfmt->custom_field);
-    g_free(cfmt);
-    list = g_list_remove_link(list, list);
-  }
-  g_list_free(list);
-  list = NULL;
+        g_free(cfmt->title);
+        g_free(cfmt->custom_fields);
+        g_free(cfmt);
+        list = g_list_next(list);
+    }
+    g_list_free(list_head);
 }
 
 /*