2 * Language "preference" handling routines
3 * Copyright 2014, Michal Labedzki for Tieto Corporation
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later*/
16 #include <epan/prefs.h>
17 #include <epan/prefs-int.h>
19 #include <wsutil/filesystem.h>
20 #include <wsutil/file_util.h>
22 #include "ui/language.h"
23 #include "ui/simple_dialog.h"
25 #define LANGUAGE_FILE_NAME "language"
26 #define LANGUAGE_PREF_LANGUAGE "language"
28 char *language = NULL;
30 /* set one user's recent common file key/value pair */
31 static prefs_set_pref_e
32 read_language_pref(gchar *key, const gchar *value,
33 void *private_data _U_, gboolean return_range_errors _U_)
35 if (strcmp(key, LANGUAGE_PREF_LANGUAGE) == 0) {
38 * For backwards compatibility, treat "auto" as meaning "use the
41 * To handle the old buggy code that didn't check whether "language"
42 * was null before trying to print it, treat "(null)" - which many,
43 * but *NOT* all, system printfs print for a null pointer (some
44 * printfs, such as the one in Solaris, *crash* with %s and a null
45 * pointer) - as meaning "use the system language".
47 if (!value || !*value || strcmp(value, "auto") == 0 ||
48 strcmp(value, "(null)") == 0)
49 language = g_strdup(USE_SYSTEM_LANGUAGE);
51 language = g_strdup(value);
58 read_language_prefs(void)
63 rf_path = get_persconffile_path(LANGUAGE_FILE_NAME, FALSE);
65 if ((rf = ws_fopen(rf_path, "r")) != NULL) {
66 read_prefs_file(rf_path, rf, read_language_pref, NULL);
75 write_language_prefs(void)
82 * - Split output lines longer than MAX_VAL_LEN
83 * - Create a function for the preference directory check/creation
84 * so that duplication can be avoided with filter.c
87 /* Create the directory that holds personal configuration files, if
89 if (create_persconffile_dir(&pf_dir_path) == -1) {
90 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
91 "Can't create directory\n\"%s\"\nfor language file: %s.", pf_dir_path,
97 rf_path = get_persconffile_path(LANGUAGE_FILE_NAME, FALSE);
98 if ((rf = ws_fopen(rf_path, "w")) == NULL) {
99 simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK,
100 "Can't open recent file\n\"%s\": %s.", rf_path,
107 fputs("# Language settings file for Wireshark " VERSION ".\n"
109 "# This file is regenerated each time Wireshark is quit.\n"
110 "# So be careful, if you want to make manual changes here.\n"
113 fprintf(rf, LANGUAGE_PREF_LANGUAGE ": %s\n", language ? language : USE_SYSTEM_LANGUAGE);
121 * Editor modelines - http://www.wireshark.org/tools/modelines.html
126 * indent-tabs-mode: nil
129 * vi: set shiftwidth=4 tabstop=8 expandtab:
130 * :indentSize=4:tabSize=8:noTabs=true: