summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorPeter Wu <peter@lekensteyn.nl>2014-04-29 00:06:02 +0200
committerAnders Broman <a.broman58@gmail.com>2014-04-29 04:16:23 +0000
commite8cb6231661ef36f17d3c2a7a9f9d12600120047 (patch)
tree5c2a00e54bd7f69a5e54c9ff297ae34f4002ece9
parentb086b783c2106bb24ebce425f97dd86036ccbb13 (diff)
downloadwireshark-e8cb6231661ef36f17d3c2a7a9f9d12600120047.tar.gz
prefs: spelling fix, simplify code
Found spelling error "a another". All those dynamic allocations and magic numbers are horrible and unnecessary. Simplify the gtk code rewording the message and merging strings. Simplify the version code by using fscanf to take care of matching the first line of a preference file. Change-Id: I1e75803aacaa494ba5005791bcbd023e0807aaaa Reviewed-on: https://code.wireshark.org/review/1424 Reviewed-by: Anders Broman <a.broman58@gmail.com>
-rw-r--r--epan/prefs.c15
-rw-r--r--ui/gtk/prefs_dlg.c29
2 files changed, 14 insertions, 30 deletions
diff --git a/epan/prefs.c b/epan/prefs.c
index 8e2a16cbc9..645023f0dc 100644
--- a/epan/prefs.c
+++ b/epan/prefs.c
@@ -3288,22 +3288,15 @@ read_prefs_file(const char *pf_path, FILE *pf,
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. */
- 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);
- }
- }
+ if (fscanf(pf, "# Configuration file for %127[^\n]", ver) == 1) {
+ /* Assume trailing period and remove it */
+ prefs.saved_at_version = g_strndup(ver, strlen(ver) - 1);
}
rewind(pf);
diff --git a/ui/gtk/prefs_dlg.c b/ui/gtk/prefs_dlg.c
index fc3c4abc78..17a903b592 100644
--- a/ui/gtk/prefs_dlg.c
+++ b/ui/gtk/prefs_dlg.c
@@ -1410,31 +1410,22 @@ prefs_main_save(gpointer parent_w)
{
if (prefs.unknown_prefs) {
gpointer dialog;
- gchar *msg;
- const gchar *msg1 = "These preferences were last saved at version ";
- const gchar *msg2 = "Obsolete or unrecognized preferences have been detected. "
- "If you plan to use this profile with ";
- const gchar *msg3 = "that version of Wireshark, ";
- const gchar *msg4 = "an older or nonstandard Wireshark version, ";
- const gchar *msg5 = "click 'Continue without Saving' and save this profile under a another name.\n";
+ const gchar *msg =
+ "Obsolete or unrecognized preferences have been detected and will be "
+ "discarded when saving this profile. If you would like to preserve "
+ "these preferences for a different Wireshark version, click "
+ "'Continue without Saving' and save this profile under a different name.";
if (prefs.saved_at_version) {
- gulong tot_msg_len = 246 + (gulong)strlen(prefs.saved_at_version) + 1;
-
- msg = (gchar *)g_malloc(tot_msg_len);
- g_snprintf(msg, tot_msg_len, "%s\"%s\". %s%s%s",
- msg1, prefs.saved_at_version, msg2, msg3, msg5);
- dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE, "%s", msg);
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE,
+ "These preferences were last saved at version \"%s\".\n%s",
+ prefs.saved_at_version, msg);
} else {
- msg = (gchar *)g_malloc(214);
-
- g_snprintf(msg, 214, "%s%s%s", msg2, msg4, msg5);
- dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE, "%s", msg);
+ dialog = simple_dialog(ESD_TYPE_CONFIRMATION, ESD_BTNS_SAVE_DONTSAVE,
+ "%s", msg);
}
simple_dialog_set_cb(dialog, overwrite_existing_prefs_cb, parent_w);
- g_free(msg);
-
} else {
prefs_main_write();
}