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
17 #include <epan/prefs.h>
18 #include <epan/prefs-int.h>
20 #include <wsutil/filesystem.h>
21 #include <wsutil/file_util.h>
23 #include "ui/language.h"
24 #include "ui/simple_dialog.h"
26 #define LANGUAGE_FILE_NAME "language"
27 #define LANGUAGE_PREF_LANGUAGE "language"
31 /* set one user's recent common file key/value pair */
32 static prefs_set_pref_e
33 read_language_pref(char *key
, const char *value
,
34 void *private_data _U_
, bool return_range_errors _U_
)
36 if (strcmp(key
, LANGUAGE_PREF_LANGUAGE
) == 0) {
39 * For backwards compatibility, treat "auto" as meaning "use the
42 * To handle the old buggy code that didn't check whether "language"
43 * was null before trying to print it, treat "(null)" - which many,
44 * but *NOT* all, system printfs print for a null pointer (some
45 * printfs, such as the one in Solaris, *crash* with %s and a null
46 * pointer) - as meaning "use the system language".
48 if (!value
|| !*value
|| strcmp(value
, "auto") == 0 ||
49 strcmp(value
, "(null)") == 0)
50 language
= g_strdup(USE_SYSTEM_LANGUAGE
);
52 language
= g_strdup(value
);
59 read_language_prefs(void)
64 rf_path
= get_persconffile_path(LANGUAGE_FILE_NAME
, false);
66 if ((rf
= ws_fopen(rf_path
, "r")) != NULL
) {
67 read_prefs_file(rf_path
, rf
, read_language_pref
, NULL
);
76 write_language_prefs(void)
83 * - Split output lines longer than MAX_VAL_LEN
84 * - Create a function for the preference directory check/creation
85 * so that duplication can be avoided with filter.c
88 /* Create the directory that holds personal configuration files, if
90 if (create_persconffile_dir(&pf_dir_path
) == -1) {
91 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
,
92 "Can't create directory\n\"%s\"\nfor language file: %s.", pf_dir_path
,
98 rf_path
= get_persconffile_path(LANGUAGE_FILE_NAME
, false);
99 if ((rf
= ws_fopen(rf_path
, "w")) == NULL
) {
100 simple_dialog(ESD_TYPE_ERROR
, ESD_BTN_OK
,
101 "Can't open recent file\n\"%s\": %s.", rf_path
,
108 fputs("# Language settings file for Wireshark " VERSION
".\n"
110 "# This file is regenerated each time Wireshark is quit.\n"
111 "# So be careful, if you want to make manual changes here.\n"
114 fprintf(rf
, LANGUAGE_PREF_LANGUAGE
": %s\n", language
? language
: USE_SYSTEM_LANGUAGE
);