1 #ifndef MC__VIEWER_INTERNAL_H
2 #define MC__VIEWER_INTERNAL_H
3
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <sys/types.h>
7
8 #include "lib/global.h"
9
10 #include "lib/search.h"
11 #include "lib/widget.h"
12 #include "lib/vfs/vfs.h"
13
14 #include "src/keybind-defaults.h"
15 #include "src/filemanager/dir.h"
16
17 #include "mcviewer.h"
18
19
20
21 typedef unsigned char byte;
22
23
24 typedef unsigned int screen_dimen;
25
26
27
28
29 enum view_ds
30 {
31 DS_NONE,
32 DS_STDIO_PIPE,
33 DS_VFS_PIPE,
34 DS_FILE,
35 DS_STRING
36 };
37
38 enum ccache_type
39 {
40 CCACHE_OFFSET,
41 CCACHE_LINECOL
42 };
43
44 typedef enum
45 {
46 NROFF_TYPE_NONE = 0,
47 NROFF_TYPE_BOLD = 1,
48 NROFF_TYPE_UNDERLINE = 2
49 } nroff_type_t;
50
51
52
53
54 struct hexedit_change_node
55 {
56 struct hexedit_change_node *next;
57 off_t offset;
58 byte value;
59 };
60
61 struct area
62 {
63 screen_dimen top, left;
64 screen_dimen height, width;
65 };
66
67
68
69
70
71
72 typedef struct
73 {
74 off_t cc_offset;
75 off_t cc_line;
76 off_t cc_column;
77 off_t cc_nroff_column;
78 } coord_cache_entry_t;
79
80 typedef struct
81 {
82 size_t size;
83 size_t capacity;
84 coord_cache_entry_t **cache;
85 } coord_cache_t;
86
87
88
89
90 typedef struct
91 {
92 off_t offset;
93 off_t unwrapped_column;
94
95 gboolean nroff_underscore_is_underlined;
96 gboolean print_lonely_combining;
97 } mcview_state_machine_t;
98
99 struct mcview_nroff_struct;
100
101 struct WView
102 {
103 Widget widget;
104
105 vfs_path_t *filename_vpath;
106 vfs_path_t *workdir_vpath;
107 char *command;
108
109 enum view_ds datasource;
110
111
112 mc_pipe_t *ds_stdio_pipe;
113 gboolean pipe_first_err_msg;
114
115
116 int ds_vfs_pipe;
117
118
119 int ds_file_fd;
120 off_t ds_file_filesize;
121 off_t ds_file_offset;
122 byte *ds_file_data;
123 size_t ds_file_datalen;
124 size_t ds_file_datasize;
125
126
127 byte *ds_string_data;
128 size_t ds_string_len;
129
130
131 gboolean growbuf_in_use;
132 GPtrArray *growbuf_blockptr;
133 size_t growbuf_lastindex;
134
135 gboolean growbuf_finished;
136
137 mcview_mode_flags_t mode_flags;
138
139
140 gboolean hexedit_mode;
141 const global_keymap_t *hex_keymap;
142 gboolean hexview_in_text;
143 int bytes_per_line;
144 off_t hex_cursor;
145 gboolean hexedit_lownibble;
146 gboolean locked;
147
148 #ifdef HAVE_CHARSET
149 gboolean utf8;
150 #endif
151
152 coord_cache_t *coord_cache;
153
154
155 screen_dimen dpy_frame_size;
156 off_t dpy_start;
157 off_t dpy_end;
158 off_t dpy_paragraph_skip_lines;
159 mcview_state_machine_t dpy_state_top;
160 mcview_state_machine_t dpy_state_bottom;
161 gboolean dpy_wrap_dirty;
162 off_t dpy_text_column;
163
164 screen_dimen cursor_col;
165 screen_dimen cursor_row;
166 struct hexedit_change_node *change_list;
167 struct area status_area;
168 struct area ruler_area;
169 struct area data_area;
170
171 ssize_t force_max;
172
173 int dirty;
174 gboolean dpy_bbar_dirty;
175
176
177
178 mc_search_t *search;
179 gchar *last_search_string;
180 struct mcview_nroff_struct *search_nroff_seq;
181 off_t search_start;
182 off_t search_end;
183 int search_numNeedSkipChar;
184
185
186 int marker;
187 off_t marks[10];
188
189 off_t update_steps;
190 off_t update_activate;
191
192
193 GIConv converter;
194
195 GArray *saved_bookmarks;
196
197 dir_list *dir;
198
199 int *dir_idx;
200
201 vfs_path_t *ext_script;
202 };
203
204 typedef struct mcview_nroff_struct
205 {
206 WView *view;
207 off_t index;
208 int char_length;
209 int current_char;
210 nroff_type_t type;
211 nroff_type_t prev_type;
212 } mcview_nroff_t;
213
214 typedef struct mcview_search_options_t
215 {
216 mc_search_type_t type;
217 gboolean case_sens;
218 gboolean backwards;
219 gboolean whole_words;
220 gboolean all_codepages;
221 } mcview_search_options_t;
222
223
224
225 extern mcview_search_options_t mcview_search_options;
226
227
228
229
230 cb_ret_t mcview_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm, void *data);
231 cb_ret_t mcview_dialog_callback (Widget * w, Widget * sender, widget_msg_t msg, int parm,
232 void *data);
233
234
235 void mcview_display_text (WView *);
236 void mcview_state_machine_init (mcview_state_machine_t *, off_t);
237 void mcview_ascii_move_down (WView *, off_t);
238 void mcview_ascii_move_up (WView *, off_t);
239 void mcview_ascii_moveto_bol (WView *);
240 void mcview_ascii_moveto_eol (WView *);
241
242
243 coord_cache_t *coord_cache_new (void);
244 void coord_cache_free (coord_cache_t * cache);
245
246 #ifdef MC_ENABLE_DEBUGGING_CODE
247 void mcview_ccache_dump (WView * view);
248 #endif
249
250 void mcview_ccache_lookup (WView * view, coord_cache_entry_t * coord, enum ccache_type lookup_what);
251
252
253 void mcview_set_datasource_none (WView *);
254 off_t mcview_get_filesize (WView *);
255 void mcview_update_filesize (WView * view);
256 char *mcview_get_ptr_file (WView *, off_t);
257 char *mcview_get_ptr_string (WView *, off_t);
258 gboolean mcview_get_utf (WView * view, off_t byte_index, int *ch, int *ch_len);
259 gboolean mcview_get_byte_string (WView *, off_t, int *);
260 gboolean mcview_get_byte_none (WView *, off_t, int *);
261 void mcview_set_byte (WView *, off_t, byte);
262 void mcview_file_load_data (WView *, off_t);
263 void mcview_close_datasource (WView *);
264 void mcview_set_datasource_file (WView *, int, const struct stat *);
265 gboolean mcview_load_command_output (WView *, const char *);
266 void mcview_set_datasource_vfs_pipe (WView *, int);
267 void mcview_set_datasource_string (WView *, const char *);
268
269
270 gboolean mcview_dialog_search (WView * view);
271 gboolean mcview_dialog_goto (WView * view, off_t * offset);
272
273
274 void mcview_update (WView * view);
275 void mcview_display (WView * view);
276 void mcview_compute_areas (WView * view);
277 void mcview_update_bytes_per_line (WView * view);
278 void mcview_display_toggle_ruler (WView * view);
279 void mcview_display_clean (WView * view);
280 void mcview_display_ruler (WView * view);
281
282
283 void mcview_growbuf_init (WView * view);
284 void mcview_growbuf_done (WView * view);
285 void mcview_growbuf_free (WView * view);
286 off_t mcview_growbuf_filesize (WView * view);
287 void mcview_growbuf_read_until (WView * view, off_t p);
288 gboolean mcview_get_byte_growing_buffer (WView * view, off_t p, int *);
289 char *mcview_get_ptr_growing_buffer (WView * view, off_t p);
290
291
292 void mcview_display_hex (WView * view);
293 gboolean mcview_hexedit_save_changes (WView * view);
294 void mcview_toggle_hexedit_mode (WView * view);
295 void mcview_hexedit_free_change_list (WView * view);
296 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
297
298
299 void mcview_toggle_magic_mode (WView * view);
300 void mcview_toggle_wrap_mode (WView * view);
301 void mcview_toggle_nroff_mode (WView * view);
302 void mcview_toggle_hex_mode (WView * view);
303 void mcview_init (WView * view);
304 void mcview_done (WView * view);
305 #ifdef HAVE_CHARSET
306 void mcview_select_encoding (WView * view);
307 void mcview_set_codeset (WView * view);
308 #endif
309 void mcview_show_error (WView * view, const char *error);
310 off_t mcview_bol (WView * view, off_t current, off_t limit);
311 off_t mcview_eol (WView * view, off_t current);
312 char *mcview_get_title (const WDialog * h, size_t len);
313 int mcview_calc_percent (WView * view, off_t p);
314
315
316 void mcview_move_up (WView *, off_t);
317 void mcview_move_down (WView *, off_t);
318 void mcview_move_left (WView *, off_t);
319 void mcview_move_right (WView *, off_t);
320 void mcview_moveto_top (WView *);
321 void mcview_moveto_bottom (WView *);
322 void mcview_moveto_bol (WView *);
323 void mcview_moveto_eol (WView *);
324 void mcview_moveto_offset (WView *, off_t);
325 void mcview_moveto (WView *, off_t, off_t);
326 void mcview_coord_to_offset (WView *, off_t *, off_t, off_t);
327 void mcview_offset_to_coord (WView *, off_t *, off_t *, off_t);
328 void mcview_place_cursor (WView *);
329 void mcview_moveto_match (WView *);
330
331
332 int mcview__get_nroff_real_len (WView * view, off_t, off_t p);
333 mcview_nroff_t *mcview_nroff_seq_new_num (WView * view, off_t p);
334 mcview_nroff_t *mcview_nroff_seq_new (WView * view);
335 void mcview_nroff_seq_free (mcview_nroff_t **);
336 nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
337 int mcview_nroff_seq_next (mcview_nroff_t *);
338 int mcview_nroff_seq_prev (mcview_nroff_t *);
339
340
341 mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
342 int *current_char);
343 mc_search_cbret_t mcview_search_update_cmd_callback (const void *user_data, gsize char_offset);
344 void mcview_do_search (WView * view, off_t want_search_start);
345
346
347
348 #include "inlines.h"
349
350 #endif