Ticket #2814: handle CK_FileNext/CK_FilePrev inside mcviewer.
[midnight-commander.git] / src / viewer / internal.h
blobc044bc8f25eae92ca073b8da75b2dee5c871bff3
1 #ifndef MC__VIEWER_INTERNAL_H
2 #define MC__VIEWER_INTERNAL_H
4 #include <stdlib.h>
5 #include <stdio.h>
6 #include <sys/types.h>
8 #include "lib/global.h"
10 #include "lib/search.h"
11 #include "lib/widget.h"
12 #include "lib/vfs/vfs.h" /* vfs_path_t */
14 #include "src/keybind-defaults.h" /* global_keymap_t */
15 #include "src/filemanager/dir.h" /* dir_list */
17 /*** typedefs(not structures) and defined constants **********************************************/
19 typedef unsigned char byte;
21 /* A width or height on the screen */
22 typedef unsigned int screen_dimen;
24 extern const off_t INVALID_OFFSET;
25 extern const off_t OFFSETTYPE_MAX;
27 /*** enums ***************************************************************************************/
29 /* data sources of the view */
30 enum view_ds
32 DS_NONE, /* No data available */
33 DS_STDIO_PIPE, /* Data comes from a pipe using popen/pclose */
34 DS_VFS_PIPE, /* Data comes from a piped-in VFS file */
35 DS_FILE, /* Data comes from a VFS file */
36 DS_STRING /* Data comes from a string in memory */
39 enum ccache_type
41 CCACHE_OFFSET,
42 CCACHE_LINECOL
45 typedef enum
47 NROFF_TYPE_NONE = 0,
48 NROFF_TYPE_BOLD = 1,
49 NROFF_TYPE_UNDERLINE = 2
50 } nroff_type_t;
52 /*** structures declarations (and typedefs of structures)*****************************************/
54 /* A node for building a change list on change_list */
55 struct hexedit_change_node
57 struct hexedit_change_node *next;
58 off_t offset;
59 byte value;
62 struct area
64 screen_dimen top, left;
65 screen_dimen height, width;
68 /* A cache entry for mapping offsets into line/column pairs and vice versa.
69 * cc_offset, cc_line, and cc_column are the 0-based values of the offset,
70 * line and column of that cache entry. cc_nroff_column is the column
71 * corresponding to cc_offset in nroff mode.
73 typedef struct
75 off_t cc_offset;
76 off_t cc_line;
77 off_t cc_column;
78 off_t cc_nroff_column;
79 } coord_cache_entry_t;
81 typedef struct
83 size_t size;
84 size_t capacity;
85 coord_cache_entry_t **cache;
86 } coord_cache_t;
88 struct mcview_nroff_struct;
90 typedef struct mcview_struct
92 Widget widget;
94 vfs_path_t *filename_vpath; /* Name of the file */
95 vfs_path_t *workdir_vpath; /* Name of the working directory */
96 char *command; /* Command used to pipe data in */
98 enum view_ds datasource; /* Where the displayed data comes from */
100 /* stdio pipe data source */
101 FILE *ds_stdio_pipe; /* Output of a shell command */
103 /* vfs pipe data source */
104 int ds_vfs_pipe; /* Non-seekable vfs file descriptor */
106 /* vfs file data source */
107 int ds_file_fd; /* File with random access */
108 off_t ds_file_filesize; /* Size of the file */
109 off_t ds_file_offset; /* Offset of the currently loaded data */
110 byte *ds_file_data; /* Currently loaded data */
111 size_t ds_file_datalen; /* Number of valid bytes in file_data */
112 size_t ds_file_datasize; /* Number of allocated bytes in file_data */
114 /* string data source */
115 byte *ds_string_data; /* The characters of the string */
116 size_t ds_string_len; /* The length of the string */
118 /* Growing buffers information */
119 gboolean growbuf_in_use; /* Use the growing buffers? */
120 GPtrArray *growbuf_blockptr; /* Pointer to the block pointers */
121 size_t growbuf_lastindex; /* Number of bytes in the last page of the
122 growing buffer */
123 gboolean growbuf_finished; /* TRUE when all data has been read. */
125 /* Editor modes */
126 gboolean hex_mode; /* Hexview or Hexedit */
127 gboolean hexedit_mode; /* Hexedit */
128 gboolean hexview_in_text; /* Is the hexview cursor in the text area? */
129 gboolean text_nroff_mode; /* Nroff-style highlighting */
130 gboolean text_wrap_mode; /* Wrap text lines to fit them on the screen */
131 gboolean magic_mode; /* Preprocess the file using external programs */
132 gboolean hexedit_lownibble; /* Are we editing the last significant nibble? */
133 gboolean locked; /* We hold lock on current file */
135 gboolean utf8; /* It's multibyte file codeset */
137 coord_cache_t *coord_cache; /* Cache for mapping offsets to cursor positions */
139 /* Display information */
140 screen_dimen dpy_frame_size; /* Size of the frame surrounding the real viewer */
141 off_t dpy_start; /* Offset of the displayed data */
142 off_t dpy_end; /* Offset after the displayed data */
143 off_t dpy_text_column; /* Number of skipped columns in non-wrap
144 * text mode */
145 off_t hex_cursor; /* Hexview cursor position in file */
146 screen_dimen cursor_col; /* Cursor column */
147 screen_dimen cursor_row; /* Cursor row */
148 struct hexedit_change_node *change_list; /* Linked list of changes */
149 struct area status_area; /* Where the status line is displayed */
150 struct area ruler_area; /* Where the ruler is displayed */
151 struct area data_area; /* Where the data is displayed */
153 int dirty; /* Number of skipped updates */
154 gboolean dpy_bbar_dirty; /* Does the button bar need to be updated? */
156 /* Mode variables */
157 int bytes_per_line; /* Number of bytes per line in hex mode */
159 /* Search variables */
160 off_t search_start; /* First character to start searching from */
161 off_t search_end; /* Length of found string or 0 if none was found */
163 /* Markers */
164 int marker; /* mark to use */
165 off_t marks[10]; /* 10 marks: 0..9 */
167 int move_dir; /* return value from widget:
168 * 0 do nothing
169 * -1 view previous file
170 * 1 view next file
173 off_t update_steps; /* The number of bytes between percent
174 * increments */
175 off_t update_activate; /* Last point where we updated the status */
177 /* converter for translation of text */
178 GIConv converter;
180 /* handle of search engine */
181 mc_search_t *search;
182 gchar *last_search_string;
183 struct mcview_nroff_struct *search_nroff_seq;
185 int search_numNeedSkipChar;
187 GArray *saved_bookmarks;
189 dir_list *dir; /* List of current directory files
190 * to handle CK_FileNext and CK_FilePrev commands */
191 int *dir_count; /* Number of files in dir structure.
192 * Pointer is used here as reference to WPanel::count */
193 int *dir_idx; /* Index of current file in dir structure.
194 * Pointer is used here as reference to WPanel::count */
195 } mcview_t;
197 typedef struct mcview_nroff_struct
199 mcview_t *view;
200 off_t index;
201 int char_width;
202 int current_char;
203 nroff_type_t type;
204 nroff_type_t prev_type;
205 } mcview_nroff_t;
207 typedef struct mcview_search_options_t
209 mc_search_type_t type;
210 gboolean case_sens;
211 gboolean backwards;
212 gboolean whole_words;
213 gboolean all_codepages;
214 } mcview_search_options_t;
216 /*** global variables defined in .c file *********************************************************/
218 extern mcview_search_options_t mcview_search_options;
220 /*** declarations of public functions ************************************************************/
222 /* actions_cmd.c: */
223 cb_ret_t mcview_callback (Widget * w, widget_msg_t msg, int parm);
224 cb_ret_t mcview_dialog_callback (Dlg_head * h, Widget * sender,
225 dlg_msg_t msg, int parm, void *data);
227 /* coord_cache.c: */
228 coord_cache_t *coord_cache_new (void);
229 void coord_cache_free (coord_cache_t * cache);
231 #ifdef MC_ENABLE_DEBUGGING_CODE
232 void mcview_ccache_dump (mcview_t * view);
233 #endif
235 void mcview_ccache_lookup (mcview_t * view, coord_cache_entry_t * coord,
236 enum ccache_type lookup_what);
238 /* datasource.c: */
239 void mcview_set_datasource_none (mcview_t *);
240 off_t mcview_get_filesize (mcview_t *);
241 void mcview_update_filesize (mcview_t * view);
242 char *mcview_get_ptr_file (mcview_t *, off_t);
243 char *mcview_get_ptr_string (mcview_t *, off_t);
244 int mcview_get_utf (mcview_t *, off_t, int *, gboolean *);
245 gboolean mcview_get_byte_string (mcview_t *, off_t, int *);
246 gboolean mcview_get_byte_none (mcview_t *, off_t, int *);
247 void mcview_set_byte (mcview_t *, off_t, byte);
248 void mcview_file_load_data (mcview_t *, off_t);
249 void mcview_close_datasource (mcview_t *);
250 void mcview_set_datasource_file (mcview_t *, int, const struct stat *);
251 gboolean mcview_load_command_output (mcview_t *, const char *);
252 void mcview_set_datasource_vfs_pipe (mcview_t *, int);
253 void mcview_set_datasource_string (mcview_t *, const char *);
255 /* dialog.c: */
256 gboolean mcview_dialog_search (mcview_t * view);
257 gboolean mcview_dialog_goto (mcview_t * view, off_t * offset);
259 /* display.c: */
260 void mcview_update (mcview_t * view);
261 void mcview_display (mcview_t * view);
262 void mcview_compute_areas (mcview_t * view);
263 void mcview_update_bytes_per_line (mcview_t * view);
264 void mcview_display_toggle_ruler (mcview_t * view);
265 void mcview_display_clean (mcview_t * view);
266 void mcview_display_ruler (mcview_t * view);
267 void mcview_percent (mcview_t * view, off_t p);
269 /* growbuf.c: */
270 void mcview_growbuf_init (mcview_t * view);
271 void mcview_growbuf_free (mcview_t * view);
272 off_t mcview_growbuf_filesize (mcview_t * view);
273 void mcview_growbuf_read_until (mcview_t * view, off_t p);
274 gboolean mcview_get_byte_growing_buffer (mcview_t * view, off_t p, int *);
275 char *mcview_get_ptr_growing_buffer (mcview_t * view, off_t p);
277 /* hex.c: */
278 void mcview_display_hex (mcview_t * view);
279 gboolean mcview_hexedit_save_changes (mcview_t * view);
280 void mcview_toggle_hexedit_mode (mcview_t * view);
281 void mcview_hexedit_free_change_list (mcview_t * view);
282 void mcview_enqueue_change (struct hexedit_change_node **, struct hexedit_change_node *);
284 /* lib.c: */
285 void mcview_toggle_magic_mode (mcview_t * view);
286 void mcview_toggle_wrap_mode (mcview_t * view);
287 void mcview_toggle_nroff_mode (mcview_t * view);
288 void mcview_toggle_hex_mode (mcview_t * view);
289 gboolean mcview_ok_to_quit (mcview_t * view);
290 void mcview_init (mcview_t * view);
291 void mcview_done (mcview_t * view);
292 void mcview_select_encoding (mcview_t * view);
293 void mcview_set_codeset (mcview_t * view);
294 void mcview_show_error (mcview_t * view, const char *error);
295 off_t mcview_bol (mcview_t * view, off_t current, off_t limit);
296 off_t mcview_eol (mcview_t * view, off_t current, off_t limit);
297 char *mcview_get_title (const Dlg_head * h, size_t len);
299 /* move.c */
300 void mcview_move_up (mcview_t *, off_t);
301 void mcview_move_down (mcview_t *, off_t);
302 void mcview_move_left (mcview_t *, off_t);
303 void mcview_move_right (mcview_t *, off_t);
304 void mcview_scroll_to_cursor (mcview_t *);
305 void mcview_moveto_top (mcview_t *);
306 void mcview_moveto_bottom (mcview_t *);
307 void mcview_moveto_bol (mcview_t *);
308 void mcview_moveto_eol (mcview_t *);
309 void mcview_moveto_offset (mcview_t *, off_t);
310 void mcview_moveto (mcview_t *, off_t, off_t);
311 void mcview_coord_to_offset (mcview_t *, off_t *, off_t, off_t);
312 void mcview_offset_to_coord (mcview_t *, off_t *, off_t *, off_t);
313 void mcview_place_cursor (mcview_t *);
314 void mcview_moveto_match (mcview_t *);
316 /* nroff.c: */
317 void mcview_display_nroff (mcview_t * view);
318 int mcview__get_nroff_real_len (mcview_t * view, off_t, off_t p);
320 mcview_nroff_t *mcview_nroff_seq_new_num (mcview_t * view, off_t p);
321 mcview_nroff_t *mcview_nroff_seq_new (mcview_t * view);
322 void mcview_nroff_seq_free (mcview_nroff_t **);
323 nroff_type_t mcview_nroff_seq_info (mcview_nroff_t *);
324 int mcview_nroff_seq_next (mcview_nroff_t *);
325 int mcview_nroff_seq_prev (mcview_nroff_t *);
328 /* plain.c: */
329 void mcview_display_text (mcview_t *);
331 /* search.c: */
332 mc_search_cbret_t mcview_search_cmd_callback (const void *user_data, gsize char_offset,
333 int *current_char);
334 int mcview_search_update_cmd_callback (const void *, gsize);
335 void mcview_do_search (mcview_t * view);
337 /*** inline functions ****************************************************************************/
339 #include "inlines.h"
341 #endif /* MC__VIEWER_INTERNAL_H */