This source file includes following definitions.
- mcview_dialog_search
- mcview_dialog_goto
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36 #include <config.h>
37
38 #include <stdlib.h>
39 #include <sys/types.h>
40
41 #include "lib/global.h"
42 #include "lib/search.h"
43 #include "lib/strutil.h"
44 #include "lib/widget.h"
45 #ifdef HAVE_CHARSET
46 #include "lib/charsets.h"
47 #endif
48
49 #include "src/history.h"
50
51 #include "internal.h"
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68 gboolean
69 mcview_dialog_search (WView *view)
70 {
71 char *exp = NULL;
72 int qd_result;
73 size_t num_of_types = 0;
74 gchar **list_of_types;
75
76 list_of_types = mc_search_get_types_strings_array (&num_of_types);
77
78 {
79 quick_widget_t quick_widgets[] = {
80
81 QUICK_LABELED_INPUT (N_("Enter search string:"), input_label_above,
82 INPUT_LAST_TEXT, MC_HISTORY_SHARED_SEARCH, &exp,
83 NULL, FALSE, FALSE, INPUT_COMPLETE_NONE),
84 QUICK_SEPARATOR (TRUE),
85 QUICK_START_COLUMNS,
86 QUICK_RADIO (num_of_types, (const char **) list_of_types,
87 (int *) &mcview_search_options.type, NULL),
88 QUICK_NEXT_COLUMN,
89 QUICK_CHECKBOX (N_("Cas&e sensitive"), &mcview_search_options.case_sens, NULL),
90 QUICK_CHECKBOX (N_("&Backwards"), &mcview_search_options.backwards, NULL),
91 QUICK_CHECKBOX (N_("&Whole words"), &mcview_search_options.whole_words, NULL),
92 #ifdef HAVE_CHARSET
93 QUICK_CHECKBOX (N_("&All charsets"), &mcview_search_options.all_codepages, NULL),
94 #endif
95 QUICK_STOP_COLUMNS,
96 QUICK_BUTTONS_OK_CANCEL,
97 QUICK_END
98
99 };
100
101 WRect r = { -1, -1, 0, 58 };
102
103 quick_dialog_t qdlg = {
104 r, N_("Search"), "[Input Line Keys]",
105 quick_widgets, NULL, NULL
106 };
107
108 qd_result = quick_dialog (&qdlg);
109 }
110
111 g_strfreev (list_of_types);
112
113 if (qd_result == B_CANCEL || exp[0] == '\0')
114 {
115 g_free (exp);
116 return FALSE;
117 }
118
119 #ifdef HAVE_CHARSET
120 {
121 GString *tmp;
122
123 tmp = str_convert_to_input (exp);
124 g_free (exp);
125 if (tmp != NULL)
126 exp = g_string_free (tmp, FALSE);
127 else
128 exp = g_strdup ("");
129 }
130 #endif
131
132 mcview_search_deinit (view);
133 view->last_search_string = exp;
134
135 return mcview_search_init (view);
136 }
137
138
139
140 gboolean
141 mcview_dialog_goto (WView *view, off_t *offset)
142 {
143 typedef enum
144 {
145 MC_VIEW_GOTO_LINENUM = 0,
146 MC_VIEW_GOTO_PERCENT = 1,
147 MC_VIEW_GOTO_OFFSET_DEC = 2,
148 MC_VIEW_GOTO_OFFSET_HEX = 3
149 } mcview_goto_type_t;
150
151 const char *mc_view_goto_str[] = {
152 N_("&Line number"),
153 N_("Pe&rcents"),
154 N_("&Decimal offset"),
155 N_("He&xadecimal offset")
156 };
157
158 static mcview_goto_type_t current_goto_type = MC_VIEW_GOTO_LINENUM;
159
160 size_t num_of_types;
161 char *exp = NULL;
162 int qd_result;
163 gboolean res;
164
165 num_of_types = G_N_ELEMENTS (mc_view_goto_str);
166
167 #ifdef ENABLE_NLS
168 {
169 size_t i;
170
171 for (i = 0; i < num_of_types; i++)
172 mc_view_goto_str[i] = _(mc_view_goto_str[i]);
173 }
174 #endif
175
176 {
177 quick_widget_t quick_widgets[] = {
178
179 QUICK_INPUT (INPUT_LAST_TEXT, MC_HISTORY_VIEW_GOTO, &exp, NULL,
180 FALSE, FALSE, INPUT_COMPLETE_NONE),
181 QUICK_RADIO (num_of_types, (const char **) mc_view_goto_str, (int *) ¤t_goto_type,
182 NULL),
183 QUICK_BUTTONS_OK_CANCEL,
184 QUICK_END
185
186 };
187
188 WRect r = { -1, -1, 0, 40 };
189
190 quick_dialog_t qdlg = {
191 r, N_("Goto"), "[Input Line Keys]",
192 quick_widgets, NULL, NULL
193 };
194
195
196 qd_result = quick_dialog (&qdlg);
197 }
198
199 *offset = -1;
200
201
202 res = (qd_result != B_CANCEL && exp[0] != '\0');
203 if (res)
204 {
205 int base = (current_goto_type == MC_VIEW_GOTO_OFFSET_HEX) ? 16 : 10;
206 off_t addr;
207 char *error;
208
209 addr = (off_t) g_ascii_strtoll (exp, &error, base);
210 if ((*error == '\0') && (addr >= 0))
211 {
212 switch (current_goto_type)
213 {
214 case MC_VIEW_GOTO_LINENUM:
215
216 if (addr > 0)
217 addr--;
218 mcview_coord_to_offset (view, offset, addr, 0);
219 *offset = mcview_bol (view, *offset, 0);
220 break;
221 case MC_VIEW_GOTO_PERCENT:
222 if (addr > 100)
223 addr = 100;
224
225 if (view->growbuf_in_use)
226 mcview_growbuf_read_all_data (view);
227 *offset = addr * mcview_get_filesize (view) / 100;
228 if (!view->mode_flags.hex)
229 *offset = mcview_bol (view, *offset, 0);
230 break;
231 case MC_VIEW_GOTO_OFFSET_DEC:
232 case MC_VIEW_GOTO_OFFSET_HEX:
233 if (!view->mode_flags.hex)
234 {
235 if (view->growbuf_in_use)
236 mcview_growbuf_read_until (view, addr);
237
238 *offset = mcview_bol (view, addr, 0);
239 }
240 else
241 {
242
243 if (view->growbuf_in_use)
244 mcview_growbuf_read_all_data (view);
245
246 *offset = addr;
247 addr = mcview_get_filesize (view);
248 if (*offset > addr)
249 *offset = addr;
250 }
251 break;
252 default:
253 *offset = 0;
254 break;
255 }
256 }
257 }
258
259 g_free (exp);
260 return res;
261 }
262
263