nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | /* language.c |
2 | * Language "preference" handling routines |
||
3 | * Copyright 2014, Michal Labedzki for Tieto Corporation |
||
4 | * |
||
5 | * Wireshark - Network traffic analyzer |
||
6 | * By Gerald Combs <gerald@wireshark.org> |
||
7 | * Copyright 1998 Gerald Combs |
||
8 | * |
||
9 | * This program is free software; you can redistribute it and/or |
||
10 | * modify it under the terms of the GNU General Public License |
||
11 | * as published by the Free Software Foundation; either version 2 |
||
12 | * of the License, or (at your option) any later version. |
||
13 | * |
||
14 | * This program is distributed in the hope that it will be useful, |
||
15 | * but WITHOUT ANY WARRANTY; without even the implied warranty of |
||
16 | * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the |
||
17 | * GNU General Public License for more details. |
||
18 | * |
||
19 | * You should have received a copy of the GNU General Public License |
||
20 | * along with this program; if not, write to the Free Software |
||
21 | * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA. |
||
22 | */ |
||
23 | |||
24 | #include "config.h" |
||
25 | |||
26 | #include <stdlib.h> |
||
27 | #include <errno.h> |
||
28 | |||
29 | #include <epan/prefs.h> |
||
30 | #include <epan/prefs-int.h> |
||
31 | |||
32 | #include <wsutil/filesystem.h> |
||
33 | #include <wsutil/file_util.h> |
||
34 | |||
35 | #include "ui/language.h" |
||
36 | #include "ui/simple_dialog.h" |
||
37 | |||
38 | #define LANGUAGE_FILE_NAME "language" |
||
39 | #define LANGUAGE_PREF_LANGUAGE "language" |
||
40 | |||
41 | char *language = NULL; |
||
42 | |||
43 | /* set one user's recent common file key/value pair */ |
||
44 | static prefs_set_pref_e |
||
45 | read_language_pref(gchar *key, const gchar *value, |
||
46 | void *private_data _U_, gboolean return_range_errors _U_) |
||
47 | { |
||
48 | if (strcmp(key, LANGUAGE_PREF_LANGUAGE) == 0) { |
||
49 | if (language) |
||
50 | g_free(language); |
||
51 | /* |
||
52 | * For backwards compatibility, treat "auto" as meaning "use the |
||
53 | * system language". |
||
54 | * |
||
55 | * To handle the old buggy code that didn't check whether "language" |
||
56 | * was null before trying to print it, treat "(null)" - which many, |
||
57 | * but *NOT* all, system printfs print for a null pointer (some |
||
58 | * printfs, such as the one in Solaris, *crash* with %s and a null |
||
59 | * pointer) - as meaning "use the system language". |
||
60 | */ |
||
61 | if (!value || !*value || strcmp(value, "auto") == 0 || |
||
62 | strcmp(value, "(null)") == 0) |
||
63 | language = g_strdup(USE_SYSTEM_LANGUAGE); |
||
64 | else |
||
65 | language = g_strdup(value); |
||
66 | } |
||
67 | |||
68 | return PREFS_SET_OK; |
||
69 | } |
||
70 | |||
71 | void |
||
72 | read_language_prefs(void) |
||
73 | { |
||
74 | char *rf_path; |
||
75 | FILE *rf; |
||
76 | |||
77 | rf_path = get_persconffile_path(LANGUAGE_FILE_NAME, FALSE); |
||
78 | |||
79 | if ((rf = ws_fopen(rf_path, "r")) != NULL) { |
||
80 | read_prefs_file(rf_path, rf, read_language_pref, NULL); |
||
81 | |||
82 | fclose(rf); |
||
83 | } |
||
84 | |||
85 | g_free(rf_path); |
||
86 | } |
||
87 | |||
88 | gboolean |
||
89 | write_language_prefs(void) |
||
90 | { |
||
91 | char *pf_dir_path; |
||
92 | char *rf_path; |
||
93 | FILE *rf; |
||
94 | |||
95 | /* To do: |
||
96 | * - Split output lines longer than MAX_VAL_LEN |
||
97 | * - Create a function for the preference directory check/creation |
||
98 | * so that duplication can be avoided with filter.c |
||
99 | */ |
||
100 | |||
101 | /* Create the directory that holds personal configuration files, if |
||
102 | necessary. */ |
||
103 | if (create_persconffile_dir(&pf_dir_path) == -1) { |
||
104 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, |
||
105 | "Can't create directory\n\"%s\"\nfor language file: %s.", pf_dir_path, |
||
106 | g_strerror(errno)); |
||
107 | g_free(pf_dir_path); |
||
108 | return FALSE; |
||
109 | } |
||
110 | |||
111 | rf_path = get_persconffile_path(LANGUAGE_FILE_NAME, FALSE); |
||
112 | if ((rf = ws_fopen(rf_path, "w")) == NULL) { |
||
113 | simple_dialog(ESD_TYPE_ERROR, ESD_BTN_OK, |
||
114 | "Can't open recent file\n\"%s\": %s.", rf_path, |
||
115 | g_strerror(errno)); |
||
116 | g_free(rf_path); |
||
117 | return FALSE; |
||
118 | } |
||
119 | g_free(rf_path); |
||
120 | |||
121 | fputs("# Language settings file for Wireshark " VERSION ".\n" |
||
122 | "#\n" |
||
123 | "# This file is regenerated each time Wireshark is quit.\n" |
||
124 | "# So be careful, if you want to make manual changes here.\n" |
||
125 | "\n", rf); |
||
126 | |||
127 | fprintf(rf, LANGUAGE_PREF_LANGUAGE ": %s\n", language ? language : USE_SYSTEM_LANGUAGE); |
||
128 | |||
129 | fclose(rf); |
||
130 | |||
131 | return TRUE; |
||
132 | } |
||
133 | |||
134 | /* |
||
135 | * Editor modelines - http://www.wireshark.org/tools/modelines.html |
||
136 | * |
||
137 | * Local variables: |
||
138 | * c-basic-offset: 4 |
||
139 | * tab-width: 8 |
||
140 | * indent-tabs-mode: nil |
||
141 | * End: |
||
142 | * |
||
143 | * vi: set shiftwidth=4 tabstop=8 expandtab: |
||
144 | * :indentSize=4:tabSize=8:noTabs=true: |
||
145 | */ |